-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-start.sh
More file actions
221 lines (202 loc) · 7.53 KB
/
quick-start.sh
File metadata and controls
221 lines (202 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# Quick start script for secure sandbox deployment
set -e
echo "=========================================="
echo "SECURE SANDBOX - QUICK START"
echo "=========================================="
# 0. Check/Install Docker
echo "[0/7] Checking Docker..."
if ! command -v docker &> /dev/null; then
echo "[INFO] Docker not found. Installing..."
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER || true
fi
# 1. Install gVisor (detect architecture)
echo "[1/7] Installing gVisor..."
ARCH=$(uname -m)
if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
GVISOR_ARCH="aarch64"
else
GVISOR_ARCH="x86_64"
fi
echo "[INFO] Detected architecture: $ARCH, downloading gVisor for $GVISOR_ARCH"
URL="https://storage.googleapis.com/gvisor/releases/release/latest/${GVISOR_ARCH}"
wget "${URL}/runsc" "${URL}/runsc.sha512"
sha512sum -c runsc.sha512 || { echo "[FAIL] Checksum failed"; exit 1; }
chmod +x runsc
sudo mv runsc /usr/local/bin/
rm -f runsc.sha512
# 2. Configure Docker
echo "[2/7] Configuring Docker..."
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json > /dev/null << 'DOCKER'
{
"runtimes": {
"runsc": {
"path": "/usr/local/bin/runsc"
}
}
}
DOCKER
sudo systemctl restart docker
# 3. Create directory structure
echo "[3/7] Creating directory structure..."
sudo mkdir -p /srv/sandbox/{skills,users}
sudo mkdir -p /srv/sandbox/users/{001,002}/{uploads,outputs}
# 4. Generate JWT keys
echo "[4/7] Generating JWT keys..."
mkdir -p ./jwt-keys
openssl ecparam -genkey -name prime256v1 -noout -out ./jwt-keys/private-key.pem
openssl ec -in ./jwt-keys/private-key.pem -pubout -out ./jwt-keys/public-key.pem
# 5. Deploy egress proxy (with working config)
echo "[5/7] Deploying egress proxy..."
# Create working envoy config
cat > /tmp/envoy-sandbox.yaml << 'ENVOY'
static_resources:
listeners:
- name: egress_listener
address:
socket_address:
address: 0.0.0.0
port_value: 8443
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: egress_http
route_config:
name: egress_route
virtual_hosts:
- name: egress_service
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: dynamic_forward_proxy_cluster
timeout: 30s
http_filters:
- name: envoy.filters.http.jwt_authn
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.jwt_authn.v3.JwtAuthentication
providers:
sandbox_jwt:
issuer: 'secure-egress-control'
audiences:
- 'egress-proxy'
local_jwks:
inline_string: |
{
"keys": [
{
"kty": "EC",
"crv": "P-256",
"x": "replace-with-your-key-x",
"y": "replace-with-your-key-y",
"kid": "your-ecdsa-key-id"
}
]
}
forward: true
from_headers:
- name: 'Proxy-Authorization'
value_prefix: 'Basic '
rules:
- match:
prefix: '/'
requires:
provider_name: 'sandbox_jwt'
- name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inline_code: |
function envoy_on_request(request_handle)
local target = request_handle:headers():get(":authority")
local allowed = {
["github.com"] = true,
["api.github.com"] = true,
["raw.githubusercontent.com"] = true,
["example.com"] = true,
["httpbin.org"] = true
}
if not allowed[target] then
request_handle:respond(
{[":status"] = "403", ["x-blocked"] = "true"},
"Host not allowed: " .. (target or "unknown")
)
end
end
- name: envoy.filters.http.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.dynamic_forward_proxy.v3.FilterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: V4_ONLY
max_hosts: 100
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: dynamic_forward_proxy_cluster
lb_policy: CLUSTER_PROVIDED
cluster_type:
name: envoy.clusters.dynamic_forward_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig
dns_cache_config:
name: dynamic_forward_proxy_cache_config
dns_lookup_family: V4_ONLY
max_hosts: 100
admin:
address:
socket_address:
address: 127.0.0.1
port_value: 9901
ENVOY
docker run -d \
--name egress-proxy \
--network bridge \
-p 8443:8443 \
-v /tmp/envoy-sandbox.yaml:/etc/envoy/envoy.yaml:ro \
envoyproxy/envoy:v1.28-latest \
-c /etc/envoy/envoy.yaml
# 6. Create test sandbox
echo "[6/7] Creating test sandbox..."
# Remove old container if exists
docker rm -f test-sandbox 2>/dev/null || true
# Create user directories
sudo mkdir -p /srv/sandbox/users/001/outputs
sudo chmod 755 /srv/sandbox/users/001/outputs || true
docker run -d \
--name test-sandbox \
--runtime=runsc \
--network=none \
--memory=4g \
--memory-swap=4g \
--cpu-shares=1024 \
--cpu-quota=200000 \
--cpu-period=100000 \
--pids-limit=100 \
--ulimit nofile=20000:20000 \
--cap-drop=ALL \
--cap-add=CHOWN \
--cap-add=SETUID \
--cap-add=SETGID \
--security-opt=no-new-privileges:true \
--read-only \
--tmpfs /tmp:noexec,nosuid,size=100m \
-v /srv/sandbox/skills:/mnt/skills:ro \
-v /srv/sandbox/users/001/outputs:/mnt/outputs:rw \
ubuntu:22.04 \
sleep infinity
# 7. Run security tests
echo "[7/7] Running security tests..."
bash scripts/security-tests.sh
echo "=========================================="
echo "[OK] Setup complete!"
echo "Test sandbox running: test-sandbox"
echo "=========================================="