feat(auth): add Google sign-in#1478
Open
VishnuM049 wants to merge 2 commits into
Open
Conversation
Adds Google OAuth alongside the existing generic OIDC slot so an org can offer both (e.g. Okta for employees + Google for external collaborators). Backend: Authlib client registered at startup when GOOGLE_OAUTH_CLIENT_ID and GOOGLE_OAUTH_CLIENT_SECRET are set. Two routes handle the redirect dance. Shared helpers (_provision_sso_user, _complete_sso_login, _start_oauth_flow) eliminate duplication with the existing OIDC callback. Google-specific checks: email_verified enforcement and optional domain allowlist via GOOGLE_OAUTH_ALLOWED_DOMAINS. Frontend: /config/public exposes google_sso_enabled flag. Login page renders a branded "Sign in with Google" button when the flag is true. Infra: GCP Terraform threads client ID/secret through Secret Manager; AWS EC2 uses env_overrides; docker-compose inherits from .env. Co-Authored-By: Apoorv Garg <apoorvgarg.work@gmail.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
efd75f3 to
3def228
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose / Description
Adds Google as a first-class sign-in option for self-hosted Observal. Admins drop in their OAuth client ID and secret (and, if they want, an email-domain allowlist) and a real "Sign in with Google" button shows up on the login page. It coexists with the existing generic OIDC slot, so an org running Okta or Keycloak can keep that and offer Google on the same screen.
The motivation: the generic OIDC slot already technically supports Google (point it at
accounts.google.com/.well-known/openid-configurationand it works), but the button just says "Sign in with SSO". That's fine for one internal IdP and confusing for everyone else. Making Google a named provider gets us a branded button, lets it sit alongside the custom OIDC, and gives us a clean place to plug in Google-specific checks likeemail_verifiedandhd-style domain restrictions.Fixes
deployment.frontend_urldefault missing:3000(caused redirect_uri_mismatch on fresh deployments)Approach
Backend. A second Authlib client called
"google"with the discovery URL hardcoded server-side, so admins only ever set client ID + secret. Two new routes —/api/v1/auth/oauth/google/loginand/api/v1/auth/oauth/google/callback— handle the redirect dance.The duplicated bits from the existing
/oauth/callbackare pulled into shared helpers (_provision_sso_userand_complete_sso_login) so the Google route reuses them instead of copy-pasting. The generic OIDC callback now also recordsauth_providerandsso_subject_idon the user row, which it wasn't doing before.Ordering fix: the
SSO_SUCCESSaudit event now fires after the DB commit. Before, a failed commit would still log a success.The Google route adds two checks the generic OIDC doesn't have: it requires Google's
email_verifiedclaim to be true, and ifGOOGLE_OAUTH_ALLOWED_DOMAINSis set (comma-separated list likeacme.com,acme.io), it rejects anything outside the list with a 403 + audit event.Frontend.
/api/v1/config/publicexposes a newgoogle_sso_enabledflag. TheuseDeploymentConfighook surfaces it. The login page renders a "Sign in with Google" button with an inline SVG Google "G" icon.Self-hosting.
.env.exampledocuments the three new variables. GCP Terraform threads the client ID and secret through Secret Manager and exposes the allowlist as a plain Cloud Run env var. AWS-EC2 uses the existingenv_overridesmap. Docker-compose pulls from.envdirectly.Docs.
docs/self-hosting/authentication.mdgot a new "Google OAuth (first-class provider)" subsection with the GCP Console steps, redirect URI, allowlist behavior, and first-login notes.No DB migration.
User.auth_providerandUser.sso_subject_idcolumns already exist from the SSO work.How Has This Been Tested?
pytest tests/test_google_oauth.py -v # 27 tests passEnd-to-end tested with real GCP OAuth credentials on localhost: button renders, Google redirect works, user auto-created on first sign-in, lands in the app authenticated.
Screenshots
Checklist
AI Assistance