Skip to content

feat(auth): auth-first opt-out and TLS config inheritance for github.com (#2545) - #2999

Merged
Daniel Meppiel (danielmeppiel) merged 6 commits into
microsoft:mainfrom
rgarciapariente:feature/issue-2545-github-auth-first
Nov 12, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 6 commits into
microsoft:mainfrom
rgarciapariente:feature/issue-2545-github-auth-first

Conversation

@rgarciapariente

@rgarciapariente rgarciapariente commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

AuthResolver.uses_public_github_anonymous_first() unconditionally tries HTTPS anonymously first for exact-host github.com, inside a from-scratch isolated git environment that discards the caller's real http.sslBackend/http.sslCAInfo. Behind a TLS-inspecting proxy whose intercepting CA chain has no revocation info at all, that isolated attempt can fail the TLS handshake even though a plain git clone (which uses the real git config) succeeds.

  • Default fix: build_public_github_anonymous_git_env() now inherits http.sslBackend/http.sslCAInfo from the real (non-isolated) git config via the new real_git_tls_config() (utils/git_env.py); credential.helper stays forced empty, so the credential-isolation boundary is unaffected.

  • Escape hatch: --auth-first / APM_GITHUB_AUTH_FIRST / apm config set github-auth-first true skip the anonymous attempt entirely for exact-host github.com, for proxies the narrow fix doesn't cover. Emits a one-time [!] warning when active.

Both resolve inside AuthResolver.uses_public_github_anonymous_first(), the single decision point already consulted by every call site, so no other caller needed to change.

Description

Implements the narrow default fix and the opt-out discussed in #2545: the anonymous-first isolated git environment for github.com HTTPS breaks behind TLS-inspecting proxies whose intercepting CA chain carries no revocation info, while a plain git clone succeeds because it uses the real git config.

Issue and approved scope

Addresses #2545.

Human scope-approval comment: none yet. The issue currently has only an automated Triage Panel "ACCEPT" verdict and my own design-proposal comment -- per CONTRIBUTING.md, "a label, automated recommendation, milestone, or silence is not approval." Opening this PR now for maintainer review of a concrete implementation ("you may experiment in your own fork without approval, but an unsolicited PR does not oblige maintainers to review or adopt it"). Happy to adjust scope or naming (e.g. --auth-first vs. --inherit-git-config, discussed in my design comment) based on maintainer feedback.

This PR does not close the issue; it proposes one candidate implementation for discussion.

Type of change

  • Bug fix

  • New feature

  • Documentation

  • Maintenance / refactor

Testing

  • Tested locally

  • All existing tests pass

  • Added tests for new functionality

Note on local verification: I could not run uv run pytest / ruff / pylint locally due to a broken corporate PyPI/Artifactory mirror on the machine where I authored this diff. I did run py_compile, scripts/lint-auth-signals.sh, scripts/lint_architecture_boundaries.py, the YAML/file-length/relative_to CI greps, and mermaid diagram validation -- all clean -- plus a careful manual review, but CI here is the first full run of the test/lint suite against this diff.

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

Maintainer note (2026-11-12): #2545 now carries an approved apm-scope:v1 record, and this PR delivers that full scope (TLS trust inheritance including http.sslCAPath, credential helpers kept off, and the --auth-first / APM_GITHUB_AUTH_FIRST / github-auth-first opt-out). The out-of-scope MCP conflict change was reverted.

Closes #2545

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical and moderate findings remain in auth-first behavior, TLS handling, and CLI validation.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds an auth-first opt-out and Git TLS configuration inheritance for exact-host github.com operations.

Changes:

  • Adds CLI, environment, and persisted configuration controls.
  • Inherits Git TLS settings for isolated operations.
  • Adds tests, documentation, changelog, and version updates.
File summaries
File Description
uv.lock Dependency lock and version metadata
tests/unit/utils/test_real_git_tls_config.py Tests ambient Git TLS configuration
tests/unit/test_install_command.py Tests install command behavior
tests/unit/test_config_command.py Tests configuration command integration
tests/unit/install/test_mcp_conflicts.py Tests MCP conflict handling
tests/unit/core/test_github_auth_first_optout.py Tests auth-first opt-out behavior
tests/integration/test_commands_config_coverage.py Integration configuration coverage
src/apm_cli/utils/git_env.py Extracts TLS settings for Git environments
src/apm_cli/install/mcp/conflicts.py Validates conflicting install options
src/apm_cli/core/auth.py Auth decisions, warnings, and Git environment integration
src/apm_cli/config.py Configuration and environment resolution
src/apm_cli/commands/install.py Adds the --auth-first option
src/apm_cli/commands/config.py Adds configuration command support
pyproject.toml Project version metadata
docs/src/content/docs/getting-started/authentication.md Authentication guidance
CHANGELOG.md Release notes
Review details

Suppressed comments (7)

CHANGELOG.md:18

  • The feature entries for #2545 remain under Unreleased, while this new heading and the corresponding pyproject.toml/uv.lock changes make the package identify as 0.31.0 and mark 0.31.0 as released on 2026-09-15. That leaves the merged binary's version inconsistent with the changelog; either keep the feature PR on the current version or perform the release by moving these entries into the versioned section together. The repository's changelog rules require Unreleased entries to move only when releasing (.github/instructions/changelog.instructions.md:12-13,27).
## [0.31.0] - 2026-09-15

CHANGELOG.md:16

  • Both new Unreleased entries claim #2545, but the changelog contract is one concise entry per PR. Combining the opt-out and TLS-inheritance behavior into one entry (or choosing the primary category) avoids double-counting this PR in release notes.
- `--auth-first` / `APM_GITHUB_AUTH_FIRST` / `apm config set github-auth-first true` skip the anonymous-first HTTPS attempt for exact-host `github.com`, as an escape hatch for networks behind a TLS-inspecting proxy whose intercepting CA chain has no revocation info at all. (#2545)

### Fixed

- The anonymous-first `github.com` HTTPS attempt now inherits `http.sslBackend`/`http.sslCAInfo` from the real (non-isolated) git config, so a corporate TLS trust store applies without needing the `--auth-first` opt-out. (#2545)

src/apm_cli/commands/install.py:981

  • This adds a new install flag, environment variable, and persisted config key, but the maintained reference pages and usage guide are still stale: docs/src/content/docs/reference/cli/install.md omits --auth-first, reference/cli/config.md omits github-auth-first, reference/environment-variables.md omits APM_GITHUB_AUTH_FIRST, and packages/apm-guide/.apm/skills/apm-usage/{commands,authentication}.md has no corresponding entries. Update those authoritative references in the same change so users of the CLI reference do not miss the escape hatch.
    "--auth-first",
    "auth_first",
    is_flag=True,
    default=False,
    help="Skip the anonymous-first HTTPS attempt for github.com and go straight to your resolved git credentials/environment (also: APM_GITHUB_AUTH_FIRST=1, apm config set github-auth-first true). Escape hatch for TLS-inspecting proxies whose intercepting CA chain has no revocation info, where the isolated anonymous attempt cannot complete a handshake even though your own git config can. Trade-off: forwards credentials on the first attempt instead of trying anonymously first.",

src/apm_cli/core/auth.py:552

  • This warning is user-facing but only describes the trade-off; it does not tell someone who enabled the persisted key or environment variable how to restore the default. Include the concrete recovery (apm config unset github-auth-first, unset APM_GITHUB_AUTH_FIRST, or omit --auth-first) so the warning passes the actionable-warning contract.
        msg = (
            "github-auth-first is enabled: git credentials will be forwarded "
            "on the first HTTPS attempt to github.com."

src/apm_cli/core/auth.py:1412

  • Even after the anonymous branch is bypassed, Git clone paths with a PAT/token build their authenticated environment through git_env_for_remote/hardened_git_base_env, which sets GIT_CONFIG_GLOBAL to the isolated config and never applies the new real_git_tls_config(). Thus --auth-first can still hit the same proxy TLS failure for token-backed installs; apply the narrow TLS inheritance to the credentialed environment as well while retaining the credential-helper fence.
        for key, value in real_git_tls_config().items():

src/apm_cli/install/mcp/conflicts.py:84

  • --auth-first changes credential order, not the transport scheme, so calling it a "transport selection" flag makes this MCP error misleading. Keep the existing transport wording for the first three flags but identify --auth-first as an auth-order flag so users understand why the option is rejected.
            "transport selection flags (--ssh/--https/--allow-protocol-fallback/"
            "--auth-first) don't apply to MCP entries"

src/apm_cli/utils/git_env.py:774

  • Filtering with and entry.value drops an empty higher-precedence value but keeps an earlier lower-precedence value for the same scalar key. For example, a global http.sslCAInfo=/corp.pem followed by a later http.sslCAInfo= is effective as empty in Git, but this returns /corp.pem and changes the anonymous clone's TLS behavior. Track the last value for each key, including empty values, then filter empty values after the scan.
    for entry in snapshot.entries:
        normalized = entry.key.lower()
        if normalized in _TLS_TRANSPORT_CONFIG_KEYS and entry.value:
            values[normalized] = entry.value
  • Files reviewed: 14/14 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/apm_cli/core/auth.py Resolved
Comment thread src/apm_cli/commands/install.py Resolved
Comment thread src/apm_cli/core/auth.py Resolved
@rgarciapariente

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved auth, TLS fallback, local-bundle validation, and probe-caching findings remain.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (4)

docs/src/content/docs/reference/cli/config.md:104

  • This labels github-auth-first as a transport preference, which conflicts with the adjacent usage guidance and the implementation's own conflict message: the setting changes credential order, not SSH/HTTPS selection. Describe this as a generic layered precedence (or explicitly split the transport and credential-order settings) so users do not expect it to choose a transport.
`allow-protocol-fallback`, `prefer-ssh`, and `github-auth-first` follow the layered transport precedence:

src/apm_cli/commands/install.py:981

  • The new option is not added to the rejected_flags map passed to install_local_bundle at install.py:1288, unlike --ssh, --https, and --allow-protocol-fallback. Consequently, apm install <bundle> --auth-first silently proceeds and ignores the flag instead of reporting an invalid local-bundle combination. Add it to that rejection map and its parameterized local-bundle test.
@click.option(
    "--auth-first",
    "auth_first",
    is_flag=True,
    default=False,
    help="Skip the anonymous-first HTTPS attempt for github.com and go straight to your resolved git credentials/environment (also: APM_GITHUB_AUTH_FIRST=1, apm config set github-auth-first true). Escape hatch for TLS-inspecting proxies whose intercepting CA chain has no revocation info, where the isolated anonymous attempt cannot complete a handshake even though your own git config can. Trade-off: forwards credentials on the first attempt instead of trying anonymously first.",

src/apm_cli/core/auth.py:535

  • Returning False here does not actually skip the anonymous request: try_with_fallback() still tests the original unauth_first at auth.py:875 and calls operation(None, ...); the relevant callers pass unauth_first=True. Thus --auth-first/the persisted setting still performs the anonymous attempt (and can hit the TLS failure) before using the token. Introduce an effective anonymous-first condition that is false only for the exact-host GitHub opt-out, while preserving the existing non-GitHub unauthenticated-first behavior and the no-token path.
        if self._github_auth_first_cli or get_apm_github_auth_first(create_config=False):
            self.emit_github_auth_first_diagnostic()
            return False

src/apm_cli/core/auth.py:533

  • On the new opt-out path, lazy_public_github becomes false, so _auth_context() resolves with path=None (via path if lazy_public_github else None in try_with_fallback). That drops the repository path from git credential fill exactly when auth-first is supposed to use the caller's credential helper; helpers with credential.useHttpPath=true can therefore select no or the wrong credential. Preserve path for the opted-out GitHub resolution.
        if self._github_auth_first_cli or get_apm_github_auth_first(create_config=False):
  • Files reviewed: 20/20 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread src/apm_cli/core/auth.py Resolved
Comment thread src/apm_cli/utils/git_env.py Resolved
@rgarciapariente
rgarciapariente force-pushed the feature/issue-2545-github-auth-first branch 2 times, most recently from da7832f to eb02ffd Compare September 16, 2026 13:42
@rgarciapariente
rgarciapariente requested a lite review from Copilot September 16, 2026 13:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved moderate issues affect fallback behavior, credential path scoping, TLS inheritance and precedence, and concurrent probe caching.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (5)

src/apm_cli/core/auth.py:793

  • When try_with_fallback is called with its default base_env=None, this passes None into git_env_for_context, whose _build_git_env path expects a mapping and calls dict(base_env). Any primary-token failure that reaches the gh or credential-fill fallback will therefore raise TypeError instead of trying the fallback (the existing path tests in tests/unit/test_auth.py use this default). Preserve the optional-base behavior while adding the TLS inheritance, for example by making the TLS-aware helper handle None and routing the no-base call through it.
                return self.git_env_for_context(
                    AuthContext(
                        token=token,
                        source=source,
                        token_type="unknown",

src/apm_cli/core/auth.py:728

  • This path-scoping change only affects try_with_fallback's resolve call. When the opt-out makes uses_public_github_anonymous_first() return False, GitHubPackageDownloader._cache_git_env() takes its direct credential path and calls resolve_for_dep(), which resolves Git credentials with path=None; a GCM setup using credential.useHttpPath=true can therefore select an account for the wrong repository. Route that bypass through the same repository-path-aware resolution (or a shared helper) instead of relying only on this fallback branch.
                path=(
                    path
                    if host_info.kind == "gitlab"
                    or (unauth_first and github_auth_first_opted_out)
                    else None

src/apm_cli/core/auth.py:1439

  • These entries are appended after every caller-provided GIT_CONFIG_* entry, so a caller's explicit http.sslBackend/http.sslCAInfo is overridden by the ambient value (Git resolves the later duplicate). That breaks the existing base_env contract, which otherwise retains per-operation TLS settings; add the ambient key only when the base has no case-insensitive entry, or insert it before the retained entries.
        for key, value in real_git_tls_config().items():
            cls._append_git_config(env, key, value)

src/apm_cli/core/auth.py:1497

  • This only adds the TLS entries when a caller already routes through git_env_for_context. The base_env=None branch of _git_env_for_context still returns ctx.git_env directly, and opt-out paths such as deps/git_reference_resolver.py and deps/github_downloader_validation.py also pass AuthContext.git_env directly after resolve_for_dep; resolve() still builds that environment with _build_git_env() alone. Consequently the first credentialed Git request on those paths can still omit http.sslBackend/http.sslCAInfo and reproduce #2545. Apply the inherited TLS config when constructing the cached context environment or route every credentialed Git path through this helper.
        if ctx.host_info.kind == "github":
            from ..utils.git_env import real_git_tls_config

            for key, value in real_git_tls_config().items():
                AuthResolver._append_git_config(env, key, value)

src/apm_cli/core/auth.py:555

  • With an InstallLogger, this detail is stored in DiagnosticCollector, whose warning renderer only prints details in verbose mode. A normal install therefore shows that credentials are forwarded but omits the only restoration action (apm config unset ... / unsetting the environment variable), making the new warning non-actionable; put the remediation in the main message or make this detail visible by default.
        self._emit_warning_with_detail(
            "github-auth-first is enabled: git credentials will be forwarded "
            "on the first HTTPS attempt to github.com.",
            "To restore the default, run 'apm config unset github-auth-first', "
            "unset APM_GITHUB_AUTH_FIRST, or omit --auth-first.",
            fallback_context="auth-first",
  • Files reviewed: 21/21 changed files
  • Comments generated: 3
  • Review effort level: Lite

Comment thread src/apm_cli/utils/git_env.py Resolved
@rgarciapariente
rgarciapariente marked this pull request as draft September 16, 2026 14:16
…com (microsoft#2545)

AuthResolver.uses_public_github_anonymous_first() unconditionally tries HTTPS
anonymously first for exact-host github.com, inside a from-scratch isolated
git environment that discards the caller's real http.sslBackend/http.sslCAInfo.
Behind a TLS-inspecting proxy whose intercepting CA chain has no revocation
info at all, that isolated attempt can fail the TLS handshake even though a
plain `git clone` (which uses the real git config) succeeds.

- Default fix: build_public_github_anonymous_git_env() now inherits
  http.sslBackend/http.sslCAInfo from the real (non-isolated) git config via
  the new real_git_tls_config() (utils/git_env.py); credential.helper stays
  forced empty, so the credential-isolation boundary is unaffected.
- Escape hatch: --auth-first / APM_GITHUB_AUTH_FIRST / `apm config set
  github-auth-first true` skip the anonymous attempt entirely for exact-host
  github.com, for proxies the narrow fix doesn't cover. Emits a one-time [!]
  warning when active.

Both resolve inside AuthResolver.uses_public_github_anonymous_first(), the
single decision point already consulted by every call site, so no other
caller needed to change.
@rgarciapariente
rgarciapariente force-pushed the feature/issue-2545-github-auth-first branch from eb02ffd to d4a2c6f Compare September 16, 2026 14:25
@rgarciapariente
rgarciapariente requested a lite review from Copilot September 16, 2026 14:28
@rgarciapariente
rgarciapariente marked this pull request as ready for review September 16, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Resolve the remaining credential path and TLS inheritance issues, and clarify the documented no-credential fallback behavior.

Review details

Suppressed comments (11)

docs/src/content/docs/getting-started/authentication.md:19

  • This says --auth-first skips the anonymous attempt entirely, but AuthResolver.try_with_fallback() still performs operation(None, ...) as a last resort when no credential resolves (covered by tests/unit/core/test_github_auth_first_optout.py::test_opted_out_with_no_token_still_falls_back_to_anonymous). Please describe this as skipping the initial anonymous probe when credentials are available, and document the no-credential fallback.
If your network sits behind a TLS-inspecting proxy whose intercepting CA chain carries no revocation info at all, the anonymous attempt's isolated environment can still fail a TLS handshake even with that inheritance. `--auth-first` / `APM_GITHUB_AUTH_FIRST=1` / `apm config set github-auth-first true` skip the anonymous attempt entirely for exact-host `github.com` and go straight to your resolved credentials/environment. See [TLS-inspecting proxy blocks the anonymous attempt](#tls-inspecting-proxy-blocks-the-anonymous-attempt).

docs/src/content/docs/reference/cli/config.md:74

  • The config-key description overstates the opt-out: the code still tries anonymous as a last resort when credential resolution returns no token. Please qualify the promise to the initial attempt when credentials are available.
| `github-auth-first` | boolean | `false` | Skip the anonymous-first HTTPS attempt for exact-host `github.com` and resolve credentials/environment immediately. Escape hatch for TLS-inspecting proxies whose intercepting CA chain has no revocation info. Equivalent to `--auth-first` or `APM_GITHUB_AUTH_FIRST=1`. |

docs/src/content/docs/reference/cli/install.md:87

  • This option description says the anonymous attempt is skipped unconditionally, but the resolver intentionally falls back to anonymous when no credential can be resolved. Please state that --auth-first skips the initial probe when credentials are available and retains the no-credential fallback.
| `--auth-first` | off | Skip the anonymous-first HTTPS attempt for exact-host `github.com` and resolve credentials/environment immediately. Escape hatch for TLS-inspecting proxies whose intercepting CA chain has no revocation info. Env: `APM_GITHUB_AUTH_FIRST=1`. |

docs/src/content/docs/reference/environment-variables.md:44

  • The documented behavior is broader than the implementation: with auth-first enabled but no credential available, try_with_fallback() still makes a last-resort anonymous attempt. Please qualify this row as skipping only the initial anonymous probe when credentials resolve.
| `APM_GITHUB_AUTH_FIRST` | Set to `1` (or `true`/`yes`/`on`) to skip the anonymous-first HTTPS attempt for exact-host `github.com` and resolve credentials/environment immediately. Escape hatch for TLS-inspecting proxies whose intercepting CA chain has no revocation info. | unset | Equivalent to `--auth-first`. Resolution: CLI flag → env var → `github-auth-first` key in `~/.apm/config.json` → `false`. See [Authentication: TLS-inspecting proxy blocks the anonymous attempt](../getting-started/authentication/#tls-inspecting-proxy-blocks-the-anonymous-attempt). |

packages/apm-guide/.apm/skills/apm-usage/authentication.md:11

  • This guide says auth-first skips the anonymous attempt entirely, but the implementation still performs a last-resort anonymous call when no credential resolves. Please mirror the resolver's conditional wording here.
If a network sits behind a TLS-inspecting proxy whose intercepting CA chain carries no revocation info at all, the isolated attempt can still fail the TLS handshake even with that inheritance. `--auth-first` / `APM_GITHUB_AUTH_FIRST=1` / `apm config set github-auth-first true` skip the anonymous attempt entirely for exact-host `github.com` and resolve credentials/environment immediately, emitting a one-time `[!]` warning when active. See [Authentication: TLS-inspecting proxy blocks the anonymous attempt](https://microsoft.github.io/apm/getting-started/authentication/#tls-inspecting-proxy-blocks-the-anonymous-attempt).

packages/apm-guide/.apm/skills/apm-usage/commands.md:436

  • This usage reference also says auth-first skips the anonymous attempt without the no-credential exception. The code's explicit no-token test shows that anonymous remains a last resort, so this description should be narrowed to the initial probe when credentials resolve.
`apm config set github-auth-first true` (or `--auth-first` / `APM_GITHUB_AUTH_FIRST=1`) skips the anonymous-first HTTPS attempt for exact-host `github.com`, for networks behind a TLS-inspecting proxy whose intercepting CA chain has no revocation info at all -- resolution order and the `false`-default noise suppression mirror `allow-protocol-fallback` above. `apm config unset github-auth-first` removes the persisted value. Unlike the transport keys, this is a credential-order decision, not a transport selector: it does not conflict with `--ssh` / `--https` / `--allow-protocol-fallback`, and it is rejected (like them) with `--mcp`, reported as a separate credential-order error rather than lumped into the transport-selection-flags message.

src/apm_cli/core/auth.py:717

  • These new path-aware lookups only cover try_with_fallback. When the opt-out makes uses_public_github_anonymous_first() return False, the direct clone/ref/API branches in clone_engine.py, git_reference_resolver.py, and github_downloader_validation.py skip this code and call resolve_for_dep(dep_ref) without path. A credential.useHttpPath=true helper can therefore choose no or the wrong account on the new auth-first path. Please add a path-aware resolver call to those branches (or route them through this path-scoped path).
            # issue #2545: also scope the credential-fill lookup by path for
            # the github-auth-first-opted-out case (mirrors the existing
            # gitlab behavior) so GCM multi-account users still get correct
            # per-URL account selection once the opt-out routes straight to
            # credentials. Guarded on unauth_first so callers that already

src/apm_cli/core/auth.py:535

  • Once auth-first returns False here, build_error_context() still uses that result to decide whether to pass dep_url as the credential-helper path. After a failed auth-first attempt it therefore re-resolves GitHub credentials with path=None, so a credential.useHttpPath=true helper can produce a misleading no-credential or wrong-account diagnostic. Keep the repository path for exact github.com error-context resolution even when anonymous-first is disabled.
        if self._github_auth_first_cli or get_apm_github_auth_first(create_config=False):
            self.emit_github_auth_first_diagnostic()
            return False

src/apm_cli/core/auth.py:696

  • This now invokes uses_public_github_anonymous_first() even when unauth_first=False. GitHub API/marketplace callers use that mode and never attempt anonymous Git, but an enabled setting still emits the warning about forwarding Git credentials. The warning is therefore shown for a path whose auth order is unchanged; short-circuit this decision when unauth_first is false (or make the warning specific to an actual Git anonymous bypass).
        github_anonymous_first_allowed = self.uses_public_github_anonymous_first(
            host,
            port=port,
            host_type=host_type,
        )

src/apm_cli/core/auth.py:1519

  • This TLS inheritance is bypassed for the supported try_with_fallback(..., base_env=None) path: its _git_env_for_context helper returns ctx.git_env directly, and resolve() populated that field with _build_git_env before this new git_env_for_context logic runs. A credentialed retry (for example a RefResolver without a caller env) therefore still omits the ambient http.sslBackend/http.sslCAInfo and can reproduce the proxy failure. Route the no-base context path through this TLS-aware builder as well, and cover that path with a regression test.
        if ctx.host_info.kind == "github":
            from ..utils.git_env import real_git_tls_config

            for key, value in real_git_tls_config().items():
                if not AuthResolver._has_git_config_key(env, key):
                    AuthResolver._append_git_config(env, key, value)

src/apm_cli/core/auth.py:710

  • When auth-first is enabled and no credential resolves, this disables the lazy public-GitHub path, so unauth_env is built by the generic _build_git_env branch rather than build_public_github_anonymous_git_env. The last-resort anonymous call at the end of try_with_fallback therefore loses the inherited TLS settings and still fails behind the exact proxy this escape hatch is meant to handle; the new no-token test only checks that an attempt occurs. Keep the last-resort exact-host GitHub anonymous env on the TLS-aware builder.
        github_auth_first_opted_out = (
            host_info.kind == "github" and not github_anonymous_first_allowed
        )
        attempt_unauthenticated = unauth_first and not github_auth_first_opted_out
  • Files reviewed: 21/21 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sergio-sisternes-epam

Sergio Sisternes (sergio-sisternes-epam) commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

PR triage recommendation

needs-issue

Recommendation only, not merge or scope approval. A responsible
human maintainer must approve. Labels, automated advice, and
silence are not approval.

Linked issue

#2545 (open). Labels: priority/high, theme/security, area/cli, type/feature, triage/recommended. Not labelled status/accepted. The 2026-08-10 Triage Panel ACCEPT comment is automated advice only. The PR author already recorded that there is no human scope-approval comment.

Proposed classification

theme/security, area/cli, type/feature (aligned with #2545). Complementary type/bug for the 0.26.0 regression is reasonable; leave that to a maintainer rather than replacing type/feature.

Suggested next action

Wait for a human maintainer to review and accept #2545 (status/accepted) before treating this PR as in-scope.

Thank you for contributing this pull request and for the detailed
write-up on #2545.

APM starts with an issue, not an implementation
(https://github.com/microsoft/apm/blob/main/CONTRIBUTING.md).
A label, automated recommendation, or silence is not approval.

#2545 is already filed and has automated triage advice, but it is
not labelled status/accepted. Please wait for a maintainer to review
that issue and accept the scope before this implementation is treated
as invited work. This PR is labelled status/deferred until that happens.


Generated by autopilot-pr-triage-worker. This comment is AI-generated and may contain errors.

@sergio-sisternes-epam Sergio Sisternes (sergio-sisternes-epam) added triage/recommended Automated advice completed; not human scope approval. status/deferred Not invited for implementation now; no release commitment. theme/security area/cli CLI command surface, flags, help text (cross-cutting). type/feature New capability, new flag, new primitive. labels Sep 18, 2026
Brings the branch up to date with main (579 commits). Conflicts resolved
in getting-started/authentication.md (keep both the main raw-marker note
and the new TLS-inspecting proxy section) and utils/git_env.py imports
(keep both sys and threading).

Co-authored-by: Copilot App <[email protected]>
The approved microsoft#2545 scope excludes unrelated MCP conflict handling, so
conflicts.py and its test return to main; --auth-first stays a dependency
install flag (still rejected for local bundles). Also tightens the
--auth-first help text per the DevX panel finding.

Addresses the microsoft#2545 apm-scope:v1 out-of-scope note and devx-ux-expert nit.

Co-authored-by: rgarciapariente <[email protected]>
Co-authored-by: Copilot App <[email protected]>
- Inherit http.sslCAPath alongside sslBackend/sslCAInfo (approved scope).
- One _inherit_ambient_github_tls helper for every isolated github.com env;
  only isolated envs are touched, caller entries win, local/worktree
  config is never a trust source, credential helpers stay off.
- Consult the opt-out only for unauth_first callers, so API paths do not
  emit the forwarding warning; keep TLS on the no-credential last resort.
- Keep path-scoped credential lookup for opted-out github.com in
  resolve_for_dep and build_error_context.
- Single-line fallback warning with the recovery action.
- Regression traps (unit + integration), each proven by mutation-break.

Addresses Copilot review 5224160136 and panel (architect, auth, supply
chain, test coverage, cli logging) follow-ups.

Co-authored-by: rgarciapariente <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Fix two broken relative links, drop duplicated apm-usage table rows from
the stale merge, correct the credential-helper TLS misattribution, state
that --auth-first skips the initial anonymous attempt only when a
credential resolves, mention sslCAPath, and collapse the CHANGELOG into
one entry for microsoft#2999.

Addresses doc-writer panel findings and Copilot docs comments.

Co-authored-by: rgarciapariente <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator

APM Review Panel: ship_with_followups

Unblocks corporate-proxy users on github.com with TLS config inheritance and an auth-first opt-out, without weakening credential isolation.

panel-mode=full; personas=python-architect,auth-expert,supply-chain-security-expert,test-coverage-expert,doc-writer,performance-expert,devx-ux-expert,cli-logging-expert,apm-ceo

cc rgarciapariente Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

This PR from rgarciapariente fixes a real problem: APM's anonymous-first github.com attempt fails behind TLS-inspecting proxies because its isolated Git environment drops the user's CA trust. The fix inherits http.sslBackend, http.sslCAInfo and http.sslCAPath through a fixed allowlist, and still forces credential.helper and http.extraheader empty. The --auth-first / APM_GITHUB_AUTH_FIRST / github-auth-first opt-out skips the initial anonymous attempt when a credential resolves. The eight panelists agreed: no blocking-severity findings and no dissent. Auth-expert confirmed credential isolation is intact. Supply-chain added defense in depth so local and worktree Git config is never trusted. Python-architect's duplicated TLS loop is now one shared helper. Test-coverage's integration gaps are closed with mutation-break-proven tests. The MCP conflict change outside the approved scope was reverted. TLS inheritance also covers credentialed exact-host github.com environments built on the isolated base. Without that, --auth-first and the private-repo credentialed retry would fail behind the same proxy. It copies TLS keys only and reads no credentials.

Aligned with: secure by default (allowlisted TLS keys, helpers forced off, repository-scoped config rejected); governed by policy (flag > env > config precedence mirrors allow-protocol-fallback); pragmatic as npm (TLS inherits automatically, one-flag escape hatch); community driven (contributor design for an accepted high-priority issue).

Panel summary

Persona B R N Takeaway
Python Architect 0 1 1 Single-owner discipline holds; TLS inheritance now goes through one shared helper.
Auth Expert 0 0 1 Credential isolation intact; TLS inheritance additive-only; opt-out suppresses anonymous-first.
Supply Chain Security Expert 0 1 0 Allowlisted TLS keys, repository config excluded, opt-out limited to exact-host github.com.
Test Coverage Expert 0 2 1 Unit coverage strong; integration-tier opt-out and isolation tests were added.
Doc Writer 0 3 0 Broken links, duplicated guide rows and repeated prose fixed.
Performance Expert 0 1 1 TLS probe cached once per process; one cross-probe dedup left as follow-up.
DevX UX Expert 0 1 1 Naming, precedence and config ergonomics solid; help text tightened.
CLI Logging Expert 0 0 1 Warning wording and dedup clean; fallback now prints one line.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 1 follow-ups

  1. [Performance Expert] Share one ambient Git config snapshot between configured_git_url_policy and real_git_tls_config. -- Both run git config once per process. Sharing the snapshot saves one subprocess. It refactors the existing URL-rewrite probe cache, which is outside [FEATURE] Opt-out for anonymous-first HTTPS on github.com behind TLS-inspecting proxies with no revocation info #2545.

Architecture

classDiagram
    direction LR
    class AuthResolver {
      +uses_public_github_anonymous_first(host) bool
      +try_with_fallback(host, operation) T
      +resolve_for_dep(dep_ref) AuthContext
      +build_public_github_anonymous_git_env(base_env) dict
      +git_env_for_context(ctx, base_env) dict
      -_github_auth_first_enabled() bool
      -_inherit_ambient_github_tls(env) void
      -_emit_warning_with_detail(msg, detail) void
    }
    class real_git_tls_config {
      <<IOBoundary>>
      +__call__(env) dict
    }
    class config_module {
      +get_apm_github_auth_first() bool
    }
    class DiagnosticCollector {
      +warn(msg) void
    }
    AuthResolver ..> real_git_tls_config : probes ambient TLS
    AuthResolver ..> config_module : reads opt-out
    AuthResolver ..> DiagnosticCollector : one-time warning
    class AuthResolver:::touched
    class real_git_tls_config:::touched
    class config_module:::touched
    classDef touched fill:#fff3b0,stroke:#d47600
Loading
flowchart TD
    A["apm install --auth-first"] --> B["AuthResolver(github_auth_first=True)"]
    B --> C{"unauth_first caller and exact github.com?"}
    C -->|"no"| D["existing order unchanged"]
    C -->|"yes"| E{"opt-out active? CLI > env > config"}
    E -->|"no: default"| F["anonymous attempt: helpers off, Git TLS inherited"]
    E -->|"yes"| G["one-time warning; path-scoped credential first"]
    G --> H{"credential resolved?"}
    H -->|"yes"| I["credentialed attempt, Git TLS inherited"]
    H -->|"no"| J["anonymous last resort, Git TLS inherited"]
    subgraph tls ["real_git_tls_config"]
        K["git config --list (system/global/env scopes, cached once)"] --> L["allowlist sslBackend, sslCAInfo, sslCAPath; drop local/worktree"]
    end
Loading

Folded in this run

  • (scope) Inherit http.sslCAPath alongside sslBackend / sslCAInfo -- resolved in c958039.
  • (scope) Reverted the out-of-scope MCP conflicts.py change and its test -- resolved in cefac53.
  • (copilot) Opt-out is consulted only for unauth_first callers, so API paths no longer show the warning -- resolved in c958039.
  • (copilot) The no-credential last resort keeps Git TLS settings when the caller's base is isolated -- resolved in c958039.
  • (copilot) Opted-out github.com keeps path-scoped credential lookup in resolve_for_dep and build_error_context -- resolved in c958039.
  • (copilot) Docs say the opt-out skips the initial anonymous attempt when a credential resolves, and document the no-credential last resort -- resolved in 5768e5d.
  • (copilot) CHANGELOG collapsed into one entry for feat(auth): auth-first opt-out and TLS config inheritance for github.com (#2545) #2999 -- resolved in 5768e5d.
  • (panel: architect) One _inherit_ambient_github_tls helper for every isolated github.com environment -- resolved in c958039.
  • (panel: supply chain) Local and worktree Git config is never a TLS trust source -- resolved in c958039.
  • (panel: test coverage) Integration opt-out test, real-probe credential-isolation test, and config set/persist tests -- resolved in c958039.
  • (panel: docs) Fixed two broken links, removed duplicated apm-usage rows, corrected the TLS explanation, trimmed repeated prose -- resolved in 5768e5d.
  • (panel: devx / logging / auth) Tighter --auth-first help text, a one-line fallback warning, and base_env: dict | None -- resolved in cefac53 / c958039.

Copilot signals reviewed

All 9 inline threads were LEGIT and already resolved by the author. Their fixes include the opt-out normalization, local-bundle rejection, the cached and locked probe, TLS on secondary credentials, and reference docs. From the suppressed comments, 22 items are LEGIT and folded or already addressed. 3 are NOT-LEGIT:

  • src/apm_cli/core/auth.py -- NOT-LEGIT: "TLS bypassed / TypeError when base_env=None". Those environments are not config-isolated, so the real Git TLS config already applies, and _build_git_env accepts None.
  • src/apm_cli/core/auth.py -- NOT-LEGIT: "cached context env omits TLS". Same reason. Isolated bases go through the TLS helper.
  • src/apm_cli/install/mcp/conflicts.py -- NOT-LEGIT: MCP wording. That change is outside the approved scope and was reverted.

Deferred (out-of-scope follow-ups)

Regression-trap evidence (mutation-break gate)

11 new or affected traps were checked. Each guard was deleted, the test failed as expected, and the guard was restored. The guards cover:

  • the credential-helper fence and sslCAPath key;
  • the isolation check and local/worktree scope skip;
  • TLS on the last resort and the unauth_first warning short-circuit;
  • path scoping in resolve_for_dep and build_error_context;
  • the no-anonymous-attempt gate, at unit and integration tier.

Lint contract

ruff check and ruff format --check (src, tests, architecture scripts), pylint R0801 (10.00/10), lint-auth-signals.sh and lint-architecture-boundaries.sh all pass silently.

CI

gh pr checks 2999 at 9894530: 23 pass, 3 skipping, 0 failing, license/cla pass. The fork runs were approved after confirming the diff has no .github/ changes. No CI fix iterations were needed.

Mergeability status

PR head SHA CEO stance iters folds defers Copilot rounds CI mergeable mergeStateStatus notes
#2999 9894530 ship_with_followups 1 14 1 2 green MERGEABLE BLOCKED pending required review

Recommendation

Ready to merge: CI is green on the pushed head, and every substantive panel finding was folded with mutation-break evidence. The one deferred item (sharing the probe snapshot) is an existing cost outside this PR's scope and belongs in a follow-up issue. The PR stays within the approved apm-scope:v1 record, keeps credential isolation intact, and now closes #2545.

Full per-persona findings

Python Architect

  • [recommended] TLS-inheritance loop copy-pasted across two AuthResolver methods at src/apm_cli/core/auth.py. Folded: one shared helper.
  • [nit] _parse_github_auth_first_env alias could be inlined at src/apm_cli/config.py. Not folded: it mirrors the existing _parse_allow_protocol_fallback_env sibling, and tests import it by name.

Auth Expert

  • [nit] _secondary_credential_env passed a possibly-None base_env to a dict-typed parameter. Folded: the annotation now allows None.

Supply Chain Security Expert

  • [recommended] Reject local/worktree-scoped entries in the TLS probe as defense in depth at src/apm_cli/utils/git_env.py. Folded with a test.

Test Coverage Expert

  • [recommended] Integration test that APM_GITHUB_AUTH_FIRST skips the anonymous attempt. Folded.
  • [recommended] Credential-helper-off plus TLS test without mocking the probe. Folded, using a real git probe against a temp user gitconfig.
  • [nit] Integration set/persist parity for github-auth-first. Folded.

Doc Writer

  • [recommended] Two relative links had the wrong depth (install.md, environment-variables.md). Folded.
  • [recommended] Duplicated config/lock rows in apm-usage commands.md. Folded.
  • [recommended] The docs wrongly credited the credential helper for TLS success, repeated the escape-hatch prose, and left TLS inheritance out of the reference pages. Folded.

Performance Expert

  • [recommended] Share the ambient Git config snapshot between two probes. Deferred because it is outside the approved scope.
  • [nit] MappingProxyType to avoid the dict copy. Not folded: the copy is a tested contract, and the cost is negligible.

DevX UX Expert

  • [recommended] Duplicate config set/unset rows in the guide. Folded.
  • [nit] Tighten the --auth-first help text. Folded.

CLI Logging Expert

  • [nit] The fallback path printed two [!] lines for one warning. Folded: it now prints one line.

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-merge-worker. This comment is AI-generated and may contain errors.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit d71d386 into microsoft:main Nov 12, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI command surface, flags, help text (cross-cutting). triage/recommended Automated advice completed; not human scope approval. type/feature New capability, new flag, new primitive.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Opt-out for anonymous-first HTTPS on github.com behind TLS-inspecting proxies with no revocation info

4 participants