How do I rotate my secrets in HashiCorp Vault and how does Kong Gateway pick up the new secret values?
You can rotate your secret in HashiCorp Vault by creating a new secret version with the updated value. You’ll also want to configure the ttl
settings in your Kong Gateway Vault entity so that Kong Gateway pulls the rotated secret periodically.
How does Kong Gateway retrieve secrets from HashiCorp Vault?
Kong Gateway retrieves secrets from HashiCorp Vault’s HTTP API through a two-step process: authentication and secret retrieval.
Step 1: Authentication
Depending on the authentication method defined in config.auth_method
, Kong Gateway authenticates to HashiCorp Vault using one of the following methods:
- If you’re using the
token
auth method, Kong Gateway uses theconfig.token
as the client token. - If you’re using the
kubernetes
auth method, Kong Gateway uses the service account JWT token mounted in the pod (path defined in theconfig.kube_api_token_file
) to call the login API for the Kubernetes auth path on the HashiCorp Vault server and retrieve a client token. -
v3.4+ If you’re using the
approle
auth method, Kong Gateway uses the AppRole credentials to retrieve a client token. The AppRole role ID is configured by fieldconfig.approle_role_id
, and the secret ID is configured by fieldconfig.approle_secret_id
orconfig.approle_secret_id_file
.- If you set
config.approle_response_wrapping
totrue
, then the secret ID configured byconfig.approle_secret_id
orconfig.approle_secret_id_file
will be a response wrapping token, and Kong Gateway will call the unwrap API/v1/sys/wrapping/unwrap
to unwrap the response wrapping token to fetch the real secret ID. Kong Gateway will use the AppRole role ID and secret ID to call the login API for the AppRole auth path on the HashiCorp Vault server and retrieve a client token.
- If you set
-
v3.11+ If you’re using the
cert
auth method, Kong Gateway uses a client certificate and private key to retrieve a client token. The certificate must be previously configured in HashiCorp vault as a trusted certificate. Alternatively, the issuing CA certificate can be set as a trusted CA. The trusted certificate role name is configured by the fieldconfig.cert_auth_role_name
. If one isn’t provided, HashiCorp vault attempts to authenticate against all configured trusted certificates or trusted CAs. The certificate is configured withconfig.cert_auth_cert
and the key withcert_auth_cert_key
.
By calling the login API, Kong Gateway will retrieve a client token and then use it in the next step as the value of X-Vault-Token
header to retrieve a secret.
Step 2: Retrieving the secret
Kong Gateway uses the client token retrieved in the authentication step to call the Read Secret API and retrieve the secret value. The request varies depending on the secrets engine version you’re using. Kong Gateway will parse the response of the read secret API automatically and return the secret value.
I get a Client sent an HTTP request to an HTTPS server.
error when I try to retrieve my secret, how do I fix this?
Configure your Vault entity to use HTTPS instead of HTTP. This can be done updating your config.hcl. You will need to set the address to include the https
protocol and include the certificate/key in the tls_cert_file
and tls_key_file
parameters.
I’m getting an unable to retrieve secret from vault: 18: self-signed certificate
error, how do I fix this?
Add the self-signed certificate in kong.conf
to the parameter lua_ssl_trusted_certificate
.
I’m getting an unable to retrieve secret from vault: certificate host mismatch
error, how do I fix this?
The hostname specified in your Vault entity does not match the cert presented by the Vault server. Confirm the Kong Vault config.host
matches the name of the certificate presented by the Vault server certificate.
I’m getting an invalid response code 400 received when performing certificate-based authentication: {"errors":["auth methods cannot create root tokens"]}
error, how do I fix this?
The certificate is mapped to a policy that would allow creation of a root token, which Vault explicitly forbids. Check the policy associated with your certificate
to ensure that it does not include CREATE
, UPDATE
, READ
operations on the path auth/token/root
I’m getting an ailure performing certificate-based authentication: 21: unable to verify the first certificate
error, how do I fix this?
This will usually occur for one of two reasons:
- You have a certificate chain and only a portion of it was uploaded for Kong Gateway to use. Fix: Include the entire chain in
KONG_LUA_SSL_TRUSTED_CERTIFICATE
. - HashiCorp Vault was setup in dev mode. This does not allow you to provide your own CA and instead uses an ephemeral cert for SAN: “localhost, 127.0.0.1, 0.0.0.0.”
I’m getting an invalid response code 503 received when performing certificate-based authentication: {"errors":["Vault is sealed"]}
error, how do I fix this?
To perform any operation on the Vault, it must be unsealed first. It was likely sealed intentionally or through a restart of the Vault process.