diff --git a/apps/base/iuclabs-runners/components/iuclabs-release/kustomization.yaml b/apps/base/iuclabs-runners/components/iuclabs-release/kustomization.yaml new file mode 100644 index 0000000..3650eda --- /dev/null +++ b/apps/base/iuclabs-runners/components/iuclabs-release/kustomization.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: kustomize.config.k8s.io/v1alpha1 +kind: Component + +resources: + - scaleset.yaml + - networkpolicy.yaml diff --git a/apps/base/iuclabs-runners/components/iuclabs-release/networkpolicy.yaml b/apps/base/iuclabs-runners/components/iuclabs-release/networkpolicy.yaml new file mode 100644 index 0000000..ae60920 --- /dev/null +++ b/apps/base/iuclabs-runners/components/iuclabs-release/networkpolicy.yaml @@ -0,0 +1,56 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: egress-iuclabs-release + namespace: iuclabs-runners +spec: + podSelector: + matchLabels: + runners.unkin.net/scale-set: iuclabs-release + policyTypes: + - Egress + egress: + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: + - 10.0.0.0/8 + - 172.16.0.0/12 + - 192.168.0.0/16 + - 198.18.0.0/15 + - 0.0.0.0/8 + - 100.64.0.0/10 + - 127.0.0.0/8 + - 169.254.0.0/16 + - 224.0.0.0/4 + - 240.0.0.0/4 + ports: + - protocol: TCP + port: 443 + # vault.service.consul servers, from `dig vault.service.consul` + - to: + - ipBlock: + cidr: 198.18.25.78/32 + - ipBlock: + cidr: 198.18.26.197/32 + - ipBlock: + cidr: 198.18.27.116/32 + - ipBlock: + cidr: 198.18.28.248/32 + - ipBlock: + cidr: 198.18.29.92/32 + ports: + - protocol: TCP + port: 8200 + # artifactapi is only exposed with TLS via traefik-internal; kube-proxy DNATs its LB IP to these pods + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: traefik-system + podSelector: + matchLabels: + app.kubernetes.io/instance: traefik-internal-traefik-system + ports: + - protocol: TCP + port: 443 diff --git a/apps/base/iuclabs-runners/components/iuclabs-release/scaleset.yaml b/apps/base/iuclabs-runners/components/iuclabs-release/scaleset.yaml new file mode 100644 index 0000000..d1dfc27 --- /dev/null +++ b/apps/base/iuclabs-runners/components/iuclabs-release/scaleset.yaml @@ -0,0 +1,76 @@ +--- +apiVersion: actions.github.com/v1alpha1 +kind: AutoscalingRunnerSet +metadata: + name: iuclabs-release + namespace: iuclabs-runners + labels: + app.kubernetes.io/version: "0.15.1" + annotations: + actions.github.com/cleanup-manager-role-name: arc-manager + actions.github.com/cleanup-manager-role-binding: arc-manager +spec: + githubConfigUrl: https://github.com/IUCLabs + githubConfigSecret: github-app + runnerScaleSetName: iuclabs-release + minRunners: 0 + maxRunners: 2 + template: + metadata: + labels: + runners.unkin.net/scale-set: iuclabs-release + spec: + serviceAccountName: runner + automountServiceAccountToken: false + restartPolicy: Never + securityContext: + runAsNonRoot: true + runAsUser: 1001 + runAsGroup: 1001 + seccompProfile: + type: RuntimeDefault + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + runners.unkin.net/scale-set: iuclabs-release + containers: + - name: runner + image: ghcr.io/actions/actions-runner:2.338.2 + command: ["/home/runner/run.sh"] + env: + - name: ACTIONS_RUNNER_HOOK_JOB_STARTED + value: /hooks/job-started.sh + - name: NODE_EXTRA_CA_CERTS + value: /etc/vault-ca/ca.crt + - name: RUNNER_RELEASE_ONLY + value: "true" + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + resources: + requests: + cpu: 1 + memory: 512Mi + limits: + cpu: 2 + memory: 2Gi + volumeMounts: + - name: hooks + mountPath: /hooks + readOnly: true + - name: vault-ca-cert + mountPath: /etc/vault-ca + readOnly: true + volumes: + - name: hooks + configMap: + name: runner-hooks + defaultMode: 0555 + - name: vault-ca-cert + secret: + secretName: vault-ca-cert diff --git a/apps/base/iuclabs-runners/job-started.sh b/apps/base/iuclabs-runners/job-started.sh index b6cf911..ae2c2eb 100755 --- a/apps/base/iuclabs-runners/job-started.sh +++ b/apps/base/iuclabs-runners/job-started.sh @@ -11,6 +11,19 @@ refuse() { [ -r "${GITHUB_EVENT_PATH:-}" ] || refuse "event payload missing" jq -e 'type == "object"' "${GITHUB_EVENT_PATH}" >/dev/null 2>&1 || refuse "event payload unparseable" +case "${RUNNER_RELEASE_ONLY:-}" in + "") ;; + true) + [ "${event}" = push ] || refuse "release runners only run tag pushes" + ref=$(jq -r '.ref' "${GITHUB_EVENT_PATH}") || refuse "event payload unreadable" + case "${ref}" in + refs/tags/v*) exit 0 ;; + *) refuse "release runners only run v* tag pushes, got '${ref}'" ;; + esac + ;; + *) refuse "invalid RUNNER_RELEASE_ONLY" ;; +esac + case "${event}" in push | workflow_dispatch | schedule | merge_group | release) ;; pull_request) diff --git a/apps/base/iuclabs-runners/kustomization.yaml b/apps/base/iuclabs-runners/kustomization.yaml index f2eff16..8e39cd3 100644 --- a/apps/base/iuclabs-runners/kustomization.yaml +++ b/apps/base/iuclabs-runners/kustomization.yaml @@ -11,6 +11,7 @@ resources: components: - components/iuclabs-k8s + - components/iuclabs-release generatorOptions: disableNameSuffixHash: true diff --git a/ci/fixtures/runner-hooks/tag-push-nov.json b/ci/fixtures/runner-hooks/tag-push-nov.json new file mode 100644 index 0000000..3eb4b39 --- /dev/null +++ b/ci/fixtures/runner-hooks/tag-push-nov.json @@ -0,0 +1,3 @@ +{ + "ref": "refs/tags/release-1" +} diff --git a/ci/fixtures/runner-hooks/tag-push.json b/ci/fixtures/runner-hooks/tag-push.json new file mode 100644 index 0000000..13906f0 --- /dev/null +++ b/ci/fixtures/runner-hooks/tag-push.json @@ -0,0 +1,3 @@ +{ + "ref": "refs/tags/v1.2.3" +} diff --git a/ci/test-runner-hooks.sh b/ci/test-runner-hooks.sh index 64e78d5..9362413 100755 --- a/ci/test-runner-hooks.sh +++ b/ci/test-runner-hooks.sh @@ -6,13 +6,14 @@ fixtures=ci/fixtures/runner-hooks fail=0 check() { - local want=$1 event=$2 fixture=$3 got=0 - local -a env=(-u GITHUB_EVENT_NAME -u GITHUB_EVENT_PATH) + local want=$1 event=$2 fixture=$3 release=${4:-} got=0 + local -a env=(-u GITHUB_EVENT_NAME -u GITHUB_EVENT_PATH -u RUNNER_RELEASE_ONLY) + [ -z "$release" ] || env+=("RUNNER_RELEASE_ONLY=$release") [ "$event" = - ] || env+=("GITHUB_EVENT_NAME=$event") [ "$fixture" = - ] || env+=("GITHUB_EVENT_PATH=$fixtures/$fixture") env "${env[@]}" "$hook" >/dev/null 2>&1 || got=1 if [ "$got" -ne "$want" ]; then - echo "FAIL: $event $fixture exit=$got want=$want" >&2 + echo "FAIL: $event $fixture release=$release exit=$got want=$want" >&2 fail=1 fi } @@ -35,5 +36,17 @@ check 1 push - check 1 push missing.json check 1 push invalid.txt check 1 - push.json +check 0 push tag-push.json + +check 0 push tag-push.json true +check 1 push push.json true +check 1 push tag-push-nov.json true +for e in pull_request workflow_dispatch schedule merge_group release; do + check 1 "$e" tag-push.json true +done +check 1 pull_request pr-same-repo.json true +check 1 push - true +check 1 push invalid.txt true +check 1 push tag-push.json yes exit "$fail"