Authentication
The KMS server offers flexible authentication options, supporting multiple authentication methods that can operate independently or in combination with each other, providing multi-factor authentication capabilities.
Authentication Modes
Non-authenticated Mode (Default)
By default, if no authentication methods are configured, the server operates in non-authenticated mode. All requests are mapped to the default user, which can be configured using:
--default-username <DEFAULT_USERNAME>
The default username to use when no authentication is configured
[env: KMS_DEFAULT_USERNAME=]
[default: admin]
Unless insecure_allow_unauthenticated is set, this mode is only accepted when the server binds a loopback address (127.0.0.1, ::1 or localhost): on any other address the server refuses to start (refusing to start: no authentication method is configured ...). Configure an authentication method, bind a loopback address, or set insecure_allow_unauthenticated = true (KMS_INSECURE_ALLOW_UNAUTHENTICATED=true) for development only. The startup warning remains when the opt-in is used. The Docker image, the packaged kms.toml and the Helm chart bind 0.0.0.0, so without authentication they refuse to start out of the box.
When the server is started with a configuration file (-c/--config or COSMIAN_KMS_CONF), environment variables and command-line arguments are ignored: set insecure_allow_unauthenticated = true under [http] in that file, not KMS_INSECURE_ALLOW_UNAUTHENTICATED.
Authenticated Mode
When one or more authentication methods are enabled, the server requires successful authentication for all requests. The authentication mechanism works in a cascading fashion, attempting each configured method until one succeeds.
Available Authentication Methods
The KMS server supports three primary authentication methods:
- TLS Client Certificates: Authentication based on X.509 client certificates
- JWT Tokens: Authentication with OpenID-compliant JWT access tokens
- API Tokens: Authentication using a pre-shared API token
These methods can be used individually or in combination for enhanced security.
Authentication Flow
When multiple authentication methods are configured, the server follows this process:
- If TLS Client Certificate authentication is enabled and a valid certificate is presented, the user is authenticated
- If JWT authentication is enabled and a valid JWT token is presented, the user is authenticated
- If API Token authentication is enabled and a valid token is presented, the user is authenticated
- If all configured authentication methods fail, access is denied with a 401 Unauthorized response
A successful authentication at any step will grant access and subsequent authentication methods will be skipped.
Configuring Authentication Methods
TLS Client Certificate Authentication
To enable certificate-based authentication, the server must be started with TLS and a certificate authority (CA) for client verification:
# For FIPS mode (default build):
docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms-fips:latest \
--tls-cert-file server.crt \
--tls-key-file server.key \
--clients-ca-cert-file client_ca.cert.pem
# For non-FIPS mode:
# docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms:latest \
# --tls-p12-file kms.server.p12 \
# --tls-p12-password password \
# --clients-ca-cert-file client_ca.cert.pem
The server extracts the username from the certificate's Subject Common Name (CN) field. Specifically, the Common Name of the client certificate subject is used directly as the username for authentication purposes. If the certificate is valid but does not contain a Common Name, authentication will fail.
Example of a subject with a CN field:
C=FR, ST=Ile-de-France, L=Paris, O=Cosmian Tech, CN=john.doe@example.com
In this example, john.doe@example.com would become the authenticated username.
Clients must present a valid certificate signed by the specified authority.
Revoking client certificates (CRL)
By default a client certificate stays valid until it expires. To reject revoked client
certificates, point clients_crl_dir (--clients-crl-dir, KMS_CLIENTS_CRL_DIR) to a directory of
CRLs. It requires clients_ca_cert_file and applies to both the HTTPS server and the KMIP socket server.
docker run -p 9998:9998 --name kms \
-v "$PWD/certs":/certs:ro \
-v /etc/cosmian/client-crls:/etc/cosmian/client-crls:ro \
ghcr.io/cosmian/kms-fips:latest \
--tls-cert-file /certs/server.crt \
--tls-key-file /certs/server.key \
--clients-ca-cert-file /certs/client_ca.cert.pem \
--clients-crl-dir /etc/cosmian/client-crls
The directory must be in the OpenSSL hashed directory format: each CRL is a PEM file named
<hash>.r0, where <hash> is the hash of the issuing CA subject name. Compute it with
openssl x509 -noout -subject_hash -in client_ca.cert.pem, or let OpenSSL create the links:
cp ca.crl.pem /etc/cosmian/client-crls/
openssl rehash /etc/cosmian/client-crls
Where the CRL comes from
The CRL must be a PEM file signed by the CA that issued the client certificates. If that CA is
managed by this KMS, generate the CRL with ckms and write it straight into the directory (the
KMS default output format is DER, so ask for PEM):
HASH=$(openssl x509 -noout -subject_hash -in client_ca.cert.pem)
ckms certificates generate-crl \
--certificate-id <CA_CERT_ID> \
--validity-days 7 \
--output-format pem \
--output-file /etc/cosmian/client-crls/$HASH.r0
Otherwise, download the CRL published by your external CA and convert it to PEM, saving it under
the same $HASH.rN name (openssl crl -inform DER -in ca.crl -out /etc/cosmian/client-crls/$HASH.r0). See
Revocation & CRL Distribution for the KMS endpoint and the
automatic refresh. The KMS does not fetch or refresh the CRLs of this directory itself: renew them
before their nextUpdate with a job of your own (for example cron), writing each renewed CRL to
the next unused suffix ($HASH.r1, $HASH.r2, ...) as described below. Do not re-run the command
above with the same file name, and do not run openssl rehash again for a renewal.
When a CRL is renewed, add it under the next suffix (<hash>.r1, <hash>.r2, ...): OpenSSL
reads them on demand, without restarting the server, and uses the CRL with the most recent
thisUpdate date. Make sure the new CRL has a later thisUpdate than the one it replaces.
Overwriting an existing <hash>.rN file is not picked up until the server restarts.
Behavior to be aware of:
- Fail-closed: when
clients_crl_diris set, a client certificate is rejected if no CRL of its issuing CA is present in the directory, or if that CRL has expired (nextUpdatein the past). Keep the CRLs refreshed before theirnextUpdate. - CRL only, no OCSP: client certificates are checked against the CRLs of this directory only. The KMS does not query an OCSP responder when authenticating clients; its own OCSP responder serves relying parties and is not used here.
- Signature: a CRL whose signature does not verify against the issuing CA certificate in
clients_ca_cert_fileis not usable and the client is rejected. - Only the client (leaf) certificate is checked against the CRL; CRLs of intermediate CAs are not.
- Revocation is evaluated when the TLS connection is established. A connection already open (for example an HTTP keep-alive connection) keeps its identity until it is closed, even if the certificate is revoked in the meantime.
- The directory is also an OpenSSL trust store: a CA certificate stored there as
<hash>.0is trusted. Only administrators may write to it. clients_crl_dirmust be an existing directory and requiresclients_ca_cert_file; otherwise the server refuses to start.
JWT Token Authentication
The server supports JWT tokens compatible with OpenID Connect. Configure JWT authentication with:
docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms:latest \
--jwt-auth-provider="https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs,cosmian_kms"
The JWT authentication provider configuration uses the format: "JWT_ISSUER_URI,JWKS_URI,JWT_AUDIENCE_1,JWT_AUDIENCE_2,..." where:
- JWT_ISSUER_URI: The issuer URI of the JWT token (required)
- JWKS_URI: The JWKS (JSON Web Key Set) URI (optional, defaults to
<JWT_ISSUER_URI>/.well-known/jwks.json) - JWT_AUDIENCE_n: Zero or more allowed audiences (optional). If multiple are provided, validation succeeds if the token
audcontains any of them (any-of). If omitted, audience validation is skipped.
Examples:
"https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs,my-audience""https://auth0.example.com,,my-app"(JWKS URI will default)"https://keycloak.example.com/auth/realms/myrealm,,"(no audience, JWKS URI will default)"https://issuer.example.com,https://issuer.example.com/jwks.json,frontend,cli"(multi-audience)
JWT tokens must be passed in the HTTP Authorization header:
Authorization: Bearer <JWT_TOKEN>
The server extracts the username from the token's email claim.
JWT tokens (and UI OIDC logins) must carry email_verified: true (a JSON boolean or the string "true"); a token without it is rejected. Identity providers that omit the claim, such as Microsoft Entra ID access tokens, are not accepted.
Users of the second and later jwt_auth_provider entries are identified as email#<jwt_issuer_uri> (for example alice@example.com#https://login.example.com/), so access rights and role lists for these users must use that form. Users of the first provider keep the bare email. Providers are taken in configuration order (command-line flags, or the TOML list). The same rule applies to the UI OIDC login: its identity is email#<ui_oidc_issuer_url> unless that URL is exactly the issuer of the first jwt_auth_provider (plain string comparison; a trailing slash makes them differ). Whitelisted Google CSE (KACLS) migration issuers are namespaced like secondary providers. The UI OIDC id_token must carry the exp, iss, aud and sub claims.
Supported Signing Algorithms
The KMS server automatically detects the signing algorithm from the JWT header (alg claim) and validates accordingly. The following signing algorithms from the jsonwebtoken library are supported; tokens using the none algorithm (for example, Algorithm::None / alg: "none") are explicitly rejected:
| Category | Algorithms |
|---|---|
| HMAC (symmetric) | HS256, HS384, HS512 |
| RSA PKCS#1 | RS256, RS384, RS512 |
| RSA-PSS | PS256, PS384, PS512 |
| ECDSA | ES256, ES384 |
| EdDSA | EdDSA (Ed25519) |
The algorithm is picked up from the token's alg header — no server-side configuration is required. The signing key must be published in the JWKS endpoint and matched by its kid claim.
PKCE Support
The KMS supports PKCE (Proof Key for Code Exchange) in two complementary ways:
- CLI / API clients (
ckmsand direct API usage): PKCE is used to obtain JWT tokens from the IDP. The client secret is optional — PKCE provides the security guarantee instead. - KMS Web UI: PKCE is mandatory. The browser login flow always sends
code_challenge_method=S256. The IDP application must be configured accordingly (see the PKCE Authentication guide for per-provider instructions).
For detailed information including required IDP settings, provider-specific examples, and troubleshooting, see the PKCE Authentication guide.
Multiple Identity Providers
To support multiple identity providers, repeat the JWT authentication provider parameter:
--jwt-auth-provider="https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs,cosmian_kms,another_client_id" \
--jwt-auth-provider="https://login.microsoftonline.com/<TENANT_ID>/v2.0,https://login.microsoftonline.com/<TENANT_ID>/discovery/v2.0/keys,<CLIENT_ID>"
API Token Authentication
API Token authentication uses a symmetric key stored in the KMS as the authentication token:
-
Generate a symmetric key and note its ID:
ckms sym keys create -
Export the key in base64 format:
ckms sym keys export -k <SYMMETRIC_KEY_ID> -f base64 api_token.base64 -
Start the server with the API token ID:
docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms:latest \
--api-token-id <SYMMETRIC_KEY_ID>
-
Configure the client to use the API token:
Authorization: Bearer <BASE64_TOKEN>
When using API token authentication, the authenticated user will be the default username.
Choosing default_username
Only the API token or the non-authenticated mode can act as default_username. Any request authenticated by another method (client certificate Common Name, JWT email or sub, Auth Verifier or SAML subject, UI session) whose identity equals default_username is rejected with 401 Unauthorized (external identity collides with the KMS default_username). The comparison ignores ASCII case and trailing spaces only: on MySQL/MariaDB, whose default accent-insensitive collations (for example utf8mb4_0900_ai_ci) can also equate accent variants such as admín with admin, such a name is not detected. Choose a default_username that is distinct from every real identity: if a certificate CN or an email is currently admin, change default_username.
Auth Verifier bearer tokens
Auth Verifier bearer tokens are only accepted when issued for the realm set in auth_verifier_realm (when it is set). Tokens of the admin realm (_) are always rejected: create a dedicated realm and users for the KMS.
Auth Verifier and Vault Token Verifier
The KMS calls the Auth Verifier ([auth_verifier] section: auth_verifier_url, auth_verifier_jwks_uri) to fetch
its signing keys and to check that a session is still live, and the Vault-compatible token verifier
(vault_auth_verifier_url) to validate X-Vault-Token values. These calls carry credentials, so:
- Each of these URLs must use
https://.http://is accepted only for a loopback host (127.0.0.1,::1,localhost). The server refuses to start otherwise. - Redirects are never followed: a
3xxanswer is an authentication failure, not a request to another host. - A request that does not connect within 5 seconds, or does not complete within 10 seconds (30 seconds for the JWKS fetch), fails (and the authentication with it) instead of waiting indefinitely.
- The signing keys (JWKS) of the Auth Verifier are refreshed periodically. A token that no cached key validates triggers one more fetch (at most once every 5 seconds) before being rejected, so a key rotation is picked up without a restart. A failed fetch keeps the previously fetched keys.
- The response of the verifier relayed on
/v1/auth/*is limited to 1 MiB; a larger answer yields502 Bad Gateway.
Force Default Username
If you want to enforce a consistent username regardless of the authentication method, use:
--force-default-username <true|false>
Force using the default username regardless of the authentication method
[env: KMS_FORCE_DEFAULT_USERNAME=]
[default: false]
When enabled, the server still performs the authentication validation to ensure the client has valid credentials, but it ignores the username that would normally be extracted (such as the certificate's Common Name or JWT email claim) and instead maps all authenticated requests to the default username.
This feature is particularly useful in scenarios where:
- You want consistent user identity across all requests regardless of authentication method
- You prefer to manage access control independently from the authentication credentials
- You're transitioning between authentication methods but need to maintain consistent audit trails
When force-default-username is enabled with multiple authentication methods, the server will still cascade through the authentication methods, but always use the default username upon successful authentication.
Multi-Factor Authentication Examples
Example 1: Client Certificate and JWT Authentication
# For FIPS mode (default build):
docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms-fips:latest \
--tls-cert-file server.crt \
--tls-key-file server.key \
--clients-ca-cert-file client_ca.cert.pem \
--jwt-auth-provider="https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs,"
# For non-FIPS mode:
# docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms:latest \
# --tls-p12-file kms.server.p12 \
# --tls-p12-password password \
# --clients-ca-cert-file client_ca.cert.pem \
# --jwt-auth-provider="https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs,"
In this configuration:
- Clients can authenticate using either a valid client certificate or a valid JWT token
- If both are provided, the certificate is checked first
Example 2: JWT and API Token Authentication
docker run -p 9998:9998 --name kms ghcr.io/cosmian/kms:latest \
--jwt-auth-provider="https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs," \
--api-token-id <SYMMETRIC_KEY_ID>
- Clients can authenticate using either a valid JWT token or the API token
- JWT authentication is attempted first, followed by API token verification
Common Identity Provider Configurations
Google ID Tokens
--jwt-auth-provider="https://accounts.google.com,https://www.googleapis.com/oauth2/v3/certs,"
Auth0
--jwt-auth-provider="https://<your-tenant>.<region>.auth0.com/,,"
Note: the trailing / is required in the issuer URI. The JWKS URI will default to the well-known endpoint.
Microsoft Entra ID (Azure AD)
--jwt-auth-provider="https://login.microsoftonline.com/<TENANT_ID>/v2.0,https://login.microsoftonline.com/<TENANT_ID>/discovery/v2.0/keys,<CLIENT_ID>"
Okta
--jwt-auth-provider="https://<OKTA_TENANT_NAME>.com,https://<OKTA_TENANT_NAME>.com/oauth2/v1/keys,<OKTA_CLIENT_ID>"