Skip to content

Add ext-authz route example #13111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,56 @@ The external authorizer is now ready to be used by the authorization policy.

You can now apply another authorization policy for the sample `ext-authz` server to control who is allowed to access it.

## Route with external authorization
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
## Route with external authorization
## Route with external authorization

Copy link
Contributor

Choose a reason for hiding this comment

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

(required to fix lint error.)

You can create a VirtualService to route your service based on external authorization headers.

1. Deploy a VirtualService `ext-authz-route`:

The following command applies a VirtualService that route all traffic to `/headers` containing a `x-ext-authz` header with value `allow` to a route, and route the rest of the traffic to `/headers` to another route.

{{< text bash >}}
$ kubectl apply -n foo -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ext-authz-route
spec:
hosts:
- httpbin.foo.svc.cluster.local
http:
- match:
- uri:
exact: "/headers"
headers:
X-Ext-Authz:
exact: allow
rewrite:
uri: "/base64/cm91dGUtYWxsb3c="
route:
- destination:
host: httpbin.foo.svc.cluster.local
- route:
- destination:
host: httpbin.foo.svc.cluster.local
rewrite:
uri: "/base64/cm91dGUtZGVueQ=="
EOF
{{< /text >}}

1. Verify a request to path `/headers` with header `x-ext-authz: allow` routes to `/base64/cm91dGUtYWxsb3c=`:

{{< text bash >}}
$ kubectl exec "$(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name})" -c sleep -n foo -- curl "http://httpbin.foo:8000/headers" -H "x-ext-authz: allow" -s
route-allow
{{< /text >}}

1. Verify a request to path `/headers` with header `x-ext-authz: deny` routes to `/base64/cm91dGUtZGVueQ==`:

{{< text bash >}}
$ kubectl exec "$(kubectl get pod -l app=sleep -n foo -o jsonpath={.items..metadata.name})" -c sleep -n foo -- curl "http://httpbin.foo:8000/headers" -H "x-ext-authz: deny" -s
route-deny
{{< /text >}}

## Clean up

1. Remove the namespace `foo` from your configuration:
Expand Down