Add Google Cloud IAP authentication method#206
Open
sa3eed3ed wants to merge 1 commit into
Open
Conversation
Validates the signed X-Goog-IAP-JWT-Assertion header that Identity-Aware Proxy adds to every proxied request (signature, expiry, audience and issuer), then provisions the user and issues session cookies, mirroring the existing google/oidc auth methods. Enabled by configuring a new [auth.iap] section.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@berggren Hello from over there ;) |
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.
Summary
This adds an optional
iapauthentication method for deployments that run behind Google Cloud Identity-Aware Proxy.When OpenRelik is deployed behind IAP (a common setup for internal/BeyondCorp-style deployments on GCP), the proxy has already authenticated the user before any request reaches the server, and IAP policy (including Google Groups) already controls who gets through. Today such deployments still have to run a second OAuth flow inside OpenRelik via the
googleauth method, which means provisioning a separate OAuth client and maintaining a duplicate allowlist.Trusting a plain identity header from a proxy would be insecure (headers can be spoofed if the backend is ever reachable directly), so this implements GCP's documented approach instead: validating the signed
X-Goog-IAP-JWT-Assertionheader that IAP attaches to every proxied request (Securing your app with signed headers).Technical details
src/auth/iap.py, closely mirroring the structure of the existingoidc.py:GET /login/iapvalidates the assertion and issues the standard OpenRelik JWT cookies, then redirects to the UI. Since IAP adds the header to every request, there is no redirect dance — validating the header is the whole login flow.google.oauth2.id_token.verify_token(thegoogle-authdependency already used bygoogle.py) against IAP's public JWK endpoint, checking signature, expiry, audience and issuer.google/oidcmethods (auth_method="iap"). IAP assertions carry no profile claims, so the email doubles as display name.[auth.iap]config section (documented insettings_example.toml):audience— the expected assertion audience shown in the IAP consoleallowlist/public_access— same semantics as the other methods. Notepublic_access = truehere does not expose the server publicly: only identities IAP has authenticated and authorized can carry a valid assertion, so deployments can fully delegate access control to IAP policy.certs_url— override of the verification-key URL, for testing against locally minted assertionsmain.pyexactly like theoidcmethod, so existing deployments are unaffected unless[auth.iap]is configured.pyjwt[crypto]dependency: IAP publishes its verification keys in JWK format, andgoogle-authdelegates JWK-set verification to PyJWT (its x509-PEM path used by the existinggooglemethod does not need it). This matches the dependency set in GCP's own signed-header validation samples.OPENRELIK_AUTH_METHODS=iaprenders a generic login button for the method.Testing
src/tests/auth/iap_test.pyfollowing the structure ofoidc_test.py: assertion validation (valid, invalid signature, wrong issuer), allowlist/public-access authorization, missing header, missing email claim, and user provisioning for new and existing users. Full test suite passes (373 tests).certs_url). Confirmed: requests without/with-invalid/with-wrong-audience assertions are rejected with 401, valid assertions log in and provision the user, and the browser flow through the proxy works end to end including cookie-based API access afterwards.