Skip to content

oauth2-proxy

A single oauth2-proxy Deployment gates every admin UI in the cluster (Argo CD, Grafana, pgAdmin, Redis Insight, the Xavia OTA dashboards). It runs the Google OAuth flow, plants a .tomoda.life cookie, and hands a verdict back to Traefik via forwardAuth.

Installed by k8s/envs/platform/oauth2-proxy/application.yaml; configuration is its inline helm.values block.

Chart and source

Field Value
Helm chart oauth2-proxy
Repository https://oauth2-proxy.github.io/manifests
Version 10.7.1 (app v7.15.5)
Destination namespace sys (created by Argo CD)
Argo CD Application oauth2-proxy
Public hostname auth.tomoda.life

The proxy itself sits behind Traefik with cert-manager-issued TLS at auth.tomoda.life (auth-tls). Sessions live in the encrypted cookie; there is no server-side session store. The Google client secret and cookie secret come from the oauth2-proxy-google Secret (config.existingSecret), an ExternalSecret over GSM tomoda-google-client-secret and tomoda-oauth2-proxy-cookie-secret.

Configuration

Key arguments from application.yaml:

extraArgs:
  - --provider=google
  - --email-domain=tomoda.life
  - --cookie-domain=.tomoda.life
  - --whitelist-domain=.tomoda.life
  - --cookie-secure=true
  - --reverse-proxy=true
  - --cookie-samesite=lax
  - --cookie-httponly=true
  - --set-xauthrequest=true
  - --redirect-url=https://auth.tomoda.life/oauth2/callback
  • --provider=google plus a Google OAuth client (the same brand used by Argo CD's Dex and Grafana's auth.google block).
  • --email-domain=tomoda.life means only @tomoda.life Google accounts can sign in. Other Google identities are rejected after the OAuth callback.
  • --cookie-domain=.tomoda.life makes the session cookie valid for every subdomain: sign in once at argo-app.tomoda.life and the same cookie is honoured at grafana.tomoda.life.

Operator allow-list

--email-domain alone admits any @tomoda.life account. Since this one proxy fronts pgAdmin, Redis Insight and Grafana, all of which reach production data, the config adds an explicit allow-list via authenticatedEmailsFile (chart mounts it as a ConfigMap and passes --authenticated-emails-file):

authenticatedEmailsFile:
  enabled: true
  restricted_access: |-
    <one email per line>

The list lives in k8s/envs/platform/oauth2-proxy/application.yaml and holds the operator role mailboxes plus each individual operator. Only those accounts pass the proxy, mirroring the Argo CD RBAC policy.csv in k8s/envs/platform/argocd/values.yaml. The list applies to every UI behind the proxy, Grafana included: a @tomoda.life account not on the list can't view dashboards either. To grant access, add the email to that file (one per line) and let Argo CD sync; there's no per-service exemption without splitting into a second proxy instance.

Traefik integration

oauth2-proxy is wired into Traefik using two Middleware CRs in the sys namespace (k8s/envs/platform/manifests/middleware.yaml):

# forwardAuth: ask oauth2-proxy whether the request is authenticated
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: oauth2-proxy-auth
  namespace: sys
spec:
  forwardAuth:
    address: "http://oauth2-proxy.sys.svc.cluster.local:80/oauth2/auth"
    trustForwardHeader: true
    authResponseHeaders:
      - X-Auth-Request-User
      - X-Auth-Request-Email
      - Set-Cookie

# errors: 401/403 -> redirect to /oauth2/start?rd=<original-url>
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: oauth2-proxy-errors
  namespace: sys
spec:
  errors:
    status: ["401-403"]
    service:
      name: oauth2-proxy
      port: 80
    query: "/oauth2/start?rd={url}"

Protected Ingresses include both middlewares as an annotation:

traefik.ingress.kubernetes.io/router.middlewares: sys-oauth2-proxy-errors@kubernetescrd,sys-oauth2-proxy-auth@kubernetescrd

The order matters: errors runs first so unauthenticated requests are turned into a redirect to Google, and auth then verifies the session on the request that comes back.

Argo CD UI gating

The Argo CD Ingress (k8s/envs/platform/argocd-ingress/ingress.yaml) carries both middlewares at argo-app.tomoda.life. It also includes a path-level route /oauth2 that points at an ExternalName Service called oauth2-proxy-redir in the argocd namespace. That Service is one of four siblings declared in k8s/envs/platform/manifests/external-services.yaml, each in a different namespace (argocd, data, tomoda-dev, tomoda-prod), all aliasing oauth2-proxy.sys.svc.cluster.local. The OAuth callback URL is https://auth.tomoda.life/oauth2/callback, but the initial /oauth2/start request happens on whatever host the user was trying to reach (e.g. argo-app.tomoda.life); ExternalName Services give every namespace a local handle to route it.

See Argo CD for the full picture of how the UI is authenticated.

Grafana gating

Grafana uses the same two middlewares (k8s/envs/platform/monitoring/values.yaml) plus auth.proxy.enabled = true on the Grafana side: Grafana trusts the X-Auth-Request-Email header that oauth2-proxy injects and auto-provisions users from it.

Operational notes

  • Cookie secret rotation (new GSM version of tomoda-oauth2-proxy-cookie-secret, then restart the pod) logs everyone out.
  • Adding a new protected UI is the middleware annotation plus an /oauth2 path to oauth2-proxy-redir; no oauth2-proxy config change as long as the hostname is under *.tomoda.life.
  • Enforced in CI. A fail-closed conftest policy (policy/admin_ingress_auth.rego, run by scripts/policy-check.sh in k8s-validate.yml) fails any PR that exposes a *.tomoda.life Ingress without the oauth2-proxy-auth middleware. A genuinely public host must be added to the policy's public_hosts allow-list with a justification, or, for a host that is public on only a few paths (Xavia OTA), its public_paths entry; Argo is exempt via its own Dex path. See Authentication threat model.