test(runner): verify sandbox isolation with a hostile program suite
This commit is contained in:
1 parent
afee564bf4
commit
e858280d91
38 files changed
+1359
-168
No files matched your search
+40
-8
@@ -13,6 +13,21 @@ LINT_GOOS ?= linux
|
||||
GOLANGCI_LINT := bin/golangci-lint
|
||||
RUNNER_IMAGE ?= lincodex-runner-dev:local
|
||||
SANDBOX_TEST_IMAGE ?= lincodex-runner-sandbox-test:local
|
||||
# Recorded in the A16 report; reading Git state changes nothing.
|
||||
RUNNER_VERSION ?= $(shell git describe --always --dirty --abbrev=12 2>/dev/null || echo unknown)
|
||||
# A16 report directory; .gitignore keeps reports out of Git.
|
||||
A16_REPORT_DIR ?= $(CURDIR)/.reports
|
||||
# Extra RUNNER_* settings for the A16 suite, for example
|
||||
# A16_ENV="RUNNER_SANDBOX_MAX_PROCESSES=4096" to see a weakened limit fail.
|
||||
A16_ENV ?=
|
||||
# Architecture of the A16 bundle for a runner host.
|
||||
A16_GOARCH ?= amd64
|
||||
A16_BUNDLE_DIR := bin/a16-bundle
|
||||
# DEVELOPMENT ONLY: --privileged gives nsjail namespaces and a writable
|
||||
# cgroup v2 tree inside the Docker Desktop VM; exec on the work tmpfs lets
|
||||
# built Go solutions run. Production never uses these flags.
|
||||
SANDBOX_RUN := $(DOCKER) run --rm --privileged --cgroupns=private --network=none \
|
||||
--tmpfs /var/lib/lincodex-runner/work:size=128m,mode=0711,exec
|
||||
OGEN_ARGS := -config codegen/ogen.yml --package api --clean ../api/runner/openapi.bundle.yml
|
||||
|
||||
##@ Build
|
||||
@@ -82,15 +97,32 @@ test: ## Run unit tests with the race detector; they need no sandbox
|
||||
image: ## Build the runner image for local development
|
||||
$(DOCKER) build --file Dockerfile --tag "$(RUNNER_IMAGE)" .
|
||||
|
||||
# DEVELOPMENT ONLY: --privileged gives nsjail namespaces and a writable
|
||||
# cgroup v2 tree inside the Docker Desktop VM. Production runs the runner on
|
||||
# its dedicated VM and never uses this target.
|
||||
.PHONY: sandbox-test-image
|
||||
sandbox-test-image: image
|
||||
$(DOCKER) build --file Dockerfile.sandbox-test --build-arg RUNNER_IMAGE="$(RUNNER_IMAGE)" --build-arg RUNNER_VERSION="$(RUNNER_VERSION)" --tag "$(SANDBOX_TEST_IMAGE)" .
|
||||
|
||||
.PHONY: test-sandbox
|
||||
test-sandbox: image ## Run the hostile-program isolation tests in a privileged dev container
|
||||
$(DOCKER) build --file Dockerfile.sandbox-test --build-arg RUNNER_IMAGE="$(RUNNER_IMAGE)" --tag "$(SANDBOX_TEST_IMAGE)" .
|
||||
$(DOCKER) run --rm --privileged --cgroupns=private --network=none \
|
||||
--tmpfs /var/lib/lincodex-runner/work:size=128m,mode=0711,exec \
|
||||
"$(SANDBOX_TEST_IMAGE)"
|
||||
test-sandbox: sandbox-test-image ## Run reference solutions and the A16 suite in a privileged dev container
|
||||
$(SANDBOX_RUN) "$(SANDBOX_TEST_IMAGE)"
|
||||
|
||||
.PHONY: test-a16
|
||||
test-a16: sandbox-test-image ## Run only the A16 hostile-program suite locally and write a report to .reports/
|
||||
@mkdir -p "$(A16_REPORT_DIR)"
|
||||
$(SANDBOX_RUN) $(foreach setting,$(A16_ENV),--env $(setting)) \
|
||||
--volume "$(A16_REPORT_DIR):/reports" \
|
||||
--env RUNNER_A16_REPORT=/reports/a16-$$(date -u +%Y%m%dT%H%M%SZ).json \
|
||||
"$(SANDBOX_TEST_IMAGE)" -test.run '^TestA16'
|
||||
|
||||
.PHONY: a16-bundle
|
||||
a16-bundle: ## Build the A16 suite for a runner host (A16_GOARCH, default amd64) into bin/a16-bundle.tar.gz
|
||||
rm -rf "$(A16_BUNDLE_DIR)"
|
||||
mkdir -p "$(A16_BUNDLE_DIR)/testdata"
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=$(A16_GOARCH) $(GO) test -c -tags sandbox \
|
||||
-ldflags "-X lincodex/runner/internal/isolationtest.runnerVersion=$(RUNNER_VERSION)" \
|
||||
-o "$(A16_BUNDLE_DIR)/isolation.test" ./internal/isolationtest
|
||||
cp -R testdata/hostile "$(A16_BUNDLE_DIR)/testdata/hostile"
|
||||
cp scripts/run-a16.sh "$(A16_BUNDLE_DIR)/run-a16.sh"
|
||||
tar -C bin -czf bin/a16-bundle.tar.gz a16-bundle
|
||||
|
||||
.PHONY: check
|
||||
check: ## Run formatting, build, unit, generated drift, and lint checks
|
||||
|
||||
Reference in new issue
Block a user