fix: detect stale PEM when GitHub App is deleted and recreated - #1019
Conversation
When a GitHub App is deleted and recreated with the same name, the CLI silently reuses the old PEM from Secret Manager because it matches by slug. The stale PEM causes auth failures at runtime since the new app has a different app ID and private key. Compare the live installation app ID against the stored ROLE_APP_IDS value. When they differ, fall through to the PEM recovery flow instead of reusing stale credentials. Signed-off-by: Wayne Sun <gsun@redhat.com>
|
fullsend review is working on this — view logs |
Site previewPreview: https://840c640d-site.fullsend-ai.workers.dev Commit: |
Review: #1019Head SHA: e41e8a9 SummaryClean, well-scoped fix for a real security/reliability issue: when a GitHub App is deleted and recreated with the same slug, the CLI now detects the stale credentials instead of silently reusing an invalid PEM. The implementation is backwards-compatible (nil storedAppIDs map makes the check a no-op), correctly integrated at both the per-org and per-repo install paths, and thoroughly tested with five new test scenarios covering stale detection, matching ID reuse, backwards compatibility, user-decline flow, and unit-level isAppIDStale edge cases. FindingsInfo
FooterOutcome: approve Previous runReview: #1019Head SHA: 3e8f4a5 SummaryThis PR adds stale-PEM detection when a GitHub App is deleted and recreated with the same slug. The core logic is correct and backwards-compatible: FindingsMedium
Low
Info
FooterOutcome: comment-only |
- Eliminate redundant GetExistingRoleAppIDs call in per-org path by returning stored IDs from copySharedAppPEMs - Log warning instead of silently swallowing GetExistingRoleAppIDs error - Differentiate error message for stale PEM vs missing PEM - Fix godoc comment placement for isAppIDStale and handleExistingApp - Add direct unit test for isAppIDStale (table-driven) - Add test for stale app ID + user declines recovery path Signed-off-by: Wayne Sun <gsun@redhat.com>
|
fullsend review is working on this — view logs |
Restore the inline comment documenting the non-obvious convention that an empty PEM field signals reuse of existing credentials. Signed-off-by: Wayne Sun <gsun@redhat.com>
|
fullsend review is working on this — view logs |
Summary
handleExistingAppmatches by slug and sees the PEM exists. The stale PEM causes auth failures at runtime since the new app has a different app ID and private key.isAppIDStale()to compare the live installation'sapp_idagainst the storedROLE_APP_IDSvalue. When they differ, falls through to the existingrecoverPEMflow instead of silently reusing stale credentials.--skip-mint-check), the check is a no-op and existing behavior is preserved.Changes
internal/appsetup/appsetup.go: AddedstoredAppIDsfield,WithStoredAppIDsbuilder,isAppIDStalemethod, and staleness check inhandleExistingAppinternal/cli/admin.go: Pass storedROLE_APP_IDStorunAppSetupfrom both per-org and per-repo install pathsinternal/appsetup/appsetup_test.go: Three new test cases covering stale ID detection, matching ID reuse, and no-stored-IDs backwards compatibilityTest plan
go test ./internal/appsetup/...— all tests pass including 3 new testsgo test ./internal/cli/...— all tests passgo vet ./internal/appsetup/... ./internal/cli/...— clean