-
Notifications
You must be signed in to change notification settings - Fork 0
feat: ✨ guide to make GitHub Apps to make tokens #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Security practices | ||
|
|
||
| ## Using GitHub Apps to generate tokens | ||
|
|
||
| [GitHub Apps](https://docs.github.com/en/apps/overview) are a way to | ||
| integrate with GitHub and perform actions on behalf of a user or | ||
| organization. For instance, they can be used to generate tokens with | ||
| specific permissions to use in GitHub Action workflows. Rather than | ||
| creating a personal access token (PAT) that works for the organisation | ||
| and then having to regularly regenerate them, if you create a GitHub | ||
| App, it can create a token when it is needed, e.g. whenever a specific | ||
| workflow runs. As soon as the workflow is done, the token is deleted. | ||
| That way, you can limit the exposure of the token, minimising security | ||
| risks. | ||
|
|
||
| You can make a GitHub App to create a token following these steps: | ||
|
|
||
| 1. Go to the organization's settings and click the "GitHub Apps" | ||
| link under "Developer Settings" at the bottom of the settings | ||
| sidebar, e.g. | ||
| [`seedcase-project`](https://github.com/organizations/seedcase-project/settings/apps). | ||
| 2. Click "New GitHub App" to create a new app. | ||
| - Fill in the app name with a descriptive name, e.g. | ||
| "generate-auto-release-token". | ||
| - Fill in the description on what the app does. | ||
| - For the homepage URL, use the format: | ||
| `https://github.com/apps/APP-NAME`, e.g. | ||
| <https://github.com/apps/generate-auto-release-token>. | ||
| - Uncheck all the checkboxes in the other sections. | ||
| - Select the permissions you want the app to have under | ||
| "Permissions". | ||
| - Select "Only on this account" under "Where can this GitHub App | ||
| be installed?". | ||
| - Click "Create GitHub App" to create the app. | ||
| 3. In the newly created app, scroll to the bottom and click "Generate a | ||
| private key" to create a private key for the app. | ||
| - Save the private key to your computer, as it will be used to | ||
| generate the token. | ||
| 4. On the sidebar, click the "Install App" link and in the new page, | ||
| click "Install" on the organisation you want it in. | ||
| - Give it access to the repositories you want it to have access to | ||
| by clicking "All repositories" or "Only select repositories" and | ||
| selecting the repositories you want it to have access to. | ||
| 5. Go to the organisation's settings under "Security" and "Secrets and | ||
| variables", click the "Actions" link. | ||
| 6. Click the "Variables" tab and then "Create new organisation | ||
| variable" (or edit an existing one). | ||
| - Write a new name for the variable, being descriptive enough to | ||
| know what it is for. | ||
| - Paste the "App ID" of the app you created, which is found in the | ||
| app's settings page at the top. | ||
| 7. Click the "Secrets" tab and then "New organisation secret" (or edit | ||
| an existing one). | ||
| - Write a new name for the secret, being descriptive enough to | ||
| know what it is for. | ||
| - Go to your computer and using a text editor, open the private | ||
| key you saved earlier. Copy the contents of the file and paste | ||
| it into the secret's value field. | ||
|
|
||
| To make use of the app and it's generated token in workflows, you can | ||
| use the | ||
| [`actions/create-github-app-token`](https://github.com/actions/create-github-app-token). | ||
| In your workflow file, add this action: | ||
|
|
||
| ``` yaml | ||
| - uses: actions/create-github-app-token@v2 | ||
| id: app-token | ||
| with: | ||
| app-id: ${{ vars.APP_ID }} | ||
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
| ``` | ||
|
|
||
| Then, in any other action that needs a token, use: | ||
|
|
||
| ``` yaml | ||
| with: | ||
| token: ${{ steps.app-token.outputs.token }} | ||
| ``` | ||
|
|
||
| For example, if you want to use the token in a checkout action, you can | ||
| do: | ||
|
|
||
| ``` yaml | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ steps.app-token.outputs.token }} | ||
| ``` | ||
|
|
||
| If you have branch rulesets or branch protections set up, you will need | ||
| to add the app to the bypass list, if it is necessary to do things that | ||
| are against the ruleset or protection. | ||
|
|
||
| If you need to set the app as a "user" in the workflow, use the name | ||
| `github-actions[bot]` and the email | ||
| `41898282+github-actions[bot]@users.noreply.github.com` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.