PostgreSQL Kerberos single sign-on with Active Directory: when it fits
Choose GSSAPI when your staff already sign in to Windows and Linux through a Kerberos realm and you want database logins without passwords stored or checked anywhere. The GSSAPI authentication method in pg_hba.conf lets PostgreSQL accept Kerberos service tickets from clients, so a user who holds a valid ticket can connect without typing a database password. Four pieces make this work: PostgreSQL, which runs the GSSAPI check; the key distribution center (KDC), which is the Kerberos service inside Active Directory Domain Services or FreeIPA; a keytab, which holds the database server's service principal key and lets PostgreSQL verify tickets; and clients, which obtain tickets from the KDC when a user signs in.
Kerberos is usually the better fit than the LDAP password method when users already hold Kerberos tickets and you want to avoid a bind that sends a password, even over LDAPS, to a directory on every login. With LDAP, the database still depends on directory passwords and on the directory being reachable at connect time. With Kerberos, the database trusts the ticket issued by the KDC, so the password check stays in the directory. Kerberos is a poorer fit when clients cannot obtain tickets (for example, many non-Kerberos application runtimes or containers without a domain identity), so confirm client support before you commit.
Plan the licensing separately. PostgreSQL is released under the PostgreSQL License, a permissive license similar to BSD or MIT. FreeIPA is licensed under GPL-3.0-or-later, and it is a community project with no paid edition of its own. Active Directory is not open source: it is a Windows Server role, so you need Windows Server licenses, including Client Access Licenses for each user or device that accesses the server. Ask your Microsoft licensing contact to confirm the core count and access license position for the domain controllers you plan to use, because the cost depends on your agreement and region, not on this database project.
How a Kerberos ticket reaches a PostgreSQL session
The flow starts with the client asking the KDC for a ticket-granting ticket, then requesting a service ticket for the postgres service principal. The client presents that ticket to the PostgreSQL server, which decrypts it with the service keytab, so the keytab must match the principal registered in Active Directory or FreeIPA. PostgreSQL then passes the authenticated principal through pg_ident.conf to a database role. Check that the three parties sit in the trust boundaries shown, and that the realm and host names match exactly, since a mismatch fails at the ticket step.
Ticket flow from client to KDC to PostgreSQL, with the keytab and identity map on the database host.
Directory choices: Active Directory, FreeIPA or a standalone KDC
This table compares three places to hold the Kerberos realm that PostgreSQL will trust for GSSAPI login: an existing Active Directory forest, FreeIPA, and a standalone MIT Kerberos KDC. Read each row against your own identity estate, since the right choice usually depends on who already manages principals and how many Linux hosts must join. The main takeaway is that existing Active Directory is rarely worth replacing for a PostgreSQL project, while a standalone KDC is the option that asks the most of your team.
| Decision factor | Active Directory as realm | FreeIPA realm | Standalone MIT KDC |
|---|---|---|---|
| Realm naming | Uses the existing AD DNS domain, so service principals follow the forest's naming | Needs its own DNS domain that does not overlap with the AD forest if a trust is planned | Any realm name you choose, managed entirely by your team |
| Who manages principals | AD administrators create service accounts and map SPNs | IdM administrators manage principals, keytabs and host enrollment | Your team manages every principal and keytab by hand or with scripts |
| Linux host join effort | Linux hosts must be configured as Kerberos clients or use third-party tools, per Microsoft's comparison | Hosts enroll through the IdM client tooling with SSSD, so enrollment is the most built-in of the three | Every host needs manual krb5.conf and keytab work |
| Licensing facts | Windows Server 2025 is licensed per core with a 16-core minimum per server, plus client access licenses for each user or device | Licensed under GPL-3.0-or-later with no paid edition of its own, per the project's COPYING file | MIT Kerberos is open source with no license fee; staffing for operation is the main cost |
| Trust with AD users | Native, since the domain already holds the users | Optional cross-forest trust with AD, supported on Windows Server 2008 R2 or later | Cross-realm trust must be set up manually and maintained by hand |
| Best fit | Your users, service accounts and Windows estate already live in one AD forest | Most Linux hosts and PostgreSQL servers need a central realm and you accept a separate identity system | You need a minimal, tightly scoped realm and have Kerberos operations skills in-house |
| Confirm before you choose | Forest and functional level, whether the PostgreSQL hosts can reach domain controllers, and who owns service account policy | Replica count, DNS design and whether AD users need Linux access through a trust | Who will patch and back up the KDC and how key rotation is run |
Setting up GSSAPI login: the build sequence
This sequence takes a PostgreSQL host from a Kerberos service identity in Active Directory or FreeIPA to a working passwordless login, with each step closed by a check the team can run and record. Done in order, it leaves the server, the keytab, the authentication rules and the client tickets consistent with one another.
Confirm the realm, DNS and time sources
Before creating any principal, the directory team confirms the Kerberos realm name, the domain controllers or FreeIPA servers that act as the KDC, and that the PostgreSQL host resolves its own fully qualified name in the forward and reverse directions. Kerberos is sensitive to clock skew and name mismatches, so the host and the KDCs should sync to the same time source. Confirm the realm and time configuration with the directory administrator in writing. Done when
kinitagainst a test account succeeds from the PostgreSQL host andklistshows a ticket for the expected realm.Create the service principal for the PostgreSQL host
A directory administrator creates a service principal for the database host, typically in the form postgres/fully.qualified.hostname, and binds it to a dedicated service account in Active Directory or to a host principal in FreeIPA. Use one principal per PostgreSQL host, and record the exact name, because pg_ident.conf and the client connection string must match it character for character. Confirm the principal exists by listing it in the directory tool and by requesting a ticket for it from a client machine with
kinitas a test user. Done when the principal appears in the directory and a client can obtain a service ticket for it.Generate and protect the keytab
The directory administrator exports the service principal's keys to a keytab file, then copies it to the database server. The file should be readable only by the operating system account that runs PostgreSQL, usually with mode 0600 and the correct owner. Store a copy under your change control with the exported key version recorded, because rotating the account password or the key invalidates existing keytabs. Verify the keytab contents with
klist -kon the server and confirm it lists the expected principal and key version. Done when the keytab lists the service principal and an unprivileged account cannot read it.Point PostgreSQL at the keytab
Set krb_server_keyfile in postgresql.conf to the absolute path of the keytab, and set krb_realm or include_realm settings only if your naming needs them, reviewing the current parameter list in the PostgreSQL documentation for your major version. Reload or restart PostgreSQL according to the parameter's context, then check the server log for errors about the keytab or missing principal. Confirm the server starts cleanly and that the setting shows the expected path in
SHOW krb_server_keyfile;. Done when the server log shows no keytab errors after restart.Add gss entries to pg_hba.conf
Add
hostgssencorhostgsslines to pg_hba.conf for the networks and databases that should accept Kerberos logins, placing them above any broader password or trust rules. Useinclude_realm=1or a narrowmap=name when you want the principal mapped through pg_ident.conf, and keep password and trust entries for a documented break-glass path only. Validate the file with the team's review process, reload PostgreSQL, and confirm the rule takes effect withSELECT * FROM pg_hba_file_rules;. Done when the rules show the gss entries in the intended order and no unintended network matches them.Write pg_ident.conf maps from principal to role
Create a map in pg_ident.conf that translates each Kerberos principal, such as an administrator or application service account, to an existing PostgreSQL role. Every mapped role must already exist and should carry only the privileges its users need, so review the roles before adding mappings. Reference the map name from pg_hba.conf and reload PostgreSQL. Verify by logging in as a mapped user and by confirming a principal without a mapping is refused. Done when the mapped user connects as the intended role and the unmapped principal receives an authentication failure.
Configure clients with valid tickets and test failures
On each client, install the Kerberos client packages, set the realm and KDC in krb5.conf, and run
kinitas the user, then confirm the ticket withklist. Connect with psql or the application driver using gssencmode and host settings that match the server, and confirm the session reports the expected role. Then test the negative cases: an expired or absent ticket, a wrong host name, and an unmapped principal should each fail with a logged authentication error. Record these results as the acceptance evidence. Done when valid tickets connect, and each failure case is refused and appears in the server log.
How pg_ident.conf maps Kerberos principals to database roles
A Kerberos login only succeeds if the authenticated principal maps to a PostgreSQL role that already exists. The principal carries its realm, so alice@EXAMPLE.COM is not the same identity as a bare alice. PostgreSQL decides how to translate the principal through the map option on the GSSAPI line in pg_hba.conf, which points to a user name map in pg_ident.conf. Two settings shape the result: whether the realm is stripped before comparison (the include_realm option controls whether the realm is kept in the name PostgreSQL compares), and whether the mapping is an exact match or a regular expression. Confirm the exact option names and their defaults against the current PostgreSQL authentication documentation for your major version before you write the rules, because the behavior is easy to assume incorrectly.
The main risk is a regular expression that matches more principals than intended. A pattern such as /^(.*)@EXAMPLE\.COM$ maps every account in the realm, including service principals, former employees who still hold valid tickets until their Active Directory accounts are disabled, and accounts from a trusted realm if the pattern is loose. Each mapping line should name one realm, one principal pattern and one target role, with anchored expressions and no catch-all rule. Give application and batch principals their own mapping to dedicated login roles rather than to a shared administrative role. Keep the map file under change control, and review each line against the roles in your least privilege design, since a mapping grants whatever the target role already holds.
Before rollout, test each mapping with a principal you control and with a principal you expect to be refused. Check that the database role exists, that the role has no superuser or broad default privileges it does not need, and that a principal from an unexpected realm is rejected. Reload the configuration after each change and record the mapping in your access review, so the list of permitted identities is a document that auditors and your own team can read. Where the AD or FreeIPA side changes, such as a renamed account or a new trust, the mapping must change with it. Plan a recurring review of the map file alongside your account recertification process.
GSSAPI encryption and what it does not protect
GSSAPI encryption protects the connection between a client and PostgreSQL, but only where every hop supports it and the rules require it. The cards below cover the pg_hba.conf rule, how it differs from TLS, client and pooler support, session verification, and the data that stays unencrypted.
Matching encrypted connections with hostgssenc
A hostgssenc line in pg_hba.conf matches only connections that negotiated GSSAPI encryption, and hostnogssenc matches the rest. Use it to require encryption for application and admin subnets, and keep a separate, narrow rule for any clients that cannot yet encrypt. The first matching line wins, so check rule order before you reload. Read the authentication methods reference for the exact option syntax in your version.
GSSAPI encryption compared with TLS
GSSAPI encryption uses keys established during the Kerberos exchange, so there are no server certificates to issue, chain, or rotate for it. TLS instead relies on a certificate chain that clients validate against a trusted CA. The two are alternatives negotiated per connection, so decide which one protects each path. Test how each client behaves when the encrypted option is unavailable, because the answer differs between drivers.
Client library support
Encryption works only when the client library was built with GSSAPI support and requests it. Confirm that libpq, the JDBC driver, your Python and Go drivers, and any reporting tools in use can negotiate it, and check the gssencmode setting each one exposes. Set the server to require encryption only after every client in your inventory passes a test login, because a client that cannot encrypt will be refused.
Poolers and proxies in the path
A pooler such as PgBouncer accepts the client connection and opens its own connection to PostgreSQL, so the path has two separate hops, each with its own encryption and authentication. Decide whether the client to pooler hop, the pooler to server hop, or both must be GSSAPI-encrypted, and confirm the pooler supports the Kerberos setup you chose. Also confirm which service principal the pooler uses on the server side, since that identity is what the server authenticates.
PgBouncer project siteConfirming encryption on each session
The pg_stat_gssapi view reports, for each backend, whether the session authenticated with GSSAPI and whether its traffic was encrypted. Use it in an acceptance test that connects through every client path and then reads the view, so the result is measured rather than assumed. Check the column list in the documentation for your PostgreSQL version. Ask your monitoring team to alert on unencrypted sessions from subnets that are meant to be encrypted only.
Encryption at rest is a separate control
GSSAPI encryption protects data in transit only. Data files, WAL segments, base backups and logical dumps remain readable to anyone with disk or backup access unless you add a separate control. Plan filesystem or block encryption, encrypted backups and key custody as their own work, covered in the encryption at rest topic. Confirm with your security team who holds the keys and how they are rotated.
Running Kerberos login after go-live
Database administrators own what PostgreSQL does with a Kerberos identity once the ticket is accepted. Their changes are the ones users notice most often: a role map that no longer matches a principal, or a reload that was never applied. Most of this work is routine, but it is easy to make a change in pg_ident.conf and assume it is live when the server has not re-read the file. The team should treat role maps and pg_hba.conf entries as versioned configuration with a named reviewer.
- Role maps: Keep every
mapentry inpg_ident.conftied to a documented owner, and confirm that each mapped database role still exists and has only the privileges it needs. - Reloading configuration: Confirm that the team knows which change requires a reload and which requires a restart, and that the reload is tested on a non-production server first.
- Keytab rotation: Agree on how the PostgreSQL service keytab is replaced, when the old key version is retired, and how a failed rotation is rolled back.
- Failure checks: Confirm a test login from a domain-joined client after every change, and record the result.
- Replica configuration: Confirm that standby servers receive the same authentication configuration as the primary.
Before handover, confirm that the team can name every role map entry, can reload configuration without interrupting active sessions, and has rehearsed a keytab replacement in a test environment.
Directory administrators own the identities behind the login: the service principal, its keytab, the accounts that users and services sign in with, and the directory servers that answer Kerberos requests. If the directory is a FreeIPA deployment, its replica topology and backups also become part of the database's availability. A deleted or disabled account, or a restored backup that is out of date, can stop logins across several databases at once, so changes need the same review as database changes.
- Principal lifecycle: Define how service and user principals are created, renamed, disabled and removed, and who approves each step.
- Replica layout: Follow the FreeIPA deployment recommendations, which advise at least two to three replicas in each datacenter, and confirm the replication agreements stay within the documented limit of four per replica.
- Backups: Confirm the team uses
ipa-backup, knows the difference between full and data-only backups, and has testedipa-restorein an isolated environment. - Restore caution: Confirm the team knows the FreeIPA warning that restoring an outdated backup into an active replica topology can break replication, and has a documented procedure for that case.
- Certificate and CRL duties: Confirm which server handles certificate renewal and CRL publication, since the FreeIPA backup documentation states the first server does this by default.
Before handover, confirm that every principal used by PostgreSQL has a named owner, that a restore has been rehearsed, and that the topology matches the recommended replica count.
The security team does not change the login path day to day, but it is accountable for whether the design can be shown to work. It needs evidence that Kerberos is the authentication method in use, that only approved principals map to database roles, and that the people with access still need it. Those answers come from PostgreSQL logs, directory records and periodic reviews, and they should be gathered in a form an auditor can follow. Plan the evidence before the first audit request arrives, not after.
- Audit evidence: Confirm that connection logging captures the authenticated identity for each session, and that logs are retained and protected on a schedule the security team sets.
- Access reviews: Schedule regular reviews of role map entries, directory group membership and the accounts that hold database roles, with a named reviewer and a record of each decision.
- Configuration baseline: Keep a copy of the approved
pg_hba.conf,pg_ident.confand GSSAPI settings, and compare running configuration against it. - Patch tracking: Track FreeIPA release notes and PostgreSQL minor releases, since security fixes arrive in both, and confirm who approves each update.
- Control mapping: Map each evidence source to the control it supports, using control titles from the framework your auditor uses.
Before handover, confirm that the security team can produce a list of every Kerberos-mapped role, its approving owner and its last review date, and can show a complete login record for one test user.
Limits to confirm in your environment
Kerberos single sign-on for PostgreSQL depends on the client stack, the Windows Server version, the Active Directory licensing model and the directory layout around it. Each card below is a limit to confirm with your vendors or in your own environment before the design is fixed.
Client driver and OS GSSAPI support
Confirm that your client libraries, drivers and operating systems support GSSAPI authentication and GSSAPI encryption in the versions you run. Application connection pools and middleware sit in the path too, so test each client type against a real service ticket rather than assuming support from the database version alone. Record the Kerberos library versions on every client image.
Auth methods docsWindows Server version and lifecycle
Confirm which domain controller version your forest runs and its support dates before you design around it. Windows Server 2025 is the current release, while Windows Server 2022 mainstream support has already ended, so an extended support date matters for long-lived services. Ask your Microsoft account team or licensing partner to confirm the dates that apply to your agreement.
- Extended support ends
- November 15, 2034
Per-core licensing and client access licenses
Domain controller licensing is per core, with a minimum number of cores per server, and every user or device that accesses the server needs a client access license. Count the domain controllers you need per site, the cores on each, and the users and devices that authenticate. Confirm regional pricing and any pay-as-you-go option with your reseller, since list prices vary by region.
Windows Server pricingCross-forest trust DNS overlap rule
If FreeIPA must trust an Active Directory forest, the IPA DNS domain cannot overlap with any domain in the AD forest. Check the DNS namespace of every AD domain and plan the IPA domain name before installation, since changing it later is disruptive. Confirm that the forest functional level and trust setup match the FreeIPA version you deploy.
FreeIPA Trusts pageNo automatic role or password policy
PostgreSQL does not create database roles for Kerberos users. Each principal must map to an existing role through pg_ident.conf, and that role must have the privileges the user needs. Password policy, expiry and lockout are handled by the directory, so confirm how Kerberos ticket lifetime, password changes and account disablement reach the database sessions you open.
Keytab handling and rotation
Each service principal and its keytab file must be protected on the database host, readable only by the postgres service account. Confirm how your directory handles keytab generation, key version numbers after password resets and the rotation schedule that your change process allows. Test a restart after rotation before changing the production keytab.
Questions buyers ask before hiring help with Kerberos login
What drives the cost of a Kerberos login project for PostgreSQL?
The cost follows the number of moving parts: how mature your directory is, how many PostgreSQL servers and client hosts need the change, how complex the mapping from Kerberos principals to database roles is, and how many operating system builds and client stacks must be tested. A directory that is already clean, with documented service accounts and working DNS, costs less to integrate than one with stale objects and inconsistent naming. Each additional client type, such as psql on Linux, JDBC on Windows or a pooler in the path, adds test cases. Ask any provider for a written scope that lists each server, client family and mapping rule, and ask which items are one-time work and which recur, such as keytab rotation reviews or retesting after OS upgrades.
How long does a PostgreSQL Kerberos integration usually take?
No duration is fixed by the vendor documentation, so the timeline depends on your environment. The largest variables are how quickly your directory team can create service principals and keytabs, how many change windows you can use, and how much testing is required across client builds. Ask for a schedule that separates a test realm build, a staging rollout, and a production cutover, and that names the approvals each stage needs. A provider should also state what happens if a change window is missed.
What do we need to provide before work starts?
Plan for administrative access to the domain controllers or FreeIPA servers, permission to create service principals and export keytabs, and a named owner for DNS records and time synchronization. You will also need a test realm or staging domain that is separate from production, so that the first logins and failure cases can be checked without affecting users. Confirm change windows in advance, because a keytab change on a live database affects every client that holds a ticket for that service. Request a written list of these prerequisites in the scope, with the person responsible for each one.
Can our own team set this up without outside help?
Yes, if your team already runs Active Directory or FreeIPA, manages Linux hosts with Kerberos, and has experience with PostgreSQL authentication. The work involves creating the service principal, generating and protecting the keytab, setting krb_server_keyfile, writing pg_hba.conf and pg_ident.conf rules, and configuring clients. Teams without recent Kerberos experience often underestimate testing across client builds and the failure cases when the KDC is unreachable. A useful test is whether your team can explain how a ticket reaches the server and how the mapping produces a role name. If not, a partner can build the design and hand over runbooks, or your team can own it with a short advisory engagement.
Does Kerberos on PostgreSQL work with Active Directory if we have Linux servers?
Active Directory can serve as the Kerberos realm for Linux hosts. Microsoft's comparison notes that Linux machines need third-party tools or must be configured to authenticate against Active Directory as a Kerberos realm, so the Linux side needs deliberate setup. FreeIPA is an alternative when you want a Linux-native identity service, and FreeIPA can establish a cross-forest trust with an Active Directory domain so AD users can reach Linux resources. The IPA domain must use a DNS name that does not overlap with any AD forest domain. Confirm with your directory team which model fits your ownership and licensing constraints before choosing.
What licensing costs should we plan for in the directory?
The PostgreSQL side is open source under the PostgreSQL License, so the database itself has no license fee. Directory costs depend on your choice. Microsoft's Windows Server 2025 pricing page says the product is licensed per core with a 16-core minimum per server and requires Client Access Licenses for each user or device, and it lists a suggested price of 1,176 US dollars for Standard and 6,771 US dollars for Datacenter for 16 core licenses, noting that prices vary by region. FreeIPA is licensed under GPL-3.0-or-later and has no paid edition of its own. Ask your reseller or Microsoft agreement holder to confirm current pricing for your region and edition.
What does the engagement cover, and what happens after handover?
A well-defined engagement covers the directory design decisions, service principal and keytab creation, the pg_hba.conf and pg_ident.conf rules, client configuration, GSSAPI encryption settings, a test matrix across the operating systems and clients you use, and written runbooks for keytab rotation and recovery. After handover, recurring work includes rotating keytabs on your schedule, retesting after operating system or PostgreSQL upgrades, and reviewing mappings when people change roles. Ask whether support or a retainer is available for these tasks, and what is excluded from a fixed-scope engagement.
What risks should we ask a provider to address in the scope?
The main risks are a KDC outage that blocks all logins, keytab exposure that allows impersonation, mapping errors that grant the wrong database role, and clock skew that breaks ticket validation. Ask how the design provides a fallback path for administrators, how keytabs are stored and their permissions set, how mappings are tested, and how time synchronization is monitored. Also ask whether GSSAPI encryption is enabled for connections that carry sensitive data, and how the team will verify it. Request these items as named deliverables with acceptance tests, not as general statements.
How DeployOpen scopes and delivers Kerberos login
DeployOpen plans, implements, hardens and documents self-hosted PostgreSQL inside the client's own infrastructure, including the Kerberos login path described on this page. DeployOpen is a Chainscore Labs company. Work runs in the client's data centers, cloud accounts or air-gapped networks, so the directory, the key distribution center, the PostgreSQL servers and the client machines stay under the client's control. The engagement typically covers the decisions that determine whether GSSAPI login works: which directory holds the principals (Active Directory or FreeIPA), how service principals and keytabs are issued and rotated, how pg_ident.conf maps Kerberos principals to database roles, and how client libraries are configured and tested against each server.
Engagements are fixed-scope. Before work starts, the written scope names the directory and realm, the PostgreSQL versions and hosts in scope, the client platforms that must sign in, the verification tests, and the handover documents. Deliverables and timelines are agreed in the same written document, and any change to them is handled as a written change. Ask any provider for the list of items excluded from the quote, such as directory redesign, Windows Server licensing, DNS clean-up or changes to application code, because those drive cost and schedule more than the database work does. A quote follows from that written scope; DeployOpen does not publish a price list.
Ongoing support, keytab rotation reviews, upgrades and continuous testing are available as retainers, which suit the recurring parts of this design. DeployOpen prepares systems, configuration and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies make those determinations, so the handover should include the configuration records, mapping files and test results an assessor will ask for, and the client should confirm with its assessor which evidence they expect.

