mirror of
https://github.com/sredevopsorg/deepseek-kubernetes-sandbox.git
synced 2026-11-03 01:13:24 +00:00
Add oauth2-proxy (GitHub provider, org-restricted) as a reverse proxy in front of the dsh-gateway, wired through the Traefik Gateway API. The gateway inherits the authenticated GitHub username via X-Forwarded-User (SSO). - gateway.py: opt-in AUTH_PROXY_HEADER trust, remote_user(), SSO bootstrap (auto-provision claim + mint/rotate token + session cookie), patch_token() - 50-gateway.yaml: AUTH_PROXY_HEADER=X-Forwarded-User, COOKIE_SECURE=true - gateway-api/dsh-demo: oauth2-proxy Deployment/Service + secret example, HTTPRoute backend -> oauth2-proxy:4180 - tests: 10 new SSO cases (106 passing) Placeholders (dsh-demo.example.com, your-github-org) are substituted at apply time. Co-authored-by: SREDevOpsAgents <agents@sredevops.org>
Gateway API — external access for dsh-demo/dsh-gateway (GitHub SSO)
Exposes the dsh-gateway service (dsh-demo, port 8080) outside the cluster
using the Kubernetes Gateway API (Traefik Gateway controller), fronted by
oauth2-proxy so access requires a GitHub login restricted to a configured
GitHub organization. The gateway inherits the authenticated GitHub username via
the X-Forwarded-User header (SSO).
Request flow
Browser ──▶ Gateway dsh-gateway (HTTPS, TLS-terminate)
──▶ HTTPRoute <your-hostname>
──▶ oauth2-proxy:4180 (GitHub OAuth, org-restricted)
──▶ dsh-gateway:8080 (X-Forwarded-User = GitHub login → SSO)
Resources
| File | Kind | Purpose |
|---|---|---|
gateway.yaml |
Gateway |
HTTPS listener with TLS termination |
httproute.yaml |
HTTPRoute |
Routes the hostname → oauth2-proxy:4180 |
oauth2-proxy.yaml |
Deployment/Service |
GitHub OAuth reverse proxy |
oauth2-proxy-secret.yaml.example |
Secret |
Example OAuth credentials (not applied as-is) |
tls-secret.yaml.example |
Secret |
Example TLS cert secret (not applied as-is) |
Prerequisites
- GitHub OAuth App — create one at
https://github.com/settings/developerswith:- Homepage URL:
https://dsh-demo.example.com - Authorization callback URL:
https://dsh-demo.example.com/oauth2/callback(replacedsh-demo.example.comwith the actual public FQDN). Note the client ID and client secret.
- Homepage URL:
- oauth2-proxy Secret —
kubectl -n dsh-demo create secret generic oauth2-proxywithclient-id,client-secret, and acookie-secret(openssl rand -base64 32). Seeoauth2-proxy-secret.yaml.example. - TLS secret — create
dsh-demo-tlsindsh-demo(seetls-secret.yaml.example). - Gateway app env — the
dsh-gatewayDeployment must run the SSO-capable image withAUTH_PROXY_HEADER=X-Forwarded-UserandCOOKIE_SECURE=true(seeexamples/dsh-agents-as-a-service/50-gateway.yaml). - Ingress and DNS — configure the upstream ingress and public DNS for the hostname.
Apply
kubectl diff -f gateway-api/dsh-demo/
kubectl apply -f gateway-api/dsh-demo/ --dry-run=server
kubectl apply -f gateway-api/dsh-demo/
⚠️ A write-enabled kubeconfig is required to create Gateways, HTTPRoutes, Deployments, and Secrets.
Verify
kubectl get gateway dsh-gateway -n dsh-demo -o yaml # expect Programmed=True
kubectl get httproute -n dsh-demo -o wide # backend oauth2-proxy:4180, Accepted
kubectl get deploy oauth2-proxy -n dsh-demo # 1/1 Ready
kubectl get endpoints oauth2-proxy -n dsh-demo # backend present
kubectl -n dsh-demo logs deploy/oauth2-proxy --tail=50 # no config errors
Browser check: open https://<your-hostname>/ — you should be redirected
to GitHub, and after signing in as a member of the allowed organization your
sandbox opens with the session showing your GitHub login. A non-member is denied
before reaching the gateway.
Rollback
kubectl delete -f gateway-api/dsh-demo/
Notes
- SSO is opt-in and additive. The gateway honors
X-Forwarded-Useronly whenAUTH_PROXY_HEADERis set; unset it to restore bearer-token/session-only auth. - Trust boundary. After this change the
dsh-gatewayService must be reachable only through oauth2-proxy (it is a ClusterIP Service). A second Route/Ingress that exposesdsh-gateway:8080directly would let clients spoof the header. - GitHub login → DSH user. GitHub usernames are lowercase alphanumerics and
hyphens, so they map 1:1 onto the gateway's dns-1123
uservalidation. - Sign-out. The gateway
/logoutclearsdsh_gw_session; oauth2-proxy's own session can be cleared at/oauth2/sign_outif desired. - No
ReferenceGrantis required: the Gateway, HTTPRoute, oauth2-proxy, and the backend Service are all indsh-demo.