Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

AuthPolicy: remove hosts from authscheme #217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eguzki
Copy link
Contributor

@eguzki eguzki commented Sep 27, 2022

what

  • Implementation of "hosts field not exposed in the AuthPolicy"

Fixes Kuadrant/kuadrant-operator#97

  • Adding e2e tests
  • Fix documentation authpolicy examples

verification steps

Setup env

make local-setup

Create HTTPRoute for *.toystore.com

kubectl apply -f - <<EOF
---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: HTTPRoute
metadata:
  name: toystore
  labels:
    app: toystore
spec:
  parentRefs:
    - name: istio-ingressgateway
      namespace: istio-system
  hostnames: ["*.toystore.com"]
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: "/toy"
          method: GET
      backendRefs:
        - name: toystore
          port: 80
EOF

Create a kuadrant AuthPolicy in which one of the rules the hosts field is missing

kubectl apply -f - <<EOF
---
apiVersion: apim.kuadrant.io/v1alpha1
kind: AuthPolicy
metadata:
  name: toystore
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: toystore
  rules:
  - hosts: ["*.admin.toystore.com"]
    methods: ["DELETE", "POST"]
    paths: ["/admin*"]
  - methods: ["DELETE", "POST"]
    paths: ["/private*"]
  authScheme:
    identity:
    - name: friends
      apiKey:
        selector:
          matchLabels:        
            group: friends
      credentials:
        in: authorization_header
        keySelector: APIKEY
EOF

Check that the authconfig object's hosts is set to the route's hostnames

k get authconfig ap-default-toystore -n kuadrant-system  -o jsonpath='{.spec.hosts}'
["*.toystore.com"]

Check that the Istio's authorizationpolicy's rules' hosts all fall under route's hostnames

k get authorizationpolicy on-istio-ingressgateway-using-toystore -n istio-system -o yaml | yq e -P
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  creationTimestamp: "2022-09-27T15:26:18Z"
  generation: 1
  name: on-istio-ingressgateway-using-toystore
  namespace: istio-system
  resourceVersion: "8945"
  uid: 353aa299-97a9-4459-a293-20d03d1185d3
spec:
  action: CUSTOM
  provider:
    name: kuadrant-authorization
  rules:
    - to:
        - operation:
            hosts:
              - '*.admin.toystore.com'
            methods:
              - DELETE
              - POST
            paths:
              - /admin*
        - operation:
            hosts:
              - '*.toystore.com'
            methods:
              - DELETE
              - POST
            paths:
              - /private*
  selector: {}

@eguzki eguzki requested a review from a team September 27, 2022 15:31
Copy link
Contributor

@guicassolato guicassolato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. In fact, I need parts of this to make progress on https://github.com/Kuadrant/kuadrant-controller/issues/183, so thanks!

Slightly aside, let's make sure this change, as well as any other upcoming PRs in the next days, are in sync with Kuadrant/kuadrant-operator#48. Maybe we should archive this repo first and only then start working on the merge of its code into https://github.com/Kuadrant/kuadrant-operator?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hosts field not exposed in the AuthPolicy
2 participants