You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
github_organization = "<the_organization_name>" // Provide the name of the GitHub Organization
28
+
github_runner_group_name = "Default" // The name of the GitHub Organization runner group
29
+
github_runner_group_id = 1 // (optional - but recommended) The GitHub Organization runner group ID. For an explanation why it't recommended to provide a value see README.md
30
+
github_runner_prefix = "runner" // The VM instance name starts with this prefix (a random string is added as a suffix)
31
+
machine_type = "c2d-highcpu-8" // The machine type of the VM instance
31
32
}
32
33
33
34
output "runner_webhook_config" {
@@ -74,21 +75,22 @@ Have a look at the [variables.tf](./variables.tf) file how to further configure
74
75
> [!TIP]
75
76
> To find the cheapest VM machine_type use this [table](https://gcloud-compute.com/instances.html) and sort by Spot instance cost. But remember that the price varies depending on the region.
76
77
77
-
## How it works
78
+
## What runner registration procedures to choose
78
79
79
-
1. As soon as a new GitHub workflow job is queued, the GitHub webhook event "Workflow jobs" invokes the Cloud Run [container](https://github.com/Privatehive/gcp-hosted-github-runner/pkgs/container/github-runner-autoscaler) with path `/webhook`
80
-
2. The Cloud run enqueues a "create-vm" Cloud task. This is necessary, because the timeout of a GitHub webhook is only 10 seconds but to start a VM instance takes about 1 minute.
81
-
3. The Cloud task invokes the Cloud Run path `/create_vm`.
82
-
4. The Cloud Run creates a runner registration token (using PAT from Secret Manager).
83
-
5. The Cloud Run creates the VM instance from the instance template (preemtible spot VM instance by default) and provides it with the runner registration token via custom metadata attribute.
84
-
6. Using the registration token the VM registers itself as an **ephemeral** runner in the runner group and immediately starts working on the workflow job.
85
-
7. As soon as the workflow job completed, the GitHub webhook event "Workflow jobs" invokes the Cloud Run again.
86
-
8. The Cloud run enqueues a "delete-vm" Cloud task. This is necessary, because the timeout of a GitHub webhook is only 10 seconds but to delete a VM instance takes about 1 minute.
87
-
9. The Cloud task invokes the Cloud Run path `/delete_vm`.
88
-
10. The Cloud Run deletes the VM instance.
80
+
There are two possible registration procedures for ephemeral runner. Via a **registration token** or via **jit-config**.
81
+
The **jit-config** is preferred over the **registration token**. *Why?*
89
82
90
-
> [!NOTE]
91
-
> The runner is run by the unprivileged user `agent` with the uid `10000` and gid `10000`
83
+
When using a registration token, the VM itself must carry out the registration process. This means that it must be equipped with the token. The registration token can be used **several times** until it expires (after 1 hour). If a malicious workflow is executed on the runner, the registration token can be extracted from the VM metadata attributes and a malicious runner controlled by an attacker can be registered within your runner group. This malicious runner may then be able to read out workflow secrets. If using the jit-config the registration process is carried out by the Cloud Run **before** the VM instance is started.
84
+
85
+
The case distinction as to which registration procedure is carried out depends on whether the variable `github_runner_group_id` is provided or not. If provided the preferred jit-config registration is performed; if it is not provided the token registration is performed.
86
+
87
+
> [!TIP]
88
+
> To check which registration procedure will be performed print the module output `runner_registration_procedure`.
89
+
90
+
## Runner features
91
+
92
+
* Executed by unprivileged user with name `agent` with the uid `10000` and gid `10000`
93
+
* Provides docker-daemon and docker-buildx
92
94
93
95
## Expected Cost
94
96
@@ -114,7 +116,24 @@ Standard persistent disk 20 GiB used ~ $0.0011
114
116
$0.053
115
117
```
116
118
117
-
Overall, only the compute instance accounts for the majority of the costs.
119
+
Overall, only the compute instance accounts for the "majority" of the costs.
120
+
121
+
## How it works
122
+
123
+
1. As soon as a new GitHub workflow job is queued, the GitHub webhook event "Workflow jobs" invokes the Cloud Run [container](https://github.com/Privatehive/gcp-hosted-github-runner/pkgs/container/github-runner-autoscaler) with path `/webhook`
124
+
2. The Cloud run enqueues a "create-vm" Cloud task. This is necessary, because the timeout of a GitHub webhook is only 10 seconds but to start a VM instance takes about 1 minute.
125
+
3. The Cloud task invokes the Cloud Run path `/create_vm`.
126
+
4. Depending if `github_runner_group_id` is provided:
127
+
* If *not provided*: Cloud Run creates a runner [registration token](https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization) (using PAT from Secret Manager).
128
+
* If *provided*: Cloud Run creates a [jit-config](https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-configuration-for-a-just-in-time-runner-for-an-organization) (using PAT from Secret Manager). The runner is then already registered (but marked as offline).
129
+
5. The Cloud Run creates the VM instance from the instance template (preemtible spot VM instance by default) and provides it with the runner registration token **or** with the jit-config via custom metadata attribute.
130
+
6. Depending if `github_runner_group_id` is provided:
131
+
* If *not provided*: Using the registration token the VM registers itself as an **ephemeral** runner in the runner group and immediately starts working on the workflow job.
132
+
* If *provided*: The runner is already registered and immediately starts working on the workflow job.
133
+
7. As soon as the workflow job completed, the GitHub webhook event "Workflow jobs" invokes the Cloud Run again.
134
+
8. The Cloud run enqueues a "delete-vm" Cloud task. This is necessary, because the timeout of a GitHub webhook is only 10 seconds but to delete a VM instance takes about 1 minute.
135
+
9. The Cloud task invokes the Cloud Run path `/delete_vm`.
136
+
10. The Cloud Run deletes the VM instance.
118
137
119
138
## Troubleshooting
120
139
@@ -132,7 +151,7 @@ Error applying IAM policy for cloudrun service "v1/projects/github-spot-runner/l
132
151
#### The VM Instance immediately stops after it was created without processing a workflow job
133
152
134
153
The VM will shoutdown itself if the registration at the GitHub runner group fails. This can be caused by:
135
-
* An invalid/expired runner registration token.
154
+
* An invalid/expired runner registration token (if token registration is performed).
136
155
* A typo in the GitHub Organization name. Check the Terraform variable `github_organization` for typos.
137
156
* A not existing GitHub runner group within the Organization. Check the Terraform variable `github_runner_group` for typos.
#### New VM Instance not starting (but a lot of instances are already running)
145
164
146
165
You exceeded your projects vCPU limit for the machine type in the region or for all regions. You may find an error log message in the Cloud Run logs stating `Machine Type vCPU quota exceeded for region`. Request a quota increase from google customer support for the project.
0 commit comments