HashiCorp Vault

HashiCorp Vault can be configured with environment variables or with a Vault entity.

Configuration via environment variables

Configure the following environment variables on your Kong Gateway data plane:

Static Vault token authentication:

  1. export KONG_VAULT_HCV_PROTOCOL=<protocol(http|https)>
  2. export KONG_VAULT_HCV_HOST=<hostname>
  3. export KONG_VAULT_HCV_PORT=<portnumber>
  4. export KONG_VAULT_HCV_MOUNT=<mountpoint>
  5. export KONG_VAULT_HCV_KV=<v1|v2>
  6. export KONG_VAULT_HCV_AUTH_METHOD=token
  7. export KONG_VAULT_HCV_TOKEN=<tokenstring>

Kubernetes service account role authentication:

  1. export KONG_VAULT_HCV_PROTOCOL=<protocol(http|https)>
  2. export KONG_VAULT_HCV_HOST=<hostname>
  3. export KONG_VAULT_HCV_PORT=<portnumber>
  4. export KONG_VAULT_HCV_MOUNT=<mountpoint>
  5. export KONG_VAULT_HCV_KV=<v1|v2>
  6. export KONG_VAULT_HCV_AUTH_METHOD=kubernetes
  7. export KONG_VAULT_HCV_KUBE_ROLE=<rolename>

You can also store this information in an entity.

Configuration via vaults entity

The Vault entity can only be used once the database is initialized. Secrets for values that are used before the database is initialized can’t make use of the Vaults entity.

Admin API

Declarative configuration

cURL

HTTPie

  1. curl -i -X PUT http://HOSTNAME:8001/vaults/my-hashicorp-vault \
  2. --data name="hcv" \
  3. --data description="Storing secrets in HashiCorp Vault" \
  4. --data config.protocol="https" \
  5. --data config.host="localhost" \
  6. --data config.port="8200" \
  7. --data config.mount="secret" \
  8. --data config.kv="v2" \
  9. --data config.token="<mytoken>"
  1. http -f PUT :8001/vaults/my-hashicorp-vault \
  2. name="hcv" \
  3. description="Storing secrets in HashiCorp Vault" \
  4. config.protocol="https" \
  5. config.host="localhost" \
  6. config.port="8200" \
  7. config.mount="secret" \
  8. config.kv="v2" \
  9. config.token="<mytoken>"

Result:

  1. {
  2. "config": {
  3. "host": "localhost",
  4. "kv": "v2",
  5. "mount": "secret",
  6. "port": 8200,
  7. "protocol": "https",
  8. "token": "<mytoken>"
  9. },
  10. "created_at": 1645008893,
  11. "description": "Storing secrets in HashiCorp Vault",
  12. "id": "0b43d867-05db-4bed-8aed-0fccb6667837",
  13. "name": "hcv",
  14. "prefix": "my-hashicorp-vault",
  15. "tags": null,
  16. "updated_at": 1645008893
  17. }

Secrets management is supported in decK 1.16 and later.

Add the following snippet to your declarative configuration file:

  1. _format_version: "3.0"
  2. vaults:
  3. - config:
  4. host: localhost
  5. kv: v2
  6. mount: secret
  7. port: 8200
  8. protocol: https
  9. token: <mytoken>
  10. description: Storing secrets in HashiCorp Vault
  11. name: hcv
  12. prefix: my-hashicorp-vault

Examples

For example, let’s say you’ve configured a HashiCorp Vault with a path of secret/hello and a key=value pair of foo=world:

  1. vault kv put secret/hello foo=world
  2. Key Value
  3. --- -----
  4. created_time 2022-01-15T01:40:03.740833Z
  5. custom_metadata <nil>
  6. deletion_time n/a
  7. destroyed false
  8. version 1

Access these secrets like this:

  1. {vault://hcv/hello/foo}

Or, if you configured an entity:

  1. {vault://my-hashicorp-vault/hello/foo}

Vault configuration options

Use the following configuration options to configure the vaults entity through any of the supported tools:

  • Admin API
  • Declarative configuration
  • Kong Manager
  • Konnect

Configuration options for a HashiCorp vault in Kong Gateway:

ParameterField nameDescription
vaults.config.protocolconfig-protocol (Kong Manager)
Protocol (Konnect)
The protocol to connect with. Accepts one of http or https.
vaults.config.hostconfig-host (Kong Manager)
Host (Konnect)
The hostname of your HashiCorp vault.
vaults.config.portconfig-port (Kong Manager)
Port (Konnect)
The port number of your HashiCorp vault.
vaults.config.mountconfig-mount (Kong Manager)
Mount (Konnect)
The mount point.
vaults.config.kvconfig-kv (Kong Manager)
Kv (Konnect)
The secrets engine version. Accepts v1 or v2.
vaults.config.tokenconfig-token (Kong Manager)
Token (Konnect)
A token string.
vaults.config.namespacenamespaceNamespace for the Vault. Vault Enterprise requires a namespace to successfully connect to it.
vaults.config.auth_methodauth-methodDefines the authentication mechanism when connecting to the Hashicorp Vault service. Accepted values are: token, or kubernetes.
vaults.config.kube_rolekube-roleDefines the HashiCorp Vault role for the Kubernetes service account of the running pod. keyring_vault_auth_method must be set to kubernetes for this to activate.

Common options:

ParameterField nameDescription
vaults.description
optional
DescriptionAn optional description for your vault.
vaults.nameNameThe type of vault. Accepts one of: env, gcp, aws, or hcv. Set hcv for HashiCorp Vault.
vaults.prefixPrefixThe reference prefix. You need this prefix to access secrets stored in this vault. For example, {vault://my-hcv-vault/<some-secret>}.