Skip to content

Instantly share code, notes, and snippets.

@allenlsy
Created February 13, 2020 19:12
Show Gist options
  • Save allenlsy/e996789543e927025e8646bb0fa9e8d0 to your computer and use it in GitHub Desktop.
Save allenlsy/e996789543e927025e8646bb0fa9e8d0 to your computer and use it in GitHub Desktop.
Istio Authz Policy debug log

Case 1:

  • Expected: Authorize HTTP requests with header required1=expected1 AND required2=expected2
  • Actual: Any header is allowed.

AuthorizationPolicy:

spec:
  selector:
    matchLabels:
      app: fortioserver
  rules:
  - when:
    - key: request.headers[required1]
      values: ["expected1"]
    - key: request.headers[required2]
      values: ["expected2"]

Envoy config dump from workload:


             "name": "envoy.filters.http.rbac",
             "typed_config": {
              "@type": "type.googleapis.com/envoy.config.filter.http.rbac.v2.RBAC",
              "rules": {
               "policies": {
                "ns[airmesh-test-authz-allen]-policy[httpheader-multi-and]-rule[0]": {
                 "permissions": [
                  {
                   "and_rules": {
                    "rules": [
                     {
                      "any": true
                     }
                    ]
                   }
                  }
                 ],
                 "principals": [
                  {
                   "and_ids": {
                    "ids": [
                     {
                      "header": {
                       "name": "required1",
                       "exact_match": "expected1"
                      }
                     },
                     {
                      "header": {
                       "name": "required2",
                       "exact_match": "expected2"
                      }
                     }
                    ]
                   }
                  }
                 ]
                }
               }
              }
             }
            }

Case 2:

  • Expected: Authorize gRPC calls to fgrpc.PingServer.Ping with principal cluster.local/ns/test-authz-allen/sa/grpc-alpha
  • Actual: All gRPC calls are denied

AuthorizationPolicy:

  selector:
    matchLabels:
      app: fortioserver
  rules:
  - from:
    - source:
        principals: ["cluster.local/ns/test-authz-allen/sa/grpc-alpha"]
    to:
    - operation:
        methods: ["fgrpc.PingServer.Ping"]

Envoy config dump from workload:

            {
             "name": "envoy.filters.http.rbac",
             "typed_config": {
              "@type": "type.googleapis.com/envoy.config.filter.http.rbac.v2.RBAC",
              "rules": {
               "policies": {
                "ns[test-authz-allen]-policy[grpc-source-method-single]-rule[0]": {
                 "permissions": [
                  {
                   "and_rules": {
                    "rules": [
                     {
                      "or_rules": {
                       "rules": [
                        {
                         "header": {
                          "name": ":method",
                          "exact_match": "fgrpc.PingServer.Ping"
                         }
                        }
                       ]
                      }
                     }
                    ]
                   }
                  }
                 ],
                 "principals": [
                  {
                   "and_ids": {
                    "ids": [
                     {
                      "or_ids": {
                       "ids": [
                        {
                         "metadata": {
                          "filter": "istio_authn",
                          "path": [
                           {
                            "key": "source.principal"
                           }
                          ],
                          "value": {
                           "string_match": {
                            "exact": "cluster.local/ns/test-authz-allen/sa/grpc-alpha"
                           }
                          }
                         }
                        }
                       ]
                      }
                     }
                    ]
                   }
                  }
                 ]
                }
               }
              }
             }
            },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment