All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org,
	 "brian m . carlson" <sandals@crustytoothpaste.net>,
	 Patrick Steinhardt <ps@pks.im>,
	 Karthik Nayak <karthik.188@gmail.com>,
	 Jeff King <peff@peff.net>,  Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v3 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo
Date: Tue, 08 Sep 2026 11:34:51 -0700	[thread overview]
Message-ID: <xmqqmrtrwq0k.fsf@gitster.g> (raw)
In-Reply-To: <20260908164129.560396-6-christian.couder@gmail.com> (Christian Couder's message of "Tue, 8 Sep 2026 18:41:29 +0200")

Christian Couder <christian.couder@gmail.com> writes:

> 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.
>
> Let's instead set `GIT_NO_LAZY_FETCH` to `0`, which 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.

While I agree that it is a good idea to make it more lenient to work
with remotes that are explicitly marked as trusted, it somehow feels
a bit unnatural for a configuration variable, or a conclusion
derived from the setting of a configuration variable, overriding an
environment variable.  Who is setting this environment variable in
the first place?

If NO_LAZY_FETCH is what server operators set and export, I strongly
suspect that not honoring it merely because the new variable could
be used to give them a finer-grained control would be very
surprising experience for them.

If the answer is "this never comes from the end-user or the server
operator.  We used to automatically set NO_LAZY_FETCH from the
process that spawns uploadpack because we trusted nobody", then I'd
imagine that we would prefer to see that code that automatically
sets NO_LAZY_FETCH to inspect the configuration variable and to
decide not to do so.

And I think that is what the code is doing (in other words, from a
cursory read, I think the new code is doing the right thing and it
is just the way how the above is explained that I found it iffy).
We used to say "when serving a client, we do not lazy fetch what we
are missing from our promisor remotes by setting NO_LAZY_FETCH" and
it was unconditional.

I think what we want to happen is:

 * If the server operator has NO_LAZY_FETCH set, we honor it and do
   not do anything.

 * If the server operator does not have NO_LAZY_FETCH set, then we
   see if the configuration variable is there, and if there is, we
   let it take care of which promisor remote to allow by not futzing
   with NO_LAZY_FETCH ourselves.

 * Otherwise, we set and export NO_LAZY_FETCH just we used to.

and what you have in the patch is close enough to that (you left the
historical "disable lazy fetch upfront" so worst case you export the
thing twice which is not necessary).

> This allows server operators to properly control lazy fetching. It is
> their responsibility, not the client's, to decide if the served repo is
> trusted,

If "the served repo" refers to where the client is fetching from,
trusting that repository or not is up to the client; if they do not
trust it, they should not be coming to you.

I may be misunderstanding what you are trying to say here, but what
is up to the server operator to decide is if the promisor remotes,
which the repo that is serving the client uses, is trustworthy,
right?

> As `GIT_NO_LAZY_FETCH` is passed down to child processes through the
> environment, this works for `pack-objects`, which performs the lazy
> fetch when serving a client, without any further plumbing.
>
> Now that "uploadpack.lazyFetchTrusted" is actually doing something,
> let's document it and reference it from GIT_NO_LAZY_FETCH's docs.

> diff --git a/builtin/upload-pack.c b/builtin/upload-pack.c
> index 32831fb879..8b531ca724 100644
> --- a/builtin/upload-pack.c
> +++ b/builtin/upload-pack.c
> @@ -42,10 +42,13 @@ int cmd_upload_pack(int argc,
>  		OPT_END()
>  	};
>  	unsigned enter_repo_flags = ENTER_REPO_ANY_OWNER_OK;
> +	bool no_lazy_fetch_set;
>  
>  	packet_trace_identity("upload-pack");
>  	disable_replace_refs();
>  	save_commit_buffer = 0;
> +
> +	no_lazy_fetch_set = !!getenv(NO_LAZY_FETCH_ENVIRONMENT);
>  	xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 0);

I am not seeing what is in the postcontext of this hunk and in the
precontext of the next hunk, but I wonder if we can just remove this
xsetenv (without "no_lazy_fetch_set" variable at all) here ...

>  	argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
> @@ -62,6 +65,14 @@ int cmd_upload_pack(int argc,
>  	if (!enter_repo(the_repository, dir, enter_repo_flags))
>  		die("'%s' does not appear to be a git repository", dir);
>  
> +	/*
> +	 * Relax the GIT_NO_LAZY_FETCH=1 default if the served repo is in
> +	 * the "uploadpack.lazyFetchTrusted" protected allowlist and
> +	 * GIT_NO_LAZY_FETCH was not already set explicitly.
> +	 */
> +	if (!no_lazy_fetch_set && upload_pack_lazy_fetch_trusted(the_repository))
> +		xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "0", 1);

... and instead check the existing environment here, and do the
choice from three possibilities I listed above here.

Other than that, this is a great endgame of the series.

Thanks.

  reply	other threads:[~2026-09-08 18:34 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10  8:51 [PATCH 0/3] Introduce a 'fromAccepted' option to GIT_NO_LAZY_FETCH Christian Couder
2026-07-10  8:51 ` [PATCH 1/3] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-07-10  8:51 ` [PATCH 2/3] promisor-remote: introduce enum allow_lazy_fetch Christian Couder
2026-07-10  8:51 ` [PATCH 3/3] promisor-remote: teach 'fromAccepted' to GIT_NO_LAZY_FETCH Christian Couder
2026-07-10 19:50 ` [PATCH 0/3] Introduce a 'fromAccepted' option " brian m. carlson
2026-07-12  9:06   ` Christian Couder
2026-08-07 13:55 ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Christian Couder
2026-08-07 13:55   ` [PATCH 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-08-07 13:58     ` Christian Couder
2026-08-07 13:55   ` [PATCH 2/5] setup: extract path_allowlist_apply() Christian Couder
2026-08-07 13:55   ` [PATCH 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
2026-08-07 13:55   ` [PATCH 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
2026-08-07 13:55   ` [PATCH 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
2026-08-07 18:31   ` [PATCH 0/5] Introduce 'uploadpack.lazyFetchTrusted' Junio C Hamano
2026-08-10  8:06     ` Christian Couder
2026-08-11  5:55       ` Junio C Hamano
2026-08-13 15:47   ` [PATCH v2 " Christian Couder
2026-08-13 20:31     ` Junio C Hamano
2026-08-14 16:31       ` Christian Couder
2026-08-14 16:40         ` Junio C Hamano
2026-09-08 16:41     ` [PATCH v3 " Christian Couder
2026-09-08 16:41       ` [PATCH v3 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-09-08 17:39         ` Junio C Hamano
2026-09-08 16:41       ` [PATCH v3 2/5] setup: extract path_allowlist_apply() Christian Couder
2026-09-08 17:48         ` Junio C Hamano
2026-09-08 16:41       ` [PATCH v3 3/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
2026-09-08 16:41       ` [PATCH v3 4/5] promisor-remote: prevent infinite recursion when lazy fetching Christian Couder
2026-09-08 18:12         ` Junio C Hamano
2026-09-09 10:00           ` Christian Couder
2026-09-09 21:39             ` Junio C Hamano
2026-09-08 16:41       ` [PATCH v3 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
2026-09-08 18:34         ` Junio C Hamano [this message]
2026-08-13 15:47   ` [PATCH v2 1/5] promisor-remote: factor out lazy_fetch_objects() Christian Couder
2026-08-14 17:49     ` Junio C Hamano
2026-09-08 17:11       ` Christian Couder
2026-08-13 15:47   ` [PATCH v2 2/5] setup: extract path_allowlist_apply() Christian Couder
2026-08-14 17:56     ` Junio C Hamano
2026-09-08 16:46       ` Christian Couder
2026-09-08 17:49         ` Junio C Hamano
2026-08-13 15:47   ` [PATCH v2 3/5] setup: add 'allow_dot' arg to path_allowlist_apply() Christian Couder
2026-08-14 18:12     ` Junio C Hamano
2026-09-08 16:55       ` Christian Couder
2026-08-13 15:47   ` [PATCH v2 4/5] upload-pack: read uploadpack.lazyFetchTrusted Christian Couder
2026-08-14 18:56     ` Junio C Hamano
2026-08-13 15:47   ` [PATCH v2 5/5] builtin/upload-pack: set GIT_NO_LAZY_FETCH to 0 on trusted repo Christian Couder
2026-08-14 19:35     ` Junio C Hamano
2026-09-08 17:02       ` Christian Couder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmrtrwq0k.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    --cc=ps@pks.im \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.