Safeguard
Security Guides•

What does trust mean in pg_hba.conf and when is it a bug?

The trust method in pg_hba.conf lets anyone who can reach the server log in as any user with no password. Use scram-sha-256 for anything real.

Safeguard Security Team
4 min read

The trust method in pg_hba.conf allows a connection unconditionally. Anyone who can reach the server can log in as any PostgreSQL user they choose, with no password. Use it only on isolated throwaway setups. For real data, use scram-sha-256 on every record that can be reached over a network.

What the documentation says

The PostgreSQL reference for pg_hba.conf describes trust plainly: it allows the connection unconditionally, so anyone who can connect can log in as any PostgreSQL user they wish, without a password or any other authentication. That includes the superuser role.

Trust shows up in tutorials and Docker examples because it removes friction. It is also easy to leave behind when a local test configuration is copied into an environment that other machines can reach.

The methods you will compare

MethodWhat it doesUse it when
trustNo authenticationIsolated local testing only
rejectRefuses the connectionBlocking specific hosts
scram-sha-256Verifies the password with SCRAM-SHA-256Default choice for password logins
md5SCRAM-SHA-256 or MD5 verificationLegacy clients, being phased out
passwordSends the password in clear textNot on untrusted networks

The md5 entry carries a warning in the documentation. Support for MD5 encrypted passwords is deprecated and will be removed in a future release. If you still have MD5 hashes stored, see migrating PostgreSQL MD5 passwords to SCRAM.

The password method is worth a note too. The docs say the password is sent in clear text over the network, so it should not be used on untrusted networks.

How to find trust in your setup

  1. Open pg_hba.conf and search for the word trust.
  2. Check each match for its connection type. A local line limits exposure to people on the host. A host line may expose the network.
  3. Read the address range. A narrow range is a smaller problem than a wide one, but still unauthenticated.
  4. Check container images and compose files, including any custom configuration they mount.
  5. Replace with scram-sha-256, set a strong password for the role, and reload the configuration.
  6. Test from a second machine that a login without the password fails.

Remember that order matters. Our post on how first match works shows how an early permissive line overrides a later strict one.

A dev container is still a risk

A common pattern is a development database with trust enabled and a published port. If that port binds to all interfaces, a person on the same network can connect with no password. See Docker Compose and published database ports for how to keep it on loopback.

When trust is acceptable

A local Unix socket on a single user machine, or an ephemeral database inside a test run that holds no real data, are the realistic cases. Even then, never copy that file into a shared environment.

Safeguard's dependency scanning and policy gates can run on the repositories that hold your container and compose files. A free scan is at gold.safeguard.sh/scan.

Quick check

Does trust skip the password for the superuser too?

Yes. The documentation says anyone who can connect can log in as any PostgreSQL user they wish.

Is scram-sha-256 the replacement?

It is the usual password method. The docs mark md5 as deprecated.

Is local trust safe?

It narrows exposure to users on the host but still skips authentication. Treat it as a testing convenience.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.