-
Notifications
You must be signed in to change notification settings - Fork 49
Add sandboxed network-isolated test execution #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
82169a0
ci: run go tests sandboxed without network access
claude 5bf54e3
ci: warm test build cache before entering sandbox
claude 594e6fe
ci: allow ubuntu apt mirrors so bubblewrap can install under harden-r…
claude f90534b
ci: install bubblewrap before harden-runner so apt egress is unrestri…
claude 3fecb83
ci: use unshare instead of bubblewrap for the linux sandbox
claude 6df74ef
ci: relax apparmor unprivileged userns restriction for unshare
claude 24ba338
test: bring up loopback inside the netns
claude 115af6b
test: make tests pass under the no-network sandbox
claude 69e05fd
test: update tests to check for cached PHP WASM binaries and skip if …
shyim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,4 +28,5 @@ devenv.local.nix | |
| # Go cache | ||
| /.gocache | ||
| /.gomodcache | ||
| /.gopath | ||
| /.gopath | ||
| .soulforge | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
|
|
||
| cd "$REPO_DIR" | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| set -- -v ./... | ||
| fi | ||
|
|
||
| # Warm the build cache while we still have network so the sandboxed run | ||
| # does not need to fetch or compile anything from the module proxy. | ||
| go test -run='^$' ./... | ||
|
|
||
| # Inside the sandbox, force the toolchain to fail fast on any cache miss | ||
| # instead of attempting (and hanging on) a network fetch. | ||
| export GOFLAGS="${GOFLAGS:-} -mod=readonly" | ||
| export GOPROXY=off | ||
|
|
||
| # Tells tests that depend on real external downloads (e.g. fetching PHP wasm | ||
| # binaries or dart-sass) to skip themselves instead of failing on DNS. | ||
| export SHOPWARE_CLI_NO_NETWORK=1 | ||
|
|
||
| case "$(uname -s)" in | ||
| Darwin) | ||
| if ! command -v sandbox-exec >/dev/null 2>&1; then | ||
| echo "error: sandbox-exec not found" >&2 | ||
| exit 1 | ||
| fi | ||
| exec sandbox-exec -f "$REPO_DIR/sandbox-no-network.sb" go test "$@" | ||
| ;; | ||
| Linux) | ||
| if ! command -v unshare >/dev/null 2>&1; then | ||
| echo "error: unshare not found (expected from util-linux)" >&2 | ||
| exit 1 | ||
| fi | ||
| # Bring loopback up inside the new netns so tests that use | ||
| # httptest.NewServer (127.0.0.1) keep working; only external | ||
| # network is blocked, matching the nix-build sandbox. | ||
| exec unshare --user --map-root-user --net -- bash -c ' | ||
| if command -v ip >/dev/null 2>&1; then | ||
| ip link set dev lo up | ||
| elif command -v ifconfig >/dev/null 2>&1; then | ||
| ifconfig lo up | ||
| else | ||
| echo "error: need either ip (iproute2) or ifconfig to bring up loopback" >&2 | ||
| exit 1 | ||
| fi | ||
| exec go test "$@" | ||
| ' bash "$@" | ||
| ;; | ||
| *) | ||
| echo "error: unsupported OS: $(uname -s)" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Darwin branch executes
sandbox-execwithsandbox-no-network.sb, but that profile currently allowsnetwork*and only denies outbound TCP on ports 80/443. This means tests can still access external services over other ports/protocols, so the new script does not actually provide the claimed "no network" isolation on macOS.Useful? React with 👍 / 👎.