-
Notifications
You must be signed in to change notification settings - Fork 373
Use GitHub App for 'This is now live' notifications #1910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Replace personal access token authentication with GitHub App so notifications appear from a bot identity rather than an individual user. Changes: - Add github_app.py module for JWT generation and token exchange - Update notify.py to use Bearer authentication - Update blue_green.py to use get_github_app_token() - Add PyJWT dependency for JWT signing Manual setup (already done): - Created GitHub App with Issues/PRs read/write permissions - Stored App ID and private key in SSM parameters 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Convert from unittest.TestCase to plain functions - Use pytest.raises instead of try/except 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
How JWT Authentication Works HereGitHub Apps use a two-step authentication flow. This PR implements that flow. Why JWT?GitHub needs to verify that requests actually come from our app, not an impersonator. The app's private key (stored in SSM) is the proof of identity - only we have it. The Authentication FlowsequenceDiagram
participant CE as CE Deploy Script
participant SSM as AWS SSM
participant GH as GitHub API
CE->>SSM: Get app ID and private key
SSM-->>CE: Credentials
Note over CE: Generate JWT<br/>(signed with private key)
CE->>GH: GET /app/installations<br/>Authorization: Bearer <jwt>
Note over GH: Verify JWT signature<br/>using app's public key
GH-->>CE: List of installations
Note over CE: Find compiler-explorer<br/>installation ID
CE->>GH: POST /app/installations/{id}/access_tokens<br/>Authorization: Bearer <jwt>
GH-->>CE: Installation token (1 hour validity)
CE->>GH: POST /repos/.../issues/.../comments<br/>Authorization: Bearer <token>
Note over GH: Posts as<br/>compiler-explorer-bot[bot]
JWT StructureA JWT is three base64-encoded parts separated by dots:
GitHub has our public key (uploaded when the app was created). When we send a JWT, GitHub:
If verification passes, GitHub knows the request is legitimately from our app. Why RS256?RS256 is asymmetric encryption - different keys for signing vs verifying. We keep the private key secret; GitHub has the public key. This means GitHub can verify our requests without ever having our secret. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR replaces personal access token (PAT) authentication with GitHub App authentication for "This is now live" notifications. This allows notifications to appear from a bot identity (compiler-explorer-bot[bot]) rather than an individual user, improving the professionalism and maintainability of automated notifications.
Key changes:
- New GitHub App authentication module with JWT generation and installation token exchange
- Updated GitHub API authentication from
tokentoBearerformat (required for GitHub Apps) - SSM parameter-based credential management for App ID and private key
Reviewed changes
Copilot reviewed 1 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Adds PyJWT[crypto] dependency for RSA-based JWT signing |
| bin/lib/github_app.py | New module implementing GitHub App authentication flow (JWT generation, installation lookup, token exchange) |
| bin/test/github_app_test.py | Comprehensive test coverage for the new GitHub App module with unit tests for all major functions |
| bin/lib/notify.py | Updates Authorization header format from token to Bearer for GitHub App compatibility |
| bin/lib/cli/blue_green.py | Replaces PAT retrieval with GitHub App token; removes old error handling and fallback logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Replace personal access token authentication with a GitHub App so "This is now live" notifications appear from a bot identity (
compiler-explorer-bot[bot]) rather than an individual user.Changes
github_app.pymodule for JWT generation and installation token exchangenotify.pyto use Bearer authentication (required for GitHub App tokens)blue_green.pyto useget_github_app_token()instead of the old PATPyJWT[crypto]dependency for JWT signingTesting
GitHub App and SSM parameters have been configured. Verified:
Token retrieval - Successfully generates JWT and exchanges for installation token:
API access - Token works for GitHub API calls:
Full notification flow - Dry-run shows correct behavior:
Unit tests - All 458 tests pass, with new tests for the GitHub App module
Configuration
The following SSM parameters have been set up:
/compiler-explorer/github-app-id- App ID/compiler-explorer/github-app-private-key- Private key (SecureString)🤖 Generated with Claude Code