Skip to content

Commit be37179

Browse files
committed
Init
0 parents  commit be37179

File tree

8 files changed

+555
-0
lines changed

8 files changed

+555
-0
lines changed

.github/workflows/build.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build Image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
jobs:
8+
build-image:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Login to GitHub Container Registry
14+
uses: docker/login-action@v1
15+
with:
16+
registry: ghcr.io
17+
username: knatnetwork
18+
password: ${{ secrets.GITHUB_TOKEN }}
19+
20+
- name: Login to Docker Hub
21+
uses: docker/login-action@v1
22+
with:
23+
username: knatnetwork
24+
password: ${{ secrets.DOCKERHUB_PASSWD }}
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v1
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v1
31+
32+
- name: Login to Docker Hub
33+
uses: docker/login-action@v1
34+
with:
35+
username: knatnetwork
36+
password: ${{ secrets.DOCKERHUB_PASSWD }}
37+
38+
- name: Cache Docker layers
39+
uses: actions/cache@v3
40+
with:
41+
path: /tmp/.buildx-cache
42+
key: ${{ runner.os }}-buildx-${{ github.sha }}
43+
restore-keys: |
44+
${{ runner.os }}-buildx
45+
46+
- name: Build and push ARM64 Version
47+
uses: docker/build-push-action@v2
48+
with:
49+
context: .
50+
platforms: linux/arm64,linux/amd64
51+
push: true
52+
tags: |
53+
ghcr.io/knatnetwork/github-runner-kms
54+
knatnetwork/github-runner-kms
55+
56+
cache-from: type=local,src=/tmp/.buildx-cache
57+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
58+
59+
- name: Move cache
60+
run: |
61+
rm -rf /tmp/.buildx-cache
62+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
config.json

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:16.13.1-alpine3.14
2+
3+
USER root
4+
5+
WORKDIR /usr/src/app
6+
7+
COPY package*.json ./
8+
9+
RUN npm ci
10+
11+
COPY . .
12+
13+
EXPOSE 3000
14+
15+
CMD ["node","index.js"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# GitHub Runner KMS
2+
3+
The fake KMS that dynamically generate Runner registration token from PAT, without the use of PAT inside Runner container.
4+
5+
Usage can be seen on https://github.com/knatnetwork/github-runner.

config.json.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"cloudflare": "ghp_bFLPOxxxxxxxxxxxxxxxxxxxxxxx",
3+
"rust-lang": "ghp_JGIGxxxxxxxxxxxxxxxxxxxOij4"
4+
}

index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const express = require('express')
2+
const app = express()
3+
const axios = require('axios');
4+
const org_pat_map = require('./config.json')
5+
const port = 3000
6+
7+
app.get('/repo/:github_repo_owner/:github_repo_name/registration-token', (req, res) => {
8+
const registration_token_url= `https://api.github.com/repos/${req.params.github_repo_owner}/${req.params.github_repo_name}/actions/runners/registration-token`
9+
const github_pat = org_pat_map[`${req.params.github_repo_owner}`]
10+
const headers = {
11+
'Authorization': `token ${github_pat}`
12+
}
13+
axios.post(registration_token_url,{},{headers: headers})
14+
.then((github_res) => {
15+
res.send(github_res['data']['token'])
16+
})
17+
})
18+
19+
app.get('/repo/:github_repo_owner/:github_repo_name/remove-token', (req, res) => {
20+
const remove_token_url= `https://api.github.com/repos/${req.params.github_repo_owner}/${req.params.github_repo_name}/actions/runners/remove-token`
21+
console.log(remove_token_url)
22+
const github_pat = org_pat_map[`${req.params.github_repo_owner}`]
23+
const headers = {
24+
'Authorization': `token ${github_pat}`
25+
}
26+
axios.post(remove_token_url,{},{headers: headers})
27+
.then((github_res) => {
28+
res.send(github_res['data']['token'])
29+
})
30+
})
31+
32+
app.get('/:github_org_name/registration-token', (req, res) => {
33+
const registration_token_url= `https://api.github.com/orgs/${req.params.github_org_name}/actions/runners/registration-token`
34+
const github_pat = org_pat_map[`${req.params.github_org_name}`]
35+
const headers = {
36+
'Authorization': `token ${github_pat}`
37+
}
38+
axios.post(registration_token_url,{},{headers: headers})
39+
.then((github_res) => {
40+
res.send(github_res['data']['token'])
41+
})
42+
})
43+
44+
app.get('/:github_org_name/remove-token', (req, res) => {
45+
const remove_token_url= `https://api.github.com/orgs/${req.params.github_org_name}/actions/runners/remove-token`
46+
const github_pat = org_pat_map[`${req.params.github_org_name}`]
47+
const headers = {
48+
'Authorization': `token ${github_pat}`
49+
}
50+
axios.post(remove_token_url,{},{headers: headers})
51+
.then((github_res) => {
52+
res.send(github_res['data']['token'])
53+
})
54+
})
55+
56+
app.listen(3000);

0 commit comments

Comments
 (0)