Security policy examples

    The policies demonstrated here are just examples and and require changes to adapt to your actual environment before applying.

    Also read the and authorization tasks for a hands-on tutorial of using the security policy in more detail.

    JWT validation is common on the ingress gateway and you may want to require different JWT issuers for different hosts. You can use the authorization policy for fine grained JWT validation in addition to the policy.

    The following two policies enable strict mTLS on namespace foo, and allow traffic from the same namespace.

    1. apiVersion: security.istio.io/v1beta1
    2. kind: PeerAuthentication
    3. metadata:
    4. name: default
    5. namespace: foo
    6. spec:
    7. mtls:
    8. mode: STRICT
    9. ---
    10. kind: AuthorizationPolicy
    11. metadata:
    12. name: foo-isolation
    13. namespace: foo
    14. spec:
    15. action: ALLOW
    16. rules:
    17. - from:
    18. namespaces: ["foo"]

    The following two policies enable strict mTLS on namespace foo, and allow traffic from the same namespace and also from the ingress gateway.

    You have configured PeerAuthentication to STRICT but want to make sure the traffic is indeed protected by mTLS with an extra check in the authorization layer, i.e., defense in depth.

    1. apiVersion: security.istio.io/v1beta1
    2. kind: AuthorizationPolicy
    3. metadata:
    4. name: require-mtls
    5. namespace: foo
    6. action: DENY
    7. rules:
    8. - from:
    9. - source:
    10. notPrincipals: ["*"]

    You can use the DENY policy if you want to require mandatory authorization check that must be satisfied and cannot be bypassed by another more permissive policy. This works because the DENY policy takes precedence over the ALLOW policy and could deny a request early before ALLOW policies.

    Use the following policy to enforce mandatory JWT validation in addition to the request authentication policy. The policy denies the request if the request principal is empty. The request principal will be empty if JWT validation failed. In other words, the policy allows requests if the request principal is non-empty. “*” means non-empty match and using with notRequestPrincipals means matching on empty request principal.

    Similarly, Use the following policy to require mandatory namespace isolation and also allow requests from ingress gateway. The policy denies the request if the namespace is not foo and the principal is not cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account. In other words, the policy allows the request only if the namespace is foo or the principal is cluster.local/ns/istio-system/sa/istio-ingressgateway-service-account.

    1. apiVersion: security.istio.io/v1beta1
    2. kind: AuthorizationPolicy
    3. metadata:
    4. name: ns-isolation-except-ingress
    5. namespace: foo
    6. spec:
    7. action: DENY
    8. rules:
    9. - from:
    10. - source: