Skip to content

Install the operational agent on the Mac mini

This is the platform side of ADR 0020, as amended by ADR 0022. The owner creates the identities and private files in task #1452; no credential belongs in Git. The operational agent runs in the namespace ops-agent of the one Lima VM k3s, owned by the standard macOS account agent-ops, next to the rootless CI runners in ci. Flux applies cluster/mac-mini/; the separate mac-mini runner is unaffected.

<checkout> below is a fresh, readable checkout of Skatzi/platform on main. The owner generates only the admin kubeconfig on their own Mac and copies it to /Users/agent-ops/.dr/kubeconfig (mode 0600); the talosconfig stays on the owner's Mac. Store the fine-grained GitHub token at /Users/agent-ops/.dr/github-token (mode 0600).

Before you start

Secrets

Run these as agent-ops. The silent prompts below read the private values from task #1452 for the ops-agent-credentials and harbor-pull Secrets without echoing them. The break-glass Secret holds only kubeconfig and github-token.

k() { limactl shell k3s sudo k3s kubectl "$@"; }
k get namespace ops-agent
# kubectl ... --dry-run=client only prints the Secret and reads no cluster; k applies it in the VM.
kubectl -n ops-agent create secret generic ops-agent-break-glass \
  --from-file=kubeconfig=$HOME/.dr/kubeconfig \
  --from-file=github-token=$HOME/.dr/github-token --dry-run=client -o yaml | k apply -f -
read -rs P; read -rs G; read -rs C     # Keycloak password of ops-agent, Gitea PAT, Claude token (nothing is echoed)
kubectl -n ops-agent create secret generic ops-agent-credentials \
  --from-file=password=<(printf %s "$P") --from-file=gitea_token=<(printf %s "$G") --from-file=claude_token=<(printf %s "$C") \
  --dry-run=client -o yaml | k apply -f -
read -rs H                             # the ops-agent-pull robot secret
kubectl -n ops-agent create secret docker-registry harbor-pull --docker-server=harbor.prod.skatzi.com \
  --docker-username='robot$skatzi+ops-agent-pull' --docker-password="$H" --dry-run=client -o yaml | k apply -f -
unset P G C H
# The release may have used up its install retries while the Secrets were missing:
# reset its failure count and reconcile now (what `flux reconcile hr --reset` does).
T=$(date +%s); k -n ops-agent annotate helmrelease ops-agent --overwrite \
  reconcile.fluxcd.io/requestedAt=$T reconcile.fluxcd.io/resetAt=$T
k -n ops-agent get helmrelease,deploy,cronjob,pvc,pods

The OCIRepository pins the chart version in cluster/mac-mini/ops-agent/oci-repository.yaml (Renovate bumps it); the image defaults to the same version. The HelmRelease enables the watchdog with N = 5 minutes and M = 60 minutes. Its code enforces a 30 minute cooldown per trigger, a cap of three sessions in six hours, and a 30 minute all-green reset. The ops-agent-dr local-path PVC holds /dr for the Deployment, watchdog CronJob and DR Jobs. The NetworkPolicy default-deny-ingress lets no pod connect to ops-agent (ADR 0022).

Access to the webshop cluster

The ops agent also maintains the webshop cluster (terraform/environments/hetzner-webshop-cluster). It gets the same cluster-admin rights there as on hetzner-mgmt, but through its own ServiceAccount kube-system/ops-agent and token Secret ops-agent-token (cluster/webshop/ops-agent-access.yaml, applied by Flux), not the Talos admin certificate: deleting ops-agent-token revokes it alone. As on hetzner-mgmt it gets no talosctl or Terraform access. The webshop cluster's API only accepts api_source_ips (the owner's home IP and hetzner-mgmt); the Mac mini reaches it from the home IP.

The owner adds it as context webshop to the break-glass kubeconfig. The default context stays hetzner-mgmt, so the host check and existing commands are unchanged; the agent uses kubectl --context webshop.

  1. On the owner's Mac (context admin@webshop), once Flux has created the token, build the file without printing the token:
umask 077; F=ops-agent-webshop.kubeconfig; CTX=admin@webshop
SERVER=$(kubectl config view --raw -o jsonpath='{.clusters[?(@.name=="webshop")].cluster.server}')
kubectl --context $CTX -n kube-system get secret ops-agent-token -o jsonpath='{.data.ca\.crt}' | base64 -d > ca.crt
KUBECONFIG=$F kubectl config set-cluster webshop --server="$SERVER" --certificate-authority=ca.crt --embed-certs >/dev/null
KUBECONFIG=$F kubectl config set-credentials ops-agent-webshop \
  --token="$(kubectl --context $CTX -n kube-system get secret ops-agent-token -o jsonpath='{.data.token}' | base64 -d)" >/dev/null
KUBECONFIG=$F kubectl config set-context webshop --cluster=webshop --user=ops-agent-webshop >/dev/null
KUBECONFIG=$F kubectl --context webshop get nodes   # webshop-controlplane-0 Ready
rm ca.crt
scp $F dunkagent@192.168.50.54:/tmp/ && rm $F
  1. On the Mac mini, merge it into the break-glass kubeconfig (keeping hetzner-mgmt as the current context), refresh the Secret and restart the agent:
sudo install -o agent-ops -m 600 /tmp/ops-agent-webshop.kubeconfig /Users/agent-ops/.dr/kubeconfig-webshop && rm /tmp/ops-agent-webshop.kubeconfig
sudo -iu agent-ops sh -c 'cd ~/.dr && cp -p kubeconfig kubeconfig.bak \
  && KUBECONFIG=kubeconfig:kubeconfig-webshop kubectl config view --flatten > kubeconfig.new \
  && chmod 600 kubeconfig.new && mv kubeconfig.new kubeconfig && rm kubeconfig-webshop \
  && kubectl --kubeconfig kubeconfig config get-contexts'

Then, as agent-ops, recreate ops-agent-break-glass with the command in Secrets and restart: k -n ops-agent rollout restart deployment/ops-agent.

Revoke: kubectl --context admin@webshop -n kube-system delete secret ops-agent-token (Flux recreates it with a new token; rebuild the file to grant access again). To remove access for good, delete cluster/webshop/ops-agent-access.yaml.

Read access to the ci namespace

The ops agent may read the ci namespace of its own cluster (owner, 2026-11-03, #2415), so it can measure the CI runners without the owner. It can read these with get, list and watch: pods, their logs (pods/log) and events, Jobs, Deployments, ReplicaSets and KEDA's ScaledJobs (Role ci/ops-agent-read, cluster/mac-mini/ci/overlay/role.yaml). It cannot exec, port-forward or read Secrets, cannot write anything, and reads no other namespace of the Mac mini than ci and its own ops-agent (below). It reads through its own ServiceAccount ops-agent/ops-agent-ci-reader and token Secret ops-agent-ci-reader-token (cluster/mac-mini/ops-agent/, applied by Flux), as context mac-mini of the break-glass kubeconfig. The context uses server https://kubernetes.default.svc, which resolves only inside the pod. Its default namespace is ci, and the default context stays hetzner-mgmt. The ci pods still cannot reach the API server (CI runners on the Mac mini → Install, step 4).

Once Flux has created the token, as agent-ops on the Mac mini, build the context, then merge it into the break-glass kubeconfig. This does not print the token:

k() { limactl shell k3s sudo k3s kubectl "$@"; }
cd ~/.dr && umask 077 && F=kubeconfig-mac-mini
k -n ops-agent get secret ops-agent-ci-reader-token -o jsonpath='{.data.ca\.crt}' | base64 -d > ca-mac-mini.crt
KUBECONFIG=$F kubectl config set-cluster mac-mini --server=https://kubernetes.default.svc \
  --certificate-authority=ca-mac-mini.crt --embed-certs >/dev/null
KUBECONFIG=$F kubectl config set-credentials ops-agent-mac-mini \
  --token="$(k -n ops-agent get secret ops-agent-ci-reader-token -o jsonpath='{.data.token}' | base64 -d)" >/dev/null
KUBECONFIG=$F kubectl config set-context mac-mini --cluster=mac-mini --user=ops-agent-mac-mini --namespace=ci >/dev/null
rm ca-mac-mini.crt && cp -p kubeconfig kubeconfig.bak \
  && KUBECONFIG=kubeconfig:$F kubectl config view --flatten > kubeconfig.new \
  && chmod 600 kubeconfig.new && mv kubeconfig.new kubeconfig && rm $F \
  && kubectl --kubeconfig kubeconfig config get-contexts   # mac-mini listed; current is still hetzner-mgmt

Then recreate ops-agent-break-glass with the command in Secrets, restart with k -n ops-agent rollout restart deployment/ops-agent, and check from the pod:

o() { k -n ops-agent exec deploy/ops-agent -- kubectl --context mac-mini "$@"; }
o get pods,jobs                          # the ci pods and Jobs
o logs deploy/act-cache -c trim --tail=3 # "Cache at …M of 8192M"
o auth can-i create pods/exec            # no
o auth can-i get secrets                 # no
o get pods -n kube-system                # Forbidden

Revoke: k -n ops-agent delete secret ops-agent-ci-reader-token. Kubernetes invalidates the token. Flux recreates the Secret with a new token, so rebuild the context to grant access again. To remove access for good, delete cluster/mac-mini/ops-agent/service-account.yaml, secret.yaml and cluster/mac-mini/ci/overlay/role.yaml and role-binding.yaml, cluster/mac-mini/ops-agent/role.yaml and role-binding.yaml, and their entries in the kustomizations.

Read access to the ops-agent namespace

The same ServiceAccount also reads the pods, their logs (pods/log) and events of its own namespace ops-agent with get, list and watch (owner, 2026-11-15, platform task #3216; Role ops-agent/ops-agent-read, cluster/mac-mini/ops-agent/role.yaml). A DR session uses it to read the log of a runner pod that was still finishing a run (DR runbook, 0. Start). It cannot exec or port-forward, read Secrets (so not the break-glass Secret or the agent's credentials), or write anything. It needs no new context or token: Flux applies the Role, and the mac-mini context gets it at once. Check from the pod:

o() { k -n ops-agent exec deploy/ops-agent -- kubectl --context mac-mini "$@"; }
o auth can-i list pods -n ops-agent                       # yes
o auth can-i get pods --subresource=log -n ops-agent      # yes
o auth can-i list events -n ops-agent                     # yes
o auth can-i get secrets -n ops-agent                     # no
o auth can-i create pods/exec -n ops-agent                # no
o auth can-i create pods -n ops-agent                     # no

Revoke this read alone: delete cluster/mac-mini/ops-agent/role.yaml and role-binding.yaml and their entries in cluster/mac-mini/kustomization.yaml. The ci read stays.

Host environment check

As a Mac administrator, install the executable for agent-ops and the LaunchDaemon for launchd:

sudo install -d -m 755 -o agent-ops -g staff /Users/agent-ops/.local/bin
sudo install -m 755 -o agent-ops -g staff <checkout>/cluster/mac-mini/host/ops-env-check.sh /Users/agent-ops/.local/bin/
sudo install -m 644 -o root -g wheel <checkout>/cluster/mac-mini/host/com.skatzi.ops-env-check.plist /Library/LaunchDaemons/
sudo launchctl bootstrap system /Library/LaunchDaemons/com.skatzi.ops-env-check.plist
sudo launchctl print system/com.skatzi.ops-env-check | grep -m1 state

Every five minutes it checks the VM k3s, local /readyz, and ops-agent-watchdog's last successful tick through limactl shell. It also uses the host's break-glass kubeconfig to read /api/v2/alerts through the Kubernetes API server's Service proxy and requires an active Watchdog alert. The host check therefore sees a stopped Alertmanager, a missing Watchdog from Prometheus, or a broken API path without asking Alertmanager to notify. The Service proxy requires cluster-admin access; it does not expose Alertmanager publicly. No guest port is forwarded to the Mac. The check does not prove that Alertmanager's Mattermost or Taskbase outbound receivers work; test those separately as described in Prometheus stack.

It restarts k3s at most once per 30 minutes for a local k3s or watchdog failure, but never for an Alertmanager or Watchdog-alert failure. After ten minutes of the same failure it opens a dr issue in GitHub using ~agent-ops/.dr/github-token, once per failure type: ~agent-ops/.dr/ops-env-issue names the failure last reported, so a failure that changes type (for example k3s into alertmanager) opens a new issue; this notification does not use Alertmanager, Taskbase, Mattermost, or the cluster. During the boot grace period, the first OPS_ENV_BOOT_GRACE_MINUTES (default 10) after the Mac booted (sysctl kern.boottime) or the VM booted (its /proc/uptime), a failure is not counted. To change N, set the variable in the plist's EnvironmentVariables. After installation, reboot once without logging in and verify both services and the Flux resources over SSH. The disaster recovery runbook has the ongoing checks and drill.

For alertmanager or watchdog-alert in ~agent-ops/.dr/ops-env-check.err.log, first check the GitHub dr issue and the host's kubectl --kubeconfig=/Users/agent-ops/.dr/kubeconfig access. If the API is reachable, inspect the Alertmanager StatefulSet, pod events and /api/v2/alerts through the Service proxy. A failed Service proxy alone cannot distinguish an API outage from an Alertmanager outage. Restore Alertmanager or Prometheus through the ops runbook, then confirm that the host check clears ops-env-failure. Close the GitHub issue after checking the notification path. If the Mac or GitHub is down, this check cannot notify; those outages need to be found manually. The first issue is delayed by up to 15 minutes (5-minute polling plus a 10-minute persistent-failure window).