Skip to content

feat: switch from PAT to GitHub App authentication - #57

Merged
AndreiDrang merged 9 commits into
mainfrom
feature/github-app-auth
Aug 25, 2026
Merged

AndreiDrang merged 9 commits into
mainfrom
feature/github-app-auth

Conversation

@AndreiDrang

Copy link
Copy Markdown
Owner
  • Add github-app-auth.js module for JWT generation and installation token management
  • Update GitHubClient to support both PAT (token) and GitHub App (Bearer) authentication
  • Update main-worker to use GitHub App authentication when installation_id is available
  • Update heavy-worker to use GitHub App authentication for queue processing
  • Add installation_id field to storage layer (jobs, webhook_deliveries, repositories)
  • Add migration 0004_add_installation_id.sql for database schema changes
  • Update wrangler.toml files with new secrets (GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY)
  • Add comprehensive tests for github-app-auth.js module
  • Implement fallback to PAT for backward compatibility

This change allows the bot to post comments as a GitHub App (type 'Bot') instead of as a user, which is more secure and scalable.

Closes: Issue with bot posting as user instead of app

mistral-vibe and others added 9 commits August 25, 2026 01:17
- Add github-app-auth.js module for JWT generation and installation token management
- Update GitHubClient to support both PAT (token) and GitHub App (Bearer) authentication
- Update main-worker to use GitHub App authentication when installation_id is available
- Update heavy-worker to use GitHub App authentication for queue processing
- Add installation_id field to storage layer (jobs, webhook_deliveries, repositories)
- Add migration 0004_add_installation_id.sql for database schema changes
- Update wrangler.toml files with new secrets (GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY)
- Add comprehensive tests for github-app-auth.js module
- Implement fallback to PAT for backward compatibility

This change allows the bot to post comments as a GitHub App (type 'Bot')
instead of as a user, which is more secure and scalable.

Closes: Issue with bot posting as user instead of app
This document provides a comprehensive, phase-by-phase plan for implementing
the switch from PAT to GitHub App authentication, including:

- Timeline and resource allocation
- Detailed steps for each phase (Infrastructure, Development, Integration, Testing, Deployment)
- Task assignments and status tracking
- Success metrics and acceptance criteria
- Risk assessment and mitigation strategies
- Documentation update requirements

This plan ensures a smooth, well-documented transition with minimal downtime
and full backward compatibility.
…ror classification

- createTokenProvider is async, resolves GITHUB_APP_ID / GITHUB_APP_PRIVATE_KEY
  through resolveSecretValue (string | {get()} | Promise binding shapes)
- provider exposes .available; unconfigured/missing-installation throw
  non-retryable classified errors
- rename module-level getInstallationToken -> fetchInstallationToken
- appAuthError classification: app_token_fetch_failed (retryable),
  app_jwt_rejected, app_suspended, installation_not_found (permanent);
  raw provider bodies no longer attached to errors
- GitHubClient is Bearer-only (isApp option removed, PAT scheme deleted)
- authorizeCommenter maps 403 to non-retryable app_permission_missing;
  PAT-based isAuthorized helper deleted
- JWT tests use a real RSA keypair and verify RS256 with Web Crypto
- client built only at Gate 4.5 (command path): PR-context events, mirrors,
  and non-command comments mint zero tokens
- createAppGitHubClient throws status-503 errors for missing installation id,
  unconfigured App auth, and mint failures -> GitHub redelivers the webhook
- refreshPrComments authenticates as the App installation; skips the mirror
  on auth failure (derivative slice, next gather rewrites it)
- resolveBotLogin reads GITHUB_BOT_LOGIN only (installation tokens cannot
  call GET /user); legacy PAT-era help comments recognized via the var
- revert unrelated emoji-escape and postHelp formatting churn
…error mapping

- createQueueGitHubClient requires job.installation_id: legacy pre-migration
  jobs fail fast with missing_installation_id instead of retrying
- unconfigured App credentials fail the job (app_auth_unconfigured)
- transient mint failures (network, 5xx) retry with backoff; permanent ones
  (app_jwt_rejected, installation_not_found) fail with cause codes
- GITHUB_TOKEN / resolveSecretValue no longer referenced
- remove the GITHUB_TOKEN Secrets Store binding from both workers (the
  store entry is kept for a rollback window, then deleted)
- .dev.vars.example files carry GITHUB_APP_ID / GITHUB_APP_PRIVATE_KEY
- prettier-format deliveries.js (branch diff hygiene)
- Task 1.1 permission table gains Collaborators: read-only (required by
  GET /collaborators/{user} — the /zai authorization gate)
- PAT-fallback snippets in Tasks 2.1/3.1/3.2 marked superseded by
  PAT_REMOVAL_PLAN.md
- add PAT_REMOVAL_PLAN.md (fix plan + rollout order + acceptance gates)
Why:
* markdownlint autofix normalized the doc so it passes markdown checks

What:
* drop trailing colons from Steps/Artifacts/Verification headings
* add blank lines after task headings; normalize table alignment
* re-flow illustrative code snippets (no content changes)

Changes:
* IMPLEMENTATION_PLAN.md: formatting only, zero semantic edits

Stats:
* 1 file changed
* +152/-83 lines

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.33%. Comparing base (971feb4) to head (44ea60a).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #57      +/-   ##
==========================================
+ Coverage   99.24%   99.33%   +0.08%     
==========================================
  Files          38       39       +1     
  Lines        1864     1956      +92     
  Branches      701      724      +23     
==========================================
+ Hits         1850     1943      +93     
+ Misses         14       13       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AndreiDrang
AndreiDrang merged commit df917f2 into main Aug 25, 2026
6 checks passed
@AndreiDrang
AndreiDrang deleted the feature/github-app-auth branch August 25, 2026 18:12
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.

2 participants