Skip to content

Commit fa300e6

Browse files
committed
Restructure README for clearer navigation and reduce redundancy
- Reorganize sections: merge Operation Modes into Usage with GitHub Actions, move Local Usage under Development - Unify Troubleshooting into a single local-reproduction workflow - Add Job Summary section with screenshots for both modes - Simplify parameter references to use GitHub Actions input names - Add cleanup FAQ entry and Buildx integration example
1 parent b4fbe67 commit fa300e6

File tree

3 files changed

+103
-124
lines changed

3 files changed

+103
-124
lines changed

README.md

Lines changed: 103 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ When you run `RUN npm install` or `RUN apt-get install` in a Dockerfile, these c
4444
- Your build logs show exactly what was blocked
4545
- The report step fails if blocked connections are detected, causing the workflow to fail
4646

47-
**Two modes available** (see [Operation Modes](#operation-modes) for details):
47+
**Two modes available** (see [Usage with GitHub Actions](#usage-with-github-actions) for details):
4848

4949
- **Audit mode**: Records all network destinations during builds, useful for creating allowlists.
5050
- **Restrict mode**: Allows access only to permitted domains, blocking everything else.
@@ -82,7 +82,11 @@ When you run `RUN npm install` or `RUN apt-get install` in a Dockerfile, these c
8282

8383
### First-Time Setup (Recommended Workflow)
8484

85-
Using buildcage in GitHub Actions involves three workflow steps: (1) start the buildcage container, which runs BuildKit inside a network-controlled environment; (2) configure Docker Buildx to use the buildcage container as a remote builder; (3) run your build as usual. Your Dockerfile and build commands stay the same — only the builder backend changes.
85+
Using buildcage in GitHub Actions involves three workflow steps:
86+
87+
1. Start the buildcage container (runs BuildKit inside a network-controlled environment)
88+
2. Configure Docker Buildx to use the buildcage container as a remote builder
89+
3. Run your build as usual — your Dockerfile and build commands stay the same
8690

8791
#### Step 1: Discover what domains your build needs (Audit Mode)
8892

@@ -113,7 +117,7 @@ jobs:
113117
uses: docker/build-push-action@v6
114118
with:
115119
context: .
116-
push: false
120+
push: false # Set to true to push the built image
117121
118122
- name: Show what domains were accessed
119123
if: always()
@@ -124,22 +128,11 @@ jobs:
124128

125129
#### Step 2: Check the report
126130

127-
The report will show output like:
131+
The report action outputs a Job Summary showing every domain your build contacted:
128132

129-
```
130-
Accessed hosts summary:
131-
------------------------------------
132-
🔍 Audited hosts (audit mode - all logged):
133-
134-
23 x registry.npmjs.org:443
135-
8 x github.com:443
136-
4 x objects.githubusercontent.com:443
137-
2 x api.github.com:443
138-
1 x fonts.googleapis.com:443
139-
1 x deb.debian.org:80
140-
```
133+
<img src="assets/report-audit-mode.png" alt="Outbound Traffic Report - audit mode" width="835">
141134

142-
Copy these domain names into `allowed_https_domains` for Step 3.
135+
Copy these domain names into `allowed_https_domains` or `allowed_http_domains` for Step 3.
143136

144137
#### Step 3: Create your allowlist and switch to restrict mode
145138

@@ -161,11 +154,7 @@ jobs:
161154
proxy_mode: restrict # Block everything except allowed domains
162155
allowed_https_domains: >-
163156
registry.npmjs.org,
164-
github.com,
165-
objects.githubusercontent.com,
166-
api.github.com,
167-
fonts.googleapis.com,
168-
deb.debian.org
157+
fonts.googleapis.com
169158
170159
- name: Set up Docker Buildx
171160
uses: docker/setup-buildx-action@v3
@@ -177,7 +166,7 @@ jobs:
177166
uses: docker/build-push-action@v6
178167
with:
179168
context: .
180-
push: false # Set to true (or use a registry) to push the built image
169+
push: false # Set to true to push the built image
181170
182171
- name: Security report
183172
if: always()
@@ -187,11 +176,24 @@ jobs:
187176

188177
Your builds are now protected. Any unexpected connections will be blocked and reported.
189178

190-
---
179+
## Usage with GitHub Actions
191180

192-
## Operation Modes
181+
### Setup Action
193182

194-
### Audit Mode (PROXY_MODE=audit)
183+
Starts the buildcage builder container.
184+
185+
```yaml
186+
- name: Start buildcage builder
187+
id: buildcage
188+
uses: dash14/buildcage/setup@v1
189+
with:
190+
proxy_mode: restrict
191+
allowed_https_domains: registry.npmjs.org,github.com
192+
```
193+
194+
#### Operation Modes
195+
196+
##### Audit Mode (`proxy_mode: audit`)
195197

196198
**When to use:** First-time setup, adding new dependencies, or investigating issues.
197199

@@ -200,18 +202,7 @@ Your builds are now protected. Any unexpected connections will be blocked and re
200202
- Logs every domain accessed during the build
201203
- Does NOT block anything
202204

203-
**Example log output:**
204-
205-
```
206-
▼ HTTP Proxy communication logs
207-
[28/Jan/2026:10:15:32 +0000] [AUDIT] TCP 200 2345 6789 0.234 "npmjs.org:443"
208-
[28/Jan/2026:10:15:33 +0000] [AUDIT] TCP 200 1234 5678 0.123 "github.com:443"
209-
[28/Jan/2026:10:15:34 +0000] [AUDIT] HTTP 200 3456 7890 0.345 "fonts.googleapis.com:80"
210-
```
211-
212-
**Next step:** Use these domains to create your allowlist for restrict mode.
213-
214-
### Restrict Mode (PROXY_MODE=restrict)
205+
##### Restrict Mode (`proxy_mode: restrict`)
215206

216207
**When to use:** Production builds, CI/CD pipelines, security-critical environments.
217208

@@ -220,49 +211,7 @@ Your builds are now protected. Any unexpected connections will be blocked and re
220211
- Blocks all other connections
221212
- Logs allowed and blocked attempts
222213

223-
**Example log output:**
224-
225-
```
226-
▼ HTTP Proxy communication logs
227-
[28/Jan/2026:10:15:30 +0000] [ALLOWED] TCP 200 1234 5678 0.123 "npmjs.org:443"
228-
[28/Jan/2026:10:15:31 +0000] [BLOCKED] TCP 502 0 0 0.001 "malicious-tracker.com:443"
229-
```
230-
231-
The report step fails if blocked connections are detected, causing the workflow to fail. You can disable this by setting `fail_on_blocked: false` in the report action.
232-
233-
**Example report output when connections are blocked:**
234-
235-
```
236-
Accessed hosts summary:
237-
------------------------------------
238-
✅ Allowed hosts (proxied to real servers):
239-
240-
23 x registry.npmjs.org:443
241-
8 x github.com:443
242-
243-
❌ Blocked hosts (rejected):
244-
245-
1 x malicious-tracker.com:443
246-
```
247-
248-
## Usage
249-
250-
### GitHub Actions
251-
252-
#### Setup Action
253-
254-
Starts the buildcage builder container.
255-
256-
```yaml
257-
- name: Start buildcage builder
258-
id: buildcage
259-
uses: dash14/buildcage/setup@v1
260-
with:
261-
proxy_mode: restrict
262-
allowed_https_domains: registry.npmjs.org,github.com
263-
```
264-
265-
##### Parameters
214+
#### Parameters
266215

267216
| Parameter | Required | Default | Description |
268217
|-----------|----------|---------|-------------|
@@ -273,13 +222,23 @@ Starts the buildcage builder container.
273222
| `allowed_https_domains` | No | empty | Allowed HTTPS domains (comma-separated, without port) |
274223
| `port` | No | `1234` | BuildKit endpoint port on localhost |
275224

276-
##### Outputs
225+
#### Outputs
277226

278227
| Name | Description |
279228
|------|-------------|
280229
| `port` | BuildKit endpoint port |
281230

282-
##### Tips
231+
Pass this port to [`docker/setup-buildx-action`](https://github.com/docker/setup-buildx-action) to use buildcage as a remote builder:
232+
233+
```yaml
234+
- name: Set up Docker Buildx
235+
uses: docker/setup-buildx-action@v3
236+
with:
237+
driver: remote
238+
endpoint: tcp://localhost:${{ steps.buildcage.outputs.port }}
239+
```
240+
241+
#### Tips
283242

284243
- Start with audit mode to discover required domains, then switch to restrict mode.
285244
- Wildcard domains are supported (e.g., `*.github.com` matches all subdomains of `github.com`).
@@ -292,7 +251,7 @@ Starts the buildcage builder container.
292251
allowed_https_domains: registry.npmjs.org
293252
```
294253

295-
#### Report Action
254+
### Report Action
296255

297256
Displays communication logs after builds and optionally fails if any BLOCKED connections are found.
298257

@@ -302,51 +261,27 @@ Displays communication logs after builds and optionally fails if any BLOCKED con
302261
uses: dash14/buildcage/report@v1
303262
```
304263

305-
##### Parameters
306-
307-
| Parameter | Required | Default | Description |
308-
|-----------|----------|---------|-------------|
309-
| `fail_on_blocked` | No | `true` | Fail the step if blocked connections are detected |
264+
#### Job Summary
310265

311-
### Local Usage (Without GitHub Actions)
266+
**Audit mode:**
312267

313-
GitHub Actions inputs use lowercase names (e.g., `proxy_mode`), while environment variables for local/Docker Compose usage use uppercase (e.g., `PROXY_MODE`).
268+
<img src="assets/report-audit-mode.png" alt="Outbound Traffic Report - audit mode" width="835">
314269

315-
#### Starting the Builder
270+
Use the domain names shown in the report to create your allowlist for restrict mode.
316271

317-
**Audit mode** (log all connections):
272+
**Restrict mode:**
318273

319-
```bash
320-
make run_audit_mode
321-
```
274+
<img src="assets/report-restrict-mode.png" alt="Outbound Traffic Report - restrict mode" width="835">
322275

323-
**Restrict mode** (allowlist-based):
276+
The report step fails if blocked connections are detected, causing the workflow to fail. You can disable this by setting `fail_on_blocked: false`.
324277

325-
```bash
326-
make run_restrict_mode
327-
```
278+
#### Parameters
328279

329-
**Start with custom domains**:
330-
331-
```bash
332-
ALLOWED_HTTPS_DOMAINS="github.com,npmjs.org,example.com" make run_restrict_mode
333-
```
334-
335-
#### End-to-End Local Workflow
336-
337-
```bash
338-
# 1. Start buildcage
339-
make run_audit_mode
340-
341-
# 2. Build
342-
docker buildx build --builder buildcage --progress=plain -f Dockerfile .
343-
344-
# 3. View report
345-
docker compose logs builder
280+
| Parameter | Required | Default | Description |
281+
|-----------|----------|---------|-------------|
282+
| `fail_on_blocked` | No | `true` | Fail the step if blocked connections are detected |
346283

347-
# 4. Clean up
348-
make clean
349-
```
284+
---
350285

351286
## Architecture
352287

@@ -476,7 +411,7 @@ Given these implementation costs versus the strict preconditions for the attack
476411
477412
**Mitigation strategies:**
478413
479-
- **Keep allowed domains to a minimum** — Only specify the domains you need in `ALLOWED_HTTP_DOMAINS` / `ALLOWED_HTTPS_DOMAINS`.
414+
- **Keep allowed domains to a minimum** — Only specify the domains you need in `allowed_http_domains` / `allowed_https_domains`.
480415
- **Be specific with allowed domains** — Avoid broad wildcard CDN domains (e.g., `*.cdn.example.com`) when possible.
481416
- **Use service-specific domains** — Prefer `registry.npmjs.org` over generic CDN wildcard domains.
482417
- **Major CDN countermeasures** — Major CDN providers like CloudFront and Cloudflare have already introduced measures to restrict domain fronting. Consult your CDN provider's documentation for current details.
@@ -496,7 +431,7 @@ A: Yes! buildcage works seamlessly with multi-stage Dockerfiles.
496431
497432
**Q: Does this work with private package registries?**
498433
499-
A: Yes. Just add your private registry's domain to `ALLOWED_HTTPS_DOMAINS`.
434+
A: Yes. Just add your private registry's domain to `allowed_https_domains`.
500435
501436
**Q: What happens if I forget to add a required domain?**
502437
@@ -506,15 +441,19 @@ A: In restrict mode, the build will fail with a clear error message. Run in audi
506441
507442
A: Yes. Prefix wildcards like `*.example.com` are supported and will match all subdomains (e.g., `sub.example.com`, `deep.sub.example.com`). Note that `*.example.com` does not match `example.com` itself—add both if needed. Suffix wildcards (e.g., `example.*`) are not supported.
508443
444+
**Q: Do I need to clean up the buildcage container?**
445+
446+
A: No. The container is automatically removed when the GitHub Actions job completes.
447+
509448
**Q: Does this protect against malicious code execution?**
510449
511450
A: No. buildcage only controls network access. It doesn't prevent malicious code from running—it prevents that code from communicating with external servers.
512451
513452
## Troubleshooting
514453
515-
If you encounter issues:
454+
If you encounter issues, try reproducing the problem locally to get detailed logs:
516455
517-
1. **Check logs first:**
456+
1. **Check logs:**
518457
```bash
519458
docker compose logs builder
520459
```
@@ -606,6 +545,46 @@ Fields: `[timestamp] [status] protocol http_status bytes_sent bytes_received dur
606545
└── test-dns/ # Test DNS server
607546
```
608547

548+
### Local Usage (without GitHub Actions)
549+
550+
GitHub Actions inputs use lowercase names (e.g., `proxy_mode`), while environment variables for local/Docker Compose usage use uppercase (e.g., `PROXY_MODE`).
551+
552+
#### Starting the Builder
553+
554+
**Audit mode** (log all connections):
555+
556+
```bash
557+
make run_audit_mode
558+
```
559+
560+
**Restrict mode** (allowlist-based):
561+
562+
```bash
563+
make run_restrict_mode
564+
```
565+
566+
**Start with custom domains**:
567+
568+
```bash
569+
ALLOWED_HTTPS_DOMAINS="github.com,npmjs.org,example.com" make run_restrict_mode
570+
```
571+
572+
#### End-to-End Local Workflow
573+
574+
```bash
575+
# 1. Start buildcage
576+
make run_audit_mode
577+
578+
# 2. Build
579+
docker buildx build --builder buildcage --progress=plain -f Dockerfile .
580+
581+
# 3. View report
582+
docker compose logs builder
583+
584+
# 4. Clean up
585+
make clean
586+
```
587+
609588
## Contributing
610589

611590
Contributions are welcome! Please feel free to submit issues or pull requests.

assets/report-audit-mode.png

124 KB
Loading

assets/report-restrict-mode.png

162 KB
Loading

0 commit comments

Comments
 (0)