github app setup - hyperfocus/porc GitHub Wiki
GitHub App Setup for PORC
This guide walks through setting up a GitHub App for PORC to enable Check Runs API access.
Prerequisites
- Python 3.11 or later
pip
package managerkubectl
configured with access to your cluster- GitHub account with admin access to the repository
Important Security Note
The following files contain sensitive information and should never be committed to version control:
k8s/secrets/
directory and all its contents*.pem
files (private keys)github-app-config.json
These files are automatically added to .gitignore
to prevent accidental commits.
Step 1: Create GitHub App
-
Go to GitHub App settings
-
Fill in the following details:
- GitHub App name:
porc-checks-bot
(or your preferred name) - Homepage URL: Your PORC API URL (e.g.,
https://github.com/hyperfocus/porc
) - Webhook URL: Leave empty for now
- Webhook secret: Leave empty for now
- GitHub App name:
-
Set the following permissions:
- Checks: Read & write
- Contents: Read-only
- Pull requests: Read-only
-
Subscribe to these events:
- Check run
- Check suite
- Pull request
-
Where can this GitHub App be installed?
- Select "Only on this account"
-
Click "Create GitHub App"
Step 2: Generate Private Key
- In your GitHub App settings, scroll to "Private keys"
- Click "Generate a private key"
- Save the downloaded
.pem
file securely
Step 3: Install GitHub App
- Go to your GitHub App's page (e.g.,
https://github.com/apps/porc-checks-bot
) - Click "Install App"
- Select your repository
- Click "Install"
Step 4: Generate Configuration
-
Install required Python packages:
pip install PyJWT
-
Run the configuration script:
python scripts/create_github_app.py \ --name "porc-checks-bot" \ --homepage "https://github.com/hyperfocus/porc" \ --owner "hyperfocus" \ --repo "porc"
-
When prompted:
- Enter the path to your downloaded
.pem
file - Enter the App ID (found in your app's settings page)
- Enter the path to your downloaded
-
The script will generate:
github-app-config.json
: Contains app ID, private key, and installation ID
Step 5: Create Kubernetes Secrets
-
Run the secrets generation script:
python scripts/create_k8s_secrets.py --config github-app-config.json
-
This will create three secret files in
k8s/secrets/
:github-app-id.yaml
: App ID secretgithub-app-key.yaml
: Private key secretgithub-app-installation-id.yaml
: Installation ID secret
-
Apply the secrets to your cluster:
kubectl apply -f k8s/secrets
Step 6: Update PORC Configuration
-
Apply the GitHub App ConfigMap:
kubectl apply -f k8s/config/github-app.yaml
-
Update the deployment:
kubectl apply -f k8s/deployment.yaml
-
Restart the deployment to pick up new configuration:
kubectl rollout restart deployment/porc-api
Step 7: Verify Setup
- Create a new PR in your repository
- The PORC API should now:
- Create check runs using the GitHub App
- Update check run status
- Post check run results
Troubleshooting
Common Issues
-
401 Unauthorized
- Verify the private key is correctly saved in Kubernetes secrets
- Check that the App ID and Installation ID are correct
- Ensure the GitHub App has the correct permissions
-
404 Not Found
- Verify the GitHub App is installed on the repository
- Check that the Installation ID is correct
-
403 Forbidden
- Verify the GitHub App has the required permissions
- Check that the repository is in the allowed list
Checking Logs
kubectl logs -f deployment/porc-api
Security Notes
- Keep the private key secure and never commit it to version control
- Regularly rotate the private key through the GitHub App settings
- Use the minimum required permissions for the GitHub App
- Consider using a dedicated namespace for the PORC deployment
Maintenance
Updating App Permissions
- Go to your GitHub App settings
- Update permissions as needed
- Click "Save changes"
- Reinstall the app on your repository
Rotating Private Key
- Generate a new private key in GitHub App settings
- Update the Kubernetes secret:
kubectl create secret generic github-app-key \ --from-file=private_key=path/to/new-key.pem \ --dry-run=client -o yaml | kubectl apply -f -
- Restart the deployment:
kubectl rollout restart deployment/porc-api