Skip to content

Commit 2cdf9cf

Browse files
authored
Oauth2 proxy (#443)
* update envoy and add oauth2 proxy * fix * fix * update oauth2 proxy args * update oauth2 proxy args * update envoy filters * upgrade proxy to v7.14 * fix envoy checksum * fix envoy * update x-osmo-auth approach * update ui to handle session * remove oauth2 proxy sign in page * update UI to handle auth header from proxy * fix token * use envoy to copy token to header * update ui accordingly * add user info to header * fix * set name in header * fix
1 parent 0e37486 commit 2cdf9cf

File tree

18 files changed

+940
-1038
lines changed

18 files changed

+940
-1038
lines changed

deployments/charts/router/templates/_envoy-config-helpers.tpl

Lines changed: 92 additions & 215 deletions
Large diffs are not rendered by default.

deployments/charts/router/templates/_sidecar-helpers.tpl

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,6 @@ Envoy sidecar container
2727
command: ["/bin/sh", "-c"]
2828
args:
2929
- |
30-
echo "$(date -Iseconds) Waiting to populate secrets..."
31-
{{- if .Values.sidecars.envoy.useKubernetesSecrets }}
32-
# For Kubernetes secrets, just wait and start
33-
sleep 5
34-
{{- else }}
35-
# For Other secrets, wait for files and process config
36-
while [ ! -f "{{ .Values.sidecars.envoy.secretPaths.clientSecret }}" ] || [ ! -s "{{ .Values.sidecars.envoy.secretPaths.clientSecret }}" ]; do
37-
echo "$(date -Iseconds) Waiting for client secret file..."
38-
sleep 2
39-
done
40-
while [ ! -f "{{ .Values.sidecars.envoy.secretPaths.hmacSecret }}" ] || [ ! -s "{{ .Values.sidecars.envoy.secretPaths.hmacSecret }}" ]; do
41-
echo "$(date -Iseconds) Waiting for HMAC secret file..."
42-
sleep 2
43-
done
44-
echo "$(date -Iseconds) Secret files ready..."
45-
{{- end }}
4630
echo "$(date -Iseconds) Starting Envoy..."
4731
exec /usr/local/bin/envoy -c /var/config/config.yaml --log-level {{ .Values.sidecars.envoy.logLevel | default "info" }} --log-path /logs/envoy.txt
4832
ports:
@@ -58,11 +42,6 @@ Envoy sidecar container
5842
- name: logs
5943
mountPath: /logs
6044
{{- end }}
61-
{{- if .Values.sidecars.envoy.useKubernetesSecrets }}
62-
- name: envoy-secrets
63-
mountPath: /etc/envoy/secrets
64-
readOnly: true
65-
{{- end }}
6645
{{- with .Values.sidecars.envoy.extraVolumeMounts }}
6746
{{- toYaml . | nindent 4 }}
6847
{{- end }}
@@ -185,16 +164,6 @@ Envoy volumes
185164
configMap:
186165
name: {{ .Values.services.service.serviceName }}-envoy-config
187166
{{- end }}
188-
{{- if .Values.sidecars.envoy.useKubernetesSecrets }}
189-
- name: envoy-secrets
190-
secret:
191-
secretName: {{ .Values.sidecars.envoy.oauth2Filter.secretName | default "oidc-secrets" }}
192-
items:
193-
- key: {{ .Values.sidecars.envoy.oauth2Filter.clientSecretKey | default "client_secret" }}
194-
path: client_secret
195-
- key: {{ .Values.sidecars.envoy.oauth2Filter.hmacSecretKey | default "hmac_secret" }}
196-
path: hmac_secret
197-
{{- end }}
198167
{{- end }}
199168

200169
{{/*
@@ -209,6 +178,92 @@ Log agent volumes
209178
{{- end }}
210179

211180
{{/*
181+
OAuth2 Proxy sidecar container
182+
*/}}
183+
{{- define "router.oauth2-proxy-sidecar-container" -}}
184+
{{- if .Values.sidecars.oauth2Proxy.enabled }}
185+
- name: oauth2-proxy
186+
image: "{{ .Values.sidecars.oauth2Proxy.image }}"
187+
imagePullPolicy: {{ .Values.sidecars.oauth2Proxy.imagePullPolicy }}
188+
securityContext:
189+
{{- toYaml .Values.sidecars.oauth2Proxy.securityContext | nindent 4 }}
190+
args:
191+
- --config={{ .Values.sidecars.oauth2Proxy.secretPaths.cookieSecret }}
192+
- --http-address=0.0.0.0:{{ .Values.sidecars.oauth2Proxy.httpPort }}
193+
- --metrics-address=0.0.0.0:{{ .Values.sidecars.oauth2Proxy.metricsPort }}
194+
- --reverse-proxy=true
195+
- --provider={{ .Values.sidecars.oauth2Proxy.provider }}
196+
- --oidc-issuer-url={{ .Values.sidecars.oauth2Proxy.oidcIssuerUrl }}
197+
- --client-id={{ .Values.sidecars.oauth2Proxy.clientId }}
198+
- --cookie-secure={{ .Values.sidecars.oauth2Proxy.cookieSecure }}
199+
- --cookie-name={{ .Values.sidecars.oauth2Proxy.cookieName }}
200+
{{- if .Values.sidecars.oauth2Proxy.cookieDomain }}
201+
- --cookie-domain={{ .Values.sidecars.oauth2Proxy.cookieDomain }}
202+
{{- end }}
203+
- --cookie-expire={{ .Values.sidecars.oauth2Proxy.cookieExpire }}
204+
- --cookie-refresh={{ .Values.sidecars.oauth2Proxy.cookieRefresh }}
205+
- --scope={{ .Values.sidecars.oauth2Proxy.scope }}
206+
- --email-domain=*
207+
- --set-xauthrequest=true
208+
- --set-authorization-header=true
209+
- --pass-access-token={{ .Values.sidecars.oauth2Proxy.passAccessToken }}
210+
- --upstream=static://200
211+
- --redirect-url=https://{{ .Values.sidecars.envoy.service.hostname }}/oauth2/callback
212+
- --silence-ping-logging=true
213+
- --skip-provider-button=true
214+
{{- range .Values.sidecars.oauth2Proxy.extraArgs }}
215+
- {{ . }}
216+
{{- end }}
217+
ports:
218+
- name: http
219+
containerPort: {{ .Values.sidecars.oauth2Proxy.httpPort }}
220+
- name: metrics
221+
containerPort: {{ .Values.sidecars.oauth2Proxy.metricsPort }}
222+
livenessProbe:
223+
httpGet:
224+
path: /ping
225+
port: http
226+
initialDelaySeconds: 10
227+
periodSeconds: 10
228+
timeoutSeconds: 3
229+
readinessProbe:
230+
httpGet:
231+
path: /ready
232+
port: http
233+
initialDelaySeconds: 5
234+
periodSeconds: 5
235+
timeoutSeconds: 3
236+
resources:
237+
{{- toYaml .Values.sidecars.oauth2Proxy.resources | nindent 4 }}
238+
volumeMounts:
239+
{{- if .Values.sidecars.oauth2Proxy.useKubernetesSecrets }}
240+
- name: oauth2-proxy-secrets
241+
mountPath: /etc/oauth2-proxy
242+
readOnly: true
243+
{{- end }}
244+
{{- with .Values.sidecars.oauth2Proxy.extraVolumeMounts }}
245+
{{- toYaml . | nindent 4 }}
246+
{{- end }}
247+
{{- end }}
248+
{{- end }}
249+
250+
{{/*
251+
OAuth2 Proxy volumes
252+
*/}}
253+
{{- define "router.oauth2-proxy-volumes" -}}
254+
{{- if .Values.sidecars.oauth2Proxy.enabled }}
255+
{{- if .Values.sidecars.oauth2Proxy.useKubernetesSecrets }}
256+
- name: oauth2-proxy-secrets
257+
secret:
258+
secretName: {{ .Values.sidecars.oauth2Proxy.secretName | default "oauth2-proxy-secrets" }}
259+
items:
260+
- key: {{ .Values.sidecars.oauth2Proxy.clientSecretKey | default "client_secret" }}
261+
path: client-secret
262+
- key: {{ .Values.sidecars.oauth2Proxy.cookieSecretKey | default "cookie_secret" }}
263+
path: cookie-secret
264+
{{- end }}
265+
{{- end }}
266+
{{- end }}
212267
Authorization sidecar container
213268
*/}}
214269
{{- define "router.authz-sidecar-container" -}}

deployments/charts/router/templates/router-service.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ spec:
3333
{{- toYaml . | nindent 8 }}
3434
{{- end }}
3535
annotations:
36+
checksum/envoy-config: {{ .Values.sidecars.envoy | toYaml | sha256sum }}
3637
{{- with .Values.extraPodAnnotations }}
3738
{{- toYaml . | nindent 8 }}
3839
{{- end }}
@@ -186,13 +187,15 @@ spec:
186187
{{- end }}
187188

188189
{{- include "router.envoy-sidecar-container" . | nindent 6}}
190+
{{- include "router.oauth2-proxy-sidecar-container" . | nindent 6}}
189191
{{- include "router.authz-sidecar-container" . | nindent 6}}
190192
{{- include "router.log-agent-sidecar-container" . | nindent 6}}
191193
{{- with .Values.extraContainers }}
192194
{{- toYaml . | nindent 6 }}
193195
{{- end }}
194196
volumes:
195197
{{- include "router.envoy-volumes" . | nindent 8 }}
198+
{{- include "router.oauth2-proxy-volumes" . | nindent 8 }}
196199
{{- include "router.log-agent-volumes" . | nindent 8 }}
197200
{{- if .Values.global.logs.enabled }}
198201
- name: logs

deployments/charts/router/values.yaml

Lines changed: 114 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -355,50 +355,17 @@ sidecars:
355355
timeout: 0s
356356

357357

358-
## OAuth2 authentication filter configuration
358+
## IDP (Identity Provider) configuration for JWT JWKS fetching
359359
##
360-
oauth2Filter:
361-
## Enable OAuth2 authentication for incoming requests
362-
##
363-
enabled: true
364-
365-
## Forward bearer token to upstream service
366-
##
367-
forwardBearerToken: true
368-
369-
## OAuth2 token endpoint URL for token exchange
360+
idp:
361+
## Hostname for the identity provider (e.g., login.microsoftonline.com)
370362
##
371-
tokenEndpoint: ""
363+
host: ""
372364

373-
## OAuth2 authorization endpoint URL for user authentication
374-
##
375-
authEndpoint: ""
376-
377-
## Redirect path for OAuth2 callback after authentication
378-
##
379-
redirectPath: api/auth/getAToken
380-
381-
## OAuth2 client ID for this application
382-
##
383-
clientId: ""
384-
385-
## OAuth2 authentication provider identifier
386-
##
387-
authProvider: ""
388-
389-
## Logout path for ending user sessions
390-
##
391-
logoutPath: logout
392-
393-
## Kubernetes secret keys (when useKubernetesSecrets is true)
394-
##
395-
secretName: oidc-secrets
396-
clientSecretKey: client_secret
397-
hmacSecretKey: hmac_secret
398-
399-
## Force re-authentication when IdToken is missing on refresh
400-
##
401-
forceReauthOnMissingIdToken: false
365+
## OAuth2 authentication filter configuration (DEPRECATED - use sidecars.oauth2Proxy instead)
366+
##
367+
oauth2Filter:
368+
enabled: false
402369

403370
## JWT (JSON Web Token) authentication configuration
404371
##
@@ -434,11 +401,10 @@ sidecars:
434401
##
435402
address: osmo-service
436403

437-
## Secret paths for OAuth2 secrets
404+
## Secret paths (legacy, kept for backward compatibility)
438405
##
439406
secretPaths:
440407
clientSecret: /etc/envoy/secrets/client_secret
441-
hmacSecret: /etc/envoy/secrets/hmac_secret
442408

443409
## Additional volume mounts for the Envoy container
444410
##
@@ -471,6 +437,111 @@ sidecars:
471437
timeoutSeconds: 3
472438

473439

440+
## OAuth2 Proxy sidecar configuration
441+
##
442+
oauth2Proxy:
443+
## Enable OAuth2 Proxy sidecar container
444+
##
445+
enabled: true
446+
447+
## OAuth2 Proxy container image
448+
##
449+
image: "quay.io/oauth2-proxy/oauth2-proxy:v7.14.2"
450+
451+
## Image pull policy
452+
##
453+
imagePullPolicy: IfNotPresent
454+
455+
## HTTP port for OAuth2 Proxy
456+
##
457+
httpPort: 4180
458+
459+
## Metrics port for OAuth2 Proxy
460+
##
461+
metricsPort: 44180
462+
463+
## OIDC provider type
464+
##
465+
provider: oidc
466+
467+
## OIDC issuer URL
468+
##
469+
oidcIssuerUrl: ""
470+
471+
## OAuth2 client ID
472+
##
473+
clientId: ""
474+
475+
## Cookie name for session management
476+
##
477+
cookieName: _osmo_session
478+
479+
## Whether to set the secure flag on cookies
480+
##
481+
cookieSecure: true
482+
483+
## Cookie domain (leave empty for default)
484+
##
485+
cookieDomain: ""
486+
487+
## Cookie expiration duration
488+
##
489+
cookieExpire: 168h
490+
491+
## Cookie refresh interval
492+
##
493+
cookieRefresh: 1h
494+
495+
## OAuth2 scopes to request
496+
##
497+
scope: "openid email profile"
498+
499+
## Pass the access token to upstream (disabled to reduce cookie size)
500+
##
501+
passAccessToken: false
502+
503+
## Use Kubernetes secrets for credentials
504+
##
505+
useKubernetesSecrets: false
506+
507+
## Kubernetes secret configuration (when useKubernetesSecrets is true)
508+
##
509+
secretName: oauth2-proxy-secrets
510+
clientSecretKey: client_secret
511+
cookieSecretKey: cookie_secret
512+
513+
## Secret file paths (when using vault or other secret managers)
514+
##
515+
secretPaths:
516+
clientSecret: /etc/oauth2-proxy/client-secret
517+
cookieSecret: /etc/oauth2-proxy/cookie-secret
518+
519+
## Additional arguments passed to oauth2-proxy
520+
##
521+
extraArgs: []
522+
523+
## Additional volume mounts
524+
##
525+
extraVolumeMounts: []
526+
527+
## Security context for OAuth2 Proxy container
528+
##
529+
securityContext:
530+
allowPrivilegeEscalation: false
531+
capabilities:
532+
drop: ["ALL"]
533+
runAsNonRoot: true
534+
runAsUser: 1001
535+
536+
## Resource limits and requests
537+
##
538+
resources:
539+
requests:
540+
cpu: "50m"
541+
memory: "64Mi"
542+
limits:
543+
memory: "128Mi"
544+
474545
## Log agent sidecar configuration for centralized logging on AWS CloudWatch
475546
##
476547
logAgent:

0 commit comments

Comments
 (0)