GitHub App Setup for Backstage
This guide walks through setting up a GitHub App for Backstage authentication and organization integration.
Why GitHub App?
GitHub Apps provide several advantages over Personal Access Tokens:
- Higher API rate limits
- Fine-grained permissions
- Act as an application, not a user
- Automatic user and team synchronization from GitHub organizations
Prerequisites
- Admin access to your GitHub organization
- Backstage application running locally
- Node.js 20 installed
Step 1: Create GitHub App
Navigate to GitHub App Creation
Go to: https://github.com/organizations/YOUR-ORG-NAME/settings/apps/new
Replace YOUR-ORG-NAME
with your organization name (e.g., open-service-portal
)
Configure Basic Information
- GitHub App name:
Your Org Backstage
(e.g., "Open Service Portal Backstage") - Description:
Backstage integration for Your Organization
- Homepage URL:
https://github.com/YOUR-ORG-NAME
Configure Authentication
Identifying and authorizing users
- Callback URL:
http://localhost:7007/api/auth/github/handler/frame?env=development
- ✅ Expire user authorization tokens
- ✅ Request user authorization (OAuth) during installation
- ❌ Enable Device Flow (not needed)
Configure Webhook (Optional)
For local development, disable webhooks:
- Active: ❌ Unchecked
For production with a public URL:
- Active: ✅ Checked
- Webhook URL:
https://your-backstage.example.com/api/github/webhook
- Webhook secret: Generate a secure secret
Configure Permissions
Repository permissions:
- Administration:: Read and Write
- Workflow: Read and Write
- Actions: Read and write
- Contents: Read and write
- Issues: Read and write
- Metadata: Read (automatically selected)
- Pull requests: Read and write
Organization permissions:
- Members: Read
Account permissions:
- Email addresses: Read
Installation Settings
- 🔘 Only on this account (recommended for organization-specific apps)
Create the App
Click the green "Create GitHub App" button.
Step 2: Configure GitHub App
After creation, you'll be redirected to the app settings page.
Generate Client Secret
- In the "Client secrets" section
- Click "Generate a new client secret"
- Copy the secret immediately (it's only shown once!)
Generate Private Key
- Scroll to "Private keys" section
- Click "Generate a private key"
- A
.pem
file will be downloaded - Save it securely (e.g.,
github-app-backstage-key.pem
)
Note Important Values
From the app settings page, note:
- App ID: (e.g.,
123456
) - Client ID: (e.g.,
Iv1234567890abcdef
) - Client Secret: (from step above)
Install the App
- Click "Install App" or go to the "Public page"
- Select your organization
- Choose "All repositories" or select specific repositories
- Click "Install"
- Note the Installation ID from the URL:
.../installations/YOUR_INSTALLATION_ID
Step 3: Configure Backstage
Add Environment Variables
Create or update .envrc
in your Backstage app:
# GitHub App Configuration
export AUTH_GITHUB_CLIENT_ID=YOUR_CLIENT_ID
export AUTH_GITHUB_CLIENT_SECRET=YOUR_CLIENT_SECRET
export AUTH_GITHUB_APP_ID=YOUR_APP_ID
export AUTH_GITHUB_APP_PRIVATE_KEY_FILE=/path/to/github-app-key.pem
export AUTH_GITHUB_APP_INSTALLATION_ID=YOUR_INSTALLATION_ID
Update app-config.yaml
Configure GitHub integration:
integrations:
github:
- host: github.com
apps:
- appId: ${AUTH_GITHUB_APP_ID}
clientId: ${AUTH_GITHUB_CLIENT_ID}
clientSecret: ${AUTH_GITHUB_CLIENT_SECRET}
privateKey:
$file: ${AUTH_GITHUB_APP_PRIVATE_KEY_FILE}
auth:
environment: development
providers:
github:
development:
clientId: ${AUTH_GITHUB_CLIENT_ID}
clientSecret: ${AUTH_GITHUB_CLIENT_SECRET}
signIn:
resolvers:
- resolver: usernameMatchingUserEntityName
Step 4: Enable GitHub Organization Import
Install the GitHub Org Module
yarn add @backstage/plugin-catalog-backend-module-github-org
Configure Backend
Add to packages/backend/src/index.ts
:
// GitHub Org Entity Provider - imports users and teams from GitHub
backend.add(import('@backstage/plugin-catalog-backend-module-github-org'));
Configure Catalog
Add to app-config.yaml
:
catalog:
rules:
- allow: [Component, System, API, Resource, Location, User, Group]
providers:
githubOrg:
- id: production
githubUrl: https://github.com
orgs: ['YOUR-ORG-NAME']
schedule:
frequency: { minutes: 30 }
timeout: { minutes: 3 }
Step 5: Start Backstage
# Load environment variables (if using direnv)
direnv allow
# Or manually with nvm
nvm use
source .envrc
# Start Backstage
yarn start
Verification
- Open http://localhost:3000
- Click "Sign In" and choose GitHub
- Authorize the GitHub App
- Check the Software Catalog for automatically imported:
- User entities (organization members)
- Group entities (teams)
Troubleshooting
Authentication Fails
- Verify all environment variables are set correctly
- Check that the callback URL includes
?env=development
- Ensure the GitHub App is installed on your organization
No Users/Groups Imported
- Check the catalog configuration includes
User
andGroup
in rules - Verify the GitHub App has
Members: Read
permission - Check logs for any errors from the GitHub Org provider
NODE_MODULE_VERSION Errors
If you see native module errors after adding the GitHub org module:
rm -rf node_modules .yarn/unplugged .yarn/install-state.gz
nvm use
yarn install
Permission Errors
- Edit the App, add required permissions.
- Install App --> Approve new Permissions in Review Request
Security Notes
- Never commit the private key file or secrets to version control
- Use environment variables or secure secret management
- Rotate client secrets regularly
- For production, use proper secret management solutions