Skip to content

Commit f7cce52

Browse files
committed
executor quoter router added and TODO.md for tomorrow's work
1 parent 35abcfc commit f7cce52

File tree

22 files changed

+3554
-13
lines changed

22 files changed

+3554
-13
lines changed

.devcontainer/Dockerfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
FROM node:20
2+
3+
ARG TZ
4+
ENV TZ="$TZ"
5+
6+
ARG CLAUDE_CODE_VERSION=latest
7+
8+
# Install basic development tools and iptables/ipset
9+
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
less \
11+
git \
12+
procps \
13+
sudo \
14+
fzf \
15+
zsh \
16+
man-db \
17+
unzip \
18+
gnupg2 \
19+
gh \
20+
iptables \
21+
ipset \
22+
iproute2 \
23+
dnsutils \
24+
aggregate \
25+
jq \
26+
nano \
27+
vim \
28+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
29+
30+
# Ensure default node user has access to /usr/local/share
31+
RUN mkdir -p /usr/local/share/npm-global && \
32+
chown -R node:node /usr/local/share
33+
34+
ARG USERNAME=node
35+
36+
# Persist bash history.
37+
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
38+
&& mkdir /commandhistory \
39+
&& touch /commandhistory/.bash_history \
40+
&& chown -R $USERNAME /commandhistory
41+
42+
# Set `DEVCONTAINER` environment variable to help with orientation
43+
ENV DEVCONTAINER=true
44+
45+
# Create workspace and config directories and set permissions
46+
RUN mkdir -p /workspace /home/node/.claude && \
47+
chown -R node:node /workspace /home/node/.claude
48+
49+
WORKDIR /workspace
50+
51+
ARG GIT_DELTA_VERSION=0.18.2
52+
RUN ARCH=$(dpkg --print-architecture) && \
53+
wget "https://github.com/dandavison/delta/releases/download/${GIT_DELTA_VERSION}/git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
54+
sudo dpkg -i "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb" && \
55+
rm "git-delta_${GIT_DELTA_VERSION}_${ARCH}.deb"
56+
57+
# Set up non-root user
58+
USER node
59+
60+
# Install global packages
61+
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
62+
ENV PATH=$PATH:/usr/local/share/npm-global/bin
63+
64+
# Set the default shell to zsh rather than sh
65+
ENV SHELL=/bin/zsh
66+
67+
# Set the default editor and visual
68+
ENV EDITOR nano
69+
ENV VISUAL nano
70+
71+
# Default powerline10k theme
72+
ARG ZSH_IN_DOCKER_VERSION=1.2.0
73+
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v${ZSH_IN_DOCKER_VERSION}/zsh-in-docker.sh)" -- \
74+
-p git \
75+
-p fzf \
76+
-a "source /usr/share/doc/fzf/examples/key-bindings.zsh" \
77+
-a "source /usr/share/doc/fzf/examples/completion.zsh" \
78+
-a "export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
79+
-x
80+
81+
# Install Claude
82+
RUN npm install -g @anthropic-ai/claude-code@${CLAUDE_CODE_VERSION}
83+
84+
85+
# Copy and set up firewall script
86+
COPY init-firewall.sh allowed-domains.txt /usr/local/bin/
87+
USER root
88+
RUN chmod +x /usr/local/bin/init-firewall.sh && \
89+
echo "node ALL=(root) NOPASSWD: /usr/local/bin/init-firewall.sh" > /etc/sudoers.d/node-firewall && \
90+
chmod 0440 /etc/sudoers.d/node-firewall
91+
USER node
92+
93+
# Install Bun
94+
# RUN curl -fsSL https://bun.com/install | bash -s "bun-v1.2.19"

.devcontainer/allowed-domains.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Claude Required
2+
registry.npmjs.org
3+
api.anthropic.com
4+
sentry.io
5+
statsig.anthropic.com
6+
statsig.com
7+
8+
# Repo Specific

.devcontainer/devcontainer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "Claude Code Sandbox",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"args": {
6+
"TZ": "${localEnv:TZ:America/Los_Angeles}",
7+
"CLAUDE_CODE_VERSION": "latest",
8+
"GIT_DELTA_VERSION": "0.18.2",
9+
"ZSH_IN_DOCKER_VERSION": "1.2.0"
10+
}
11+
},
12+
"runArgs": ["--cap-add=NET_ADMIN", "--cap-add=NET_RAW"],
13+
"customizations": {
14+
"vscode": {
15+
"extensions": [
16+
"dbaeumer.vscode-eslint",
17+
"esbenp.prettier-vscode",
18+
"eamodio.gitlens"
19+
],
20+
"settings": {
21+
"editor.formatOnSave": true,
22+
"editor.defaultFormatter": "esbenp.prettier-vscode",
23+
"editor.codeActionsOnSave": {
24+
"source.fixAll.eslint": "explicit"
25+
},
26+
"terminal.integrated.defaultProfile.linux": "zsh",
27+
"terminal.integrated.profiles.linux": {
28+
"bash": {
29+
"path": "bash",
30+
"icon": "terminal-bash"
31+
},
32+
"zsh": {
33+
"path": "zsh"
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"remoteUser": "node",
40+
"mounts": [
41+
"source=claude-code-bashhistory-${devcontainerId},target=/commandhistory,type=volume",
42+
"source=claude-code-config-${devcontainerId},target=/home/node/.claude,type=volume",
43+
"source=/dev/null,target=/workspace/.env.development,type=bind,consistency=delegated",
44+
"source=/dev/null,target=/workspace/.env.test,type=bind,consistency=delegated",
45+
"source=/dev/null,target=/workspace/.env,type=bind,consistency=delegated"
46+
],
47+
"containerEnv": {
48+
"NODE_OPTIONS": "--max-old-space-size=4096",
49+
"CLAUDE_CONFIG_DIR": "/home/node/.claude",
50+
"POWERLEVEL9K_DISABLE_GITSTATUS": "true"
51+
},
52+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated",
53+
"workspaceFolder": "/workspace",
54+
"postCreateCommand": "sudo /usr/local/bin/init-firewall.sh"
55+
}

.devcontainer/init-firewall.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
set -euo pipefail # Exit on error, undefined vars, and pipeline failures
3+
IFS=$'\n\t' # Stricter word splitting
4+
5+
# 1. Extract Docker DNS info BEFORE any flushing
6+
DOCKER_DNS_RULES=$(iptables-save -t nat | grep "127\.0\.0\.11" || true)
7+
8+
# Flush existing rules and delete existing ipsets
9+
iptables -F
10+
iptables -X
11+
iptables -t nat -F
12+
iptables -t nat -X
13+
iptables -t mangle -F
14+
iptables -t mangle -X
15+
ipset destroy allowed-domains 2>/dev/null || true
16+
17+
# 2. Selectively restore ONLY internal Docker DNS resolution
18+
if [ -n "$DOCKER_DNS_RULES" ]; then
19+
echo "Restoring Docker DNS rules..."
20+
iptables -t nat -N DOCKER_OUTPUT 2>/dev/null || true
21+
iptables -t nat -N DOCKER_POSTROUTING 2>/dev/null || true
22+
echo "$DOCKER_DNS_RULES" | xargs -L 1 iptables -t nat
23+
else
24+
echo "No Docker DNS rules to restore"
25+
fi
26+
27+
# First allow DNS and localhost before any restrictions
28+
# Allow outbound DNS
29+
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
30+
# Allow inbound DNS responses
31+
iptables -A INPUT -p udp --sport 53 -j ACCEPT
32+
# Allow outbound SSH
33+
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
34+
# Allow inbound SSH responses
35+
iptables -A INPUT -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
36+
# Allow localhost
37+
iptables -A INPUT -i lo -j ACCEPT
38+
iptables -A OUTPUT -o lo -j ACCEPT
39+
40+
# Create ipset with CIDR support
41+
ipset create allowed-domains hash:net
42+
43+
# Fetch GitHub meta information and aggregate + add their IP ranges
44+
echo "Fetching GitHub IP ranges..."
45+
gh_ranges=$(curl -s https://api.github.com/meta)
46+
if [ -z "$gh_ranges" ]; then
47+
echo "ERROR: Failed to fetch GitHub IP ranges"
48+
exit 1
49+
fi
50+
51+
if ! echo "$gh_ranges" | jq -e '.web and .api and .git' >/dev/null; then
52+
echo "ERROR: GitHub API response missing required fields"
53+
exit 1
54+
fi
55+
56+
echo "Processing GitHub IPs..."
57+
while read -r cidr; do
58+
if [[ ! "$cidr" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/[0-9]{1,2}$ ]]; then
59+
echo "ERROR: Invalid CIDR range from GitHub meta: $cidr"
60+
exit 1
61+
fi
62+
echo "Adding GitHub range $cidr"
63+
ipset add allowed-domains "$cidr" 2>/dev/null || echo " (already exists, skipping)"
64+
done < <(echo "$gh_ranges" | jq -r '(.web + .api + .git)[]' | aggregate -q)
65+
66+
# Get the script's directory to find the domains file
67+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
68+
DOMAINS_FILE="$SCRIPT_DIR/allowed-domains.txt"
69+
70+
if [ ! -f "$DOMAINS_FILE" ]; then
71+
echo "ERROR: Domains file not found at $DOMAINS_FILE"
72+
exit 1
73+
fi
74+
75+
# Resolve and add other allowed domains
76+
while IFS= read -r domain || [ -n "$domain" ]; do
77+
# Skip empty lines and lines starting with #
78+
[[ -z "$domain" || "$domain" =~ ^[[:space:]]*# ]] && continue
79+
echo "Resolving $domain..."
80+
# First get the DNS response (could be IPs or CNAMEs)
81+
dns_response=$(dig +short A "$domain")
82+
83+
# Follow CNAMEs and extract only IP addresses
84+
ips=""
85+
while read -r record; do
86+
if [[ "$record" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
87+
# It's already an IP, add it
88+
ips="$ips$record"$'\n'
89+
else
90+
# It's a CNAME, resolve it recursively
91+
resolved_ips=$(dig +short A "$record" | grep -E '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$')
92+
if [ -n "$resolved_ips" ]; then
93+
ips="$ips$resolved_ips"$'\n'
94+
fi
95+
fi
96+
done < <(echo "$dns_response")
97+
98+
# Remove empty lines and duplicates
99+
ips=$(echo "$ips" | grep -v '^$' | sort -u)
100+
101+
if [ -z "$ips" ]; then
102+
echo "ERROR: Failed to resolve $domain to any IP addresses"
103+
exit 1
104+
fi
105+
106+
while read -r ip; do
107+
echo "Adding $ip for $domain"
108+
ipset add allowed-domains "$ip" 2>/dev/null || echo " (already exists, skipping)"
109+
done < <(echo "$ips")
110+
done < "$DOMAINS_FILE"
111+
112+
# Get host IP from default route
113+
HOST_IP=$(ip route | grep default | cut -d" " -f3)
114+
if [ -z "$HOST_IP" ]; then
115+
echo "ERROR: Failed to detect host IP"
116+
exit 1
117+
fi
118+
119+
HOST_NETWORK=$(echo "$HOST_IP" | sed "s/\.[0-9]*$/.0\/24/")
120+
echo "Host network detected as: $HOST_NETWORK"
121+
122+
# Set up remaining iptables rules
123+
iptables -A INPUT -s "$HOST_NETWORK" -j ACCEPT
124+
iptables -A OUTPUT -d "$HOST_NETWORK" -j ACCEPT
125+
126+
# Set default policies to DROP first
127+
iptables -P INPUT DROP
128+
iptables -P FORWARD DROP
129+
iptables -P OUTPUT DROP
130+
131+
# First allow established connections for already approved traffic
132+
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
133+
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
134+
135+
# Then allow only specific outbound traffic to allowed domains
136+
iptables -A OUTPUT -m set --match-set allowed-domains dst -j ACCEPT
137+
138+
echo "Firewall configuration complete"
139+
echo "Verifying firewall rules..."
140+
if curl --connect-timeout 5 https://example.com >/dev/null 2>&1; then
141+
echo "ERROR: Firewall verification failed - was able to reach https://example.com"
142+
exit 1
143+
else
144+
echo "Firewall verification passed - unable to reach https://example.com as expected"
145+
fi
146+
147+
# Verify GitHub API access
148+
if ! curl --connect-timeout 5 https://api.github.com/zen >/dev/null 2>&1; then
149+
echo "ERROR: Firewall verification failed - unable to reach https://api.github.com"
150+
exit 1
151+
else
152+
echo "Firewall verification passed - able to reach https://api.github.com as expected"
153+
fi

0 commit comments

Comments
 (0)