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
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.