Skip to content

fix(traffic): require a traffic-capable PAT for the archive workflow#265

Merged
davida-ps merged 2 commits into
mainfrom
fix/archive-traffic-token
Jun 11, 2026
Merged

fix(traffic): require a traffic-capable PAT for the archive workflow#265
davida-ps merged 2 commits into
mainfrom
fix/archive-traffic-token

Conversation

@davida-ps

@davida-ps davida-ps commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

User description

Summary

The daily Archive GitHub Traffic workflow (example failure) has failed on every scheduled run since it was added in #252, so no traffic history has been captured yet. Root cause: the TRAFFIC_ARCHIVE_TOKEN secret was never provisioned, and the || github.token fallback can never work — GitHub rejects the Actions installation token on all traffic endpoints (403 Resource not accessible by integration). Traffic endpoints require a PAT from a user with push access.

Changes

  • .github/workflows/archive-traffic.ymlGH_TRAFFIC_TOKEN now uses secrets.TRAFFIC_ARCHIVE_TOKEN only (the github.token fallback was guaranteed to 403). When the secret is missing, the step fails fast with an actionable ::error annotation instead of a cryptic API error.
  • scripts/archive-github-traffic.mjs — 403 push-access failures and 401 invalid-token failures now append a hint explaining the token requirements.
  • scripts/test-github-traffic-archive.mjs — new tests for the 401/403 hints; the workflow-shape test now asserts GH_TRAFFIC_TOKEN binds to secrets.TRAFFIC_ARCHIVE_TOKEN and never to github.token.

Live verification (workflow_dispatch from this branch)

  • An intermediate commit tried falling back to the existing POLL_NVD_CVES_PAT — it returned 401 Bad credentials, i.e. that PAT (set 2026-02-05) is expired or revoked, so the fallback was dropped.
  • Second dispatch confirms the fail-fast guard: the run now stops with “No traffic-capable token configured. Set the TRAFFIC_ARCHIVE_TOKEN secret to a PAT with push access (classic: repo scope; fine-grained: Administration read).”
  • A classic repo-scoped token from a maintainer was confirmed to read /traffic/views successfully (834 views / 378 uniques in the current 14-day window).

Required follow-up after merge (ops)

  1. Create a PAT — recommended: fine-grained, scoped to this repository only, with Administration: read (a classic PAT with repo scope also works), owned by a user with push access.
  2. gh secret set TRAFFIC_ARCHIVE_TOKEN --repo prompt-security/clawsec
  3. gh workflow run archive-traffic.yml --repo prompt-security/clawsec — the first green run creates the traffic-archive branch and seeds it with the current 14-day window.

⏳ GitHub only retains ~14 days of traffic data; each day without the secret permanently loses a day of history.

Heads-up (separate issue)

POLL_NVD_CVES_PAT returning 401 also means the community-advisory.yml automation will fail the next time an issue is labeled advisory-approved — that PAT needs rotation regardless of this PR.

🤖 Generated with Claude Code


Generated description

Below is a concise technical summary of the changes proposed in this PR:
Clarify the archive workflow token requirements by binding GH_TRAFFIC_TOKEN exclusively to secrets.TRAFFIC_ARCHIVE_TOKEN and failing fast with guidance when the secret is missing. Enhance archive-github-traffic.mjs and its tests to append specific hints for 403/401 errors so operators know to provide a push-capable PAT.

TopicDetails
Workflow token guard Enforce the traffic archive workflow to require a configured PAT via secrets.TRAFFIC_ARCHIVE_TOKEN, report an actionable error when absent, and only run archive-github-traffic once the token guard passes.
Modified files (1)
  • .github/workflows/archive-traffic.yml
Latest Contributors(2)
UserCommitDate
David.a@prompt.securityfix(traffic): require ...June 10, 2026
david.a@prompt.securityfeat(traffic): archive...June 04, 2026
Token error hints Clarify scripts/archive-github-traffic.mjs and its tests to append push-access or rotation hints on 403/401 responses so failures point to the required PAT credentials.
Modified files (2)
  • scripts/archive-github-traffic.mjs
  • scripts/test-github-traffic-archive.mjs
Latest Contributors(2)
UserCommitDate
David.a@prompt.securityfix(traffic): use a tr...June 10, 2026
david.a@prompt.securityfeat(traffic): archive...June 04, 2026
Review this PR on Baz | Customize your next review

davida-ps and others added 2 commits June 10, 2026 18:47
The daily Archive GitHub Traffic run has failed since creation: the
TRAFFIC_ARCHIVE_TOKEN secret was never provisioned, so the workflow fell
back to github.token, which GitHub categorically rejects on traffic
endpoints (403 "Resource not accessible by integration").

- Fall back to the existing POLL_NVD_CVES_PAT automation token instead
  of github.token, keeping TRAFFIC_ARCHIVE_TOKEN as the preferred
  override once provisioned.
- Fail fast with an actionable error when no traffic-capable token is
  configured.
- Explain token requirements in the script's 401/403 errors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…AT fallback

A live dispatch confirmed POLL_NVD_CVES_PAT is expired (401 Bad
credentials), so falling back to it only trades one daily failure for
another. Require the dedicated secret and fail fast with setup
instructions instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment on lines +326 to +329
const hint = lacksPushAccess
? ' Traffic endpoints require a token with push access to the repository; the Actions GITHUB_TOKEN is always rejected. Use a classic PAT with the repo scope or a fine-grained PAT with read access to Administration.'
: response.status === 401
? ' The token was rejected as invalid — it may be expired or revoked. Rotate the TRAFFIC_ARCHIVE_TOKEN secret.'

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.

The invalid-token hint is gated only on response.status === 401, but GitHub can return 403/404 for auth failures too — should we key this off the error body (for example Bad credentials) or include those cases as well?

Severity web_search

Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
scripts/archive-github-traffic.mjs around lines 321-332 inside the `if (!response.ok)`
error handling, the token-invalid/expired hint is currently only shown when
`response.status === 401` (lines ~328-330). Refactor the `hint` selection so it also
covers GitHub’s documented auth/permission failure variants (notably 403 and 404) by
keying off the response body text (e.g., look for “Bad credentials” /
authentication-failure phrases) rather than status alone, while keeping the existing
dedicated “missing push access” hint for 403 with the “resource not
accessible/must have push access” messages. Ensure the body-based checks are used in
the right precedence order so unrelated 401s don’t incorrectly get the expired-token
message, and revoked/expired tokens get the correct hint for 401/403/404 shapes.

@davida-ps davida-ps merged commit 9fd3059 into main Jun 11, 2026
14 of 17 checks passed
@davida-ps davida-ps deleted the fix/archive-traffic-token branch June 11, 2026 05:25
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.

1 participant