Before you can configure the Vault entity in Kong Gateway, you must configure HashiCorp Vault to authenticate clients using EC2 instance identity documents and store a secret.
First, create the primary configuration file config.hcl for HashiCorp Vault in the ./vault directory:
listener "tcp" {
address = "0.0.0.0:8200"
tls_disable = true
}
storage "file" {
path = "./vault/data"
}
ui = true
Then, create the HashiCorp Vault policy file rw-secrets.hcl in the ./vault directory:
path "*" {
capabilities = ["create", "read", "update", "delete", "list", "sudo"]
}
- In a new terminal, start HashiCorp Vault:
vault server -config=./vault/config.hcl
- In your previous terminal, set the Vault address:
export VAULT_ADDR="http://localhost:8200"
- Initialize the Vault:
vault operator init -key-shares=1 -key-threshold=1
This outputs your unseal key and initial root token. Export them as environment variables:
export HCV_UNSEAL_KEY='YOUR-UNSEAL-KEY'
export DECK_HCV_TOKEN='YOUR-INITIAL-ROOT-TOKEN'
- Unseal your Vault:
vault operator unseal $HCV_UNSEAL_KEY
- Log in to your Vault:
vault login $DECK_HCV_TOKEN
- Write the policy to access secrets:
vault policy write rw-secrets ./vault/rw-secrets.hcl
- Enable AWS authentication:
- Create an EC2 role that binds to your Kong Gateway instance’s AMI ID:
vault write auth/aws/role/kong-role \
auth_type=ec2 \
bound_ami_id="$KONG_EC2_AMI_ID" \
token_policies="rw-secrets"
- Enable the K/V secrets engine:
vault secrets enable -path=kong kv
- Create a secret:
vault kv put kong/headers/request header="x-kong:test"
- Confirm you can retrieve the secret through Vault:
vault kv get kong/headers/request