DigitalOcean Managed Database trusted sources: lock the cluster to your app

A DigitalOcean Managed Database is reached over TLS on a public hostname, and trusted sources decide who may connect. The documentation does not say what an empty list allows, so add the entries yourself and prove the lockout with a connection that should fail.

A managed database takes the worst job off your plate, which is running one. What it does not take off your plate is deciding who may knock on its door. DigitalOcean calls that setting trusted sources, and it is easy to leave unset on a cluster you created in a hurry.

What trusted sources are

Every engine's secure page opens with the same idea: typically, only application servers are allowed to connect to the database cluster. Trusted sources are how you say which ones. The PostgreSQL, MySQL, Valkey, MongoDB, Kafka and OpenSearch pages share one template, so what follows applies across engines.

In the control panel, on the cluster's Network Access tab, each entry shows an icon for its type, such as a Droplet, an App Platform app, a tag or a Kubernetes cluster, and you can also enter IP addresses or CIDR ranges. Through the API and doctl, the allowed types are droplet, k8s, ip_addr, tag and app. The API reference explains how tags behave: when a tag is provided, any Droplet or Kubernetes node with that tag applied has access. A tag is the neat way to cover a fleet, and it is also a way to grant database access to anything you tag carelessly. We found no mention of load balancers or other database clusters as source types.

What an empty list does, and what the docs leave out

This is the question that matters most, and the documentation does not answer it. We checked the secure pages for all six engines, the API reference for the firewall endpoint, the PostgreSQL create page and the release notes. None says what a cluster with no trusted sources accepts.

There are hints. The App Platform page says that enabling an app as a trusted source blocks any other connections, and it tells you to disable trusted sources on the database to let an app connect during development. That reads as if a disabled list means unrestricted access, but it is an implication, not a statement. The create flow does not prompt you either. The PostgreSQL create page only says you can complete tasks such as restricting inbound connections while the cluster provisions.

So do not rely on a default. Open the Network Access tab for each cluster and look at what is there. Then test the result the way an outsider would: from a machine that is not on the list, try to connect with your normal client. If the connection is accepted, the lockout is not working, whatever the tab says.

One habit helps here. Add application servers by tag rather than by IP address, because Droplets are replaced far more often than clusters. Because the API reference says any Droplet or Kubernetes node with the tag gains access, keep the tag name specific, such as one that means this app may reach this database, and never reuse a broad tag such as the one on every web server.

The private hostname, and the VPC option

The connection page describes public and private hostnames and states that only resources in the same VPC network as the cluster can connect using the private one. Whether trusted sources also apply to the private hostname is not stated anywhere we read.

What DigitalOcean does say, in the API reference, is that when possible it recommends placing databases into a VPC network to limit access, instead of using a firewall. That is worth taking literally. The strongest arrangement is both: connect your application over the private hostname from the same VPC, and keep trusted sources limited to that application. The VPC article covers the network side.

Ports are not the ones you remember

A self-hosted PostgreSQL listens on 5432. A DigitalOcean Managed Database does not. The documentation tells you to take the port from Connection Details and mostly uses a placeholder. The API reference examples show 25060 for a PostgreSQL cluster and 25061 for a connection pool, the MySQL connect page uses -P 25060, and the Valkey page uses 25061. Those are examples, so read your own Connection Details instead of copying a number.

It also means that a firewall rule written for 5432, or a port scan that looks for 3306, tells you nothing about your managed clusters. Look at the cluster's own settings.

TLS is required, and not all verification is equal

DigitalOcean says managed PostgreSQL clusters require TLS for all connections, and that the connection details come with sslmode set to require. That encrypts the traffic but does not verify the server's identity. The verify-ca and verify-full modes are disabled by default because they can affect performance, and verify-full is described as the most secure option. On a Standard Edition cluster you download the CA certificate from the control panel. On an Advanced Edition cluster you do not, and the documentation uses sslrootcert=system with libpq 16 or later.

MySQL, OpenSearch and Kafka pages say you must use SSL by default. For an application that talks across the public internet, verify-full is worth the effort.

Managing rules with doctl

The doctl databases firewalls commands are list, append, remove and replace. A rule is written as type:value. The reference's own example appends a tag:

doctl databases firewalls list <database-cluster-id>
doctl databases firewalls append <database-cluster-id> --rule tag:example-tag
doctl databases firewalls replace <database-cluster-id> \
  --rules droplet:<droplet-id>,ip_addr:203.0.113.7

Be careful with replace. DigitalOcean's description of the bulk update is that the rules in the request become the cluster's full list and any existing rule you omit is removed. That is exactly what you want when tightening a cluster and exactly how you lock out your own application. Run list first, and keep its output. The reference page is also inconsistent about whether the flag is spelled --rule or --rules, so run the command with --help on your version before you script it.

Checking every cluster

The columns of doctl databases list include ID, Name and Engine, so a loop over your clusters is short:

for id in $(doctl databases list --format ID --no-header); do
  echo "== $id"
  doctl databases firewalls list "$id"
done

Any cluster that prints an empty list is the one to open first. The loop only lists, so it is safe to run against production.

Limits and gaps

  • Rule count. The docs say clusters are limited to 100 firewall rules. The PostgreSQL and MySQL limits pages add that by default a cluster supports up to 2,000 IP addresses as trusted sources, and that different resource types add varying numbers. A Droplet typically counts as two.
  • No IPv6. You currently cannot add IPv6 rules to a cluster's trusted sources.
  • No Cloud Firewall. The MySQL limits page says you cannot use DigitalOcean's Cloud Firewalls with managed databases, so trusted sources are the only network control on the cluster itself. Your Droplets still need theirs, as the Cloud Firewall article explains.
  • Forks start fresh. The MySQL limits page says firewall rules are not copied when you create a cluster by forking, and that the fork uses default firewall settings. The default is not defined, which makes a fork a cluster to check at once.

Taken together, the safe habit is to treat every new cluster, restored backup and fork the same way: open Network Access, add the one application that needs it, and try a connection from somewhere else.

FAQ

What happens if a DigitalOcean database has no trusted sources?

The documentation does not say. Treat it as unrestricted until you have tested it: add your application as a trusted source, then try to connect from a machine that is not on the list.

Can I use a Cloud Firewall with a managed database?

No. DigitalOcean's MySQL limits page says Cloud Firewalls cannot be used with managed databases. Use trusted sources, and a VPC where you can.

Do trusted sources work with IPv6?

No. DigitalOcean states you cannot add IPv6 rules to a cluster's trusted sources.

Which port does a managed DigitalOcean database use?

Read it from the cluster's Connection Details. The documentation examples show 25060 for a PostgreSQL cluster and 25061 for a connection pool, but they are examples.

Secorvia lists Managed Databases among the DigitalOcean services it connects, read-only, with a read-scope token. The DigitalOcean integration page and the DigitalOcean page say what that covers.

Keep reading
DigitalOcean · 6 min read

DigitalOcean Cloud Firewalls: audit every Droplet at once

DigitalOcean · 5 min read

DigitalOcean API tokens: what a leaked one can reach

Fundamentals · 5 min read

Toxic combinations: two safe settings that are dangerous together

Try it against your own cloud account.