Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 36 ยท Security and mTLS

Authorization Policies

Write Istio AuthorizationPolicy rules that allow or deny requests by identity, namespace, method, path and JWT claim, and learn how ALLOW and DENY are evaluated.

mTLS tells a workload who is calling. An AuthorizationPolicy decides whether that caller is allowed to do what it is asking. Policies are enforced by the destination's proxy, on every request, using the identity from the certificate (and optionally the end-user's JWT). This is how you express "only web may call catalog, and only with GET".

YAML is read-only. The evaluator in the stand-ins follows Istio's documented order but is a simplification (it ignores CUSTOM actions and many fields).

A first policy

YAML
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: catalog-allow-web
  namespace: shop
spec:
  selector:
    matchLabels:
      app: catalog
  action: ALLOW
  rules:
    - from:
        - source:
            principals: ["cluster.local/ns/shop/sa/web"]
      to:
        - operation:
            methods: ["GET"]
            paths: ["/api/*"]
      when:
        - key: request.headers[x-tenant]
          notValues: [""]

Parts:

  • selector picks the workloads protected; without it the policy covers the whole namespace (or, in the root namespace, the whole mesh).
  • action: ALLOW, DENY, AUDIT or CUSTOM (delegate the decision to an external authorizer). The default is ALLOW.
  • rules: a list of alternatives. A request matches a rule when all of its from, to and when parts match. Inside each field, listed values are alternatives.
  • from.source: principals (mTLS identities), namespaces, ipBlocks, requestPrincipals (from a JWT).
  • to.operation: methods, paths, hosts, ports.
  • when: extra conditions on attributes such as headers, JWT claims (request.auth.claims[group]) or source IP.

Every field also has a not form (notPrincipals, notPaths...).

How policies are evaluated

The order is fixed:

  1. If any CUSTOM policy matches, the external authorizer decides; a denial ends evaluation.
  2. If any DENY policy matches the request, it is denied.
  3. If there are no ALLOW policies for the workload, the request is allowed.
  4. If any ALLOW policy matches, the request is allowed.
  5. Otherwise it is denied.

(AUDIT policies only record; they never change the outcome.)

flowchart TD
    S["Request arrives"] --> D{"Matches a DENY policy?"}
    D -- yes --> X["Denied (403)"]
    D -- no --> A{"Any ALLOW policy applies to this workload?"}
    A -- no --> OK["Allowed"]
    A -- yes --> M{"Matches one ALLOW rule?"}
    M -- yes --> OK
    M -- no --> X

The moment one ALLOW policy exists for a workload, anything not matched by an ALLOW rule is rejected.

Two consequences:

  • Default deny is created by an ALLOW policy with an empty spec: no rules, so nothing matches. Then you add ALLOW policies for each permitted path.
  • DENY always beats ALLOW, so use it for must-never rules such as "nobody outside shop may reach /admin".
YAML
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: default-deny
  namespace: shop
spec: {}

An empty spec with no selector applies to every workload in shop and allows nothing.

What a denial looks like

The proxy answers HTTP requests with 403 RBAC: access denied. For TCP traffic the connection is reset. Remember that plain-text callers have no identity, so a rule with principals can never match them: authorization based on identity requires mTLS (mTLS and Peer Authentication) for the caller.

Policy design tips

  • Start with default deny per namespace, then open specific paths.
  • Use service accounts, not IP blocks: IPs change, identities do not.
  • Use AUDIT first to see what a new policy would affect (it logs to a configured provider), or apply a new DENY in a test namespace.
  • Keep policies small and named for intent: catalog-allow-web, payments-deny-external.
  • For L7 rules (methods, paths) in ambient mode, remember a waypoint is required (see Ambient Mode: ztunnel and Waypoints).

Stand-ins

Python Stand-in: the DENY / ALLOW evaluation order

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: path patterns in operations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A workload has no AuthorizationPolicy at all. What happens to requests?

    With no policies Istio allows traffic; policy only restricts once one exists.
  2. 2. Which policy makes a namespace default-deny?

    An ALLOW policy with no rules matches nothing, so every request lacks an allow and is rejected.
  3. 3. A request matches both a DENY policy and an ALLOW policy. The result is:

    DENY policies are evaluated first and always win.
  4. 4. Why can a principals rule never match a plain-text caller?

    Identity comes from the peer certificate, which only exists with mTLS.

Summary

  • AuthorizationPolicy decides what an authenticated caller may do, per workload, namespace or mesh.
  • Actions: ALLOW, DENY, AUDIT, CUSTOM. DENY wins; if any ALLOW exists, unmatched requests are denied.
  • An empty ALLOW policy creates default deny.
  • Match on principals (service accounts), namespaces, methods, paths, hosts, ports and conditions.
  • Identity rules require mTLS from the caller.

Next: Request Authentication and JWTs