Repository navigation
feat: switch from PAT to GitHub App authentication - #57
Merged
Merged
Conversation
- 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
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