Skip to content

feat: add the Cilium Sandbox (Kubernetes) template to coder-labs - #1254

Open
bpmct wants to merge 1 commit into
mainfrom
feat/coder-labs-kubernetes-cilium
Open

bpmct wants to merge 1 commit into
mainfrom
feat/coder-labs-kubernetes-cilium

Conversation

@bpmct

@bpmct bpmct commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Description

Adds a coder-labs template that runs each workspace in a plain Kubernetes Pod, with Cilium as the firewall. It is the Cilium sibling of Plain Sandbox (Kubernetes) (#1232): the same profiles, presets, and apps, but CiliumNetworkPolicies replace the Squid proxy and the NetworkPolicy.

  • Network isolation: each workspace gets two CiliumNetworkPolicies. A DNS policy lets Cilium's DNS proxy answer only the profile's names. An egress policy allows only addresses from those answers (toFQDNs) on the profile's ports, and always denies private ranges. Profiles: Fully isolated (default), GitHub only, GitHub and package registries, Public internet, or Custom.
  • Closed from the first packet: cluster/ adds a CiliumClusterwideNetworkPolicy that denies all traffic in the namespace and cloud metadata. So there is no start gate and no VPC CNI Pod-name workaround.
  • Kernel isolation: the node's container runtime by default. List gvisor, kata-qemu, or kata-clh in runtimes to offer them.
  • Cluster setup: cluster/ is a small Terraform configuration for the namespace, the RBAC, CRD read access, and the baseline policy. cluster/README.md shows Cilium in AWS VPC CNI chaining mode on its own node group, with Helm values.
  • Shared with feat(registry/coder-labs/templates): add the Plain Sandbox (Kubernetes) template #1232: the workspace image (kubernetes-sandboxed/build/Dockerfile), the scoped AI Gateway token, and the code-server, git-clone, and Claude Code setup.
  • Icon: .icons/cilium.svg from cncf/artwork.

Startup on EKS, create to connected agent: about 9 s from a prebuild, 20 to 42 s cold.

Type of Change

  • New module
  • New template
  • Bug fix
  • Feature/enhancement
  • Documentation
  • Other

Template Information

Path: registry/coder-labs/templates/kubernetes-cilium

Testing & Validation

  • Tests pass locally (terraform test: 29 template runs and 5 cluster/ runs, with mock providers). CI runs .tftest.hcl only for modules, so these do not run in CI.
  • Code formatted (prettier --check, terraform fmt), README validator and ShellCheck pass
  • Changes tested locally (EKS 1.37, VPC CNI 1.23 with Cilium 1.20.4 chaining, gVisor). The live cluster runs cluster/ from this PR.
Live test results
Case Result
Fully isolated, claim from a prebuild claim 9 s, Pod not replaced. Coder allowed. DNS for other names refused. Raw IP, metadata, Kubernetes API, node, other Pods blocked
GitHub only GitHub 200, clone works. npm, gist.github.com, example.com blocked
GitHub and package registries GitHub and npm 200, example.com blocked
Public internet (runc) any name on 443 and 80. Raw IP, port 22, and names that resolve to metadata or the node (*.nip.io) blocked
Custom *.npmjs.org, gVisor, cold 4.19.0-gvisor, registry.npmjs.org and npmjs.org 200, GitHub and port 80 blocked
Pod with no workspace policies baseline blocks everything, DNS included
Rest of the cluster no Pod outside the new node group restarted, and no other node changed
Retest on 2026-11-24 (head `ece0872`, Coder v2.39.4-devel)

Pushed this branch to the live deployment and ran the Network check app in a new workspace for each case. All matched the README. Deleting each workspace removed its Pod, PVC, and both CiliumNetworkPolicies.

Case Result
Fully isolated Coder only. DNS for other names, raw IP, metadata, and Kubernetes API blocked
GitHub only GitHub allowed, npm and example.com blocked
GitHub and package registries GitHub and npm allowed, example.com blocked
Public internet, gVisor gVisor kernel. Any name allowed. Raw IP, metadata, and Kubernetes API blocked
Custom *.example.com, github.com example.com, www.example.com, and github.com allowed. api.github.com and npm blocked
Custom 10.0.0.1 create rejected: "Not a host name that Cilium can allow"
Stop and start (Custom) start 23 s, home kept, same rules
Decisions
  • Two policies per workspace: kubernetes_manifest needs every list element to have the same attributes, so unused ones are null. A null rules object still reaches the API as {}, which the CRD rejects. So the DNS rule, the only one with L7 rules, is in its own policy.
  • A fixed DNS server (dns_server), not kube-dns: in chaining mode, CoreDNS runs on nodes without Cilium. Cilium sees the CoreDNS Pod addresses after Service translation, and those change. The default is the Amazon VPC resolver.
  • DNS answers only allowed names, not *. This blocks DNS lookups for other names, and it is the L7 part of the policy.
  • Deny rule for private ranges, with exceptions for the DNS server and coder_egress_cidrs, so a public name that resolves to a private address stays blocked.
  • node_selector defaults to coder.com/pool=cilium, to match cluster/cilium-values.yaml. With {} on a mixed cluster, a Pod could land on a node without Cilium and have no firewall.
  • operator.unmanagedPodWatcher.restart: false and a custom IPAM pool in the example values: with Cilium on some nodes only, the default restarts every Pod on the other nodes, and the default pool 10.0.0.0/8 holds the EKS service CIDR.
  • No STUN rule: Coder connections relay through the Coder server.
Comparison with the Cilium pilot in coder/dogfood

Both chain Cilium onto VPC CNI on selected nodes, keep kube-proxy, turn off the unmanaged Pod restart, move the IPAM pool, and select the workspace by com.coder.workspace.id.

coder/dogfood pilot This template
Policy source one static policy in Flux for one workspace the template, for every workspace
Default deny egress only, ingress unchanged ingress and egress, plus a namespace baseline
DNS CoreDNS Pod /32s, marked pilot only. Any name answered a fixed resolver. Only allowed names answered
Private ranges blocked by default deny, but reachable if an allowed name resolves to one always denied, also for allowed names
Direct connections Google STUN on UDP 19302 none, relay only
Operator and Hubble Relay and UI on Auto Mode, with cert-manager mTLS on the Cilium nodes. Hubble in the agent only
Runtime Kata runc, gVisor, or Kata
Review

A Claude review found no blockers. Fixed: the node_selector default (it was {}, which fails open on a mixed cluster), a metadata dns_server (it now fails validation), coder_egress_cidrs that hold a whole private range or are not in network form, a lowercase access host, wording on ingress from the local node and on shared CDN addresses, and more tests (manifest shape, private IP access URL, ports, git-clone, AI Gateway). Not changed: IPv6 deny entries (IPv4 only, as documented), and TLS server name rules through Envoy, which could be a follow-up.

Related Issues

None


🤖 This PR was generated by Coder Agents on behalf of @bpmct.

bpmct added a commit to coder/coder that referenced this pull request Nov 17, 2026
Adds a "Sandbox agents" guide under Extending templates, and adds
startup time tips from the [Improving Coder Workspace Startup
Times](https://www.youtube.com/watch?v=-xcVJQWVCxs) livestream to the
speed-up templates guide.

**Sandbox agents**
(`docs/templates/extending-templates/sandbox-agents.md`) is organized
around three traits: kernel, network, and secrets isolation, plus fast
startup. Each trait has a short methods table with tradeoffs, plus
examples and references.

- Starts with the coder-labs registry templates (agent-sandbox, Plain
Sandbox, OpenShell) that implement all three, and calls out
[agent-sandbox](https://agent-sandbox.sigs.k8s.io/).
- Explains what the sandbox covers for CLI Agents, Coder Agents, and
Agent Relay.
- Shows how to define sandbox profiles as immutable parameters with one
preset each, and how to control which profile an agent gets.
- Kernel: gVisor, Kata, and EKS Nitro Sandboxes (`isolated-sandbox`
RuntimeClass in EKS Auto Mode).
- Network: separate proxy Pod vs. sidecar, example rules using an
internal GitHub and artifact store, and a cloud firewall layer (AWS
Network Firewall, Route 53 Resolver DNS Firewall) that also limits DNS.
- Secrets: `api_key_scope = "no_user_data"`, a scoped AI Gateway token
(skipped for prebuilds, optional `lifetime`), per-workspace EKS Pod
Identity, and just-in-time credentials from Vault.

**Speed up templates** (`docs/workspaces/speed-up-templates.md`) gets
new sections for pre-warming Kubernetes nodes (with GKE, EKS, and AKS
alternatives), building tools into the image, prebuilt workspaces
(including one preset for each configuration), and skipping the
Kubernetes rollout wait (with coder-logstream-kube to surface Pods that
can't start). It links the
[fast-workspaces-lab](https://github.com/coder-contrib/fast-workspaces-lab)
repo for the sample base image, node schedule, and prebuild templates.

**Agent Firewall** gets a notice on its index page and in the glossary
that it is being phased out, pointing to the sandbox guide. The sandbox
guide doesn't mention Agent Firewall.

Two diagrams in the speed-up templates guide come from the talk's slide
deck, cropped to the diagram.

Notes for reviewers:

- The scoped AI Gateway token (`user:read_personal`) isn't tied to a
workspace, so with several organizations, AI Gateway uses the user's
effective group for budgets. The page doesn't mention this.
- The Nitro (coder/registry#1253) and Cilium (coder/registry#1254)
registry templates are still open, so they aren't linked yet.

<details>
<summary>Decisions and checks</summary>

- **Structure:** three traits, several ways to get each, and simple
tradeoffs.
- **Sysbox** is not listed as kernel isolation, because system calls
still reach the node's kernel.
- **Deployments** stay the recommendation over bare Pods, because
`wait_for_rollout` and coder-logstream-kube cover the startup and error
cases.
- **Token lifetime** is left commented out in the example: Coder can't
revoke the token at stop, and a lifetime shorter than autostop breaks
running workspaces.
- **Process logging** wording: the eBPF sidecar runs inside the sandbox
with gVisor, Kata, or Nitro, so the page asks readers to test it.
- **"CLI Agents"** is kept as the term for agents that run fully in the
workspace.
- **Verified in code:**
- `mutable = false` is enforced on later builds
(`coderd/dynamicparameters/resolver.go`).
- Presets match by subset, also without a `preset_id`
(`coderd/database/queries/prebuilds.sql`, `coderd/workspaces.go`).
- `no_user_data` blocks the Git SSH key and external auth
(`coderd/gitsshkey_test.go`, `coderd/externalauth_test.go`).
- Token creation is rejected for the prebuilds system user
(`coderd/apikey.go`), and the default token lifetime is 7 days
(`codersdk/deployment.go`).
- No Coder code sets `CODER_SESSION_TOKEN` in a workspace; registry
modules such as `coder-login` do.
- **Checks run:** `make lint/emdash`, `make lint/docs-html`, `make
lint/docs-manifest`, markdownlint, markdown-table-formatter, Vale (0
errors), and the pre-commit hook.

</details>

🤖 This PR was generated by Coder Agents on behalf of @bpmct.
@bpmct
bpmct marked this pull request as ready for review November 24, 2026 11:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant