-
Notifications
You must be signed in to change notification settings - Fork 25
Update documentation #150
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
Update documentation #150
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
db6b967
Update documentation
yhaliaw b522a64
Fix typo
yhaliaw 0fbb685
Update charm architecture docs
yhaliaw a66849c
Update how-to docs
yhaliaw 108a74d
Update docs
yhaliaw 593ee69
Update change token docs
yhaliaw 7db96bf
Remove how-to- prefix
yhaliaw a0a078c
Add how-to-run-on-lxd doc
yhaliaw 2ed096d
Update docs
yhaliaw a289cc7
Merge branch 'main' into docs
yhaliaw 76336de
Add how to contribute docs
yhaliaw b748e80
Fix grammar
yhaliaw 6865180
Add reference to resource usage in quick start
yhaliaw d87683c
Remove reference to security for repo policy
yhaliaw bf7d8ed
Add configure denylist
yhaliaw a6c7d3b
Merge branch 'main' into docs
yhaliaw 03eefa9
Apply suggestions from code review
yhaliaw 96bfcd0
Fix juju config command
yhaliaw 0bcf59d
Update according to comments
yhaliaw 03ee006
Fix docs on GitHub token usage
yhaliaw 27bf358
Merge branch 'main' into docs
yhaliaw f41ce85
Fix docs
yhaliaw 9c12a68
Merge branch 'main' into docs
yhaliaw fd9188d
Merge branch 'main' into docs
yhaliaw 8cafac8
Merge branch 'main' into docs
yhaliaw 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,74 @@ | ||
| # Charm architecture | ||
|
|
||
| A [Juju](https://juju.is/) [charm](https://juju.is/docs/olm/charmed-operators) to operate a set of [GitHub self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners) while managing the security and resource usage. | ||
| A [Juju](https://juju.is/) [charm](https://juju.is/docs/olm/charmed-operators) to operate a set of [GitHub self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners) while managing security and resource usage. | ||
|
|
||
| Conceptually, the charm can be divided into the following: | ||
|
|
||
| - Management of LXD ephemeral virtual machines to host [ephemeral self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling). | ||
| - Management of a [Python web service for checking GitHub repository settings](https://github.com/canonical/repo-policy-compliance). | ||
| - Management of LXD ephemeral virtual machines to host [ephemeral self-hosted runners](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/autoscaling-with-self-hosted-runners#using-ephemeral-runners-for-autoscaling) | ||
| - Management of the network | ||
| - GitHub API usage | ||
| - Management of [Python web service for checking GitHub repository settings](https://github.com/canonical/repo-policy-compliance) | ||
| - Management of dependencies | ||
|
|
||
| ## LXD ephemeral virtual machines | ||
|
|
||
| To ensure a clean and isolated environment for every runner, Self-hosted runners are hosted using LXD virtual machines. The charm spawns virtual machines setting resources based on charm configurations. The self-hosted runners start with the ephemeral option and will clean themselves up once the execution has finishes, freeing the resources. | ||
| To ensure a clean and isolated environment for every runner, self-hosted runners use LXD virtual machines. The charm spawns virtual machines, setting resources based on charm configurations. The self-hosted runners start with the ephemeral option and will clean themselves up once the execution has finished, freeing the resources. This is [similar to how GitHub hosts their runners due to security concerns](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#self-hosted-runner-security). | ||
|
|
||
| As the virtual machines are single-use, the charm will replenish virtual machines on a regular schedule. This time period is determined by the [`reconcile-interval` configuration](https://charmhub.io/github-runner/configure#reconcile-interval). | ||
|
|
||
| On schedule or upon configuration change, the charm performs a reconcile to ensure the number of runners managed by the charm matches the [`virtual-machines` configuration](https://charmhub.io/github-runner/configure#virtual-machines), and the resources used by the runners match the various resource configurations. | ||
|
|
||
| The virtual machines hosting the runner use random access memory as disk; therefore, the [`vm-disk` configuration](https://charmhub.io/github-runner/configure#vm-disk) can impact the memory usage of the Juju machine. This is done to prevent disk IO exhaustion on the Juju machine on disk-intensive GitHub workflows. In the future, an alternative method to prevent disk IO exhaustion will be implemented. | ||
|
|
||
| ## Network configuration | ||
|
|
||
| The charm respects the HTTP(S) proxy configuration of the model configuration of Juju. The configuration can be set with [`juju model-config`](https://juju.is/docs/juju/juju-model-config) using the following keys: `juju-http-proxy`, `juju-https-proxy`, `juju-no-proxy`. The GitHub self-hosted runner applications are configured to use the proxy configuration. | ||
|
|
||
| If an HTTP(S) proxy is used, all HTTP(S) requests in the GitHub workflow will be transparently routed to the proxy with [aproxy](https://github.com/canonical/aproxy). Iptables are set up to route network traffic to the destination on ports 80 and 443 to the aproxy. The aproxy will route received packets to the configured HTTP(S) proxy. The service is installed on each runner virtual machine and configured according to the proxy configuration from the Juju model. | ||
|
|
||
| The nftables on the Juju machine are configured to deny traffic from the runner virtual machine to IPs on the [`denylist` configuration](https://charmhub.io/github-runner/configure#denylist). The runner will always have access to essential services such as DHCP and DNS, regardless of the denylist configuration. | ||
|
|
||
|
|
||
| ## GitHub API usage | ||
|
|
||
| The charm requires a GitHub personal access token for the [`token` configuration](https://charmhub.io/github-runner/configure#token). This token is used for: | ||
|
|
||
| - Requesting self-hosted runner registration tokens | ||
| - Requesting self-hosted runner removal tokens | ||
| - Requesting a list of runner applications | ||
| - Requesting a list of self-hosted runners configured in an organization or repository | ||
| - Deletion of self-hosted runners | ||
|
yhaliaw marked this conversation as resolved.
|
||
|
|
||
| The token is also passed to [repo-policy-compliance](https://github.com/canonical/repo-policy-compliance) to access GitHub API for the service. | ||
|
|
||
| ## GitHub repository setting check | ||
|
|
||
| A [flask application](https://flask.palletsprojects.com/) hosted on [gunicorn](https://gunicorn.org/) provides a RESTful HTTP API to check the settings of GitHub repository. This ensures the GitHub repository settings do not allow the execution of code not reviewed by maintainers on the self-hosted runners. | ||
| The [repo-policy-compliance](https://github.com/canonical/repo-policy-compliance) is a [Flask application](https://flask.palletsprojects.com/) hosted on [Gunicorn](https://gunicorn.org/) that provides a RESTful HTTP API to check the settings of GitHub repositories. This ensures the GitHub repository settings do not allow the execution of code not reviewed by maintainers on the self-hosted runners. | ||
|
|
||
| Using the [pre-job script](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job#about-pre--and-post-job-scripts), the self-hosted runners call the Python web service to check if the GitHub repository settings for the job are compliant. If not compliant, it will output an error message and force stop the runner to prevent code from being executed. | ||
|
|
||
| ## Dependencies management | ||
|
|
||
| Upon installing or upgrading the charm, the kernel will be upgraded, and the Juju machine will be restarted if needed. | ||
|
|
||
| The charm installs the following dependencies: | ||
|
|
||
| - For running repo-policy-compliance | ||
| - gunicorn | ||
| - For firewall to prevent runners from accessing web service on the denylist | ||
| - nftables | ||
| - For virtualization and virtual machine management | ||
| - lxd | ||
| - cpu-checker | ||
| - libvirt-clients | ||
| - libvirt-daemon-driver-qemu | ||
| - apparmor-utils | ||
|
|
||
| These dependencies can be regularly updated using the [landscape-client charm](https://charmhub.io/landscape-client). | ||
|
|
||
| The charm installs the following dependencies and regularly updates them: | ||
|
yhaliaw marked this conversation as resolved.
|
||
|
|
||
| - repo-policy-compliance | ||
| - GitHub self-hosted runner application | ||
|
yhaliaw marked this conversation as resolved.
|
||
|
|
||
| Using the [pre-job script](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/running-scripts-before-or-after-a-job#about-pre--and-post-job-scripts), the self-hosted runners calls the Python web service to check if the GitHub repository settings for the job are compliant. If not compliant, it will output an error message and force stop the runner to prevent code from being executed. | ||
| The charm checks if the installed versions are the latest and performs upgrades if needed before creating new virtual machines for runners. | ||
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,18 +1,22 @@ | ||
| # How to change GitHub personal access token | ||
|
|
||
| This charm supports changing [GitHub personal access token (PAT)](https://github.com/settings/tokens) used. | ||
| This charm supports changing the [GitHub personal access token (PAT)](https://github.com/settings/tokens) used. | ||
|
|
||
| ## Personal access token scope | ||
|
|
||
| For using this charm for GitHub repository the following scopes should be selected: | ||
| To use this charm for GitHub repositories, the following scopes should be selected: | ||
|
|
||
| - `repo` | ||
|
|
||
| For using this charm for GitHub organization the following scopes should be selected: | ||
| To use this charm for GitHub organisations, the following scopes should be selected: | ||
|
|
||
| - `repo` | ||
| - `admin:org` | ||
|
|
||
| ## Changing the token | ||
|
|
||
| By using [`juju config`](https://juju.is/docs/juju/juju-config) to change the [charm configuration token](https://charmhub.io/github-runner/configure#token) the charm unregisters and removes the old self-hosted runners and instantiates new ones. | ||
| By using [`juju config`](https://juju.is/docs/juju/juju-config) to change the [charm configuration token](https://charmhub.io/github-runner/configure#token) the charm unregisters and removes the old self-hosted runners and instantiates new ones. | ||
|
yhaliaw marked this conversation as resolved.
|
||
|
|
||
| ```shell | ||
| juju config <APP_NAME> token=<TOKEN> | ||
| ``` | ||
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,24 @@ | ||
| # How to restrict self-hosted runner network access | ||
|
|
||
| The [`denylist` configuration](https://charmhub.io/github-runner/configure#denylist) can be used to restrict network access for self-hosted runners. | ||
|
|
||
| This can be employed to prevent self-hosted runners from accessing the network on the Juju machine. Generally, all IPv4 local addresses should be included in the denylist: | ||
|
|
||
| - 0.0.0.0/8 | ||
| - 10.0.0.0/8 | ||
| - 100.64.0.0/10 | ||
| - 127.0.0.0/8 | ||
| - 169.254.0.0/16 | ||
| - 172.16.0.0/12 | ||
| - 192.0.0.0/24 | ||
| - 192.0.2.0/24 | ||
| - 192.88.99.0/24 | ||
| - 192.168.0.0/16 | ||
| - 198.18.0.0/15 | ||
| - 198.51.100.0/24 | ||
| - 203.0.113.0/24 | ||
| - 224.0.0.0/4 | ||
| - 233.252.0.0/24 | ||
| - 240.0.0.0/4 | ||
|
|
||
| Additionally, include any IPv4 address or CIDR block that the runner should not have access to on the denylist. |
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,21 @@ | ||
| # How to comply with repository policies | ||
|
|
||
| The charm enforces a set of best practice GitHub repository settings. Self-hosted runners managed by the charm will not run jobs on repositories not compliant with the practices. This will be opt-in in the future. | ||
|
|
||
| The repository settings are enforced with this [Python library](https://github.com/canonical/repo-policy-compliance). The rules enforced are different depending on how the GitHub Actions workflow is triggered. The details can be found in the README. | ||
|
|
||
| In this guide, a recommended set of policies will be presented, but any set repository settings that passes the [Python library](https://github.com/canonical/repo-policy-compliance) checks will work with the self-hosted runners managed by this charm. | ||
|
|
||
| ## Recommended policy | ||
|
|
||
| - For outside collaborators the permission should be set to read. See [here](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/managing-teams-and-people-with-access-to-your-repository#changing-permissions-for-a-team-or-person) for instructions to change collaborator permissions. Outside collaborators will still be able to contribute with pull requests, but reviews will be needed. Details in a later section. | ||
| - Create the following branch protection rules, with the instructions [here](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/managing-a-branch-protection-rule#creating-a-branch-protection-rule): | ||
| - branch name pattern matching only the default branch of the repository, such as `main`, with the follow enabled: | ||
| - `Dismiss stale pull request approvals when new commits are pushed` | ||
| - `Do not allow bypassing the above settings` | ||
|
|
||
| With these settings, the common workflow of creating branches with pull requests and merging to the default branch is supported. Other GitHub Actions workflow triggers such as workflow_dispatch, push, and schedule are supported as well. | ||
|
|
||
| ### Working with outside collaborators | ||
|
|
||
| Contributions from outside collaborators (in the case where a repository is public) need to be handled slightly differently. As such, this charm requires pull requests by outside collaborators to be reviewed by someone with `write` permission or above. Once the review is completed, the reviewer should add a comment including the following string: `/canonical/self-hosted-runners/run-workflows <commit SHA>`, where `<commit SHA>` is the commit SHA of the approved commit. Once posted, the self-hosted runners will run the workflow for this commit. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| # Actions | ||
|
|
||
| See [Actions](https://charmhub.io/github-runner/actions). | ||
| See [Actions](https://charmhub.io/github-runner/actions). |
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,3 +1,3 @@ | ||
| # Configurations | ||
|
|
||
| See [Configure](https://charmhub.io/github-runner/configure). | ||
| See [Configure](https://charmhub.io/github-runner/configure). |
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.
Uh oh!
There was an error while loading. Please reload this page.