hammerkit

Backend

Where the tasks of a run execute: this machine, or Jobs on a Kubernetes cluster, and which runtimes tasks may use.

backend says where the tasks of runs execute. host is this machine, with the same engine as hammerkit run. kubernetes runs them as Jobs on a cluster, see Kubernetes. runtimes says which runtimes of the engine tasks may use.

server.yaml
backend:
  type: host
  platform: { os: macos, arch: arm64 }   # detected when left out
runtimes: [docker]   # what tasks may run on, docker by default
KeyWhat it does
backend.typehost (this machine, the default) or kubernetes (a cluster).
backend.platformhost only. What the machine offers: os is linux, macos or windows, arch is amd64 or arm64. Detected when left out. Clients read it from the discovery document.
runtimesWhat tasks may run on, see Runtimes.

Runtimes

runtimes lists what tasks may run on: docker (containers, the default) and local (commands on this machine as the user of the server, which have to be allowed by name).

server.yaml
runtimes: [docker, local]

A build file with a task on a runtime that is not listed is refused when it is published or proposed, see What a build file may not do. The server logs a warning at startup when local is allowed on a host. A container task uses the docker daemon of the server's environment, so name DOCKER_HOST in runs.env.allow when it is not the default.

On a cluster local means a task without an image runs in the toolImage of a pool, see Pools. An aggregate task, which only groups its dependencies, runs on no runtime: it is never refused for runtimes.

One server is one trust level

On a host, the process of a run is not a sandbox. It runs as the user of the server, a local task reads everything that user can read, and a container task can use the docker daemon the server is configured for. Accounts keep credentials apart (a task only reads the secrets of the accounts its run was admitted for), but they do not keep code apart on one machine. Do not mix production and untrusted agents on one server: run them on different servers, each with the accounts of its own level, and with local only on a server whose users you trust with the machine. The storage directory and the other runs of a server are inside what a local task can read.

The containers of a run with an open network are on a network of the run, not on Docker's default bridge, so they don't reach the containers of other runs or other callers. The volumes of a service are its caller's: the server puts a scope of the caller and the source in front of each name (pg-data becomes hammerkit-ref-<hash>-pg-data), so a build file can't open, or with resetOnChange remove, the data of somebody else's services. A volume named like a path is refused, since docker would mount that path of the host. The outputs a service gets from the tasks it depends on keep their names, which come from the run's own files. Nothing removes the scoped volumes, and volumes of a server from before the scope are no run's any more: both are listed by docker volume ls --filter label=app=hammerkit.

Each running run takes one Docker network, and each limited task or service one more, out of the daemon's address pools, which hold about 30 by default. A server with many runs at a time needs larger pools (default-address-pools in daemon.json). A daemon that runs Windows containers has no such networks: there the open containers of all runs stay on its default network, so it doesn't keep runs apart.

What lies beyond the host is not hammerkit's to block on Docker: an open container reaches the LAN, the host's own services through the gateway of its network and the cloud's metadata address (169.254.169.254), which hands out the machine's credentials. So open means the internet only once the host's firewall says so. On a host that runs nothing but the server, rules like these do it (the run networks are br-* bridges, the egress proxies of allow items are on docker0). They need Docker's iptables firewall backend, which has the DOCKER-USER chain (not firewall-backend: nftables), and a daemon with IPv6 off, its default; with IPv6 on, the same rules are needed in ip6tables for fe80::/10, fc00::/7 and fd00:ec2::/32. The script can run again, replacing what it set, and the rules stay when Docker restarts. Test them with an open task that has to fail wget -T 3 http://169.254.169.254/ and still resolve names:

firewall of the server's host
# the resolvers the containers use, the only private addresses they reach on port 53: like
# Docker, read systemd-resolved's upstream list when /etc/resolv.conf names only its stub
RESOLV_CONF=/etc/resolv.conf
grep -q '^nameserver 127\.0\.0\.53' "$RESOLV_CONF" && RESOLV_CONF=/run/systemd/resolve/resolv.conf
RESOLVERS=$(awk '/^nameserver/ && $2 !~ /^127\./ && !seen[$2]++ { print $2 }' "$RESOLV_CONF")
iptables -N HAMMERKIT-RUNS 2>/dev/null || iptables -F HAMMERKIT-RUNS
iptables -A HAMMERKIT-RUNS -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
for resolver in $RESOLVERS; do
  iptables -A HAMMERKIT-RUNS -d "$resolver" -p udp --dport 53 -j RETURN
  iptables -A HAMMERKIT-RUNS -d "$resolver" -p tcp --dport 53 -j RETURN
done
iptables -A HAMMERKIT-RUNS -d 10.20.0.15 -j RETURN       # an internal registry runs may reach anyway
for range in 169.254.0.0/16 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 100.64.0.0/10; do
  iptables -A HAMMERKIT-RUNS -d "$range" -j DROP
done
# leaving a network of containers for anywhere else; Docker keeps the networks apart itself
for bridge in 'br-+' docker0; do
  iptables -C DOCKER-USER -i "$bridge" ! -o "$bridge" -j HAMMERKIT-RUNS 2>/dev/null ||
    iptables -I DOCKER-USER -i "$bridge" ! -o "$bridge" -j HAMMERKIT-RUNS
  # the host itself, through the gateway of the network
  iptables -C INPUT -i "$bridge" -m conntrack ! --ctstate ESTABLISHED,RELATED -j DROP 2>/dev/null ||
    iptables -I INPUT -i "$bridge" -m conntrack ! --ctstate ESTABLISHED,RELATED -j DROP
done

Saved as /usr/local/sbin/hammerkit-firewall.sh, a unit puts the rules back after a reboot. Start the server after it (After=hammerkit-firewall.service in the server's unit), so no run starts before the rules are in:

/etc/systemd/system/hammerkit-firewall.service
[Unit]
Description=Firewall rules for the containers of hammerkit runs
After=docker.service
Requires=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh /usr/local/sbin/hammerkit-firewall.sh

[Install]
WantedBy=multi-user.target

systemctl enable --now hammerkit-firewall applies them now and on every boot.

On a cluster every task is a pod of its own in the caller's namespace, without a token of the cluster. The boundary is the container, the namespace and the network policies the server puts in it (see Namespaces), which only hold on a network plugin that enforces NetworkPolicy. They keep an open pod off the metadata and private ranges by default, so there open means the internet without a firewall of your own (see deniedEgress in Kubernetes). Keep the server off the nodes of the pools, so a task that escapes its container does not share a node with the server's token. The server still holds the right to mint the tokens of every account (see Secrets in the Job), so the advice stands: one server, and one set of accounts, per trust level.

Capabilities

A container task can add Linux capabilities (capAdd, see Capabilities), such as SYS_ADMIN for a daemonless image build. A capability is root's power over the kernel the container runs on, which the runs of other callers share, so a server adds one only where its operator allows it, and then only in a sandbox with a kernel of its own:

server.yaml
backend:
  type: kubernetes
  capabilities:
    allow: [SYS_ADMIN]       # what a build file may add
    runtimeClass: gvisor     # the sandbox the pods of those tasks run in
sandboxes:
  capabilities: [SYS_ADMIN]  # runs on sandboxes add none unless named here
server.yaml
backend:
  type: host
  capabilities:
    allow: [SYS_ADMIN]
    runtime: runsc           # a runtime of the docker daemon: gVisor's
KeyWhat it does
backend.capabilities.allowThe capabilities a task may add. A build file with a task that adds another is refused when it is published or proposed (400); without capabilities the server allows none.
backend.capabilities.runtimeClasskubernetes only. The RuntimeClass the pods of tasks that add capabilities run in.
backend.capabilities.runtimehost only. The docker runtime the containers of those tasks run in, as named in the daemon's daemon.json.
sandboxes.capabilitiesWhat a run on a sandbox may add, out of allow. None by default: a sandbox holds code nobody reviewed.

Only the containers of tasks that add capabilities run in the sandbox, the others run as before, and such a task never runs in the runner of a sandbox. The sandbox has to be one: hammerkit can't tell whether a RuntimeClass or a docker runtime keeps the capability from the host, so name only one that does, such as gVisor (runsc, which handles the container's system calls in a kernel of its own) or Kata Containers (a virtual machine per pod). gVisor is gvisor on GKE (GKE Sandbox, on by default on Autopilot) and installed on the nodes elsewhere; on a docker host runsc install adds it to the daemon. Kata is kata-vm-isolation with AKS Pod Sandboxing. A task can't ask for privileged, on any backend. On a docker host, such a task can't bind files of the run (src, file outputs, mounts) yet, see build files: build images with it on a Kubernetes backend.

The pod of such a task goes to the nodes of the first pool, and on a sandbox to the node of the sandbox's files: those nodes need the runtime. Where only a node pool of its own has it (GKE Standard, AKS), name that pool's labels in the first pool, or make sure the RuntimeClass's scheduling sends the pod there. A pod no node can take stays Pending, and hammerkit doesn't fail it early yet.

Pod Security baseline refuses these capabilities in a sandbox too, it does not know about RuntimeClasses. With capabilities the server makes the namespaces of new callers enforce privileged and audit baseline, and an admission policy of yours refuses in them what baseline refuses, and capabilities beyond baseline to every pod outside the sandbox. The server never changes the level of a namespace it made before: that would take patch on every namespace of the cluster. Until you relabel one, the tasks that add capabilities fail in it and say so, the others run. The second policy keeps the namespaces the server makes to its own, so it can't make one that enforces privileged outside them. Both need Kubernetes 1.30 or later (ValidatingAdmissionPolicy). Apply them before you set capabilities, with the RuntimeClass you name there, the server's ServiceAccount and its namespacePrefix:

admission.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: { name: hammerkit-capabilities }
spec:
  matchConstraints:
    namespaceSelector: { matchLabels: { hammerkit.dev/managed: 'true' } }
    resourceRules:
      - { apiGroups: [''], apiVersions: ['*'], operations: [CREATE, UPDATE], resources: [pods, pods/ephemeralcontainers] }
  variables:
    - name: sandboxed
      expression: "object.spec.?runtimeClassName.orValue('') == 'gvisor'"
    # the security context of every container, init and ephemeral ones too
    - name: contexts
      expression: >-
        object.spec.containers.filter(c, has(c.securityContext)).map(c, c.securityContext)
        + object.spec.?initContainers.orValue([]).filter(c, has(c.securityContext)).map(c, c.securityContext)
        + object.spec.?ephemeralContainers.orValue([]).filter(c, has(c.securityContext)).map(c, c.securityContext)
    - name: baseline
      expression: "['AUDIT_WRITE', 'CHOWN', 'DAC_OVERRIDE', 'FOWNER', 'FSETID', 'KILL', 'MKNOD', 'NET_BIND_SERVICE', 'SETFCAP', 'SETGID', 'SETPCAP', 'SETUID', 'SYS_CHROOT']"
    - name: seLinuxTypes
      expression: "['', 'container_t', 'container_init_t', 'container_kvm_t', 'container_engine_t']"
    - name: sysctls
      expression: "['kernel.shm_rmid_forced', 'net.ipv4.ip_local_port_range', 'net.ipv4.ip_unprivileged_port_start', 'net.ipv4.tcp_syncookies', 'net.ipv4.ping_group_range', 'net.ipv4.ip_local_reserved_ports', 'net.ipv4.tcp_keepalive_time', 'net.ipv4.tcp_fin_timeout', 'net.ipv4.tcp_keepalive_intvl', 'net.ipv4.tcp_keepalive_probes', 'net.ipv4.tcp_rmem', 'net.ipv4.tcp_wmem']"
  validations:
    - expression: "variables.sandboxed || variables.contexts.all(s, s.?capabilities.?add.orValue([]).all(a, a in variables.baseline))"
      message: capabilities beyond baseline are added in the RuntimeClass gvisor only
    - expression: "!variables.contexts.exists(s, s.?privileged.orValue(false))"
      message: no privileged containers
    - expression: "!object.spec.?hostNetwork.orValue(false) && !object.spec.?hostPID.orValue(false) && !object.spec.?hostIPC.orValue(false)"
      message: no host namespaces
    - expression: "!object.spec.?volumes.orValue([]).exists(v, has(v.hostPath))"
      message: no hostPath volumes
    - expression: >-
        !object.spec.containers.exists(c, c.?ports.orValue([]).exists(p, p.?hostPort.orValue(0) != 0))
        && !object.spec.?initContainers.orValue([]).exists(c, c.?ports.orValue([]).exists(p, p.?hostPort.orValue(0) != 0))
      message: no host ports
    - expression: "variables.contexts.all(s, s.?procMount.orValue('Default') == 'Default')"
      message: no unmasked /proc
    - expression: >-
        object.spec.?securityContext.?seccompProfile.?type.orValue('') != 'Unconfined'
        && variables.contexts.all(s, s.?seccompProfile.?type.orValue('') != 'Unconfined')
      message: no unconfined seccomp
    - expression: >-
        object.spec.?securityContext.?appArmorProfile.?type.orValue('') != 'Unconfined'
        && variables.contexts.all(s, s.?appArmorProfile.?type.orValue('') != 'Unconfined')
        && object.metadata.?annotations.orValue({}).all(k, !k.startsWith('container.apparmor.security.beta.kubernetes.io/')
          || object.metadata.annotations[k] == 'runtime/default' || object.metadata.annotations[k].startsWith('localhost/'))
      message: no unconfined AppArmor
    - expression: >-
        object.spec.?securityContext.?seLinuxOptions.?type.orValue('') in variables.seLinuxTypes
        && object.spec.?securityContext.?seLinuxOptions.?user.orValue('') == '' && object.spec.?securityContext.?seLinuxOptions.?role.orValue('') == ''
        && variables.contexts.all(s, s.?seLinuxOptions.?type.orValue('') in variables.seLinuxTypes
          && s.?seLinuxOptions.?user.orValue('') == '' && s.?seLinuxOptions.?role.orValue('') == '')
      message: no SELinux options beyond the container types
    - expression: "object.spec.?securityContext.?sysctls.orValue([]).all(s, s.name in variables.sysctls)"
      message: only the safe sysctls
    - expression: >-
        !object.spec.?securityContext.?windowsOptions.?hostProcess.orValue(false)
        && !variables.contexts.exists(s, s.?windowsOptions.?hostProcess.orValue(false))
      message: no Windows host processes
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata: { name: hammerkit-capabilities }
spec: { policyName: hammerkit-capabilities, validationActions: [Deny] }
---
# the server makes the namespaces of its callers only, at the levels it sets
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: { name: hammerkit-namespaces }
spec:
  matchConstraints:
    resourceRules:
      - { apiGroups: [''], apiVersions: ['*'], operations: [CREATE, UPDATE], resources: [namespaces] }
  matchConditions:
    - { name: server, expression: "request.userInfo.username == 'system:serviceaccount:hammerkit:hammerkit'" }
  validations:
    - expression: "object.metadata.name.matches('^hammerkit-[0-9a-f]{16}$')"
      message: the server makes the namespaces of its callers only
    - expression: "object.metadata.?labels['hammerkit.dev/managed'].orValue('') == 'true'"
      message: the namespaces of callers are labelled hammerkit.dev/managed
    - expression: "object.metadata.?labels['pod-security.kubernetes.io/enforce'].orValue('') in ['baseline', 'privileged']"
      message: the namespaces of callers enforce Pod Security baseline, or privileged with capabilities
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata: { name: hammerkit-namespaces }
spec: { policyName: hammerkit-namespaces, validationActions: [Deny] }

Then relabel the namespaces the server made before, those of its prefix:

kubectl get namespace -l hammerkit.dev/managed=true -o name | grep '^namespace/hammerkit-' | \
  xargs -r -I{} kubectl label {} pod-security.kubernetes.io/enforce=privileged \
  pod-security.kubernetes.io/audit=baseline --overwrite

When you remove capabilities again, set them back to enforce=baseline (and remove audit) before the server restarts: it runs nothing in a namespace that still enforces privileged, and its error names the command.

Building container images walks through a build of a Dockerfile with BuildKit in gVisor, pushed with a token of a service account.

Kubernetes

Experimental, like the server. Linux nodes only.

server.yaml
backend:
  type: kubernetes
  namespace: hammerkit              # the server's own; the namespace of its pod when left out
  # kubeconfig: /etc/hammerkit/kubeconfig   # with context, for a cluster the server is not in
  # context: prod
  storageClass: standard-rwo        # of the claims of tasks; the cluster's default when left out
  volumeSize: 1Gi                   # default, of a task's claim that states no volumeSize
  maxVolumeSize: 50Gi               # the most a task may state; 10Gi (or volumeSize, if more) when left out
  keepVolumes: 15m                  # default; how long a task's claim stays for the next run, false for not at all
  pools:
    - name: builds
      platform: { os: linux, arch: amd64 }
      nodeSelector: { cloud.google.com/gke-nodepool: builds }
      tolerations: [{ key: builds, operator: Exists, effect: NoSchedule }]
      toolImage: ghcr.io/corp/build-tools:2026.10
  providers:
    gsm: { image: gcr.io/google.com/cloudsdktool/google-cloud-cli:slim }
  quota: { requests.cpu: '8', requests.memory: 16Gi, persistentvolumeclaims: '20', requests.storage: 100Gi }
  defaultResources: { requests: { cpu: 250m, memory: 256Mi } }
  sandboxes: { size: 4Gi, storageClass: sandboxes }
  # runRole: hammerkit-runs           # the ClusterRole the server binds in each caller's namespace
  # deniedEgress: [169.254.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, fe80::/10, fc00::/7]
  allowedEgress: [10.20.0.15/32]     # an internal registry open tasks may reach anyway
  networkPolicy: enforced            # the network plugin enforces NetworkPolicy; limited tasks need it
  # openNetworkGate: false             # what open pods wait to no longer reach, see Namespaces

The server runs as before (it checks the code out, plans the run with the engine in a process of its own and keeps the cache), but every container task of a run becomes a Job and every service a Deployment, in a namespace of the caller.

KeyWhat it does
namespaceThe server's own namespace, where the credentials of the accounts are. Found on its own when the server runs in a pod.
kubeconfig, contextThe cluster, for a server outside of it. Without them the server uses its default kubeconfig, else the cluster it runs in.
namespacePrefixA caller's namespace is this and the first 16 hex digits of the sha-256 of their issuer and subject, hammerkit- by default. Two servers on one cluster need a prefix each.
storageClassThe storage class of the claims tasks get.
volumeSize, maxVolumeSizeThe size of a task's or service's claim when it states no volumeSize (1Gi), and the most one may state: 10Gi when left out, or volumeSize if that is more, since a build file states its own. A task over it fails before its pods start. Each claim counts as its size in a requests.storage quota, which bounds what a caller's claims take together.
keepVolumesHow long the claim of a task stays after the run that mounted it last (15m), see Kept claims. false removes it at the end of the run.
poolsWhere pods are placed, see Pools. One linux/amd64 pool when left out.
providersPer secret provider, the image its command runs in. Every provider an account reads needs one.
quotaThe ResourceQuota of each caller's namespace, as Kubernetes writes it (requests.cpu, limits.memory, pods, persistentvolumeclaims, requests.storage).
defaultResourcesrequests and limits (cpu, memory) for containers without resources, as a LimitRange, so they are admitted under a quota that limits compute.
sandboxesWhere sandboxes are kept: two claims per sandbox in its caller's namespace, their size and storage class, and the image and resources of the pod that reads and edits its files.
runRoleThe ClusterRole the server binds to itself in each caller's namespace, hammerkit-runs by default, see What the server may do.
deniedEgressAddress ranges a pod of a run with an open network, or an egress proxy, may not connect to. By default the link-local ranges, where the clouds' metadata endpoints hand out the node's identity (169.254.0.0/16, fe80::/10), and the private ones (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, fc00::/7), where the cluster's nodes, pods and services and the networks behind it are. So open means the internet. A cluster with pod or service ranges outside of them (GKE's 34.118.224.0/20) adds those.
openNetworkGateWith networkPolicy: enforced, what a pod with an open network waits to no longer reach before it starts: { host, port }, an IPv4 address inside deniedEgress that answers without the policy, by default the metadata endpoint 169.254.169.254:80, or false for no wait. See Namespaces.
allowedEgressAddresses inside deniedEgress they may reach anyway, such as an internal registry, a package mirror, the secret manager a provider reads in a Job, or the database of an allow TCP forward. None by default. The pods of the caller's own namespace and DNS are reachable without it.

Namespaces

The first run of a caller makes their namespace, labelled hammerkit.dev/managed. A namespace of that name without the label is refused, the server runs no task in a namespace it did not make. When a run starts the server puts in it, replacing what was there:

  • a RoleBinding of runRole to itself, its only rights in the namespace;
  • a NetworkPolicy that lets each pod with an open network accept connections from the pods of its namespace only (the services a task needs), so callers can not reach each other's pods;
  • a NetworkPolicy for the pods with an open network and the egress proxies: they reach their namespace, DNS, any address outside deniedEgress and the addresses of allowedEgress;
  • a NetworkPolicy that lets nothing into an egress proxy, so a proxy takes connections only from the task its own policy names, and from nobody once that policy is gone;
  • a NetworkPolicy that lets nothing into or out of the pods that copy files into and out of claims (labelled hammerkit.dev/transfer), which the server reaches through the API only;
  • quota and defaultResources; removing one from the config removes it from the namespace.

The server does that again for each run, but not within 5 minutes of the last time for the same namespace: a namespace that was deleted and made anew, or a server that restarted, gets it at the next run.

Policies add up, so none of them widens a pod with a limited network (labelled hammerkit.dev/network: limited): its own policy alone decides what it reaches, DNS left out, and what reaches it. An egress proxy takes connections from its task only.

Some network plugins apply a policy a moment after a pod started. With networkPolicy: enforced, a pod with an open network therefore starts with the init container hammerkit-network, which waits until the pod no longer reaches an address the namespace denies it, as a limited pod waits for its own policy (see Network). By default that is the metadata endpoint, 169.254.169.254:80. Each open pod starts about a second later for it, the time the gate waits for an answer that doesn't come, and each node pulls the proxy's image once. When the policy doesn't hold within a minute, the pod fails rather than run open, and says so.

openNetworkGate changes what it waits for:

  • an address and port inside deniedEgress that answers without the policy, such as a node's kubelet ({ host: 10.0.0.10, port: 10250 }). Use one where the metadata endpoint doesn't answer at all (bare metal, kind, k3s, AWS without IMDS): there the default gate opens at once and proves nothing.
  • false turns it off, for a cluster whose metadata traffic is redirected before the network plugin sees it, where the gate would never open.

When deniedEgress doesn't cover the gate's address, or allowedEgress lets it in, open pods start without the gate. An allow of the address the cloud redirects metadata to (GKE's 169.254.169.252:988) isn't seen: turn the gate off there.

The policies of a task or service that a service run no longer has after a move go once its pods have ended.

The namespace enforces the baseline Pod Security Standard: no privileged pods, host paths or host network (with capabilities, an admission policy of the operator in its place). Every container of a run runs with allowPrivilegeEscalation: false (so sudo and other setuid programs do not work), without the NET_RAW capability (no ping) and with the runtime's seccomp profile, and without a token of the cluster.

What a run makes there carries the label hammerkit.dev/run and is deleted when the run ends, whether it succeeded or not, and the end of the run waits until its pods and claims are gone: an idle caller costs nothing on the cluster but the claims it keeps for a while. What a run left because the server stopped before its end is deleted when the caller's next run starts: the first run of the caller after the server started, or after a run whose objects could not all be deleted.

The runs of one caller execute side by side in their namespace, up to runs.limits.running, as the runs of different callers do. Several agents of one identity, each on a sandbox of its own, do not wait for each other. On a server the Jobs, Deployments, Services, Secrets and claims of a task are named after its cache id (its first 32 characters) and the run (the first 8 digits of its hammerkit.dev/run label), and found by both labels, so two runs of the same task have their own objects and the end of one never removes what the other uses. Kept claims are named after the source they are kept for instead. Two runs that share kept claims execute one after the other: runs of the same branch or tag of a repository, checks of the same repository and runs from a commit hash of it, runs of the same sandbox, or the uploads of one caller (a source of type upload), whose kept claims are the caller's. The second waits in the queue, without counting against runs.maxDuration. Runs of two branches have kept claims of their own and go side by side. With keepVolumes: false nothing is shared and even the runs of one branch run side by side.

The runs of a caller share the quota of the namespace, so size it for runs.limits.running runs of one caller at once, and for a task with all its services up: a service and the task that needs it hold their room at the same time. Kept claims count once for each branch that ran in the last keepVolumes, so set requests.storage to bound the disk they take. A pod that does not fit the nodes waits for one, until runs.maxDuration. The pod of a task or service over the quota is not created until the quota has room: it says so in its log, with what the quota refused, and waits. A pod that asks for more than the quota allows at all fails at once. After 10 minutes the wait goes on only while a pod that will end holds room in the namespace, such as another task of the run or of another run; when only services hold it, they wait for what waits for them, and the task or service fails. The wait of a task's pod does not count against its timeout, and lasts at most that timeout in all. While the quota refuses a task's pod, the run starts no other task that is less urgent than it (see which ready task runs first), so the room that frees goes to it. A task that needs a service is not held back: its service is up already and holds its room until the task ran. The pods that copy a task's files into its claim and its outputs out of it wait 10 minutes. They ask for 64Mi and are limited to 512Mi of memory, so they take little of a quota sized for the tasks, whatever defaultResources says. Each service pod also has a small debug container beside the service, with the service's files, for a shell with kubectl exec; it asks for 10m CPU and 16Mi and is limited to 100m and 256Mi. A claim over the quota (persistentvolumeclaims, requests.storage) does not wait. The server first removes released kept claims of the caller to make room, and when that is not enough the task fails with exceeded quota.

What changes objects of the whole namespace happens for one run at a time: making the namespace and its policies and quota at the start of a run, removing what a stopped server left (the objects of a run that does not execute) and removing kept claims that expired. These take a moment at the start of a run, not the whole run.

Kept claims

The claim of a container task stays after the run for keepVolumes (15m), and each run that mounts it again starts the time anew. The next run of the same source finds the task's outputs in it: when the task's inputs did not change, the task is cached and the tasks that depend on it mount its outputs from there, without restoring them from the cache. A restore copies the outputs into a new claim through a pod, which for a node_modules of an npm ci takes a while; with the claim kept, a change to code the install does not read goes straight to the compile and test steps.

When the inputs did change, the task runs on its kept claim emptied first, as on a new one, so a run's outputs never mix with those of an earlier one. Without a kept claim, a cache hit restores into a new claim as before.

A kept claim is the source's, within its cache: the runs of one branch or tag of a repository share theirs, the checks of a repository and its runs from a commit hash theirs, and a run on a sandbox mounts only those of the same sandbox, never what a run of the repository or of another sandbox kept. The approved runs of a sandbox share claims of their own, per sandbox: they never mount what the sandbox's runs that needed no approval kept, as their cache is apart from theirs. The first run of a new branch finds none and restores the cached outputs, as without kept claims; each active branch takes claims of its own until they expire. Its name carries a hash of the source, and its label hammerkit.dev/volume-scope the source.

The disk they take is bounded by the time and the quota of the namespace: the server removes a claim once it expired, and when a claim of a run does not fit a requests.storage or persistentvolumeclaims quota, the kept claims the run does not use make room: those of the caller's other sources that their last run released, and those of its own a task no longer has (one renamed or changed). The claims a run of another source mounts while it executes stay, and the sweep of expired claims leaves all claims of a source while one of its runs executes. Room for a claim is made differently: a run of one branch may remove the released claims of another branch that runs at the same time but has not mounted them yet, and that run's tasks then restore from the cache. Size requests.storage for the branches that run at once to keep them warm. After a restart, the server finds the claims it kept before when its first run starts, and removes them as they expire. Services keep no claim; theirs go with the run.

Pools

A pool is a set of nodes: platform (linux, with amd64 or arm64), nodeSelector (the labels besides kubernetes.io/os and kubernetes.io/arch, which come from platform) and tolerations. Container tasks and services go to the first pool. A task without an image runs in the toolImage of the first pool that has one and offers the platform the task declares (platform: { arch: arm64 } picks an arm64 pool). A task for macOS or Windows has no pool and fails when the run starts. runtimes has to list local for such tasks, and at least one pool needs a toolImage then.

Secrets in the Job

The server reads no secret of a provider for a task on a cluster: the Job of the task does, with only the credentials of the accounts it uses. Each provider secret gets an init container in the provider's image, which runs the provider's command with the provider's and the account's env and writes the value into a volume in memory. The task's container mounts only that volume: a path: secret is the file, an env: secret is set before the command runs.

The credential of an account is set under accounts.<name>.kubernetes and is put at /var/run/hammerkit/account/ in the init containers of that account only:

server.yaml
accounts:
  payments-dev:
    providers:
      gsm: { env: { CLOUDSDK_AUTH_CREDENTIAL_FILE_OVERRIDE: /var/run/hammerkit/account/gcp.json } }
    kubernetes:
      serviceAccount: payments-dev    # a ServiceAccount in backend.namespace
      audience: //iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/hk/providers/cluster
      secret: payments-dev-federation # a Secret in backend.namespace, each key a file
KeyWhat it does
serviceAccountA ServiceAccount of the server's namespace. Right before each Job of the task, the server asks for a token of it (an hour, for audience) and puts it at token; the Secret that carries it is deleted when the Job is done. A cloud that trusts the cluster's issuer for that ServiceAccount (GCP workload identity federation, AWS AssumeRoleWithWebIdentity, Azure federated credentials) exchanges it for the account's credentials. Short-lived, and one trust binding per account whoever the caller is.
audienceThe audience of that token; the cluster's default when left out.
secretA Secret of the server's namespace, each key a file of the directory: the federation config that points at token, or a key file where nothing else works (long-lived, so the second choice).

Secrets of a task with a limited network

A task with network: none or an allow list reaches nothing else, and its init containers share its policy. backend.providers.<name>.allow names the hosts a provider's command reaches:

server.yaml
backend:
  type: kubernetes
  networkPolicy: enforced
  providers:
    gsm:
      image: gcr.io/google.com/cloudsdktool/google-cloud-cli:slim
      # Google's STS exchanges the token of the account's ServiceAccount, Secret Manager reads the value
      allow: [sts.googleapis.com, secretmanager.googleapis.com]
runs:
  secretNetwork: none
  • The task's egress proxy lets a tunnel to one of those hosts, on port 443, through only when it carries the proxy's token. The token is new for each run of the task, in a Secret of the caller's namespace that the init containers read their proxy variables from (HTTPS_PROXY=http://hammerkit:<token>@hammerkit-proxy:3128). The task's own container gets neither the token nor those variables, so its command reaches the provider's hosts as little as any other. The Secret goes with the proxy.
  • A task with network: none gets a proxy for this alone, which allows its own command no host.
  • The names are exact names or *. patterns, without a port; like a pattern of allow, they never reach a private address. Name the hosts the command needs, not their domain: *.googleapis.com would let it reach every Google API. The provider's command has to read HTTPS_PROXY, user and password included; gcloud does. A command that ignores it can't read a secret under a limited network. A federation config that impersonates a Google service account (service_account_impersonation_url) also needs iamcredentials.googleapis.com.
  • With runs.secretNetwork every task that reads a secret has to be limited, so each provider of such a task needs allow.

On a cluster every account with providers needs kubernetes, or the server does not start: its commands would otherwise run as whatever identity the node or the provider's image has, the same for every account.

The values never reach the server, so it can not mask them in the log. The task's output is masked in the pod instead, with awk, line by line, before it leaves the pod: the image of a task that reads such a secret needs awk (busybox, alpine, debian and their kin have it), and stdout and stderr arrive as one stream. Encodings of a value (base64, hex) are not masked there. env: secrets (variables of runs.env.allow) are the server's own and are handed over as before.

Not yet on a cluster, and refused when a build file is published: a provider secret on a service, and a provider secret with cache: true (its digest would be needed before the Job reads the value).

Cache and sources

The cache stays on the server, one per source trust as on a host (a repository's runs share it). After a task ran, its outputs are copied from its claim into the cache, and a later run that hits restores them into a new claim before its dependents start, unless the claim is still kept. The files of a task's src are copied from the server's checkout into its claim. So on a cluster the storage directory of the server (storage.directory) belongs on a volume of its own.

Network

A task's network works on a cluster as in a Kubernetes environment: a limited task's Jobs get a NetworkPolicy that lets them reach only the services they need and, under allow, their egress proxy, a Deployment on the first pool. A task without an image runs in a container of the tool image, so it is limited like a container task: it may name its own network on such a server (elsewhere a local task with a limited network is refused when the build file is read), and runs.network and runs.secretNetwork hold it as well. The policy, the proxy and its Service carry hammerkit.dev/run and go with the rest of the run. Pods with an open network are governed by the policy of the caller's namespace, see Namespaces.

The cluster's network plugin has to enforce NetworkPolicy (Calico and Cilium do, and recent kind), for network: and for keeping callers apart. Without it nothing is isolated. Hammerkit can't tell from the API, so backend.networkPolicy: enforced states it; without it a task with a limited network fails instead of running open. With sandboxes, whose runs are limited by sandboxes.network, a config without it is refused unless that is open, and so is one with endpoints, whose services only the server is to reach. Some apply a policy a moment after the pod started, so a limited pod waits in an init container until its policy holds, and fails after 60 seconds if it never does (see Kubernetes). A run's policies go only after its pods are gone. A pod with an open network has no such wait, so on those plugins it can reach a deniedEgress address in its first moment.

A task that reads a provider's secret can have a limited network when the server names the endpoints of the provider: its init containers are in the task's pod, under the same policy, and reach the secret manager through the task's egress proxy (under none too). See Secrets in the Job. Without them such a task keeps an open network: a build file that limits it is refused when it is published.

Sandboxes

A sandbox is two claims in its caller's namespace, next to the namespace's runs: its files, and its git data. A short pod of backend.sandboxes.image fetches into them, reads and edits the files and commits what the server pushes; the Jobs of a run on the sandbox mount the files only. The quota of sandboxes is a ResourceQuota on their storage class, when they have one of their own. The pod runs as root with only the capabilities to own and change files (the baseline Pod Security level allows it, restricted does not).

A task of a run on a sandbox that mounts all of its files and nothing else runs in the sandbox's runner, a pod hammerkit-runner-<key> that stays and takes each command over pods/exec (see sandboxes). The pod of the files owns it, so it goes with that pod after sandboxes.idle, and so does its NetworkPolicy, which outlives the runner while the pod of the files stays. The runner carries no hammerkit.dev/run label: the end of a run leaves it, and removing what a stopped server left skips it. It counts against the quota like a task's pod, so a namespace with sandboxes needs room for one runner per active sandbox besides the runs. It has the security context, resources and placement of the task's Job, but no token and no service links, and an init container of busybox:1.37.0-musl (pinned by digest) that copies the busybox the runner cleans up with: a cluster that pulls only from a registry of its own needs that image there too. When the runner can not be used (the cluster refuses it, it does not start, or another task of the run is in it) the task runs as a Job.

What the server may do

Across the cluster the server makes namespaces and binds runRole in the ones it made. With sandboxes it also lists namespaces when it starts, to find the claims of sandboxes in the ones it made. With service runs it deletes the namespace of each at its end, and lists them to remove the ones a stopped server left. It needs no rights on Secrets or pods outside of them: those come from runRole, which it binds in each caller's namespace (Kubernetes lets it bind that role only, by bind). In its own namespace it reads the Secrets of the accounts and makes tokens of their ServiceAccounts, by name. The processes of runs use the same identity. list on events is how the log of a run that failed gets what the cluster said of its pods (a failed image pull, a pod no node takes); a runRole without it still works, and the log says the events could not be read. list on pods.metrics.k8s.io and, across the cluster, on nodes and nodes.metrics.k8s.io are only for what remote capacity and the dashboard show of the CPU and memory in use; without them, they say what they could not read.

rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata: { name: hammerkit-server }
rules:
  - { apiGroups: [''], resources: [namespaces], verbs: [get, list, create, delete] }   # list: with sandboxes or service runs, delete: service runs
  - { apiGroups: [rbac.authorization.k8s.io], resources: [rolebindings], verbs: [get, create, update] }
  - apiGroups: [rbac.authorization.k8s.io]
    resources: [clusterroles]
    verbs: [bind]
    resourceNames: [hammerkit-runs]
  # optional, for the capacity: the nodes, what they have and use
  - { apiGroups: [''], resources: [nodes], verbs: [list] }
  - { apiGroups: [metrics.k8s.io], resources: [nodes], verbs: [list] }
---
# bound by the server in each caller's namespace, never across the cluster
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata: { name: hammerkit-runs }
rules:
  - { apiGroups: [''], resources: [resourcequotas, limitranges], verbs: [get, create, update, delete] }
  - apiGroups: ['']
    resources: [pods, pods/exec, pods/log, persistentvolumeclaims, secrets, services]
    verbs: [get, list, create, patch, delete, deletecollection]
  - { apiGroups: [''], resources: [events], verbs: [list] }   # what the cluster said of a run that failed
  - { apiGroups: [metrics.k8s.io], resources: [pods], verbs: [list] }   # what the pods of runs use, for the capacity
  - apiGroups: [batch]
    resources: [jobs, jobs/status]
    verbs: [get, list, create, patch, delete, deletecollection]
  - { apiGroups: [apps], resources: [deployments], verbs: [get, list, create, patch, delete, deletecollection] }
  - apiGroups: [networking.k8s.io]
    resources: [networkpolicies]
    verbs: [get, list, create, update, patch, delete]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: { name: hammerkit-accounts, namespace: hammerkit }
rules:
  # the secret and serviceAccount of each account
  - { apiGroups: [''], resources: [secrets], verbs: [get], resourceNames: [payments-dev-federation] }
  - { apiGroups: [''], resources: [serviceaccounts/token], verbs: [create], resourceNames: [payments-dev] }

Bind hammerkit-server with a ClusterRoleBinding and hammerkit-accounts with a RoleBinding to the server's ServiceAccount; do not bind hammerkit-runs yourself. Making RoleBindings across the cluster still lets the server bind hammerkit-runs in a namespace it did not make. To rule that out, admit its RoleBindings only in the namespaces of its own callers, its namespacePrefix and 16 hex digits, and not in those of another server on the cluster. The second policy keeps the deletes of namespaces to those of its service runs:

admission.yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: { name: hammerkit-managed-namespaces }
spec:
  matchConstraints:
    resourceRules:
      - { apiGroups: [rbac.authorization.k8s.io], apiVersions: ['*'], operations: [CREATE, UPDATE], resources: [rolebindings] }
  matchConditions:
    - { name: server, expression: "request.userInfo.username == 'system:serviceaccount:hammerkit:hammerkit'" }
  validations:
    - expression: "namespaceObject.metadata.?labels['hammerkit.dev/managed'].orValue('') == 'true'"
    - expression: "namespaceObject.metadata.name.matches('^hammerkit-[0-9a-f]{16}$')"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata: { name: hammerkit-managed-namespaces }
spec: { policyName: hammerkit-managed-namespaces, validationActions: [Deny] }
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata: { name: hammerkit-service-run-namespaces }
spec:
  matchConstraints:
    resourceRules:
      - { apiGroups: [''], apiVersions: ['*'], operations: [DELETE], resources: [namespaces] }
  matchConditions:
    - { name: server, expression: "request.userInfo.username == 'system:serviceaccount:hammerkit:hammerkit'" }
  validations:
    - expression: "oldObject.metadata.?labels['hammerkit.dev/service-run'].hasValue()"
    - expression: "oldObject.metadata.name.matches('^hammerkit-[0-9a-f]{16}$')"
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata: { name: hammerkit-service-run-namespaces }
spec: { policyName: hammerkit-service-run-namespaces, validationActions: [Deny] }

Upgrading a server for service runs: add delete on namespaces to hammerkit-server and the second policy. Without them a service run still ends, but its namespace stays: the server removes what runs in it, and says in its log and in the run's what its ClusterRole needs.

Not yet: Windows nodes, holding a pod with an open network back until the policy of its namespace holds, a cache in a registry or a bucket, a limited network for a task that reads a provider's secret, and failing a task early whose pod can not start (an image that can not be pulled, no node for its pool).

On this page