From 609c8e6c7d0fe3017db41fc6cd81945e4dccf6b0 Mon Sep 17 00:00:00 2001 From: Christian Ditscher Date: Thu, 26 Nov 2026 20:33:33 +0100 Subject: [PATCH 1/2] git: proactive auth for github.com only when the token is set With http.https://github.com/.proactiveAuth = basic and no token, Git asks for a password before the first request, so even public clones fail. On a fresh host the zsh plugin clones then print the credential helper's hint and Git errors, and the machine apply health check fails (CI apt-rpi-zero, apt-home-laptop). machine now writes proactiveAuth into github-token.gitconfig only when the token variable resolves at apply time (environment or ~/.env*). Without a token Git stays anonymous and runs the helper only after a 401. --- docs/git.md | 2 +- home/core/.config/git/private.gitconfig | 7 +-- machine_cli/dotfiles.py | 35 ++++++++++++-- .../github-proactive-auth-token/design.md | 42 ++++++++++++++++ .../github-proactive-auth-token/proposal.md | 35 ++++++++++++++ .../specs/git-config/spec.md | 39 +++++++++++++++ .../github-proactive-auth-token/tasks.md | 23 +++++++++ tests/unit/test_dotfiles.py | 48 ++++++++++++++++++- tests/unit/test_gitconfig.py | 13 +++++ 9 files changed, 233 insertions(+), 11 deletions(-) create mode 100644 openspec/changes/github-proactive-auth-token/design.md create mode 100644 openspec/changes/github-proactive-auth-token/proposal.md create mode 100644 openspec/changes/github-proactive-auth-token/specs/git-config/spec.md create mode 100644 openspec/changes/github-proactive-auth-token/tasks.md diff --git a/docs/git.md b/docs/git.md index eb93f32..1dffc8c 100644 --- a/docs/git.md +++ b/docs/git.md @@ -5,7 +5,7 @@ Shared and host-local Git settings, identities and credentials. - `~/.gitconfig` → symlink into the repo, identical on all hosts. `git config --global alias.x ...` lands there directly → commit, done. - `~/.gitconfig.local` → host-local, not in git, included after the shared settings. `machine setup` creates it once from the context (`work` → work user, otherwise private) and never overwrites it; on work hosts an existing file only gets a missing `http.sslCAInfo` appended. Signing key, `safe.directory`, credentials and proxy go here. - Owner rules at the end of `~/.gitconfig` override the host default by remote URL: github.com `bosch-*`/`bosch_*`/`*_bosch` owners (HTTPS and SSH), GHES and Bitbucket → `~/.config/git/work.gitconfig`, any other github.com owner → `~/.config/git/private.gitconfig`. Each sets identity plus the GitHub credential username and helper. A repository name ending in `_bosch` does not select the work identity. -- `git-credential-env VAR` serves tokens from the environment or `~/.env` (`GITHUB_TOKEN`, `BDC_GITHUB_TOKEN`, `GITHUB_PRIVATE_TOKEN`) and never stores them. When a GUI-started process lacks the token, it sources only `~/.shell/common/environment.sh` in Bash; it does not start interactive shell initialization. For github.com the variable follows the host type: `GITHUB_TOKEN` on private hosts, `GITHUB_PRIVATE_TOKEN` on work hosts (where `GITHUB_TOKEN` is the work token); `machine` writes the choice to `~/.config/git/github-token.gitconfig` on every dotfile apply. On private hosts `machine setup` also switches the checkout's `origin` to SSH (`git@github.com:…`) when the SSH key authenticates at GitHub, so pushing needs no token. `~/.netrc` entries for the same host take precedence in curl, so keep GitHub out of it. `machine env pull` writes `~/.netrc` from Bitwarden (see [secrets.md](secrets.md)) and warns for a `github.com` block. When such a block is needed (for example by the work devcontainers), `private.gitconfig` sets `http.https://github.com/.proactiveAuth = basic`, so Git asks the credential helper first and the netrc entry is not used for pushes and fetches in a repository; this needs Git 2.46 or newer, and a first `git clone` is not covered because no repository config exists yet. +- `git-credential-env VAR` serves tokens from the environment or `~/.env` (`GITHUB_TOKEN`, `BDC_GITHUB_TOKEN`, `GITHUB_PRIVATE_TOKEN`) and never stores them. When a GUI-started process lacks the token, it sources only `~/.shell/common/environment.sh` in Bash; it does not start interactive shell initialization. For github.com the variable follows the host type: `GITHUB_TOKEN` on private hosts, `GITHUB_PRIVATE_TOKEN` on work hosts (where `GITHUB_TOKEN` is the work token); `machine` writes the choice to `~/.config/git/github-token.gitconfig` on every dotfile apply. On private hosts `machine setup` also switches the checkout's `origin` to SSH (`git@github.com:…`) when the SSH key authenticates at GitHub, so pushing needs no token. `~/.netrc` entries for the same host take precedence in curl, so keep GitHub out of it. `machine env pull` writes `~/.netrc` from Bitwarden (see [secrets.md](secrets.md)) and warns for a `github.com` block. When such a block is needed (for example by the work devcontainers), `machine` adds `http.https://github.com/.proactiveAuth = basic` to `~/.config/git/github-token.gitconfig`, so Git asks the credential helper first and the netrc entry is not used for github.com clones, fetches and pushes; this needs Git 2.46 or newer. It does so only when the token variable is set at apply time (environment or `~/.env*`): without a token, proactive auth would make Git ask for a password even for public repositories (for example the zsh plugin clones on a fresh host), so Git then stays anonymous and runs the helper only when GitHub asks for a credential. A host that gets its token later is covered by its next `machine update`. - Single repo with a different identity: `git user-work` / `git user-private` (repo-local include of the same snippet), undo with `git user-unset-local`; show: `git user-show`. - `machine update` and `machine commit` move host-only entries from the shared config into `~/.gitconfig.local`. A key that is absent locally moves, an equal value is dropped from the shared file, and a different local value is a conflict that `machine update` asks about (non-interactive runs keep both and leave the shared file dirty). Repeated values are preserved. Backups live under `~/.local/share/machine/local-overrides-backup/`. Text added to `~/.bashrc` is handled the same way: known text is removed silently, new text is moved only when you select it, and moved text stands between `# machine-local begin/end` markers in `~/.bashrc-local`. - The installed pre-commit hook does the same before an ordinary Git commit. If it changes the shared file, review and stage the cleaned file, then commit again. diff --git a/home/core/.config/git/private.gitconfig b/home/core/.config/git/private.gitconfig index fd67638..56d78ba 100644 --- a/home/core/.config/git/private.gitconfig +++ b/home/core/.config/git/private.gitconfig @@ -9,13 +9,10 @@ # empty value drops earlier helpers (store), so tokens never land in ~/.git-credentials helper = -# Run the credential helper before the first request. Otherwise curl sends a -# github.com entry of ~/.netrc up front and Git never asks the helper (Git 2.46+). -[http "https://github.com/"] - proactiveAuth = basic - # The token helper itself, written by `machine` from the host config: GITHUB_TOKEN on # private hosts, GITHUB_PRIVATE_TOKEN on work hosts (where GITHUB_TOKEN is the work # token). Must come after the reset above; a missing file means no token helper. +# With a token it also runs the helper before the first request, so a github.com +# entry of ~/.netrc does not replace the token (http.proactiveAuth, Git 2.46+). [include] path = ~/.config/git/github-token.gitconfig diff --git a/machine_cli/dotfiles.py b/machine_cli/dotfiles.py index 33ae400..56eed70 100644 --- a/machine_cli/dotfiles.py +++ b/machine_cli/dotfiles.py @@ -66,14 +66,38 @@ def github_token_variable(context: str) -> str: return "GITHUB_PRIVATE_TOKEN" if context == "work" else "GITHUB_TOKEN" -def render_github_token_config(context: str) -> str: - return ( +def render_github_token_config(context: str, proactive_auth: bool = True) -> str: + text = ( "# Written by `machine` from the host config on every dotfile apply; do not edit.\n" "# Included by ~/.config/git/private.gitconfig after its credential reset.\n" '[credential "https://github.com"]\n' " helper = !$HOME/.local/bin/git-credential-env " f"{github_token_variable(context)}\n" ) + if proactive_auth: + # Run the helper before the first request, so a github.com entry in ~/.netrc + # does not replace the token (Git 2.46+). Only with a token: without one, Git + # would ask for a password even for public repositories. + text += '\n[http "https://github.com/"]\n proactiveAuth = basic\n' + return text + + +def github_token_available(variable: str, repo: Path, home: Path) -> bool: + """Resolve the token like git-credential-env: environment, else the shell + environment loader (~/.env*). The checkout's loader, because the first apply runs + before $HOME is linked.""" + if os.environ.get(variable): + return True + loader = Path(repo) / "home/core/.shell/common/environment.sh" + if not loader.is_file() or not system.have("bash"): + return False + result = system.run( + ["bash", "-c", '. "$1" >/dev/null 2>&1; printenv "$2"', "_", str(loader), variable], + env={**os.environ, "HOME": str(home)}, + check=False, + capture=True, + ) # fmt: skip + return result.returncode == 0 and bool((result.stdout or "").strip()) def github_ssh_url(url: str) -> str: @@ -296,12 +320,15 @@ def run_dotfiles_apply(self) -> None: def write_github_token_config(self, context: str) -> None: path = self.home / GITHUB_TOKEN_CONFIG - text = render_github_token_config(context) + variable = github_token_variable(context) + proactive = github_token_available(variable, Path(self.repo), self.home) + text = render_github_token_config(context, proactive) if path.is_file() and path.read_text(encoding="utf-8") == text: return path.parent.mkdir(parents=True, exist_ok=True) path.write_text(text, encoding="utf-8") - log(f"GitHub token for github.com: {github_token_variable(context)} ({path})") + state = "set, helper first" if proactive else "not set, anonymous until asked" + log(f"GitHub token for github.com: {variable} ({state}; {path})") def switch_origin_to_ssh(self, context: str, device: str) -> None: """Private hosts push with their SSH key: move an https github.com origin to SSH, diff --git a/openspec/changes/github-proactive-auth-token/design.md b/openspec/changes/github-proactive-auth-token/design.md new file mode 100644 index 0000000..31e396e --- /dev/null +++ b/openspec/changes/github-proactive-auth-token/design.md @@ -0,0 +1,42 @@ +# Design + +## Context + +See proposal.md for the motivation. + +Current state: +- `private.gitconfig` is included for every github.com remote (`includeIf hasconfig:remote.*.url`). It sets `credential.https://github.com.username = ditschi`, resets the helpers, includes the machine-written `github-token.gitconfig` (helper `git-credential-env GITHUB_TOKEN`, or `GITHUB_PRIVATE_TOKEN` on work hosts) and sets `http.https://github.com/.proactiveAuth = basic` (change `private-github-url-user`, 2026-11-17), so a `github.com` entry in `~/.netrc` does not replace the personal token. +- Checked on this host (2026-11-26, Git 2.56) with the repository's Git config files in a temporary HOME and no token: `git clone --depth 1 https://github.com/zsh-users/zsh-autosuggestions` runs the helper (the `hasconfig` rule is already active during a clone, contrary to the note in the earlier design), the helper prints its hint, Git asks for a password and exits 128 (`terminal prompts disabled`). +- With proactive auth Git passes `wwwauth[]=Basic` to the helper just as after a real 401, so the helper cannot tell the two cases apart. +- GitHub answers 401 to empty or wrong Basic credentials also for public repositories (anonymous: 200), so no placeholder credential can stand in for a missing token. +- The zsh plugin manager (antidote, `home/core/.shell/zsh/plugins.zsh`) clones antidote and the plugins from `https://github.com/...` at the first shell start and retries the bundle at every start while it fails. The `machine apply` health check runs `zsh -i` and fails on its stderr (CI run 44610448518, commit 0a3d695). +- Hosts: every host and container without a token in its environment or `~/.env*` is affected; hosts with the token behave as before. + +## Goals / Non-Goals + +**Goals:** +- Public github.com clones and fetches work without the token. +- Hosts with the token keep the personal token in front of a `github.com` netrc entry. + +**Non-Goals:** +- Silencing the helper's hint: when GitHub asks for a credential and none is set, the hint is correct. +- A change to the health check: the errors were real. + +## Decisions + +**Proactive auth only with an available token** (owner decision, 2026-11-26). `machine` writes `[http "https://github.com/"] proactiveAuth = basic` into `github-token.gitconfig` when the token variable that the file names resolves to a non-empty value at apply time, in the same way the helper resolves it: the `machine` environment first, else the checkout's `home/core/.shell/common/environment.sh` sourced in Bash (it reads `~/.env*`). The checkout's loader is used because the first apply writes the file before `$HOME` is linked. Git config cannot depend on an environment variable at run time, so the decision is made at apply time. `machine update` pulls the env files before the dotfile apply, so a host that gets its token is covered on its next update. The setting moves out of `private.gitconfig`; because that file includes `github-token.gitconfig`, the setting still applies to every github.com remote, also to work owners, as before. + +**Alternatives considered and rejected:** +- Making the helper quiet without a token: Git still asks for a password and the clone still fails. +- Proactive auth only with a `github.com` netrc entry (and the token): more conditions to keep correct for no practical gain; with the token proactive auth is harmless. +- Proactive auth per repository (e.g. `git user-private` or the dotfiles checkout): gives up the rule for every github.com remote. + +## Risks / Trade-offs + +- [A host gets its token after the apply] → proactive auth is off until the next apply; until then a `github.com` netrc entry wins for personal pushes, as before the earlier change. +- [A work host without `GITHUB_PRIVATE_TOKEN` but with the work netrc entry] → work-owner and public requests use the netrc credential; personal pushes fail as they would without a token anyway. +- [The token is removed after the apply] → proactive auth stays on until the next apply and public clones fail as today; the next apply drops it. + +## Migration Plan + +None: the next dotfile apply rewrites `github-token.gitconfig`. diff --git a/openspec/changes/github-proactive-auth-token/proposal.md b/openspec/changes/github-proactive-auth-token/proposal.md new file mode 100644 index 0000000..2f343eb --- /dev/null +++ b/openspec/changes/github-proactive-auth-token/proposal.md @@ -0,0 +1,35 @@ +# Proposal + +## Why + +On a host without the GitHub token (a fresh container, the APT integration tests in CI, a host before its first `machine env pull`), Git cannot reach public github.com repositories over HTTPS. `private.gitconfig` sets `http.https://github.com/.proactiveAuth = basic` for every github.com remote, so Git demands a credential before the first request; the helper has none, Git asks for a password and fails without a terminal. The zsh plugin manager clones its plugins from github.com at the first shell start, so the shell start prints `git-credential-env: GITHUB_TOKEN is not set` and Git errors, the plugins stay missing, and the `machine apply` health check fails (CI jobs `apt-rpi-zero (26.04)` and `apt-home-laptop`). A missing token must not break public clones; it should only matter when GitHub actually asks for a credential. + +## What Changes + +- `machine` writes `http.https://github.com/.proactiveAuth = basic` into the generated `~/.config/git/github-token.gitconfig` only when the host's GitHub token variable is set at apply time (environment, or `~/.env*` through the shell environment loader of the checkout). +- `private.gitconfig` no longer sets `proactiveAuth` itself. +- Without the token, Git clones and fetches public github.com repositories anonymously and asks the credential helper only after GitHub answers 401; the helper's hint about the missing variable stays for that case. +- `docs/git.md` describes the condition. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `git-config`: the requirement "Credential helper before netrc for github.com" applies only when the token is available; a new requirement covers anonymous access without the token. + +Affected contexts: `private` and `work`, all devices; in practice hosts without the token (containers, fresh hosts, CI). + +## Impact + +- Code: `machine_cli/dotfiles.py` (token config rendering), `home/core/.config/git/private.gitconfig`. +- Tests: `tests/unit/test_dotfiles.py`, `tests/unit/test_gitconfig.py`; the APT host-yaml integration test covers the clean install. +- Docs: `docs/git.md`. +- Hosts: the next dotfile apply rewrites `github-token.gitconfig`. A host that gets its token later gets proactive auth on the next apply (`machine update` pulls the env files before it applies the dotfiles). + +## Where the change is made + +In the worktree `$(machine repo)/.worktrees/github-proactive-auth-token` on branch `github-proactive-auth-token`, because the change edits Git configuration that every shell and tool on the host reads. diff --git a/openspec/changes/github-proactive-auth-token/specs/git-config/spec.md b/openspec/changes/github-proactive-auth-token/specs/git-config/spec.md new file mode 100644 index 0000000..556209e --- /dev/null +++ b/openspec/changes/github-proactive-auth-token/specs/git-config/spec.md @@ -0,0 +1,39 @@ +# Spec Delta + +## MODIFIED Requirements + +### Requirement: Credential helper before netrc for github.com +When the github.com token variable is set at dotfile apply time (environment or `~/.env*`), Git SHALL ask its credential helper for github.com before the first request (`http.https://github.com/.proactiveAuth = basic`, written by `machine` into `github-token.gitconfig`), so that a `github.com` entry in `~/.netrc` does not replace the configured credential. Work owners SHALL keep the credential helper of `work.gitconfig`. Git versions that do not know the key SHALL behave as before. + +#### Scenario: Personal repository with a work netrc entry +- **WHEN** the token is set, `~/.netrc` has a `machine github.com` entry for another login and a repository has the remote `https://github.com/ditschi/dotfiles.git` +- **THEN** Git pushes with the personal token from its credential helper and not with the netrc credentials + +#### Scenario: Work owner +- **WHEN** a repository has the remote `https://github.com/bosch-example/repo.git` +- **THEN** the credential helper of `work.gitconfig` is the effective helper and the identity is the work identity + +#### Scenario: Any other owner +- **WHEN** the token is set and a repository has a github.com remote of an owner that does not match a work rule +- **THEN** the rule is active through `private.gitconfig` without naming the owner + +#### Scenario: Remote unchanged +- **WHEN** a user runs `git remote -v` +- **THEN** the remotes show the URLs as configured + +#### Scenario: Git without the key +- **WHEN** Git is older than 2.46 +- **THEN** it ignores the key and reports no error + +## ADDED Requirements + +### Requirement: Anonymous github.com access without a token +When the github.com token variable is not set at dotfile apply time, `github-token.gitconfig` SHALL NOT enable proactive auth, so Git clones and fetches public github.com repositories anonymously and runs the credential helper only when GitHub asks for a credential. + +#### Scenario: Fresh container clones zsh plugins +- **WHEN** a host without the token starts zsh for the first time and the plugin manager clones from `https://github.com/` +- **THEN** the clones succeed and the credential helper prints nothing + +#### Scenario: Private repository without a token +- **WHEN** a host without the token fetches a repository for which GitHub answers 401 +- **THEN** the credential helper reports that the token variable is not set diff --git a/openspec/changes/github-proactive-auth-token/tasks.md b/openspec/changes/github-proactive-auth-token/tasks.md new file mode 100644 index 0000000..03b0639 --- /dev/null +++ b/openspec/changes/github-proactive-auth-token/tasks.md @@ -0,0 +1,23 @@ +# Tasks + +Work only in the worktree `$(machine repo)/.worktrees/github-proactive-auth-token` (see proposal.md). + +## 1. Token config + +- [x] 1.1 In `machine_cli/dotfiles.py`, render `[http "https://github.com/"] proactiveAuth = basic` into `github-token.gitconfig` only when the token variable resolves (environment, else the checkout's `home/core/.shell/common/environment.sh` in Bash) and log whether it is on; cover with unit tests in `tests/unit/test_dotfiles.py` (token in environment, token only in `~/.env`, no token). +- [x] 1.2 Remove `proactiveAuth` from `home/core/.config/git/private.gitconfig`; in `tests/unit/test_gitconfig.py` assert that the effective `http.proactiveauth` of a personal and a work-owner github.com remote is empty when the token file is rendered without the token, and stays `basic` with it. + +## 2. Documentation + +- [x] 2.1 Update the `~/.netrc` note in `docs/git.md`: proactive auth only with the token, and correct the note that a first clone is not covered. + +## 3. Validation + +- [x] 3.1 Run `pytest tests/unit/test_dotfiles.py tests/unit/test_gitconfig.py -q`. +- [x] 3.2 Reproduce the CI failure check by hand: with the repository's Git config files in a temporary HOME and no token, `git clone --depth 1 https://github.com/zsh-users/zsh-autosuggestions` succeeds and prints nothing from the helper. +- [x] 3.3 Run the APT integration tests `tests/integration/test_host_yaml_install.py -k "rpi_zero or home_laptop"` if Docker is available. +- [x] 3.4 Run `pre-commit run --files ` including untracked additions, then `openspec validate github-proactive-auth-token --strict`. + +## Workflow follow-up + +- Archive with `/opsx-archive` following the archive guidance in `openspec/config.yaml`. diff --git a/tests/unit/test_dotfiles.py b/tests/unit/test_dotfiles.py index e751b9f..c2c5906 100644 --- a/tests/unit/test_dotfiles.py +++ b/tests/unit/test_dotfiles.py @@ -582,8 +582,13 @@ def test_machine_link_follows_the_running_checkout(tmp_path): ("", "GITHUB_TOKEN"), ], ) -def test_github_token_variable_follows_the_context(tmp_path, context, variable): +def test_github_token_variable_follows_the_context( + tmp_path, monkeypatch, context, variable +): + monkeypatch.delenv("GITHUB_TOKEN", raising=False) + monkeypatch.delenv("GITHUB_PRIVATE_TOKEN", raising=False) host = _Host(tmp_path) + host.repo = tmp_path / "no-checkout" host.write_github_token_config(context) text = (tmp_path / ".config/git/github-token.gitconfig").read_text() assert f"git-credential-env {variable}\n" in text @@ -593,6 +598,47 @@ def test_github_token_variable_follows_the_context(tmp_path, context, variable): assert f"git-credential-env {other}\n" not in text +def _token_host(tmp_path): + host = _Host(tmp_path / "home") + host.home.mkdir() + host.repo = REPO + return host + + +def _token_config(host) -> str: + return (host.home / ".config/git/github-token.gitconfig").read_text() + + +def test_github_token_in_environment_enables_proactive_auth(tmp_path, monkeypatch): + monkeypatch.setenv("GITHUB_TOKEN", "token") + host = _token_host(tmp_path) + host.write_github_token_config("private") + assert "proactiveAuth = basic\n" in _token_config(host) + + +def test_github_token_from_env_file_enables_proactive_auth(tmp_path, monkeypatch): + """GITHUB_PRIVATE_TOKEN only in ~/.env: found through the checkout's loader.""" + monkeypatch.delenv("GITHUB_PRIVATE_TOKEN", raising=False) + host = _token_host(tmp_path) + env_file = host.home / ".env" + env_file.write_text("GITHUB_PRIVATE_TOKEN=token\n") + env_file.chmod(0o600) + host.write_github_token_config("work") + assert "proactiveAuth = basic\n" in _token_config(host) + + +def test_no_github_token_keeps_anonymous_access(tmp_path, monkeypatch): + """Without a token, proactive auth would make Git ask for a password even for + public repositories (zsh plugin clones in a fresh container).""" + monkeypatch.delenv("GITHUB_TOKEN", raising=False) + monkeypatch.setenv("GITHUB_PRIVATE_TOKEN", "work-only") + host = _token_host(tmp_path) + host.write_github_token_config("private") + text = _token_config(host) + assert "git-credential-env GITHUB_TOKEN\n" in text + assert "proactiveAuth" not in text + + def test_private_gitconfig_includes_the_token_file_after_the_reset(tmp_path): """Git resolves the helper list: reset, then the helper of the included file.""" import subprocess diff --git a/tests/unit/test_gitconfig.py b/tests/unit/test_gitconfig.py index 3256d13..c3a95c9 100644 --- a/tests/unit/test_gitconfig.py +++ b/tests/unit/test_gitconfig.py @@ -397,6 +397,19 @@ def test_github_asks_the_credential_helper_before_netrc(git_home, url, expected) assert _proactive_auth(env, repo) == expected +@pytest.mark.parametrize( + "url", + ["https://github.com/ditschi/dotfiles.git", "https://github.com/bosch-foo/x.git"], +) +def test_github_without_token_stays_anonymous(git_home, url): + home, repo, env = git_home + (home / ".config/git/github-token.gitconfig").write_text( + render_github_token_config("work", proactive_auth=False) + ) + _run(env, repo, "remote", "add", "origin", url) + assert _proactive_auth(env, repo) == "" + + def test_work_owner_keeps_the_work_helper_with_proactive_auth(git_home): _home, repo, env = git_home _run(env, repo, "remote", "add", "origin", "https://github.com/bosch-foo/x.git") From ce46e4d31a7035a0d98dde5764b9476513c1eeb9 Mon Sep 17 00:00:00 2001 From: Christian Ditscher Date: Thu, 26 Nov 2026 20:33:51 +0100 Subject: [PATCH 2/2] Archive github-proactive-auth-token; update the git-config credential-helper requirement and add anonymous access without a token --- .../design.md | 0 .../proposal.md | 0 .../specs/git-config/spec.md | 0 .../tasks.md | 0 openspec/specs/git-config/spec.md | 17 ++++++++++++++--- 5 files changed, 14 insertions(+), 3 deletions(-) rename openspec/changes/{github-proactive-auth-token => archive/2026-11-26-github-proactive-auth-token}/design.md (100%) rename openspec/changes/{github-proactive-auth-token => archive/2026-11-26-github-proactive-auth-token}/proposal.md (100%) rename openspec/changes/{github-proactive-auth-token => archive/2026-11-26-github-proactive-auth-token}/specs/git-config/spec.md (100%) rename openspec/changes/{github-proactive-auth-token => archive/2026-11-26-github-proactive-auth-token}/tasks.md (100%) diff --git a/openspec/changes/github-proactive-auth-token/design.md b/openspec/changes/archive/2026-11-26-github-proactive-auth-token/design.md similarity index 100% rename from openspec/changes/github-proactive-auth-token/design.md rename to openspec/changes/archive/2026-11-26-github-proactive-auth-token/design.md diff --git a/openspec/changes/github-proactive-auth-token/proposal.md b/openspec/changes/archive/2026-11-26-github-proactive-auth-token/proposal.md similarity index 100% rename from openspec/changes/github-proactive-auth-token/proposal.md rename to openspec/changes/archive/2026-11-26-github-proactive-auth-token/proposal.md diff --git a/openspec/changes/github-proactive-auth-token/specs/git-config/spec.md b/openspec/changes/archive/2026-11-26-github-proactive-auth-token/specs/git-config/spec.md similarity index 100% rename from openspec/changes/github-proactive-auth-token/specs/git-config/spec.md rename to openspec/changes/archive/2026-11-26-github-proactive-auth-token/specs/git-config/spec.md diff --git a/openspec/changes/github-proactive-auth-token/tasks.md b/openspec/changes/archive/2026-11-26-github-proactive-auth-token/tasks.md similarity index 100% rename from openspec/changes/github-proactive-auth-token/tasks.md rename to openspec/changes/archive/2026-11-26-github-proactive-auth-token/tasks.md diff --git a/openspec/specs/git-config/spec.md b/openspec/specs/git-config/spec.md index ade988c..0104c29 100644 --- a/openspec/specs/git-config/spec.md +++ b/openspec/specs/git-config/spec.md @@ -123,10 +123,10 @@ For github.com, the credential helper SHALL read `GITHUB_PRIVATE_TOKEN` on hosts - **THEN** `origin` is not changed ### Requirement: Credential helper before netrc for github.com -Git SHALL ask its credential helper for github.com before the first request (`http.https://github.com/.proactiveAuth = basic` in `private.gitconfig`), so that a `github.com` entry in `~/.netrc` does not replace the configured credential. Work owners SHALL keep the credential helper of `work.gitconfig`. Git versions that do not know the key SHALL behave as before and report no error. +When the github.com token variable is set at dotfile apply time (environment or `~/.env*`), Git SHALL ask its credential helper for github.com before the first request (`http.https://github.com/.proactiveAuth = basic`, written by `machine` into `github-token.gitconfig`), so that a `github.com` entry in `~/.netrc` does not replace the configured credential. Work owners SHALL keep the credential helper of `work.gitconfig`. Git versions that do not know the key SHALL behave as before. #### Scenario: Personal repository with a work netrc entry -- **WHEN** `~/.netrc` has a `machine github.com` entry for another login and a repository has the remote `https://github.com/ditschi/dotfiles.git` +- **WHEN** the token is set, `~/.netrc` has a `machine github.com` entry for another login and a repository has the remote `https://github.com/ditschi/dotfiles.git` - **THEN** Git pushes with the personal token from its credential helper and not with the netrc credentials #### Scenario: Work owner @@ -134,7 +134,7 @@ Git SHALL ask its credential helper for github.com before the first request (`ht - **THEN** the credential helper of `work.gitconfig` is the effective helper and the identity is the work identity #### Scenario: Any other owner -- **WHEN** a repository has a github.com remote of an owner that does not match a work rule +- **WHEN** the token is set and a repository has a github.com remote of an owner that does not match a work rule - **THEN** the rule is active through `private.gitconfig` without naming the owner #### Scenario: Remote unchanged @@ -144,3 +144,14 @@ Git SHALL ask its credential helper for github.com before the first request (`ht #### Scenario: Git without the key - **WHEN** Git is older than 2.46 - **THEN** it ignores the key and reports no error + +### Requirement: Anonymous github.com access without a token +When the github.com token variable is not set at dotfile apply time, `github-token.gitconfig` SHALL NOT enable proactive auth, so Git clones and fetches public github.com repositories anonymously and runs the credential helper only when GitHub asks for a credential. + +#### Scenario: Fresh container clones zsh plugins +- **WHEN** a host without the token starts zsh for the first time and the plugin manager clones from `https://github.com/` +- **THEN** the clones succeed and the credential helper prints nothing + +#### Scenario: Private repository without a token +- **WHEN** a host without the token fetches a repository for which GitHub answers 401 +- **THEN** the credential helper reports that the token variable is not set