Skip to content

gitcache: save only the job's own repository - #220

Merged
linyiru merged 1 commit into
mainfrom
gitcache-own-repo
Nov 8, 2026
Merged

linyiru merged 1 commit into
mainfrom
gitcache-own-repo

Conversation

@linyiru

@linyiru linyiru commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

With git_cache, a trusted job on one repository that fetched another private repository (a second checkout, a submodule) stored that pack under its own repository and default ref. A fork PR may read the default branch's caches, so it could restore that pack straight from cache-server with the git/ prefix, without the other repository's credentials.

Changes:

  • Git cache keys now name their repository in clear: git/<owner>/<name>/<hash>. gitcache.KeyRepository parses them, and gitcache.EntryVersion is the git entry version.
  • cache-server refuses to save a git entry whose key names a repository other than the job's own. actions/cache keys under any other version are untouched.
  • Lookups skip any git entry that does not name the job's own repository. A fork PR therefore cannot restore entries saved in the old format either.
  • README and changelog are updated. Images built before this change keep fetching from GitHub but no longer save to the git cache.

Tests:

  • internal/cacheserver/gitentry_test.go covers which saves are accepted or refused, and that an old-format entry is not restored by a prefix lookup.
  • internal/gitproxy/cache_test.go uses real keys and adds a cross-repository save test.
  • internal/gitcache has a KeyRepository table.
  • scripts/mutate.sh confirmed that both the save rule and the lookup filter are caught.

Review: a fresh reviewer agent reviewed the change. It confirmed that case, %2F, .. and redirects cannot get another repository saved under the job's scope. Its should-fix, that old entries were still readable by a direct client, is fixed here. Its test nits are also addressed.

With git_cache, a trusted job on one repository that fetched another
private one (a second checkout, a submodule) stored that pack under its
own repository and default ref. A fork PR, which may read the default
branch's caches, could then restore it straight from cache-server with
the "git/" prefix, without that repository's credentials.

Git cache keys now name their repository in clear,
"git/<owner>/<name>/<hash>". cache-server refuses to save a git entry
whose key names another repository than the job's, and never returns a
git entry that does not name the job's own, so entries saved in the old
format are not restored either.

Signed-off-by: Yi-Ru Lin <deduce@gmail.com>
@linyiru
linyiru enabled auto-merge November 8, 2026 05:35
@linyiru
linyiru merged commit 9260afe into main Nov 8, 2026
7 checks passed
@linyiru
linyiru deleted the gitcache-own-repo branch November 8, 2026 05:37
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