active
flag must be set to true
for Tyk to load the policy into memory, this makes it easy to enable or disable policies without deleting them.
is_inactive
flag applies to the key itself. If you set this value to true
, any key with this policy will be disabled, you can actually set this same value on a key object to make the single key inactive, but as part of a policy it makes it possible to deny access to a whole block of users with a single change.
policies section
in your configuration file as follows:
policy_source
section is set to file
and tells Tyk to look for policy record in the file specified in the policy_record_name
field. An example file is shipped with Tyk, and it will look like this:
default
.
/create
(or /add
) endpoint in the Tyk REST API with a session object that has the apply_policy_id
flag set to the name default
(or whatever you named your policy).
apply_policy_id
is still supported, it is now deprecated. apply_policies
is now used to list your policy IDs as an array. This supports the Multiple Policy feature introduced in the v2.4 release.access_rights
section, in each version definition, we can see an allowed_urls
section, here we can define which URLs are enabled in this key as follows:
access_rights
field
partitions
section to your policy object:
quota
: If set to true
, enforce the quota element of this policyrate_limit
: If set to true
, enforce the rate limit of this policyacl
: If set to true
, enforce the access control rules of this policycomplexity
: If set to true
, enforce the GraphQL complexity rules of this policyexpires
value with a Unix timestamp of when the key should expire.
expires
can only be a positive number, or 0
if you don’t want the key to expire.session_lifetime
value (in seconds) in your API Definition Object, this will need to be managed via the Dashboard REST API.
murmur3
, and serves more to obfuscate than to cryptographically secure the tokens.
It is possible to disable key hashing in Tyk using hash_keys
set to false
in your tyk.conf
and tyk_analytics.conf
.
See the Gateway Configuration Options for more details.
hash_key_function
in your tyk.conf
to one of the following options:
murmur32
murmur64
murmur128
sha256
sha256
cryptographic key hashing algorithm, for cases when you are willing to sacrifice some performance for additional security.
Performance wise, setting new key hashing algorithms can increase the key hash length, as well as key length itself, so expect that your analytics data size to grow (but not that much, up to about 10%). Additionally, if you set the sha256
algorithm, it will significantly slowdown Tyk, because cryptographic functions are slow by design but very secure.
Technically wise, it is implemented by new key generation algorithms, which now embed additional metadata to the key itself, and if you are curious about the actual implementation details, feel free to check the following pull request.
Changing hashing algorithm is entirely backward compatible. All your existing keys will continue working with the old murmur32
hashing algorithm, and your new keys will use the algorithm specified in your tyk.conf
. Moreover, changing algorithms is also backward compatible, and Tyk will maintain keys with multiple hashing algorithms without any issues.
A hashed installation imposes some constraints on how Tyk is used:
enable_hashed_keys_listing
to true
in your tyk.conf
file
POST /keys/create
, POST /keys
and POST /keys/{keyName}
also return the field "key_hash"
for future useGET /keys
get all (or per API) key hashes. You can disable this endpoint by using the new tyk.conf
setting enable_hashed_keys_listing
(set to false
by default)GET /keys/{keyName}
was modified to be able to get a key by hash. You just need provide the key hash as a keyName
and call it with the new optional query parameter hashed=true
. So the new format is GET /keys/{keyName}?hashed=true"
DELETE /keys/{keyName}?hashed=true
and call it with the optional query parameter hashed=true
. So the format is GET /keys/{keyName}?hashed=true"
DELETE /keys/{keyName}?hashed=true
endpointallowance
& rate
: these should be set to the same value, these are the users allowance during a period as set by per
.per
: The time in seconds where a rate limit is applied.expires
: The date when the key expires. Note: expires
can only be a positive number, or -1 (unlimited).quota_max
: The usage quota for the user. Note: quota_max
can only be a positive number, or -1 (unlimited).quota_renews
: the Unix timestamp when the quota is renewed.quota_renewal_rate
: The time, in seconds, of when the quota gets renewed (e.g. 86400 would represent 1 day).allowance
and rate
are set to the same value, this should be number of requests to be allowed in a time period, so if you wanted 100 requests every second, set this value to 100.per
is set to the time limit. Again, as in the above example, if you wanted 100 requests per second, set this value to 1. If you wanted 100 per 5 seconds, set this value to 5 etc.quota_max
is set to the maximum amount of requests that a user is allowed to make in a time period.quota_remaining
is set to the same value as quota_max
, this is the value that will decrement on each request (failed or successful).quota_renewal_rate
to the value, in seconds, of when the quota should renew. For example, if you would like it to renew every 30 days, you would have 2592000
seconds (((60*60) * 24) * 30 = 2592000
).quota_max
to -1
.
quota_max
can only be a positive number, or -1 (unlimited).expires
value with the timestamp of when the key should expire.
Leave this field empty for it never to expire.
last_check
(deprecated): No longer used, but this value is related to rate limiting.
allowance
(deprecated): No longer directly used, this value, no key creation, should be the same as rate
.
rate
: The number of requests that are allowed in the specified rate limiting window.
per
: The number of seconds that the rate window should encompass.
expires
: A Unix timestamp that defines when the key should expire. You can set this to 0
(zero) if you don’t want the key to expire.
quota_max
: The maximum number of requests allowed during the quota period.
quota_renews
: An epoch that defines when the quota renews.
quota_remaining
: The number of requests remaining for this user’s quota (unrelated to rate limit).
quota_renewal_rate
: The time, in seconds. during which the quota is valid. So for 1000
requests per hour, this value would be 3600
while quota_max
and quota_remaining
would be 1000
.
access_rights
: This section is defined in the Access Control section of this documentation, use this section define what APIs and versions this token has access to.
org_id
: The organization this user belongs to, this can be used in conjunction with the org_id
setting in the API Definition object to have tokens “owned” by organizations. See the Organizations Quotas section of the Tyk Gateway API.
oauth_client_id
: This is set by Tyk if the token is generated by an OAuth client during an OAuth authorization flow.
basic_auth_data
: This section defines the basic auth password and hashing method.
jwt_data
: This section contains a JWT shared secret if the ID matches a JWT ID.
hmac_enabled
: If this token belongs to an HMAC user, this will set the token as a valid HMAC provider.
hmac_string
: The value of the HMAC shared secret.
is_inactive
: Set this value to true
to deny access.
apply_policy_id
(supported but now deprecated): The policy ID that is bound to this token.
apply_policies
: This replaces apply_policy_id
and lists your policy IDs as an array. This supports the Multiple Policy feature introduced in the v2.4 of the Gateway.
data_expires
: An value, in seconds, that defines when data generated by this token expires in the analytics DB (must be using Pro edition and MongoDB).
monitor
: Rate monitor trigger settings, defined elsewhere in the documentation.
meta_data
: Metadata to be included as part of the session, this is a key/value string map that can be used in other middleware such as transforms and header injection to embed user-specific data into a request, or alternatively to query the providence of a key.
tags
: Tags are embedded into analytics data when the request completes. If a policy has tags, those tags will supersede the ones carried by the token (they will be overwritten).
alias
: As of v2.1, an Alias offers a way to identify a token in a more human-readable manner, add an Alias to a token in order to have the data transferred into Analytics later on so you can track both hashed and un-hashed tokens to a meaningful identifier that doesn’t expose the security of the underlying token.