Skip to content

Database

Configuring the Database connection

IMPORTANT: The options in this section are set in /etc/sicura/sicura-console.yaml and apply to the Classic Console only, which also accepts them as DB_* environment variables; see Classic Console Environment Variables. The Sicura Console does not read sicura-console.yaml and takes its database connection only from the DB_* environment variables; see Sicura Console Environment Variables.

There is no default database so you must define a PostgreSQL connection string in sicura-console.yaml using one of the following formats:

Option 1 — Connection URL

Put the host, port, and database name in the connection URL itself, and supply the credentials through main.database.options:

main.database: postgres://ip_address:port/database
main.database.options:
 user: user
 password: password

Option 2 — Individual Options

Set main.database to just the postgres:// scheme and supply every connection detail as its own key under main.database.options:

main.database: "postgres://"
main.database.options:
 user: user
 password: password
 host: ip_address
 port: port
 database: database

You can specify additional general and PostgreSQL specific options using main.database.options.

Encrypting the Database Connection

The Console connects to PostgreSQL over TLS. How strictly it checks the server is set by sslmode, and the certificate authority it trusts by sslrootcert:

  • Container image — DB_SSLMODE and DB_SSLROOTCERT
  • sicura-console.yaml — sslmode and sslrootcert under main.database.options

require encrypts the connection but does not check the server's certificate, so it does not protect against a host impersonating the database; it is the default. Set DB_SSLMODE explicitly rather than relying on a default, and use verify-full and point sslrootcert at the certificate authority (CA) that signed the server's certificate to have the Console verify both the certificate and the server's host name:

DB_SSLMODE=verify-full
DB_SSLROOTCERT=/run/secrets/sicura-db-ca

The name in DB_HOST must match the server certificate's subject alternative name. The Reference Deployment with SSL Termination shows a complete verify-full setup.

Set DB_SSLMODE=disable only for a database that does not accept TLS connections.

Certificate Authentication and Additional Connection Settings

IMPORTANT: The settings in this section require Sicura Console 2026.11.0 or later (an image tagged <version>-rails, for example registry.customers.sicura.us/products/sicura-console:<version>-rails). It reads its database connection only from the DB_* environment variables, not from sicura-console.yaml. Earlier releases and the Classic Console support only DB_SSLMODE and DB_SSLROOTCERT.

These settings let the Console authenticate to PostgreSQL with a client certificate instead of a password, check certificates against a revocation list, and enforce a minimum TLS version. Each one applies to all three databases the Console uses: the main database and the job-queue and cache databases.

Environment Variables

Variable Default Purpose
DB_SSLMODE require TLS mode: disable, allow, prefer, require, verify-ca, or verify-full
DB_SSLROOTCERT (none) CA certificate(s) used to verify the server; system uses the operating system's trust store
DB_SSLCERT (none) Client certificate, PEM format
DB_SSLKEY (none) Private key for DB_SSLCERT
DB_SSLPASSWORD (none) Passphrase for an encrypted DB_SSLKEY
DB_SSLCRL (none) Certificate revocation list file used to check the server's certificate
DB_SSLCRLDIR (none) Directory of revocation lists, in the format of OpenSSL's c_rehash
DB_SSL_MIN_PROTOCOL_VERSION (libpq default, TLSv1.2) Lowest TLS version accepted, for example TLSv1.3
DB_CHANNEL_BINDING (libpq default, prefer) For password (SCRAM) authentication only: require refuses a login that is not bound to the TLS channel. Do not set require with a client certificate; certificate logins have no channel binding and are refused
DB_APPLICATION_NAME sicura-console Name the Console reports to the server, for audit logs and pg_stat_activity
DB_PASSWORD_FILE (none) Read the database password from this file instead of DB_PASSWORD
DB_SSLCERT_EXPIRY_WARNING_DAYS 30 Log a warning at startup when the client certificate or a CA certificate in DB_SSLROOTCERT expires within this many days

DB_SSLMODE and DB_APPLICATION_NAME always have a value: when either is unset or empty, the Console uses the default in the table. PostgreSQL's own environment variables for these settings, PGSSLMODE and PGAPPNAME, have no effect on the Console. To have the Console verify the database server, set DB_SSLMODE=verify-full (or verify-ca); setting PGSSLMODE does not change the TLS mode.

The other connection settings, DB_SSLROOTCERT, DB_SSLCERT, DB_SSLKEY, DB_SSLPASSWORD, DB_SSLCRL, DB_SSLCRLDIR, DB_SSL_MIN_PROTOCOL_VERSION, DB_CHANNEL_BINDING, and the password (DB_PASSWORD_FILE or DB_PASSWORD), are not passed to PostgreSQL's client library (libpq) when unset or empty, so libpq's own default applies, including its PG* environment variables.

With a client certificate, DB_PASSWORD can be left unset. Mount the certificate, key, and CA files into the container, for example as Podman or Kubernetes secrets, and point the variables at the mounted paths.

Setting Up Certificate Authentication

The steps below configure a PostgreSQL server to accept the Console only by client certificate. They assume you already have a CA that can issue certificates; the Console does not issue them.

  1. Configure the server for TLS and tell it which CA signs client certificates, in postgresql.conf:

    ssl = on
    ssl_cert_file = '/path/to/server.pem'
    ssl_key_file = '/path/to/server.key'
    ssl_ca_file = '/path/to/ca.pem'
    ssl_min_protocol_version = 'TLSv1.3'
    

    To reject revoked client certificates, also set ssl_crl_file or ssl_crl_dir.

  2. Create a database role for the Console, with no password:

    psql -c "CREATE ROLE sicura_console LOGIN CREATEDB"
    

    CREATEDB lets the Console create its three databases on first start. If you create them yourself, owned by sicura_console, the role needs only LOGIN.

  3. Require a verified client certificate for that role in pg_hba.conf, and map the certificate's common name (CN) to the role in pg_ident.conf:

    # pg_hba.conf
    hostssl  all  sicura_console  10.0.0.0/24  cert  clientcert=verify-full  map=console
    
    # pg_ident.conf
    # MAPNAME  CERTIFICATE-CN        DATABASE-ROLE
    console    console.example.com   sicura_console
    

    Without a map, the certificate's CN must equal the role name. Reload PostgreSQL after editing these files.

  4. Issue the Console a client certificate whose CN is the name in pg_ident.conf, with the clientAuth extended key usage:

    openssl req -new -newkey rsa:4096 -nodes -keyout client.key -out client.csr \
        -subj "/CN=console.example.com"
    # Sign client.csr with your CA, including extendedKeyUsage=clientAuth.
    
  5. Make the key readable by the Console. The Console runs as the sicura-console user, and libpq refuses a key that is readable by anyone else: the key must be owned by that user with mode 0600, or owned by root with mode 0640 or stricter. Look up the user's ID in the image:

    podman run --rm --entrypoint id registry.customers.sicura.us/products/sicura-console:<version>-rails sicura-console
    

    The user ID is not fixed, so check it again after each upgrade; if it changes, the Console refuses to start and names the key file.

    With Podman, set the owner and mode when you mount the key as a secret:

    podman secret create sicura-db-client-key client.key
    podman run ... --secret sicura-db-client-key,uid=<console-uid>,mode=0600 ...
    
  6. Start the Console with the certificate settings and no password:

    DB_HOST=db.example.com
    DB_USER=sicura_console
    DB_SSLMODE=verify-full
    DB_SSLROOTCERT=/run/secrets/sicura-db-ca
    DB_SSLCERT=/run/secrets/sicura-db-client-cert
    DB_SSLKEY=/run/secrets/sicura-db-client-key
    

To confirm the Console is connected by certificate, run this on the server:

psql -c "SELECT a.usename, a.application_name, s.version, s.client_dn
         FROM pg_stat_ssl s JOIN pg_stat_activity a USING (pid)
         WHERE a.application_name = 'sicura-console'"

Each row should show sicura_console, a TLS version, and the client certificate's subject.

Startup Checks

Before connecting, the Console checks the files named by DB_SSLROOTCERT, DB_SSLCERT, DB_SSLKEY, DB_SSLCRL, and DB_SSLCRLDIR. It refuses to start, and logs which variable is wrong and how to fix it, when:

  • a file does not exist or cannot be read by the sicura-console user
  • the key's permissions are looser than libpq allows
  • the client certificate cannot be parsed, has expired, or is not yet valid
  • the client certificate is in DER form rather than PEM; the message gives the openssl x509 -inform der command that converts it
  • the CA bundle or CRL cannot be loaded: it is in DER form (the message gives the openssl x509 -inform der or openssl crl -inform der command that converts it), it is not PEM, or it has a certificate or CRL block that OpenSSL cannot read, which makes libpq load nothing from the file. A CRL file must hold at least one CRL; libpq silently ignores a CRL it cannot load, which would leave revocation checking off
  • every certificate in the CA bundle has expired or is not yet valid
  • every CRL in the CRL file is past its next update or not yet valid; once libpq loads a CRL, OpenSSL refuses every connection while the CA's CRL is out of date

It checks only the files libpq will read: with DB_SSLMODE=disable it checks none of them, and it checks DB_SSLKEY only when DB_SSLCERT is also set.

A client certificate or CA certificate that expires within DB_SSLCERT_EXPIRY_WARNING_DAYS days starts normally but logs a warning that names the certificate and its expiry date. So does a CA bundle that holds an expired CA beside valid ones, since the Console cannot tell which CA signed the server's certificate until it connects. Likewise, a CRL file that holds an out-of-date CRL from one CA beside current CRLs from others logs a warning, and an out-of-date CRL beside a newer one from the same CA is ignored, as OpenSSL uses the newer one. A CRL logs a warning in the last day before its next update.

These checks run only when the Console starts. A CRL is usually reissued every few days, and one that lapses while the Console runs makes every new database connection fail, so monitor CRL refreshes separately.

Rotating the Client Certificate

The Console reads the certificate and key each time it opens a database connection, so where both files can be swapped together while the container runs (a Kubernetes secret mounted without subPath), a renewed certificate takes effect without a restart:

  1. Issue a new certificate with the same CN (and the same pg_ident.conf mapping) before the old one expires.
  2. Replace the certificate and key files. Podman secrets cannot change under a running container, so with Podman recreate the secrets and restart the container.
  3. Confirm with the pg_stat_ssl query above that new connections carry the new certificate's subject.

Connections already open stay authenticated until they close, even after the old certificate expires, because PostgreSQL checks the certificate only when a connection starts. Restart the Console to move every connection to the new certificate at once. The startup expiry warning is checked only when the Console starts, so monitor the certificate's expiry date separately as well.

Troubleshooting

Message Cause
connection requires a valid client certificate The Console sent no client certificate: DB_SSLCERT or DB_SSLKEY is unset
certificate authentication failed for user The certificate's CN does not match the role, and no pg_ident.conf mapping covers it
certificate revoked The client certificate is listed in the server's revocation list
certificate verify failed The server's certificate is not signed by the CA in DB_SSLROOTCERT
server certificate for "..." does not match host name DB_HOST is not a name in the server certificate's subject alternative names
server does not support SSL, but SSL was required The server has ssl = off; enable TLS on the server, or set DB_SSLMODE=disable