Repository navigation
fix(auth): match XID ACL principals case-insensitively - #1446
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces case-insensitive matching for ASCII letters in ACL principals (users, service accounts, groups, and domains) and canonicalizes authenticated emails to lowercase. It also adds validation to reject non-ASCII or malformed email addresses. Feedback on the changes suggests normalizing userEmail and groupEmail at the beginning of isUserInGroup to ensure consistent cache keys and robust API queries.
VLukiantsev
marked this pull request as ready for review
October 27, 2026 16:31
Email addresses issued by Google identity providers are case-insensitive, but XID ACL checks compared user, service account and domain principals byte-for-byte, so an ACL entry such as "First.Last@Example.com" denied the same user authenticating as "first.last@example.com". - Canonicalize the authenticated email once in AuthenticateUserFromContext for all identity paths (session token, JWKS, Google/IAP ID token). The email must be a plain ASCII address (no display name, comment, quoting or surrounding whitespace) in a conservative charset; it is then lowercased for ASCII letters only, so Unicode case folding (e.g. U+212A KELVIN SIGN) cannot alias principals. Non-conforming identities fail closed with Unauthenticated. - When a JWKS token has no subject, the user ID falls back to the canonical email. - Add auth.NormalizePrincipal (trim + ASCII lowercase) for stored-side ACL values, and compare user, service account and domain principals in that form. Extract the domain with LastIndex and never let an empty principal match. - Key the group membership cache on canonical emails. - Make MockAuth ACL matching case-insensitive, consistent with Authorizer. - Document case-insensitive matching and the email requirements in docs/authentication.md. Creator and dashboard Owner values stored from the authenticated email are lowercase from now on. Existing rows with mixed-case values may no longer match exact creator filters; a backfill is deferred (b/575771582). Bug: b/575771582 TAG=agy
Normalize user and group emails at the start of isUserInGroup so a mixed-case cache miss queries the membership API with canonical principals, consistent with the cache key. Addresses review comment on #1446. Bug: b/575771582 TAG=agy CONV=99d9ba56-87b3-434a-8f7d-5c0546bef484
VLukiantsev
force-pushed
the
fix/acl-case-insensitive-principal-match
branch
from
October 27, 2026 17:07
1988006 to
d0c0279
Compare
andrzejfudro
approved these changes
Oct 28, 2026
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
Canonicalize the authenticated email once in
AuthenticateUserFromContextand match XID ACL user, service account and domain principals case-insensitively, so ACL entries such asFirst.Last@Example.comauthorizefirst.last@example.com. Stack 1/3 for b/575771582.Motivation & Context
Web login lowercases emails, but the Google/IAP ID token, JWKS and custom session token paths did not normalize, and
isPrincipalInListcompared principals byte-for-byte. Mixed-case ACL entries (new or legacy rows) therefore returnedPermissionDenied. Comparison normalizes both sides, so no data migration is required for authorization correctness.Security review hardening: the email must be a plain ASCII address (
mail.ParseAddresswith no display name, exact match, conservative charset) and is lowercased for ASCII letters only, preventing Unicode case-folding aliasing (e.g. U+212A KELVIN SIGN →k) and display-name / quoted-local-part tricks. Non-conforming identities fail closed withUnauthenticated.Key Changes
internal/auth/principal.go:NormalizePrincipal(trim + ASCII lowercase),canonicalEmail,principalsMatch,emailDomain(LastIndex; empty principal never matches).internal/auth/authentication.go: single canonicalization point for all identity paths; JWKS user ID falls back to the canonical email.internal/auth/authorization.go: case-insensitive user/SA/domain match; group cache keyed on canonical email.internal/auth/test_utils.go:MockAuthmatching is case-insensitive, consistent withAuthorizer.docs/authentication.md: documents case-insensitive matching and email requirements.Assumptions
email/Subjectis not a plain ASCII address are rejected — required to close the aliasing hole — impact if wrong: such identities lose access and would need an allowlisted format.userIDleft as the raw claim — session emails are already lowercased at login.Verification & Testing
./.githooks/pre-commit(gofmt, golangci-lint, buildifier, addlicense,tools/run_affected_tests.py— 11 affected Bazel targets).Eve <a@corp.com>,"x@evil.com"@corp.com, JWKS subject fallback, all three identity paths; XIDCheckUserAuthorizationand ESSCreateExperimentmixed-case owner cases.Related Issues / Bugs
Fixes bug b/575771582 (part 1/3)
TAG=agy
CONV=99d9ba56-87b3-434a-8f7d-5c0546bef484