01 The kcp Server
When we're done here, we'll have a host running the socialweb-computer gateway, one tenant cluster at Ready, nodes sized for the job, and a runner credential in hand. Nothing here requires GitLab.
Read README.md first. The tenant apiserver binds loopback on this host, so GitLab has to run here too.
Contents
- 1 Run the Gateway
- 2 Tenant Cluster
- 3 Node Sizing
- 4 Minting Runner Credentials
- 5 Tenant Cluster RBAC
- Values for Runner Setup
- Separate GitLab Hosts
1 Run the Gateway
The gateway runs the socialweb-computer binary under its own lingering account (socialweb on the production host). Install it with scripts/deploy.sh:
BINARY=<path to socialweb-computer> SHA256=<sha256> SSH_KEY=~/.ssh/id_ed25519_no_password \
GATEWAY_ENV_FILE=~/.tmp/deploy/gateway.env GATEWAY_SPEC_FILE=~/.tmp/deploy/gateway-spec.yaml \
scripts/deploy.sh
deploy.sh runs socialweb-computer install gateway on the first run and upgrade on later runs, then waits until the gateway answers /api/config. Verify the service as that account:
systemctl --user status socialweb-computer-gateway.service
curl -fsS http://127.0.0.1:8788/api/config
2 Tenant Cluster
A cluster is a control plane that exists before its first node, and nodes are only rented when a Pod needs one. List the clusters and look up the cluster URL:
kubectl --kubeconfig <admin> get clusters
kubectl --kubeconfig <admin> get cluster <name> -o jsonpath='{.status.url}'
<admin> is the kcp admin kubeconfig, set in the adminKubeconfig field of the gateway's gateway.json. It stays with the provider and is never given to a runner. The returned URL is https://127.0.0.1:<leased port>, with one port per cluster. Use it for the runner's host and when signing the runner's certificate.
3 Node Sizing
Nodes boot with 2 vCPU and 2048 MiB, which is enough for a probe but too small for a toolchain. Those values come from vcpu and memMiB in the manifest of the guest image booted by the bidder, so changing either means building a new image.
Root Filesystem Space
Job images and build outputs go into the node's root filesystem, where containerd stores layers. If it fills up, image pulls fail and the Pod never starts:
failed to pull and unpack image ... no space left on device
Size the image's root filesystem to hold both the toolchain and its layers. Staging a large file into the image doesn't work because mkfs.ext4 -d rejects files of about 2 GiB or more with Ext2 file too big. Pull anything that large inside the guest at run time instead (see 03).
State Directory on Disk
Node disks and root filesystems are large files. When /tmp is a tmpfs backed by RAM, point the state directory to real disk on the host:
TMPDIR=/var/tmp/kcp
If the state directory can't hold a node's disks, the node fails partway through boot with a full filesystem instead of failing up front with a configuration error.
Host Checks
Check the host before booting any nodes:
socialweb-computer check-host -role gateway -state-dir <state dir>
This prints one line per check with its fix and exits 1 when any check fails (docs/host-contract.md).
4 Minting Runner Credentials
A runner authenticates to the tenant apiserver with a client certificate signed by that cluster's ClientCA. Each credential is only valid against that cluster.
Do not use the superuser.
system:admininsystem:mastersis cluster-admin on the tenant cluster and bypasses all the RBAC rules below.
Mint a scoped credential:
SOCIALWEB_TENANTCREDENTIAL_STATE_DIR=/var/lib/socialweb \
SOCIALWEB_TENANTCREDENTIAL_CLUSTER=ci \
SOCIALWEB_TENANTCREDENTIAL_SERVER="$(kubectl --kubeconfig <admin> get cluster ci -o jsonpath='{.status.url}')" \
SOCIALWEB_TENANTCREDENTIAL_COMMON_NAME=gitlab-runner \
SOCIALWEB_TENANTCREDENTIAL_ORGANIZATIONS=gitlab-runner \
SOCIALWEB_TENANTCREDENTIAL_OUT_DIR=/etc/gitlab-runner/tenant-ci \
SOCIALWEB_TENANTCREDENTIAL_VALID_FOR=720h \
socialweb-computer internal tenantcredential
This writes three files at mode 0600:
| File | Purpose |
|---|---|
ca.crt | Cluster serving CA presented by the apiserver at that URL |
tls.crt | Runner client cert. CommonName is the username, and Organizations are the groups. |
tls.key | Private key |
VALID_FOR is optional and defaults to the mint's own validity. Because there's no revocation path, a credential's lifetime is how long a leaked copy stays valid. Move the old files aside first when rotating credentials, because the tool refuses to overwrite them.
A scoped identity can only come from the ClientCA on disk. The OpenBao-backed path's PKI role pins the organization to system:masters, so a rejected COMMON_NAME or ORGANIZATIONS comes from that restriction even if it looks like a typo. In Go, the scoped entry point is clusterprovider.MintTenantCredentialForClusterAs, which signs directly and bypasses the vault.
5 Tenant Cluster RBAC
Apply this manifest to the tenant cluster. Create the namespace first because the runner doesn't create it:
kubectl --kubeconfig <tenant-admin> apply -f - <<'YAML'
apiVersion: v1
kind: Namespace
metadata:
name: gitlab-runner
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: gitlab-runner
rules:
- apiGroups: [""]
resources: ["pods", "pods/exec", "pods/attach", "pods/log"]
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["secrets", "configmaps", "services", "serviceaccounts", "events", "persistentvolumeclaims"]
verbs: ["create", "delete", "get", "list", "watch", "update"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["create", "delete", "get", "list", "update"]
- apiGroups: ["policy"]
resources: ["poddisruptionbudgets"]
verbs: ["create", "delete", "get", "list", "update"]
- apiGroups: ["scheduling.k8s.io"]
resources: ["priorityclasses"]
verbs: ["get", "create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: gitlab-runner
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: gitlab-runner
subjects:
- kind: Group
name: gitlab-runner
apiGroup: rbac.authorization.k8s.io
YAML
Group has to match the ORGANIZATIONS value from step 4, or every job fails with a 403 that looks like a broken runner. priorityclasses is cluster-scoped, so a namespaced Role can't grant it. Both apps/deployments and scheduling.k8s.io/priorityclasses are only needed by the pre-warmed pause pods in 03.
Verify both the certificate subject and RBAC permissions before blaming the runner:
openssl x509 -in /etc/gitlab-runner/tenant-ci/tls.crt -noout -subject
# subject=O = gitlab-runner, CN = gitlab-runner
kubectl --kubeconfig <tenant-admin> auth can-i create pods \
--namespace gitlab-runner --as=gitlab-runner --as-group=gitlab-runner
# yes
The openssl output confirms the O and CN fields on the cert, and auth can-i confirms the gitlab-runner group can create pods in the gitlab-runner namespace.
Values for Runner Setup
02 needs these values from this setup:
| Setting | Value |
|---|---|
| Apiserver URL | https://127.0.0.1:<leased port> |
| Runner credentials | /etc/gitlab-runner/tenant-ci/{ca.crt,tls.crt,tls.key} |
| Group name | gitlab-runner |
| Namespace | gitlab-runner |
Separate GitLab Hosts
Running GitLab on its own VM or another host doesn't work because the tenant apiserver binds loopback on the kcp host. The runner reports connection timeouts, and no runner configuration fixes it.
Supporting a separate host requires the kcp host to publish an authenticated front for the apiserver, which is a trust-boundary change. The gateway refuses to bind anything except loopback, and the entrypoint publishes one port whose only upstream is the gateway.