KEY
in Consul you will use consul://KEY
or $secret_consul.KEY
notation depending on the location of the referenceKEY
in Vault you will use vault://KEY
or $secret_vault.KEY
notation depending on the location of the referencesecrets
section in the Tyk Gateway configuration file allows you to store settings that are specific to a single Tyk Gateway instance. This is useful for storing instance-specific configuration to be injected into API middleware or if you prefer using configuration files.
KEY
in the secrets
config you will use secrets://KEY
or $secret_conf.KEY
notation depending on the location of the referencesecrets
section in the Gateway config file) using environment variables, you should use the following notation: TYK_GW_SECRETS=key:value,key2:value2
TYK_GW_SECRETS
then this will allow you to access those KV dataVAR_NAME
you will use env://VAR_NAME
or $secret_env.VAR_NAME
notation depending on the location of the referencetyk.conf
)
tyk.conf
), you can retrieve values from KV stores for the following fields:
secret
node_secret
storage.password
cache_storage.password
security.private_certificate_encoding_secret
db_app_conf_options.connection_string
policies.policy_connection_string
slave_options.api_key
consul://path/to/key
vault://path/to/secret.key
tyk.conf
secrets: secrets://key
env://key
shared-secret
in secret gateway-dashboard
within directory tyk-secrets/
then you could use the Value as the node_secret
in your Gateway config by including the following in your tyk.conf
file:
node_secret
, which is used to secure connection to the Tyk Dashboard.
Note that all of these references are read (and replaced with the values read from the KV location) on Gateway start when loading the tyk.conf
file.
consul://path/to/key
vault://path/to/secret.key
secrets://key
env://key
UPSTREAM_SERVER_URL
with the Value http://httpbin.org/
then within your API definition you could use the Value for the Target URL for your Tyk OAS API as follows:
TYK_SECRET_{KEY_NAME}
. They were referred to in the API definition using env://{KEY_NAME}
excluding the TYK_SECRET_
prefix.KEY_NAME
, and the full name should be provided in the API definition reference. The pre-v5.3.0 naming convention is still supported for backward compatibility, but only for these two fields.$secret_consul.key
$secret_vault.key
$secret_conf.key
$secret_env.key
or env://key
(see here)user_id
then you could use the Value in the rewriteTo
upstream address in the URL rewrite middleware for your Tyk OAS API by including the following in your API definition:
GET /anything
, Tyk will retrieve the Value assigned to the user_id
Key in Consul and rewrite the Target URL for the request to /api/v1/users/{user_id}
.
These references are read (and replaced with the values read from the KV location) during the processing of the API request or response.
$secret_env.{KEY_NAME}
format.
env://{KEY_NAME}
and $secret_env.{KEY_NAME}
formats.
env://{KEY_NAME}
format for both the pattern
and rewriteTo
fields. The rewriteTo
field also supports $secret_env.{KEY_NAME}
format.
$secret_env
format, it expects the environment variable to be named TYK_SECRET_{KEY_NAME}
and to be referenced from the API definition using $secret_env.{KEY_NAME}
.TYK_SECRET_NEW_UPSTREAM=http://new.upstream.com
, then in a request body transform middleware, you would reference it as follows:rewriteTo
field using this variable you could use either:string
fieldsconsul://key
vault://secret.key
secrets://key
env://key
/tyk-apis
directory on Consul or Vault, you should not provide the path/to/
the key except for Target URL and Listen Path (as described above).secrets
section of the tyk.conf
file with the Key auth_header_name
:
secrets
section in the Gateway config file and use this to identify the header where Tyk Gateway should look for the Authentication token in requests to your Tyk OAS API.
tyk.conf
) by adding the kv
section as follows:
Key | Description |
---|---|
address | The location of the Consul server |
scheme | The URI scheme for the Consul server, e.g. http |
datacenter | Consul datacenter (agent) identifier |
http_auth | Username and password for Tyk to log into Consul using HTTP Basic Auth (if required by your Consul service) |
wait_time | Limits how long a watch will block in milliseconds (if enabled in your Consul service) |
token | Used to provide a per-request access token to Consul (if required by your Consul service) |
tls_config | Configuration for TLS connection to Consul (if enabled in your Consul service) |
string
field in the API definition. For these you should create a folder named tyk-apis
in the root of your Consul KV store and store all keys in a flat structure there (sub-directories not currently supported). You should not include the tyk-apis
path in the reference so, for example, given a key-value pair "foo":"bar"
stored in tyk-apis
in Consul, you would reference this from the API definition using consul://foo
.
tyk.conf
) you can retrieve values from Consul using the following notation:
consul://path/to/KEY
consul://path/to/KEY
$secret_consul.KEY
string
field in the API definition in the Consul KV store. You can retrieve these values from Consul, noting that you do not provide the directory path (/tyk-apis
) when accessing data for these fields, using the following notation:
consul://KEY
tyk.conf
) by adding the kv
section as follows:
Key | Description |
---|---|
address | The address of the Vault server, which must be a complete URL such as http://www.vault.example.com |
agent_address | The address of the local Vault agent, if different from the Vault server, must be a complete URL |
max_retries | The maximum number of attempts Tyk will make to retrieve the value if Vault returns an error |
timeout | The maximum time that Tyk will wait for a response from Vault (in nanoseconds, if set to 0 (default) will be interpreted as 60 seconds) |
token | The Vault root access token |
kv_version | The version number of Vault, usually defaults to 2 |
secret.key
) to access the value from a specific key within a secret.
Example of storing key value data in Vault
If you want to store a secret named tyk
with a key gw
and value 123
in Vault then, from the command line, you would:
kv
secrets engine in Vault under the path my-secret
using:vault secrets enable -version=2 -path=my-secret kv
tyk
with the key gw
and value 123
in Vault:vault kv put my-secret/tyk gw=123
/data
to the secret path):
excited
and foo
):
TYK_GW_SECRET=vault://my-secret/tyk.gw
string
field in the API definition. For these you should create a folder named tyk-apis
in the root of your Vault KV store and store all secrets in a flat structure there (sub-directories not currently supported). You should not include the tyk-apis
path in the reference so, for example, given a key-value pair "foo":"bar"
stored in a secret named my-secret
in /tyk-apis
in Vault, you would reference this from the API definition using vault://my-secret.foo
.
tyk.conf
) you can retrieve values from Vault using the following notation:
vault://path/to/secret.KEY
vault://path/to/secret.KEY
$secret_vault.KEY
string
field in the API definition in the Vault KV store. You can retrieve these values from Vault, noting that you do not provide the directory path (/tyk-apis
) when accessing data for these fields, using the following notation:
vault://KEY