feat: add GitLab CI OIDC detector#302
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds GitLab CI/CD as a first-class OIDC auto-discovery environment for the CLI’s credential resolution chain, enabling GitLab pipelines to authenticate to Cloudsmith using a GitLab-minted OIDC JWT (instead of a static API key).
Changes:
- Added a
GitLabCIDetectorthat detects GitLab CI and retrieves an OIDC JWT fromCLOUDSMITH_OIDC_TOKEN(with legacy fallbacks). - Registered the GitLab detector ahead of the AWS detector in the OIDC environment detection order.
- Added unit tests for detection behavior and token retrieval precedence, and documented GitLab CI OIDC usage in the README.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| README.md | Documents GitLab CI OIDC configuration and usage example. |
| cloudsmith_cli/core/tests/test_gitlab_ci_detector.py | Adds unit tests for GitLab CI detection and token selection behavior. |
| cloudsmith_cli/core/credentials/oidc/detectors/gitlab_ci.py | Implements the GitLab CI OIDC environment detector. |
| cloudsmith_cli/core/credentials/oidc/detectors/init.py | Registers GitLab CI detector ahead of AWS in the detection chain. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fcd9f7e to
2777f92
Compare
2777f92 to
95748ef
Compare
Add GitLab CI to OIDC credential auto-discovery. When running in GitLab CI/CD, the CLI reads the OIDC token from CLOUDSMITH_OIDC_TOKEN (configured via id_tokens in .gitlab-ci.yml, with legacy fallbacks to CI_JOB_JWT_V2 and CI_JOB_JWT) and exchanges it for a Cloudsmith access token. Works out of the box with no extra dependencies. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
95748ef to
83faa10
Compare
6 tasks
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
Adds a GitLab CI environment detector to the OIDC credential auto-discovery chain. When the CLI runs inside a GitLab pipeline, it reads an OIDC JWT minted by GitLab's
id_tokensconfiguration and exchanges it for a short-lived Cloudsmith API token — no static API key required.Behaviour
GITLAB_CI=trueplus a token environment variable.CLOUDSMITH_OIDC_TOKEN, falling back to the legacyCI_JOB_JWT_V2/CI_JOB_JWTvariables.Usage
The
audmust behttps://api.cloudsmith.io/openid/<org>— that is the audience the Cloudsmith OIDC endpoint validates.Testing
GITLAB_CIflag) and token retrieval (preference order, legacy fallback, missing-token error).black/isort/flake8/pylintclean.POST /openid/<org>/with the service slug, andcloudsmith whoamireturnedis_authenticated: trueas the service account — authenticating purely via OIDC with no API key.🤖 Generated with Claude Code