Kerberos Authentication for Databases 1.23.0+¶
CxReports can connect to Microsoft SQL Server and PostgreSQL with Kerberos instead of a database login and password. The connection authenticates as a domain account, and no password is stored in the connection string.
The CxReports and Data Agent Docker images include the Kerberos client. No sidecar container is required, and the Data Agent is needed only if you already use it to reach the database.
Scope
This page covers connections from CxReports to your databases. It is not related to how users sign in to CxReports; for that, see Single Sign-On.
Setup¶
Kerberos is configured on the container that opens the database connection: the CxReports application, or the Data Agent for databases reached through an agent. The setup is the same for both.
1. Mount the Kerberos configuration and the keytab¶
Mount your krb5.conf and the keytab of the account CxReports should connect as, and point the KRB5_CLIENT_KTNAME environment variable at the keytab:
services:
app:
image: codaxy/cx-reports:latest # or codaxy/cx-reports-data-agent:latest
environment:
KRB5_CLIENT_KTNAME: /etc/krb5/cxreports.keytab
volumes:
- ./krb5.conf:/etc/krb5.conf:ro
- ./cxreports.keytab:/etc/krb5/cxreports.keytab:ro
# ... the rest of the service definition
A minimal krb5.conf looks like this. Replace the realm (upper case) and the host names with your own:
[libdefaults]
default_realm = CORP.EXAMPLE.COM
rdns = false
[realms]
CORP.EXAMPLE.COM = {
kdc = dc01.corp.example.com
kdc = dc02.corp.example.com
}
[domain_realm]
.corp.example.com = CORP.EXAMPLE.COM
corp.example.com = CORP.EXAMPLE.COM
The keytab is a binary file that holds the keys of one account. klist -k -e cxreports.keytab lists what it contains:
Keytab name: FILE:cxreports.keytab
KVNO Principal
---- --------------------------------------------------------------
2 [email protected] (aes256-cts-hmac-sha1-96)
2 [email protected] (aes128-cts-hmac-sha1-96)
A ticket is obtained from the keytab on the first connection, and a new one is obtained when it expires, so there is no need to run kinit or to schedule a renewal.
The keytab must be readable by the user the container runs as: the non-root user dotnet in the CxReports image, root in the Data Agent image.
2. Use a connection string without a password¶
Register the database in the Admin application under Connections → Databases, or in the Data Agent's ConnectionStrings configuration, using the server's fully qualified domain name:
Integrated Security=truetells CxReports to sign in with the Kerberos account instead of a SQL login. It replacesUser IdandPassword, which are ignored when it is set.TrustServerCertificate=trueis optional. The connection is encrypted by default and the SQL Server certificate is validated; add this flag to skip the validation when the certificate is self-signed or issued by an authority the container does not trust.
Select Test connection to verify the setup.
Alternative: Ticket Cache from a Sidecar¶
The keytab setup above is the recommended one: it has no extra moving parts, and CxReports gets a new ticket by itself whenever it needs one.
Use a sidecar only when the keytab must not be available to the CxReports container, or when your platform already provides a Kerberos ticket cache. The sidecar keeps a ticket cache up to date on a shared volume, and CxReports reads it through the KRB5CCNAME environment variable instead of KRB5_CLIENT_KTNAME:
services:
app:
image: codaxy/cx-reports:latest
environment:
KRB5CCNAME: FILE:/krb5cc/ccache
volumes:
- ./krb5.conf:/etc/krb5.conf:ro
- krb5cc:/krb5cc:ro
# ... the rest of the service definition
kerberos:
image: codaxy/cx-reports:latest
user: root
restart: always
entrypoint:
- sh
- -c
- |
while true; do
kinit -c FILE:/krb5cc/ccache.tmp -k -t /etc/krb5/cxreports.keytab [email protected] \
&& chown dotnet /krb5cc/ccache.tmp \
&& mv /krb5cc/ccache.tmp /krb5cc/ccache
sleep 3600
done
volumes:
- ./krb5.conf:/etc/krb5.conf:ro
- ./cxreports.keytab:/etc/krb5/cxreports.keytab:ro
- krb5cc:/krb5cc
volumes:
krb5cc:
The example reuses the CxReports image for the sidecar because it already contains kinit; any image with the Kerberos client tools works.
Keep in mind:
- The sidecar still needs the keytab. The credential is moved out of the CxReports container, not removed.
- The ticket cache must be readable by the
dotnetuser of the CxReports container, which is why the sidecar runs asrootand hands the file over withchown. - The refresh interval (
sleep 3600) must be shorter than the ticket lifetime. If the sidecar stops, database connections fail once the ticket expires. - The connection strings are the same as in step 2.
Data Agent on Windows¶
A Data Agent installed with the Windows installer on a domain-joined machine needs no Kerberos configuration. It authenticates as the account the CxReports DataAgent Windows service runs under. By default this is Local System, which is the computer account (DOMAIN\MACHINENAME$) on the network.
Changing the service account
The agent stores its key in the profile of the account it runs under. After changing the service account, the agent generates a new key, which must be registered again in Connections → Data Agents.
Troubleshooting¶
The Kerberos tools are available inside the container, for example docker compose exec app klist.
| Check | Command |
|---|---|
| Show the current ticket | klist |
| Show the principals in the keytab | klist -k /etc/krb5/cxreports.keytab |
| Get a ticket from the keytab manually | kinit -k -t /etc/krb5/cxreports.keytab [email protected] |
| Request a ticket for the database server | kvno MSSQLSvc/sql01.corp.example.com:1433 or kvno postgres/pg01.corp.example.com |
Set KRB5_TRACE=/dev/stderr on the container to get a detailed Kerberos trace in the container log.
| Symptom | Likely cause |
|---|---|
Cannot find KDC for realm / Cannot contact any KDC |
krb5.conf is not mounted, or the domain controller is not reachable from the container |
Clock skew too great |
The host clock is out of sync with the domain controller |
Preauthentication failed / Key table entry not found |
The keytab is out of date or was created for a different account |
kvno fails with Server not found in Kerberos database |
The connection string uses an IP address, an alias or a short name instead of the server's fully qualified domain name, or the server has no service principal name |
SQL Server: The target principal name is incorrect. Cannot generate SSPI context. |
No ticket could be obtained (keytab not mounted, not readable, or KRB5_CLIENT_KTNAME not set), or Server is an IP address or a name that does not match the server's service principal name |
SQL Server: Certificate failed chain validation during the pre-login handshake |
The SQL Server certificate is not trusted by the container; see TrustServerCertificate above |
SQL Server: Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication. |
The ticket was obtained and sent, but the SQL Server could not validate it or map it to a domain login |
PostgreSQL: Unable to authenticate with GSS: received UnknownCredentials |
No ticket could be obtained: the keytab is not mounted or not readable, or KRB5_CLIENT_KTNAME is not set |
PostgreSQL: Unable to authenticate with GSS: received GenericFailure |
The Host value is an IP address or a short name instead of the fully qualified domain name |
PostgreSQL: No password has been provided but the backend requires one |
Username is missing from the connection string, or the server has no gss rule in pg_hba.conf matching this user, database and client address |
PostgreSQL: GSSAPI authentication failed for user "[email protected]" |
Username is missing from the connection string, so the full principal name was used as the role name |
| The login is rejected by the database | Kerberos worked; the account has no login, role or permissions on the database server |