# istio_allow-full-in.yaml
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: allow
  namespace: cfg
spec:
  action: ALLOW
  rules:
  - from:
    - source:
        principals: [ "principal", "principal-prefix-*", "*-suffix-principal", "*" ]
        notPrincipals: [ "not-principal", "not-principal-prefix-*", "*-suffix-not-principal", "*" ]
  - from:
    - source:
        serviceAccounts: [ "ns/sa", "sa-only" ]
        notServiceAccounts: [ "ns/sa-not", "sa-not-only" ]
  - from:
    - source:
        requestPrincipals: [ "requestPrincipals", "requestPrincipals-prefix-*", "*-suffix-requestPrincipals", "*" ]
        notRequestPrincipals: [ "not-requestPrincipals", "not-requestPrincipals-prefix-*", "*-suffix-not-requestPrincipals", "*" ]
  - from:
    - source:
        namespaces: [ "ns", "ns-prefix-*", "*-ns-suffix", "*" ]
        notNamespaces: [ "not-ns", "not-ns-prefix-*", "*-not-ns-suffix", "*" ]
  - from:
    - source:
        ipBlocks: [ "1.2.3.4", "5.6.0.0/16" ]
        notIpBlocks: [ "2.2.3.4", "6.6.0.0/16" ]
  - from:
    - source:
        remoteIpBlocks: [ "1.2.3.4", "5.6.0.0/16" ]
        notRemoteIpBlocks: [ "2.2.3.4", "6.6.0.0/16" ]
  - to:
    - operation:
        methods: ["method", "method-prefix-*", "*-suffix-method", "*"]
        notMethods: ["not-method", "not-method-prefix-*", "*-suffix-not-method", "*"]
  - to:
    - operation:
        hosts: ["exact.com", "*.suffix.com", "prefix.*", "*"]
        notHosts: ["not-exact.com", "*.not-suffix.com", "not-prefix.*", "*"]
  - to:
    - operation:
        ports: ["80", "90"]
        notPorts: ["800", "900"]
  - to:
    - operation:
        paths: ["/exact", "/prefix/*", "*/suffix", "*"]
        notPaths: ["/not-exact", "/not-prefix/*", "*/not-suffix", "*"]
  - when:
    - key: "request.headers[X-header]"
      values: ["header", "header-prefix-*", "*-suffix-header", "*"]
      notValues: ["not-header", "not-header-prefix-*", "*-not-suffix-header", "*"]
  - when:
    - key: "source.ip"
      values: ["10.10.10.10", "192.168.10.0/24"]
      notValues: ["90.10.10.10", "90.168.10.0/24"]
  - when:
    - key: "remote.ip"
      values: ["10.10.10.10", "192.168.10.0/24"]
      notValues: ["90.10.10.10", "90.168.10.0/24"]
  - when:
    - key: "source.namespace"
      values: ["ns", "ns-prefix-*", "*-ns-suffix", "*"]
      notValues: ["not-ns", "not-ns-prefix-*", "*-not-ns-suffix", "*"]
  - when:
    - key: "source.principal"
      values: ["principal", "principal-prefix-*", "*-suffix-principal", "*"]
      notValues: ["not-principal", "not-principal-prefix-*", "*-not-suffix-principal", "*"]
  - when:
    - key: "request.auth.principal"
      values: ["requestPrincipals", "requestPrincipals-prefix-*", "*-suffix-requestPrincipals", "*"]
      notValues: ["not-requestPrincipals", "not-requestPrincipals-prefix-*", "*-not-suffix-requestPrincipals", "*"]
  - when:
    - key: "request.auth.audiences"
      values: ["audiences", "audiences-prefix-*", "*-suffix-audiences", "*"]
      notValues: ["not-audiences", "not-audiences-prefix-*", "*-not-suffix-audiences", "*"]
  - when:
    - key: "request.auth.presenter"
      values: ["presenter", "presenter-prefix-*", "*-suffix-presenter", "*"]
      notValues: ["not-presenter", "not-presenter-prefix-*", "*-not-suffix-presenter", "*"]
  - when:
    - key: "request.auth.claims[iss]"
      values: ["iss", "iss-prefix-*", "*-suffix-iss", "*"]
      notValues: ["not-iss", "not-iss-prefix-*", "*-not-suffix-iss", "*"]
  - when:
    - key: "request.auth.claims[nested1][nested2]"
      values: ["nested", "nested-prefix-*", "*-suffix-nested", "*"]
      notValues: ["not-nested", "not-nested-prefix-*", "*-not-suffix-nested", "*"]
  - when:
    - key: "destination.ip"
      values: ["10.10.10.10", "192.168.10.0/24"]
      notValues: ["90.10.10.10", "90.168.10.0/24"]
  - when:
    - key: "destination.port"
      values: ["91", "92"]
      notValues: ["9001", "9002"]
  - when:
    - key: "connection.sni"
      values: ["exact.com", "*.suffix.com", "prefix.*", "*"]
      notValues: ["not-exact.com", "*.not-suffix.com", "not-prefix.*", "*"]
  - when:
    - key: "experimental.envoy.filters.a.b[c]"
      values: ["exact", "prefix-*", "*-suffix", "*"]
      notValues: ["not-exact", "not-prefix-*", "*-not-suffix", "*"]