ci(gates): FE-GATE-013을 일회용 systemd 컨테이너 안에서 돌린다

문제: FE-GATE-013의 test:system은 provider sandbox를 실제로 띄운다.
systemd user manager(systemd-run --user --scope)와 cgroup v2 위임,
bubblewrap(--unshare-net 등)이 필요하다. runner의 job 컨테이너는
entrypoint가 sleep이라 systemd가 없고 bwrap도 없어 사전 점검에서 실패한다
(run 56·80·81). desktop 호스트는 다 있지만 Ubuntu 24.04의
apparmor_restrict_unprivileged_userns=1이 비특권 bwrap을 막는다.
그래서 이 게이트는 runner와 desktop 어디서도 초록인 적이 없다.

고른 방법(소유자 결정 2026-11-11 5절 e: 조건이 되는 실행 환경을 찾는다):
- config/ci/system-container.Dockerfile: Ubuntu 24.04(digest 고정) +
  systemd PID 1 + root linger + bubblewrap 등 hostRequirements의 도구.
- scripts/run-in-system-container.sh: 이미지(Dockerfile 해시 태그)가 없으면
  만들고, privileged·자체 cgroup namespace로 띄워 systemd와 root user
  manager를 기다린 뒤, 작업 트리·git 이력·호출한 쪽의 node와 corepack을
  복사해 명령을 root로 돌리고 artifacts/를 되가져온 다음 지운다. root는
  호스트의 userns 제한을 받지 않는다.
- gates.json 게이트 필드 hostEnvironment: "system-container"(FE-GATE-013).
  생성기는 그 게이트의 run 줄에 래퍼를 붙이고, 실행 검사
  (workflowGateExecutionFailures)는 계약이 정한 접두어로 돈 줄만 센다.
  scripts/verify.sh gate·parts·stage도 같은 래퍼로 돌린다.
- CI에서는 runner의 Docker proxy로 안쪽 dind daemon을 쓴다(platform-core
  gitea-runner README가 「남은 위험」으로 적은 길: proxy가 privileged
  컨테이너를 막지 않는다).
- 버린 대안: 전용 VM runner(문서 조건을 그대로 만족하지만 platform-core
  변경과 VM 자원·runner 등록이 필요), 호스트 AppArmor profile(호스트
  userns 제한을 푸는 보안 설정 변경, 소유자 sudo).

위험·한계:
- root로 돌아 「비특권 runner에서 bwrap userns」 조건 자체는 증명하지
  않는다. release 단계 provider job 둘은 아직 job 컨테이너에서 돈다(범위
  밖, 같은 래퍼나 VM runner가 필요).
- runner가 rootless dind로 바뀌면 privileged 컨테이너를 못 띄워 깨진다.
- 래퍼 준비(이미지 확인·기동·복사)에 desktop에서 50~60초가 든다.

검증(desktop): 래퍼로 check-system-test-prerequisites → PASS(root),
tests/system/ci-runner/provider-process-group.test.ts 1개 통과.
python3 -m unittest scripts.tests.test_verify 통과, check:ci PASS(게이트 28),
ci-workflow-generation 시험 통과. 게이트 전체(test:system 116개 포함)는 이
브랜치 끝의 merge 단계에서 돈다.
This commit is contained in:
DongHyeonka
2026-11-12 00:04:05 +09:00
parent 66138440f4
commit 1d3eb901d2
10 changed files with 193 additions and 13 deletions
+1 -1
View File
@@ -106,7 +106,7 @@ jobs:
run: corepack pnpm ci:gate -- FE-GATE-007
- name: "FE-GATE-013 / security"
if: ${{ !cancelled() }}
run: corepack pnpm ci:gate -- FE-GATE-013
run: scripts/run-in-system-container.sh corepack pnpm ci:gate -- FE-GATE-013
- name: "FE-GATE-020 / removability"
if: ${{ !cancelled() }}
run: corepack pnpm ci:gate -- FE-GATE-020
+2 -1
View File
@@ -1802,7 +1802,8 @@
"hostRequirements": [
"Linux with executable /usr/bin/bwrap (with --size), /usr/bin/prlimit, /usr/bin/systemd-run, /usr/bin/systemctl and /usr/bin/tar, an active systemd user manager 254 or newer, and unified cgroup v2 with delegated memory, pids and cpu controllers",
"unprivileged user and network namespaces for bwrap (the provider sandbox runs bwrap --unshare-pid --unshare-ipc --unshare-uts --unshare-net); Ubuntu 23.10 and later refuse them while kernel.apparmor_restrict_unprivileged_userns=1 unless /usr/bin/bwrap has an AppArmor profile that allows userns; scripts/check-system-test-prerequisites.ts probes this before test:system runs"
]
],
"hostEnvironment": "system-container"
},
{
"id": "FE-GATE-014",
+16
View File
@@ -0,0 +1,16 @@
# The host FE-GATE-013 runs on (scripts/run-in-system-container.sh): systemd as
# PID 1 with a lingering root user manager, cgroup v2 delegation, bubblewrap and
# the tools the provider sandbox calls (config/ci/gates.json hostRequirements).
# Node and pnpm are not installed here: the script copies in the caller's own,
# so the gate runs with the same versions as the job that called it.
FROM docker.io/library/ubuntu:24.04@sha256:fe81560990fae86dc4743202b2cb4d3df98d0bcf949173cecef15ce1127ef852
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
bubblewrap ca-certificates dbus dbus-user-session git systemd systemd-sysv tar util-linux \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /var/lib/systemd/linger \
&& touch /var/lib/systemd/linger/root
STOPSIGNAL SIGRTMIN+3
CMD ["/sbin/init"]
+8
View File
@@ -299,6 +299,14 @@ const gateSchema = z
* contract baseline, like any other change to what a gate demands.
*/
hostRequirements: z.array(nonEmpty.max(512)).min(1).max(8).optional(),
/**
* Where the gate runs when the job container cannot meet its host
* requirements. "system-container": scripts/run-in-system-container.sh
* runs the gate in a disposable privileged systemd container
* (config/ci/system-container.Dockerfile), in CI through the runner's
* Docker daemon and on desktop through scripts/verify.sh.
*/
hostEnvironment: z.enum(["system-container"]).optional(),
})
.strict();
+14 -3
View File
@@ -254,6 +254,15 @@ function renderHostRequirements(
);
}
/**
* A gate whose host requirements the job container cannot meet runs in the
* environment its contract names (`hostEnvironment`). FE-GATE-013's provider
* sandbox needs systemd and bubblewrap, which the runner's job image lacks.
*/
function gateHostPrefix(gate: Readonly<{ hostEnvironment?: "system-container" | undefined }> | undefined): string {
return gate?.hostEnvironment === "system-container" ? "scripts/run-in-system-container.sh " : "";
}
function renderStep(
job: CiWorkflowJob,
step: CiWorkflowStep,
@@ -303,7 +312,7 @@ function renderStep(
return job.gateIds.flatMap((gateId) => [
` - name: ${yamlScalar(`${gateId} / ${index.gates.get(gateId)?.name ?? ""}`)}`,
" if: ${{ !cancelled() }}",
` run: corepack pnpm ci:gate -- ${gateId}`,
` run: ${gateHostPrefix(index.gates.get(gateId))}corepack pnpm ci:gate -- ${gateId}`,
]);
}
// 12-02: every gate the job owns runs, in order. Rendering only the first
@@ -533,9 +542,11 @@ export function workflowGateExecutionFailures(
) {
productFailures.push(`product gates do not hold the release stage: ${PRODUCT_GATES_HOLD} does not need ${PRODUCT_GATE_JOB}`);
}
const hostPrefixes = new Map(contract.gates.map((gate) => [gate.id, gateHostPrefix(gate)]));
for (const job of jobs) {
for (const match of job.matchAll(/^ +run: corepack pnpm ci:gate -- (FE-GATE-\d{3})$/gmu)) {
executed.add(match[1]!);
for (const match of job.matchAll(/^ +run: (\S+ )?corepack pnpm ci:gate -- (FE-GATE-\d{3})$/gmu)) {
// A gate runs through the prefix its contract names, and only that one.
if ((match[1] ?? "") === hostPrefixes.get(match[2]!)) executed.add(match[2]!);
}
if (/^ +run: corepack pnpm ci:gate -- \$\{\{ matrix\.gate \}\}$/mu.test(job)) {
for (const match of job.matchAll(/^ +- \{ gate: (FE-GATE-\d{3}),/gmu)) {
+88
View File
@@ -0,0 +1,88 @@
#!/usr/bin/env bash
# Runs one command in a disposable systemd container, for a gate whose host requirements a CI job
# container or a developer shell does not meet (config/ci/gates.json `hostEnvironment: "system-container"`,
# FE-GATE-013's provider sandbox: bubblewrap, a systemd user manager, delegated cgroup v2).
#
# scripts/run-in-system-container.sh <command…> e.g. corepack pnpm ci:gate -- FE-GATE-013
#
# The container is privileged with its own cgroup namespace and boots systemd (config/ci/system-container.Dockerfile).
# The command runs as root there, so bubblewrap needs no unprivileged user namespace from the host kernel
# (Ubuntu 23.10+ refuses those to unconfined processes). Node and pnpm come from the caller, copied in with the
# working tree and its git history; artifacts/ is copied back and the container removed, whatever the result.
# Docker: the CI job reaches the runner's own daemon through its Docker proxy
# (platform-core infrastructure/ci/gitea-runner); on desktop it is the host daemon.
# Environment: SYSTEM_CONTAINER_DOCKER (default docker), SYSTEM_CONTAINER_KEEP=1 keeps the container for debugging.
# Exit code: the command's, or 3 when the container could not be prepared.
set -euo pipefail
[ $# -gt 0 ] || { sed -n '2,13p' "$0" | sed 's/^# \{0,1\}//' >&2; exit 2; }
docker=${SYSTEM_CONTAINER_DOCKER:-docker}
root=$(git rev-parse --show-toplevel)
cd "$root"
dockerfile=config/ci/system-container.Dockerfile
tag="fe-system-container:$(sha256sum "$dockerfile" | cut -c1-16)"
node_root=$(dirname "$(dirname "$(command -v node)")")
corepack_home=${COREPACK_HOME:-$HOME/.cache/node/corepack}
# The environment the gate reads (scripts/verify.sh ci_env, the workflow's global env).
pass_env=(CI VITE_BUILD_ID VITE_COMMIT_SHA RELEASE_ID CI_RUNNER_IMAGE SOURCE_DATE_EPOCH APP_PROFILE RELEASE_TARGET)
say() { echo "system-container: $*" >&2; }
fail() { say "$*"; exit 3; }
if ! $docker image inspect "$tag" > /dev/null 2>&1; then
say "building $tag"
$docker build -q -t "$tag" -f "$dockerfile" config/ci > /dev/null || fail "image build failed"
fi
cid=$($docker run -d --privileged --cgroupns=private --tmpfs /run --tmpfs /run/lock "$tag") \
|| fail "container did not start"
cleanup() {
if [ "${SYSTEM_CONTAINER_KEEP:-0}" = 1 ]; then say "kept container $cid"; else $docker rm -f "$cid" > /dev/null 2>&1 || :; fi
}
trap cleanup EXIT
# systemd reaches a final state, then root's lingering user manager opens its bus. Until PID 1 has its own
# bus up, systemctl cannot connect and answers nothing, so ask again for up to a minute.
state=""
for _ in $(seq 1 120); do
state=$($docker exec "$cid" systemctl is-system-running --wait 2>/dev/null || :)
case "$state" in running | degraded) break ;; esac
sleep 0.5
done
case "$state" in running | degraded) ;; *) fail "systemd did not start (state: ${state:-none})" ;; esac
$docker exec "$cid" sh -c 'for i in $(seq 1 120); do [ -S /run/user/0/bus ] && exit 0; sleep 0.5; done; exit 1' \
|| fail "the root user manager did not start"
# The working tree as it is (node_modules included) and its history. A linked worktree's .git is a file
# naming a directory outside the tree, so the history goes in as a bundle of HEAD instead.
tar -C "$root" --exclude=./.git --exclude=./.tmp -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /work && tar -C /work --no-same-owner -xf -' \
|| fail "copying the working tree failed"
if [ -d .git ]; then
tar -C "$root" -cf - .git | $docker exec -i "$cid" tar -C /work --no-same-owner -xf - || fail "copying .git failed"
else
bundle=$(mktemp)
git bundle create -q "$bundle" HEAD
$docker exec -i "$cid" sh -c 'cat > /tmp/head.bundle' < "$bundle"
rm -f "$bundle"
$docker exec -w /work "$cid" sh -c 'git init -q . && git fetch -q /tmp/head.bundle HEAD && git update-ref HEAD FETCH_HEAD && git reset -q' \
|| fail "restoring the git history failed"
fi
tar -C "$node_root" -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /opt/node && tar -C /opt/node --no-same-owner -xf -' \
|| fail "copying node failed"
if [ -d "$corepack_home" ]; then
tar -C "$corepack_home" -cf - . | $docker exec -i "$cid" sh -c 'mkdir -p /opt/corepack && tar -C /opt/corepack --no-same-owner -xf -' \
|| fail "copying the corepack cache failed"
fi
exec_env=(-e PATH=/opt/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
-e COREPACK_HOME=/opt/corepack -e HOME=/root
-e XDG_RUNTIME_DIR=/run/user/0 -e DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus)
for name in "${pass_env[@]}"; do
[ -z "${!name+x}" ] || exec_env+=(-e "$name=${!name}")
done
rc=0
$docker exec -w /work "${exec_env[@]}" "$cid" "$@" || rc=$?
# The gate's log and evidence come back even when it failed.
mkdir -p artifacts
$docker exec "$cid" sh -c '[ -d /work/artifacts ] && tar -C /work -cf - artifacts' | tar -C "$root" -xf - \
|| say "copying artifacts back failed"
exit "$rc"
+21 -3
View File
@@ -45,12 +45,29 @@ class StagePlanTest(unittest.TestCase):
def test_parts_runs_each_command_of_the_gate(self) -> None:
contract = gates()
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-013")
gate = next(g for g in contract["gates"] if g["id"] == "FE-GATE-005")
scripts = {c["id"]: c["script"] for c in contract["commands"]}
result = sh([str(VERIFY), "parts", "FE-GATE-013", "--dry-run"], cwd=REPO)
result = sh([str(VERIFY), "parts", "FE-GATE-005", "--dry-run"], cwd=REPO)
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()],
[f"corepack pnpm -s {scripts[c]}" for c in gate["commandIds"]])
def test_a_gate_with_a_host_environment_runs_in_it_as_in_the_workflow(self) -> None:
# FE-GATE-013 needs systemd and bubblewrap; the workflow and verify.sh both run it through
# scripts/run-in-system-container.sh (config/ci/gates.json hostEnvironment).
contract = gates()
hosted = [g for g in contract["gates"] if g.get("hostEnvironment") == "system-container"]
self.assertEqual([g["id"] for g in hosted], ["FE-GATE-013"])
scripts = {c["id"]: c["script"] for c in contract["commands"]}
wrapper = "scripts/run-in-system-container.sh"
result = sh([str(VERIFY), "gate", "FE-GATE-013", "FE-GATE-005", "--dry-run"], cwd=REPO)
self.assertEqual(result.stdout.splitlines(), [f"FE-GATE-013: {wrapper} corepack pnpm -s ci:gate FE-GATE-013",
"FE-GATE-005: corepack pnpm -s ci:gate FE-GATE-005"])
result = sh([str(VERIFY), "parts", "FE-GATE-013", "--dry-run"], cwd=REPO)
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()],
[f"{wrapper} corepack pnpm -s {scripts[c]}" for c in hosted[0]["commandIds"]])
workflow = (REPO / ".gitea/workflows/quality-gates.yml").read_text(encoding="utf-8")
self.assertIn(f"run: {wrapper} corepack pnpm ci:gate -- FE-GATE-013", workflow)
def test_parts_passes_each_command_its_arguments_as_ci_gate_does(self) -> None:
# run-ci-gate.ts runs `pnpm <script> ...args`. Without the args FE-GATE-009's
# `review:a11y-manual -- --format-only` checked the release evidence instead and failed.
@@ -63,9 +80,10 @@ class StagePlanTest(unittest.TestCase):
with self.subTest(gate=gate["id"]):
result = sh([str(VERIFY), "parts", gate["id"], "--dry-run"], cwd=REPO)
expected = []
prefix = ["scripts/run-in-system-container.sh"] if gate.get("hostEnvironment") else []
for command_id in gate["commandIds"]:
command = commands[command_id]
words = ["corepack", "pnpm", "-s", command["script"], *command.get("args", [])]
words = [*prefix, "corepack", "pnpm", "-s", command["script"], *command.get("args", [])]
expected.append(" ".join(words))
self.assertEqual([line.split(": ", 1)[1] for line in result.stdout.splitlines()], expected)
+20 -4
View File
@@ -55,6 +55,11 @@ elif kind == "stage":
elif kind == "gate":
if not any(gate["id"] == names[0] for gate in contract["gates"]):
sys.exit(1)
elif kind == "host":
gate = next((gate for gate in contract["gates"] if gate["id"] == names[0]), None)
if gate is None:
sys.exit(1)
print(gate.get("hostEnvironment", ""))
elif kind == "scripts":
gate = next((gate for gate in contract["gates"] if gate["id"] == names[0]), None)
if gate is None:
@@ -120,26 +125,37 @@ step() {
return "$rc"
}
# 계약이 hostEnvironment를 정한 게이트(FE-GATE-013)는 workflow와 같이 그 환경에서 돈다.
host_prefix() {
case "$(gates_json host "$1")" in
system-container) echo scripts/run-in-system-container.sh ;;
esac
}
run_gates() {
local failed=0 gate
local failed=0 gate prefix
[ "$DRY_RUN" = 1 ] || ci_env
for gate in "$@"; do
gates_json gate "$gate" || { echo "verify: config/ci/gates.json에 없는 게이트: $gate" >&2; return 2; }
step "$gate" corepack pnpm -s ci:gate "$gate" || failed=1
prefix=$(host_prefix "$gate")
# shellcheck disable=SC2086 # 접두어는 공백 없는 경로 하나이거나 비어 있다
step "$gate" $prefix corepack pnpm -s ci:gate "$gate" || failed=1
done
return "$failed"
}
run_parts() {
local gate=$1 failed=0 script expect code argtext rc args
local gate=$1 failed=0 script expect code argtext rc args prefix
[ "$DRY_RUN" = 1 ] || ci_env
gates_json scripts "$gate" > /dev/null || { echo "verify: config/ci/gates.json에 없는 게이트: $gate" >&2; return 2; }
prefix=$(host_prefix "$gate")
while IFS=$'\x1f' read -r script expect code argtext; do
rc=0
args=()
# The command's args, as run-ci-gate.ts passes them (`pnpm <script> ...args`).
[ -z "$argtext" ] || IFS=$'\x1e' read -r -a args <<< "$argtext"
step "$gate $script" corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
# shellcheck disable=SC2086
step "$gate $script" $prefix corepack pnpm -s "$script" ${args[@]+"${args[@]}"} || rc=$?
# expect=fail인 명령(음성 fixture)은 정해진 종료 코드로 실패해야 통과다.
if [ "$expect" = fail ]; then
[ "$DRY_RUN" = 1 ] || [ "$rc" = "${code:-1}" ] || failed=1
@@ -109,7 +109,7 @@ jobs:
run: corepack pnpm ci:gate -- FE-GATE-007
- name: "FE-GATE-013 / security"
if: \${{ !cancelled() }}
run: corepack pnpm ci:gate -- FE-GATE-013
run: scripts/run-in-system-container.sh corepack pnpm ci:gate -- FE-GATE-013
- name: "FE-GATE-020 / removability"
if: \${{ !cancelled() }}
run: corepack pnpm ci:gate -- FE-GATE-020
+22
View File
@@ -1687,6 +1687,28 @@ describe("CI workflow generation", () => {
expect(workflow.match(/ runner requirement: /gu)).toHaveLength(requirements.length);
});
// The job container has neither systemd nor bubblewrap, so FE-GATE-013 runs
// in the system container its contract names (hostEnvironment).
it("runs a gate with a host environment through it, and counts only that run", async () => {
const contract = await loadCiGateContract(process.cwd());
expect(contract.gates.filter((gate) => gate.hostEnvironment).map(({ id }) => id)).toEqual(["FE-GATE-013"]);
const workflow = renderCiWorkflow(contract);
const wrapped = " run: scripts/run-in-system-container.sh corepack pnpm ci:gate -- FE-GATE-013";
expect(workflow.split("\n").filter((line) => line.includes("ci:gate -- FE-GATE-013"))).toEqual([wrapped]);
expect(workflowGateExecutionFailures(contract, workflow)).toEqual([]);
expect(workflowGateExecutionFailures(
contract,
workflow.replace(wrapped, " run: corepack pnpm ci:gate -- FE-GATE-013"),
)).toEqual(["gate is not executed by any workflow run step: FE-GATE-013"]);
expect(workflowGateExecutionFailures(
contract,
workflow.replace(
" run: corepack pnpm ci:gate -- FE-GATE-005",
" run: scripts/run-in-system-container.sh corepack pnpm ci:gate -- FE-GATE-005",
),
)).toEqual(["gate is not executed by any workflow run step: FE-GATE-005"]);
});
it("rejects a runner requirement that would leave its workflow comment (1105/12-01)", async () => {
const contract = JSON.parse(
JSON.stringify(await loadCiGateContract(process.cwd())),