Configure Google Cloud Secret Manager as a vault backend
Save a secret in Google Cloud Secret Manager and create a service account with the Secret Manager Secret Accessor
role. Export your service account key JSON as an environment variable (GCP_SERVICE_ACCOUNT
), set lua_ssl_trusted_certificate=system
in your kong.conf
file, then configure a Vault entity with your Secret Manager configuration. Reference secrets from your Secret Manager vault like the following: {vault://gcp-sm-vault/test-secret}
Prerequisites
Google Cloud configuration
To add Secret Manager as a Vault backend to Kong Gateway, you must configure the following:
- In the Google Cloud console, create a project and name it
test-gateway-vault
. - On the Secret Manager page, create a secret called
test-secret
with the following JSON content:secret
Copied to clipboard! - Create a service account key and grant IAM permissions:
- In the Service Account settings, click the
test-gateway-vault
project and then click the email address of the service account that you want to create a key for. - From the Keys tab, create a new key from the add key menu and select JSON for the key type.
- Save the JSON file you downloaded.
- From the IAM & Admin settings, click the edit icon next to the service account to grant access to the
Secret Manager Secret Accessor
role for your service account. icon_url: /assets/icons/google-cloud.svg
- In the Service Account settings, click the
Set the environment variables needed to authenticate to Google Cloud:
export GCP_SERVICE_ACCOUNT=$(cat /path/to/file/service-account.json | jq -c)
export KONG_LUA_SSL_TRUSTED_CERTIFICATE='system'
Note that these variables need to be passed when creating your Data Plane container.
Configure Secret Manager as a vault with the Vault entity
To enable Secret Manager as your vault in Kong Gateway, you can use the Vault entity.
echo '
_format_version: "3.0"
vaults:
- name: gcp
description: Stored secrets in Secret Manager
prefix: gcp-sm-vault
config:
project_id: test-gateway-vault
' | deck gateway apply -
Validate
To validate that the secret was stored correctly in Google Cloud, you can call a secret from your vault using the kong vault get
command within the Data Plane container.
kong vault get {vault://gcp-sm-vault/test-secret}
kong vault get {vault://gcp-sm-vault/test-secret}
If the vault was configured correctly, this command should return the value of the secret. You can use {vault://gcp-sm-vault/test-secret}
to reference the secret in any referenceable field.
Cleanup
Cleanup Google Cloud Resources
If you created new Google Cloud resources for this tutorial, make sure to delete them to avoid unnecessary charges.