Skip to content

Commit 152c24a

Browse files
committed
Improve clarity and accuracy of security documentation
- Reorder sections logically: Network Isolation → DNS → Proxy → Direct IP - Clarify DNS redirect, HTTP proxy, and iptables descriptions - Add missing Host header rejection to proxy control section - Split Direct IP section into traffic redirection and IP allowlist check - Fix variable names and add audit mode link
1 parent 86931e3 commit 152c24a

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

docs/development.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Fields: `[timestamp] buildcage [status] "domain:port" reason`
8383
| `make run_restrict_mode` | Start in restrict mode (default domains) |
8484
| `make test_audit_mode` | Run audit mode tests (start → build → verify → clean up) |
8585
| `make test_restrict_mode` | Run restrict mode tests (start → build → verify → clean up) |
86+
| `make test_unit` | Run unit tests |
8687
| `make clean` | Remove all resources |
8788

8889
## Directory Structure
@@ -102,6 +103,7 @@ Fields: `[timestamp] buildcage [status] "domain:port" reason`
102103
│ ├── action.yml # GitHub Action: dash14/buildcage/report@v1
103104
│ └── main.mjs # Log analysis and Job Summary output
104105
├── docs/
106+
│ ├── development.md # Development guide
105107
│ ├── rules.md # Rule format reference
106108
│ ├── security.md # Security design
107109
│ └── self-hosting.md # Self-hosting guide

docs/security.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,32 @@ For a high-level overview, see the [Security Considerations](../README.md#securi
66

77
## Security Mechanisms
88

9-
### Direct IP Address Connections
9+
### Network Isolation
1010

11-
- **Direct IP blocked by iptables**: Connections to raw IP addresses (e.g., `curl http://1.2.3.4/`) bypass DNS and attempt to reach the IP directly, which iptables drops. Connections using domain names go through the proxy and are checked against the allowlist via Host header (HTTP) or SNI (HTTPS).
11+
- **CNI configuration**: Places temporary containers from BuildKit RUN steps into isolated-net (buildkit0 bridge, 172.20.0.0/24).
12+
- **iptables**: Drops all FORWARD from buildkit0, also blocks direct access to buildkitd API.
13+
- **Gateway enforcement**: All traffic must go through the proxy on 172.20.0.1.
1214

1315
### DNS-Level Control
1416

15-
- **Full redirect**: Returns the proxy IP for all DNS queries.
17+
- **Universal DNS redirect**: All domain name queries return the proxy IP (172.20.0.1), forcing all traffic through the proxy regardless of the requested domain.
1618
- **ECH prevention**: The internal DNS server operates without any upstream resolvers, so DNS HTTPS (type 65) records — required to initiate Encrypted Client Hello (ECH) — are never returned to build containers.
1719

1820
### HTTP/HTTPS Proxy Control
1921

2022
- **HTTPS**: Determines the target server name by reading the SNI field, without terminating TLS. Certificate validation is unaffected.
21-
- **HTTP**: Domain determination via Host header.
22-
- **Dynamic allowlist**: Controlled via environment variables.
23+
- **HTTP**: Determines the target domain by inspecting the Host header, then checks it against the allowlist.
24+
- **Dynamic allowlist**: Controlled via `allowed_https_rules`, `allowed_http_rules`, and `allowed_ip_rules` environment variables.
25+
- **Missing Host header rejection**: HTTP requests without a valid Host header are rejected with HTTP 400, preventing requests that cannot be checked against the allowlist.
2326

24-
### Network Isolation
27+
### Direct IP Address Connections
2528

26-
- **CNI configuration**: Places temporary containers from BuildKit RUN steps into isolated-net (buildkit0 bridge, 172.20.0.0/24).
27-
- **iptables**: Drops all FORWARD from buildkit0, also blocks direct access to buildkitd API.
28-
- **Gateway enforcement**: All traffic must go through the proxy on 172.20.0.1.
29+
- **Traffic redirection**: All TCP traffic from the isolated network is redirected to HAProxy via an iptables `PREROUTING REDIRECT` rule.
30+
- **IP allowlist check**: Connections to raw IP addresses (e.g., `curl http://1.2.3.4/`) are checked against `allowed_ip_rules`. If no `allowed_ip_rules` are configured, all direct IP connections are blocked.
2931

3032
## Attack Resistance
3133

32-
The following attack vectors are defended against by buildcage's architecture.
34+
buildcage's architecture defends against the following attack vectors.
3335

3436
### SNI Spoofing
3537

@@ -47,7 +49,7 @@ TLS 1.3 Encrypted Client Hello (ECH) encrypts the true SNI, which could theoreti
4749

4850
An attacker may attempt to encode data into DNS queries to exfiltrate information or establish communication with external servers.
4951

50-
**Why this is prevented:** The internal DNS server has no upstream resolvers and answers all queries locally. Additionally, iptables rules block direct DNS traffic to any external server. With no path for DNS queries to reach the outside, encoded data has no route to an attacker's infrastructure.
52+
**Why this is prevented:** The internal DNS server has no upstream resolvers and answers all queries locally. Additionally, all forwarded traffic from the isolated network is dropped by iptables — including any attempt to reach external DNS servers directly. With no path for DNS queries to reach the outside, encoded data has no route to an attacker's infrastructure.
5153

5254
### Non-TCP Protocol Tunneling (ICMP, UDP, QUIC)
5355

@@ -59,7 +61,7 @@ An attacker may attempt to tunnel data using non-TCP protocols such as ICMP echo
5961

6062
An attacker may attempt to use IPv6 to circumvent IPv4-based iptables rules.
6163

62-
**Why this is prevented:** Equivalent ip6tables rules drop all forwarded IPv6 traffic from the isolated network. Additionally, the internal DNS server returns an empty IPv6 address for all queries, effectively disabling IPv6 name resolution within build containers.
64+
**Why this is prevented:** Equivalent ip6tables rules drop all forwarded IPv6 traffic from the isolated network. Additionally, the internal DNS server returns the IPv6 unspecified address (::) for all queries, effectively disabling IPv6 name resolution within build containers.
6365

6466
### Alternative DNS Transports (DoH / DoT)
6567

@@ -96,8 +98,8 @@ Given these implementation costs versus the strict preconditions for the attack
9698

9799
**Mitigation strategies:**
98100

99-
- **Keep allowed domains to a minimum** — Only specify the domains you need in `allowed_http_domains` / `allowed_https_domains`.
101+
- **Keep allowed domains to a minimum** — Only specify the domains you need in `allowed_http_rules` / `allowed_https_rules`.
100102
- **Be specific with allowed domains** — Avoid broad wildcard CDN domains (e.g., `*.cdn.example.com`) when possible.
101103
- **Use service-specific domains** — Prefer `registry.npmjs.org` over generic CDN wildcard domains.
102104
- **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.
103-
- **Regular audits** — Periodically run in audit mode to detect anomalies in connection patterns.
105+
- **Regular audits** — Periodically run in [audit mode](../README.md#operation-modes) to detect anomalies in connection patterns.

0 commit comments

Comments
 (0)