From 2b4f4a2fb935f38e2dfc3add701d41528bdbb571 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Fri, 27 Nov 2026 22:27:39 +1100 Subject: [PATCH] Add iuclabs-build runner scale set (#610) IUCLabs rpmbuilder and container repos need a runner that can build images and publish to artifactapi, without opening that egress to every dind job. - Adds the `iuclabs-build` scale set (copy of `iuclabs-dind`, `RUNNER_MODE=build`, same min/max runners) - Allows egress to traefik-internal on 443/80 on top of the dind rules - Mounts `vault-ca-cert` as the dind registry CA for artifactapi.k8s.syd1.au.unkin.net - `job-started.sh` restricts build mode to IUCLabs/rpmbuilder and the listed container-* repos, then applies the usual event checks - Extends `ci/test-runner-hooks.sh` with build-mode cases Reviewed-on: https://git.unkin.net/unkin/argocd-apps/pulls/610 Co-authored-by: unkin-agent Co-committed-by: unkin-agent --- .../iuclabs-build/kustomization.yaml | 7 + .../iuclabs-build/networkpolicy.yaml | 59 +++++++ .../components/iuclabs-build/scaleset.yaml | 165 ++++++++++++++++++ apps/base/iuclabs-runners/job-started.sh | 6 + apps/base/iuclabs-runners/kustomization.yaml | 1 + ci/test-runner-hooks.sh | 12 ++ 6 files changed, 250 insertions(+) create mode 100644 apps/base/iuclabs-runners/components/iuclabs-build/kustomization.yaml create mode 100644 apps/base/iuclabs-runners/components/iuclabs-build/networkpolicy.yaml create mode 100644 apps/base/iuclabs-runners/components/iuclabs-build/scaleset.yaml diff --git a/apps/base/iuclabs-runners/components/iuclabs-build/kustomization.yaml b/apps/base/iuclabs-runners/components/iuclabs-build/kustomization.yaml new file mode 100644 index 0000000..3650eda --- /dev/null +++ b/apps/base/iuclabs-runners/components/iuclabs-build/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-build/networkpolicy.yaml b/apps/base/iuclabs-runners/components/iuclabs-build/networkpolicy.yaml new file mode 100644 index 0000000..9dd1115 --- /dev/null +++ b/apps/base/iuclabs-runners/components/iuclabs-build/networkpolicy.yaml @@ -0,0 +1,59 @@ +--- +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: egress-iuclabs-build + namespace: iuclabs-runners +spec: + podSelector: + matchLabels: + runners.unkin.net/scale-set: iuclabs-build + 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 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 + # container-base fetches the internal CA RPM over http from artifactapi before TLS trust exists + - protocol: TCP + port: 80 diff --git a/apps/base/iuclabs-runners/components/iuclabs-build/scaleset.yaml b/apps/base/iuclabs-runners/components/iuclabs-build/scaleset.yaml new file mode 100644 index 0000000..566dfcc --- /dev/null +++ b/apps/base/iuclabs-runners/components/iuclabs-build/scaleset.yaml @@ -0,0 +1,165 @@ +--- +apiVersion: actions.github.com/v1alpha1 +kind: AutoscalingRunnerSet +metadata: + name: iuclabs-build + 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-build + minRunners: 0 + maxRunners: 4 + template: + metadata: + labels: + runners.unkin.net/scale-set: iuclabs-build + spec: + serviceAccountName: runner + automountServiceAccountToken: false + restartPolicy: Never + securityContext: + runAsNonRoot: true + runAsUser: 1001 + runAsGroup: 1001 + supplementalGroups: + - 123 + seccompProfile: + type: RuntimeDefault + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + runners.unkin.net/scale-set: iuclabs-build + initContainers: + - name: init-dind-externals + image: ghcr.io/actions/actions-runner:2.338.2 + command: ["cp"] + args: ["-r", "/home/runner/externals/.", "/home/runner/tmpDir/"] + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + resources: + requests: + cpu: 100m + memory: 64Mi + ephemeral-storage: 100Mi + limits: + cpu: 500m + memory: 256Mi + ephemeral-storage: 1Gi + volumeMounts: + - name: dind-externals + mountPath: /home/runner/tmpDir + - name: dind + image: docker.io/library/docker:29.9.3-dind + args: + - dockerd + - --host=unix:///var/run/docker.sock + - --group=$(DOCKER_GROUP_GID) + env: + - name: DOCKER_GROUP_GID + value: "123" + restartPolicy: Always + startupProbe: + exec: + command: + - docker + - info + initialDelaySeconds: 0 + failureThreshold: 24 + periodSeconds: 5 + securityContext: + privileged: true + runAsNonRoot: false + runAsUser: 0 + runAsGroup: 0 + resources: + requests: + cpu: 1 + memory: 1Gi + ephemeral-storage: 10Gi + limits: + cpu: 2 + memory: 4Gi + ephemeral-storage: 50Gi + volumeMounts: + - name: work + mountPath: /home/runner/_work + - name: dind-sock + mountPath: /var/run + - name: dind-externals + mountPath: /home/runner/externals + - name: dind-storage + mountPath: /var/lib/docker + - name: vault-ca-cert + mountPath: /etc/docker/certs.d/artifactapi.k8s.syd1.au.unkin.net/ca.crt + subPath: ca.crt + readOnly: true + 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_MODE + value: build + - name: DOCKER_HOST + value: unix:///var/run/docker.sock + - name: RUNNER_WAIT_FOR_DOCKER_IN_SECONDS + value: "120" + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + resources: + requests: + cpu: 1 + memory: 512Mi + ephemeral-storage: 2Gi + limits: + cpu: 2 + memory: 2Gi + ephemeral-storage: 20Gi + volumeMounts: + - name: work + mountPath: /home/runner/_work + - name: dind-sock + mountPath: /var/run + - name: hooks + mountPath: /hooks + readOnly: true + - name: vault-ca-cert + mountPath: /etc/vault-ca + readOnly: true + volumes: + - name: work + emptyDir: + sizeLimit: 20Gi + - name: dind-sock + emptyDir: {} + - name: dind-externals + emptyDir: {} + - name: dind-storage + emptyDir: + sizeLimit: 30Gi + - 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 925b04d..7b96f3b 100755 --- a/apps/base/iuclabs-runners/job-started.sh +++ b/apps/base/iuclabs-runners/job-started.sh @@ -19,6 +19,12 @@ case "${RUNNER_MODE:-}" in *) refuse "infra runners only run IUCLabs terraform repos, got '${GITHUB_REPOSITORY:-}'" ;; esac ;; + build) + case "${GITHUB_REPOSITORY:-}" in + IUCLabs/rpmbuilder | IUCLabs/container-agent-base | IUCLabs/container-agent-dev | IUCLabs/container-agent-infra | IUCLabs/container-base | IUCLabs/container-gobuilder | IUCLabs/container-opentofu | IUCLabs/container-postfix | IUCLabs/container-rpmbuilder | IUCLabs/container-tea) ;; + *) refuse "build runners only run IUCLabs rpmbuilder and container repos, got '${GITHUB_REPOSITORY:-}'" ;; + esac + ;; release) [ "${event}" = push ] || refuse "release runners only run tag pushes" ref=$(jq -r '.ref' "${GITHUB_EVENT_PATH}") || refuse "event payload unreadable" diff --git a/apps/base/iuclabs-runners/kustomization.yaml b/apps/base/iuclabs-runners/kustomization.yaml index 02c4d76..8c1a992 100644 --- a/apps/base/iuclabs-runners/kustomization.yaml +++ b/apps/base/iuclabs-runners/kustomization.yaml @@ -14,6 +14,7 @@ components: - components/iuclabs-infra - components/iuclabs-release - components/iuclabs-dind + - components/iuclabs-build generatorOptions: disableNameSuffixHash: true diff --git a/ci/test-runner-hooks.sh b/ci/test-runner-hooks.sh index 31d3b5d..c6c2afd 100755 --- a/ci/test-runner-hooks.sh +++ b/ci/test-runner-hooks.sh @@ -72,4 +72,16 @@ check 1 infra push push.json check 1 infra push - IUCLabs/terraform-vault check 0 default push push.json IUCLabs/terraform-vault +for r in rpmbuilder container-agent-base container-agent-dev container-agent-infra container-base container-gobuilder container-opentofu container-postfix container-rpmbuilder container-tea; do + check 0 build push push.json "IUCLabs/$r" + check 0 build pull_request pr-same-repo.json "IUCLabs/$r" + check 1 build pull_request pr-fork-none.json "IUCLabs/$r" + check 1 build issue_comment issue-comment.json "IUCLabs/$r" +done +for r in IUCLabs/terraform-git IUCLabs/container-evil iuclabs/rpmbuilder evil/rpmbuilder IUCLabs/rpmbuilder-x "IUCLabs/rpmbuilder "; do + check 1 build push push.json "$r" +done +check 1 build push push.json +check 1 build push - IUCLabs/rpmbuilder + exit "$fail"