fix(git-env): skip the HTTP header probe for non-HTTP effective URLs - #2906
Draft
Arnaud (arnaudoisel) wants to merge 2 commits into
Draft
fix(git-env): skip the HTTP header probe for non-HTTP effective URLs#2906Arnaud (arnaudoisel) wants to merge 2 commits into
Arnaud (arnaudoisel) wants to merge 2 commits into
Conversation
An `insteadOf` rule that rewrites the fetched HTTPS URL to SSH, such as `url."git@github.com:".insteadOf = https://github.com/`, made every private dependency download fail on the authenticated retry. `_validated_git_url_rewrite_policy` asked whether an HTTP `extraHeader` applied to the effective URL. With an SCP-style target that probe ran `git config --get-urlmatch http.extraHeader git@github.com:owner/repo`, which git rejects with `invalid URL scheme name or missing '://' suffix` and exit status 128, so the probe raised `GitUrlRewriteProbeError`. An HTTP header can never reach a non-HTTP transport, so the answer is already known: report no authorization and do not spawn the probe. The remaining non-zero branch now names the exit status instead of only saying the probe failed. Fixes microsoft#2898
|
Arnaud (@arnaudoisel) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Since 0.30.0,
apm installcannot download a private Git dependency when the user's Git config holds aninsteadOfrule that rewrites the fetched URL to SSH:The install fails with
Unable to verify Git URL rewrite safety (Git URL-match probe failed)and tells the user to remove a legitimate, very common rule.Root cause.
_validated_git_url_rewrite_policyresolves the rewrite, then asks_has_applicable_http_authorizationwhether an HTTPextraHeaderapplies to the effective URL. On the authenticated retry APM has injectedhttp.extraheader = Authorization: ...in thecommandscope, so the header group is non-empty and_urlmatched_header_groupruns:Git rejects SCP-style syntax there with
fatal: invalid URL scheme name or missing '://' suffixand exit status 128 -- neither 0 nor 1 -- so the probe raisesGitUrlRewriteProbeError. Measured with git 2.55.0 and an injectedGIT_CONFIG_KEY_0=http.extraheader:--get-urlmatchhttps://github.com/o/rssh://git@github.com/o/rgit@github.com:o/rThat explains the three conditions needed to trigger it: only the authenticated retry (a public dependency never injects a header), only a rule that matches the fetched URL, and only when something must actually be downloaded.
Fix. An HTTP header can never reach a non-HTTP transport, so the answer is already known without asking Git.
_has_applicable_http_authorizationnow returnsFalsefor any effective URL that is not HTTP(S), before spawning the probe. The single guard covers both callers, includingGitConfigInsteadOfResolver.resolveindeps/transport_selection.py._build_git_auth_fencealready had the equivalent scheme guard.The credential-origin rules in
validate_resolved_git_url_rewriteonly apply tohttp/httpstargets, so no rewrite that was rejected before is accepted now. Cross-host, HTTPS-downgrade, remote-helper and credential-bearing rewrites are all still rejected, as their existing tests confirm.Secondary: the remaining non-zero branch of the probe now names the exit status instead of only saying the probe failed, so a genuine failure is diagnosable. No raw Git output is rendered.
Fixes #2898
Type of change
Testing
Two regression tests in
tests/unit/cache/test_git_env.py, both under the existingwindows_compatmarker:test_clone_allows_scp_ssh_rewrite_while_a_header_is_injecteddrivesclone_git_worktreethrough the realgit configwith anAuthorizationheader andurl.git@git.example.com:.insteadOf. Onmainit fails with the exact error from the issue; with the fix the clone proceeds.test_scp_ssh_url_reports_no_http_authorization_without_probing_gitasserts the probe subprocess is never spawned for an SCP-style URL.Verified green:
tests/unit/cache/test_git_env.py(87), plustest_git_transport_policy.py,test_transport_selection.py,test_public_github_anonymous_first.py,test_validation_strict_transport.py,test_proxy_compat.py(244 total).ruff checkandruff format --checkclean on the changed files, andlint_architecture_boundaries.pypasses.Also reproduced end to end on Windows 11 with git 2.55.0 and the rule set globally: installing a private dependency with an empty cache logs the probe failure on 0.30.0 and no longer does with this change.
Spec conformance (OpenAPM v0.1)