Repository navigation
feat: add Nitro Sandbox template to daveahr2172 namespace - #1253
Conversation
Import Dave's newer live template under the dahr registry namespace. Document the cluster and image prerequisites, and validate proxy and demo inputs. Co-authored-by: Dave Ahr <[email protected]>
Co-authored-by: Dave Ahr <[email protected]>
daveahr2172
left a comment
There was a problem hiding this comment.
Thanks for pulling this into the registry, Ben. I reviewed it with a security pass and tested it on our EKS cluster. Please apply the changes below before merging. The full diff is at the end, tested against this PR's head (36fb86b).
Security
- Policy gate (
start-agent.sh). A connection that takes longer than 0.3 s counts as "blocked", so the agent could start before the NetworkPolicy is in force. Open the gate only after 3 failed connections in a row, each with a 1 s timeout. Exit ifKUBERNETES_SERVICE_HOSTis unset. - Scoped AI Gateway token. Every build mints a new 24 h token, and none are ever revoked. Change the default lifetime to 8 h, with validation (1 to 168). Each start revokes the workspace's earlier tokens with the
coderCLI on the provisioner, in a best-effortterraform_datastep that runs before the mint. Coder gives stop builds no owner session token, so revoking at stop is not possible. The README says so, and also says that the token is in Terraform state. aws_regionhas no validation. It reaches the Squiddstdomainline, so add a Region format check.- Kiro by default. Kiro sends model traffic outside AI Gateway, so take it out of
default_egress_bundles. It stays offered, but becomes opt-in. - README: recommend
aws:SourceVpce(S3 gateway endpoint) oraws:SourceIp(NAT) conditions on the workspace role, because Pod Identity credentials that leave the workspace work from anywhere.
Scope and correctness
6. Remove kube_host, kube_ca_certificate and kube_token, plus the matching README text. This template targets one cluster with Coder and Nitro Sandboxes, and dropping them also removes a sensitive variable.
7. Remove the kata-qemu and gvisor examples and the Kata comment in start-agent.sh.
8. Firewall demo: probe AI Gateway with a 1-token POST /v1/messages, because Bedrock providers do not serve /v1/models.
9. README: a bundle the profile does not offer is not ignored. Passed from the CLI, it fails the build (tested).
10. README: coder templates push keeps a variable's previous value when the file leaves it out. To clear one, pass --variable name=.
11. The registry requires the namespace avatar to be avatar.png or avatar.svg. Convert avatar.jpeg to a 400x400 PNG and update registry/dahr/README.md. This part is not in the text diff below.
Tested
terraform test: 13 of 13 pass (4 new: region injection, Kiro opt-in, revoke before mint on start, no mint on stop).terraform fmt, Prettier, ShellCheck (--severity=warning),cmd/readmevalidationand typos all pass.- Live on EKS 1.37 with Auto Mode and Nitro Sandboxes, as a separate template:
- Workspace verification: 33/0/1 (Claude Code and Kiro profile) and 30/0/1 (Coder Agents profile).
- Platform checks: 18 pass, 0 fail, including a two-workspace S3 isolation test.
- Firewall demo: AI Gateway HTTP 200.
- A restart revoked the old token and minted one new 8 h token.
Full diff against 36fb86b (text files)
diff --git a/registry/dahr/README.md b/registry/dahr/README.md
index 8125393..ea957bd 100644
--- a/registry/dahr/README.md
+++ b/registry/dahr/README.md
@@ -2,7 +2,7 @@
display_name: Dave Ahr
bio: DevRel and Labs at Coder
github: dahr
-avatar: ./.images/avatar.jpeg
+avatar: ./.images/avatar.png
status: community
---
diff --git a/registry/dahr/templates/governed-agents-nitro/README.md b/registry/dahr/templates/governed-agents-nitro/README.md
index 86fce2a..108e34d 100644
--- a/registry/dahr/templates/governed-agents-nitro/README.md
+++ b/registry/dahr/templates/governed-agents-nitro/README.md
@@ -18,7 +18,7 @@ Kernel isolation and network isolation are separate layers. A Nitro Sandbox does
### Kernel isolation
-When `sandbox_runtime_class` is `isolated-sandbox`, the workspace Pod sets that RuntimeClass. On EKS Auto Mode, the Pod then runs in a Nitro Sandbox, so code in the workspace does not share a kernel with the node or with other Pods. The VM gets its CPU and memory at boot from the Pod requests, so a Nitro workspace requests its full size of 2 vCPUs and 4 GiB. The variable also accepts other RuntimeClass names, such as `kata-qemu` or `gvisor`. When the value is empty, the Pod uses the node's default runtime and shares the node kernel.
+When `sandbox_runtime_class` is `isolated-sandbox`, the workspace Pod sets that RuntimeClass. On EKS Auto Mode, the Pod then runs in a Nitro Sandbox, so code in the workspace does not share a kernel with the node or with other Pods. The VM gets its CPU and memory at boot from the Pod requests, so a Nitro workspace requests its full size of 2 vCPUs and 4 GiB. When the value is empty, the Pod uses the node's default runtime and shares the node kernel.
The workspace container runs as UID 1000 with no Linux capabilities, no privilege escalation, the `RuntimeDefault` seccomp profile, and no Kubernetes service account token.
@@ -27,7 +27,7 @@ The workspace container runs as UID 1000 with no Linux capabilities, no privileg
1. **NetworkPolicy.** The workspace Pod accepts no inbound connections. It can connect out only to the Coder access URL addresses in `coder_egress_cidrs`, its own egress proxy, and the EKS Pod Identity Agent when it has an AWS identity. Your CNI must enforce NetworkPolicy, or this layer does nothing.
2. **No DNS.** The Pod's only name server is `127.0.0.1`, so lookups fail. The template writes the access URL host name to `/etc/hosts` from `coder_host_ip`. The proxy resolves all other names.
3. **Egress proxy.** Squid runs in a separate Pod for each workspace. It accepts only HTTPS `CONNECT` requests to port 443 for the host names in the chosen bundles. It refuses names that resolve to private or link-local addresses, does not decrypt TLS, and logs each request to its container output. Its own NetworkPolicy accepts traffic only from its workspace and allows out only public IPv4 addresses on port 443, plus DNS to the configured servers.
-4. **Policy gate.** The Coder agent waits until it cannot connect to the Kubernetes API server. The check then runs every 5 seconds and stops the container if the API server becomes reachable. If the API server remains reachable for 60 seconds, the container exits. This is a useful signal, not proof that every network rule works.
+4. **Policy gate.** The Coder agent waits until 3 connections in a row to the Kubernetes API server fail, each with a 1 second timeout, so one slow connection cannot open the gate. The check then runs every 5 seconds and stops the container if the API server becomes reachable. If the API server remains reachable for 60 seconds, the container exits. This is a useful signal, not proof that every network rule works.
5. **Upstream firewall (optional).** Set `node_pool` to the `key=value` label of a node group whose subnets send traffic through a firewall that you run, such as AWS Network Firewall. Workspace and proxy Pods then select those nodes and tolerate a `NoSchedule` taint with the same key and value. The template does not create or check that firewall.
The proxy Pod does not use the sandbox RuntimeClass. It runs on the node's normal container runtime as UID 31, with a read-only root filesystem and no capabilities.
@@ -52,7 +52,7 @@ The **Agent profile** is set at create and cannot change later. Each profile is
## Allowed destinations
-In the first two profiles, **Allowed destinations** picks bundles of reviewed host names for the proxy. The template offers bundles for GitHub, npm, PyPI, and Go modules, the Kiro CLI in the Claude Code and Kiro profile, and a demo bundle that opens `example.com`. GitHub is on by default, and so is Kiro where it is offered. A value that is not offered for the profile is ignored. The host names for each bundle are in `local.egress_bundles` in `main.tf`. To add one, add an entry there.
+In the first two profiles, **Allowed destinations** picks bundles of reviewed host names for the proxy. The template offers bundles for GitHub, npm, PyPI, and Go modules, the Kiro CLI in the Claude Code and Kiro profile, and a demo bundle that opens `example.com`. GitHub is on by default. Kiro is opt-in, because it sends model traffic outside AI Gateway. The form offers only the bundles of the chosen profile; a bundle the profile does not offer, passed from the CLI, fails the build. The host names for each bundle are in `local.egress_bundles` in `main.tf`. To add one, add an entry there.
You can change the bundles later in the workspace settings. The next start applies them: a checksum annotation on the proxy Pod restarts Squid with the new list. `extra_allowed_hosts` adds host names to every workspace that has a proxy.
@@ -76,7 +76,7 @@ Workspaces reach Coder by IP address only. Give the access URL static IPv4 addre
### Provisioner access
-The provisioner reaches the workspace cluster in one of three ways: in-cluster credentials when Coder runs in the same cluster, `~/.kube/config` with `use_kubeconfig`, or `kube_host`, `kube_ca_certificate`, and `kube_token` for a separate cluster.
+The provisioner reaches the workspace cluster with in-cluster credentials when Coder runs in the same cluster, or with `~/.kube/config` when `use_kubeconfig` is true.
The namespace must already exist. Label it for Pod Security `restricted`; both Pods meet that profile. The provisioner identity needs a Role in the namespace that covers every object the template manages, for example:
@@ -137,7 +137,7 @@ Then push from this directory:
coder templates push governed-agents-nitro -d . --variables-file ~/governed-agents-nitro.yaml
```
-If the provisioner uses `kube_token`, add it to this file only on the machine you push from. Set its permissions to `600` and do not commit it.
+Variables you leave out of the file keep their value from the previous version. To clear one, pass it explicitly, for example `--variable shared_service_account=`.
Prebuilds need Coder Premium. By default each of the three presets keeps one prebuilt workspace running; set `prebuild_instances` to `0` to turn them off.
@@ -147,8 +147,9 @@ Prebuilds need Coder Premium. By default each of the three presets keeps one pre
- **Without an upstream firewall,** the proxy connects from the node to any public IPv4 address that an allowed name resolves to. There is no second allowlist and no DNS filtering beyond your resolver, so the demo bundle reaches `example.com`. Setting `node_pool` only schedules on labeled nodes. It does not configure or verify network routing.
- **The proxy is not in a Nitro Sandbox.** It shares the node kernel with other Pods on its node. Its NetworkPolicy and Squid configuration limit what it accepts and where it connects.
- **NetworkPolicy depends on the CNI.** The policy gate checks only that the Kubernetes API server is unreachable. It does not prove every rule is in force.
-- **The scoped token is not limited to AI Gateway.** A `user:read_personal` token also works with other Coder API endpoints that allow that scope, from any network that reaches Coder. Any process in the workspace can read it. It lives for `ai_gateway_token_lifetime_hours`, Coder does not revoke it on stop, and each start creates a new one. Keep the lifetime close to the template's autostop time. The `session` mode token has full API access for the owner, but Coder deletes it on stop.
-- **Kiro bypasses AI Gateway.** AI Gateway does not record Kiro prompts. The proxy log records Kiro's connections.
+- **The scoped token is not limited to AI Gateway.** A `user:read_personal` token also works with other Coder API endpoints that allow that scope, from any network that reaches Coder. Any process in the workspace can read it. Each start revokes the workspace's earlier tokens with the `coder` CLI on the provisioner, so only the newest is valid. Coder gives stop builds no owner credentials, so the last token stays valid for up to `ai_gateway_token_lifetime_hours` (8 by default) after the workspace stops. Keep the lifetime close to the template's autostop time. Like the owner session token, the scoped token is stored unencrypted in Terraform state, which template admins can read. The `session` mode token has full API access for the owner, but Coder deletes it on stop.
+- **Kiro bypasses AI Gateway.** AI Gateway does not record Kiro prompts, so its bundle is opt-in. The proxy log records Kiro's connections.
+- **AWS credentials work outside your network.** Pod Identity credentials are ordinary temporary credentials. If an agent copied them to an allowed host that accepts uploads, they would work from anywhere until they expire. Add a condition to the workspace role's policy: `aws:SourceVpce` with your S3 gateway endpoint's ID for S3, or `aws:SourceIp` with your NAT gateway addresses for services reached through it. `aws:SourceVpc` and `aws:SourceVpce` are set only on requests through a VPC endpoint.
- **HTTPS on port 443 only.** SSH, plain HTTP, and other ports do not work through the proxy. Use Git over HTTPS. IPv4 only.
- **Fixed size in a Nitro Sandbox.** CPU and memory are set at boot. Check allocatable resources on your sandbox nodes before you change the size in `main.tf`.
diff --git a/registry/dahr/templates/governed-agents-nitro/firewall-demo.sh.tftpl b/registry/dahr/templates/governed-agents-nitro/firewall-demo.sh.tftpl
index c6b62a7..4490ec7 100644
--- a/registry/dahr/templates/governed-agents-nitro/firewall-demo.sh.tftpl
+++ b/registry/dahr/templates/governed-agents-nitro/firewall-demo.sh.tftpl
@@ -76,7 +76,10 @@ imdsprobe() {
run_probes() {
echo "##AI models"
- probe "Claude via AI Gateway (Coder)" -H "Authorization: Bearer $${ANTHROPIC_AUTH_TOKEN:-}" -H 'anthropic-version: 2023-06-01' "$${ANTHROPIC_BASE_URL:-$${CODER_AGENT_URL%/}/api/v2/ai-gateway/anthropic}/v1/models"
+ # A one-token model call: Bedrock providers serve /v1/messages only.
+ probe "Claude via AI Gateway (Coder)" -H "Authorization: Bearer $${ANTHROPIC_AUTH_TOKEN:-}" -H 'anthropic-version: 2023-06-01' -H 'content-type: application/json' \
+ -d '{"model":"claude-haiku-5-5","max_tokens":1,"messages":[{"role":"user","content":"ok"}]}' \
+ "$${ANTHROPIC_BASE_URL:-$${CODER_AGENT_URL%/}/api/v2/ai-gateway/anthropic}/v1/messages"
probe "Anthropic API directly" https://api.anthropic.com/v1/models
if [ -n "$KIRO_RUNTIME" ]; then
probe "Kiro service" "https://$KIRO_RUNTIME/"
diff --git a/registry/dahr/templates/governed-agents-nitro/main.tf b/registry/dahr/templates/governed-agents-nitro/main.tf
index 61298d9..d0bc9de 100644
--- a/registry/dahr/templates/governed-agents-nitro/main.tf
+++ b/registry/dahr/templates/governed-agents-nitro/main.tf
@@ -66,30 +66,6 @@ variable "use_kubeconfig" {
default = false
}
-variable "kube_host" {
- description = "API server URL of the cluster that runs workspaces, when it is not the cluster Coder runs in. Supply this from your EKS cluster."
- type = string
- default = ""
-
- validation {
- condition = var.kube_host == "" || startswith(var.kube_host, "https://")
- error_message = "kube_host must be empty or an https:// URL."
- }
-}
-
-variable "kube_ca_certificate" {
- description = "Base64 CA certificate of kube_host."
- type = string
- default = ""
-}
-
-variable "kube_token" {
- description = "Token of the provisioner's namespace-scoped service account in kube_host's cluster."
- type = string
- default = ""
- sensitive = true
-}
-
variable "namespace" {
description = "Namespace for workspaces. Create it with Pod Security and the provisioner Role before using the template."
type = string
@@ -152,7 +128,7 @@ variable "coder_host_ip" {
}
variable "sandbox_runtime_class" {
- description = "RuntimeClass for hardware isolation. The default isolated-sandbox runs on EKS Auto Mode with Nitro Sandboxes. Other installed runtimes, such as kata-qemu or gvisor, also work. Empty uses the node default runtime."
+ description = "RuntimeClass for hardware isolation. The default isolated-sandbox runs each workspace Pod in its own AWS Nitro Sandbox on EKS Auto Mode. Empty uses the node default runtime, which shares the node kernel."
type = string
default = "isolated-sandbox"
@@ -165,6 +141,11 @@ variable "sandbox_runtime_class" {
variable "aws_region" {
description = "AWS Region of the EKS cluster and the artifacts bucket."
type = string
+
+ validation {
+ condition = can(regex("^[a-z]{2}(-[a-z]+)+-[0-9]+$", var.aws_region))
+ error_message = "aws_region must be an AWS Region name, such as us-east-1."
+ }
}
variable "eks_cluster_name" {
@@ -242,7 +223,7 @@ variable "extra_allowed_hosts" {
}
variable "ai_gateway_token_mode" {
- description = "Coder token that Claude Code sends to AI Gateway. scoped: a new token limited to user:read_personal, which expires after ai_gateway_token_lifetime_hours but is not attributed to the workspace in AI Gateway. session: the owner's workspace session token, which AI Gateway attributes to the workspace and Coder deletes on stop, but which has full API access."
+ description = "Coder token that Claude Code sends to AI Gateway. scoped: a new token limited to user:read_personal. Each start revokes the workspace's earlier ones, and each expires after ai_gateway_token_lifetime_hours. AI Gateway does not attribute it to the workspace. session: the owner's workspace session token, which AI Gateway attributes to the workspace and Coder deletes on stop, but which has full API access."
type = string
default = "scoped"
@@ -253,9 +234,14 @@ variable "ai_gateway_token_mode" {
}
variable "ai_gateway_token_lifetime_hours" {
- description = "Lifetime of the scoped AI Gateway token. Keep it near the template's autostop time. It cannot exceed the deployment's maximum token lifetime."
+ description = "Lifetime of the scoped AI Gateway token. Coder cannot revoke it at stop, so this is how long it stays valid after the workspace stops. Keep it near the template's autostop time. It cannot exceed the deployment's maximum token lifetime."
type = number
- default = 24
+ default = 8
+
+ validation {
+ condition = var.ai_gateway_token_lifetime_hours >= 1 && var.ai_gateway_token_lifetime_hours <= 168 && floor(var.ai_gateway_token_lifetime_hours) == var.ai_gateway_token_lifetime_hours
+ error_message = "ai_gateway_token_lifetime_hours must be a whole number from 1 to 168."
+ }
}
variable "ai_gateway_provider" {
@@ -338,10 +324,7 @@ variable "github_external_auth_id" {
}
provider "kubernetes" {
- config_path = var.kube_host == "" && var.use_kubeconfig ? "~/.kube/config" : null
- host = var.kube_host != "" ? var.kube_host : null
- cluster_ca_certificate = var.kube_host != "" ? base64decode(var.kube_ca_certificate) : null
- token = var.kube_host != "" ? var.kube_token : null
+ config_path = var.use_kubeconfig ? "~/.kube/config" : null
}
# The provisioner uses its own AWS credentials when it creates an association.
@@ -472,7 +455,9 @@ locals {
} : k => b if var.enable_kiro
},
)
- default_egress_bundles = ["github", "kiro"]
+ # Kiro is opt-in: it sends model traffic to its own service, outside AI
+ # Gateway, so a user must choose its bundle.
+ default_egress_bundles = ["github"]
private_cidrs = ["10.0.0.0/8", "100.64.0.0/10", "169.254.0.0/16", "172.16.0.0/12", "192.168.0.0/16"]
dns_servers = var.dns_servers != "" ? [for server in split(",", var.dns_servers) : trimspace(server)] : ["169.254.169.253"]
@@ -1354,9 +1339,16 @@ module "git-clone" {
# --------------------------------------------------------------------------
# The owner's session token has full Coder API access. This template uses
-# it once at build time to mint a token with only the user:read_personal
-# scope, which AI Gateway accepts. timestamp() defers the request to apply,
-# so a plan creates nothing, and a prebuild gets its token when it is claimed.
+# it at build time to mint a token with only the user:read_personal scope,
+# which AI Gateway accepts. timestamp() defers the request to apply, so a
+# plan creates nothing, and a prebuild gets its token when it is claimed.
+#
+# Every start first revokes this workspace's earlier scoped tokens, so only
+# the newest one is valid. Coder gives stop and delete builds no owner
+# session token, so the template cannot revoke at stop: the last token stays
+# valid until ai_gateway_token_lifetime_hours runs out. Like the owner
+# session token, the minted token is stored unencrypted in Terraform state,
+# which template admins can read.
locals {
ai_gateway_token_ready = (
local.claude &&
@@ -1364,7 +1356,26 @@ locals {
!data.coder_workspace.me.is_prebuild &&
data.coder_workspace_owner.me.session_token != ""
)
- mint_ai_gateway_token = local.ai_gateway_token_ready && var.ai_gateway_token_mode == "scoped"
+ mint_ai_gateway_token = local.ai_gateway_token_ready && var.ai_gateway_token_mode == "scoped"
+ ai_gateway_token_prefix = "ai-gateway-${substr(data.coder_workspace.me.id, 0, 8)}-"
+}
+
+# Runs on the provisioner, which ships the coder CLI. Best effort: a failure
+# must not block the start, and the old tokens still expire on their own.
+resource "terraform_data" "revoke_ai_gateway_tokens" {
+ count = local.mint_ai_gateway_token ? 1 : 0
+ triggers_replace = timestamp()
+
+ provisioner "local-exec" {
+ interpreter = ["/bin/sh", "-c"]
+ command = "coder tokens list -c id,name | awk -v p=\"$TOKEN_PREFIX\" 'NR > 1 && index($2, p) == 1 { print $1 }' | while read -r id; do coder tokens remove --delete \"$id\" > /dev/null; done"
+ on_failure = continue
+ environment = {
+ CODER_URL = local.access_url
+ CODER_SESSION_TOKEN = data.coder_workspace_owner.me.session_token
+ TOKEN_PREFIX = local.ai_gateway_token_prefix
+ }
+ }
}
data "http" "ai_gateway_token" {
@@ -1376,12 +1387,16 @@ data "http" "ai_gateway_token" {
"Content-Type" = "application/json"
}
request_body = jsonencode({
- token_name = "ai-gateway-${substr(data.coder_workspace.me.id, 0, 8)}-${formatdate("YYYYMMDDhhmmss", timestamp())}"
+ token_name = "${local.ai_gateway_token_prefix}${formatdate("YYYYMMDDhhmmss", timestamp())}"
scopes = ["user:read_personal"]
# time.Duration in nanoseconds.
lifetime = var.ai_gateway_token_lifetime_hours * 3600 * 1000000000
})
+ # Revoke the earlier tokens first, or the revocation would also match the
+ # new one.
+ depends_on = [terraform_data.revoke_ai_gateway_tokens]
+
lifecycle {
postcondition {
condition = self.status_code == 201
diff --git a/registry/dahr/templates/governed-agents-nitro/start-agent.sh b/registry/dahr/templates/governed-agents-nitro/start-agent.sh
index 506bab3..cfb6ffd 100755
--- a/registry/dahr/templates/governed-agents-nitro/start-agent.sh
+++ b/registry/dahr/templates/governed-agents-nitro/start-agent.sh
@@ -8,29 +8,41 @@
# allow the Kubernetes API server, so a connection to it that fails proves
# the policy is in force. After start, the same check runs every 5 seconds,
# and the container stops if the API server becomes reachable. Fail closed:
-# a slow reply, or a check that prints nothing, counts as reachable.
+# a check that prints nothing counts as reachable, and the gate opens only
+# after 3 failed connections in a row, each with a 1 second timeout, so one
+# slow connection cannot open it.
+
+if [ -z "${KUBERNETES_SERVICE_HOST:-}" ] || [ -z "${KUBERNETES_SERVICE_PORT:-}" ]; then
+ echo "policy gate: KUBERNETES_SERVICE_HOST is not set, so the check cannot run, exiting" >&2
+ exit 1
+fi
api="https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT/"
api_open() {
- r=$(curl -sk -o /dev/null --noproxy '*' --connect-timeout 0.3 -m 1 -w '%{http_code} %{time_connect}' "$api" 2> /dev/null)
+ r=$(curl -sk -o /dev/null --noproxy '*' --connect-timeout 1 -m 2 -w '%{http_code} %{time_connect}' "$api" 2> /dev/null)
[ -z "$r" ] && return 0
awk -v t="${r#* }" 'BEGIN { exit !(t + 0 > 0) }'
}
-i=0
-while api_open; do
- i=$((i + 1))
- if [ "$i" -ge 240 ]; then
- echo "policy gate: NetworkPolicy is not enforced after 60 s, exiting" >&2
- exit 1
+closed=0
+deadline=$((SECONDS + 60))
+while [ "$closed" -lt 3 ]; do
+ if api_open; then
+ closed=0
+ if [ "$SECONDS" -ge "$deadline" ]; then
+ echo "policy gate: NetworkPolicy is not enforced after 60 s, exiting" >&2
+ exit 1
+ fi
+ sleep 0.25
+ else
+ closed=$((closed + 1))
fi
- sleep 0.25
done
-echo "policy gate: NetworkPolicy enforced after $i checks" >&2
+echo "policy gate: NetworkPolicy enforced after $SECONDS s" >&2
-# The agent must be PID 1, or the web terminal gets no input under Kata.
-# So the re-check runs in the background.
+# The agent runs as PID 1 (exec below), so the re-check runs in the
+# background.
(
while sleep 5; do
if api_open; then
diff --git a/registry/dahr/templates/governed-agents-nitro/tests/inputs.tftest.hcl b/registry/dahr/templates/governed-agents-nitro/tests/inputs.tftest.hcl
index e7ed480..9b78ca1 100644
--- a/registry/dahr/templates/governed-agents-nitro/tests/inputs.tftest.hcl
+++ b/registry/dahr/templates/governed-agents-nitro/tests/inputs.tftest.hcl
@@ -140,3 +140,80 @@ run "accepts_public_hosts_and_dns" {
error_message = "Valid host names and DNS servers must reach the proxy configuration."
}
}
+
+run "rejects_squid_directive_in_region" {
+ command = plan
+ variables {
+ aws_region = "us-east-1\nhttp_access allow all"
+ }
+ expect_failures = [var.aws_region]
+}
+
+run "kiro_is_opt_in" {
+ command = plan
+
+ override_data {
+ target = data.coder_parameter.profile
+ values = { value = "workspace-agents" }
+ }
+
+ assert {
+ condition = contains(keys(local.offered_bundles), "kiro") && !contains(local.default_egress_bundles, "kiro")
+ error_message = "Kiro sends model traffic outside AI Gateway, so its bundle must be offered but not chosen by default."
+ }
+}
+
+run "start_revokes_earlier_tokens_before_minting" {
+ command = plan
+
+ override_data {
+ target = data.coder_workspace.me
+ values = {
+ id = "00000000-0000-4000-8000-000000000001"
+ name = "test"
+ access_url = "https://203.0.113.10"
+ start_count = 1
+ transition = "start"
+ is_prebuild = false
+ }
+ }
+ override_data {
+ target = data.coder_workspace_owner.me
+ values = {
+ id = "00000000-0000-4000-8000-000000000002"
+ name = "tester"
+ session_token = "owner-session-token"
+ }
+ }
+ override_data {
+ target = data.coder_parameter.profile
+ values = { value = "workspace-agents" }
+ }
+ override_data {
+ target = data.coder_parameter.egress_bundles
+ values = { value = "[\"github\"]" }
+ }
+ override_module {
+ target = module.code-server
+ outputs = {}
+ }
+
+ assert {
+ condition = length(terraform_data.revoke_ai_gateway_tokens) == 1 && length(data.http.ai_gateway_token) == 1 && var.ai_gateway_token_lifetime_hours == 8
+ error_message = "A start must revoke the workspace's earlier tokens and mint one with an 8 hour default lifetime."
+ }
+}
+
+run "stop_mints_no_token" {
+ command = plan
+
+ override_data {
+ target = data.coder_parameter.profile
+ values = { value = "workspace-agents" }
+ }
+
+ assert {
+ condition = length(terraform_data.revoke_ai_gateway_tokens) == 0 && length(data.http.ai_gateway_token) == 0 && length(coder_env.anthropic_auth_token) == 0
+ error_message = "A stop has no owner credentials, so it must mint no token and pass none to the workspace."
+ }
+}This review was generated by Coder Agents on behalf of @daveahr2172 (@dahr).
…mespace Apply Dave's security and scope fixes: a stricter policy gate, an 8 hour scoped AI Gateway token that each start revokes and replaces, Region validation, Kiro as opt-in, a source condition note for AWS credentials, no separate-cluster provider variables, and a firewall demo probe that works with Bedrock. Convert the avatar to a 400x400 PNG. Move the namespace from dahr to daveahr2172, the account Dave uses in the coder organization. Co-authored-by: Dave Ahr <[email protected]>
daveahr2172
left a comment
There was a problem hiding this comment.
Approving at 9dd05db. All six template files and the avatar match the version I tested on EKS with Nitro Sandboxes, and CI passes. The daveahr2172 namespace is fine.
This approval was generated by Coder Agents on behalf of @daveahr2172.
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.
…1270) Renames the `daveahr2172/governed-agents-nitro` template from "Agent Workspaces on EKS with Nitro Sandboxes" to "AWS Nitro Sandboxes", in the `display_name` and the README heading. This is the name shown on https://registry.coder.com/templates/daveahr2172/governed-agents-nitro. The template ID, description, and code are unchanged, so existing pushes and links keep working. Follow-up to #1253. 🤖 This PR was generated by Coder Agents on behalf of @bpmct. Co-authored-by: Dave Ahr <[email protected]> Co-authored-by: DevCats <[email protected]>
…bes, gate wording (#1268) ## Description Brings `registry/daveahr2172/templates/governed-agents-nitro` up to date with the Nov 18 changes from the live Nitro Sandbox deployment (EKS 1.37, Auto Mode), after review of #1253. - **Disk limits:** ephemeral-storage 8 GiB on the workspace and 256 MiB on the proxy, and a 2 GiB size limit on `/tmp`. In a Nitro Sandbox the kubelet cannot measure disk use; the sandbox gets a disk the size of the limit and writes past it fail with `ENOSPC` (measured live; `/tmp` `sizeLimit` is not enforced there, so the README says so). - **Firewall demo, GitHub rows:** an unauthenticated 401 now reads "no credential sent; the network allowed it" instead of "only credentials stop it". With `github_external_auth_id` set, new rows use the owner's linked GitHub credential with writes that are well formed but cannot succeed (a branch at an all-zero commit, a gist with an empty file), so nothing is created. A 403 or 404 is reported as denied, with GitHub's reason. A 422 is reported as unclear: the request is invalid, so it does not show that the credential may write, and no permitted write was tested. Empty request bodies were not a valid test: GitHub answered a branch creation in `coder/coder` with 422 although the token has no push access there. - **Policy gate:** described as a readiness check, not a security boundary (the workspace user can kill it, and any failed connection counts as closed). - **README:** recommends `networkPolicy: DefaultDeny` on the Auto Mode NodeClass, adds a stop procedure with an optional quarantine ClusterNetworkPolicy, and notes that network stops leave established connections open. - **README, enforce placement:** the cluster does not require the template's node pool or sandbox RuntimeClass, so the README adds an example `ValidatingAdmissionPolicy` that does (node affinity required, no `spec.nodeName`, sandbox RuntimeClass except for the proxy), rolled out with Warn/Audit first. Checked with a server-side dry run on EKS 1.37 (compiles, nothing created) and with cel-go against 11 Pod shapes; not yet enforced on a live cluster. A new test run, `pods_meet_the_readme_placement_policy`, fails if the template's Pods stop matching the policy's node affinity, RuntimeClass, or proxy label rules. - **README, stop procedure:** the proxy log lives only in the proxy container's stdout, so `coder stop` deletes it. The README now says to ship proxy container logs to a log store first, for example with a platform-owned log DaemonSet on the agent nodes. Tested on EKS with Fluent Bit: a request made just before `coder stop` was in CloudWatch Logs after the Pod was gone. - **Providers:** pinned with `~>` to the tested versions. ## Type of Change - [x] Bug fix - [x] Feature/enhancement - [x] Documentation ## Template Information **Path:** `registry/daveahr2172/templates/governed-agents-nitro` ## Testing & Validation - [x] `terraform validate` and `terraform test` (15 passing, 2 new runs and 4 new assertions) - [x] After review: the 422 wording fix (`57d0300`) was checked with stubbed responses and live on labs with the same probe code - [x] `bun run fmt`, ShellCheck (`--severity=warning`, including the rendered demo script), `cmd/readmevalidation`, and typos - [x] Live on EKS 1.37 Auto Mode with Nitro Sandboxes, from the source repo at the same changes: disk limit (ENOSPC at 8 GiB), DefaultDeny and quarantine (new connections blocked, open connections stay up), and the GitHub rows with Coder's built-in GitHub provider (`/user` 200; branch in an org repo, branch in a personal repo, and gist all denied with 403 "Resource not accessible by integration"; nothing created). ## Related Issues Follow-up to #1253. Generated with Coder Agents on behalf of @daveahr2172.
Description
Pull Dave Ahr's active Nitro Sandbox template into his
daveahr2172namespace. The README states the cluster, images, IAM role, and optional firewall setup that users must provide. The template defaults to Nitro, validates proxy, Region, and demo inputs, and no longer claims an upstream firewall exists just because a node pool was selected. Dave is a Git co-author.Dave's review is applied as he sent it:
KUBERNETES_SERVICE_HOSTis unset.coderCLI on the provisioner before it mints a new one. Stop builds get no owner session token, so the last token stays valid until it expires. The README says so, and that the token is in Terraform state.aws:SourceVpceoraws:SourceIpconditions on the workspace role, and explains how--variable name=clears a variable.kube_host,kube_ca_certificate, andkube_tokenvariables, and the Kata and gVisor examples.POST /v1/messages, which Bedrock providers serve.avatar.png, 400x400.Type of Change
Template Information
Path:
registry/daveahr2172/templates/governed-agents-nitroTesting & Validation
terraform validateandterraform test(13 passing)terraform fmt, Prettier, ShellCheck (--severity=warning),cmd/readmevalidation, and typos36fb86bwith his diff)Related Issues
None.
Source comparison and decisions
coder/devrel. It moves workspace metadata to the agent-token resource so Coder shows it on the workspace page. This PR starts from that active version. The source does not include thecluster/,build/, orTESTING.mdfiles named in its old README, so the guide treats those components as prerequisites.daveahr2172is the account Dave uses in thecoderorg.dahris his personal account. The earlier two commits still creditdahras co-author. The new commit creditsdaveahr2172.coder tokens list -c id,nameandcoder tokens remove --deleteexist in the current CLI (cli/tokens.goin coder/coder).Prepared by Coder Agents for Ben Potter. The PR is opened as
bpmct, not as Dave.