Configure the Konnect Config Store vault

Uses: Kong Gateway decK
Incompatible with
on-prem
Minimum Version
Kong Gateway - 3.4
TL;DR
  1. Use the Konnect API to create a Config Store using the /config-stores endpoint.
  2. Create a Konnect Vault using the /vaults/ endpoint.
  3. Store your secret as a key/value pair using the /secrets endpoint.
  4. Reference the secret using the Vault prefix and key (for example: {vault://mysecretvault/secret-key}).

Prerequisites

This is a Konnect tutorial. If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.

  1. The following Konnect items are required to complete this tutorial:

    • Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
    • Control Plane Name: You can use an existing Control Plane or create a new one to use for this tutorial.
    • Konnect Proxy URL: By default, a self-hosted Data Plane uses http://localhost:8000. You can set up Data Plane nodes for your Control Plane from the Gateway Manager in Konnect.
  2. Set the personal access token, the Control Plane name, the Control Plane URL, and the Konnect proxy URL as environment variables:

     export DECK_KONNECT_TOKEN='YOUR KONNECT TOKEN'
     export DECK_KONNECT_CONTROL_PLANE_NAME='YOUR CONTROL PLANE NAME'
     export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
     export KONNECT_PROXY_URL='KONNECT PROXY URL'
    

This tutorial requires Kong Gateway Enterprise. If you don’t have Kong Gateway set up yet, you can use the quickstart script with an enterprise license to get an instance of Kong Gateway running almost instantly.

  1. Export your license to an environment variable:

     export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'
    
  2. Run the quickstart script:

     curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA 
    

    Once Kong Gateway is ready, you will see the following message:

     Kong Gateway Ready
    

decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial you will first need to install decK.

To use the copy, paste, and run the instructions in this how-to, you must export the additional environmental variable CONTROL_PLANE_ID:

export CONTROL_PLANE_ID='YOUR CONTROL PLANE ID'

You can find your control plane UUID by navigating to the control plane in the Konnect UI or by sending a GET request to the /control-planes endpoint.

Configure a Konnect Config Store

Before you can configure a Konnect Vault, you must first create a Config Store using the Control Planes Configuration API by sending a POST request to the /config-stores endpoint:

curl -X POST "$KONNECT_CONTROL_PLANE_URL/v2/control-planes/$CONTROL_PLANE_ID/config-stores" \
     -H "Accept: application/json"\
     -H "Content-Type: application/json"\
     -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
     --json '{
       "name": "my-config-store"
     }'

Export the Config Store ID in the response body as an environment variable so you can use it later:

export DECK_CONFIG_STORE_ID='CONFIG STORE ID'

Configure Konnect as your Vault

Enable Konnect as your vault with the Vault entity:

echo '
_format_version: "3.0"
vaults:
  - name: konnect
    prefix: mysecretvault
    description: Storing secrets in Konnect
    config:
      config_store_id: "${{ env "DECK_CONFIG_STORE_ID" }}"
' | deck gateway apply -

Store a secret in your Konnect Vault

By storing a secret in a Konnect Vault, you can reference it within kong.conf or as a referenceable plugin fields without having to store any values in plain-text.

Store your secret by sending a POST request to the /secrets endpoint:

curl -X POST "$KONNECT_CONTROL_PLANE_URL/v2/control-planes/$CONTROL_PLANE_ID/config-stores/$DECK_CONFIG_STORE_ID/secrets/" \
     -H "Accept: application/json"\
     -H "Content-Type: application/json"\
     -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
     --json '{
       "key": "secret-key",
       "value": "my-secret-value"
     }'

Validate

You can validate that your secret was stored correctly by sending a GET request to the /secrets endpoint:

curl -X GET "$KONNECT_CONTROL_PLANE_URL/v2/control-planes/$CONTROL_PLANE_ID/config-stores/$DECK_CONFIG_STORE_ID/secrets/" \
     -H "Accept: application/json"\
     -H "Content-Type: application/json"\
     -H "Authorization: Bearer $DECK_KONNECT_TOKEN"

If your secret was successfully stored in Konnect, the endpoint should return a 201 status code and your secret-key key in the output.

You can now reference your Konnect secret in configurations as {vault://mysecretvault/secret-key}.

Cleanup

If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.

FAQs

No. You can’t reference secrets stored in a Konnect Config Store Vault in kong.conf because Konnect resolves the secret after Kong Gateway connects to the control plane. For more information about the fields you can reference as secrets, see What can be stored as a secret?.

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!