{"thread":{"id":"64803","subject":"[PATCH v5] remote-curl: use auth for probe_rpc() requests too","startedAt":"2026-01-14T16:38:30Z","lastAt":"2026-01-14T16:38:30Z","messageCount":1,"participants":["Aaron Plattner"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"533841","messageId":"20260114163619.614297-2-aplattner@nvidia.com","threadId":"64803","inReplyTo":null,"subject":"[PATCH v5] remote-curl: use auth for probe_rpc() requests too","fromName":"Aaron Plattner","fromEmail":"aplattner@nvidia.com","sentAt":"2026-01-14T16:36:19Z","receivedAt":"2026-01-14T16:38:30Z","isPatch":true,"sender":{"key":"aplattner@nvidia.com","avatar":"https://avatars.githubusercontent.com/u/343551?v=4"},"body":"If a large request requires post_rpc() to call probe_rpc(), the latter\ndoes not use the authorization credentials used for other requests. If\nthis fails with an HTTP 401 error and http_auth.multistage isn't set,\nthen the whole request just fails.\n\nFor example, using git-credential-msal [1], the following attempt to clone a\nlarge repository fails partway through because the initial request to download\nthe commit history and promisor packs succeeds, but the\nsubsequent request to download the blobs needed to construct the working\ntree fails with a 401 error and the checkout fails.\n\n(lines removed for brevity)\n\n  git clone --filter=blob:none https://secure-server.example/repo\n  11:03:26.855369 git.c:502               trace: built-in: git clone --filter=blob:none https://secure-server.example/repo\n  Cloning into 'sw'...\n  warning: templates not found in /home/aaron/share/git-core/templates\n  11:03:26.857169 run-command.c:673       trace: run_command: git remote-https origin https://secure-server.example/repo\n  11:03:27.012104 http.c:849              => Send header: GET repo/info/refs?service=git-upload-pack HTTP/1.1\n  11:03:27.049243 http.c:849              <= Recv header: HTTP/1.1 401 Unauthorized\n  11:03:27.049270 http.c:849              <= Recv header: WWW-Authenticate: Bearer error=\"invalid_request\", error_description=\"No bearer token found in the request\", msal-tenant-id=\"<tenant>\", msal-client-id=\"<client>\"\n  11:03:27.053786 run-command.c:673       trace: run_command: 'git credential-msal get'\n  11:03:27.952830 http.c:849              => Send header: GET repo/info/refs?service=git-upload-pack HTTP/1.1\n  11:03:27.952849 http.c:849              => Send header: Authorization: Bearer <redacted>\n  11:03:27.995419 http.c:849              <= Recv header: HTTP/1.1 200 OK\n  11:03:28.230039 http.c:890              == Info: Reusing existing https: connection with host secure-server.example\n  11:03:28.230208 http.c:849              => Send header: POST repo/git-upload-pack HTTP/1.1\n  11:03:28.230216 http.c:849              => Send header: Content-Type: application/x-git-upload-pack-request\n  11:03:28.230221 http.c:849              => Send header: Authorization: Bearer <redacted>\n  11:03:28.269085 http.c:849              <= Recv header: HTTP/1.1 200 OK\n  11:03:28.684163 http.c:890              == Info: Reusing existing https: connection with host secure-server.example\n  11:03:28.684379 http.c:849              => Send header: POST repo/git-upload-pack HTTP/1.1\n  11:03:28.684391 http.c:849              => Send header: Accept: application/x-git-upload-pack-result\n  11:03:28.684393 http.c:849              => Send header: Authorization: Bearer <redacted>\n  11:03:28.869546 run-command.c:673       trace: run_command: git index-pack --stdin --fix-thin '--keep=fetch-pack 43856 on dgx-spark' --promisor\n  11:06:39.861237 run-command.c:673       trace: run_command: git -c fetch.negotiationAlgorithm=noop fetch origin --no-tags --no-write-fetch-head --recurse-submodules=no --filter=blob:none --stdin\n  11:06:39.865981 run-command.c:673       trace: run_command: git remote-https origin https://secure-server.example/repo\n  11:06:39.868039 run-command.c:673       trace: run_command: git-remote-https origin https://secure-server.example/repo\n  11:07:30.412575 http.c:849              => Send header: GET repo/info/refs?service=git-upload-pack HTTP/1.1\n  11:07:30.456285 http.c:849              <= Recv header: HTTP/1.1 401 Unauthorized\n  11:07:30.456318 http.c:849              <= Recv header: WWW-Authenticate: Bearer error=\"invalid_request\", error_description=\"No bearer token found in the request\", msal-tenant-id=\"<tenant>\", msal-client-id=\"<client>\"\n  11:07:30.456439 run-command.c:673       trace: run_command: 'git credential-cache get'\n  11:07:30.461266 http.c:849              => Send header: GET repo/info/refs?service=git-upload-pack HTTP/1.1\n  11:07:30.461282 http.c:849              => Send header: Authorization: Bearer <redacted>\n  11:07:30.501628 http.c:849              <= Recv header: HTTP/1.1 200 OK\n  11:07:34.725262 http.c:849              => Send header: POST repo/git-upload-pack HTTP/1.1\n  11:07:34.725279 http.c:849              => Send header: Content-Type: application/x-git-upload-pack-request\n  11:07:34.761407 http.c:849              <= Recv header: HTTP/1.1 401 Unauthorized\n  11:07:34.761443 http.c:890              == Info: Bearer authentication problem, ignoring.\n  11:07:34.761453 http.c:849              <= Recv header: WWW-Authenticate: Bearer error=\"invalid_request\", error_description=\"No bearer token found in the request\", msal-tenant-id=\"<tenant>\", msal-client-id=\"<client>\"\n  11:07:34.761509 http.c:890              == Info: The requested URL returned error: 401\n  11:07:34.761530 http.c:890              == Info: closing connection #0\n  11:07:34.761913 run-command.c:673       trace: run_command: 'git credential-cache erase'\n  11:07:34.761927 run-command.c:765       trace: start_command: /bin/sh -c 'git credential-cache erase' 'git credential-cache erase'\n  11:07:34.768069 git.c:502               trace: built-in: git credential-cache erase\n  11:07:34.768690 run-command.c:673       trace: run_command: 'git credential-msal erase'\n  11:07:34.768713 run-command.c:765       trace: start_command: /bin/sh -c 'git credential-msal erase' 'git credential-msal erase'\n  11:07:34.772742 git.c:808               trace: exec: git-credential-msal erase\n  11:07:34.772783 run-command.c:673       trace: run_command: git-credential-msal erase\n  11:07:34.772819 run-command.c:765       trace: start_command: /usr/bin/git-credential-msal erase\n  error: RPC failed; HTTP 401 curl 22 The requested URL returned error: 401\n  fatal: unable to write request to remote: Broken pipe\n  fatal: could not fetch c4fff0229c9be06ecf576356a4d39a8a755b8d81 from promisor remote\n  warning: Clone succeeded, but checkout failed.\n  You can inspect what was checked out with 'git status'\n  and retry with 'git restore --source=HEAD :/'\n\nIn this case, the HTTP_REAUTH retry logic is not used because the\ncredential helper didn't set the 'continue' flag, so\nhttp_auth.multistage is false and handle_curl_result() fails with\nHTTP_NOAUTH instead.\n\nFix the immediate problem by including the authorization headers in the\nprobe_rpc() request as well.\n\nAdd a test for this scenario:\n\n 1. Create a repository with two thousand refs.\n 2. Clone that into the web root used by t5563-simple-http-auth.sh.\n 3. Configure http.postBuffer to be very small in order to trigger the\n    probe_rpc() path that fails.\n 4. Clone using a valid Bearer token.\n\n[1] https://github.com/Binary-Eater/git-credential-msal\n\nTested-by: Lucas De Marchi <demarchi@kernel.org>\nSigned-off-by: Aaron Plattner <aplattner@nvidia.com>\n---\nv5: use test_seq -f, reorder Tested-by vs Signed-off-by lines\n\n remote-curl.c               |  1 +\n t/t5563-simple-http-auth.sh | 45 +++++++++++++++++++++++++++++++++++++\n 2 files changed, 46 insertions(+)\n\ndiff --git a/remote-curl.c b/remote-curl.c\nindex 69f919454a..92e40bb682 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -876,6 +876,7 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)\n \n \theaders = curl_slist_append(headers, rpc->hdr_content_type);\n \theaders = curl_slist_append(headers, rpc->hdr_accept);\n+\theaders = http_append_auth_header(&http_auth, headers);\n \n \tcurl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0L);\n \tcurl_easy_setopt(slot->curl, CURLOPT_POST, 1L);\ndiff --git a/t/t5563-simple-http-auth.sh b/t/t5563-simple-http-auth.sh\nindex c1febbae9d..0063581615 100755\n--- a/t/t5563-simple-http-auth.sh\n+++ b/t/t5563-simple-http-auth.sh\n@@ -605,6 +605,51 @@ test_expect_success 'access using bearer auth with invalid credentials' '\n \tEOF\n '\n \n+test_expect_success 'clone with bearer auth and probe_rpc' '\n+\ttest_when_finished \"per_test_cleanup\" &&\n+\ttest_when_finished \"rm -rf large.git\" &&\n+\n+\t# Set up a repository large enough to trigger probe_rpc\n+\tgit init large.git &&\n+\t(\n+\t\tcd large.git &&\n+\t\tgit config set maintenance.auto false &&\n+\t\tgit commit --allow-empty --message \"initial\" &&\n+\t\t# Create many refs to trigger probe_rpc, which is called when\n+\t\t# the request body is larger than http.postBuffer.\n+\t\t#\n+\t\t# In the test later, http.postBuffer is set to 70000. Each\n+\t\t# \"want\" line is ~45 bytes, so we need at least 70000/45 = ~1600\n+\t\t# refs\n+\t\ttest_seq -f \"create refs/heads/branch-%d @\" 2000 |\n+\t\tgit update-ref --stdin\n+\t) &&\n+\tgit clone --bare large.git \"$HTTPD_DOCUMENT_ROOT_PATH/large.git\" &&\n+\n+\t# Clone it through HTTP with a Bearer token\n+\tset_credential_reply get <<-EOF &&\n+\tcapability[]=authtype\n+\tauthtype=Bearer\n+\tcredential=YS1naXQtdG9rZW4=\n+\tEOF\n+\n+\t# Bearer token\n+\tcat >\"$HTTPD_ROOT_PATH/custom-auth.valid\" <<-EOF &&\n+\tid=1 creds=Bearer YS1naXQtdG9rZW4=\n+\tEOF\n+\n+\tcat >\"$HTTPD_ROOT_PATH/custom-auth.challenge\" <<-EOF &&\n+\tid=1 status=200\n+\tid=default response=WWW-Authenticate: Bearer authorize_uri=\"id.example.com\"\n+\tEOF\n+\n+\t# Set a small buffer to force probe_rpc to be called\n+\t# Must be > LARGE_PACKET_MAX (65520)\n+\ttest_config_global http.postBuffer 70000 &&\n+\ttest_config_global credential.helper test-helper &&\n+\tgit clone \"$HTTPD_URL/custom_auth/large.git\" partial-auth-clone 2>clone-error\n+'\n+\n test_expect_success 'access using three-legged auth' '\n \ttest_when_finished \"per_test_cleanup\" &&\n \n-- \n2.52.0\n\n"}]}