rdsaccess.guide A guide by Firezone

Reach a private RDS database from a laptop

An Amazon RDS database is safest when it has no public endpoint. Your team still needs to run queries from a laptop. This guide compares each way to connect, and it shows how to do it with no open inbound port.

Secure a Postgres database with FirezoneBook a demo

How a laptop reaches a private RDS databaseA laptop sends an encrypted tunnel to a Gateway inside the VPC. The Gateway connects through a security group to the RDS instance on the database port. An internet scanner finds no public endpoint, because the public endpoint is turned off.InternetYour VPCtunnelno route5432allowLaptoppsql, Firezone ClientInternet scannertries port 5432Gatewaydials out onlyPublic endpointturned offSecurity groupallows the Gateway onlyRDS instanceprivate, TCP/5432
  1. The database has no public address

    The public endpoint is turned off. A scanner on the internet has no route to the database port.

  2. The laptop connects to a Gateway

    The Client sets up a WireGuard tunnel to a Gateway in the VPC. The Gateway accepts no inbound connection from the internet.

  3. The security group trusts one source

    The security group of the database accepts the database port from the Gateway and from your apps.

  4. Only the database port passes

    The Resource is limited to TCP/5432. The laptop reaches the database and no other host in the VPC.

Why a private RDS database is hard to reach

Each Amazon RDS instance has an endpoint, which is a DNS name such as mydb.abc123.us-east-1.rds.amazonaws.com. Each instance also has a setting with the name Publicly accessible.

  • When the setting is on, the instance has a public IP address. The RDS endpoint resolves to that address from outside the VPC.
  • When the setting is off, the instance has a private IP address only. The RDS endpoint resolves to an address that only hosts inside the VPC can reach.

A private RDS database is the correct default. Your applications run in the same VPC and connect with no problem.

The problem starts when a person needs access. A developer wants to connect to RDS from a laptop with psql or a database tool. The laptop is not in the VPC, so the private address goes nowhere.

AWS describes the network rules for an instance in its guide to DB instances in a VPC.

Why a publicly accessible database is a risk

The fast fix is to turn on the public endpoint. This fix puts the database port on the internet.

  • Scans. Scanners look for open database ports such as 5432 and 3306 on all public addresses.
  • Password attacks. The only protection that stays is the database password. Database passwords are frequently old, shared, and stored in many places.
  • One rule from exposure. A security group rule that permits 0.0.0.0/0 opens the database to all of the internet. A person can add that rule in a hurry and not remove it.
  • Audit findings. Most security frameworks and cloud audit tools flag a database with a public address.

A database holds the data that an attacker wants most. Keep it off the internet, and solve the access problem a different way.

Four ways to connect to RDS from a laptop

A public endpoint with an IP allowlist

You turn on the public endpoint and limit the security group to known source addresses. This option needs no more infrastructure.

It fails for people who move. Home addresses change, and a coffee shop or a hotel has a new address each time. The allowlist grows, nobody removes old entries, and the database is still on a public address.

A bastion host with an SSH tunnel

You run a small instance in a public subnet. The developer opens an SSH tunnel through it:

ssh -N -L 5432:mydb.abc123.us-east-1.rds.amazonaws.com:5432 ec2-user@bastion.example.com

The developer then connects to localhost:5432. The database stays private. The cost is the bastion host: an open SSH port, an instance to patch, and an SSH key for each person. Each developer must also start the tunnel before each session.

A cloud VPN

A managed client VPN from the cloud provider puts the laptop in the VPC. The database stays private, and no SSH tunnel is necessary.

A cloud VPN usually gives a route to full subnets, so you must add rules to limit each user to the database. The price usually depends on the number of connections and on the hours of use.

Zero trust access

A small agent in the VPC makes an outbound connection to a broker. The user signs in with an identity provider. A rule gives one group access to the database endpoint on the database port, and to no other host.

This option gives you RDS without a bastion host and without a public address.

Good practices for any option

  • Keep the public endpoint off. Set Publicly accessible to no, and put the instance in private subnets.
  • Refer to a security group, not to an address range. Let the database security group accept the database port from the security group of the hop. Do not use a wide CIDR.
  • Give each person a database user. Do not share the master user. Give read-only roles to people who only read.
  • Require TLS. Make the database refuse connections that are not encrypted.
  • Use the endpoint name. The private address of an instance can change after a failover. The RDS endpoint name stays the same.
  • Keep a record. Know who connected to the database, from which device, and when.

How Firezone gives access to a private RDS database

Firezone is an open source zero trust access platform built on WireGuard. You run a Gateway inside the VPC. Firezone runs the control plane. The Gateway makes outbound connections only, so its security group needs no inbound rule.

  1. Deploy a Gateway in the VPC. The Terraform example for AWS deploys Gateways that fail over and balance load for each other.
  2. Add a DNS Resource. Use the RDS endpoint name as the address. The Gateway resolves the name inside the VPC, so it gets the private address.
  3. Add a traffic restriction. Limit the Resource to TCP/5432 for PostgreSQL, or to TCP/3306 for MySQL and MariaDB.
  4. Write a Policy. Give the database Group access to that one Resource. Access is default-deny for all other people.
  5. Update the security group. Let the database accept its port from the security group of the Gateway.

The developer signs in to the Firezone Client and connects with the usual command:

psql -h mydb.abc123.us-east-1.rds.amazonaws.com -U app_reader -d app

No tunnel command and no local port are necessary. The same endpoint name works in database tools and in scripts. The Postgres guide shows each step, and the steps apply to other databases also.

The database still authenticates the user with its own user name and password. Firezone controls who can reach the port. A conditional access rule can also limit a Policy by country, by source IP range, or by time of day. Conditional access is available on the Team plan and higher. Flow Logs record which person connected to the Resource and when.

Public endpoint, bastion host, cloud VPN, and Firezone

The four approaches differ in what the internet can reach and in how much work each connection takes.

Public endpointBastion + SSH tunnelCloud VPNFirezone
The database has no public addressNoYesYesYes
No inbound port open to the internetNoThe database portNoTCP 22 on the bastion hostNoThe VPN endpointYes
Access limited to the database portYesPartialThe bastion host can reach morePartialNeeds authorization rulesYesOne Resource with TCP/5432
Works from any network with no allowlist changeNoPartialIf port 22 is open to allYesYes
Connect with the endpoint name, no tunnel commandYesNoStart an SSH tunnel firstYesYes
Sign-in with your identity providerNoPartialNeeds more softwareYesYesOIDC or an email code
No more hosts to run in the VPCYesNoThe bastion hostYesThe provider runs itNoOne or more Gateways

The table describes the usual design of each category. A specific product or setup can be different. Read the documentation of the product before you decide.

Common questions

How do I connect to a private RDS database from my local machine?

You need a hop inside the VPC. The hop can be a bastion host with an SSH tunnel, a cloud VPN, or a zero trust Gateway. The hop connects to the RDS endpoint on the database port, and the security group of the database must permit the hop.

Is it safe to make an RDS instance publicly accessible?

It is a risk that you can avoid. A strict security group reduces the risk, but the database still has a public address, and one wrong rule opens it to the internet. Keep the public endpoint off, and use a private path.

Can I reach RDS without a bastion host?

Yes. A cloud VPN and zero trust access each give a private path with no bastion host and no SSH tunnel. With Firezone, a Gateway in the VPC connects outbound, and you add the RDS endpoint as a DNS Resource.

Why does the RDS endpoint not connect from outside the VPC?

The endpoint of a private instance resolves to a private IP address. That address has a route only inside the VPC. From a laptop on a different network, the connection times out.

Which port does Amazon RDS use?

The default port depends on the engine. PostgreSQL uses TCP 5432. MySQL and MariaDB use TCP 3306. You can set a different port when you create the instance.

Is this guide about Windows Remote Desktop Services?

No. This guide is about Amazon RDS, the managed database service. For Windows Remote Desktop Services, you want zero trust access to RDP. See Access a device via SSH or RDP.

Keep the database private and the access simple

Firezone is zero trust access built on WireGuard. Deploy a Gateway in your VPC, add the RDS endpoint as a DNS Resource, and write a Policy for the database Group. The Starter plan is free.

See plans and pricingBook a demo