From 660a5674ee7541039fc4ea2ab3a8102c26b206da Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 19 Sep 2026 09:23:06 -0400 Subject: [PATCH] Run TSan with a narrowly scoped test-container seccomp profile --- .gitea/workflows/build.yaml | 13 +++++++++++- deploy/README.md | 8 ++++++++ deploy/docker/Dockerfile | 4 +++- docs/adr/0020-foundation-delivery.md | 24 ++++++++++++++++++++++ docs/engineering/VALIDATION.md | 16 +++++++++++++++ tools/ci/tsan-profile.mjs | 30 ++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 tools/ci/tsan-profile.mjs diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index f4ee6a9..459dd47 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -31,9 +31,20 @@ jobs: run: | set -eu docker version + ci_image="aevolution-ci:${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-$CHECK_SUITE" docker build --progress=plain --file deploy/docker/Dockerfile \ --build-arg "UBUNTU_IMAGE=$UBUNTU_IMAGE" \ - --target "ci-$CHECK_SUITE" . + --target "ci-$CHECK_SUITE" --tag "$ci_image" . + if [ "$CHECK_SUITE" = tsan ]; then + profile="$RUNNER_TEMP/aevolution-tsan-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}.json" + node tools/ci/tsan-profile.mjs "$profile" + docker run --rm --network none --read-only --user 10001:10001 \ + --cap-drop ALL --security-opt no-new-privileges \ + --security-opt "seccomp=$profile" \ + --tmpfs /source/build/tsan/Testing:rw,noexec,nosuid,size=16m \ + --tmpfs /source/build/tsan/cli-integration:rw,noexec,nosuid,size=16m \ + --tmpfs /tmp:rw,noexec,nosuid,size=16m "$ci_image" + fi image: needs: [checks] diff --git a/deploy/README.md b/deploy/README.md index f9dac58..90178eb 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -95,3 +95,11 @@ more than once: harmless here, not an exactly-once persistence mechanism. World0 is unchanged. Persistent deployment follows [infrastructure architecture](../docs/architecture/INFRASTRUCTURE_ARCHITECTURE.md) and [operations gates](../docs/infrastructure/OPERATIONS.md). + +TSan requires execution outside the Docker build sandbox on this runner. The +ci-tsan target now builds its tests; the Gitea workflow runs them in a non-root, +read-only, networkless container with tmpfs test-output directories. Its pinned +Moby seccomp profile adds only personality(0x40000). No host security settings +change. See ADR-0020 for the source, integrity hash and removal policy. Building +the ci-tsan image alone is NOT a TSan test pass; use the workflow's docker run +command with the generated profile to execute it locally. diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index b597eba..e107f42 100644 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -25,7 +25,9 @@ FROM ci-toolchain AS ci-checks RUN bash tools/ci/linux-check.sh checks FROM ci-toolchain AS ci-tsan -RUN bash tools/ci/linux-check.sh tsan +RUN cmake --preset tsan -DCMAKE_CXX_COMPILER=clang++-19 \ + && cmake --build --preset tsan --parallel 2 +CMD ["ctest", "--preset", "tsan", "--no-tests=error", "--timeout", "120"] FROM toolchain AS build RUN cmake --preset release -B build/container \ diff --git a/docs/adr/0020-foundation-delivery.md b/docs/adr/0020-foundation-delivery.md index b038b2c..4b35aa1 100644 --- a/docs/adr/0020-foundation-delivery.md +++ b/docs/adr/0020-foundation-delivery.md @@ -72,3 +72,27 @@ Sources: [Gitea variables](https://docs.gitea.com/usage/actions/actions-variable [Gitea runner](https://docs.gitea.com/runner/), [Argo hooks](https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks/), [Kubernetes Jobs](https://kubernetes.io/docs/concepts/workloads/controllers/job/). + +### TSan test-container exception (2026-09-19) + +Run 1400 demonstrated Clang19 failing before main because Docker's build sandbox +blocked personality(ADDR_NO_RANDOMIZE). Compile TSan in the image build, then run +CTest in a non-root, networkless, capability-free container with a read-only root +and bounded tmpfs test-output directories. No host ASLR/sysctl change and no +seccomp=unconfined or privileged container is used. + +The CI profile generator downloads Moby's maintained Apache-2.0 default seccomp +profile at commit 245180c51918481c0525424b3ee025d2b435d46c and verifies SHA256 +785b2429264afba4d594320337cb17f144f3c7d51585f9805eef72e28f4f9334. It adds exactly one +argument-constrained allow rule: personality(0x40000), PER_LINUX with +ADDR_NO_RANDOMIZE. This deliberately disables ASLR only for sanitizer processes +requiring a fixed shadow layout. All other default rules remain. The profile is +not part of the game image or Kubernetes runtime configuration. Review/removal +owner: foundation/toolchain maintainers when TSan no longer requires this call. +The tradeoff is a pinned upstream network fetch and profile maintenance, rather +than vendoring a large allowlist or permitting every syscall. Failed tests still +block publication. + +Evidence: [Docker seccomp](https://docs.docker.com/engine/security/seccomp/), +[LLVM19 runtime](https://github.com/llvm/llvm-project/blob/llvmorg-19.1.1/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp), +[pinned Moby profile](https://github.com/moby/profiles/blob/245180c51918481c0525424b3ee025d2b435d46c/seccomp/default.json). diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 0ea233c..63efaaa 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -62,3 +62,19 @@ is not a compiler version. Update this report with run URL, tested commit, image digest and Job result when those checks execute. Never overwrite a golden merely to make CI pass. + +## Expanded Linux run 1400 + +[Run 1400](https://git.aeternalisgames.com/dingo/AEvolution/actions/runs/1400), +commit 9e412736d91ad103b7a951f99b811c629c5ac61e: GCC14 Debug and Release, Clang19 +analysis and ASan/UBSan each passed 5/5 tests. Formatting passed. The seeded fuzz +smoke completed 10000 cases with no reported failure. CMake 3.28.3, GCC 14.2.0, +Clang/format/tidy 19.1.1, Linux 6.8.0-110-generic x86-64. Million-tick hash matched +Windows (fab22c2e8ae1c379); benchmark hash matched too (3bad6db1612cbd1), with +0.0674131 seconds observed for 10000 entities * 1000 ticks on the CI host. + +TSan compiled but all executions failed before main: its runtime could not call +personality(ADDR_NO_RANDOMIZE) inside the Docker build sandbox. The image job was +skipped, as required. This is not recorded as a TSan pass. The follow-up isolates +execution in a container with the narrowly constrained profile from ADR-0020; +its result must be recorded after execution. diff --git a/tools/ci/tsan-profile.mjs b/tools/ci/tsan-profile.mjs new file mode 100644 index 0000000..e609790 --- /dev/null +++ b/tools/ci/tsan-profile.mjs @@ -0,0 +1,30 @@ +// CI-only dependency: Moby profiles, Apache-2.0. See ADR-0020. +import { createHash } from 'node:crypto'; +import { writeFile } from 'node:fs/promises'; + +const revision = '245180c51918481c0525424b3ee025d2b435d46c'; +const expectedHash = '785b2429264afba4d594320337cb17f144f3c7d51585f9805eef72e28f4f9334'; +const destination = process.argv[2]; +if (!destination) throw new Error('Expected output seccomp profile path'); +const response = await fetch( + `https://raw.githubusercontent.com/moby/profiles/${revision}/seccomp/default.json`, + { signal: AbortSignal.timeout(30000) }, +); +if (!response.ok) throw new Error(`Profile download failed: ${response.status}`); +const bytes = Buffer.from(await response.arrayBuffer()); +if (createHash('sha256').update(bytes).digest('hex') !== expectedHash) { + throw new Error('Pinned seccomp profile checksum mismatch'); +} +const profile = JSON.parse(bytes.toString('utf8')); +if (profile.defaultAction !== 'SCMP_ACT_ERRNO' || !Array.isArray(profile.syscalls)) { + throw new Error('Unexpected upstream profile structure'); +} +// Only PER_LINUX | ADDR_NO_RANDOMIZE, not arbitrary execution personalities. +// Changes the test process address layout; does not change a host sysctl. +profile.syscalls.push({ + names: ['personality'], + action: 'SCMP_ACT_ALLOW', + args: [{ index: 0, value: 0x40000, op: 'SCMP_CMP_EQ' }], +}); +await writeFile(destination, `${JSON.stringify(profile, null, 2)}\n`); +console.log(`Verified Moby ${revision}; added only personality(0x40000) for TSan`);