Setup GitOps GitHub App Authentication¶
Purpose¶
This guide explains how to create and configure a GitHub App for the automated promotion workflow that creates PRs to the cluster-gitops repository.
Why GitHub App Instead of PAT?¶
The promote-to-staging and promote-to-production jobs in the CI/CD workflow need to:
- Clone the
cluster-gitopsrepository - Modify environment values files
- Create pull requests to trigger ArgoCD deployments
Why not use GITHUB_TOKEN?
- Default
GITHUB_TOKENhas read-only access to external repositories - Cannot trigger workflows in other repositories (security feature)
Why not use PAT (Personal Access Token)?
- Tied to individual user account (continuity issues if user leaves)
- Broad permissions across all repositories user can access
- Difficult to audit and track usage
Why GitHub App? ✅
- ✅ Repository-scoped permissions: Only access
cluster-gitops, not all repos - ✅ Organization-level identity: Not tied to individual users
- ✅ Fine-grained permissions: Specify exact permissions needed
- ✅ Better audit trail: All actions show as performed by the app
- ✅ No expiration: Unlike PATs, app credentials don't expire (though private keys can be rotated)
- ✅ Can trigger workflows: Unlike
GITHUB_TOKEN, can trigger workflows in target repos
Prerequisites¶
- Organization admin or appropriate permissions to create GitHub Apps
- Access to organization settings
- Basic understanding of public/private key cryptography
Creating the GitHub App¶
Step 1: Create New GitHub App¶
- Go to Organization Settings → Developer settings → GitHub Apps
Direct link: https://github.com/organizations/{org-name}/settings/apps
-
Click New GitHub App
-
Configure the app:
Basic Information:
- GitHub App name: SyRF GitOps Automation (must be unique across GitHub)
- Description: Automated deployment promotions to cluster-gitops repository
- Homepage URL: https://github.com/camaradesuk/syrf
Webhook: - Active: ❌ Uncheck (we don't need webhooks)
Permissions (Repository permissions):
- Contents: Read and write (clone repo, push changes)
- Pull requests: Read and write (create PRs)
- Metadata: Read-only (automatically selected)
Where can this GitHub App be installed?: - ✅ Only on this account (recommended for security)
- Click Create GitHub App
Step 2: Generate Private Key¶
-
After creating the app, scroll to Private keys section
-
Click Generate a private key
-
A
.pemfile will be downloaded automatically -
IMPORTANT: Store this file securely - you'll need it for the secrets
Step 3: Install the App on cluster-gitops Repository¶
-
On the GitHub App settings page, click Install App (left sidebar)
-
Click Install next to your organization name
-
Select Only select repositories
-
Choose:
cluster-gitops -
Click Install
-
Note the App ID from the GitHub App settings page (you'll need this)
Step 4: Add Secrets to syrf Repository¶
- Go to syrf repository settings:
https://github.com/camaradesuk/syrf/settings/secrets/actions
-
Click New repository secret
-
Add APP_ID:
- Name:
APP_ID - Value: The App ID from Step 3 (e.g.,
123456) -
Click Add secret
-
Add APP_PRIVATE_KEY:
- Name:
APP_PRIVATE_KEY -
Value: Contents of the
.pemfile from Step 2 -
Click Add secret
Step 5: Verify Secrets are Available¶
-
Go to:
https://github.com/camaradesuk/syrf/settings/secrets/actions -
Verify both secrets appear:
- ✅
APP_ID - ✅
APP_PRIVATE_KEY
How It Works in the Workflow¶
The workflow uses the actions/create-github-app-token action to generate a short-lived token:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
repositories: cluster-gitops # Only access this repo
This token is then used for checkout and PR creation:
- name: Checkout cluster-gitops
uses: actions/checkout@v4
with:
repository: camaradesuk/cluster-gitops
token: ${{ steps.app-token.outputs.token }}
path: cluster-gitops
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.app-token.outputs.token }}
path: cluster-gitops
# ... other configuration
Key Points:
- Token is generated fresh for each workflow run
- Token expires after 1 hour (short-lived for security)
- Token is scoped to only the
cluster-gitopsrepository - Actions performed by the token show as done by "SyRF GitOps Automation[bot]"
Security Considerations¶
Permissions (Principle of Least Privilege)¶
The app has only the permissions it needs:
- ✅ Contents: Read and write - Clone and push to cluster-gitops
- ✅ Pull requests: Read and write - Create promotion PRs
- ❌ NOT granted: Issues, Actions, Administration, etc.
Repository Scope¶
- App is installed only on
cluster-gitopsrepository - Cannot access any other repositories in the organization
- If you need access to additional repos, must explicitly install there
Private Key Security¶
The .pem private key is the most sensitive component:
- Never commit the
.pemfile to git - Store securely in a password manager or secrets vault
- Rotate regularly (see Rotation Strategy below)
- Revoke immediately if compromised
Audit Trail¶
All actions performed by the app are logged:
- GitHub Audit Log shows app activity
- Commits show author as "SyRF GitOps Automation[bot]"
- PRs show creator as the app
- Easy to identify automated vs manual changes
Rotation Strategy¶
When to Rotate Private Key¶
- Every 90 days (recommended best practice)
- Immediately if key is potentially compromised
- Before team member leaves (if they had access to the key)
- After security incident in the organization
How to Rotate Private Key¶
- Generate new private key:
- Go to GitHub App settings
- Scroll to Private keys
- Click Generate a private key
-
Download the new
.pemfile -
Update secret:
- Go to syrf repository secrets
- Click Update on
APP_PRIVATE_KEY - Paste contents of new
.pemfile -
Click Update secret
-
Test workflow:
- Trigger a test workflow run
- Verify promotion still works
-
Check PR is created successfully
-
Revoke old key:
- Go to GitHub App settings → Private keys
- Click Delete on the old key
- Confirm deletion
Important: Have the new key working before revoking the old one!
Troubleshooting¶
Error: "Resource not accessible by integration"¶
Cause: App doesn't have required permissions
Fix:
- Go to GitHub App settings → Permissions
- Verify Contents and Pull requests are set to "Read and write"
- Click Save changes
- Approve the permission change (organization admins may need to approve)
Error: "Bad credentials" or "Authentication failed"¶
Cause: Invalid APP_ID or APP_PRIVATE_KEY
Fix:
- Verify
APP_IDmatches the App ID in GitHub App settings - Verify
APP_PRIVATE_KEYcontains the full.pemfile contents - Check for extra spaces or newlines when copying
- Regenerate private key if necessary
Error: "App is not installed on repository"¶
Cause: GitHub App not installed on cluster-gitops
Fix:
- Go to GitHub App settings → Install App
- Verify app is installed on
cluster-gitopsrepository - If not, click Install and select
cluster-gitops
PR Creation Shows Wrong Author¶
Expected: PRs should show "SyRF GitOps Automation[bot]" as creator
If showing user account instead:
- Workflow might be using
GITHUB_TOKENinstead of app token - Verify workflow uses
${{ steps.app-token.outputs.token }}
Token Generation Fails¶
Error: "Failed to create installation access token"
Fix:
- Check app is installed on target repository
- Verify
repositories:parameter matches installation - Ensure organization didn't revoke app access
- Check app isn't suspended or disabled
Testing the Setup¶
After configuring the secrets, test the GitHub App authentication:
Test 1: Verify Secrets¶
# This will fail if secrets aren't configured
gh secret list --repo camaradesuk/syrf | grep -E "APP_ID|APP_PRIVATE_KEY"
Expected output:
Test 2: Trigger Promotion Workflow¶
- Make a small change to any service:
echo "# Test GitHub App authentication" >> src/services/api/README.md
git add .
git commit -m "test: verify GitHub App authentication"
git push origin main
- Monitor workflow run:
- Go to:
https://github.com/camaradesuk/syrf/actions - Watch for
promote-to-stagingjob -
Should succeed without errors
-
Check PR in cluster-gitops:
- Go to:
https://github.com/camaradesuk/cluster-gitops/pulls - Verify PR was created
- Check author shows as "SyRF GitOps Automation[bot]"
Test 3: Verify App Audit Trail¶
- Go to:
https://github.com/organizations/{org-name}/settings/audit-log - Filter by:
action:git.clone actor:syrf-gitops-automation - Should see app activity for checkout and PR creation
Comparison: GitHub App vs PAT¶
| Feature | GitHub App ✅ | PAT (Personal Access Token) |
|---|---|---|
| Scoped to specific repos | ✅ Yes | ❌ No (all repos user can access) |
| Organization-level identity | ✅ Yes | ❌ No (tied to user) |
| Fine-grained permissions | ✅ Yes | ⚠️ Limited (PAT scopes are broad) |
| Audit trail | ✅ Clear (bot account) | ⚠️ Mixed with user activity |
| Expiration | ✅ No expiration | ❌ Must renew periodically |
| Can trigger workflows | ✅ Yes | ✅ Yes |
| Survives user leaving | ✅ Yes | ❌ No (token deleted) |
| Setup complexity | ⚠️ More complex | ✅ Simpler |
Verdict: GitHub App is more secure and maintainable for production use.
Migration from PAT (If Previously Used)¶
If you previously used GITOPS_PAT, here's how to migrate:
- Set up GitHub App (follow steps above)
- Update workflow (already done - uses
APP_IDandAPP_PRIVATE_KEY) - Test new setup (follow Testing section)
- Remove old PAT secret:
- Go to repository secrets
- Delete
GITOPS_PAT - Revoke PAT:
- Go to:
https://github.com/settings/tokens - Find "GitOps Cluster Deployment Automation" token
- Click Delete
Related Documentation¶
- CI/CD Workflow:
.github/workflows/ci-cd.yml - GitHub Apps Documentation: https://docs.github.com/en/apps
- create-github-app-token Action: https://github.com/actions/create-github-app-token
- Why GitHub Apps over PATs: https://docs.github.com/en/apps/creating-github-apps/about-creating-github-apps/about-creating-github-apps
Maintenance Checklist¶
Monthly¶
- ✅ Verify app is still installed on cluster-gitops
- ✅ Check recent workflow runs succeeded
- ✅ Review audit log for unexpected activity
Quarterly¶
- ✅ Review app permissions (are they still minimal?)
- ✅ Consider rotating private key
- ✅ Verify only necessary repositories have app installed
Annually¶
- ✅ Rotate private key (mandatory)
- ✅ Review GitHub App security best practices
- ✅ Audit all organization GitHub Apps
Support¶
If you encounter issues:
- Check Troubleshooting section above
- Review workflow logs:
https://github.com/camaradesuk/syrf/actions - Check GitHub Status:
https://www.githubstatus.com/ - Review audit log for app activity
- Create issue in syrf repository with error details