Skip to content

Security Model

Mohammad Rasoul Kazemi edited this page Nov 29, 2026 · 4 revisions

Security Model

This page summarises how KingresDB authenticates users and servers, what protects secrets, which checks keep a user database from taking over the privileged service role, and what the ledger does and does not guarantee. It states the design as the repository documents and the code have it; it is not a certification. The first release, 0.1.0, was published on 2026-11-28; the limits are on Limitations and Known Issues. To report a vulnerability, read SECURITY.md.

Accounts and roles

  • A panel account is a PostgreSQL role, authenticated by PostgreSQL. There is no separate user store (ADR 0015). Cluster permissions are membership in four built-in roles with the hierarchy kingres_admin > kingres_ops > kingres_readonly > kingres_stats.
  • Roles are synchronised to every server with their SCRAM-SHA-256 verifiers, never with plain passwords. Passwords reach PostgreSQL as verifiers computed in kingresd.
  • LDAP and OIDC are not supported in the first release. LDAP, GSSAPI and PAM authentication are designed by phase 16 and not built (see Status and Roadmap).
  • Every administrative action through the REST API is written to an audit log; the audit file and the kingresd log never contain statement text, passwords or tokens.

The REST API

Every operation passes one guard, in this order: node-state gating (while uninitialized only /healthz, /readyz and /setup/* work), a cross-site check, a rate limit for operations without a session, authentication (a bearer token, a session cookie, or the one-time setup token), a CSRF check for cookie sessions on state-changing requests, the role check against x-required-role in the contract, and validation of query parameters. The minimum role of each operation comes from a table generated from openapi.yaml (contract 0.34.0). Login attempts are rate limited per client address and per user name. Security headers are set on every response, and the console is tested under a content security policy.

/metrics needs a stats-role session token or the bearer token set in metrics-token.

The setup token

The first setup of a node needs a one-time setup token written to <data-dir>/setup-token (owner-only, mode 0600; it exists only while the node is uninitialized); only the file name is logged. Setup from another machine is refused unless allow-remote-setup is set (default false), and the token is still required. Failed setup-token attempts are rate limited and are audit events. To add a server, the cluster needs the setup token of the new node and the SHA-256 fingerprint of the new node's self-signed internal certificate (sent as X-Kingres-Pin-Sha256), so the leader talks to the node it meant to add. See Cluster Setup and Configuration.

TLS defaults

Channel Default How to change
REST API and console (listen) Plain HTTP on 127.0.0.1:8091 tls-cert-file and tls-key-file (both or neither) turn on HTTPS and the Strict-Transport-Security header. For another address use TLS or a TLS-terminating proxy
Internal API between servers (internal-listen) Off until set; when on, a separate listener with TLS 1.3 and mutual TLS under the cluster certificate authority Not optional once on
PostgreSQL instances ssl = on (TLS 1.3, the server certificate, ssl_ca_file the cluster CA, ssl_crl_file the revocation list); between servers the generated pg_hba.conf takes a certificate rule first, and the sharding connections use sslmode=verify-full Network login of clients is refused until rules are added on the network access page
Ledger publication listener Off; when on, plain HTTP and no authentication ledger-publication-tls-cert and ledger-publication-tls-key
Table and database transfers Off (dataTransfer.enabled); they need TLS The cluster setting
Anchoring Outgoing requests reach exactly the configured host and port, follow no redirect and use no proxy The target configuration

The container port note

The container image listens on 0.0.0.0:8091 over plain HTTP and accepts setup from other machines (KINGRES_ALLOW_REMOTE_SETUP=true), guarded only by the setup token, because a published port reaches kingresd from the Docker bridge and not from loopback. Its database port 5432 listens on 0.0.0.0 too. Publishing the port with docker run -p 8091:8091 on a network that is not trusted sends the setup token and the first password in clear text. Publish both ports on 127.0.0.1, as the compose file does, or on a private network only, or put TLS in front (install guide).

Servers trust each other by certificates

Creating a cluster creates a certificate authority for it (ECDSA P-256). Each server gets a certificate; certificates renew automatically and can be revoked (the authority itself is not rotated). Private keys never leave the server that generated them. Server-to-server traffic uses an internal HTTP API with mutual TLS on its own port. That API authenticates by client certificate only, checks the revocation list, authorises by a fixed table of which calls a peer may make, and never executes a path, a program name or SQL text taken from a request, except one statement-execution call that only the leader may make and that is logged with its length and hash. A forwarded request carries the proof (fwdproof) that the forwarding server holds a session of the user it names. Connections between servers for sharding use the server certificate and no password.

The trust model is stated: every server of a cluster is fully trusted by every other. A server that is not the leader cannot call the leader-only calls, a removed server's certificate is revoked, but someone who controls one server's key can act as any role on all of them.

The certificate authority key and its escrow

The key of the certificate authority (pki/ca.key, with pki/revoked.json) is held by the manager leader. After a failover of the map group the new leader can issue, renew and revoke certificates only if it has the key:

  • Escrow, off by default. An administrator can switch the escrow on and off (getCaEscrow, setCaEscrow, rotateCaEscrow; the Certificate authority tab of the Security page). With it on, the leader seals the CA key and the revocation list to every server that hosts a ready standby of the map group and keeps the copies current (after every revocation, when the standbys change, and at least every 6 hours). A new leader opens its own copy and goes on without an alert. A server that holds a copy can become the authority, so switch it on only when those servers are as trusted as the leader; a removed server that held a copy and cannot be reached must be treated as knowing the key. Rotation makes new escrow keys and reseals the copies; it does not change the CA key.
  • Without the escrow the new leader raises the critical alert certificateAuthorityUnavailable until the operator restores pki/ca.key and pki/revoked.json from a backup of the old leader. There is no automated backup of the key.

See High Availability.

Service credentials

kingresd runs initdb, pg_ctl and the instance as the unprivileged user kingres. Its service role is a superuser with a SCRAM password in <data-dir>/service-credentials (mode 0600); service connections use the instance's unix socket and a fixed search path, so the password is not sent over TCP. The systemd unit runs with NoNewPrivileges, an empty capability set, ProtectSystem=strict, a system-call filter and other restrictions (Installing and Packaging). A cold copy of /var/lib/kingres holds the certificate authority key and the service credentials and must be treated as a secret. A server that runs the lease protocol does not start without kingres-watchdog.

The extension schema and catalog trust checks

The service role is a superuser, and it opens sessions in databases whose owners, and roles with CREATE on the database, are not trusted. A name such as kingres.ledger_pending tells nothing about who made the object: a database owner could create the schema kingres, a view in it and a function that the view calls, and a superuser session that reads the view would run that function as a superuser. Two layers close this:

  • In the extensions. kingres_shard, kingres_ledger and kingres_columnar do not trust a schema that lets another role create objects, an extension catalog that is not the installed extension's own, or a registry that cannot be trusted. The check of the schema runs in every install and upgrade script. The search path of the privileged SQL of kingres_shard is fixed. What an extension moves into the schema kingres belongs to the bootstrap superuser, and the schemas kingres and kingres_* are refused to other extensions. The ledger refuses UPDATE, DELETE and TRUNCATE of a table that looks like a ledger table while it cannot be one.
  • In kingresd (extguard and extgate). Before the service role reads or calls anything in the schema of a KingresDB extension in a user database, extguard decides with one catalog query that (1) a row of pg_extension exists and its owner is a superuser, (2) the schema of the extension is owned by a superuser, (3) the ACL of the schema grants CREATE to no role that is not a superuser and not to PUBLIC, and (4) every relation, function, type, operator and other object in the schema is a member of an extension owned by a superuser (the extensions kingres_shard, kingres_ledger, kingres_timepart and kingres_columnar share the schema kingres). The answer is installed, absent or untrusted. extgate turns an untrusted answer into a refusal with the code extension_unavailable that names the database and the check that failed, or into the old "not installed" behaviour where the caller can do without. The monitor raises the alert extensionSchemaUntrusted (contract 0.24.0) and kingresd reads nothing in a schema it does not trust. A kingresd guard is made per transaction or pass and never kept for the life of the process.
  • When a server is added. Copying extensions to an added server checks the package, the schema owner and the leader's version. An owner difference of an extension schema on the added server skips that extension and raises the alert extensionSkipped (contract 0.30.0), one for each skipped extension; it clears when a later apply succeeds or the database is dropped.

The package spooftest holds the test of the schema spoof. The marker tables of the transfers have row security and a checked tag.

Transfers

Export and import of a table (CSV) and of a database (a zip archive) are off until dataTransfer.enabled is on, and need TLS. The files are staged on disk sealed in 64 KiB segments with AES-256-GCM under a master key that is never inside the staging directory (ADR 0027). Transfers run as the PostgreSQL role that asked, never as the service role, so PostgreSQL's own privileges are the guarantee. The archive of a database import is treated as hostile input: it is read again from its bytes, every statement is classified by a grammar before anything is made, a role that is dangerous or that has a login member that can act as it is refused, and the structure is loaded into a private database that only the service role can reach during its own steps.

Failover and the operator's proof

A hard failover of the map group that declares the candidate lost (lostServerId) carries the proof of the operator's session and goes only to the server whose primary of the map group is held back. That server checks it against the keys of the administrators that it cached on disk (failover/admin-keys.json, younger than admin-keys-max-age, 72 hours by default), so one member's certificate is not enough to forge it (ADR 0026). A hard failover that accepts a loss of data needs kingres_admin. The local command kingresd -release-map-hold needs both -lost and -accept-data-loss and is audited. A restored system database is accepted by an operator, and the acceptance is a signed event (ADR 0025).

Ledger secrets

The private signing keys of the ledger are Ed25519 files in ledger-keys-dir, mode 0600 in a 0700 directory. They are sealed with PBKDF2-HMAC-SHA256 and AES-256-GCM when ledger-key-passphrase-file is set; otherwise they are in clear text and kingresd logs a warning. The passphrase comes from a file, never from the environment or the command line. The review of the key handling found no way for a secret to reach a log, an answer or a stored row (Ledger Signing and Publication). Anchor target credentials are write-only through the API. Back the keys up off the cluster, separately from the passphrase.

What the ledger guarantees and what it does not

The ledger detects changes to history; it does not prevent them by a privileged user. The extension guards its own tables so that only its own code writes them (a role with inherited privileges of the owner, or a member of pg_write_all_data, cannot insert), and reviews tested this in many forms. Limits stated plainly:

  • A database can be dropped with its ledger by every role that has the privileges of its owner or can SET ROLE to it. Nothing inside the database prevents that; ledger_status lists such roles.
  • A check inside the database is relative to a digest that you keep elsewhere. Tamper evidence outside the database needs the signed publication and the anchors. Anchoring to RFC 3161 authorities and OpenTimestamps was tested against local fakes only (Ledger Anchoring).
  • After a restore of the system database the aggregate log and the events cannot be re-derived: the operator accepts the loss, and the logs fork against what was published.
  • The standalone verifier does not trust the database: it checks checkpoints, proofs, bundles, client signatures and anchors against keys and certificates the auditor pins, and proves what is in the files it is given and nothing else (The Verifier).

Sharding and security

The sharding extension forces fixed session settings on the connections it opens to other nodes. A fragment runs with the rights of the session role, never of the node, and a group parses a fragment again and refuses a forged one. A table whose objects a non-superuser could use to run code as a superuser during the online copy of create_distributed_table_concurrently is refused. See Sharding and Sharding Table Lifecycle.

Reporting

Report a vulnerability privately through the Security tab of the repository (see SECURITY.md). Do not open a public issue for it. A vulnerability in PostgreSQL itself goes to the PostgreSQL security team.

Sources

Clone this wiki locally