Repository navigation
arch(auth): guard authenticated HTTP egress and credential headers - #3823
Daniel Meppiel (danielmeppiel) merged 26 commits into
Conversation
AuthResolver.try_with_fallback is now the single entry for authenticated host access. A new core/auth_outcome.py owns auth-outcome classification (401/403, a redirect to the ADO sign-in service, an HTML sign-in page, Git auth errors) and core/auth_chain.py walks ADO_APM_PAT -> az bearer -> path-scoped git credential fill, recording an AuthAttemptLog that diagnostics render. - Route install validation, clone, ref resolution, install --update preflight, ADO file downloads, org policy discovery (ADO, GitHub with per-org PAT, GitLab) and marketplace REST/ref paths through the chain. - Helper credentials keep their username (GitHelperCredential) and are sent as Basic username:password, cached per (host, port, path). - git credential fill sets GCM_INTERACTIVE=0 when stdin is not a TTY or CI is set; APM never calls credential approve/reject. - Azure DevOps requests use only the credential chosen by the auth chain. - #3753: az token failures show the Azure CLI reason; the exhausted chain lists every step in order; "bearer token" is no longer redacted. - Remove execute_with_bearer_fallback; is_ado_auth_failure_signal and is_public_github_auth_failure become thin classifier wrappers. - Static guard transport-platform-auth-outcome-owner on the host-credential-resolution owner record, with a mutation case. No live Azure DevOps organization was available: behavior follows the documented contracts and is validated by hermetic tests. Fixes #3752 Fixes #3758 Fixes #3753 apm-spec-waiver: auth chain owner refactor with no spec surface change Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…ject guard Fold panel follow-ups on #3790: RefResolver converts an exhausted ADO chain into GitLsRemoteError naming every step (new integration test), and transport-platform-auth-outcome-owner also rejects shell-string forms of git credential approve/reject. Co-authored-by: Copilot App <[email protected]>
…-in redirects - Legacy *.visualstudio.com remotes query the credential helper with the Project/_git/repo path the helper stores. - Tenant id lookup is single-flight under a lock. - ADO file downloads and marketplace ADO REST fetches no longer follow redirects; a sign-in 3xx reaches the classifier and the chain escalates. apm-spec-waiver: review folds inside the approved auth owner scope Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…e chain Co-authored-by: Copilot App <[email protected]>
The cause-chain walk follows __cause__/__context__ only through real exceptions, and any other error value is read as text. apm-spec-waiver: hardening inside the approved auth classifier owner Co-authored-by: Copilot App <[email protected]>
Add transport-platform-authenticated-egress, an AST architecture-linter rule that keeps HTTP egress primitives (requests verbs and sessions, urllib urlopen) and literal credential header keys in their owner modules or in a frozen, reasoned inventory that can only shrink. The rule carries two guard ids registered on host-credential-resolution and credential-origin-scope. lint-auth-signals.sh drops stale Rule A exemptions and Rule B now defers to the architecture linter. Refs #3752, #3726 Co-authored-by: Copilot App <[email protected]>
…he redirect owner The ADO items fetch sends only the chain-selected Authorization header, disables ambient credentials, and refuses the cross-origin sign-in redirect so the auth chain classifies the 3xx and escalates. apm-spec-waiver: adapts the approved auth owner to the redirect owner API Co-authored-by: Copilot App <[email protected]>
…lls; widen resolve fakes - Add RT1's lock replay (0.35.1 / 0.36.0 locks) and ADO adjacent-egress installed-CLI scenarios byte-for-byte. - Resolver test doubles accept the port/host_type keywords the chain now passes. Co-authored-by: Copilot App <[email protected]>
… main Co-authored-by: Copilot App <[email protected]>
…n fallback - Every ADO chain step's git env carries only its own Authorization header, suppresses credential helpers, and holds no PAT, bearer, or ambient GitHub token from another step (PAT -> bearer -> helper and tokenless). - A failing AuthResolver never lets the GitHub policy fetch fall back to GITHUB_TOKEN, GITHUB_APM_PAT, or GH_TOKEN from the environment. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…uthenticated-egress-guard # Conflicts: # .apm/architecture/owners/transport-auth-platform.json # scripts/architecture_linter/groups/transport_platform.py # scripts/lint-auth-signals.sh # tests/integration/test_architecture_owner_rule_mutations.py # tests/unit/scripts/test_architecture_runner.py
Policy fetches (URL, GitHub, Azure DevOps, GitLab), the Artifactory boundary probe and the install validation GitHub probe now send through origin_bounded_request. Policy and probe redirects away from the requested resource stay unfollowed and are reported as before. Literal credential headers move to AuthResolver.github_rest_headers, AuthResolver.bearer_headers and RegistryAuthContext.headers. The authenticated-egress inventory drops every pending entry; the origin-bounded-redirect inventory drops the policy and Artifactory entries; lint-auth-signals Rule B also defers auth-outcome-owner. Refs #3752, #3726 Co-authored-by: Copilot App <[email protected]>
…d_request The origin-bounded owner sends every hop without automatic redirects and refuses HTTPS downgrades, so the response URL check in _fetch_url_direct could never fire. The test now drives a downgrade redirect through the owner instead of faking a final URL. Refs #3726 Co-authored-by: Copilot App <[email protected]>
DownloadDelegate.resilient_get takes redirect_base instead of allow_redirects; when set, every retry attempt goes through origin_bounded_request bounded to that base, with ambient netrc excluded. download_ado_file passes its request URL, so no redirect is followed and a sign-in 3xx still reaches the auth-outcome classifier. The 429/503/connection retry and backoff loop is unchanged. A shared owner helper, unfollowed_redirect_request, returns the refused 3xx instead of raising; policy fetches and the Artifactory boundary probe use it too. The download_strategies entry leaves the origin-bounded-redirect inventory. apm-spec-waiver: redirect routing inside the approved auth and redirect owners Refs #3752, #3726 Co-authored-by: Copilot App <[email protected]>
…ner seam Refs #3752 Co-authored-by: Copilot App <[email protected]>
The authenticated-egress owner case now reintroduces urllib.request.urlopen in the marketplace metadata fetch; direct requests.get egress stays covered by the rule's unit tests. Refs #3726 Co-authored-by: Copilot App <[email protected]>
…ted-egress-guard #3790's squash differs from the previously merged head 74ef67d only in three test files; those deltas are applied here. Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved issues allow redirects to unintended resources, break policy URLs using HTTP Basic credentials, and let raw session HTTP calls bypass the egress guard.
3 open issues
What changed in this PR
This PR adds static enforcement for APM’s shared authentication and HTTP transport owners, building on #3785 and #3790.
Changes:
- Adds an AST guard for raw HTTP calls and credential-header construction, with reasoned exemption inventories.
- Centralizes header builders and routes policy fetches, validation probes, Artifactory probes and ADO downloads through shared HTTP helpers.
- Updates lint registration, adds regression coverage and retargets existing test mocks.
| File | Description |
|---|---|
tests/unit/test_install_command.py |
Retargets validation mocks. |
tests/unit/test_audit_policy_command.py |
Retargets policy-fetch mocks. |
tests/unit/test_artifactory_support.py |
Retargets boundary-probe mocks. |
tests/unit/scripts/test_architecture_runner.py |
Registers the new rule in the expected inventory. |
tests/unit/scripts/test_architecture_authenticated_egress.py |
Tests egress/header detection and stale exemptions. |
tests/unit/policy/test_policy_serialization_properties.py |
Retargets policy transport mocks. |
tests/unit/policy/test_policy_http.py |
Tests redirect responses and selected credentials. |
tests/unit/policy/test_extends_host_pin.py |
Exercises redirect refusal through the HTTP owner. |
tests/unit/policy/test_discovery.py |
Updates provider-specific policy mocks. |
tests/unit/policy/test_discovery_policy_resolution.py |
Updates resolution and authenticated-URL mocks. |
tests/unit/policy/test_discovery_phase3w4.py |
Retargets policy discovery mocks. |
tests/unit/policy/test_cache_merged_effective.py |
Updates transport mocks for cache tests. |
tests/unit/marketplace/test_marketplace_client.py |
Tests HTTPS downgrade refusal through the owner. |
tests/unit/install/test_validation_transient_probe.py |
Adds API-origin redirect coverage. |
tests/unit/install/test_validation_tls.py |
Retargets TLS validation mocks. |
tests/unit/install/test_validation_rate_limit.py |
Retargets rate-limit validation mocks. |
tests/unit/install/test_validation_proxy.py |
Retargets proxy-mode validation mocks. |
tests/unit/install/test_artifactory_resolver.py |
Adds owner-level boundary redirect coverage. |
tests/unit/deps/test_download_strategies_phase3.py |
Tests ADO sign-in redirect classification. |
tests/spec_conformance/test_policy_reqs.py |
Retargets fail-closed policy transport mocking. |
tests/integration/test_uninstall_policy_pack_flow.py |
Updates policy-fetch mocks. |
tests/integration/test_policy_url_chain_parity.py |
Updates URL-chain transport mocking. |
tests/integration/test_policy_coverage.py |
Retargets transport-failure mocking. |
tests/integration/test_integrators_validation_rules.py |
Retargets package-validation mocking. |
tests/integration/test_ghe_marketplace_install_e2e.py |
Updates outbound-probe mocks and explanatory comment. |
tests/integration/test_credential_fill_disambiguation.py |
Retargets credential-fallback validation mocks. |
tests/integration/test_artifactory_probe_pipeline_e2e.py |
Retargets pipeline boundary-probe mocks. |
tests/integration/test_architecture_owner_rule_mutations.py |
Adds mutations for both new guard IDs. |
tests/integration/test_ado_policy_project_coordinate.py |
Retargets ADO policy transport mocks. |
src/apm_cli/utils/http_credentials.py |
Adds a helper returning refused redirect responses. |
src/apm_cli/policy/discovery.py |
Routes policy requests through the shared helper. |
src/apm_cli/policy/_policy_http.py |
Adds the common policy HTTP entry point. |
src/apm_cli/policy/_gitlab.py |
Uses the shared policy transport. |
src/apm_cli/marketplace/client.py |
Reuses header construction; removes redundant HTTPS checking. |
src/apm_cli/marketplace/builder.py |
Reuses GitHub header construction. |
src/apm_cli/install/validation.py |
Adds origin-bounded GitHub API requests. |
src/apm_cli/install/artifactory_resolver.py |
Routes HEAD probes through the HTTP owner. |
src/apm_cli/deps/registry/client.py |
Uses registry-owned credential headers. |
src/apm_cli/deps/registry/auth.py |
Adds a credential-header mapping builder. |
src/apm_cli/deps/github_downloader.py |
Forwards the new redirect-base option. |
src/apm_cli/deps/github_downloader_validation.py |
Reuses GitHub header construction. |
src/apm_cli/deps/git_reference_resolver.py |
Reuses GitHub header construction. |
src/apm_cli/deps/download_strategies.py |
Adds bounded retry transport and shared headers. |
src/apm_cli/core/auth.py |
Adds GitHub and bearer header builders. |
src/apm_cli/commands/auth.py |
Reuses GitHub headers for token checks. |
scripts/lint-auth-signals.sh |
Removes stale exemptions and verifies deferred guards. |
scripts/architecture_linter/groups/transport_platform.py |
Loads the new egress rule. |
scripts/architecture_linter/checks/transport_origin_bounded_redirect.py |
Removes migrated redirect exemptions. |
scripts/architecture_linter/checks/transport_authenticated_egress.py |
Implements egress and credential-header ownership checks. |
scripts/architecture_linter/checks/transport_auth_outcome.py |
Updates the policy credential-routing check. |
.apm/architecture/owners/transport-auth-platform.json |
Registers both guard IDs on their owners. |
Review effort: Balanced
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 3 | 0 | Owner placement is sound: unfollowed_redirect_request lives in http_credentials and policy_get is a thin consumer. Tighten the resilient_get exemption, credential-header vocabulary, and owner registration. |
| Test Coverage Expert | 0 | 3 | 0 | Guard teeth and cross-origin refusal have regression traps (195 tests run, green). Gaps: the same-path bound of base_url=url, retries on redirect_base, and the probe token header. |
| Auth Expert | 0 | 3 | 0 | Token precedence and credential selection are unchanged; the ADO header change matches the old behavior and sign-in 3xx still reaches the classifier. Remaining issues are hardening and behavior edges. |
| Supply Chain Security Expert | 0 | 3 | 0 | Policy/ADO/Artifactory/probe migrations keep credentials on-origin. Fix the resilient_get inventory claim and make unfollowed mode truly unfollowed. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 5 follow-ups
- [auth-expert, supply-chain-security-expert, test-coverage-expert] IN THIS PR: make unfollowed_redirect_request truly unfollowed when base_url is not given (for example max_hops=0), and pin it with a real-socket same-origin same-path 302 test plus same-path cases for the ADO download and Artifactory probe. -- Three panelists converge; the fix(registry): follow redirects only within the configured registry origin #3785 inventory retirement and the ADO/Artifactory comments rely on refusing every redirect, and Artifactory existence semantics depend on it.
- [test-coverage-expert] IN THIS PR: parametrize the resilient_get 503/connection retry tests over redirect_base, assert the Authorization header the validation probe sends, and add a direct test for github_rest_headers and bearer_headers. -- The redirect_base branch and the Bearer-to-token change have no assertions; a regression would silently break ADO download retries or GitHub validation.
- [supply-chain-security-expert, python-architect] IN THIS PR: correct the resilient_get exemption reason and pin a site count per egress inventory key. POST-MERGE: route credential-bearing resilient_get calls through the owner with an origin-root base and ambient credentials off. -- A qualname-keyed exemption with no count would admit future credential-bearing egress inside resilient_get without review.
- [supply-chain-security-expert, python-architect] IN THIS PR: derive or pin the guard's credential-header key set to CREDENTIAL_HEADER_NAMES so Proxy-Authorization is covered. POST-MERGE: flag non-None auth= keywords outside the owners. -- The header vocabulary exists in three places and already disagrees.
- [auth-expert] IN THIS PR: pass ambient_credentials=False inside try_with_fallback callbacks (validation probe, GitHub and GitLab policy), surface RedirectRefusedError on the validation probe as an inconclusive probe or a verbose reason, and update the owner-record prose for the new helpers and consumers. -- Anonymous chain attempts should not pick up credentials outside AuthResolver precedence, and GHES users behind redirecting gateways need an actionable message.
Recommendation
Fold the in-PR items before the reviewer pass, highest priority first: the unfollowed_redirect_request contract fix and its real-socket test, the missing tests for the new wire behaviors, the resilient_get reason and site counts, the shared header vocabulary, the redirect-refused diagnostic and the owner-record prose. Track routing resilient_get through the owner and auth= keyword detection as post-merge issues. With those folds, this slice is ready for the 0.36.1 auth track.
Full per-persona findings
Python Architect
- [recommended] The function-wide exemption for resilient_get hides credential-bearing egress that skips the owner, and its stated reason does not match the code. at
scripts/architecture_linter/checks/transport_authenticated_egress.py:98
Same facts as the supply-chain finding 1. The sibling redirect check pins a site count per path; this one does not.
Suggested: Make the owner the default for credential-bearing resilient_get calls, or at minimum correct the reason and pin a site count per inventory key. - [recommended] The credential-header vocabulary now exists in three places and they disagree: the new guard omits Proxy-Authorization. at
scripts/architecture_linter/checks/transport_authenticated_egress.py:46
Split authority applied to linter vocabulary.
Suggested: Use one shared constant derived from or pinned to CREDENTIAL_HEADER_NAMES; add a proxy-authorization snippet test. - [recommended] Guard 2's owner allowlist covers files no owner record selects, and the owner records do not name the new helpers or consumers. at
.apm/architecture/owners/transport-auth-platform.json
deps/registry/auth.py is not selected by any record; the owner prose omits unfollowed_redirect_request, the new consumers, and the header builders.
Suggested: Update the owner/consumer prose in both records; scope deps/registry/auth.py ownership to RegistryAuthContext.auth_header/headers.
Test Coverage Expert
- [recommended] unfollowed_redirect_request says 'no redirect is followed at all', but a same-origin same-path redirect is followed; no test pins either behavior. at
src/apm_cli/utils/http_credentials.py:349
Verified on the head: origin_bound_refusal returns None for a different query or a sub-path. All new consumer tests use a cross-origin Location.
Suggested: Pick a contract and pin it with a real-socket test in tests/unit/utils/test_http_credentials.py plus an Artifactory same-path case.
Proof (missing at):tests/unit/utils/test_http_credentials.py-- proves: The documented redirect contract for credentialed policy/ADO/Artifactory fetches holds against a real HTTP server. [secure-by-default,governed-by-policy] - [recommended] The redirect_base branch of resilient_get has no test for the 503/ConnectionError retry loop. at
src/apm_cli/deps/download_strategies.py:130
All TestResilientGet cases patch requests.get, which this branch never calls; grep for redirect_base in tests/ returns 0 hits.
Suggested: Parametrize the retry tests over redirect_base, patching CredentialScopedSession.request.
Proof (missing at):tests/unit/deps/test_download_strategies_phase3.py-- proves: ADO file downloads still retry on a transient 503 or a dropped connection. [devx,secure-by-default] - [recommended] The validation GitHub probe's Bearer->token header change has no assertion on the header actually sent; the new header builders have no direct tests. at
src/apm_cli/install/validation.py:709
Updated tests patch _github_api_get but never check headers.
Suggested: Assert the Authorization header in a validation test; add a parametrized test for github_rest_headers and bearer_headers.
Proof (missing at):tests/unit/install/test_validation_tls.py-- proves: The validation probe sends the chosen GitHub credential scheme. [secure-by-default,devx]
Auth Expert
- [recommended] The helper documented as following no redirects still follows redirects that stay on the same path, and sends credentials on them. at
src/apm_cli/utils/http_credentials.py:364
unfollowed_redirect_request defaults base_url=url, and origin_bound_refusal accepts a same-origin target on the same path or below it (any query), for up to MAX_REDIRECT_HOPS. The old allow_redirects=False never followed anything. Credentials stay on the same origin and path, so the risk is low, but the docstring and the ADO/Artifactory comments promise no follow. The Artifactory probe also changes: an in-path 3xx was existence proof, and now the final status decides.
Suggested: When base_url is None, pass max_hops=0 so any 3xx comes back unfollowed. Add a same-path 302 test for the ADO download and the Artifactory probe. - [recommended] Anonymous auth-chain attempts in install validation and in GitHub/GitLab policy fetches can still pick up ambient netrc credentials. at
src/apm_cli/policy/_policy_http.py:25
_github_api_get and policy_get leave ambient_credentials at its default of True. With unauth_first=True, an anonymous attempt can be authenticated from .netrc, a source outside the AuthResolver precedence. Not a regression; the ADO policy path already opts out.
Suggested: Pass ambient_credentials=False for every request made inside a try_with_fallback callback (_github_api_get, _fetch_github_contents, _authenticated_gitlab_request). Keep netrc only for the plain policy URL fetch. Add a test. - [recommended] A cross-origin redirect on the GitHub API validation probe now fails validation with a generic message. at
src/apm_cli/install/validation.py:712
RedirectRefusedError is not recognized by _inconclusive_github_probe_detail, so validation returns False with no hint that a redirect was refused. Refusing it is correct for credential safety, but the diagnostic regresses for GHES gateways that redirect to another host.
Suggested: Treat RedirectRefusedError as an inconclusive probe, or log its reason through verbose_log. Add a test.
Supply Chain Security Expert
- [recommended] The resilient_get exemption reason overstates containment: GitHub Contents API and generic-host credential calls still use bare requests.get with ambient netrc and default redirect following. at
src/apm_cli/deps/download_strategies.py:179
With redirect_base None and allow_netrc True, resilient_get calls plain requests.get with token headers; netrc can override the explicit header and redirects are auto-followed. This predates the PR, but the qualname-keyed exemption admits any future credential-bearing caller.
Suggested: In resilient_get, route credential-bearing headers through the owner with base_url=origin_root(url) and ambient credentials off, or correct the inventory reason and file a follow-up. - [recommended] unfollowed_redirect_request with the default base_url=url still follows same-origin redirects to the same path or a sub-path; the docstring says no redirect is followed. at
src/apm_cli/utils/http_credentials.py:364
Same as auth-expert finding 1. The fix(registry): follow redirects only within the configured registry origin #3785 inventory retirement assumed 'refuses every redirect'.
Suggested: max_hops=0 when base_url is None; add a test. - [recommended] Guard blind spots: header keys omit Proxy-Authorization and ignore auth= kwargs, and qualname-keyed exemptions admit additional egress inside an exempted scope. at
scripts/architecture_linter/checks/transport_authenticated_egress.py:46
The owner's CREDENTIAL_HEADER_NAMES includes Proxy-Authorization. The egress inventory has no site counts, unlike the fix(registry): follow redirects only within the configured registry origin #3785 redirect inventory. No current violation found.
Suggested: Derive the key set from CREDENTIAL_HEADER_NAMES, flag a non-None auth= keyword outside the owners, and pin a site count per exemption.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
- unfollowed_redirect_request now follows no redirect (max_hops=0), so a same-path 3xx is returned like any other; pinned with a real-socket test plus Artifactory and ADO download retry cases. - The validation GitHub probe treats a refused redirect as inconclusive and leaves the decision to the download step, with a verbose reason. - The egress guard reads its credential header vocabulary from CREDENTIAL_HEADER_NAMES (adds Proxy-Authorization) and pins an exact site count per inventory entry; the resilient_get reason now states what the code does. - deps/registry/auth.py header ownership narrows to RegistryAuthContext; owner records name the new helpers and consumers. - Tests assert the probe's token header and the REST header builders. apm-spec-waiver: review folds inside the approved auth and redirect owners Refs #3752, #3726 Co-authored-by: Copilot App <[email protected]>
…ess prefilter - policy_get moves userinfo from a direct policy URL into an explicit Basic header through the new http_credentials.split_url_credentials owner helper, matching the previous requests behaviour. Redirect targets that embed userinfo stay refused. Covered by a transport-level test that only mocks the adapter send. - The egress guard prefilter also matches 'session', so session-receiver calls in modules without other HTTP tokens are scanned. - The no-follow regression test covers query and descendant-path shapes. apm-spec-waiver: review folds inside the approved auth and redirect owners Refs #3726 Co-authored-by: Copilot App <[email protected]>
…eal candidate Refs #3726 Co-authored-by: Copilot App <[email protected]>
Merge worker: ready for maintainer reviewHead Folded in this run
Copilot signals reviewed
Deferred (out-of-scope follow-ups)
Regression-trap evidence (mutation-break gate)
Lint contract
CIgh pr checks 3823 at ad3282f: 27 pass, 3 skipping, 0 failing, 0 pending (CI, Lint, Merge Gate, Spec conformance, CodeQL, NOTICE Drift, CRLF Invariance). Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors. |

Description
TL;DR
Adds the
transport-platform-authenticated-egressarchitecture guard. Raw HTTP egress (requestsverbs/sessions,urlliburlopen) and literalAuthorization/PRIVATE-TOKENheader keys can now appear only in their owner modules or in a frozen, reasoned inventory that can only shrink. Every remaining credential-bearing call site moves onto the owners #3785 and #3790 introduced, andlint-auth-signals.shstops carrying stale exemptions.Note
Wire change: the install-validation GitHub API probe now sends
Authorization: token <t>instead ofBearer <t>. It reuses the sharedAuthResolver.github_rest_headersbuilder, and GitHub's REST API accepts both schemes.Problem (WHY)
requests.get(..., headers={"Authorization": ...})from bypassingAuthResolverandorigin_bounded_request.f"token {t}",f"Bearer {t}") instead of once per scheme.allow_redirects=False). fix(registry): follow redirects only within the configured registry origin #3785's redirect guard left them in a "migrates in the guard PR" exemption.lint-auth-signals.shRule A exempted three files that no longer referenceget_bearer_provider. Rule B was a 5-line comment-proximity grep that the architecture linter now does structurally.The repo rule this enforces: "Every durable decision ... has exactly ONE canonical owner. Every call site routes THROUGH that owner", and a fix is complete only with "A registered static guard in the architecture linter, referenced by the owner's registry record."
Approach (WHAT)
transport-platform-authenticated-egresswith two guard ids, one per owner record. The registry rejects one guard id on two owners, so-credential-headersgoes oncredential-origin-scope.(path, enclosing qualname)to an exact site count and a reason. A stale entry or a changed count is a violation, so the inventory only shrinks. The header vocabulary is read fromhttp_credentials.CREDENTIAL_HEADER_NAMES(Authorization, PRIVATE-TOKEN, Proxy-Authorization).AuthResolver.github_rest_headers/bearer_headers(new, next togitlab_rest_headers) andRegistryAuthContext.headers().origin_bounded_requestwithbase_url= the request URL, so "never follow a redirect away from the resource" holds exactly. A new owner helper,unfollowed_redirect_request, follows no redirect at all (max_hops=0) and returns any 3xx to the auth-outcome classifier.marketplace/client.py::_fetch_url_direct, since the owner already refuses downgrades.Implementation (HOW)
scripts/architecture_linter/checks/transport_authenticated_egress.py(new, under the 2100-line cap;transport_auth_platform.pywas already at 1984). It tracksimport requests as x,from requests import get,from urllib.request import urlopen,requests.Sessionsubclasses, and verb calls on*sessionreceivers. It skips type annotations and matches header keys case-insensitively in dict keys, subscript stores, kwargs andadd_header-style calls.apm authstatus probe, self-update, lifecycle SSRF sessions, the Artifactory no-netrc entry fetch, the sharedresilient_getretry transport, the raw CDN fetch, the MCP registry, archive download and the version check. It also has two header exemptions:adapters/client/base.py(MCP config written for the harness; owned by the harness track) andversion_checker.src/apm_cli/policy/_policy_http.py(new):policy_getis the single HTTP entry for policy fetches. The ADO path sendsauthorization_headers(git_env)withambient_credentials=False, so only the chain-selected credential is sent and anonymous attempts never pick up.netrc.install/artifactory_resolver.py:_head_proberoutes the boundary HEAD through the owner; a 3xx still counts as "exists".deps/download_strategies.py:resilient_gettakesredirect_baseinstead ofallow_redirects. When it is set, each retry attempt is sent through the owner with ambient netrc excluded. The 429/503/connection retry and backoff loop is unchanged.download_ado_filepasses its request URL.install/validation.py:_github_api_getusesbase_url = origin_root(url), so same-origin repo renames are still followed and any other origin is refused. A refused redirect counts as an inconclusive probe, so the download step makes the final call and--verboseshows the reason.policy/discovery.pybecomesheaders=authorization_headers(git_env).scripts/lint-auth-signals.sh: Rule A loses its stale exemptions. Rule B defers to the linter and fails if any deferred guard id (auth-outcome-owner,authenticated-egress,-credential-headers,git-child-environment) leaves the owner registry. The CI entrypoint is unchanged.Diagrams
Where each kind of HTTP call is allowed to live once this lands:
flowchart LR A["HTTP call or credential header in src/apm_cli"] --> B{"Owner module?"} B -->|"yes"| OK["allowed"] B -->|"no"| C{"In frozen inventory?"} C -->|"yes, reasoned"| OK C -->|"no"| X["violation: route through owner"] INV["inventory entry with no matching site"] --> S["violation: stale exemption"]Trade-offs
resilient_getkeeps an egress exemption as the shared retry transport. Only callers that opt in withredirect_base(today the ADO download) send through the owner. Other callers already pass owner-built headers and followrequestsdefaults; moving them all is a larger change.Bearertotokento share one builder (see the note above).resilient_getcallers (GitHub contents, generic hosts) through the owner; flaggingauth=keywords outside the owners; excluding ambient.netrcfrom anonymous auth-chain attempts. The last one is deferred because Git itself honors.netrc, so changing only the HTTP probe would make installs fail for users who rely on netrc alone.Benefits
requests/urlopencall or literal credential header anywhere insrc/apm_clifails the CI architecture lint.origin_bounded_request: theallow_redirects=inventory shrinks from 7 to 3 entries, and each of those 3 refuses every redirect.lint-auth-signals.shdrops 3 stale exemptions and a heuristic grep rule.Issue and approved scope
Refs #3752
Refs #3726
Human scope-approval comments: #3752 (comment) and #3726 (comment)
This PR is the static-guard slice of the 0.36.1 auth track. #3752 was delivered by #3790 and #3726 by #3785; nothing in either issue remains open for this PR.
apm-spec-waiver: ownership consolidation and static guard inside the approved auth and redirect owners; no OpenAPM-observable behaviour change
Type of change
Testing
Scenario evidence
tests/unit/scripts/test_architecture_authenticated_egress.py;tests/integration/test_architecture_owner_rule_mutations.py(both guard ids)tests/unit/policy/test_policy_http.py::test_sign_in_redirect_is_returned_unfollowed;tests/unit/policy/test_extends_host_pin.py::TestFetchFromUrlRedirectRefusaltests/unit/policy/test_policy_http.py::test_ado_policy_sends_only_the_chain_selected_credential,::test_anonymous_attempt_keeps_ambient_netrc_outtests/unit/install/test_artifactory_resolver.py::TestRedirectLeakGuard::test_probe_never_follows_a_redirecttests/unit/install/test_validation_transient_probe.py::test_github_api_probe_keeps_its_credential_on_the_api_originauth_requiredand never followedtests/unit/deps/test_download_strategies_phase3.py::test_ado_download_sign_in_redirect_is_classified_not_followedValidation output (this branch merged with main 155a2d7, which includes #3790)
No live Azure DevOps org or Artifactory proxy was used; behaviour is pinned by hermetic tests.
How to test
bash scripts/lint-architecture-boundaries.shpasses.requests.get(u, headers={"Authorization": t})to anysrc/apm_cli/utils/*.pyfunction; the lint reports both guard ids. Revert._EGRESS_EXEMPTIONS; the lint reports the site. Delete a site instead; the lint reports a stale exemption.pytest -p no:xdist tests/unit/policy/test_policy_http.py tests/unit/scripts/test_architecture_authenticated_egress.pySpec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regeneratedCo-authored-by: Copilot [email protected]