PostgreSQL client certificate authentication

Client certificates let services and administrators log in to PostgreSQL without shared passwords. This page covers how the cert method, clientcert=verify-full, pg_ident.conf mapping and an internal CA fit together, and what to confirm before rollout.

On this page

PostgreSQL client certificate authentication for services and admins

If your team wants to retire shared database passwords for services and administrators, client certificate authentication is the PostgreSQL feature built for that goal. The cert method in pg_hba.conf tells the server to accept a connection only when the client presents a certificate signed by a CA the server trusts, and it uses the certificate's identity in place of a password the client must know. PostgreSQL documents certificate as one of its client authentication methods, alongside password, GSSAPI, LDAP and OAuth. Certificates fit best when the caller is software that can hold a private key on disk or in a secrets store, such as a batch job, an application service or a deployment pipeline, and when you need to revoke one caller without changing a password shared by many. They fit less well for people who connect from ad hoc tools that cannot present a client certificate.

This section covers certificate design only. The server-side TLS setup, including server certificates, protocol versions and requiring hostssl, is covered in the sibling topic on configuring TLS for PostgreSQL connections, and the rule-ordering questions belong to the pg_hba.conf topic. Before you start, confirm in writing who will own the internal CA, how long client certificates will live, and where private keys will be stored. Those three decisions drive most of the later work. The PostgreSQL client authentication documentation describes the method and its options, and you should read it against the exact major version you run, since authentication behavior has changed across releases.

How a client certificate becomes a database login

The flow starts with the internal CA, which signs a client certificate for a service or admin. The client then opens a TLS connection with sslmode=verify-full, so it checks the server certificate against the trusted root. On the server, pg_hba.conf decides whether a cert rule applies to the connection, and pg_ident.conf maps the certificate name to a database role. Check each hand-off: the CA chain, the name the client presents, and the map entry that produces the login role.

Trust boundaries between the CA, the client and the PostgreSQL server during certificate login.

Certificate authentication options and when each fits

This table compares the certificate-based options PostgreSQL offers, from checking only the certificate chain to matching the certificate name to a role. Read each row against the account type you are placing: service, human admin or replication. The main takeaway is that the stricter the name check and the more direct the mapping, the less room there is for a mislabeled or reused certificate to reach a privileged role.

OptionWhat it checksRole mappingWhen it fits
cert with clientcert=verify-caClient certificate is signed by a trusted CA, but the certificate name is not compared to the usernameUsername supplied by the client must match a role; any certificate from the CA can claim any roleRarely appropriate; use only where the CA is tightly controlled and roles are few
cert with clientcert=verify-fullClient certificate is signed by a trusted CA and the certificate name must match the requested usernameCertificate common name is compared directly to the database role, with no separate mapping fileService accounts with one role each, where certificate names are issued per service
cert with a map (pg_ident.conf)Certificate is signed by a trusted CA and its name is passed through a map before the role is chosenMaps certificate names to one or more roles, so names and roles can differHuman admins and shared identity schemes where names and database roles do not match one to one
cert without a map, role matched by nameCertificate validity and certificate name, with the name used as the roleDirect match, which is simple to audit but ties certificate issuance to role namingSmall estates where each certificate name equals one database role and renewals are tracked
Replication connectionsCertificate used for streaming replication, usually limited to the replication pseudo-databaseDedicated replication role that should hold no other privilegesStandby servers that need a separate, narrowly scoped certificate and role
Human admin accessNamed personal certificate, ideally with a map that routes it to an admin roleMapped to a role that is not the superuser, with elevation handled separatelyNamed administrators who need traceable access and quick revocation
Confirm for your versionOption names, keywords and map syntax can change between major versionsCheck the supported version's client authentication documentation before writing rulesBefore any rule is deployed to production or an assessor review

Setting up certificate login step by step

This sequence takes you from an internal certificate authority to a working login where a client certificate, not a password, proves who is connecting and which database role they receive. Each step ends with a check so you know it held before you move on.

  1. Define the internal CA and protect its key

    The security team or PKI owner creates a certificate authority used only for PostgreSQL and related services, with a root or intermediate key stored offline or in a hardware-backed or secrets store your organization already audits. Decide the validity periods, the subject naming convention (for example, one service identity per application and one per named administrator) and who may sign requests. Keep the CA certificate file ready for distribution to the server and every client. The step is done when you can show the CA certificate, its fingerprint, and a written record of who can access the signing key.

  2. Issue server and client certificates

    Generate a private key and certificate signing request for the PostgreSQL server, with its host name in the subject alternative name so clients can verify it. Then generate one key and certificate per client identity, setting the common name or subject to exactly the string you will map to a database role. Sign each request with your CA. The check is to inspect each certificate with openssl and confirm the issuer, validity dates, subject and subject alternative names match your naming plan, and that the client keys are readable only by the account that runs each client.

  3. Enable TLS on the PostgreSQL server

    Install the server certificate, its private key and the CA certificate on the database host, then set the SSL options in postgresql.conf so the server presents the certificate and, for client verification, loads the CA file. Confirm that the key file permissions are restricted to the PostgreSQL operating system user, since the server refuses keys it considers too open. Reload or restart as your platform requires. The check is to run SHOW ssl in psql and confirm it reports on, then confirm a TLS connection succeeds with the server certificate verified by the CA.

  4. Add the hostssl cert rule to pg_hba.conf

    Add a hostssl line that uses the cert method with clientcert=verify-full for the specific database, user or user group and address range that should log in with certificates. Keep it above any broader password rules, and place the map option only if you will map certificate names in pg_ident.conf. Remove or narrow any entries that would let the same account log in another way. Reload the configuration. The check is a pg_hba_file_rules view query showing the rule parsed without error, since a syntax problem in this file can lock out administrators.

  5. Write pg_ident.conf mappings

    Where the certificate subject does not match the database role name, add a map name in pg_hba.conf and matching lines in pg_ident.conf that translate each certificate identity to a role. Map only the identities you intend, and avoid wildcard mappings that would grant roles to any certificate issued by the CA. Make sure every target role already exists with the minimum privileges it needs. Reload and verify. The check is a query on pg_hba_file_rules that shows the map column and no errors, and a test login from one identity that lands in the expected role.

  6. Configure clients with sslcert and sslkey

    On each client, set the connection to use sslmode=verify-full, the CA file as sslrootcert, and the client certificate and key as sslcert and sslkey, either in the connection string or in the user's .postgresql directory with restricted permissions. Applications that run through a connection pooler need the same setup on the pooler's server side, so confirm how your pooler forwards client certificates before you rely on it. The check is that the client connects, reports the expected role with SELECT current_user, and shows ssl as true in pg_stat_ssl for its session.

  7. Test a successful login and a rejected login

    Run two tests from a clean session. First, connect with a valid certificate from an allowed identity and confirm it reaches the intended role and database. Second, attempt a connection that must fail: a certificate signed by a different CA, an expired certificate, a certificate whose name is not mapped, or a client without a certificate. Each rejected attempt should fail with an authentication or SSL error recorded in the server log. Keep the test results with your change record. This closes the sequence only when both outcomes match the design.

Running an internal CA for database client certificates

Start by separating the certificate authority that signs client certificates from anything people or services use day to day. The root CA key should stay offline or in a hardware-backed store, and an intermediate CA should do the signing for PostgreSQL client certificates. If an intermediate is compromised, you revoke and replace it without rebuilding trust across every database, and the root can stay locked away. Decide who may request certificates, who approves them, and which CA signs database client certificates, then write those rules down before the first certificate is issued. Ask your CA software vendor or internal PKI team which key storage options they support for each level of the hierarchy.

Validity periods and renewal are where most internal CAs cause outages. Short-lived service certificates reduce the damage from a stolen key but add renewal work that must be automated, while long-lived admin certificates need a planned expiry reminder. Set the lifetime for each certificate class, record the renewal owner, and test what happens when a certificate expires on a live connection pool. Remember that the server checks the certificate chain and the role mapping, so a rotated certificate must still map to the same role in pg_ident.conf. Confirm your rotation procedure with a staging server first.

Revocation needs the most explicit decision. PostgreSQL does not run a certificate revocation list or OCSP check for you, so the server does not reject a certificate just because your CA has revoked it. Confirm in the PostgreSQL client authentication documentation and your test environment exactly what the server validates, then decide how you will stop a compromised certificate. Common approaches are removing the role mapping, disabling the login role, or restarting with a trust store that no longer contains the issuing intermediate. Whatever you choose, keep the private keys in a controlled location such as a secrets manager or hardware module, restrict who can read them on database hosts, and rehearse a revocation before you need it.

Security and operational risks of certificate authentication

Certificate authentication removes shared passwords, but it moves the risk to private keys, certificate names and certificate lifetimes. The cards below pair each risk with the control that reduces it, so the team can check those controls before certificates replace passwords in production.

Private key exposure on client hosts

A client key file that can be read by another local user or process lets that party connect as the mapped PostgreSQL role. Store each service key with owner-only permissions, run the service under its own account, and keep admin keys off shared jump hosts. Check file modes and ownership on every host that holds a key, and confirm whether the key is protected by a passphrase or a hardware-backed store. Where a key is exposed, reissue the certificate and revoke the old one.

Overly broad certificate name mapping

A regular expression in pg_ident.conf that matches more names than intended can let a certificate issued for one service log in as a privileged role. Map each certificate subject to a single database role, avoid wildcards on the common name, and keep the map file under change control. Test each mapping with a certificate that should be refused, not only with the one that should work.

Expiry causing outages

When a client or server certificate expires, every connection that depends on it fails at once, often during an unrelated deployment. Record the not-after date of each certificate, alert well before it, and schedule renewal as routine work. Confirm how your applications and connection poolers reload a renewed certificate, because some need a restart before they pick it up.

Missing revocation

A certificate signed by your internal CA stays valid until it expires unless you revoke it and clients or servers check revocation. PostgreSQL does not check certificate revocation lists on its own in the way many teams assume, so confirm what your CA publishes and how the server validates the chain. Short lifetimes and a documented procedure for removing a compromised service's role access reduce the window in which a stolen key works.

Keys in container images or CI logs

Private keys baked into a container image, committed to a repository, or printed by a pipeline step spread to every system that can read those artifacts. Inject keys at runtime from a secrets store, mount them read-only, and scan images and build logs for key material. Confirm that your CI system masks secret variables and that old image layers and cached artifacts do not retain the key.

Password and trust entries left in pg_hba.conf

Once certificates work, leftover password, md5 or trust lines in pg_hba.conf still allow a weaker login path for the same roles. Remove those entries after the certificate path is verified, and keep hostssl rules so that only encrypted, certificate-checked connections match. Review the file after each change and confirm the server reloads with the intended rules, since an earlier matching line takes precedence.

Questions buyers ask before certificate authentication rollout

Can our own team set up certificate authentication for PostgreSQL without a partner?

Yes, many teams can, provided they already run an internal certificate authority and have engineers comfortable with pg_hba.conf, pg_ident.conf and TLS. The PostgreSQL side is a small set of configuration changes: a cert line in pg_hba.conf with clientcert=verify-full, and optionally a mapping in pg_ident.conf from certificate names to database roles. The harder parts are usually outside the database: issuing and rotating client certificates for every service, updating each application's connection settings, and handling admins' workstations. Ask yourself whether those tasks already have an owner and a process. If they do not, a partner can help design them, and your team keeps the result.

What drives the effort of a certificate authentication rollout?

The main drivers are the number of services and admins that connect, how mature your certificate authority is, the client tools each application uses, and how much of your existing PKI you can reuse. Each application or client library may handle certificates, passphrases and sslmode settings differently, so every connection path needs testing. A CA that already issues short-lived certificates with automated renewal shortens the work. A CA that is manual, undocumented or not yet built adds design and operations work before PostgreSQL changes at all. Replication, connection poolers and any tools that sit between clients and the server also add paths to verify.

What does the work need from our organization before it starts?

The work needs a named owner for the certificate authority, including who signs intermediate certificates, where the private keys are stored and how revocation is handled. It also needs a current inventory of every service account and human login that uses a database password today, with each account's owner and the roles it holds. Change windows must be agreed for the server restart or reload, and for each application cutover. Ask for access to a non-production PostgreSQL instance that matches production versions and TLS settings, so the rollout can be tested before anything changes in production.

How long does a certificate authentication rollout take?

Duration depends on scope: how many databases, roles and applications are involved, whether a CA already exists, and how many client paths need a cutover. A rollout limited to one database and one service with an existing CA is much shorter than a multi-cluster rollout that also builds a CA and migrates admin access. The schedule should follow from a written list of in-scope clusters, clients and roles. Do not accept a duration that is not tied to that list. Ask for phases with clear exit checks, such as a verified test connection and a documented rollback path for each application.

Should we replace passwords everywhere or keep them for some accounts?

Most organizations keep passwords for some accounts for a period, because not every client supports certificates equally well. The useful question is which accounts move first and which stay on a stronger password method. Keep the older rules in place until each replacement is verified, then remove them from pg_hba.conf so the password path cannot be used as a fallback. Check which entries allow password or trust access, because a leftover permissive line can undo the work. A review of the full rule set is a sensible part of the same project.

What should a quote for certificate authentication include?

A quote should follow from a written scope and list the deliverables explicitly. Ask it to state which PostgreSQL clusters, roles and client applications are covered, whether the CA is built, reviewed or only used, and how certificates are issued, renewed and revoked. It should name the server and client TLS settings to be changed, the test plan for each client path, the rollback steps, and the documentation handed over. Ask which costs are one-time, such as design and cutover, and which recur, such as CA operation, certificate renewal and support. Also ask what the customer must provide, so the quote does not hide dependencies.

Will certificate authentication satisfy our compliance auditor on its own?

No. Certificate authentication is one control. An auditor will look at how access is granted, reviewed and removed, how keys and certificates are protected, and whether logs show who connected. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications. Ask your assessor early which evidence they expect, such as the CA procedure, certificate lifetimes, revocation records and the configuration history of pg_hba.conf. Those records should be produced as part of the rollout, not reconstructed later.

Limits to confirm in your environment

Certificate authentication touches the PostgreSQL server, every client driver and pooler in the path, your PKI and your access model. The cards below list the points to confirm before you design the rollout, because a gap in any one of them can force a return to passwords.

PostgreSQL version and certificate behavior

Confirm which PostgreSQL major version you run and whether its certificate handling matches the behavior your design assumes. The supported versions today are 14 through 18, and only supported versions receive security fixes, so an older cluster should be upgraded before you rely on certificate rules that depend on newer server behavior. Read the release notes for your exact version and test clientcert=verify-full on a non-production cluster first.

Supported major versions
14 to 18
Versioning policy

Driver and pooler support

Not every client library or connection pooler passes client certificates through the way your applications expect. Confirm that each driver can present a client certificate and key, and check how PgBouncer handles client authentication for your specific version, since it currently ships security fixes in 1.26.1. Where a pooler sits in the path, test whether the certificate identity reaches PostgreSQL or is replaced by the pooler's own login.

PgBouncer site

PKI can issue the required certificates

Your existing certificate authority must issue client certificates whose subject fields can be mapped to database roles. Check whether it can set the common name or other fields you plan to map, control validity periods, and sign certificates for non-human service identities. If the current PKI only issues server or user certificates for a different purpose, plan an internal CA for database clients before you start.

Revocation and rotation process

PostgreSQL checks whether a presented certificate chains to a trusted CA, but it does not remove access on its own when a key is lost or an employee leaves. Decide how a compromised certificate is revoked, whether through short validity periods, a regular rotation schedule or a revocation list your team can check, and confirm that the pg_hba.conf and CA files can be reloaded without an outage. Document who can trigger revocation and how quickly it must take effect.

Roles and privileges stay separate

A valid certificate proves identity, not permission. Mapping a certificate name to a role with pg_ident.conf only decides who may log in as that role; grants, default privileges and superuser use are still managed in PostgreSQL. Confirm who owns role design, how new service identities are approved, and how mapping entries are reviewed when staff change teams.

Audit trail for certificate logins

Confirm that your logging captures which certificate identity connected, from which address and to which database, so that access reviews can tie a session to a specific certificate. Check whether your pooler and application layers preserve that identity or hide it behind a shared service account. Without this link, an access review can show that a role was used but not which certificate or team used it.

How DeployOpen scopes a certificate authentication project

A certificate authentication project starts with an inventory, not with configuration. DeployOpen lists every service account, application, batch job, replication path and administrator who connects to the cluster today, along with the authentication method each one uses, the databases and roles it needs, and who owns its credentials. That inventory decides how many certificate identities are needed, which rules in pg_hba.conf can move to cert and which must stay on a password or directory method for a transition period, and where a connection pooler sits in the path, since its client-facing and server-facing connections may need separate handling. We confirm the inventory with the client's own platform and security owners before anything changes.

Next, DeployOpen reviews the existing certificate authority or designs one if none exists. The client keeps ownership of the root and intermediate keys, the issuance policy, validity periods and revocation approach, and DeployOpen documents those decisions rather than setting them. The written deliverables typically include the pg_ident.conf mapping design, the pg_hba.conf and server TLS changes, a tested rollback procedure that restores password authentication without a database outage, and a renewal runbook covering how certificates are issued, rotated and revoked. Work is fixed-scope and agreed in writing before it starts, so the client can see what is included and what it must provide, such as CA access, a test environment and named approvers. Before committing to a timeline, ask whether the project includes a test cycle against a non-production cluster.

How DeployOpen delivers PostgreSQL certificate authentication

DeployOpen plans, builds and documents certificate authentication for self-hosted PostgreSQL inside your own infrastructure. The work covers your internal CA design, the cert method in pg_hba.conf, clientcert=verify-full settings and pg_ident.conf mappings, with testing and handover to your operations team.

How we scope

  • Written scope lists which services, admins and clusters move from passwords to client certificates.
  • Scope records your CA ownership, certificate lifetimes, renewal process and who approves issuance.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.

How we build

  • We configure the internal CA or integrate with your existing one, based on your key storage rules.
  • We write pg_hba.conf rules using hostssl and the cert method, with clientcert=verify-full where required.
  • We map certificate common names to database roles in pg_ident.conf and keep mappings reviewable.
  • We test each rule with valid, expired, revoked and unknown certificates before any cutover.

How we hand over

  • Deliverables include the CA design, rule set, mapping file, client onboarding steps and rollback plan.
  • Runbooks cover certificate issuance, rotation, revocation and reloading PostgreSQL after changes.
  • Evidence packs record configuration, test results and access decisions for your security and compliance reviews.
  • Your team receives knowledge transfer sessions so administrators can operate the setup independently.

How we support

  • Support covers certificate renewals, CA maintenance and PostgreSQL minor or major version upgrades.
  • Retainers include periodic review of role mappings and revocation handling as services change.
  • Retesting follows any change to pg_hba.conf, pg_ident.conf, TLS settings or the certificate chain.
  • Confirm with your team which connection poolers sit in the path, since they affect how client certificates are presented.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.