Skip to content

Commit 1de4bcd

Browse files
Add Coder template for jail development
Creates a comprehensive Coder template specifically designed for developing the jail network isolation tool. The template provisions AWS EC2 VMs with: - Ubuntu 22.04 LTS for modern kernel namespace support - Go 1.24+ development environment - Network tools (iptables, netfilter, tcpdump) for jail functionality - Pre-installed jail binary built from source - Code Server and JetBrains IDE support - Proper network configuration for namespace operations The template is optimized for jail's requirements including: - Linux VM environment (not containers) for namespace syscalls - Network forwarding and netfilter configuration - Development tools and debugging utilities - Comprehensive documentation and validation script Co-authored-by: bcpeinhardt <[email protected]>
1 parent 1e687be commit 1de4bcd

File tree

6 files changed

+789
-0
lines changed

6 files changed

+789
-0
lines changed

template/.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Terraform files
2+
*.tfstate
3+
*.tfstate.*
4+
*.tfvars
5+
*.tfvars.json
6+
.terraform/
7+
.terraform.lock.hcl
8+
terraform.log
9+
10+
# OS generated files
11+
.DS_Store
12+
.DS_Store?
13+
._*
14+
.Spotlight-V100
15+
.Trashes
16+
ehthumbs.db
17+
Thumbs.db
18+
19+
# IDE files
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# Temporary files
27+
*.tmp
28+
*.temp

template/README.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
display_name: Jail Development Environment (AWS EC2)
3+
description: AWS EC2 Linux VM optimized for developing the coder/jail network isolation tool
4+
icon: ../docs/images/logo.png
5+
verified: false
6+
tags: [vm, linux, aws, jail, go, networking, namespaces]
7+
---
8+
9+
# Jail Development Environment on AWS EC2
10+
11+
This Coder template provisions AWS EC2 VMs specifically configured for developing the [coder/jail](https://github.com/coder/jail) network isolation tool. The template sets up a complete development environment with all necessary dependencies, tools, and configurations.
12+
13+
## What is Jail?
14+
15+
Jail is a network isolation tool for monitoring and restricting HTTP/HTTPS requests from processes. It creates isolated network environments for target processes using Linux namespaces and intercepts traffic through a transparent proxy.
16+
17+
## Features
18+
19+
- **Linux VM Environment**: Full Linux VM (not containers) required for namespace syscalls
20+
- **Go 1.24+ Development**: Latest Go toolchain automatically installed
21+
- **Network Tools**: iptables, netfilter, and networking utilities pre-configured
22+
- **Development Tools**: Build essentials, debugging tools, and utilities
23+
- **Jail Pre-installed**: Repository cloned, built, and ready to use
24+
- **Code Server & JetBrains**: Web-based development environments
25+
- **Network Configuration**: Proper kernel settings for namespace operations
26+
27+
## Prerequisites
28+
29+
### Authentication
30+
31+
By default, this template authenticates to AWS using the provider's default [authentication methods](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication-and-configuration).
32+
33+
The simplest way is via environment variables (e.g. `AWS_ACCESS_KEY_ID`) or a [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-format). If you are running Coder on a VM, this file must be in `/home/coder/aws/credentials`.
34+
35+
### Required AWS Permissions
36+
37+
The following sample policy allows Coder to create EC2 instances and modify instances provisioned by Coder:
38+
39+
```json
40+
{
41+
"Version": "2012-10-17",
42+
"Statement": [
43+
{
44+
"Sid": "VisualEditor0",
45+
"Effect": "Allow",
46+
"Action": [
47+
"ec2:GetDefaultCreditSpecification",
48+
"ec2:DescribeIamInstanceProfileAssociations",
49+
"ec2:DescribeTags",
50+
"ec2:DescribeInstances",
51+
"ec2:DescribeInstanceTypes",
52+
"ec2:DescribeInstanceStatus",
53+
"ec2:CreateTags",
54+
"ec2:RunInstances",
55+
"ec2:DescribeInstanceCreditSpecifications",
56+
"ec2:DescribeImages",
57+
"ec2:ModifyDefaultCreditSpecification",
58+
"ec2:DescribeVolumes"
59+
],
60+
"Resource": "*"
61+
},
62+
{
63+
"Sid": "CoderResources",
64+
"Effect": "Allow",
65+
"Action": [
66+
"ec2:DescribeInstanceAttribute",
67+
"ec2:UnmonitorInstances",
68+
"ec2:TerminateInstances",
69+
"ec2:StartInstances",
70+
"ec2:StopInstances",
71+
"ec2:DeleteTags",
72+
"ec2:MonitorInstances",
73+
"ec2:CreateTags",
74+
"ec2:RunInstances",
75+
"ec2:ModifyInstanceAttribute",
76+
"ec2:ModifyInstanceCreditSpecification"
77+
],
78+
"Resource": "arn:aws:ec2:*:*:instance/*",
79+
"Condition": {
80+
"StringEquals": {
81+
"aws:ResourceTag/Coder_Provisioned": "true"
82+
}
83+
}
84+
}
85+
]
86+
}
87+
```
88+
89+
## Architecture
90+
91+
This template provisions the following resources:
92+
93+
- **AWS EC2 Instance**: Ubuntu 22.04 LTS with 20GB storage
94+
- **Network Configuration**: Properly configured for namespace operations
95+
- **Development Environment**: Complete Go development setup
96+
- **Jail Installation**: Pre-built and system-wide accessible
97+
98+
## Software Installed
99+
100+
### Core Development
101+
- **Go 1.24+**: Latest Go compiler and tools
102+
- **Build Tools**: gcc, make, git, and build-essential
103+
- **Jail**: Pre-compiled and installed system-wide
104+
105+
### Network Tools
106+
- **iptables**: Netfilter administration tool
107+
- **iproute2**: Advanced IP routing utilities
108+
- **tcpdump/wireshark**: Network packet analysis
109+
- **net-tools**: Basic network utilities
110+
111+
### Development Tools
112+
- **Code Server**: Web-based VS Code editor
113+
- **JetBrains**: IDE support for Go development
114+
- **Debug Tools**: gdb, strace, ltrace for troubleshooting
115+
- **System Tools**: htop, tree, jq for system management
116+
117+
## Getting Started
118+
119+
After your workspace is created:
120+
121+
1. **Access your workspace** via Code Server or JetBrains
122+
2. **Navigate to jail directory**: `cd ~/jail`
123+
3. **Build jail**: `make build`
124+
4. **Run tests**: `make test` (requires sudo for E2E tests)
125+
5. **Try jail**: `jail --help`
126+
127+
### Example Usage
128+
129+
```bash
130+
# Test jail with a simple HTTP request
131+
jail --allow "github.com" -- curl https://github.com
132+
133+
# Monitor all network requests
134+
jail --log-level info --allow "*" -- your-application
135+
136+
# Block all requests (default deny-all)
137+
jail -- curl https://example.com # This will be blocked
138+
```
139+
140+
### Development Workflow
141+
142+
```bash
143+
# Make changes to jail source code
144+
vim ~/jail/jail.go
145+
146+
# Rebuild
147+
make build
148+
149+
# Test your changes
150+
./jail --allow "example.com" -- curl https://example.com
151+
152+
# Run full test suite
153+
sudo make test
154+
```
155+
156+
## Network Namespace Requirements
157+
158+
This template configures the system for network namespace operations:
159+
160+
- **IP Forwarding**: Enabled for network isolation
161+
- **Netfilter**: Configured for traffic interception
162+
- **User Permissions**: Coder user has sudo access for namespace operations
163+
- **Kernel Features**: Modern Ubuntu 22.04 kernel with namespace support
164+
165+
## Instance Sizing
166+
167+
Default instance size is `t3.medium` (2 vCPU, 4GB RAM) which provides adequate resources for jail development. For intensive development or testing, consider `t3.large` or larger.
168+
169+
## Persistent Storage
170+
171+
This template uses persistent EBS storage. Your development work, built binaries, and git history will persist across workspace restarts.
172+
173+
## Security Considerations
174+
175+
- **Sudo Access**: The coder user has passwordless sudo access required for namespace operations
176+
- **Network Tools**: Various network administration tools are installed
177+
- **Kernel Features**: Network forwarding and netfilter capabilities are enabled
178+
179+
This configuration is necessary for jail development but should only be used in trusted environments.
180+
181+
## Troubleshooting
182+
183+
### Jail Binary Not Found
184+
If jail isn't in PATH, it should be at `/usr/local/bin/jail` or you can rebuild:
185+
```bash
186+
cd ~/jail && make build && sudo cp jail /usr/local/bin/
187+
```
188+
189+
### Network Namespace Issues
190+
Ensure you're using sudo for operations that require network namespaces:
191+
```bash
192+
sudo jail --allow "example.com" -- curl https://example.com
193+
```
194+
195+
### Go Module Issues
196+
If Go modules aren't working, ensure GOPATH is set:
197+
```bash
198+
export GOPATH=$HOME/go
199+
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
200+
```
201+
202+
## Contributing to Jail
203+
204+
This environment is set up for contributing to the jail project:
205+
206+
1. Make your changes in `~/jail/`
207+
2. Test thoroughly with the test suite
208+
3. Ensure all tests pass: `sudo make test`
209+
4. Submit pull requests to the main jail repository
210+
211+
## Template Customization
212+
213+
This template can be modified to:
214+
- Change instance sizes or storage
215+
- Add additional development tools
216+
- Modify network configurations
217+
- Install different Go versions
218+
- Add custom startup scripts
219+
220+
Edit `main.tf` and the cloud-init templates to customize the environment.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#cloud-config
2+
cloud_final_modules:
3+
- [scripts-user, always]
4+
hostname: ${hostname}
5+
users:
6+
- name: ${linux_user}
7+
sudo: ALL=(ALL) NOPASSWD:ALL
8+
shell: /bin/bash
9+
groups: sudo,netdev
10+
# Enable IP forwarding and other network features needed for jail
11+
write_files:
12+
- path: /etc/sysctl.d/99-jail.conf
13+
content: |
14+
# Network settings for jail development
15+
net.ipv4.ip_forward = 1
16+
net.ipv4.conf.all.route_localnet = 1
17+
net.netfilter.nf_conntrack_helper = 0
18+
permissions: '0644'
19+
runcmd:
20+
- sysctl --system
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
sudo -u '${linux_user}' sh -c '${init_script}'

0 commit comments

Comments
 (0)