Keyboard shortcuts

Press โ† or โ†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sovereign, high-performance data protection

Audit logging

The Eviden KMS server can record a cryptographically chained, tamper-evident audit trail of every KMIP operation, including authentication failures. Two backends are available: a local JSONL file, or a PostgreSQL database for a fleet of instances. See Audit events for the fields every event carries.

Audit logging is disabled by default: no backend is started until the feature is enabled. The server logs a SECURITY: warning at startup when audit logging is disabled.

Audit logging: requests become queued events written to a file or PostgreSQL backend

Covered transports

  • Recorded: KMIP over HTTP (/kmip, /kmip/2_1), the KMIP socket server, /v1/crypto, KV, /google_cse, /ms_dke, /aws (user [aws-xks-service]) and /azureekm.
  • Not recorded: /tokenize, the Vault transit, PKI and auth scopes, /ui and /health.

Choosing a backend

File backendPostgreSQL backend
Best forA single instance, or one file per instanceA fleet of instances sharing one audit trail
If the backend is unreachable at startupStarts anyway and buffers eventsRefuses to start
If content is found corrupted at startupSeals the old chain, starts a new one, keeps servingSeals the old chain, starts a new one, keeps serving
Sealed-evidence checkAutomatic, part of ckms audit verifyManual, see PostgreSQL backend
Size capYes, --audit-file-max-size-bytesNo

The backend is chosen at configuration time, with no fallback between the two. See File backend or PostgreSQL backend for the configuration and behavior specific to each.


Configuration

Enabling the pipeline is shared by both backends; each backend then needs its own path or URL.

cosmian_kms configure (step 8) can write this section for you, including the signed checkpoints.

[audit]
enabled = true

With no other setting, the file backend starts at its default path, <root-data-path>/audit.jsonl. See File backend to set a specific path, or PostgreSQL backend for a shared database.

Not safe for multiple KMS instances sharing one file

The file backend is designed for one writer per file. If you run multiple KMS instances (horizontal scaling, Kubernetes replicas), each one needs its own audit file: never point several instances at the same path on a shared volume. For a centrally consolidated, multi-writer-safe audit trail, use the PostgreSQL backend instead.

The settings below apply to whichever backend you use:

CLI flagEnvironment variableDefaultDescription
--audit-enableKMS_AUDIT_ENABLEfalseEnable the audit pipeline. When false, no backend is started.
--audit-channel-capacityKMS_AUDIT_CHANNEL_CAPACITY4096Capacity of the in-memory queue between request handling and the backend writer. Raise this if you see channel full warnings under sustained load.
--audit-trusted-proxy-cidrsKMS_AUDIT_TRUSTED_PROXY_CIDRS(empty)Comma-separated CIDR blocks (e.g. 10.0.0.0/8,172.16.0.0/12) of reverse proxies/load balancers allowed to set client_ip via X-Forwarded-For. See Client IP and reverse proxies.
--audit-failure-modeKMS_AUDIT_FAILURE_MODEcontinueWhat to do when an event cannot be queued for the writer. continue: log the error, keep serving. reject: return HTTP 503. See Audit failure mode.
--audit-fail-closedKMS_AUDIT_FAIL_CLOSEDfalseRefuse any operation whose audit record cannot be durably stored. See Fail-closed audit.
--audit-max-backlogKMS_AUDIT_MAX_BACKLOG0Queued writer messages at which /health reports the audit pipeline as down. 0 = --audit-channel-capacity, else between 1 and it.

If you see AuditFileStore: channel full, dropping audit event in the server log, raise --audit-channel-capacity. The dropped events are still accounted for: the next successful write is preceded by an audit:eviction event recording how many were lost. Events the backend fails to persist (for example while the PostgreSQL audit database is unreachable) are counted the same way. See Audit events.

Client IP and reverse proxies

By default (--audit-trusted-proxy-cidrs empty), client_ip in every audit event is always the direct TCP peer address: the X-Forwarded-For header is ignored entirely.

If the KMS runs directly reachable by clients (no reverse proxy/load balancer in front), leave this unset: the TCP peer address is always the real client.

If the KMS runs behind a reverse proxy or load balancer, the direct TCP peer is always the proxy, not the real client. Set --audit-trusted-proxy-cidrs to the proxy's IP/CIDR so the audit middleware knows it can trust X-Forwarded-For coming from that address. Otherwise every audit event records the proxy's IP instead of the real client's.

Never trust X-Forwarded-For unconditionally: any direct caller can set that header to an arbitrary value, corrupting the forensic trail (e.g. framing another IP, or hiding its own). Restricting trust to known proxy CIDRs prevents this while still letting a legitimate reverse proxy forward the real client IP.


Audit failure mode

By default (continue) the KMS keeps serving even when an audit event cannot be queued: the event is dropped, an error is logged, and the request succeeds normally.

Audit event queueing and the failure mode when the queue is full

Set --audit-failure-mode reject to refuse requests whose event cannot be queued: if the queue is full or the writer has stopped, the KMS returns HTTP 503 to the client instead of the normal KMIP response. The KMIP operation has already executed at this point; the 503 signals that its outcome was not recorded.

reject governs queue admission only. The response is sent before the writer persists the event, so a queued event that the backend then fails to write (disk error, PostgreSQL audit database unreachable after retries) does not turn the response into a 503. Such an event is dropped, an error is logged, and the next successful write is preceded by an audit:eviction event recording the loss.

reject mode can cause service disruption

When failure_mode = reject, a saturated event queue or a stopped backend will make every subsequent KMIP request fail with 503 until the condition is resolved. Only use this mode when unlogged operations are strictly unacceptable (e.g. regulated environments requiring a complete audit trail).


Fail-closed audit

With --audit-fail-closed ([audit] fail_closed = true) the KMS never runs an operation it cannot record:

  1. Before each request runs, an audit:intent record is written and waited for until it is durable (file fsync, PostgreSQL commit). If that fails, nothing runs and the client gets HTTP 503 (KMIP OperationFailed on the socket server).
  2. The outcome record is written and awaited after the operation. The operation has then already run: if this write fails, the response is a 503 and the outcome is missing from the trail, but the audit:intent record proves the attempt.
  3. At startup the whole chain is verified. A broken chain, or an audit backend that cannot be opened, aborts the start instead of being sealed and rolled over. Only a torn last line (interrupted write) is repaired.

It supersedes --audit-failure-mode and requires --audit-enable (the server refuses to start without it). A request rejected before it runs (for example by authentication) still gets an outcome record closing its intent. /health reports an audit dependency as down when the writer has stopped, the audit file reached --audit-file-max-size-bytes (every request is then refused), or --audit-max-backlog messages (default 0: --audit-channel-capacity) are waiting: the node is then DEGRADED (HTTP 200 unless the probe uses /health?strict=true), or DOWN (HTTP 503) with --audit-fail-closed.

Fail-closed trades availability for completeness

A full disk or an unreachable audit database stops every audited request. Every request pays one durable write before it runs and one after.


Signed checkpoints and timestamps

The hash chain is unkeyed. A checkpoint anchors the chain head with a signature that an attacker who can rewrite the log cannot forge. Setting --audit-signing-key enables them:

CLI flagEnvironment variableDefaultDescription
--audit-signing-keyKMS_AUDIT_SIGNING_KEY(unset)UID of the private key that signs checkpoints: EC (ECDSA, SHA-256), RSA, Ed25519 or ML-DSA (FIPS 204, signs the raw message). It must be usable for Sign by --default-username; the server refuses to start if it cannot sign.
--audit-checkpoint-eventsKMS_AUDIT_CHECKPOINT_EVENTS1000Write a checkpoint after this many new events.
--audit-checkpoint-secondsKMS_AUDIT_CHECKPOINT_SECONDS300Write a checkpoint at least this often when there are new events.
--audit-tsa-urlKMS_AUDIT_TSA_URL(unset)RFC 3161 time-stamping authority (http(s)://, no credentials in the URL); each checkpoint signature is timestamped through it.

A checkpoint is an ordinary chained event, audit:checkpoint, whose details hold the anchored head_id and head_hash, the signature over them (SHA-256 digest for EC and RSA, the raw message for Ed25519 and ML-DSA), and, with a TSA, the hex DER TimeStampToken over SHA-256(signature). If the TSA does not answer, the checkpoint is still written, with a timestamp_error, and ckms audit verify prints a warning. A checkpoint that cannot be signed (missing key, no Sign permission) is logged and retried after --audit-checkpoint-seconds.

ckms audit verify --path audit.jsonl --checkpoint-key audit-signing-key.pem --tsa-ca tsa-ca.pem

--checkpoint-key is the PEM public key, for both the file and the PostgreSQL sources. Repeat it to accept every key used across signing-key rotations: a checkpoint is valid if any of the keys verifies it (never pass a key known to be compromised: it could re-sign a rewrite). Verification checks each signature, that the anchored head is the event with that row_hash in the source (a log rewritten after the checkpoint fails), and the timestamp token; with --tsa-ca the token must also chain to that CA, as of the time the token was issued, and every checkpoint must carry one (a recorded TSA failure does not excuse a missing token: that field is unsigned, so a stripped token could hide behind it; verify without --tsa-ca a log that lived through a TSA outage). Without --tsa-ca the tokens are not authenticated and a warning says so. Certificate revocation is not checked. A non-empty file, or a PostgreSQL instance, with no checkpoint at all fails (NO CHECKPOINT), and the output names the events after the last signed head, which no signature covers. A checkpoint cannot prove that the log was not truncated back to before an older checkpoint if the later ones are removed: keep the latest checkpoint outside the audit store.


Verifying the trail

# File backend
ckms audit verify --path /var/log/cosmian-kms/audit.jsonl

# PostgreSQL backend
ckms audit verify --audit-postgres-url postgresql://kms_audit:password@db-host:5432/kms_audit

Exit code 0 means the chain is internally consistent; 1 means a broken link or a tampered event was found, or, with the file backend, that sealed evidence is altered or missing. The chain hashes are unkeyed, so whoever can write the audit file or bypass the database triggers can rewrite events and recompute later hashes, or drop the latest events, without failing verification. To detect that, enable signed checkpoints and verify with --checkpoint-key, or keep the latest chain head (id and row_hash) outside the audit store and compare it on audit. To verify a rotated file that does not start at the genesis, pass the row_hash of the previous file's last event with --prev-hash. See File backend or PostgreSQL backend for the full set of options and sample output.


Retention and monitoring

Retain audit data for the compliance window required by your framework, for example PCI-DSS Req. 10.7 (12 months) or HIPAA ยง164.312(b) (6 years). Restrict read access to the audit data to the KMS process user and auditors only: it contains usernames, client IPs, and operation details.

Monitor for the recovery events listed in Audit events and the matching server log lines in the log reference. A torn write is routine after an ungraceful restart; a seal-and-roll (audit:reanchor) is worth investigating.

For SIEM ingestion and CEF export, see SIEM integration.