GitHub Apps with GitHub Actions, How is that supposed to work #156853
Replies: 3 comments
-
|
A GitHub App is usually recommended over a PAT for automation because the token is installation-scoped, permission-scoped, and short-lived. A PAT is tied to a user account; a GitHub App can act as its own bot identity and can be installed only on the orgs/repos it needs. For Actions, you usually do not need to hand-roll the JWT flow. Store the app private key as an Actions secret, store the app/client ID as a variable, then mint an installation token inside the workflow: steps:
- uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ vars.APP_CLIENT_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
- run: gh api /repos/${{ github.repository }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}That answers the private-key part: the PEM is not read from a server; it is stored as a GitHub Actions secret and passed only to the token-generation step. For the owner/org question, So the flow is:
It feels like a chicken-and-egg problem at first, but the bootstrap secret is only the app’s private key. After that, each workflow run creates a short-lived installation token. Docs:
If this clears it up, please mark it as the answer so future Actions/App users can find the pattern. |
Beta Was this translation helpful? Give feedback.
-
|
A concise answer to each of your questions:
If you're just getting started, I'd recommend using |
Beta Was this translation helpful? Give feedback.
-
|
These are common questions when moving from PATs to GitHub Apps. Here's the general idea: Why GitHub Apps instead of fine-grained PATs? GitHub Apps provide more granular, repository-specific permissions, short-lived installation tokens, and better auditing. They're generally considered more secure than long-lived personal access tokens. Where does the private key (.pem) go? In GitHub Actions, you typically store the private key as an encrypted repository or organization secret. The workflow reads that secret at runtime to generate the JWT—there's no need for a continuously running server just for authentication. How do you know which installation to use? The workflow context (such as the repository owner and repository name) can be used to determine the appropriate installation. If your app is installed on multiple accounts, you may need to query the GitHub API to find the matching installation before requesting an installation token. Why does it feel like a chicken-and-egg problem? It can seem that way initially because you need a JWT to request an installation token, but the JWT is created locally using your app's private key. Once you have the installation token, you authenticate API requests as the app installation rather than as a user. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
I'm in the process of learning GitHub Actions to a professional level. Learning has been harder than I thought it would be. I've read the GitHub Actions documentation, some pages like 5 times, then there are pages that link to other pages, then I realize I've looped. I've been working to complete my first GitHub Actions for a few months now. Its getting better. Here are a few question I'm trying to get answered:
Beta Was this translation helpful? Give feedback.
All reactions