Skip to content

Commit 6269149

Browse files
committed
self-hosted-runner: allow running in private repositories
GitHub's documentation provides a stern warning against registering self-hosted runners on public repositories: https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/about-self-hosted-runners#self-hosted-runner-security To counter that, we specifically spin up ephemeral self-hosted runners in `git-for-windows/git-for-windows-automation` and have automation to prevent unauthorized people from trying to play games with our runners. However, for testing in separate repositories, this strategy is utterly inconvenient. And unnecessary, when running in a private repository anyway. Except that we need to have a public URL for the post-deployment script. So let's work around that by hard-coding the CI token into that URL. This should be good enough, especially when we scrub the token from the logs (manually, if necessary). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 15ecd92 commit 6269149

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

.github/workflows/create-azure-self-hosted-runners.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,21 @@ jobs:
126126
# https://github.com/actions/runner/issues/475
127127
- name: Generate Actions Runner token and registration URL
128128
run: |
129+
# We need to URL-encode the user name because it usually is a GitHub App, which means that
130+
# it has the suffix `[bot]`. If un-encoded, this would cause a cURL error "bad range in URL"
131+
# because it would mistake this for an IPv6 address or something like that.
132+
user_pwd="$(jq -n \
133+
--arg user '${{ github.actor }}' \
134+
--arg pwd '${{ secrets.GITHUB_TOKEN }}' \
135+
'$user | @uri + ":" + $pwd')"
129136
case "$ACTIONS_RUNNER_SCOPE" in
130137
"org-level")
131-
ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/actions/runners/registration-token"
132-
ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG"
138+
ACTIONS_API_URL="https://$user_pwd@api.github.com/repos/$ACTIONS_RUNNER_ORG/actions/runners/registration-token"
139+
ACTIONS_RUNNER_REGISTRATION_URL="https://$user_pwd@github.com/$ACTIONS_RUNNER_ORG"
133140
;;
134141
"repo-level")
135-
ACTIONS_API_URL="https://api.github.com/repos/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO/actions/runners/registration-token"
136-
ACTIONS_RUNNER_REGISTRATION_URL="https://github.com/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO"
142+
ACTIONS_API_URL="https://$user_pwd@api.github.com/repos/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO/actions/runners/registration-token"
143+
ACTIONS_RUNNER_REGISTRATION_URL="https://$user_pwd@github.com/$ACTIONS_RUNNER_ORG/$ACTIONS_RUNNER_REPO"
137144
;;
138145
*)
139146
echo "Unsupported runner scope: $ACTIONS_RUNNER_SCOPE"
@@ -225,7 +232,7 @@ jobs:
225232
if: always()
226233
env:
227234
CUSTOM_SCRIPT_OUTPUT: ${{ steps.deploy-arm-template.outputs.customScriptInstanceView }}
228-
run: echo "$CUSTOM_SCRIPT_OUTPUT" | jq -r '.substatuses[0].message'
235+
run: echo "$CUSTOM_SCRIPT_OUTPUT" | jq -r '.substatuses[0].message' | sed 's/${{ secrets.GITHUB_TOKEN }}/***/g'
229236

230237
- name: Deallocate the VM for later use
231238
if: env.DEALLOCATE_IMMEDIATELY == 'true'

0 commit comments

Comments
 (0)