Token generation for Registering Self Hosted Github Runner via REST API

Motivation

w.r.t https://www.narenvadapalli.com/blog/self-hosted-github-runner-registration-process/, while registering a windows host as github self hosted runner, you need to generate a Token for registration.

This blog will take you through the process of generating the token, using Github REST API

Github Personal Access token (Classic) Generation

You Need to sign in to Github org account by clicking on https://github.com/settings/tokens.

The token that was used with config.cmd (REF: self-hosted-github-runner-registration-process) is a one time registration token and we would have to generate a new token for each new self hosted github runner. But fortunately, there seems to be the required API calls with github to generate the token, that would be valid for an hour

REF: https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization

1 gh classic access token repo and admin 2 gh classic access token repo and admin

Copy/backup the token for it to be used in the next step

3 gh classic access token repo and admin

Token Generation using Github's REST API for registering self hosted runner

Following would capture the Token in to a variable called $token when run in a Powershell.

Remember to replace the following in the command below with a Github Personal Access Token that has both repo and admin:org permissions

  • <<GITHUB_ACCESS_TOKEN_REDACTED>>
  • <<GITHUB_ORG>>
$token=$(Invoke-RestMethod -Method Post `
  -Uri https://api.github.com/orgs/<<GITHUB_ORG>>/actions/runners/registration-token `
  -Headers @{
    "Accept" = "application/vnd.github+json"
    "Authorization" = "Bearer <<GITHUB_ACCESS_TOKEN_REDACTED"
    "X-GitHub-Api-Version" = "2022-11-28"
  }).token

Print the token to check it

$token

Latest Blogposts

How to find a linux machine is a VM (Virtual Machine) or a Bare Metal

If you can SSH into a linux machine and want to find out if its baremetal or Virtual Machine

7 November 2023

Storing Github access token in git credential store

Using git credentials store the github access token to avoid the re-prompting of username and pwd

4 April 2023

Setting up a Self Hosted Github Runner

Explains how to setup a Github self hosted runner and register

20 March 2023

Managing the NodeJS versions on Windows

Node Version Manager (nvm) helps in managing multiple NodeJS versions

13 November 2022

Customizing the Powershell terminal with oh-my-posh

Instructions on customizing the terminal in powershell with oh-my-posh and winget

7 July 2022