Skip to content

feat(coder/modules/boundary): add boundary module#840

Open
35C4n0r wants to merge 78 commits intomainfrom
35C4n0r/feat-boundary-module
Open

feat(coder/modules/boundary): add boundary module#840
35C4n0r wants to merge 78 commits intomainfrom
35C4n0r/feat-boundary-module

Conversation

@35C4n0r
Copy link
Copy Markdown
Collaborator

@35C4n0r 35C4n0r commented Apr 13, 2026

Description

Extracts boundary installation and wrapper logic into a standalone coder/agent-firewall module, decoupling it from agentapi.

Why

Boundary is currently embedded inside agentapi (scripts/boundary.sh) and duplicated in claude-code. This couples network isolation to the AI/Tasks stack, but boundary is a general-purpose primitive — users running a plain agent with no agentapi or tasks should be able to use it too.

What this adds

registry/coder/modules/agent-firewall/ — a new first-class module that:

  • Installs boundary via one of three strategies:
    1. coder boundary subcommand (default, zero-install)
    2. Direct binary from release (use_agent_firewall_directly = true)
    3. Compiled from source (compile_agent_firewall_from_source = true)
  • Ships a comprehensive default allowlist config (Anthropic, OpenAI, VCS, package managers, cloud platforms, etc.)
  • Auto-fills the Coder deployment domain via data.coder_workspace.me.access_url
  • Supports inline config (agent_firewall_config) or external file (agent_firewall_config_path), mutually exclusive with cross-variable validation
  • Creates a wrapper script at $HOME/.coder-modules/coder/agent-firewall/scripts/agent-firewall-wrapper.sh
  • Strips CAP_NET_ADMIN from the coder binary (copies to coder-no-caps) to allow execution inside network namespaces without sys_admin
  • Supports pre_install_script / post_install_script hooks
  • Exposes agent_firewall_wrapper_path, agent_firewall_config_path, and scripts outputs for script coordination
  • No env vars exported — everything is output-only

Usage

module "agent-firewall" {
  source   = "registry.coder.com/coder/agent-firewall/coder"
  version  = "0.0.1"
  agent_id = coder_agent.main.id
}

Works standalone with any agent — no agentapi dependency required.

Testing

  • 8 Terraform plan tests (agent-firewall.tftest.hcl): default outputs, compile from source, use directly, custom hooks, custom module directory, inline config, external config path, mutual exclusion validation
  • TypeScript integration tests (main.test.ts): state verification, coder subcommand happy path, inline config, config path skip, custom hooks, env var absence, wrapper execution, idempotent installation

Type of Change

  • New module

Module Information

Path: registry/coder/modules/agent-firewall
New version: v0.0.1
Breaking change: No

Related Issues

Closes #844

🤖 Generated by Coder Agents

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new coder/boundary registry module intended to set up Boundary-related tooling for Coder workspaces.

Changes:

  • Introduces a Boundary install/setup shell script that can compile from source, install from release, or rely on coder boundary.
  • Adds a Terraform module (main.tf) that deploys and runs the install script on an agent.
  • Adds module README and Terraform native tests (.tftest.hcl).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
registry/coder/modules/boundary/scripts/install.sh Installs Boundary (or validates coder boundary) and generates a wrapper script.
registry/coder/modules/boundary/main.tf Defines module variables and a coder_script to deliver/execute install.sh.
registry/coder/modules/boundary/README.md Documents module usage and examples.
registry/coder/modules/boundary/boundary.tftest.hcl Adds Terraform plan-time assertions for basic module wiring.

Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/main.tf Outdated
Comment thread registry/coder/modules/agent-firewall/README.md Outdated
@35C4n0r 35C4n0r marked this pull request as draft April 13, 2026 03:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Comment thread registry/coder/modules/boundary/main.tf Outdated
Comment thread registry/coder/modules/boundary/main.tf Outdated
Comment thread registry/coder/modules/boundary/main.test.ts Outdated
Comment thread registry/coder/modules/boundary/testdata/boundary-mock.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Comment thread registry/coder/modules/boundary/scripts/install.sh Outdated
Jay Kumar and others added 8 commits April 14, 2026 18:19
…missing mock support

Three root causes:

1. boundary_script_destination used 'install.sh' - same filename that coder-utils
   writes to. This caused the running script to overwrite itself, corrupting
   bash's incremental read and producing empty install.log / no wrapper.
   Fix: rename to 'boundary-install.sh'.

2. coder-mock.sh didn't handle 'coder exp sync' commands used by coder-utils
   for script ordering. With set -o errexit, scripts failed immediately.
   Fix: add exp sync as no-op (exit 0).

3. Test setup used setupUtil which only extracts ONE coder_script, but
   coder-utils creates multiple (pre_install, install, post_install).
   Fix: extract all coder_scripts from terraform state and run them
   sequentially in lifecycle order.

4. wrapper-script-execution test called 'wrapper.sh --help' which the mock
   couldn't handle after the '--' separator (tried to exec '--help').
   Fix: test with 'echo boundary-test' instead.
The boundary command (both 'coder boundary' and standalone 'boundary')
expects a '--' separator before the command to execute. The wrapper
scripts were passing arguments directly without this separator, causing
the wrapper-script-execution test to fail.

🤖 Generated by Coder Agents
The boundary wrapper scripts pass arguments directly without a '--'
separator. Updated the coder mock to match this behavior and adjusted
the test comment accordingly.

🤖 Generated by Coder Agents
@35C4n0r 35C4n0r marked this pull request as ready for review April 15, 2026 17:27
@matifali matifali requested review from SasSwart, dannykopping and jcjiang and removed request for matifali April 16, 2026 04:50
@35C4n0r
Copy link
Copy Markdown
Collaborator Author

35C4n0r commented May 7, 2026

/coder-agents-review

35C4n0r and others added 10 commits May 7, 2026 11:27
base64 decode outputs the literal string '$HOME/...' — command
substitution does not expand variables in its output. Add an
explicit bash parameter substitution step for all path variables.
Plain strings and paths are injected directly with single/double
quotes. Only the config content needs base64 since it is arbitrary
multi-line YAML from user input.
…nt printf

- Revert log_dir back to /tmp/boundary_logs (static default)
- Remove BOUNDARY_LOG_DIR template variable
- Remove jail_type: landjail (debug leftover)
- Remove printf for BOUNDARY_CONFIG_CONTENT (too verbose)
@35C4n0r 35C4n0r marked this pull request as ready for review May 7, 2026 07:52
@DevelopmentCats
Copy link
Copy Markdown
Collaborator

Reviewing and testing this morning.

Comment thread registry/coder/modules/boundary/config.yaml.tftpl Outdated
Comment thread registry/coder/modules/agent-firewall/boundary.tftest.hcl Outdated

- Installs boundary (via coder subcommand, direct installation, or compilation from source)
- Creates a wrapper script at `$HOME/.coder-modules/coder/boundary/scripts/boundary-wrapper.sh`
- Writes a default boundary config to `$HOME/.coder-modules/coder/boundary/config/config.yaml` (customizable)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Writes a default boundary config to `$HOME/.coder-modules/coder/boundary/config/config.yaml` (customizable)
- Writes a [default boundary config](./config.yaml.tftpl) to `$HOME/.coder-modules/coder/boundary/config/config.yaml` (customizable)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matifali Writes a default boundary config
will this render as a valid url in registry ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good question. @DevelopmentCats do you know?

Comment thread registry/coder/modules/boundary/README.md Outdated
Comment thread registry/coder/modules/boundary/README.md Outdated
Comment thread registry/coder/modules/boundary/README.md Outdated
35C4n0r and others added 3 commits May 7, 2026 20:08
…n config at runtime

- Rename all public input variables: boundary_* -> agent_firewall_*
- Rename outputs: boundary_wrapper_path -> agent_firewall_wrapper_path,
  boundary_config_path -> agent_firewall_config_path
- Set log_dir to $HOME/.coder-modules/coder/boundary/logs/boundary_logs
  in default config template
- Expand $HOME in config content via sed at runtime before writing to
  disk, so the config contains absolute paths
- Internals (locals, template vars, script logic) unchanged
35C4n0r

This comment was marked as duplicate.

@matifali
Copy link
Copy Markdown
Member

matifali commented May 7, 2026

Lets rename the module path to agent-firewall

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lest move this all to registry/coder/modules/agent-firewall

Comment on lines +2 to +6
display_name: Boundary
description: Configures boundary for network isolation in Coder workspaces
icon: ../../../../.icons/coder.svg
verified: true
tags: [boundary, ai, agents, firewall]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
display_name: Boundary
description: Configures boundary for network isolation in Coder workspaces
icon: ../../../../.icons/coder.svg
verified: true
tags: [boundary, ai, agents, firewall]
display_name: Agent Firewall
description: Configures agent firewall for network isolation in Coder workspaces
icon: ../../../../.icons/coder.svg
verified: true
tags: [boundary, ai, agents, firewall]

While we are at it, let's rename the front-facing content.

Comment on lines +9 to +27
# Boundary

Installs [boundary](https://coder.com/docs/ai-coder/agent-firewall) for network isolation in Coder workspaces.

This module:

- Installs boundary (via coder subcommand, direct installation, or compilation from source)
- Creates a wrapper script at `$HOME/.coder-modules/coder/boundary/scripts/boundary-wrapper.sh`
- Writes a default boundary config to `$HOME/.coder-modules/coder/boundary/config/config.yaml` (customizable)
- Provides the wrapper path, config path, and script names via outputs
- Uses coder-utils and output `scripts` for synchronization. https://registry.coder.com/modules/coder/coder-utils?tab=outputs

```tf
module "boundary" {
source = "registry.coder.com/coder/boundary/coder"
version = "0.0.1"
agent_id = coder_agent.main.id
}
```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Boundary
Installs [boundary](https://coder.com/docs/ai-coder/agent-firewall) for network isolation in Coder workspaces.
This module:
- Installs boundary (via coder subcommand, direct installation, or compilation from source)
- Creates a wrapper script at `$HOME/.coder-modules/coder/boundary/scripts/boundary-wrapper.sh`
- Writes a default boundary config to `$HOME/.coder-modules/coder/boundary/config/config.yaml` (customizable)
- Provides the wrapper path, config path, and script names via outputs
- Uses coder-utils and output `scripts` for synchronization. https://registry.coder.com/modules/coder/coder-utils?tab=outputs
```tf
module "boundary" {
source = "registry.coder.com/coder/boundary/coder"
version = "0.0.1"
agent_id = coder_agent.main.id
}
```
# Agent Firewall
Installs [Agent Firewall](https://coder.com/docs/ai-coder/agent-firewall) for network isolation in Coder workspaces.
```tf
module "agent-firewall" {
source = "registry.coder.com/coder/agent-firewall/coder"
version = "0.0.1"
agent_id = coder_agent.main.id
}

And similarly at other places. 

@35C4n0r 35C4n0r force-pushed the 35C4n0r/feat-boundary-module branch from f58688c to f255d6c Compare May 7, 2026 17:58
Copy link
Copy Markdown
Member

@matifali matifali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks

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.

Decouple boundary into its own standalone module

5 participants