Skip to content

fix(auth): fix credential helper reliability on Windows interactive login#389

Open
frblondin wants to merge 6 commits intomicrosoft:mainfrom
frblondin:fix/auth-credential-helper
Open

fix(auth): fix credential helper reliability on Windows interactive login#389
frblondin wants to merge 6 commits intomicrosoft:mainfrom
frblondin:fix/auth-credential-helper

Conversation

@frblondin
Copy link

Summary

On Windows, apm install could fail silently or prompt the user twice when authentication relied on git credential fill (e.g. the GitHub account picker via Windows Credential Manager). This PR fixes both symptoms as part of a single reliability improvement to credential helper handling.

Root causes

  • Silent timeout: git credential fill was called with a hardcoded 5-second timeout. The Windows account-selection dialog takes ~25 seconds, so the subprocess raised TimeoutExpired (caught silently), APM received no token, and reported the package as "not accessible or doesn't exist".

  • Duplicate prompts: Multiple GitHubPackageDownloader instances are created per command (validation phase + install phase). Each owned a fresh GitHubTokenManager with an empty cache, so the credential helper was invoked once per instance rather than once per command.

Changes

  • DEFAULT_GIT_CREDENTIAL_TIMEOUT_SECONDS: 5 → 60
  • MAX_GIT_CREDENTIAL_TIMEOUT_SECONDS: 180
  • New APM_GIT_CREDENTIAL_TIMEOUT env override (seconds, clamped 1–180)
  • _SHARED_CREDENTIAL_CACHE class variable (keyed by host) + threading.Lock() on GitHubTokenManager — credential helper called at most once per host across all instances in a single process

Tests

5 new unit tests in tests/test_token_manager.py covering timeout defaults, env override, clamping, and shared-cache deduplication. All 43 token-manager tests pass.

Documentation

Updated docs/src/content/docs/getting-started/authentication.md with a note on the configurable timeout and per-command caching behaviour.

Use a class-level shared cache keyed by host so that multiple
GitHubTokenManager instances created within a single command
(e.g. validation phase + install phase) only invoke the git
credential helper once per host instead of once per instance.
@frblondin
Copy link
Author

@microsoft-github-policy-service agree

@danielmeppiel danielmeppiel requested a review from Copilot March 20, 2026 14:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves Windows authentication reliability for apm install by extending git credential fill timeouts and deduplicating credential-helper prompts via a shared cache.

Changes:

  • Increase default credential-helper timeout and add an env override with max clamping.
  • Introduce a process-wide shared credential cache guarded by a lock to reduce duplicate credential-helper calls.
  • Add unit tests and documentation describing the new timeout and caching behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
tests/test_token_manager.py Adds tests for timeout selection and shared-cache behavior; adds an autouse fixture to isolate shared cache between tests.
src/apm_cli/core/token_manager.py Implements configurable git credential fill timeout and shared credential cache guarded by a lock.
docs/src/content/docs/getting-started/authentication.md Documents the new timeout env var and per-command/per-host credential caching behavior.

@danielmeppiel
Copy link
Collaborator

Great stuff let's get the pr comments addressed @frblondin and get this merged. Thank you!

frblondin and others added 4 commits March 20, 2026 16:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@frblondin
Copy link
Author

Great @danielmeppiel , please have a look with new updates.

danielmeppiel added a commit that referenced this pull request Mar 21, 2026
- Fix docs conflating EMU with *.ghe.com — EMU orgs can exist on
  github.com too; *.ghe.com is specifically GHE Cloud Data Residency
- Increase git credential fill timeout: 5s → 60s default (configurable
  via APM_GIT_CREDENTIAL_TIMEOUT, max 180s) — fixes silent auth failures
  on Windows when credential helper shows interactive account picker
- Add 7 timeout tests
- CHANGELOG entry for credential timeout fix

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
danielmeppiel added a commit that referenced this pull request Mar 21, 2026
- Fix docs conflating EMU with *.ghe.com — EMU orgs can exist on
  github.com too; *.ghe.com is specifically GHE Cloud Data Residency
- Increase git credential fill timeout: 5s → 60s default (configurable
  via APM_GIT_CREDENTIAL_TIMEOUT, max 180s) — fixes silent auth failures
  on Windows when credential helper shows interactive account picker
- Add 7 timeout tests
- CHANGELOG entry for credential timeout fix

Credit: credential timeout fix based on investigation by @frblondin in #389.

Co-authored-by: Thomas Caudal <thomas@caudal.fr>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants