|
| 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. |
0 commit comments