Skip to content

oidc: fix bug when matching GitLab environment claims #18338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025

Conversation

facutuesca
Copy link
Contributor

@facutuesca facutuesca commented Jul 2, 2025

Bug reported here: #18330

The OIDC publisher lookup refactor in #18169 introduced a bug where we normalize the incoming environment claim (making it lowercase) when doing the DB lookup for matching GitLab publishers.

This means that the lookup would incorrectly fail when the environment was capitalized (e.g: SomeEnvironment), since it would be lowercased before searching the DB (which contained the correct capitalized version).

Inversely, a lookup would incorrectly succeed when the incoming environment claim was capitalized but the environment configured in the Publisher was not. These are different environments (since GitLab's environments are case-sensitive), but by lowercasing the incoming claim, we would match against the publisher with a different (lowercase) claim.

Luckily this second scenario does not result in successful authentication, since this buggy lookup logic is separate from the "claim checking" logic, which happens after a publisher is found, and does not contain the bug.

This PR removes the incorrect .lower() call, and adds tests for the two scenarios mentioned above

This fixes #18330

cc @di @miketheman

@facutuesca facutuesca requested a review from a team as a code owner July 2, 2025 16:07
Copy link
Member

@miketheman miketheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that the added tests expose the problem if the call to .lower() remains.

@miketheman miketheman merged commit e548b99 into pypi:main Jul 2, 2025
20 checks passed
@miketheman
Copy link
Member

Thanks for the speedy fix, @facutuesca !

@facutuesca facutuesca deleted the ft/fix-gitlab-oidc-bug branch July 2, 2025 16:54
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.

Trusted publishing from GitLab CI/CD fails with caps in environment name
2 participants