MeshTrafficPermission (beta)

This policy uses new policy matching algorithm and is in beta state, it should not be mixed with TrafficPermission.

TargetRef support matrix

TargetRef typetop leveltofrom
Mesh
MeshSubset
MeshService
MeshServiceSubset

If you don’t understand this table you should read matching docs.

Configuration

Action

Kuma allows configuring one of 3 actions for a group of service’s clients:

  • ALLOW - allows incoming requests matching the from targetRef.
  • DENY - denies incoming requests matching the from targetRef
  • ALLOW_WITH_SHADOW_DENY - same as ALLOW but will log as if request is denied, this is useful for rolling new restrictive policies without breaking things.

Examples

Service ‘payments’ allows requests from ‘orders’

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTrafficPermission
  3. metadata:
  4. namespace: kuma-system
  5. name: allow-orders
  6. spec:
  7. targetRef: # 1
  8. kind: MeshService
  9. name: payments
  10. from:
  11. - targetRef: # 2
  12. kind: MeshService
  13. name: orders
  14. default: # 3
  15. action: ALLOW
  1. type: MeshTrafficPermission
  2. name: allow-orders
  3. mesh: default
  4. spec:
  5. targetRef: # 1
  6. kind: MeshService
  7. name: payments
  8. from:
  9. - targetRef: # 2
  10. kind: MeshService
  11. name: orders
  12. default: # 3
  13. action: ALLOW

Explanation

  1. Top level targetRef selects data plane proxies that implement payments service. MeshTrafficPermission allow-orders will be configured on these proxies.

    1. targetRef: # 1
    2. kind: MeshService
    3. name: payments
  2. TargetRef inside the from array selects proxies that implement order service. These proxies will be subjected to the action from default.action.

    1. - targetRef: # 2
    2. kind: MeshService
    3. name: orders
  3. The action is ALLOW. All requests from service orders will be allowed on service payments.

    1. default: # 3
    2. action: ALLOW

Deny all

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTrafficPermission
  3. metadata:
  4. namespace: kuma-system
  5. name: deny-all
  6. spec:
  7. targetRef: # 1
  8. kind: Mesh
  9. from:
  10. - targetRef: # 2
  11. kind: Mesh
  12. default: # 3
  13. action: DENY
  1. type: MeshTrafficPermission
  2. name: deny-all
  3. mesh: default
  4. spec:
  5. targetRef: # 1
  6. kind: Mesh
  7. from:
  8. - targetRef: # 2
  9. kind: Mesh
  10. default: # 3
  11. action: DENY

Explanation

  1. Top level targetRef selects all proxies in the mesh.

    1. targetRef: # 1
    2. kind: Mesh
  2. TargetRef inside the from array selects all clients.

    1. - targetRef: # 2
    2. kind: Mesh
  3. The action is DENY. All requests from all services will be denied on all proxies in the default mesh.

    1. default: # 3
    2. action: DENY

Allow requests from zone ‘us-east’, deny requests from ‘dev’ environment

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshTrafficPermission
  3. metadata:
  4. namespace: kuma-system
  5. name: example-with-tags
  6. spec:
  7. targetRef: # 1
  8. kind: Mesh
  9. from:
  10. - targetRef: # 2
  11. kind: MeshSubset
  12. tags:
  13. kuma.io/zone: us-east
  14. default: # 3
  15. action: ALLOW
  16. - targetRef: # 4
  17. kind: MeshSubset
  18. tags:
  19. env: dev
  20. default: # 5
  21. action: DENY

Apply the configuration with kubectl apply -f [..].

  1. type: MeshTrafficPermission
  2. name: example-with-tags
  3. mesh: default
  4. spec:
  5. targetRef: # 1
  6. kind: Mesh
  7. from:
  8. - targetRef: # 2
  9. kind: MeshSubset
  10. tags:
  11. kuma.io/zone: us-east
  12. default: # 3
  13. action: ALLOW
  14. - targetRef: # 4
  15. kind: MeshSubset
  16. tags:
  17. env: dev
  18. default: # 5
  19. action: DENY

Apply the configuration with kumactl apply -f [..] or with the HTTP API.

Explanation

  1. Top level targetRef selects all proxies in the mesh.

    1. targetRef: # 1
    2. kind: Mesh
  2. TargetRef inside the from array selects proxies that have label kuma.io/zone: us-east. These proxies will be subjected to the action from default.action.

    1. - targetRef: # 2
    2. kind: MeshSubset
    3. tags:
    4. kuma.io/zone: us-east
  3. The action is ALLOW. All requests from the zone us-east will be allowed on all proxies.

    1. default: # 3
    2. action: ALLOW
  4. TargetRef inside the from array selects proxies that have tags kuma.io/zone: us-east. These proxies will be subjected to the action from default.action.

    1. - targetRef: # 4
    2. kind: MeshSubset
    3. tags:
    4. env: dev
  5. The action is DENY. All requests from the env dev will be denied on all proxies.

    1. default: # 5
    2. action: DENY

Order of rules inside the from array matters. Request from the proxy that has both kuma.io/zone: east and env: dev will be denied. This is because the rule with DENY is later in the from array than any ALLOW rules.