Service intentions configuration entry reference

This topic provides reference information for the service intentions configuration entry. Intentions are configurations for controlling access between services in the service mesh. A single service intentions configuration entry specifies one destination service and one or more L4 traffic sources, L7 traffic sources, or combination of traffic sources. Refer to Service mesh intentions overview for additional information.

Configuration model

The following outline shows how to format the service intentions configuration entry. Click on a property name to view details about the configuration.

Complete configuration

When every field is defined, a service intentions configuration entry has the following form:

  1. Kind = "service-intentions"
  2. Name = "<name of destination service>"
  3. Namespace = "<destination namespace>" # string
  4. Partition = "<destination partition>" # string
  5. Meta = {
  6. "<key-1>" = "<value-1>"
  7. "<key-2>" = "<value-2>"
  8. }
  9. JWT = {
  10. Providers = [
  11. {
  12. Name = "<JWT-provider-name>"
  13. VerifyClaims = [
  14. {
  15. Path = ["<claim>"]
  16. Value = "<api.apps.organization.com>"
  17. }
  18. ]
  19. }
  20. ]
  21. }
  22. Sources = [
  23. {
  24. Name = "<name of service sending traffic>" # string
  25. Peer = "<name of cluster containing source service>" # string
  26. Namespace = "<namespace containing source service>" # string
  27. Partition = "<sources-partition>" # string
  28. SamenessGroup = "<group-name>" # string
  29. Action = "allow" or "deny" # string for L4 intentions
  30. Permissions = [
  31. {
  32. Action = "allow" or "deny" # string for L7 intenions
  33. HTTP = {
  34. PathExact = "<exact path to match>" # string
  35. PathPrefix = "<path prefix to match>" # string
  36. PathRegex = "<regex pattern to match>" # string
  37. Methods = [
  38. "<fist http method to match>", # string
  39. "<second http method to match>"
  40. ]
  41. Header = [
  42. {
  43. Name = "<http header name>" # string
  44. Present = <true or false> # boolean
  45. },
  46. {
  47. Name = "<http header name>" # string
  48. Exact = "<header-value>" # boolean
  49. },
  50. {
  51. Name = "<http header name>" # string
  52. Prefix = "<source header value prefix>" # string
  53. },
  54. {
  55. Name = "<http header name>" # string
  56. Suffix = "<source header value suffix>" # string
  57. },
  58. {
  59. Name = "<http header name>" # string
  60. Regex = "<regex pattern to match>" # string
  61. Invert = <true or false> # boolean
  62. }
  63. ]
  64. }
  65. }
  66. ]
  67. Type = "consul" # string
  68. Description = "<description for API responses>" # string
  69. Precedence = <read-only> # number
  70. LegacyID = <read-only> # string
  71. LegacyMeta = <read-only> # string
  72. LegacyCreateTime = <read-only> # string
  73. LegacyUpdateTime = <read-only> # string
  74. }
  75. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: <name of destination service>
  5. namespace: <destination namespace>
  6. spec:
  7. destination:
  8. name: <name of destination service>
  9. namespace: <destination namespace>
  10. jwt:
  11. providers:
  12. name: <JWT-provider-name>
  13. verifyClaims:
  14. path: [<aud>]
  15. value: <api.apps.organization.com>
  16. sources:
  17. name: <name of service sending traffic>
  18. peer: <name of cluster containing source service>
  19. namespace: <namespace containing source service>
  20. partition: <sources-partition>
  21. samenessGroup: <group-name>
  22. action: allow or deny
  23. permissions:
  24. - action: allow or deny
  25. http:
  26. pathExact: <exact path to match>
  27. pathPrefix: <path prefix to match>
  28. pathRegex: <regex pattern to match>
  29. methods:
  30. - <fist http method to match>
  31. <second http method to match>
  32. header:
  33. - name: <http header name>
  34. present: true
  35. - name: <http header name>
  36. exact: false
  37. - name: <http header name>
  38. prefix: <source header value prefix>
  39. - name: <http header name>
  40. suffix: <source header value suffix>
  41. - name: <http header name>
  42. regex: <regex pattern to match>
  43. invert: false
  44. description: <description for API responses>
  1. {
  2. "Kind":"service-intentions",
  3. "Name":"<name of destination service>",
  4. "Namespace":"<destination namespace>",
  5. "Partition":"<destination partition>",
  6. "Meta":{
  7. "key-1":"<value-1>",
  8. "key-2":"<value-2>"
  9. },
  10. "JWT": {
  11. "Providers": [
  12. {
  13. "Name": "<JWT-provider-name>",
  14. "VerifyClaims": [
  15. {
  16. "Path": ["<aud>"],
  17. "Value": "<api.apps.organization.com>"
  18. }
  19. ]
  20. }
  21. ]
  22. },
  23. "Sources":[
  24. {
  25. "Name":"<name of service sending traffic>",
  26. "Peer":"<name of cluster containing source service>",
  27. "Namespace":"<namespace containing source service>",
  28. "Partition":"<sources-partition>",
  29. "SamenessGroup":"<group-name>",
  30. "Action":"allow or deny",
  31. "Permissions":[
  32. {
  33. "Action":"allow or deny",
  34. "HTTP":{
  35. "PathExact":"<exact path to match>",
  36. "PathPrefix":"<path prefix to match>",
  37. "PathRegex":"<regex pattern to match>",
  38. "Methods":[
  39. "<fist http method to match>",
  40. "<second http method to match>"
  41. ],
  42. "Header":[
  43. {
  44. "Name":"<http header name>",
  45. "Present":true
  46. },
  47. {
  48. "Name":"<http header name>",
  49. "Exact":false
  50. },
  51. {
  52. "Name":"<http header name>",
  53. "Prefix":"<source header value prefix>"
  54. },
  55. {
  56. "Name":"<http header name>",
  57. "Suffix":"<source header value suffix>"
  58. },
  59. {
  60. "Name":"<http header name>",
  61. "Regex":"<regex pattern to match>",
  62. "Invert":false
  63. }
  64. ]
  65. }
  66. }
  67. ],
  68. "Type":"consul",
  69. "Description":"<description for API responses>",
  70. "Precedence":"<read-only-number>",
  71. "LegacyID":"<read-only-string>",
  72. "LegacyMeta":"<read-only-string>",
  73. "LegacyCreateTime":"<read-only-string>",
  74. "LegacyUpdateTime":"<read-only-string>"
  75. }
  76. ]
  77. }

Specification

This section provides details about the fields you can configure in the service intentions configuration entry.

Kind

Specifies the type of configuration entry to implement. Must be set to service-intentions.

Values

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

Name

Specifies a name of the destination service for all intentions defined in the configuration entry.

Values

  • Default: Defaults to the name of the node after writing the entry to the Consul server.
  • This field is required.
  • Data type: String

You can also specify a wildcard character (*) to match all services without intentions. Intentions that are applied with a wildcard, however, are not supported when defining L7 Permissions.

Namespace EnterpriseService intentions - 图11Enterprise

Specifies the namespace that the configuration entry applies to. Services in the namespace are the traffic destinations that the intentions allow or deny traffic to.

Values

  • Default: default
  • Data type: String

You can also specify a wildcard character (*) to match all namespaces. Intentions that are applied with a wildcard, however, are not supported when defining L7 Permissions.

Partition EnterpriseService intentions - 图12Enterprise

Specifies the admin partition to apply the configuration entry. Services in the specified partition are the traffic destinations that the intentions allow or deny traffic to.

Values

  • Default: default
  • Data type: String

Meta

Specifies key-value pairs to add to the KV store when the configuration entry is evaluated.

Values

  • Default: None
  • Data type: Map of one or more key-value pairs
    • keys: String
    • values: String, integer, or float

JWT

Specifies a JSON Web Token provider configured in a JWT provider configuration entry, as well as additional configurations for verifying a service’s JWT before authorizing communication between services

Values

JWT{}.Providers

Specifies the names of one or more previously configured JWT provider configuration entries, which include the information necessary to validate a JSON web token.

Values

  • Default: None
  • Data type: List of maps

JWT{}.Providers[].Name

Specifies the name of a JWT provider defined in the Name field of the jwt-provider configuration entry. You must write the JWT Provider to Consul before referencing it in a service intention.

Values

  • Default: None
  • Data type: String

JWT{}.Providers[].VerifyClaims

Specifies additional token information to verify beyond what is configured in the JWT provider configuration entry. This map takes the form of a JSON web token claim and a value to match for verification.

Values

  • Default: None

  • Data type: List of maps that can contain the following parameters:

JWT{}.Providers[].VerifyClaims[].Path

Specifies the path to the claim in the JSON web token. For more information about JWT claims, refer to the IETF standards documentation.

Values

  • Default: None
  • Data type: List of strings

JWT{}.Providers[].VerifyClaims.Value

Specifies the value to match on when verifying the the claim designated in JWT{}.Providers[].VerifyClaims[].Path.

Values

  • Default: None
  • Data type: String

Sources[]

List of configurations that define intention sources and the authorization granted to the sources. You can specify source configurations in any order, but Consul stores and evaluates them in order of reverse precedence at runtime. Refer to Precedence for additional information.

Values

Sources[].Name

Specifies the name of the source that the intention allows or denies traffic from. If Type is set to consul, then the value refers to the name of a Consul service. The source is not required to be registered into the Consul catalog.

Values

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

Sources[].Peer

Specifies the name of a peered Consul cluster that the intention allows or denies traffic from. Refer to Cluster peering overview for additional information about peers.

The Peer and Partition fields are mutually exclusive.

Values

  • Default: None
  • Data type: String

Sources[].Namespace EnterpriseService intentions - 图16Enterprise

Specifies the traffic source namespace that the intention allows or denies traffic from.

Values

  • Default: If Peer is unspecified, defaults to the destination Namespace.
  • Data type: String

Sources[].Partition EnterpriseService intentions - 图17Enterprise

Specifies the name of an admin partition that the intention allows or denies traffic from. Refer to Admin Partitions for additional information about partitions.

The Peer and Partition fields are mutually exclusive.

Values

  • Default: If Peer is unspecified, defaults to the destination Partition.
  • Data type: string

Sources[].SamenessGroup EnterpriseService intentions - 图18Enterprise

Specifies the name of a sameness group that the intention allows or denies traffic from. Refer to create samenes groups for additional information.

Values

  • Default: None
  • Data type: string

Sources[].Action

Specifies the action to take when the source sends traffic to the destination service. The value is either allow or deny. Do not configure this field to apply L7 intentions to the same source. Configure the Permissions field instead.

Values

  • Default: None
  • This field is required for L4 intentions.
  • Data type: String value set to either allow or deny

Refer to the following examples for additional guidance:

Sources[].Permissions[]

Specifies a list of permissions for L7 traffic sources. The list contains one or more actions and a set of match criteria for each action.

Consul applies permissions in the order specified in the configuration. Beginning at the top of the list, Consul applies the first matching request and stops evaluating against the remaining configurations.

For requests that do not match any of the defined permissions, Consul applies the intention behavior defined in the acl_default_policy configuration.

Do not configure this field for L4 intentions. Use the Sources.Action parameter instead.

The Permissions only applies to services with a compatible protocol. Permissions are not supported when the Name or Namespace field is configured with a wildcard because service instances or services in a namespace may use different protocols.

Values

  • Default: None
  • List of objects that contain the following fields:

Refer to the following examples for additional guidance:

Sources[].Permissions[].Action

Specifies the action to take when the source sends traffic to the destination service. The value is either allow or deny.

Values

  • Default: None
  • This field is required.
  • Data type: String value set to either allow or deny.

Sources[].Permissions[].HTTP

Specifies a set of HTTP-specific match criteria. Consul applies the action defined in the Action field to source traffic that matches the criteria.

Values

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

The following table describes the parameters that the HTTP map may contain:

ParameterDescriptionData typeDefault
PathExactSpecifies an exact path to match on the HTTP request path. Do not specify PathExact if PathPrefix or PathRegex are configured in the same HTTP configuration.stringnone
PathPrefixSpecifies a path prefix to match on the HTTP request path. Do not specify PathPrefix if PathExact or PathRegex are configured in the same HTTP configuration.stringnone
PathRegexDefines a regular expression to match on the HTTP request path. Do not specify PathRegex if PathExact or PathPrefix are configured in the same HTTP configuration. The regex syntax is proxy-specific. If using Envoy, refer to the re2 documentation for details.stringnone
MethodsSpecifies a list of HTTP methods. Consul applies the permission if a request matches the PathExact, PathPrefix, PathRegex, or Header, and the source sent the request using one of the specified methods. Refer to the Mozilla documentation for a list of supported request headers.listAll request methods
HeaderSpecifies a header name and matching criteria for HTTP request headers. Refer to Sources[].Permissions[].HTTP[].Header for details.list of mapsnone

Sources[].Permissions[].HTTP[].Header[]

Specifies a header name and matching criteria for HTTP request headers. The request header must match all specified criteria for the permission to apply.

Values

  • Default: None
  • Data type: list of objects

Each member of the Header list is a map that contains a Name field and at least one match criterion. The following table describes the parameters that each member of the Header list may contain:

ParameterDescriptionData typeRequired
NameSpecifies the name of the header to match.stringrequired
PresentEnables a match if the header configured in the Name field appears in the request. Consul matches on any value as long as the header key appears in the request. Do not specify Present if Exact, Prefix, Suffix, or Regex are configured in the same Header configuration.booleanoptional
ExactSpecifies a value for the header key set in the Name field. If the request header value matches the Exact value, Consul applies the permission. Do not specify Exact if Present, Prefix, Suffix, or Regex are configured in the same Header configuration.stringoptional
PrefixSpecifies a prefix value for the header key set in the Name field. If the request header value starts with the Prefix value, Consul applies the permission. Do not specify Prefix if Present, Exact, Suffix, or Regex are configured in the same Header configuration.stringoptional
SuffixSpecifies a suffix value for the header key set in the Name field. If the request header value ends with the Suffix value, Consul applies the permission. Do not specify Suffix if Present, Exact, Prefix, or Regex are configured in the same Header configuration.stringoptional
RegexSpecifies a regular expression pattern as the value for the header key set in the Name field. If the request header value matches the regex, Consul applies the permission. Do not specify Regex if Present, Exact, Prefix, or Suffix are configured in the same Header configuration. The regex syntax is proxy-specific. If using Envoy, refer to the re2 documentation for details.stringoptional
InvertInverts the matching logic configured in the Header. Default is false.booleanoptional

Sources[].Precedence

The Precedence field contains a read-only integer. Consul generates the value based on name configurations for the source and destination services. Refer to Precedence and matching order for additional information.

Sources[].Type

Specifies the type of destination service that the configuration entry applies to. The only value supported is consul.

Values

  • Default: consul
  • Data type: String

Sources[].Description

Specifies a description of the intention. Consul presents the description in API responses to assist other tools integrated into the network.

Values

  • Default: None
  • Data type: String

Sources[].LegacyID

Read-only unique user ID (UUID) for the intention in the system. Consul generates the value and exposes it in the configuration entry so that legacy API endpoints continue to function. Refer to Read Specific Intention by ID for additional information.

Sources[].LegacyMeta

Read-only set of arbitrary key-value pairs to attach to the intention. Consul generates the metadata and exposes it in the configuration entry so that legacy intention API endpoints continue to function. Refer to Read Specific Intention by ID for additional information.

Sources[].CreateTime

Read-only timestamp for the intention creation. Consul exposes the timestamp in the configuration entry to allow legacy intention API endpoints to continue functioning. Refer to Read Specific Intention by ID for additional information.

Sources[].LegacyUpdateTime

Read-only timestamp marking the most recent intention update. Consul exposes the timestamp in the configuration entry to allow legacy intention API endpoints to continue functioning. Refer to Read Specific Intention by ID for additional information.

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 ServiceIntentions.

Values

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

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 an arbitrary name for the configuration entry. Note that in other configuration entries, the metadata.name field specifies the name of the service that the settings apply to. For service intentions, the service that accepts the configurations is the destination and is specified in the spec.destination.name field. Refer to the following topics for additional information:

Values

  • Default: None
  • Data type: String

metadata.namespace EnterpriseService intentions - 图19Enterprise

Specifies the namespace that the configuration entry applies to. Refer to Consul Enterprise for information about how Consul namespaces map to Kubernetes Namespaces. Open source Consul distributions (Consul OSS) ignore the metadata.namespace configuration.

Values

  • Default: default
  • Data type: String

spec

Map that contains the details about the ServiceIntentions 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.destination

Map that identifies the destination name and destination namespace that source services are allowed or denied access to.

Values

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

spec.destination.name

Specifies the name of the destination service in the mesh that the intentions apply to. You can also specify a wildcard character (*) to match all services that are missing intention settings. Intentions that are applied with a wildcard, however, are not supported when defining L7 permissions.

Values

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

spec.jwt

Specifies a JSON Web Token provider configured in a JWT provider configuration entry, as well as additional configurations for verifying a service’s JWT before authorizing communication between services

Values

spec.jwt.providers

Specifies the names of one or more previously configured JWT provider configuration entries, which include the information necessary to validate a JSON web token.

Values

  • Default: None
  • Data type: List of maps

spec.jwt.providers[].name

Specifies the name of a JWT provider defined in the metadata.name field of the JWT provider configuration entry. You must write the JWT Provider to Consul before referencing it in a service intention.

Values

  • Default: None
  • Data type: String

spec.jwt.providers[].verifyClaims

Specifies additional token information to verify beyond what is configured in the JWT provider configuration entry. This map takes the form of a JSON web token claim and a value to match for verification.

Values

  • Default: None

  • Data type: List of maps that can contain the following parameters:

spec.jwt.providers[].verifyClaims[].path

Specifies the path to the claim in the JSON web token. For more information about JWT claims, refer to the IETF standards documentation.

Values

  • Default: None
  • Data type: List of strings

spec.jwt.providers[].verifyClaims[].value

Specifies the value to match on when verifying the the claim designated in JWT{}.Providers[].VerifyClaims[].Path.

Values

  • Default: None
  • Data type: String

spec.sources[]

List of configurations that define intention sources and the authorization granted to the sources. You can specify source configurations in any order, but Consul stores and evaluates them in order of reverse precedence at runtime.

Values

spec.sources[].name

Specifies the name of the source that the intention allows or denies traffic from. If type is set to consul, then the value refers to the name of a Consul service. The source is not required to be registered into the Consul catalog.

Values

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

spec.sources[].peer

Specifies the name of a peered Consul cluster that the intention allows or denies traffic from. Refer to Cluster peering overview for additional information about peers. The peer and partition fields are mutually exclusive.

Values

  • Default: None
  • Data type: String

spec.sources[].namespace EnterpriseService intentions - 图23Enterprise

Specifies the traffic source namespace that the intention allows or denies traffic from.

Values

spec.sources[].partition EnterpriseService intentions - 图24Enterprise

Specifies the name of an admin partition that the intention allows or denies traffic from. Refer to Admin Partitions for additional information about partitions. The peer and partition fields are mutually exclusive.

Values

spec.sources[].samenessGroup EnterpriseService intentions - 图25Enterprise

Specifies the name of a sameness group that the intention allows or denies traffic from. Refer to create samenes groups for additional information.

Values

  • Default: None
  • Data type: string

spec.sources[].action

Specifies the action to take when the source sends traffic to the destination service. The value is either allow or deny. Do not configure this field for L7 intentions. Configure the spec.sources.permissions field instead.

Values

  • Default: None
  • This field is required for L4 intentions.
  • Data type: String value set to either allow or deny

spec.sources[].permissions[]

Specifies a list of permissions for L7 traffic sources. The list contains one or more actions and a set of match criteria for each action.

Consul applies permissions in the order specified in the configuration. Starting at the beginning of the list, Consul applies the first matching request and stops evaluating against the remaining configurations.

For requests that do not match any of the defined permissions, Consul applies the intention behavior defined in the acl_default_policy configuration.

Do not configure this field for L4 intentions. Use the spec.sources.action parameter instead.

permissions configurations only apply to services with a compatible protocol. As a result, they are not supported when the spec.destination.name or spec.destination.namespace field is configured with a wildcard because service instances or services in a namespace may use different protocols.

Values

  • Default: None
  • List of objects that contain the following fields:

spec.sources[].permissions[].action

Specifies the action to take when the source sends traffic to the destination service. The value is either allow or deny.

Values

  • Default: None
  • This field is required.
  • Data type: String value set to either allow or deny

spec.sources[].permissions[].http

Specifies a set of HTTP-specific match criteria. Consul applies the action defined in the spec.sources.permissions.action field to source traffic that matches the criteria.

Values

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

The following table describes the parameters that the HTTP map may contain:

ParameterDescriptionData typeDefault
pathExactSpecifies an exact path to match on the HTTP request path. Do not specify pathExact if pathPrefix or pathRegex are configured in the same http configuration.stringnone
pathPrefixSpecifies a path prefix to match on the HTTP request path. Do not specify pathPrefix if pathExact or pathRegex are configured in the same http configuration.stringnone
pathRegexDefines a regular expression to match on the HTTP request path. Do not specify pathRegex if pathExact or pathPrefix are configured in the same http configuration. The regex syntax is proxy-specific. If using Envoy, refer to the re2 documentation for details.stringnone
methodsSpecifies a list of HTTP methods. Consul applies the permission if a request matches the pathExact, pathPrefix, pathRegex, or header, and the source sent the request using one of the specified methods. Refer to the Mozilla documentation for a list of supported request headers.listAll request methods
headerSpecifies a header name and matching criteria for HTTP request headers. Refer to spec.sources[].permissions[].http[].header for details.list of mapsnone

spec.sources[].permissions[].http[].header

Specifies a set of criteria for matching HTTP request headers. The request header must match all specified criteria for the permission to apply.

Values

  • Default: None
  • Data type: List of maps

Each member of the header list is a map that contains a name field and at least one match criterion. The following table describes the parameters that each member of the header list may contain:

ParameterDescriptionData typeRequired
nameSpecifies the name of the header to match.stringrequired
presentEnables a match if the header configured in the name field appears in the request. Consul matches on any value as long as the header key appears in the request. Do not specify present if exact, prefix, suffix, or regex are configured in the same header configuration.booleanoptional
ExactSpecifies a value for the header key set in the Name field. If the request header value matches the exact value, Consul applies the permission. Do not specify exact if present, prefix, suffix, or regex are configured in the same header configuration.stringoptional
prefixSpecifies a prefix value for the header key set in the name field. If the request header value starts with the prefix value, Consul applies the permission. Do not specify prefix if present, exact, suffix, or regex are configured in the same header configuration.stringoptional
suffixSpecifies a suffix value for the header key set in the name field. If the request header value ends with the suffix value, Consul applies the permission. Do not specify suffix if present, exact, prefix, or regex are configured in the same header configuration.stringoptional
regexSpecifies a regular expression pattern as the value for the header key set in the name field. If the request header value matches the regex, Consul applies the permission. Do not specify regex if present, exact, prefix, or suffix are configured in the same header configuration. The regex syntax is proxy-specific. If using Envoy, refer to the re2 documentation for details.stringoptional
invertInverts the matching logic configured in the header. Default is false.booleanoptional

spec.sources[].type

Specifies the type of destination service that the configuration entry applies to. The only value supported is consul.

Values

  • Default: consul
  • Data type: String

spec.sources[].description

Specifies a description of the intention. Consul presents the description in API responses to assist other tools integrated into the network.

Values

  • Default: None
  • Data type: String

Examples

The following examples demonstrate potential use-cases for the service intentions configuration entry.

L4 Intentions for specific sources and destinations

The following example configuration entry specifies an L4 intention that denies traffic from web to db service instances, but allows traffic from api to db.

  1. Kind = "service-intentions"
  2. Name = "db"
  3. Sources = [
  4. {
  5. Name = "web"
  6. Action = "deny"
  7. },
  8. {
  9. Name = "api"
  10. Action = "allow"
  11. }
  12. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: db
  5. spec:
  6. destination:
  7. name: db
  8. sources:
  9. - name: web
  10. action: deny
  11. - name: api
  12. action: allow
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "db",
  4. "Sources": [
  5. {
  6. "Action": "deny",
  7. "Name": "web"
  8. },
  9. {
  10. "Action": "allow",
  11. "Name": "api"
  12. }
  13. ]
  14. }

L4 intentions for all destinations

In the following L4 example, the destination is configured with a * wildcard. As a result, traffic from web service instances is denied for any service in the datacenter.

  1. Kind = "service-intentions"
  2. Name = "*"
  3. Sources = [
  4. {
  5. Name = "web"
  6. Action = "deny"
  7. }
  8. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: web-deny-all
  5. spec:
  6. destination:
  7. name: *
  8. sources:
  9. - name: web
  10. action: deny
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "*",
  4. "Sources": [
  5. {
  6. "Action": "deny",
  7. "Name": "web"
  8. }
  9. ]
  10. }

L4 intentions for all sources

In the following L4 example, the source is configured with a * wildcard. As a result, traffic from any service is denied to db service instances.

  1. Kind = "service-intentions"
  2. Name = "db"
  3. Sources = [
  4. {
  5. Name = "*"
  6. Action = "deny"
  7. }
  8. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: db
  5. spec:
  6. destination:
  7. name: db
  8. sources:
  9. - name: *
  10. action: deny
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "db",
  4. "Sources": [
  5. {
  6. "Action": "deny",
  7. "Name": "*"
  8. }
  9. ]
  10. }

REST access

In the following example, the admin-dashboard and report-generator services have different levels of access when making REST calls:

  1. Kind = "service-intentions"
  2. Name = "api"
  3. Sources = [
  4. {
  5. Name = "admin-dashboard"
  6. Permissions = [
  7. {
  8. Action = "allow"
  9. HTTP {
  10. PathPrefix = "/v2"
  11. Methods = ["GET", "PUT", "POST", "DELETE", "HEAD"]
  12. }
  13. }
  14. ]
  15. },
  16. {
  17. Name = "report-generator"
  18. Permissions = [
  19. {
  20. Action = "allow"
  21. HTTP {
  22. PathPrefix = "/v2/widgets"
  23. Methods = ["GET"]
  24. }
  25. }
  26. ]
  27. }
  28. # NOTE: a default catch-all based on the default ACL policy will apply to
  29. # unmatched connections and requests. Typically this will be DENY.
  30. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: api
  5. spec:
  6. destination:
  7. name: api
  8. sources:
  9. - name: admin-dashboard
  10. permissions:
  11. - action: allow
  12. http:
  13. pathPrefix: /v2
  14. methods: ['GET', 'PUT', 'POST', 'DELETE', 'HEAD']
  15. - name: report-generator
  16. permissions:
  17. - action: allow
  18. http:
  19. pathPrefix: /v2/widgets
  20. methods: ['GET']
  21. # NOTE: a default catch-all based on the default ACL policy will apply to
  22. # unmatched connections and requests. Typically this will be DENY.
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "api",
  4. "Sources": [
  5. {
  6. "Name": "admin-dashboard",
  7. "Permissions": [
  8. {
  9. "Action": "allow",
  10. "HTTP": {
  11. "PathPrefix": "/v2",
  12. "Methods": ["GET", "PUT", "POST", "DELETE", "HEAD"]
  13. }
  14. }
  15. ]
  16. },
  17. {
  18. "Name": "report-generator",
  19. "Permissions": [
  20. {
  21. "Action": "allow",
  22. "HTTP": {
  23. "PathPrefix": "/v2/widgets",
  24. "Methods": ["GET"]
  25. }
  26. }
  27. ]
  28. }
  29. ]
  30. }

gRPC

In the following example, Consul denies requests from frontend-web to the IssueRefund gRPC service. Because gRPC method calls use the HTTP/2 protocol, you can apply an HTTP path-matching rule to control traffic:

  1. Kind = "service-intentions"
  2. Name = "billing"
  3. Sources = [
  4. {
  5. Name = "frontend-web"
  6. Permissions = [
  7. # The frontend website can execute all billing service methods except
  8. # issuing refunds.
  9. {
  10. Action = "deny"
  11. HTTP {
  12. PathExact = "/mycompany.BillingService/IssueRefund"
  13. }
  14. },
  15. {
  16. Action = "allow"
  17. HTTP {
  18. PathPrefix = "/mycompany.BillingService/"
  19. }
  20. }
  21. ]
  22. },
  23. {
  24. Name = "support-portal"
  25. Permissions = [
  26. # But the support team portal page can execute all methods.
  27. {
  28. Action = "allow"
  29. HTTP {
  30. PathPrefix = "/mycompany.BillingService/"
  31. }
  32. }
  33. ]
  34. }
  35. # A default catch-all based on the default ACL policy applies to
  36. # unmatched connections and requests. This is typically DENY.
  37. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: billing
  5. spec:
  6. destination:
  7. name: billing
  8. sources:
  9. # The frontend website can execute all billing service methods except
  10. # issuing refunds.
  11. - name: frontend-web
  12. permissions:
  13. - action: deny
  14. http:
  15. pathExact: /mycompany.BillingService/IssueRefund
  16. - action: allow
  17. http:
  18. pathPrefix: '/mycompany.BillingService/'
  19. - name: support-protocol
  20. # But the support team portal page can execute all methods.
  21. permissions:
  22. - action: allow
  23. http:
  24. pathPrefix: '/mycompany.BillingService/'
  25. # A default catch-all based on the default ACL policy applies to
  26. # unmatched connections and requests. This is typically DENY.
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "billing",
  4. "Sources": [
  5. {
  6. "Name": "frontend-web",
  7. "Permissions": [
  8. {
  9. "Action": "deny",
  10. "HTTP": {
  11. "PathExact": "/mycompany.BillingService/IssueRefund"
  12. }
  13. },
  14. {
  15. "Action": "allow",
  16. "HTTP": {
  17. "PathPrefix": "/mycompany.BillingService/"
  18. }
  19. }
  20. ]
  21. },
  22. {
  23. "Name": "support-portal",
  24. "Permissions": [
  25. {
  26. "Action": "allow",
  27. "HTTP": {
  28. "PathPrefix": "/mycompany.BillingService/"
  29. }
  30. }
  31. ]
  32. }
  33. ]
  34. }

L4 and L7

In the following example, Consul enforces application layer intentions that deny requests to api from hackathon-project but allow requests from web. In the same configuration entry, Consul enforces network layer intentions that allow requests from nightly-reconciler that send POST requests to the /v1/reconcile-data HTTP endpoint:

  1. Kind = "service-intentions"
  2. Name = "api"
  3. Sources = [
  4. {
  5. Name = "hackathon-project"
  6. Action = "deny"
  7. },
  8. {
  9. Name = "web"
  10. Action = "allow"
  11. },
  12. {
  13. Name = "nightly-reconciler"
  14. Permissions = [
  15. {
  16. Action = "allow"
  17. HTTP {
  18. PathExact = "/v1/reconcile-data"
  19. Methods = ["POST"]
  20. }
  21. }
  22. ]
  23. },
  24. # A default catch-all based on the default ACL policy applies to
  25. # unmatched connections and requests. This is typically DENY.
  26. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: api
  5. spec:
  6. destination:
  7. name: api
  8. sources:
  9. - name: hackathon-project
  10. action: deny
  11. - name: web
  12. action: allow
  13. - name: nightly-reconciler
  14. permissions:
  15. - action: allow
  16. http:
  17. pathExact: /v1/reconcile-data
  18. methods: ['POST']
  19. # A default catch-all based on the default ACL policy applies to
  20. # unmatched connections and requests. This is typically DENY.
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "api",
  4. "Sources": [
  5. {
  6. "Name": "hackathon-project",
  7. "Action": "deny"
  8. },
  9. {
  10. "Name": "web",
  11. "Action": "allow"
  12. },
  13. {
  14. "Name": "nightly-reconciler",
  15. "Permissions": [
  16. {
  17. "Action": "allow",
  18. "HTTP": {
  19. "PathExact": "/v1/reconcile-data",
  20. "Methods": ["POST"]
  21. }
  22. }
  23. ]
  24. }
  25. ]
  26. }

Cluster peering

When using cluster peering connections, intentions secure your deployments with authorized service-to-service communication between remote datacenters. In the following example, the service intentions configuration entry authorizes the backend-service to communicate with the frontend-service that is hosted on remote peer cluster-02:

  1. Kind = "service-intentions"
  2. Name = "backend-service"
  3. Sources = [
  4. {
  5. Name = "frontend-service"
  6. Peer = "cluster-02"
  7. Action = "allow"
  8. }
  9. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: backend-deny
  5. spec:
  6. destination:
  7. name: backend
  8. sources:
  9. - name: "*"
  10. action: deny
  11. - name: frontend
  12. action: allow
  13. peer: cluster-01 ## The peer of the source service
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "backend-service",
  4. "Sources": [
  5. {
  6. "Name": "frontend-service",
  7. "Peer": "cluster-02",
  8. "Action": "allow"
  9. }
  10. ]
  11. }

JWT validation with intentions

The following example configures a service intention that evaluates requests when a service named backend receives a request from the frontend service. When the request is sent to the /admin HTTP path, a JSON Web Token provided by Okta is evaluated. In addition to the validation requirements in a separate JWT provider configuration entry, an additional check occurs to confirm that the token has either a perms or role claim with the admin value. If it does, the request is authorized.

Because the intention allows requests that come from the / HTTP path, only requests on the /admin path are subject to token validation.

  1. Kind = "service-intentions"
  2. Name = "backend"
  3. Sources = [
  4. {
  5. Name = "frontend"
  6. Permissions = [
  7. {
  8. HTTP = {
  9. PathExact = "/admin"
  10. }
  11. JWT = {
  12. Providers = [
  13. {
  14. Name = "okta"
  15. VerifyClaims = [
  16. {
  17. Path = ["perms", "role"]
  18. Value = "admin"
  19. }
  20. ]
  21. }
  22. ]
  23. }
  24. },
  25. {
  26. Action = "allow"
  27. HTTP = {
  28. PathPrefix = "/"
  29. }
  30. }
  31. ]
  32. }
  33. ]
  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceIntentions
  3. metadata:
  4. name: backend
  5. spec:
  6. sources:
  7. name: frontend
  8. permissions:
  9. http:
  10. pathExact: /admin
  11. jwt:
  12. providers:
  13. name: okta
  14. verifyClaims:
  15. path:
  16. - perms
  17. - role
  18. value: admin
  19. action: allow
  20. http:
  21. pathPrefix: /
  1. {
  2. "Kind": "service-intentions",
  3. "Name": "backend",
  4. "Sources": [
  5. {
  6. "Name": "frontend",
  7. "Permissions": [
  8. {
  9. "HTTP": {
  10. "PathExact": "/admin"
  11. },
  12. "JWT": {
  13. "Providers": [
  14. {
  15. "Name": "okta",
  16. "VerifyClaims": [
  17. {
  18. "Path": ["perms", "role"],
  19. "Value": "admin"
  20. }
  21. ]
  22. }
  23. ]
  24. }
  25. },
  26. {
  27. "Action": "allow",
  28. "HTTP": {
  29. "PathPrefix": "/"
  30. }
  31. }
  32. ]
  33. }
  34. ]
  35. }