External authorization extension configuration reference

This topic describes how to configure the external authorization Envoy extension, which configures Envoy proxies to request authorization from an external service. Refer to Delegate authorization to an external service for usage information.

Configuration model

The following list outlines the field hierarchy, data types, and requirements for the external authorization configuration. Place the configuration inside the EnvoyExtension.Arguments field in the proxy defaults or service defaults configuration entry. Refer to the following documentation for additional information:

Click on a property name to view additional details, including default values.

Complete configuration

When each field is defined, an ext-authz configuration has the following form:

  1. Name = "builtin/ext-authz"
  2. Arguments = {
  3. ProxyType = "connect-proxy"
  4. InsertOptions = {
  5. Location = "<location in the filter chain>"
  6. FilterName = "<filter relative to the location>"
  7. }
  8. Config = {
  9. BootstrapMetadataLabelsKey = "<key from bootstrap metadata>"
  10. ClearRouteCache = false // HTTP only
  11. GrpcService = {
  12. Target = {
  13. Service = {
  14. Name = "<upstream service to send gRPC authorization requests to>"
  15. Namespace = "<namespace containing the upstream service>"
  16. Partition = "<partition containing the upstream service>"
  17. URI = "<URI of the upstream service>"
  18. Timeout = "1s"
  19. Authority = "<authority header to send in the gRPC request>"
  20. InitialMetadata = [
  21. "<Key>" : "<value>"
  22. HttpService = {
  23. Target = {
  24. Service = {
  25. Name = "<upstream service to send gRPC authorization requests to>"
  26. Namespace = "<namespace containing the upstream service>"
  27. Partition = "<partition containing the upstream service>"
  28. URI = "<URI of the upstream service>"
  29. Timeout = "1s"
  30. }
  31. }
  32. PathPrefix = "/<authorization-request-header-prefix>/"
  33. AuthorizationRequest = {
  34. AllowedHeaders = [
  35. Contains = "<client request headers must contain this value>",
  36. Exact = "<client request headers can only be this value>",
  37. IgnoreCase = false,
  38. Prefix = "<client request headers must begin with this value>",
  39. SafeRegex = "<client request headers can match this regex pattern>"
  40. ]
  41. HeadersToAdd = [
  42. "<header key>" = "<header value>"
  43. ]
  44. }
  45. AuthorizationResponse = {
  46. AllowedUpstreamHeaders = [
  47. Contains = "<authorization response headers must contain this value>",
  48. Exact = "<authorization response headers can only be this value>",
  49. IgnoreCase = false,
  50. Prefix = "<authorization response headers must begin with this value>",
  51. SafeRegex = "<authorization response headers can match this regex pattern>"
  52. Suffix = "<authorization response headers must end with this value>"
  53. ]
  54. AllowedUpstreamHeadersToAppend = [
  55. Contains = "<authorization response headers must contain this value>",
  56. Exact = "<authorization response headers can only be this value>",
  57. IgnoreCase = false,
  58. Prefix = "<authorization response headers must begin with this value>",
  59. SafeRegex = "<authorization response headers can match this regex pattern>"
  60. Suffix = "<authorization response headers must end with this value>"
  61. ]
  62. AllowedClientHeaders = [
  63. Contains = "<client response headers must contain this value>",
  64. Exact = "<client response headers can only be this value>",
  65. IgnoreCase = false,
  66. Prefix = "<client response headers must begin with this value>",
  67. SafeRegex = "<client response headers can match this regex pattern>"
  68. Suffix = "<client response headers must end with the value>"
  69. ]
  70. AllowedClientHeadersOnSuccess = [
  71. Contains = "<client response headers must contain this value>",
  72. Exact = "<client response headers can only be this value>",
  73. IgnoreCase = false,
  74. Prefix = "<client response headers must begin with this value>",
  75. SafeRegex = "<client response headers can match this regex pattern>"
  76. Suffix = "<client response headers must end with the value>"
  77. DynamicMetadataFromHeaders = [
  78. Contains = "<authorization response headers must contain this value>",
  79. Exact = "<authorization response headers can only be this value>",
  80. IgnoreCase = false,
  81. Prefix = "<authorization response headers must begin with this value>",
  82. SafeRegex = "<authorization response headers can match this regex pattern>"
  83. Suffix = "<authorization response headers must end with the value>"
  84. ]
  85. IncludePeerCertificate = false
  86. MetadataContextNamespaces = [
  87. "<metadata namespace>"
  88. ]
  89. StatusOnError = 403 // HTTP only
  90. StatPrefix = "response"
  91. WithRequestBody = { //HTTP only
  92. MaxRequestBytes = <uint32 value specifying the max size of the message body>
  93. AllowPartialMessage = false
  94. PackAsBytes = false

Specification

This section provides details about the fields you can configure for the external authorization extension.

Name

Specifies the name of the extension. Must be set to builtin/ext-authz.

Values

  • Default: None
  • This field is required.
  • Data type: String value set to builtin/ext-authz.

Arguments

Contains the global configuration for the extension.

Values

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

Arguments.ProxyType

Specifies the type of Envoy proxy that this extension applies to. The extension only applies to proxies that match this type and is ignored for all other proxy types. The only supported value is connect-proxy.

Values

  • Default: connect-proxy
  • This field is required.
  • Data type: String

Arguments.InsertOptions

Specifies options for defining the insertion point for the external authorization filter in the Envoy filter chain. By default, the external authorization filter is inserted as the first filter in the filter chain per the default setting for the Location field.

Values

  • Default: None
  • Data type: Map

Arguments.InsertOptions.Location

Specifies the insertion point for the external authorization filter in the Envoy filter chain. You can specify one of the following string values:

  • First: Inserts the filter as the first filter in the filter chain, regardless of the filter specified in the FilterName field.
  • BeforeLast: Inserts the filter before the last filter in the chain, regardless of the filter specified in the FilterName field. This allows the filter to be inserted after all other filters and immediately before the terminal filter.
  • AfterFirstMatch: Inserts the filter after the first filter in the chain that has a name matching the value of the FilterName field.
  • AfterLastMatch: Inserts the filter after the last filter in the chain that has a name matching the value of the FilterName field.
  • BeforeFirstMatch: Inserts the filter before the first filter in the chain that has a name matching the value of the FilterName field.
  • BeforeLastMatch: Inserts the filter before the last filter in the chain that has a name matching the value of the FilterName field.

Values

  • Default: BeforeFirstMatch
  • Data type: String

Arguments.InsertOptions.FilterName

Specifies the name of an existing filter in the chain to match when inserting the external authorization filter. Specifying a filter name enables you to configure an insertion point relative to the position of another filter in the chain.

Values

  • Default: envoy.filters.network.tcp_proxy for TCP services. envoy.filters.http.router for HTTP services.
  • Data type: String

Arguments.Config

Contains the configuration settings for the extension.

Values

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

Arguments.Config.BootstrapMetadataLabelsKey

Specifies a key from the Envoy bootstrap metadata. Envoy adds labels associated with the key to the authorization request context.

Values

  • Default: None
  • Data type: String

Arguments.Config.ClearRouteCache

Directs Envoy to clear the route cache so that the external authorization service correctly affects routing decisions. If set to true, the filter clears all cached routes.

Envoy also clears cached routes if the status returned from the authorization service is 200 for HTTP responses or 0 for gRPC responses. Envoy also clears cached routes if at least one authorization response header is added to the client request or is used for altering another client request header.

Values

  • Default: false
  • Data type: Boolean

Arguments.Config.GrpcService

Specifies the external authorization configuration for gRPC requests. Configure the GrpcService or the HttpService settings, but not both.

Values

  • Default: None
  • Either the GrpcService or the HttpService configuration is required.
  • Data type: Map

Arguments.Config.GrpcService.Target

Configuration for specifying the service to send gRPC authorization requests to. The Target field may contain the following fields:

Values

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

Arguments{}.Config{}.GrpcService{}.Target{}.Service{}

Specifies the upstream external authorization service. Configure this field when authorization requests are sent to an upstream service within the service mesh. The service must be configured as an upstream of the service that the filter is applied to.

Configure either the Service field or the Uri field, but not both.

Values

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

The following table describes how to configure parameters for the Service field:

ParameterDescriptionData typeDefault
NameSpecifies the name of the upstream service.StringNone
NamespaceEnterprise Specifies the Consul namespace that the upstream service belongs to.Stringdefault
PartitionEnterprise Specifies the Consul admin partition that the upstream service belongs to.Stringdefault

Arguments.Config.GrpcService.Target.Uri

Specifies the URI of the external authorization service. Configure this field when you must provide an explicit URI to the external authorization service, such as cases in which the authorization service is running on the same host or pod. If set, the value of this field must be one of localhost:<port>, 127.0.0.1:<port>, or ::1:<port>.

Configure either the Uri field or the Service field, but not both.

Values

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

Arguments.Config.GrpcService.Target.Timeout

Specifies the maximum duration that a response can take to arrive upon request.

Values

  • Default: 1s
  • Data type: String

Arguments.Config.GrpcService.Authority

Specifies the authority header to send in the gRPC request. If this field is not set, the authority field is set to the cluster name. This field does not override the SNI that Envoy sends to the external authorization service.

Values

  • Default: Cluster name
  • Data type: String

Arguments.Config.GrpcService.InitialMetadata[]

Specifies additional metadata to include in streams initiated to the GrpcService. You can specify metadata for injecting additional ad-hoc authorization headers, for example, x-foo-bar: baz-key. For more information, including details on header value syntax, refer to the Envoy documentation on custom request headers.

Values

  • Default: None

  • Data type: List of one or more key-value pairs:

    • KEY: String
    • VALUE: String

Arguments{}.Config{}.HttpService{}

Contains the configuration for raw HTTP communication between the filter and the external authorization service. Configure the HttpService or the GrpcService settings, but not both.

Values

  • Default: None
  • Either the HttpService or the GrpcService configuration is required.
  • Data type: Map

Arguments{}.Config{}.HttpService{}.Target{}

Configuration for specifying the service to send HTTP authorization requests to. The Target field may contain the following fields:

Values

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

Arguments{}.Config{}.HttpService{}.Target{}.Service{}

Specifies the upstream external authorization service. Configure this field when HTTP authorization requests are sent to an upstream service within the service mesh. The service must be configured as an upstream of the service that the filter is applied to.

Configure either the Service field or the Uri field, but not both.

Values

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

The following table describes how to configure parameters for the Service field:

ParameterDescriptionData typeDefault
NameSpecifies the name of the upstream service.StringNone
NamespaceEnterprise Specifies the Consul namespace that the upstream service belongs to.Stringdefault
PartitionEnterprise Specifies the Consul admin partition that the upstream service belongs to.Stringdefault

Arguments{}.Config{}.HttpService{}.Target{}.Uri

Specifies the URI of the external authorization service. Configure this field when you must provide an explicit URI to the external authorization service, such as cases in which the authorization service is running on the same host or pod. If set, the value of this field must be one of localhost:<port>, 127.0.0.1:<port>, or ::1:<port>.

Configure either the Uri field or the Service field, but not both.

Values

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

Arguments{}.Config{}.HttpService{}.Target{}.Timeout

Specifies the maximum duration that a response can take to arrive upon request.

Values

  • Default: 1s
  • Data type: String

Arguments{}.Config{}.HttpService{}.PathPrefix

Specifies a prefix for the value of the authorization request header Path. You must include the preceding forward slash (/).

Values

  • Default: None
  • Data type: String

Arguments{}.Config{}.HttpService{}.AuthorizationRequest{}

HTTP-only configuration that controls the HTTP authorization request metadata. The AuthorizationRequest field may contain the following parameters:

Values

  • Default: None
  • Data type: Map

Arguments{}.Config{}.HttpService{}.AuthorizationRequest{}.AllowHeaders[]

Specifies a set of rules for matching client request headers. The request to the external authorization service includes any client request headers that satisfy any of the rules. Refer to the Envoy documentation for a detailed explanation.

Values

  • Default: None
  • Data type: List of key-value pairs

The following table describes the matching rules you can configure in the AllowHeaders field:

RuleDescriptionData typeDefault
ContainsSpecifies a string that the input string must contain.StringN/A
ExactSpecifies a string that the input string must match exactly.StringN/A
IgnoreCaseDirects Envoy to ignore capitalization. If set to true, the other matching rules in the configuration are not case sensitive. This rule does not affect SafeRegex.Booleanfalse
PrefixSpecifies a string that the input string must begin with.StringN/A
SafeRegexSpecifies a regular expression for matching the input string programmatically. Envoy supports Google’s RE2 regex engine.StringN/A
SuffixSpecifies a string that the input string must end with.StringN/A

Arguments{}.Config{}.HttpService{}.AuthorizationRequest{}.HeadersToAdd[]

Specifies a list of headers to include in the request to the authorization service. Note that Envoy overwrites client request headers with the same key.

Values

  • Default: None

  • Data type: List of one or more key-value pairs:

    • KEY: String
    • VALUE: String

Arguments{}.Config{}.HttpService{}.AuthorizationResponse{}

HTTP-only configuration that controls HTTP authorization response metadata. The AuthorizationResponse field may contain the following parameters:

Values

  • Default: None
  • Data type: Map

Arguments{}.Config{}.HttpService{}.AuthorizationResponse{}.AllowedUpstreamHeaders[]

Specifies a set of rules for matching authorization response headers. Envoy adds any headers from the external authorization service to the client response that satisfy the rules. Envoy overwrites existing headers.

Values

  • Default: None
  • Data type: Map

The following table describes the matching rules you can configure in the AllowedUpstreamHeaders field:

RuleDescriptionData typeDefault
ContainsSpecifies a string that the input string must contain.StringN/A
ExactSpecifies a string that the input string must match exactly.StringN/A
IgnoreCaseDirects Envoy to ignore capitalization. If set to true, the other matching rules in the configuration are not case sensitive. This rule does not affect SafeRegex.Booleanfalse
PrefixSpecifies a string that the input string must begin with.StringN/A
SafeRegexSpecifies a regular expression for matching the input string programmatically. Envoy supports Google’s RE2 regex engine.StringN/A
SuffixSpecifies a string that the input string must end with.StringN/A

Arguments{}.Config{}.HttpService{}.AuthorizationResponse{}.AllowedUpstreamHeadersToAppend[]

Specifies a set of rules for matching authorization response headers. Envoy appends any headers from the external authorization service to the client response that satisfy the rules. Envoy appends existing headers.

Values

  • Default: None
  • Data type: Map

The following table describes the matching rules you can configure in the AllowedUpstreamHeadersToAppend field:

RuleDescriptionData typeDefault
ContainsSpecifies a string that the input string must contain.StringN/A
ExactSpecifies a string that the input string must match exactly.StringN/A
IgnoreCaseDirects Envoy to ignore capitalization. If set to true, the other matching rules in the configuration are not case sensitive. This rule does not affect SafeRegex.Booleanfalse
PrefixSpecifies a string that the input string must begin with.StringN/A
SafeRegexSpecifies a regular expression for matching the input string programmatically. Envoy supports Google’s RE2 regex engine.StringN/A
SuffixSpecifies a string that the input string must end with.StringN/A

Arguments{}.Config{}.HttpService{}.AuthorizationResponse{}.AllowedClientHeaders[]

Specifies a set of rules for matching client response headers. Envoy adds any headers from the external authorization service to the client response that satisfy the rules. When the list is not set, Envoy includes all authorization response headers except Authority (Host). When a header is included in this list, Envoy automatically adds the following headers:

Values

  • Default: None
  • Data type: Map

The following table describes the matching rules you can configure in the AllowedClientHeaders field:

RuleDescriptionData typeDefault
ContainsSpecifies a string that the input string must contain.StringN/A
ExactSpecifies a string that the input string must match exactly.StringN/A
IgnoreCaseDirects Envoy to ignore capitalization. If set to true, the other matching rules in the configuration are not case sensitive. This rule does not affect SafeRegex.Booleanfalse
PrefixSpecifies a string that the input string must begin with.StringN/A
SafeRegexSpecifies a regular expression for matching the input string programmatically. Envoy supports Google’s RE2 regex engine.StringN/A
SuffixSpecifies a string that the input string must end with.StringN/A

Arguments{}.Config{}.HttpService{}.AuthorizationResponse{}.AllowedClientHeadersOnSuccess[]

Specifies a set of rules for matching client response headers. Envoy adds headers from the external authorization service to the client response when the headers satisfy the rules and the authorization is successful. If the headers match the rules but the authorization fails or is denied, the headers are not added. If this field is not set, Envoy does not add any additional headers to the client’s response on success.

Values

  • Default: None
  • Data type: Map

The following table describes the matching rules you can configure in the AllowedClientHeadersOnSuccess field:

RuleDescriptionData typeDefault
ContainsSpecifies a string that the input string must contain.StringN/A
ExactSpecifies a string that the input string must match exactly.StringN/A
IgnoreCaseDirects Envoy to ignore capitalization. If set to true, the other matching rules in the configuration are not case sensitive. This rule does not affect SafeRegex.Booleanfalse
PrefixSpecifies a string that the input string must begin with.StringN/A
SafeRegexSpecifies a regular expression for matching the input string programmatically. Envoy supports Google’s RE2 regex engine.StringN/A
SuffixSpecifies a string that the input string must end with.StringN/A

Arguments{}.Config{}.HttpService{}.AuthorizationResponse{}.DynamicMetadataFromHeaders[]

Specifies a set of rules for matching authorization response headers. Envoy emits headers from the external authorization service as dynamic metadata that the next filter in the chain can consume.

Values

  • Default: None
  • Data type: Map

The following table describes the matching rules you can configure in the DynamicMetadataFromHeaders field:

RuleDescriptionData typeDefault
ContainsSpecifies a string that the input string must contain.StringN/A
ExactSpecifies a string that the input string must match exactly.StringN/A
IgnoreCaseDirects Envoy to ignore capitalization. If set to true, the other matching rules in the configuration are not case sensitive. This rule does not affect SafeRegex.Booleanfalse
PrefixSpecifies a string that the input string must begin with.StringN/A
SafeRegexSpecifies a regular expression for matching the input string programmatically. Envoy supports Google’s RE2 regex engine.StringN/A
SuffixSpecifies a string that the input string must end with.StringN/A

Arguments{}.Config{}.IncludePeerCertificate

If set to true, Envoy includes the peer X.509 certificate in the authorization request if the certificate is available.

Values

  • Default: false
  • Data type: Boolean

Arguments{}.Config{}.MetadataContextNamespace[]

HTTP only field that specifies a list of metadata namespaces. The values of the namespaces are included in the authorization request context. The consul namespace is always included in addition to the namespaces you configure.

Values

  • Default: ["consul"]
  • Data type: List of string values

Arguments{}.Config{}.StatusOnError

HTTP only field that specifies a return code status to respond with on error. Refer to the Envoy documentation for additional information.

Values

  • Default: 403
  • Data type: Integer

Arguments{}.Config{}.StatPrefix

Specifies a prefix to add when writing statistics.

Values

  • Default: response
  • Data type: String

Arguments{}.Config{}.WithRequestBody{}

HTTP only field that configures Envoy to buffer the client request body and send it with the authorization request. If unset, the request body is not sent with the authorization request.

Values

  • Default: None
  • Data type: Map

The following table describes the parameters that you can include in the WithRequestBody field:

ParameterDescriptionData typeDefault
MaxRequestBytesSpecifies the maximum size of the message body that the filter holds in memory. Envoy returns HTTP 403 and does not initiate the authorization process when the buffer reaches the number set in this field unless AllowPartialMessage is set to true.uint32None
AllowPartialMessageIf set to true, Envoy buffers the request body until the value of MaxRequestBytes is reached. The authorization request is dispatched with a partial body and no 413 HTTP error returns by the filter.Booleanfalse
PackAsBytesIf set to true, Envoy sends the request body to the external authorization as raw bytes. Otherwise, Envoy sends the request body as a UTF-8 encoded string.Booleanfalse

Examples

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

Authorize gRPC requests to a URI

In the following example, a service defaults configuration entry contains an ext-authz configuration. The configuration allows the api service to make gRPC authorization requests to a service at localhost:9191:

  1. Kind = "service-defaults"
  2. Name = "api"
  3. EnvoyExtensions = [
  4. {
  5. Name = "builtin/ext-authz"
  6. Arguments = {
  7. ProxyType = "connect-proxy"
  8. Config = {
  9. GrpcService = {
  10. Target = {
  11. URI = "127.0.0.1:9191"
  12. }
  13. }
  14. }
  15. }
  16. }
  17. ]

Upstream authorization

In the following example, a service defaults configuration entry contains an ext-authz configuration. The configuration allows the api service to make gRPC authorization requests to a service named authz:

  1. Kind = "service-defaults"
  2. Name = "api"
  3. EnvoyExtensions = [
  4. {
  5. Name = "builtin/ext-authz"
  6. Arguments = {
  7. ProxyType = "connect-proxy"
  8. Config = {
  9. GrpcService = {
  10. Target = {
  11. Service = {
  12. Name = "authz"
  13. }
  14. }
  15. }
  16. }
  17. }
  18. }
  19. ]

Authorization requests after service intentions for Consul Enterprise

In the following example for Consul Enterprise, the api service is configured to make an HTTP authorization requests to a service named authz in the foo namespace and bar partition. Envoy also inserts the external authorization filter after the envoy.filters.http.rbac filter:

  1. Kind = "service-defaults"
  2. Name = "api"
  3. Protocol = "http"
  4. EnvoyExtensions = [
  5. {
  6. Name = "builtin/ext-authz"
  7. Arguments = {
  8. ProxyType = "connect-proxy"
  9. InsertOptions = {
  10. Location = "AfterLastMatch"
  11. FilterName = "envoy.filters.http.rbac"
  12. }
  13. Config = {
  14. HttpService = {
  15. Target = {
  16. Service = {
  17. Name = "authz"
  18. Namespace = "foo"
  19. Partition = "bar"
  20. }
  21. }
  22. }
  23. }
  24. }
  25. }
  26. ]