Skip to content

The agent that grows with you

fix(release): the final stable tag push authenticates with GH_TOKEN

ethernet310e05c0278c
diff --git a/scripts/releases/stable.py b/scripts/releases/stable.py
index e8ff24b8ae2..3d83ade119a 100644
--- a/scripts/releases/stable.py
+++ b/scripts/releases/stable.py
@@ -832,6 +832,19 @@ def _final_metadata(tag: str, commit: str, claim: dict, candidate_manifest_sha25
}
+def authenticated_push(ref: str, env: dict | None = None) -> list[str]:
+ """``git push origin <ref>`` that authenticates with GH_TOKEN when it is set.
+
+ The publication checkout runs with persist-credentials: false, so git has
+ no token of its own; gh hands GH_TOKEN to this one push as a credential
+ helper, keeping the token out of argv and out of .git/config.
+ """
+ env = os.environ if env is None else env
+ auth = (["-c", "credential.helper=", "-c", "credential.helper=!gh auth git-credential"]
+ if env.get("GH_TOKEN") else [])
+ return ["git", *auth, "push", "origin", ref]
+
+
def ensure_final_tag(tag: str, commit: str, claim: dict, *, candidate_manifest_sha256: str | None,
docker_manifest_digest: str, release_id: int, run=output) -> str:
"""Create or verify the immutable annotated final tag."""
@@ -856,7 +869,7 @@ def ensure_final_tag(tag: str, commit: str, claim: dict, *, candidate_manifest_s
or run(["git", "rev-parse", f"{ref}^{{commit}}"]) != commit
or tag_record(run(["git", "tag", "-l", tag, "--format=%(contents)"])) != expected):
raise ValueError("Local final tag collision")
- run(["git", "push", "origin", ref])
+ run(authenticated_push(ref))
remote_raw = run(["git", "ls-remote", "origin", ref, f"{ref}^{{}}"])
remote = dict(line.split()[::-1] for line in remote_raw.splitlines())
tag_object, peeled = remote.get(ref), remote.get(f"{ref}^{{}}")
diff --git a/tests/scripts/test_release_sequencer.py b/tests/scripts/test_release_sequencer.py
index c025d3606b5..d33b5e2505e 100644
--- a/tests/scripts/test_release_sequencer.py
+++ b/tests/scripts/test_release_sequencer.py
@@ -457,7 +457,7 @@ def _sequencer_fixture(*versions, manifest_digest, docker_digest="sha256:" + "b"
tag = argv[argv.index("-a") + 1]
tags[tag] = (str(len(tags)) * 40, tags[claim_tag][1], tags[tag][2])
return ""
- if argv[:2] == ["git", "push"]:
+ if argv[0] == "git" and "push" in argv:
return ""
if argv[:3] == ["docker", "buildx", "imagetools"]:
return json.dumps(docker_digest)
diff --git a/tests/scripts/test_stable_release.py b/tests/scripts/test_stable_release.py
index 92d76efadb9..b4cf1ac6b17 100644
--- a/tests/scripts/test_stable_release.py
+++ b/tests/scripts/test_stable_release.py
@@ -1161,3 +1161,15 @@ def test_a_claim_that_skipped_tests_records_skipped_smokes_never_passed(
stable.require_smokes_match_claim(manifest, skip_tests=True)
with pytest.raises(ValueError, match="test policy"):
stable.require_smokes_match_claim(manifest, skip_tests=False)
+
+
+def test_the_final_tag_push_authenticates_with_gh_token_without_persisted_credentials():
+ """The publication checkout persists no credentials; the push brings GH_TOKEN itself."""
+ from scripts.releases.stable import authenticated_push
+ ref = "refs/tags/v1.2.3"
+ argv = authenticated_push(ref, {"GH_TOKEN": "token"})
+ assert argv[0] == "git" and argv[-3:] == ["push", "origin", ref]
+ # Reset inherited helpers first, then hand git the token through gh.
+ assert argv[1:5] == ["-c", "credential.helper=", "-c", "credential.helper=!gh auth git-credential"]
+ assert "token" not in " ".join(argv)
+ assert authenticated_push(ref, {}) == ["git", "push", "origin", ref]