From a30ef222d5538b388d11267afa401c0bdab707c6 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 6 Oct 2025 11:00:36 -0500 Subject: [PATCH] init simple integration --- registry/coder/modules/claude-code/main.tf | 17 ++++++++++++ .../coder/modules/claude-code/main.tftest.hcl | 26 +++++++++++++++++++ .../modules/claude-code/scripts/start.sh | 18 ++++++++++++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 4836347b..4d2ad66c 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -192,6 +192,18 @@ variable "claude_md_path" { default = "$HOME/.claude/CLAUDE.md" } +variable "enable_boundary" { + type = bool + description = "Whether to enable coder boundary for network filtering" + default = false +} + +variable "boundary_log_dir" { + type = string + description = "Directory for boundary logs" + default = "/tmp/boundary_logs" +} + resource "coder_env" "claude_code_md_path" { count = var.claude_md_path == "" ? 0 : 1 @@ -231,6 +243,8 @@ locals { start_script = file("${path.module}/scripts/start.sh") module_dir_name = ".claude-module" remove_last_session_id_script_b64 = base64encode(file("${path.module}/scripts/remove-last-session-id.sh")) + # Extract hostname from access_url for boundary --allow flag + coder_host = replace(replace(data.coder_workspace.me.access_url, "https://", ""), "http://", "") } module "agentapi" { @@ -270,6 +284,9 @@ module "agentapi" { ARG_PERMISSION_MODE='${var.permission_mode}' \ ARG_WORKDIR='${local.workdir}' \ ARG_AI_PROMPT='${base64encode(var.ai_prompt)}' \ + ARG_ENABLE_BOUNDARY='${var.enable_boundary}' \ + ARG_BOUNDARY_LOG_DIR='${var.boundary_log_dir}' \ + ARG_CODER_HOST='${local.coder_host}' \ /tmp/start.sh EOT diff --git a/registry/coder/modules/claude-code/main.tftest.hcl b/registry/coder/modules/claude-code/main.tftest.hcl index c48923cf..55eedd5e 100644 --- a/registry/coder/modules/claude-code/main.tftest.hcl +++ b/registry/coder/modules/claude-code/main.tftest.hcl @@ -187,3 +187,29 @@ run "test_claude_code_permission_mode_validation" { error_message = "Permission mode should be one of the valid options" } } + +run "test_claude_code_with_boundary" { + command = plan + + variables { + agent_id = "test-agent-boundary" + workdir = "/home/coder/boundary-test" + enable_boundary = true + boundary_log_dir = "/tmp/test-boundary-logs" + } + + assert { + condition = var.enable_boundary == true + error_message = "Boundary should be enabled" + } + + assert { + condition = var.boundary_log_dir == "/tmp/test-boundary-logs" + error_message = "Boundary log dir should be set correctly" + } + + assert { + condition = local.coder_host != "" + error_message = "Coder host should be extracted from access URL" + } +} diff --git a/registry/coder/modules/claude-code/scripts/start.sh b/registry/coder/modules/claude-code/scripts/start.sh index b5fca7a5..ccc22d90 100644 --- a/registry/coder/modules/claude-code/scripts/start.sh +++ b/registry/coder/modules/claude-code/scripts/start.sh @@ -15,6 +15,9 @@ ARG_DANGEROUSLY_SKIP_PERMISSIONS=${ARG_DANGEROUSLY_SKIP_PERMISSIONS:-} ARG_PERMISSION_MODE=${ARG_PERMISSION_MODE:-} ARG_WORKDIR=${ARG_WORKDIR:-"$HOME"} ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d) +ARG_ENABLE_BOUNDARY=${ARG_ENABLE_BOUNDARY:-false} +ARG_BOUNDARY_LOG_DIR=${ARG_BOUNDARY_LOG_DIR:-"/tmp/boundary_logs"} +ARG_CODER_HOST=${ARG_CODER_HOST:-} echo "--------------------------------" @@ -25,6 +28,9 @@ printf "ARG_DANGEROUSLY_SKIP_PERMISSIONS: %s\n" "$ARG_DANGEROUSLY_SKIP_PERMISSIO printf "ARG_PERMISSION_MODE: %s\n" "$ARG_PERMISSION_MODE" printf "ARG_AI_PROMPT: %s\n" "$ARG_AI_PROMPT" printf "ARG_WORKDIR: %s\n" "$ARG_WORKDIR" +printf "ARG_ENABLE_BOUNDARY: %s\n" "$ARG_ENABLE_BOUNDARY" +printf "ARG_BOUNDARY_LOG_DIR: %s\n" "$ARG_BOUNDARY_LOG_DIR" +printf "ARG_CODER_HOST: %s\n" "$ARG_CODER_HOST" echo "--------------------------------" @@ -74,7 +80,17 @@ function start_agentapi() { fi fi printf "Running claude code with args: %s\n" "$(printf '%q ' "${ARGS[@]}")" - agentapi server --type claude --term-width 67 --term-height 1190 -- claude "${ARGS[@]}" + + if [ "${ARG_ENABLE_BOUNDARY:-false}" = "true" ]; then + mkdir -p "$ARG_BOUNDARY_LOG_DIR" + printf "Starting with coder boundary enabled\n" + agentapi server --type claude --term-width 67 --term-height 1190 -- \ + coder boundary --log-dir "$ARG_BOUNDARY_LOG_DIR" \ + --allow "*.anthropic.com" --allow "$ARG_CODER_HOST" -- \ + claude "${ARGS[@]}" + else + agentapi server --type claude --term-width 67 --term-height 1190 -- claude "${ARGS[@]}" + fi } validate_claude_installation