Repository navigation
feat(auth): opt-in strict host credentials for GitHub-class hosts (#4324) - #4615
Merged
Daniel Meppiel (danielmeppiel) merged 6 commits intoNov 21, 2026
Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
Daniel Meppiel (danielmeppiel) merged 6 commits into
Conversation
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Nov 21, 2026
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
) APM_STRICT_HOST_CREDENTIALS=1/true/yes/on (any unrecognised value too, with a warning) keeps GITHUB_APM_PAT_<ORG>, GITHUB_APM_PAT, GITHUB_TOKEN and GH_TOKEN on the configured host (GITHUB_HOST, else github.com). For every other github.com or *.ghe.com host, AuthResolver runs gh auth token and git credential fill without GitHub-class token variables, warns once naming the host, and repeats the notice on an auth failure there. Co-authored-by: Copilot App <[email protected]>
- route the secondary gh/fill fallback through the strict-aware helpers - parse GITHUB_HOST with a scheme; drop per-org advice on withheld hosts - print the withheld notice immediately (a deferred one is lost when every package fails validation) and repeat it in the not-found reason - background lookups without external fallback withhold silently - conformance control covers APM_STRICT_HOST_CREDENTIALS unset Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…ring (#4324) Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
force-pushed
the
danielmeppiel-p1-4324-strict-host-credentials
branch
from
November 21, 2026 13:07
1d601c7 to
604fa5f
Compare
Daniel Meppiel (danielmeppiel)
marked this pull request as ready for review
November 21, 2026 13:19
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 21, 2026 13:19
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An early return for stored credentials omits the strict-mode notice and remedy when repository access fails; the source-bearing result needs the notice and coverage for a rejected helper credential.
1 open issue
What changed in this PR
Adds opt-in strict host credentials to APM's authentication resolver, limiting GitHub environment tokens to the configured host while preserving default behavior.
Changes:
- Restricts token eligibility and scrubs inherited GitHub tokens from credential-helper processes for other GitHub-class hosts.
- Adds strict-mode diagnostics, integration tests, and installed-CLI regression coverage.
- Documents the setting and updates host-scoping conformance records.
| File | Description |
|---|---|
| tests/spec_conformance/test_security_behavior_reqs.py | Activates host-scoping checks and adds strict/default cases. |
| tests/spec_conformance/gen_statement.py | Documents host-class behavior in generated statements. |
| tests/integration/test_strict_host_credentials.py | Tests token scrubbing, configured hosts, and setting values. |
| tests/integration/test_repository_not_found_lifecycle.py | Tests installed-CLI credential isolation and failure diagnostics. |
| src/apm_cli/core/token_manager.py | Accepts an explicit environment for gh token lookup. |
| src/apm_cli/core/auth.py | Owns strict-mode parsing, credential eligibility, and diagnostics. |
| packages/apm-guide/.apm/skills/apm-usage/authentication.md | Adds strict-mode usage guidance. |
| docs/src/content/docs/reference/environment-variables.md | Documents the new environment variable. |
| docs/src/content/docs/getting-started/authentication.md | Explains strict host scoping and sign-in remedies. |
| CONFORMANCE.md | Updates host-class documentation and conformance status. |
| CONFORMANCE.json | Records expanded, active host-scoping coverage. |
| CHANGELOG.md | Announces opt-in strict host credentials. |
Review effort: Balanced
…#4324) describe_credential_tried appends the strict-mode notice and remedy to the credential-tried reason too, so a stored gh or git-helper credential that a withheld host rejects still names strict mode in the failure. Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-p1-4324-strict-host-credentials
branch
November 21, 2026 15:34
Merged
3 of 10 tasks
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
Opt-in strict host credentials for GitHub-class hosts.
APM_STRICT_HOST_CREDENTIALSunset, empty,0,false,nooroffkeeps the documented 0.37 behaviour.1,true,yesoron(case-insensitive) turns strict mode on. Any other value also turns it on (fail closed) and prints one warning naming the value.In strict mode the owner
AuthResolver(src/apm_cli/core/auth.py) reads the setting once and:GITHUB_APM_PAT_<ORG>,GITHUB_APM_PAT,GITHUB_TOKENandGH_TOKENonly to the configured host (GITHUB_HOST, elsegithub.com);github.com/*.ghe.comhost, runsgh auth token --hostnameandgit credential fill(primary chain and the secondary fallback) withoutGH_TOKEN,GITHUB_TOKEN,GH_ENTERPRISE_TOKEN,GITHUB_ENTERPRISE_TOKEN,GITHUB_APM_PATorGITHUB_APM_PAT_*;APM_GITHUB_AUTH_FIRSTunchanged).Git children already scrub every token variable (
_build_git_env), and the version check, marketplace and policy paths all resolve throughAuthResolver, so no consumer re-derives host scope.gh behaviour, executed for real (record requirement)
gh version 2.103.3 (2026-10-26), isolatedGH_CONFIG_DIR,env -i,gh auth token --hostname <host>with one inert variable set:So gh hands an inherited
GH_TOKEN/GITHUB_TOKENback for any*.ghe.comhost; strict mode therefore scrubs them from the gh child, not only from APM's own lookup.Auth-expert review
An auth-expert pass found no leak path in strict mode and confirmed byte-identical behaviour with strict off. Folded: unset-variable control row; secondary fallback routed through the strict-aware helpers;
GITHUB_HOSTwith a scheme; no per-org advice on withheld hosts; background lookups (update check) withhold silently; the notice prints immediately (a deferred diagnostic was lost when every package failed validation) and the installed-CLI test asserts the notice and its count. Not folded (latent, no production caller):GitHubDownloader._resolve_dep_token(None)andGitHubTokenManager.get_token_with_credential_fallback(tests only).Issue and approved scope
Issue: Fixes #4324
Human scope-approval comment: #4324 (comment) (amended record)
Does this PR complete the issue, or what remains? Completes it.
Dependency order: none (independent of open PRs).
Type of change
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
tests/spec_conformance/test_security_behavior_reqs.py::test_token_scoped_to_its_host_classloses its auth: opt-in strict mode that scopes *.ghe.com credentials to the configured tenant #4324 strict-xfail and now sets the strict variable; rows also cover the control (acme.ghe.com receivesGITHUB_APM_PATwith the variable unset or empty) and hosts outside the GitHub-operated class (no GitHub token, strict or not).tests/integration/test_strict_host_credentials.py(new): real AuthResolver in a fresh process with stubghand a git credential helper that record every inherited variable name and, like real gh, returnGH_TOKEN/GITHUB_TOKEN. In strict mode none of the scrubbed names reaches either child for acme.ghe.com, the distinct inert helper credential is the one resolved, and the configured host (github.com, thenGITHUB_HOST=acme.ghe.com) still receives the env token. A value table pins off/on/unrecognised parsing and the warning.tests/integration/test_repository_not_found_lifecycle.py::test_strict_host_credentials_withhold_env_token_from_unconfigured_ghe_host[GITHUB_APM_PAT|GH_TOKEN](installed CLI, impersonated *.ghe.com harness): strict + env token,apm install lifecycle.ghe.com/...sends that host no Authorization header, exits 1 naming the host and strict mode with the remedy, writes nothing; withGITHUB_HOSTset to that host the token is sent.Red without the fix: the strict cases of the new integration module (6 failed, 7 control cases passed), the conformance strict row, and both installed-CLI cases fail on main.
pytest -n 2 tests/unit/core tests/integration/test_auth_resolver.py tests/spec_conformance/test_security_behavior_reqs.py tests/test_token_manager.py tests/integration/test_credential_fill_disambiguation.py tests/integration/test_strict_host_credentials.py tests/integration/test_repository_not_found_lifecycle.py(APM_BINARY_PATH=.venv/bin/apm) -> 2691 passed, 31 skipped; 1 failuretests/unit/core/test_auth_credential_report.py::test_hanging_helper_store_never_fails_the_operationalso fails on main code on this loaded host (timing; ADO path untouched here). Controlstest_cross_host_redirect_drops_every_credential_headerandtests/integration/test_auth_resolver.pygreen.Lint:
uvx [email protected] check/format --check,scripts/lint_architecture_boundaries.py --root ., complexity ratchet vs main,tests.quality.taxonomy --changed,scripts/check_test_assertions.py,scripts/lint-auth-signals.sh-> clean.Changelog
## [Unreleased]inCHANGELOG.md:user-visible effect first, 25 words or fewer, ending with
(#PR);breaking changes only under upgrade notes; no Highlights; see
.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
@pytest.mark.req("req-sc-005")test un-xfailed and extended.CONFORMANCE.{md,json}regenerated viapython -m tests.spec_conformance.gen_statement(req-sc-005 xfail -> active; new "GitHub-operated host class" section documents basis (c) and how strict mode narrows it).