-
Notifications
You must be signed in to change notification settings - Fork 50
feat(auth): add URL-dispatched session auth for GitHub and GitLab #1173
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Authentication | ||
|
|
||
| Fromager automatically authenticates to GitHub and GitLab APIs using | ||
| credentials from netrc or environment variables. Credentials are | ||
| resolved lazily on the first request to each host. | ||
|
|
||
| Authentication is recommended to avoid [API rate limits](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api) (especially | ||
| for GitHub) and required to access private repositories or registries. | ||
|
|
||
| ## Credential lookup order | ||
|
|
||
| For each host, fromager checks the following sources in order and uses | ||
| the first match: | ||
|
|
||
| **GitHub** (`GITHUB_API_URL`, default `https://api.github.com`): | ||
|
|
||
| 1. [netrc](https://docs.python.org/3/library/netrc.html) entry for | ||
| the host -- the password is used as the token | ||
| 2. `GITHUB_TOKEN` environment variable | ||
|
|
||
| **GitLab** (`CI_SERVER_URL`, default `https://gitlab.com`): | ||
|
|
||
| 1. netrc entry for the host -- if the login is `gitlab-ci-token` a | ||
| CI job token header is used, otherwise a private token header | ||
| 2. `CI_JOB_TOKEN` environment variable | ||
| 3. `GITLAB_PRIVATE_TOKEN` environment variable | ||
|
|
||
| ## netrc | ||
|
|
||
| The [requests](https://requests.readthedocs.io) library, `pip`, and | ||
| `git` all read credentials from `~/.netrc`. Another location can be | ||
| specified by setting the `NETRC` environment variable. Note that | ||
| `git` uses libcurl for HTTPS transport and libcurl only supports the | ||
| `NETRC` variable since [8.16.0](https://curl.se/ch/8.16.0.html) | ||
| (2025-09-10). Older versions only read `$HOME/.netrc`. | ||
|
|
||
| For example, to authenticate to a GitLab package registry with a | ||
| [personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token): | ||
|
|
||
| ```text | ||
| machine gitlab.com login pat password $token | ||
| ``` | ||
|
|
||
| To authenticate to the GitHub API with a | ||
| [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens): | ||
|
|
||
| ```text | ||
| machine api.github.com login pat password $token | ||
| ``` | ||
|
|
||
| ## Environment variables | ||
|
|
||
| To authenticate via environment variables instead of netrc: | ||
|
|
||
| ```shell | ||
| # GitHub personal access token (avoids API rate limits) | ||
| export GITHUB_TOKEN=<access_token> | ||
|
|
||
| # GitLab CI job token (set automatically in CI pipelines) | ||
| export CI_JOB_TOKEN=<job_token> | ||
|
|
||
| # GitLab personal/project access token | ||
| export GITLAB_PRIVATE_TOKEN=<access_token> | ||
| ``` |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.