git/builtin
Christian Couder 85c7f5e7da builtin/upload-pack: don't disable lazy fetching on trusted repo
A previous commit added a new "uploadpack.lazyFetchTrusted" protected
config variable that can contain an allowlist of repos, as well as
functions to check if the current repo is in that list. But when the
current repo is in that list, we currently do nothing.

Since 7b70e9efb1 (upload-pack: disable lazy-fetching by default,
2024-04-16), `upload-pack` sets `GIT_NO_LAZY_FETCH` to 1 itself,
unconditionally, because by default it shouldn't trust the repositories
it serves. Lazily fetching runs `git fetch`, which may execute
arbitrary commands specified in the configuration and hooks of the
served repo.

The new "uploadpack.lazyFetchTrusted" protected config variable is not
about overriding an environment variable. It's rather about teaching
the code that automatically sets `GIT_NO_LAZY_FETCH` (because it had no
way to know if the served repo could be trusted) to look at the new
config variable to find out if a server operator actually vouched for
that repo.

Let's implement that, so we now have the following cases:

  - if `GIT_NO_LAZY_FETCH` is already set, we honor it and leave it
    alone, as it comes from the server operator,

  - otherwise, if the served repo is in the
    "uploadpack.lazyFetchTrusted" allowlist, we don't disable lazy
    fetching,

  - otherwise, we disable lazy fetching, as we used to.

This allows `upload-pack` and its `pack-objects` child process to
lazily fetch the objects they need to serve a client, for example when
the filter used by the client and the one used by the server don't
match.

Note that what a server operator vouches for by listing a repo there
is that the promisor remotes this repo is configured to lazily fetch
from, as well as its configuration and hooks, are trustworthy. Whether
a client trusts the repo it fetches from is a separate matter, and up
to the client.

As `pack-objects`, which performs the lazy fetch when serving a
client, is a child process of `upload-pack`, not setting
`GIT_NO_LAZY_FETCH` in `upload-pack` is enough for it to be allowed to
lazily fetch, without any further plumbing.

On the other hand, as we leave `GIT_NO_LAZY_FETCH` unset for a trusted
repo instead of setting it to 0, the trust doesn't propagate: if a
trusted repo lazily fetches from a promisor remote that is itself
served by `upload-pack` on the same machine, that nested `upload-pack`
decides for its own repo. This is unlike when a server operator sets
`GIT_NO_LAZY_FETCH` to 0, as that is inherited by all child processes.

Now that "uploadpack.lazyFetchTrusted" is actually doing something,
let's document it (including this difference with `GIT_NO_LAZY_FETCH`),
let's reference it from `GIT_NO_LAZY_FETCH`'s docs, and let's add tests
for it.

Signed-off-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-10-02 07:40:34 -07:00
..
add.c Merge branch 'jt/receive-pack-pluggable-writes' 2026-08-31 08:25:00 -07:00
am.c
…
annotate.c
…
apply.c
…
archive.c
…
backfill.c
…
bisect.c Merge branch 'js/coverity-unchecked-returns-fix' 2026-08-24 13:17:50 -07:00
blame.c Merge branch 'bc/parse-options-exit-0-on-help' 2026-07-19 10:42:16 -07:00
branch.c Merge branch 'hn/branch-delete-merged' 2026-08-20 07:30:51 -07:00
bugreport.c
…
bundle.c bundle: generate packfiles via the object database 2026-08-21 09:01:55 -07:00
cat-file.c Merge branch 'ps/cat-file-remote-object-info-type' 2026-08-23 18:01:42 -07:00
check-attr.c
…
check-ignore.c
…
check-mailmap.c
…
check-ref-format.c refs: remove remaining uses of `the_repository` 2026-07-16 07:40:22 -07:00
checkout--worker.c
…
checkout-index.c
…
checkout.c refs: remove remaining uses of `the_repository` 2026-07-16 07:40:22 -07:00
clean.c
…
clone.c Merge branch 'af/clone-revision-v0-segfault-fix' 2026-08-03 09:31:29 -07:00
column.c
…
commit-graph.c
…
commit-tree.c
…
commit.c
…
config.c Merge branch 'js/coverity-unchecked-returns-fix' 2026-08-24 13:17:50 -07:00
count-objects.c
…
credential-cache--daemon.c
…
credential-cache.c
…
credential-store.c
…
credential.c
…
describe.c Merge branch 'kk/prio-queue-get-put-fusion' 2026-07-13 08:27:27 -07:00
diagnose.c
…
diff-files.c
…
diff-index.c
…
diff-pairs.c
…
diff-tree.c
…
diff.c diff: handle NULL return from repo_get_commit_tree() 2026-07-10 08:13:54 -07:00
difftool.c Merge branch 'rs/tempfile-wo-the-repository' 2026-07-30 10:32:02 -07:00
fast-export.c Merge branch 'ps/refspec-wo-the-repository' 2026-07-27 09:09:00 -07:00
fast-import.c Merge branch 'js/pack-objects-delta-size-t' 2026-08-24 13:17:51 -07:00
fetch-pack.c repository: move fetch_if_missing into struct repository 2026-08-15 08:37:54 -07:00
fetch.c Merge branch 'ps/refspec-wo-the-repository' 2026-07-27 09:09:00 -07:00
fmt-merge-msg.c
…
for-each-ref.c
…
for-each-repo.c
…
fsck.c Merge branch 'ty/repository-fetch-if-missing' 2026-09-02 09:21:59 -07:00
fsmonitor--daemon.c fsmonitor: plug token-data leak on early daemon-startup failures 2026-07-05 09:12:10 -07:00
gc.c Merge branch 'ps/odb-pluggable-housekeeping' 2026-08-05 11:10:51 -07:00
get-tar-commit-id.c
…
grep.c Merge branch 'ps/odb-generalize-prepare' 2026-07-13 08:27:28 -07:00
hash-object.c
…
help.c
…
history.c Merge branch 'rs/tempfile-wo-the-repository' 2026-07-30 10:32:02 -07:00
hook.c
…
index-pack.c Merge branch 'ty/repository-fetch-if-missing' 2026-09-02 09:21:59 -07:00
init-db.c setup: pass worktree to `init_db()` 2026-07-07 10:49:41 -07:00
interpret-trailers.c
…
last-modified.c last-modified: handle repo_parse_commit() failures 2026-08-12 09:05:50 -07:00
log.c Merge branch 'jk/format-patch-leakfix' 2026-07-13 08:27:27 -07:00
ls-files.c Merge branch 'js/objects-larger-than-4gb-on-windows-more' 2026-06-21 16:41:38 -07:00
ls-remote.c
…
ls-tree.c
…
mailinfo.c
…
mailsplit.c mailsplit: move NULL check before first use of file handle 2026-07-10 08:13:54 -07:00
merge-base.c
…
merge-file.c
…
merge-index.c
…
merge-ours.c
…
merge-recursive.c
…
merge-tree.c
…
merge.c Merge branch 'tc/merge-default-to-upstream-leakfix' 2026-08-07 14:48:01 -07:00
mktag.c
…
mktree.c
…
multi-pack-index.c
…
mv.c Merge branch 'lo/mv-missing-dest-dir-check' 2026-08-11 10:07:00 -07:00
name-rev.c
…
notes.c worktree: pass repository to public functions 2026-07-16 07:40:22 -07:00
pack-objects.c Merge branch 'ty/repository-fetch-if-missing' 2026-09-02 09:21:59 -07:00
pack-redundant.c
…
pack-refs.c
…
patch-id.c hash: use git_hash_init() consistently 2026-07-07 21:56:00 -07:00
prune-packed.c
…
prune.c repository: move fetch_if_missing into struct repository 2026-08-15 08:37:54 -07:00
pull.c refspec: let callers pass in hash algorithm when parsing items 2026-07-16 13:58:25 -07:00
push.c Merge branch 'ty/migrate-excludes-file' 2026-07-30 10:32:03 -07:00
range-diff.c
…
read-tree.c
…
rebase.c reset: introduce ability to skip updating HEAD 2026-07-03 10:32:33 -07:00
receive-pack.c odb/transaction: add transaction interface to write packfiles 2026-08-20 20:28:02 -07:00
reflog.c worktree: pass repository to public functions 2026-07-16 07:40:22 -07:00
refs.c worktree: pass repository to public functions 2026-07-16 07:40:22 -07:00
remote-ext.c
…
remote-fd.c
…
remote.c
…
repack.c builtin/repack: add guards for --drop-filtered 2026-08-13 13:34:50 -07:00
replace.c
…
replay.c
…
repo.c setup: move prefix into repository 2026-07-07 10:49:40 -07:00
rerere.c
…
reset.c
…
rev-list.c repository: move fetch_if_missing into struct repository 2026-08-15 08:37:54 -07:00
rev-parse.c setup: move prefix into repository 2026-07-07 10:49:40 -07:00
revert.c
…
rm.c
…
send-pack.c refspec: stop depending on `the_repository` 2026-07-16 13:58:25 -07:00
shortlog.c parse-options: exit 0 on -h 2026-07-07 17:48:57 -07:00
show-branch.c
…
show-index.c
…
show-ref.c
…
sparse-checkout.c use repo_hold_lock_file_for_update{,_mode,_timeout}() with custom repos 2026-07-14 12:54:25 -07:00
stash.c stash: avoid sparse-index expansion for in-cone paths 2026-07-21 10:33:25 -07:00
stripspace.c
…
submodule--helper.c Merge branch 'ps/refspec-wo-the-repository' 2026-07-27 09:09:00 -07:00
symbolic-ref.c
…
tag.c
…
unpack-file.c
…
unpack-objects.c Merge branch 'jt/receive-pack-pluggable-writes' 2026-08-31 08:25:00 -07:00
update-index.c odb/transaction: add transaction finalize interface 2026-08-20 20:28:01 -07:00
update-ref.c
…
update-server-info.c
…
upload-archive.c
…
upload-pack.c builtin/upload-pack: don't disable lazy fetching on trusted repo 2026-10-02 07:40:34 -07:00
url-parse.c
…
var.c
…
verify-commit.c
…
verify-pack.c
…
verify-tag.c
…
worktree.c Merge branch 'yn/worktree-add-no-dwim-with-b' 2026-08-31 08:24:58 -07:00
write-tree.c
…