-
Notifications
You must be signed in to change notification settings - Fork 35
feat(github): add GitHub App authentication for self-hosted runner registration #860
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
Open
adrianriobo
wants to merge
4
commits into
redhat-developer:main
Choose a base branch
from
adrianriobo:fix-851
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08967c5
feat(github): add GitHub App authentication for self-hosted runner re…
adrianriobo fbd71ed
docs(github): fix runner auth precedence and scope in self-hosted-run…
adrianriobo 6f8c6c0
feat(github): add organization-level runner support
adrianriobo b98c0e9
feat(github): add --ghactions-runner-ephemeral flag to control runner…
adrianriobo 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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,59 +1,85 @@ | ||||||
| # Overview | ||||||
|
|
||||||
| This feature of `mapt` allows to setup hosts deployed by it as a GitHub Self Hosted Runner, which can then be directly used for running GitHub actions jobs. | ||||||
| This feature of `mapt` allows to setup hosts deployed by it as a GitHub Self Hosted Runner, which can then be directly used for running GitHub Actions jobs. | ||||||
| It benefits from all the existing features that `mapt` already provides, allowing to create self-hosted runners that can be used for different QE scenarios. | ||||||
|
|
||||||
| ## Providers and Platforms | ||||||
|
|
||||||
| Currently, it allows to create self-hosted runners on AWS (Windows Server, RHEL) and Azure (Windows Desktop) | ||||||
| Currently, it allows to create self-hosted runners on: | ||||||
|
|
||||||
| ### Prerequisite | ||||||
| * AWS: Windows Server, RHEL, Fedora, macOS | ||||||
| * Azure: Windows Desktop, RHEL | ||||||
| * IBM Cloud: IBM Power (ppc64le), IBM Z (s390x) | ||||||
|
|
||||||
| To register a Self Hosted Runner for a repository or a GitHub organization, the runner program needs a registration token, which can be obtained by requesting the | ||||||
| GitHub API. | ||||||
| ## Authentication | ||||||
|
|
||||||
| * [Information for requesting a token to register a runner for an Organization](https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-an-organization) | ||||||
| * [Information for requesting a token to register a runner for a repository](https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository) | ||||||
| Registering a Self Hosted Runner requires a short-lived registration token from GitHub. `mapt` supports three ways to supply it. Precedence order: GitHub App credentials → explicit registration token → GITHUB_TOKEN (PAT auto-generate). | ||||||
|
|
||||||
| After obtaining the token we can invoke `mapt` with it to deploy a VM as a Self hosted runner. | ||||||
| ### Option A — GitHub App (recommended) | ||||||
|
|
||||||
| For example to add a runner to this repository, we can use the following `curl` command to request a token: | ||||||
| Using a GitHub App avoids long-lived credentials. `mapt` exchanges the App's private key for a short-lived installation access token inside the Pulumi deployment, then uses it to fetch a fresh runner registration token automatically. | ||||||
|
|
||||||
| ``` | ||||||
| % curl -L \ | ||||||
| -X POST \ | ||||||
| -H "Accept: application/vnd.github+json" \ | ||||||
| -H "Authorization: Bearer <github_personal_access_token>" \ | ||||||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||||||
| https://api.github.com/repos/redhat-developer/mapt/actions/runners/registration-token | ||||||
| ``` | ||||||
| The Response from this `POST` request will be: | ||||||
| **Prerequisites:** | ||||||
|
|
||||||
| ``` | ||||||
| { | ||||||
| "token": "ACDZL3QXEIC73UXBDGSEYEI", | ||||||
| "expires_at": "2024-07-12T19:01:48.478+05:30" | ||||||
| } | ||||||
| ``` | ||||||
| 1. Create a GitHub App with the `administration:write` permission on the target repository. | ||||||
| 2. Install the App on the target repository and note the **Installation ID**. | ||||||
| 3. Generate and download the App's **private key** (`.pem` file). | ||||||
|
|
||||||
| ### Operations | ||||||
| **Flags:** | ||||||
|
|
||||||
| After getting the required token, we need to also decide what we are going to call this runner, the desired name can be passed to the `mapt` command using the | ||||||
| `--ghactions-runner-name` flag. | ||||||
| | Flag | Description | | ||||||
| |------|-------------| | ||||||
| | `--ghactions-app-id` | GitHub App ID (numeric, shown on the App settings page) | | ||||||
| | `--ghactions-app-installation-id` | Installation ID for the target org or repository | | ||||||
| | `--ghactions-app-private-key` | Path to the App RSA private key PEM file | | ||||||
| | `--ghactions-runner-repo` | Full URL of the repository (mutually exclusive with `--ghactions-runner-org`) | | ||||||
| | `--ghactions-runner-org` | GitHub organization name for an org-level runner (mutually exclusive with `--ghactions-runner-repo`) | | ||||||
| | `--ghactions-runner-labels` | Comma-separated labels to attach to the runner (optional) | | ||||||
|
|
||||||
| The full URL of the repository or the GitHub organization also needs to be passed using the `--ghactions-runner-repo` flag. | ||||||
| **Example:** | ||||||
|
|
||||||
| ```bash | ||||||
| mapt aws rhel create \ | ||||||
| --ghactions-runner-repo "https://github.com/redhat-developer/mapt" \ | ||||||
| --ghactions-app-id "123456" \ | ||||||
| --ghactions-app-installation-id "789012" \ | ||||||
| --ghactions-app-private-key "/path/to/app-private-key.pem" \ | ||||||
| --project-name mapt-rhel-aws \ | ||||||
| --backed-url file:///workspace/state \ | ||||||
| --conn-details-output /workspace/conn-details | ||||||
| ``` | ||||||
|
|
||||||
| To deploy a Windows runner on the Azure provider, we can use the following command: | ||||||
| ### Option B — Personal Access Token (PAT) | ||||||
|
|
||||||
| Set the `GITHUB_TOKEN` environment variable to a PAT with `repo` admin scope. `mapt` will call the GitHub API to generate a registration token automatically before deployment. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only covers the repo case. For org-level runners (
Suggested change
|
||||||
|
|
||||||
| ```bash | ||||||
| export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxx | ||||||
| mapt aws rhel create \ | ||||||
| --ghactions-runner-repo "https://github.com/redhat-developer/mapt" \ | ||||||
| --project-name mapt-rhel-aws \ | ||||||
| --backed-url file:///workspace/state \ | ||||||
| --conn-details-output /workspace/conn-details | ||||||
| ``` | ||||||
| % mapt azure windows create --spot \ | ||||||
| --install-ghactions-runner \ | ||||||
| --ghcations-runner-token="ACDZL3QXEIC73UXBDGSEYEI" \ | ||||||
| --ghcations-runner-name "az-win-11" \ | ||||||
| --ghcations-runner-repo "https://github.com/redhat-developer/mapt" \ | ||||||
|
|
||||||
| ### Option C — Pre-generated registration token | ||||||
|
|
||||||
| Pass a registration token obtained manually from the GitHub API directly via `--ghactions-runner-token`. Tokens expire after 1 hour. | ||||||
|
|
||||||
| ```bash | ||||||
| # Obtain a token via the GitHub API: | ||||||
| curl -L -X POST \ | ||||||
| -H "Accept: application/vnd.github+json" \ | ||||||
| -H "Authorization: Bearer <pat>" \ | ||||||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||||||
| https://api.github.com/repos/redhat-developer/mapt/actions/runners/registration-token | ||||||
|
|
||||||
| mapt azure windows create --spot \ | ||||||
| --ghactions-runner-repo "https://github.com/redhat-developer/mapt" \ | ||||||
| --ghactions-runner-token "ACDZL3QXEIC73UXBDGSEYEI" \ | ||||||
| --project-name mapt-windows-azure \ | ||||||
| --backed-url file:///Users/tester/workspace \ | ||||||
| --conn-details-output /Users/tester/workspace/conn-details | ||||||
| --backed-url file:///workspace/state \ | ||||||
| --conn-details-output /workspace/conn-details | ||||||
| ``` | ||||||
| > *NOTE:* additional _labels_ can be added to the runner using the flag `--ghactions-runner-labels`, e.g `--ghactions-runner-lables="azure,mapt,windows"` | ||||||
|
|
||||||
| > **Note:** Additional labels can be added to the runner with `--ghactions-runner-labels`, e.g. `--ghactions-runner-labels="azure,mapt,windows"`. | ||||||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For org-level runners (
--ghactions-runner-org), the App needs theorganization_self_hosted_runners:writepermission instead of repo-leveladministration:write. Since the flags table and code already support the org path, consider something like: