JWT provider configuration entry reference

This page provides reference information for the JWT provider configuration entry, which configures Consul to use a JSON Web Token (JWT) and JSON Web Key Set (JWKS) in order to add JWT validation to proxies in the service mesh. Refer to Use JWT authorization with service intentions for more information.

Configuration model

The following list outlines field hierarchy, language-specific data types, and requirements in a JWT provider configuration entry. Click on a property name to view additional details, including default values.

Complete configuration

When every field is defined, a JWT provider configuration entry has the following form:

  1. Kind = "jwt-provider" # required
  2. Name = "<name-of-provider-configuration-entry>" # required
  3. Issuer = "<jwt-issuer>" # required
  4. JSONWebKeySet = { # required
  5. Local = { # cannot specify with JWKS{}.Remote
  6. JWKS = "<JWKS-as-base64-string>" # cannot specify with JWKS{}.Local{}.Filename
  7. Filename = "<path/to/JWKS/file>" # cannot specify with JWKS{}.Local{}.String
  8. }
  9. }
  10. JSONWebKeySet = {
  11. Remote = { # cannot specify with JWKS{}.Local
  12. URI = "<uniform-resource-identifier>"
  13. RequestTimeoutMs = 1500
  14. CacheDuration = "5m"
  15. FetchAsynchronously = false
  16. RetryPolicy = {
  17. NumRetries = 0
  18. RetryPolicyBackoff = {
  19. BaseInterval = "1s"
  20. MaxInterval = "10s"
  21. }
  22. }
  23. JWKSCluster = {
  24. DiscoveryType = "STATIC"
  25. ConnectTimeout = "10s"
  26. # specify only one child: TrustedCA or CaCertificateProviderInstance
  27. TLSCertificates = {
  28. # specify only one child: Filename, EnvironmentVariable, InlineString or InlineBytes
  29. TrustedCA = {
  30. Filename = "<path/to/cert/file>"
  31. EnvironmentVariable = "<env-variable>"
  32. InlineString = "<inline-string>"
  33. InlineBytes = "\302\000\302\302\302\302"
  34. }
  35. }
  36. TLSCertificates = {
  37. CaCertificateProviderInstance = {
  38. InstanceName = "<instance-name>"
  39. CertificateName = "<certificate-name>"
  40. }
  41. }
  42. }
  43. }
  44. }
  45. Audiences = ["<aud-claims>"]
  46. Locations = [
  47. {
  48. Header = {
  49. Name = "<name-of-header-with-token>"
  50. ValuePrefix = "<prefix-in-header-before-token>"
  51. Forward = false
  52. }
  53. },
  54. {
  55. QueryParam = {
  56. Name = "<name-of-query-parameter-with-token>"
  57. }
  58. },
  59. {
  60. Cookie = {
  61. Name = "<name-of-cookie-with-token>"
  62. }
  63. }
  64. ]
  65. Forwarding = {
  66. HeaderName = "<name-appended-to-forwarding-header>"
  67. PadForwardPayloadHeader = false
  68. }
  69. ClockSkewSeconds = 30
  70. CacheConfig = {
  71. Size = 0
  72. }
  1. {
  2. "Kind": "jwt-provider", // required
  3. "Name": "<name-of-provider-configuration-entry>", // required
  4. "Issuer": "<jwt-issuer>", // required
  5. "JSONWebKeySet": { // required
  6. "Local": { // cannot specify with JWKS.Remote
  7. "JWKS": "<JWKS-as-base64-string>", // cannot specify with JWKS.Local.Filename
  8. "Filename": "<path/to/JWKS/file>" // cannot specify with JWKS.Local.String
  9. }
  10. },
  11. "JSONWebKeySet": {
  12. "Remote": { // cannot specify with JWKS.Local
  13. "URI": "<uniform-resource-identifier>",
  14. "RequestTimeoutMs": "1500",
  15. "CacheDuration": "5m",
  16. "FetchAsynchronously": "false",
  17. "RetryPolicy": {
  18. "NumRetries": "0",
  19. "RetryPolicyBackOff": {
  20. "BaseInterval": "1s",
  21. "MaxInterval": "10s"
  22. }
  23. },
  24. "JWKSCluster": {
  25. "DiscoveryType": "STATIC",
  26. "ConnectTimeout": "10s",
  27. // specify only one child: TrustedCA or CaCertificateProviderInstance
  28. "TLSCertificates": {
  29. // specify only one child: Filename, EnvironmentVariable, InlineString or InlineBytes
  30. "TrustedCA": {
  31. "Filename": "<path/to/cert/file>",
  32. "EnvironmentVariable": "<env-variable>",
  33. "InlineString": "<inline-string>",
  34. "InlineBytes": "\302\000\302\302\302\302"
  35. },
  36. "TLSCertificates": {
  37. "CaCertificateProviderInstance": {
  38. "InstanceName": "<instance-name>",
  39. "CertificateName": "<certificate-name>"
  40. }
  41. }
  42. }
  43. }
  44. },
  45. "Audiences": ["<aud-claims>"],
  46. "Locations": [
  47. {
  48. "Header": {
  49. "Name": "<name-of-header-with-token>",
  50. "ValuePrefix": "<prefix-in-header-before-token>",
  51. "Forward": "false"
  52. }
  53. },
  54. {
  55. "QueryParam": {
  56. "Name":"<name-of-query-parameter-with-token>",
  57. }
  58. },
  59. {
  60. "Cookie": {
  61. "Name": "<name-of-cookie-with-token>"
  62. }
  63. }
  64. ],
  65. "Forwarding": {
  66. "HeaderName": "<name-appended-to-forwarding-header>",
  67. "PadForwardPayloadHeader": "false"
  68. },
  69. "ClockSkewSeconds": "30",
  70. "CacheConfig": {
  71. "Size": "0"
  72. }
  73. }
  1. apiVersion: consul.hashicorp.com/v1alpha1 # required
  2. kind: JWTProvider # required
  3. metadata: # required
  4. name: <name-of-provider-configuration-entry> # required
  5. namespace: <namespace>
  6. spec: # required
  7. issuer: <jwt-issuer>
  8. jsonWebKeySet:
  9. local: # cannot specify with spec.jsonWebKeySet.remote
  10. jwks: <jwks-as-base64-string> # cannot specify with spec.jsonWebKeySet.local.filename
  11. filename: <path/to/jwks/file> # cannot specify with spec.jsonWebKeySet.local.string
  12. jsonWebKeySet:
  13. remote: # cannot specify with spec.jsonWebKeySet.local
  14. uri: <uniform-resource-identifier>
  15. requestTimeoutMs: 1500
  16. cacheDuration: 5m
  17. fetchAsynchronously: false
  18. retryPolicy:
  19. numRetries: 0
  20. retryPolicyBackoff:
  21. baseInterval: 1s
  22. maxInterval: 10s
  23. jwksCluster:
  24. discoveryType: STATIC
  25. connectTimeout: 10s
  26. # specify only one child: trustedCA or caCertificateProviderInstance
  27. tlsCertificates:
  28. # specify only one child: filename, environmentVariable, inlineString or inlineBytes
  29. trustedCA:
  30. filename: <path/to/cert/file>
  31. environmentVariable: <env-variable>
  32. inlineString: <inline-string>
  33. inlineBytes: \302\000\302\302\302\302
  34. tlsCertificates:
  35. caCertificateProviderInstance:
  36. instanceName: <instance-name>
  37. certificateName: <certificate-name>
  38. audiences: [<aud-claims>]
  39. locations:
  40. header:
  41. name: <name-of-header-with-token>
  42. valuePrefix: "<prefix-in-header-before-token>"
  43. forward: false
  44. queryParam:
  45. name: "<name-of-query-parameter-with-token>"
  46. cookie:
  47. name: "<name-of-cookie-with-token>"
  48. forwarding:
  49. headerName: "<name-appended-to-forwarding-header>"
  50. padForwardPayloadHeader: false
  51. clockSkewSeconds: 30
  52. cacheConfig:
  53. size: 0

Specification

This section provides details about the fields you can configure in the JWT provider configuration entry.

Kind

Specifies the type of configuration entry to implement.

Values

  • Default: None
  • This field is required.
  • Data type: String value that must be set to jwt-provider.

Name

Specifies a name for the configuration entry. We recommend naming the configuration file after the JWT provider used in the configuration. Refer to the Okta JWT Provider example for an example configuration.

Values

  • Default: None
  • This field is required.
  • Data type: String

Issuer

Specifies the provider that issued the JWT. This value must match the token’s iss (issuer) claim.

Values

  • Default: None
  • Data type: String

JSONWebKeySet

Defines a JSON Web Key Set. This field can be configured for a local file, or it can specify instructions to fetch a key set from a remote server. You cannot specify JSONWebKeySet{}.Local and JSONWebKeySet{}.Remote in the same map.

Values

  • Default: None

  • Data type: Map that can contain one of the following parameters:

JSONWebKeySet{}.Local

Specifies a local source for the JSON Web Key Set. You can specify the source as a string in the configuration entry or you can include a local filename that contains the set. You cannot specify both JWKS and Filename in the same map.

Values

  • Default: None

  • Data type: Map that can contain one of the following parameters:

JSONWebKeySet{}.Local{}.JWKS

Specifies the JSON Web Key Set that validates the JWT’s signature, formatted as a base64 encoded string. You cannot specify the JWKS parameter if JWKS{}.Local{}.Filename is also specified in the same map.

Values

  • Default: None
  • Data type: String

JSONWebKeySet{}.Local{}.Filename

Specifies the path to the JSON Web Key Set’s location on the local disk. When this field is specified, the file must be present on the disk for all proxies with service intentions referencing this provider. You cannot specify the Filename parameter if JWKS{}.Local{}.String is also specified in the same map.

Values

  • Default: None
  • Data type: String

JSONWebKeySet{}.Remote

Specifies a remote source for the JSON Web Key Set and configures behavior when fetching the key set.

Values

JSONWebKeySet{}.Remote{}.URI

Specifies the URI of the server to query for the JSON Key Web Set.

Values

  • Default: None
  • Data type: String

JSONWebKeySet{}.Remote{}.RequestTimeoutMs

Specifies the length of time before a request to the remote URI times out, measured in milliseconds (ms).

Values

  • Default: None
  • Data type: Integer

JSONWebKeySet{}.Remote{}.CacheDuration

Specifies the amount of time cached keys are available before they expire.

The default cache duration is 5 minutes.

Values

  • Default: 5m
  • Data type: String

JSONWebKeySet{}.Remote{}.FetchAsynchronously

Determines if the JSON Web Key Set is fetched before a client request arrives. When enabled, the JWKS is fetched before incoming requests. When not enabled, the JWKS is fetched after each request arrives and the proxy listener waits for the JWKS to be fetched before activating.

This parameter is set to false by default.

Values

  • Default: false
  • Data type: Boolean

JSONWebKeySet{}.Remote{}.RetryPolicy

Defines a retry policy when fetching the JSON Web Key Set from the remote location.

Values

JSONWebKeySet{}.Remote{}.RetryPolicy{}.NumRetries

Specifies the number of times to attempt to fetch the JSON Web Key Set when the previous attempt fails.

Values

  • Default: 0
  • Data type: Integer

JSONWebKeySet{}.Remote{}.RetryPolicy{}.RetryPolicyBackoff

Specifies a jittered exponential backoff strategy. When this field is empty, Envoy’s default policy is used. This policy has a 1 second base interval and a 10 second max interval.

Values

  • Default: None
  • Data type: Map that can contain the following parameters:
ParameterDescriptionData typeDefault value
BaseIntervalSpecifies the base interval to use for the next back off computation.String1s
MaxIntervalSpecifies the maximum interval between retries. By default, this value is 10 times BaseInterval.String10s

JSONWebKeySet{}.Remote{}.JWKSCluster

Defines how Envoy fetches the remote JSON Web Key Set URI.

Values

JSONWebKeySet{}.Remote{}.JWKSCluster{}.DiscoveryType

Specifies the service discovery type to use for resolving the cluster. You can specify the following discovery types:

Values

  • Default: STRICT_DNS
  • Data type: String

JSONWebKeySet{}.Remote{}.JWKSCluster{}.ConnectTimeout

Specifies the duration of time new network connections attempt to connect to hosts in the cluster before they timeout.

Values

  • Default: 5s
  • Data type: String

JSONWebKeySet{}.Remote{}.JWKSCluster{}.TLSCertificates

Specifies the data containing certificate authority certificates to use for verifying a presented peer certificate. Envoy does not verify certificates that peers present if this field is not configured.

You cannot specify TLSCertificates{}.CaCertificateProviderInstance and TLSCertificates{}.TrustedCA in the same map.

Values

JSONWebKeySet{}.Remote{}.JWKSCluster{}.TLSCertificates{}.CaCertificateProviderInstance

Speficies the certificate provider instance for fetching TLS certificates.

Values

  • Default: None
  • Data type: Map that can contain the following parameters:
ParameterDescriptionData typeDefault value
InstanceNameRefers to the certificate provider instance name.Stringdefault
CertificateNameSpecifies the certificate instances or types. For example, use ROOTCA to specify a root-certificate.StringNone

JSONWebKeySet{}.Remote{}.JWKSCluster{}.TLSCertificates{}.TrustedCA

Specifies TLS certificate data containing certificate authority certificates. Specify exactly one of the following data holders:

Values

  • Default: None
  • Data type: Map containing one of the following parameters:
ParameterDescriptionData typeDefault value
FilenameThe name of the file on the local system to use a data source for trusted CA certificates.StringNone
EnvironmentVariableThe environment variable on the local system to use a data source for trusted CA certificates.StringNone
InlineStringA string to inline in the configuration for use as a data source for trusted CA certificates.StringNone
InlineBytesA sequence of bytes to inline in the configuration for use as a data source for trusted CA certificates.StringNone

Audiences

Specifies a set of audiences that the JWT is allowed to access, formatted as a list of aud (audience) claims. When this field is specified, all JWTs verified with the provider must address at least one of the audiences in order to be considered valid.

Values

  • Default: None
  • Data type: List of strings

Locations

Specifies the locations in requests where the JWT can be found. Envoy checks all of these locations to extract a JWT.

This field can specify token locations in a header, a query parameter, or a cookie. When no locations are specified, Envoy defaults to the following locations:

  1. Authorization header with Bearer schema: "Authorization: Bearer <token>"
  2. access_token query parameter.

Values

Locations[].Header

Defines how to extract a JWT from an HTTP request header.

Values

Locations[].Header{}.Name

Specifies the name of the HTTP request header containing the token.

Values

  • Default: None
  • Data type: String

Locations[].Header{}.ValuePrefix

Specifies a prefix that must precede the token in the header value.

For example, Bearer is a standard value prefix for a header named “Authorization” that is formatted as Authorization: Bearer <token>. The prefix is not part of the token.

Values

  • Default: None
  • Data type: String

Locations[].Header{}.Forward

Specifies whether the header with the JWT is forwarded after the token is verified. When set to false, the header is not forwarded.

The default value is false.

Values

  • Default: false
  • Data type: Boolean

Locations[].QueryParam

Defines how to extract a JWT from an HTTP request query parameter.

Values

  • Default: None
  • Data type: Map that contains the following parameter:
ParameterDescriptionData typeDefault value
NameSpecifies the name of the query parameter containing the token.StringNone

Defines how to extract a JWT from an HTTP request cookie.

Values

  • Default: None
  • Data type: Map that contains the following parameter:
ParameterDescriptionData typeDefault value
NameSpecifies the name of the cookie containing the token.StringNone

Forwarding

Defines rules for forwarding JWTs to the backend after they are verified.

Values

Forwarding{}.HeaderName

Specifies a header name to use when forwarding a verified JWT to the backend. This field does not assume where the JWT was extracted from, and it can be applied to tokens extracted from headers, query parameters, or cookies.

The header value is base64 URL encoded. It is not padded by default.

Values

  • Default: None
  • Data type: String

Forwarding{}.PadForwardPayloadHeader

Determines whether to add padding to the base64 encoded token specified in Forwarding{}.HeaderName.

By default, this field is set to false.

Values

  • Default: false
  • Data type: Boolean

ClockSkewSeconds

Specifies the maximum allowable time difference from clock skew when validating the JSON web token’s exp (expiration) and nbf (not before) claims, measured in seconds.

By default, this parameter is configured to 30 seconds.

Values

  • Default: 30
  • Data type: Integer

CacheConfig

Defines behavior for caching the validation result of previously encountered JWTs. Caching results can speed up verification when the same tokens are expected to be handled multiple times. By default, the cache can hold 100 JWTs.

Values

  • Default: None
  • Data type: Map that contains the following parameter:
ParameterDescriptionData typeDefault value
SizeSpecifies the number of JSON web tokens to cache.Integer100

apiVersion

Specifies the version of the Consul API for integrating with Kubernetes. The value must be consul.hashicorp.com/v1alpha1.

Values

  • Default: None
  • This field is required.
  • String value that must be set to consul.hashicorp.com/v1alpha1.

kind

Specifies the type of configuration entry to implement. Must be set to jwtProvider.

Values

  • Default: None
  • This field is required.
  • Data type: String value that must be set to jwtProvider.

metadata

Map that contains an arbitrary name for the configuration entry and the namespace it applies to.

Values

  • Default: None
  • Data type: Map

metadata.name

Specifies a name for the configuration entry. The name is metadata that you can use to reference the configuration entry when performing Consul operations, such as applying a configuration entry to a specific cluster. We recommend naming the configuration file after the JWT provider used in the configuration. Refer to the Okta JWT Provider example for an example configuration.

Values

  • Default: None
  • This field is required.
  • Data type: String

metadata.namespace EnterpriseJWT Provider - 图1Enterprise

Specifies the namespace that the configuration applies to. Refer to namespaces for more information.

Values

  • Default: None
  • Data type: String

spec

Map that contains the details about the jwtProvider configuration entry. The apiVersion, kind, and metadata fields are siblings of the spec field. All other configurations are children.

Values

  • Default: None
  • This field is required.
  • Data type: Map

spec.issuer

Specifies the provider that issued the JWT. This value must match the token’s iss (issuer) claim.

Values

  • Default: None
  • Data type: String

spec.jsonWebKeySet

Defines a JSON Web Key Set. This field can be configured for a local file, or it can specify instructions to fetch a key set from a remote server. You cannot specify spec.jsonWebKeySet.local and spec.jsonWebKeySet.remote in the same map.

Values

  • Default: None

  • Data type: Map that can contain one of the following parameters:

spec.jsonWebKeySet.local

Specifies a local source for the JSON Web Key Set. You can specify the source as a string in the configuration entry or you can include a local filename that contains the set. You cannot specify both string and filename in the same map.

Values

  • Default: None

  • Data type: Map that can contain one of the following parameters:

spec.jsonWebKeySet.local.jwks

Specifies the JSON Web Key Set that validates the JWT’s signature, formatted as a base64 encoded string. You cannot specify the jwks parameter if spec.jsonWebKeySet.local.filename is also specified in the same map.

Values

  • Default: None
  • Data type: String

spec.jsonWebKeySet.local.filename

Specifies the path to the JSON Web Key Set’s location on the local disk. When this field is specified, the file must be present on the disk for all proxies with service intentions referencing this provider. You cannot specify the filename parameter if spec.jsonWebKeySet.local.jwks is also specified in the same map.

Values

  • Default: None
  • Data type: String

spec.jsonWebKeySet.remote

Specifies a remote source for the JSON Web Key Set and configures behavior when fetching the key set.

Values

spec.jsonWebKeySet.remote.uri

Specifies the URI of the server to query for the JSON Key Web Set.

Values

  • Default: None
  • Data type: String

spec.jsonWebKeySet.remote.requestTimeoutMs

Specifies the length of time before a request to the remote URI times out, measured in milliseconds (ms).

Values

  • Default: None
  • Data type: Integer

spec.jsonWebKeySet.remote.cacheDuration

Specifies the amount of time cached keys are available before they expire.

The default cache duration is 5 minutes.

Values

  • Default: 5m
  • Data type: String

spec.jsonWebKeySet.remote.fetchAsynchronously

Determines if the JSON Web Key Set is fetched before a client request arrives. When enabled, the JWKS is fetched before incoming requests. When not enabled, the JWKS is fetched after each request arrives and the proxy listener waits for the JWKS to be fetched before activating.

This parameter is set to false by default.

Values

  • Default: false
  • Data type: Boolean

spec.jsonWebKeySet.remote.retryPolicy

Defines a retry policy when fetching the JSON Web Key Set from the remote location.

Values

spec.jsonWebKeySet.remote.retryPolicy.numRetries

Specifies the number of times to attempt to fetch the JSON Web Key Set when the previous attempt fails.

Values

  • Default: 0
  • Data type: Integer

spec.jsonWebKeySet.remote.retryPolicy.retryPolicyBackoff

Specifies a jittered exponential backoff strategy. When this field is empty, Envoy’s default policy is used. This policy has a 1 second base interval and a 10 second max interval.

Values

  • Default: None
  • Data type: Map that can contain the following parameters:
ParameterDescriptionData typeDefault value
baseIntervalSpecifies the base interval to use for the next back off computation.String1s
maxIntervalSpecifies the maximum interval between retries. By default, this value is 10 times BaseInterval.String10s

spec.jsonWebKeySet.remote.jwksCluster

Defines how Envoy fetches the remote JSON Web Key Set URI.

Values

spec.jsonWebKeySet.remote.jwksCluster.discoveryType

Specifies the service discovery type to use for resolving the cluster. You can specify the following discovery types:

String values must be a valid Cluster DiscoveryType.

Values

  • Default: STRICT_DNS
  • Data type: String

spec.jsonWebKeySet.remote.jwksCluster.connectTimeout

Specifies the timeout for new network connections to hosts in the cluster.

Values

  • Default: 5s
  • Data type: String

spec.jsonWebKeySet.remote.jwksCluster.tlsCertificates

Specifies the data containing certificate authority certificates to use for verifying a presented peer certificate. Envoy does not verify certificates that peers present if this field is not configured.

You cannot specify spec.tlsCertificates.caCertificateProviderInstance and spec.tlsCertificates.trustedCA in the same map.

Values

spec.jsonWebKeySet.remote.jwksCluster.tlsCertificates.caCertificateProviderInstance

Speficies the certificate provider instance for fetching TLS certificates.

Values

  • Default: None
  • Data type: Map that can contain the following parameters:
ParameterDescriptionData typeDefault value
instanceNameRefers to the certificate provider instance name.Stringdefault
certificateNameSpecifies the certificate instances or types. For example, use ROOTCA to specify a root-certificate.StringNone

spec.jsonWebKeySet.remote.jwksCluster.tlsCertificates.trustedCA

Specifies TLS certificate data containing certificate authority certificates. Specify exactly one of the following data holders:

Values

  • Default: None
  • Data type: Map containing one of the following parameters:
ParameterDescriptionData typeDefault value
filenameThe name of the file on the local system to use a data source for trusted CA certificates.StringNone
environmentVariableThe environment variable on the local system to use a data source for trusted CA certificates.StringNone
inlineStringA string to inline in the configuration for use as a data source for trusted CA certificates.StringNone
inlineBytesA sequence of bytes to inline in the configuration for use as a data source for trusted CA certificates.StringNone

spec.audiences

Specifies a set of audiences that the JWT is allowed to access, formatted as a list of aud (audience) claims. When this field is specified, all JWTs verified with the provider must address at least one of the audiences in order to be considered valid.

Values

  • Default: None
  • Data type: List of strings

spec.locations

Specifies the locations in requests where the JWT can be found. Envoy checks all of these locations to extract a JWT.

This field can specify token locations in a header, a query parameter, or a cookie. When no locations are specified, Envoy defaults to the following locations:

  1. Authorization header with Bearer schema: "Authorization: Bearer <token>"
  2. access_token query parameter.

Values

spec.locations[].header

Defines how to extract a JWT from an HTTP request header.

Values

spec.locations[].header.name

Specifies the name of the HTTP request header containing the token.

Values

  • Default: None
  • Data type: String

spec.locations[].header.valuePrefix

Specifies a prefix that must precede the token in the header value.

For example, Bearer is a standard value prefix for a header named “Authorization” that is formatted as Authorization: Bearer <token>. The prefix is not part of the token.

Values

  • Default: None
  • Data type: String

spec.locations[].header.forward

Specifies whether the header with the JWT is forwarded after the token is verified. When set to false, the header is not forwarded.

The default value is false.

Values

  • Default: false
  • Data type: Boolean

spec.locations[].queryParam

Defines how to extract a JWT from an HTTP request query parameter.

Values

  • Default: None
  • Data type: Map that contains the following parameter:
ParameterDescriptionData typeDefault value
nameSpecifies the name of the query parameter containing the token.StringNone

Defines how to extract a JWT from an HTTP request cookie.

Values

  • Default: None
  • Data type: Map that contains the following parameter:
ParameterDescriptionData typeDefault value
nameSpecifies the name of the cookie containing the token.StringNone

spec.forwarding

Defines rules for forwarding JWTs to the backend after they are verified.

Values

spec.forwarding.headerName

Specifies a header name to use when forwarding a verified JWT to the backend. This field does not assume where the JWT was extracted from, and it can be applied to tokens extracted from headers, query parameters, or cookies.

The header value is base64 URL encoded. It is not padded by default.

Values

  • Default: None
  • Data type: String

spec.forwarding.padForwardPayloadHeader

Determines whether to add padding to the base64 encoded token specified in spec.forwarding.headerName`.

By default, this field is set to false.

Values

  • Default: false
  • Data type: Boolean

spec.clockSkewSeconds

Specifies the maximum allowable time difference from clock skew when validating the JSON web token’s exp (expiration) and nbf (not before) claims, measured in seconds.

By default, this parameter is configured to 30 seconds.

Values

  • Default: 30
  • Data type: Integer

spec.cacheConfig

Defines behavior for caching the validation result of previously encountered JWTs. Caching results can speed up verification when the same tokens are expected to be handled multiple times. By default, the cache can hold 100 JWTs.

Values

  • Default: None
  • Data type: Map that contains the following parameter:
ParameterDescriptionData typeDefault value
sizeSpecifies the number of JSON web tokens to cache.Integer100

Metrics

Envoy proxies expose metrics that can track JWT authentication details. Use the following Envoy metrics:

  1. http.public_listener.jwt_authn.allowed
  2. http.public_listener.jwt_authn.cors_preflight_bypassed
  3. http.public_listener.jwt_authn.denied
  4. http.public_listener.jwt_authn.jwks_fetch_failed
  5. http.public_listener.jwt_authn.jwks_fetch_success
  6. http.public_listener.jwt_authn.jwt_cache_hit
  7. http.public_listener.jwt_authn.jwt_cache_miss

Note: Currently, Envoy does not reference these metrics in their documentation. Refer to Envoy documentation for more information about exposed metrics.

Examples

The following examples demonstrate common JWT provider configuration patterns for specific use cases.

Okta JWT provider

The following example configures Consul to fetch a JSON Web Token issued by Okta. Consul fetches the token from the URI and keeps it in its cache for 30 minutes before the token expires. After validation, the token is forwarded to the backend with user-token appended to the HTTP header.

  1. Kind = "jwt-provider"
  2. Name = "okta"
  3. Issuer = "okta"
  4. JSONWebKeySet = {
  5. Remote = {
  6. URI = "https://<org>.okta.com/oauth2/default/v1/keys"
  7. CacheDuration = "30m"
  8. }
  9. }
  10. Forwarding = {
  11. HeaderName = "user-token"
  12. }
  1. {
  2. "Kind": "jwt-provider",
  3. "Name": "okta",
  4. "Issuer": "okta",
  5. "JSONWebKeySet": {
  6. "Remote": {
  7. "URI": "https://<org>.okta.com/oauth2/default/v1/keys",
  8. "CacheDuration": "30m"
  9. }
  10. },
  11. "Forwarding": {
  12. "HeaderName": "user-token"
  13. }
  14. }
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: jwtProvider
  3. metadata:
  4. name: okta
  5. spec:
  6. issuer: okta
  7. jsonwebkeyset:
  8. remote:
  9. uri: https://<org>.okta.com/oauth2/default/v1/keys
  10. cacheDuration: 30m
  11. forwarding:
  12. headerName: user-token