Skip to content

Present a git token for dependencies from private repositories - #11

Open
telchak wants to merge 1 commit into
dagger:mainfrom
telchak:git-token
Open

telchak wants to merge 1 commit into
dagger:mainfrom
telchak:git-token

Conversation

@telchak

@telchak telchak commented Oct 22, 2026

Copy link
Copy Markdown

Why

The default base has git, so a git dependency from a public repository works. One from a private repository can't be fetched by any of the uv-based modules, because nothing can hand git a credential. We hit this with a project that depends on pkg @ git+https://github.com/<org>/<private-repo>.git@<sha>, with CI on GitHub Actions, where a GitHub App mints a short-lived token for that one repository.

What

  • Pyproject takes gitToken: Secret = null and gitHost: String! = "github.com". pytest, uv, mypy and ty expose both and forward them. ruff never touches uv, so it doesn't.

  • With a token, withGitToken applies to whichever base is used, default or custom:

    • the token becomes a secret variable;
    • a git credential helper for https://<gitHost> only is declared through GIT_CONFIG_COUNT / GIT_CONFIG_KEY_0 / GIT_CONFIG_VALUE_0 (git 2.31+).

    uv runs the git CLI with its environment, so the helper reaches it with no config file written. The token stays out of every layer, URL and uv.lock, and it is read only when the host asks for credentials.

  • The README documents the setting in the Python environment section and in the three settings tables.

[modules.pytest.settings]
gitToken = "env://GIT_TOKEN"

One limitation: a custom base that already sets its own GIT_CONFIG_* variables would have them replaced while a token is set.

Tests

New gitTokenCheck in the e2e suite, which checks that:

  • git credential fill for github.com returns the token (compared inside the shell, since stdout comes back scrubbed);
  • a request for another host gets nothing;
  • the token is not a plain environment variable;
  • a base without a token declares no helper.

I ran the e2e suite from a Windows client. git-token-check passes. Every other result matches a run of unmodified main on the same machine, failure for failure: there, the workspace search fails with path cannot escape search root and ghcr.io pulls are refused. That host also needed pyproject/images/uv/Dockerfile temporarily pointed at astral/uv:0.12.9 on Docker Hub; the change isn't part of this PR. A run from a Linux client would be welcome.

Used for real through the fork in prairialab/reliability-engine, whose tests install a private dependency this way.

🤖 Generated with Claude Code

A git dependency from a private repository cannot be fetched by any of the uv
based modules: the default base has git, but no way to give it credentials.

gitToken, on pytest, uv, mypy and ty, takes a secret that the shared library
hands to git as a credential helper declared through GIT_CONFIG_* variables,
for gitHost only (github.com by default). uv runs the git CLI with its
environment, so the helper reaches it with no config file written, and the
token stays out of every layer, URL and uv.lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: telchak <scanachib@gmail.com>
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.

1 participant