Skip to content

Route OAuth callback through the vice-operator relay - #17

Merged
johnworth merged 3 commits into
mainfrom
auth-relay
May 14, 2026
Merged

Route OAuth callback through the vice-operator relay#17
johnworth merged 3 commits into
mainfrom
auth-relay

Conversation

@johnworth

@johnworth johnworth commented May 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • vice-proxy no longer sends its own per-app subdomain as the Keycloak redirect_uri — Keycloak only honors * as a trailing wildcard, so https://*.cyverse.run:4343/* can never match a real VICE subdomain (this is the "invalid parameter: redirect_uri" error seen in QA).
  • It now sends the vice-operator's fixed callback URL as redirect_uri and carries the original app URL inside an HMAC-signed state blob (new github.com/cyverse-de/go-mod/viceauth codec).
  • The operator relays the auth code back to this app's subdomain, where the state cookie is still present and the code is exchanged as before. The operator never does a token exchange and never holds the client secret.

Changes

  • RequireKeycloakAuth: encodes signed state (StateID + Origin); uses OPERATOR_CALLBACK_URL as redirect_uri.
  • HandleAuthorizationCode: decodes/verifies state, compares StateID against the cookie; token-exchange redirect_uri now byte-matches the operator callback URL.
  • State-session cookie gains SameSite=Lax + Secure (gated on an HTTPS frontend) to survive the extra cross-site redirect hop.
  • New required env vars when auth is enabled: OPERATOR_CALLBACK_URL, STATE_HMAC_SECRET (delivered via the cluster-config Secret).

Dependencies

  • Depends on Add viceauth module for signed OAuth state go-mod#11 (the viceauth module) — currently pinned to a pseudo-version of that branch; will be bumped to viceauth/v1.0.0 once it merges.
  • Companion PR in app-exposer adds the operator-side /auth/callback relay handler and the two new cluster-config keys.

Test plan

  • go build ./..., go vet ./..., go test ./..., gofmt
  • Register the QA operator's /auth/callback URL in Keycloak
  • End-to-end in QA: launch a VICE app, confirm redirect to Keycloak carries the operator callback URL, login bounces operator → app subdomain, session established
  • Negative: hand-crafted state with off-domain Origin is rejected by the operator

🤖 Generated with Claude Code

Keycloak only treats * as a trailing wildcard in Valid Redirect URIs, so
per-app VICE subdomains can never match https://*.cyverse.run:4343/*. Instead
of sending its own subdomain as redirect_uri, vice-proxy now sends the
operator's fixed callback URL and carries the original app URL in an
HMAC-signed state blob (new go-mod/viceauth codec). The vice-operator relays
the authorization code back to this app's subdomain, where the state cookie is
still present and the code is exchanged as before.

RequireKeycloakAuth encodes the signed state and uses OPERATOR_CALLBACK_URL as
redirect_uri; HandleAuthorizationCode decodes and verifies the state, and the
token-exchange redirect_uri now byte-matches the operator callback URL. The
state-session cookie gains SameSite=Lax/Secure so it survives the extra
cross-site redirect hop. OPERATOR_CALLBACK_URL and STATE_HMAC_SECRET are new
required env vars when auth is enabled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@socket-security

socket-security Bot commented May 14, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedgithub.com/​cyverse-de/​go-mod/​viceauth@​v1.0.0100100100100100

View full report

@johnworth

Copy link
Copy Markdown
Collaborator Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

John Wregglesworth and others added 2 commits May 14, 2026 10:29
HandleAuthorizationCode now checks for a Keycloak ?error= response (e.g. the
user denied consent) up front. Such responses carry no code or state, so
without this the flow fell through to the state check and reported a
confusing "no state found". Only the bounded RFC 6749 error code is echoed to
the browser; the full description is logged.

Also updates the frontendURL struct field comment — after the relay change it
is no longer the OAuth redirect_uri (that is operatorCallbackURL), only the
post-login browser redirect destination.

Addresses code review feedback on PR #17.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
go-mod#11 merged and viceauth/v1.0.0 is tagged; move off the auth-relay
pseudo-version to the released tag.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@johnworth
johnworth marked this pull request as ready for review May 14, 2026 17:47
@johnworth
johnworth merged commit d447204 into main May 14, 2026
3 checks passed
@johnworth
johnworth deleted the auth-relay branch May 14, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant