Configure Google Cloud Secret Manager as a vault backend

Uses: Kong Gateway decK
TL;DR

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

To add Secret Manager as a Vault backend to Kong Gateway, you must configure the following:

  1. In the Google Cloud console, create a project and name it test-gateway-vault.
  2. On the Secret Manager page, create a secret called test-secret with the following JSON content:
     secret
    
    Copied to clipboard!
  3. Create a service account key and grant IAM permissions:
    1. 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.
    2. From the Keys tab, create a new key from the add key menu and select JSON for the key type.
    3. Save the JSON file you downloaded.
    4. 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

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'
Copied to clipboard!

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 -
Copied to clipboard!

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}
Copied to clipboard!

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

If you created new Google Cloud resources for this tutorial, make sure to delete them to avoid unnecessary charges.

FAQs

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!