fix: send auth header for GitHub release lookup in installer and self-update#1588
Merged
Conversation
…-update
Two anonymous GitHub release API calls caused rate-limit failures (403)
on shared IPs and corporate NAT:
(a) install.sh - the initial releases/latest curl ran anonymously even
though AUTH_HEADER_VALUE (GITHUB_APM_PAT > GITHUB_TOKEN) was
resolved above. Now sends the header on the first attempt when set,
preserving anonymous fallback when no token is configured.
(b) src/apm_cli/utils/version_checker.py - get_latest_version_from_github
called requests.get with no Authorization header. Adds _get_github_token()
following canonical TOKEN_PRECEDENCE["modules"] order:
GITHUB_APM_PAT -> GITHUB_TOKEN -> GH_TOKEN. Header is sent only when a
token is present; anonymous fallback unchanged when none is set.
Auth guardrails:
- Token value is never logged, echoed, or included in exception text.
- Anonymous fallback preserved when no token env var is set.
- No new env vars introduced; existing precedence preserved.
- scripts/lint-auth-signals.sh passes (no get_bearer_provider or
unannotated git ls-remote violations introduced).
Closes #1582
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes anonymous GitHub releases/latest lookups during installation and apm self-update by conditionally sending an Authorization header when a GitHub token is available, preserving anonymous fallback when no token is set. This directly addresses rate-limit (403) failures seen on shared IPs/corporate NAT.
Changes:
- Update
install.shto includeAuthorization: token ...on the initialreleases/latestcurl request when a token is already resolved. - Update
get_latest_version_from_github()to add an auth header whenGITHUB_APM_PAT/GITHUB_TOKEN/GH_TOKENis present (canonical precedence). - Extend unit tests to cover token precedence and header emission behavior.
Show a summary per file
| File | Description |
|---|---|
install.sh |
Sends auth header on the first GitHub release metadata request when a token is available, avoiding anonymous rate limits. |
src/apm_cli/utils/version_checker.py |
Adds token resolution helper and passes conditional Authorization header for GitHub release lookup used by self-update. |
tests/unit/test_version_checker.py |
Adds tests validating token precedence and that auth headers are included/omitted correctly. |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Comment on lines
6
to
7
| from pathlib import Path | ||
| from typing import Optional, Tuple # noqa: F401, UP035 |
…back, add CHANGELOG entry - Remove `from typing import Optional, Tuple # noqa: F401, UP035` from version_checker.py: symbols are unused (file uses PEP 604 str|None and builtin tuple); the noqa suppressor was masking dead code - Add GH_TOKEN as third fallback in install.sh auth resolution block for consistency with version_checker.py TOKEN_PRECEDENCE['modules'] order: GITHUB_APM_PAT > GITHUB_TOKEN > GH_TOKEN - Add CHANGELOG entry for the rate-limit fix (closes #1582) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collaborator
Author
apm-review-panel advisory (shepherd-driver, 1 iteration)Verdict: ship_with_followups -- CI green, auth safe, two items folded, one deferred. Panel findingspython-architect
auth-expert
test-coverage-expert
supply-chain-security-expert
cli-logging-expert
devx-ux-expert
oss-growth-hacker
Items folded into this PR
Items deferred (follow-up issues recommended)
|
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.
TL;DR
Two anonymous GitHub API calls caused rate-limit failures (403) on shared IPs and corporate NAT. Both now send a conditional
Authorizationheader when a token is present, with anonymous fallback preserved.Closes #1582
Problem
install.sh resolved
AUTH_HEADER_VALUE(fromGITHUB_APM_PAT/GITHUB_TOKEN) around line 213, but the firstreleases/latestcurl call around line 232 ignored it and ran anonymously. Under rate-limiting the first call would fail, triggering the private-repo fallback unnecessarily.src/apm_cli/utils/version_checker.pyget_latest_version_from_githubcalledrequests.getwith no headers;self_update.pycalls this function, soapm self-updatealso hit the rate limit silently.Approach
Authorization: token $AUTH_HEADER_VALUEwhen already resolved; anonymous otherwise. Anonymous fallback + private-repo retry path unchanged._get_github_token()following canonicalTOKEN_PRECEDENCE["modules"]order (GITHUB_APM_PAT -> GITHUB_TOKEN -> GH_TOKEN); pass header inrequests.getonly when a token is present.Implementation
install.sh (around line 231):
version_checker.py:
Auth guardrails
GITHUB_APM_PAT > GITHUB_TOKEN > GH_TOKEN(mirrorsTOKEN_PRECEDENCE["modules"]incore/token_manager.py). No new env vars.scripts/lint-auth-signals.shpasses (noget_bearer_provideror unannotatedgit ls-remoteviolations).Validation evidence
New tests (
TestGitHubTokenResolution,TestGitHubVersionFetchAuth):Authorizationheader is sent only when a token is presentNonegracefully