Hello
I use Istio + Keycloack + oauth2-proxy for client auth(n/z). It works well using CUSTOM action. However I also need to setup direct access to api endpoint using only JWT validation: now I have the following config:
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: myapp-redirect-keycloak
spec:
selector:
matchLabels:
app: myapp
action: CUSTOM
provider:
name: oauth2-proxy
rules:
- to:
- operation:
notPaths: ["/static/*","/api/*"]
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: myapp-require-jwt
spec:
selector:
matchLabels:
app: myapp
action: ALLOW
rules:
- from:
- source:
requestPrincipals: ["*"]
- to:
- operation:
paths: ["/static/*"]
---
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: myapp-keycloak-staging
spec:
selector:
matchLabels:
app: myapp
jwtRules:
- issuer: redacted
jwksUri: redacted
fromHeaders:
- name: x-auth-request-access-token
---
...
meshConfig:
extensionProviders:
- envoyExtAuthzHttp:
headersToDownstreamOnDeny:
- content-type
- set-cookie
headersToUpstreamOnAllow:
- authorization
- path
- x-auth-request-user
- x-auth-request-email
- x-auth-request-access-token
includeHeadersInCheck:
- authorization
- cookie
port: "80"
service: "keycloak-oauth2-proxy.istio-keycloak.svc.cluster.local"
name: "oauth2-proxy"
...
Basically I want to disable redirect to auth page for /api path and use only jwt validation for that path. It works well, but some app’s functionality depends on user’s ability to contact /api endpoint from the browser (html page is being populated from /api requests from browser). Since all requests to /api endpoint don’t come to oauth2-proxy, x-auth-request-access-token header is not set automatically by it and web users get an error during page load.
From my understanding oauth2-proxy can’t store a cookie with plain jwt and RequestAuthentication can’t validate jwt from cookies, so using EnvoyFilter after successful auth I should store jwt in some arbitrary cookie and then extract it and put it into x-auth-request-access-token header for all requests to /api. Is it possible to do at all? Is this good approach or there’s a better one?
Thank you