Skip to content

Commit 8b18024

Browse files
fengtttclaude
andcommitted
ci: address review — credential-free PR paths, fingerprinted native cache, contained fallback
Review fixes for #418 / matrixone#27077 (XuPeng-SH, aptend, LeftHandCold): [P0] No credential may share a runner with PR-controlled code. The shared build job drops environment: ci and every registry secret; all ci-builder pulls (build-mo and the three seed steps) are now anonymous and the checkout no longer persists its token. If anonymous ACR pulls are not permitted, provision a pull-only credential at the runner/node level via infrastructure — never via workflow-level docker login, which persists credentials in runner docker state that later PR-controlled steps can read. [P1] The prebuilt thirdparties/install tree now restores only on an exact fingerprint match (schema, os, arch, git rev-parse HEAD:thirdparties — the tree hash covers every archive, header, the Makefile with its flags, and the download script) at all four consumers; any mismatch clears the seed and builds native deps from source. Go module/build caches remain best-effort acceleration, which is always correctness-safe. [P2] Fallback now lives inside the producer: the cached container build is best-effort (continue-on-error) with ownership repair and a loader smoke test; on any failure the job sets up the checkout's Go toolchain and runs the existing make clean cold build, and packaging (with a final env -u LD_LIBRARY_PATH smoke test) runs after either path. A consumer skip via needs now only happens on a genuine compile failure, which is the intended behavior. Also per review: every runtime DSO ships under lib/ ($ORIGIN/lib), the prebuilt-cgo/ contract is gone, and the Docker Hub fallback pull is time-bounded like the ACR attempt so a registry outage cannot make the optimized path slower than the cold baseline (layers are content- addressed, so a timed-out ACR attempt still counts toward the Docker Hub attempt). Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 176f205 commit 8b18024

3 files changed

Lines changed: 133 additions & 133 deletions

File tree

‎.github/workflows/build-mo.yaml‎

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,17 @@ on:
2424
TOKEN_ACTION:
2525
description: "Token for checkout (e.g. pull from fork/private)"
2626
required: false
27-
DOCKERHUB_USERNAME:
28-
description: "Optional Docker Hub login for the ci-builder pull (rate limits)"
29-
required: false
30-
DOCKERHUB_TOKEN:
31-
description: "Optional Docker Hub token for the ci-builder pull (rate limits)"
32-
required: false
33-
ACR_USERNAME:
34-
description: "Optional ACR login for the ci-builder mirror pull"
35-
required: false
36-
ACR_TOKEN:
37-
description: "Optional ACR token for the ci-builder mirror pull"
38-
required: false
3927

4028
jobs:
4129
build-linux-amd64:
4230
# Must stay on the same runner pool as the BVT consumers so the binary
4331
# links against the same glibc the test runners (and the ubuntu:22.04
4432
# runtime image) provide.
45-
environment: ci
33+
#
34+
# Trust contract: this job checks out and COMPILES the untrusted PR head,
35+
# so it must never hold credentials the PR code could reach. No
36+
# environment, no registry logins (the ci-builder pulls below are
37+
# anonymous), and the checkout does not persist its token.
4638
runs-on: ${{ vars.RUNNER_LABEL || 'ubuntu-22.04' }}
4739
name: Build MatrixOne (shared)
4840
timeout-minutes: 40
@@ -53,6 +45,7 @@ jobs:
5345
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
5446
with:
5547
token: ${{ secrets.TOKEN_ACTION }}
48+
persist-credentials: false
5649
fetch-depth: "3"
5750
repository: ${{ github.event.pull_request.head.repo.full_name }}
5851
ref: ${{ github.event.pull_request.head.sha }}
@@ -63,89 +56,111 @@ jobs:
6356
# from a full -cover build of the default branch, and the compiled C
6457
# thirdparties. Building inside it recompiles only what the PR changed;
6558
# go build incrementally downloads modules newer than the baked cache,
66-
# so a stale image only costs speed. The login avoids Docker Hub
67-
# anonymous pull rate limits; both login and pull are best-effort.
59+
# so a stale image only costs speed. Pulls are ANONYMOUS on purpose:
60+
# this job compiles untrusted PR code, so no registry credential may
61+
# ever touch this runner. Both pulls are time-bounded so a registry
62+
# outage cannot make the optimized path slower than a cold build
63+
# (layers are content-addressed, so a timed-out ACR attempt still
64+
# counts toward the Docker Hub attempt of the same image).
6865
- name: Pull CI builder image
6966
id: builder
70-
env:
71-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
72-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
73-
ACR_USERNAME: ${{ secrets.ACR_USERNAME }}
74-
ACR_TOKEN: ${{ secrets.ACR_TOKEN }}
7567
run: |
7668
set +e
7769
ACR_IMAGE="registry.cn-shanghai.aliyuncs.com/matrixorigin/matrixone:ci-builder"
7870
HUB_IMAGE="matrixorigin/matrixone:ci-builder"
79-
if [ -n "${ACR_TOKEN}" ]; then
80-
echo "${ACR_TOKEN}" | docker login registry.cn-shanghai.aliyuncs.com -u "${ACR_USERNAME}" --password-stdin || true
81-
fi
82-
if [ -n "${DOCKERHUB_TOKEN}" ]; then
83-
echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin || true
84-
fi
85-
# Prefer the ACR mirror (fast from the self-hosted China runners),
86-
# time-bounded so a slow cross-region pull cannot eat the savings;
71+
# Prefer the ACR mirror (fast from the self-hosted China runners);
8772
# fall back to Docker Hub.
8873
image=""
8974
if timeout 300 docker pull "${ACR_IMAGE}"; then
9075
image="${ACR_IMAGE}"
91-
elif docker pull "${HUB_IMAGE}"; then
76+
elif timeout 300 docker pull "${HUB_IMAGE}"; then
9277
image="${HUB_IMAGE}"
9378
fi
9479
if [ -z "${image}" ]; then
9580
echo "::warning::ci-builder image unavailable; building from source on the runner"
9681
fi
9782
echo "image=${image}" >> "$GITHUB_OUTPUT"
9883
84+
# Best-effort cached build: any failure here (stale image, toolchain
85+
# skew, broken cache) falls through to the from-source build below, so
86+
# cache/infrastructure problems never fail this job — only a genuine
87+
# compile failure does, which correctly blocks the BVT consumers once.
88+
- name: Build MatrixOne (cached)
89+
id: cached
90+
if: ${{ steps.builder.outputs.image != '' }}
91+
continue-on-error: true
92+
run: |
93+
set -uo pipefail
94+
cd "$GITHUB_WORKSPACE"
95+
# The mount path must match the ci-builder warm build's WORKDIR:
96+
# cgo compile-cache entries hash the -I include paths. The prebuilt
97+
# thirdparties are restored only on an exact fingerprint match, so
98+
# PRs that change native inputs (or branches whose native tree
99+
# diverges from the nightly image) rebuild them from source.
100+
docker run --rm \
101+
-v "$GITHUB_WORKSPACE":/go/src/github.com/matrixorigin/matrixone \
102+
-w /go/src/github.com/matrixorigin/matrixone \
103+
-e MO_GOBUILD_OPT='${{ inputs.gobuild_opt }}' \
104+
'${{ steps.builder.outputs.image }}' \
105+
bash -c '
106+
set -euo pipefail
107+
git config --global --add safe.directory /go/src/github.com/matrixorigin/matrixone
108+
expected=$(printf "schema=1\nos=%s\narch=%s\nthirdparties_tree=%s" \
109+
"$(uname -s)" "$(uname -m)" "$(git rev-parse HEAD:thirdparties)")
110+
if [ "${expected}" = "$(cat /mo-prebuilt/thirdparties.fingerprint 2>/dev/null)" ]; then
111+
rm -rf thirdparties/install
112+
cp -r /mo-prebuilt/thirdparties/install thirdparties/install
113+
else
114+
echo "prebuilt thirdparties fingerprint mismatch; building native deps from source"
115+
rm -rf thirdparties/install
116+
fi
117+
make build GOBUILD_OPT="${MO_GOBUILD_OPT}"'
118+
status=$?
119+
sudo chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE" || true
120+
[ "${status}" -eq 0 ]
121+
# Loader smoke test: a broken cached artifact fails here so the
122+
# from-source fallback below repairs it. A coverage-instrumented
123+
# binary needs a writable GOCOVERDIR even for -h.
124+
env -u LD_LIBRARY_PATH GOCOVERDIR="$(mktemp -d)" ./mo-service -h >/dev/null
125+
99126
- name: Set up Go And Java
100-
if: ${{ steps.builder.outputs.image == '' }}
127+
if: ${{ steps.cached.outcome != 'success' }}
101128
uses: matrixorigin/CI/actions/setup-env@main
102129
with:
103130
go-version-file: "${{ github.workspace }}/go.mod"
104131

105-
- name: Build MatrixOne
132+
- name: Build MatrixOne (from source)
133+
if: ${{ steps.cached.outcome != 'success' }}
106134
run: |
107135
cd "$GITHUB_WORKSPACE"
108-
if [ -n "${{ steps.builder.outputs.image }}" ]; then
109-
# The mount path must match the ci-builder warm build's WORKDIR:
110-
# cgo compile-cache entries hash the -I include paths.
111-
docker run --rm \
112-
-v "$GITHUB_WORKSPACE":/go/src/github.com/matrixorigin/matrixone \
113-
-w /go/src/github.com/matrixorigin/matrixone \
114-
-e MO_GOBUILD_OPT='${{ inputs.gobuild_opt }}' \
115-
'${{ steps.builder.outputs.image }}' \
116-
bash -c '
117-
set -euo pipefail
118-
git config --global --add safe.directory /go/src/github.com/matrixorigin/matrixone
119-
rm -rf thirdparties/install
120-
cp -r /mo-prebuilt/thirdparties/install thirdparties/install
121-
make build GOBUILD_OPT="${MO_GOBUILD_OPT}"'
122-
sudo chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE"
123-
else
124-
make clean && make GOBUILD_OPT='${{ inputs.gobuild_opt }}' build
125-
fi
126-
git rev-parse --short HEAD
136+
# make clean also clears any partial cached-build outputs.
137+
make clean && make GOBUILD_OPT='${{ inputs.gobuild_opt }}' build
127138
128139
- name: Package build artifact
129140
id: package
130141
run: |
131142
set -euo pipefail
132143
cd "$GITHUB_WORKSPACE"
144+
git rev-parse --short HEAD
133145
{
134146
echo 'head_sha=${{ github.event.pull_request.head.sha }}'
135147
echo 'gobuild_opt=${{ inputs.gobuild_opt }}'
136148
} > BUILD_INFO
137-
# cgo shared libraries are staged under a dedicated directory so the
138-
# runtime image build can COPY them without picking up host build
139-
# residue from cgo/.
140-
rm -rf prebuilt-cgo && mkdir -p prebuilt-cgo
141-
cp cgo/*.so prebuilt-cgo/
149+
# Consolidate every runtime DSO under lib/, the binary'"'"'s
150+
# $ORIGIN/lib rpath: make build already put the thirdparties
151+
# libraries there; add MatrixOne'"'"'s own cgo library so consumers
152+
# need no extra layout knowledge.
153+
cp cgo/*.so lib/
154+
# Final artifact smoke test: the staged tree must run with no help
155+
# from the environment before it is published.
156+
env -u LD_LIBRARY_PATH GOCOVERDIR="$(mktemp -d)" ./mo-service -h >/dev/null
142157
# The tar preserves the self-contained runtime tree that make build
143-
# produces at the repo root: mo-service with rpath $ORIGIN/lib, the
144-
# thirdparties shared libraries in lib/, and the jieba dict/.
158+
# produces at the repo root: mo-service with rpath $ORIGIN/lib, all
159+
# runtime shared libraries in lib/, and the jieba dict/.
145160
pack_dir="${RUNNER_TEMP}/mo-build"
146161
mkdir -p "${pack_dir}"
147162
tar --exclude='*.a' -czf "${pack_dir}/mo-build.tar.gz" \
148-
mo-service BUILD_INFO lib dict prebuilt-cgo
163+
mo-service BUILD_INFO lib dict
149164
ls -lh "${pack_dir}/mo-build.tar.gz"
150165
echo "artifact_name=mo-shared-build-attempt-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT"
151166

‎.github/workflows/ci.yaml‎

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ on:
3737
EE_DB_DB:
3838
description: "matrixone cloud db"
3939
required: true
40-
DOCKERHUB_USERNAME:
41-
description: "Optional Docker Hub login for the ci-builder cache seed (rate limits)"
42-
required: false
43-
DOCKERHUB_TOKEN:
44-
description: "Optional Docker Hub token for the ci-builder cache seed (rate limits)"
45-
required: false
46-
ACR_USERNAME:
47-
description: "Optional ACR login for the ci-builder mirror pull"
48-
required: false
49-
ACR_TOKEN:
50-
description: "Optional ACR token for the ci-builder mirror pull"
51-
required: false
5240

5341
jobs:
5442
ut-linux-x86:
@@ -139,29 +127,22 @@ jobs:
139127
# recompile. Any failure here just leaves the job building cold.
140128
- name: Seed Go caches from CI builder image
141129
continue-on-error: true
142-
env:
143-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
144-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
145-
ACR_USERNAME: ${{ secrets.ACR_USERNAME }}
146-
ACR_TOKEN: ${{ secrets.ACR_TOKEN }}
147130
run: |
148131
set -euo pipefail
149132
command -v docker >/dev/null || { echo "docker unavailable; skipping seed"; exit 0; }
150133
ACR_IMAGE="registry.cn-shanghai.aliyuncs.com/matrixorigin/matrixone:ci-builder"
151134
HUB_IMAGE="matrixorigin/matrixone:ci-builder"
152-
if [ -n "${ACR_TOKEN}" ]; then
153-
echo "${ACR_TOKEN}" | docker login registry.cn-shanghai.aliyuncs.com -u "${ACR_USERNAME}" --password-stdin || true
154-
fi
155-
if [ -n "${DOCKERHUB_TOKEN}" ]; then
156-
echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin || true
157-
fi
158-
# Prefer the ACR mirror (fast from the self-hosted China runners),
159-
# time-bounded so a slow cross-region pull cannot eat the savings;
160-
# fall back to Docker Hub.
135+
# ANONYMOUS pulls on purpose: this job later executes PR-controlled
136+
# code, so no registry credential may ever touch this runner. Both
137+
# pulls are time-bounded so a registry outage cannot make the
138+
# optimized path slower than a cold build; layers are content-
139+
# addressed, so a timed-out ACR attempt still counts toward the
140+
# Docker Hub attempt of the same image. Prefer the ACR mirror
141+
# (fast from the self-hosted China runners).
161142
image=""
162143
if timeout 300 docker pull "${ACR_IMAGE}"; then
163144
image="${ACR_IMAGE}"
164-
elif docker pull "${HUB_IMAGE}"; then
145+
elif timeout 300 docker pull "${HUB_IMAGE}"; then
165146
image="${HUB_IMAGE}"
166147
fi
167148
[ -n "${image}" ] || { echo "ci-builder image unreachable; skipping seed"; exit 0; }
@@ -178,8 +159,18 @@ jobs:
178159
# read-only directories, which docker cp cannot populate.
179160
docker cp "${ctr}:/go/pkg/mod" - | tar -x --no-same-permissions --strip-components=1 -C "${gomodcache}"
180161
fi
181-
docker cp "${ctr}:/mo-prebuilt/thirdparties/install" "${RUNNER_TEMP}/mo-seed/thirdparties-install"
182-
echo "MO_PREBUILT_THIRDPARTIES=${RUNNER_TEMP}/mo-seed/thirdparties-install" >> "$GITHUB_ENV"
162+
# Restore the prebuilt thirdparties only on an exact fingerprint
163+
# match, so changed native inputs or a diverged branch rebuild from
164+
# source instead of silently testing stale native code.
165+
docker cp "${ctr}:/mo-prebuilt/thirdparties.fingerprint" "${RUNNER_TEMP}/mo-seed/thirdparties.fingerprint"
166+
expected=$(printf 'schema=1\nos=%s\narch=%s\nthirdparties_tree=%s' \
167+
"$(uname -s)" "$(uname -m)" "$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD:thirdparties)")
168+
if [ "${expected}" = "$(cat "${RUNNER_TEMP}/mo-seed/thirdparties.fingerprint")" ]; then
169+
docker cp "${ctr}:/mo-prebuilt/thirdparties/install" "${RUNNER_TEMP}/mo-seed/thirdparties-install"
170+
echo "MO_PREBUILT_THIRDPARTIES=${RUNNER_TEMP}/mo-seed/thirdparties-install" >> "$GITHUB_ENV"
171+
else
172+
echo "thirdparties fingerprint mismatch; native deps will build from source"
173+
fi
183174
- name: Unit Testing
184175
id: ut
185176
run: |
@@ -316,29 +307,22 @@ jobs:
316307
# failure here just leaves the job building cold.
317308
- name: Seed Go caches from CI builder image
318309
continue-on-error: true
319-
env:
320-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
321-
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
322-
ACR_USERNAME: ${{ secrets.ACR_USERNAME }}
323-
ACR_TOKEN: ${{ secrets.ACR_TOKEN }}
324310
run: |
325311
set -euo pipefail
326312
command -v docker >/dev/null || { echo "docker unavailable; skipping seed"; exit 0; }
327313
ACR_IMAGE="registry.cn-shanghai.aliyuncs.com/matrixorigin/matrixone:ci-builder"
328314
HUB_IMAGE="matrixorigin/matrixone:ci-builder"
329-
if [ -n "${ACR_TOKEN}" ]; then
330-
echo "${ACR_TOKEN}" | docker login registry.cn-shanghai.aliyuncs.com -u "${ACR_USERNAME}" --password-stdin || true
331-
fi
332-
if [ -n "${DOCKERHUB_TOKEN}" ]; then
333-
echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin || true
334-
fi
335-
# Prefer the ACR mirror (fast from the self-hosted China runners),
336-
# time-bounded so a slow cross-region pull cannot eat the savings;
337-
# fall back to Docker Hub.
315+
# ANONYMOUS pulls on purpose: this job later executes PR-controlled
316+
# code, so no registry credential may ever touch this runner. Both
317+
# pulls are time-bounded so a registry outage cannot make the
318+
# optimized path slower than a cold build; layers are content-
319+
# addressed, so a timed-out ACR attempt still counts toward the
320+
# Docker Hub attempt of the same image. Prefer the ACR mirror
321+
# (fast from the self-hosted China runners).
338322
image=""
339323
if timeout 300 docker pull "${ACR_IMAGE}"; then
340324
image="${ACR_IMAGE}"
341-
elif docker pull "${HUB_IMAGE}"; then
325+
elif timeout 300 docker pull "${HUB_IMAGE}"; then
342326
image="${HUB_IMAGE}"
343327
fi
344328
[ -n "${image}" ] || { echo "ci-builder image unreachable; skipping seed"; exit 0; }
@@ -359,8 +343,18 @@ jobs:
359343
if [ -z "$(ls -A "${lintcache}")" ]; then
360344
docker cp "${ctr}:/root/.cache/golangci-lint/." "${lintcache}/" || true
361345
fi
362-
docker cp "${ctr}:/mo-prebuilt/thirdparties/install" "${RUNNER_TEMP}/mo-seed/thirdparties-install"
363-
echo "MO_PREBUILT_THIRDPARTIES=${RUNNER_TEMP}/mo-seed/thirdparties-install" >> "$GITHUB_ENV"
346+
# Restore the prebuilt thirdparties only on an exact fingerprint
347+
# match, so changed native inputs or a diverged branch rebuild from
348+
# source instead of silently testing stale native code.
349+
docker cp "${ctr}:/mo-prebuilt/thirdparties.fingerprint" "${RUNNER_TEMP}/mo-seed/thirdparties.fingerprint"
350+
expected=$(printf 'schema=1\nos=%s\narch=%s\nthirdparties_tree=%s' \
351+
"$(uname -s)" "$(uname -m)" "$(git -C "$GITHUB_WORKSPACE" rev-parse HEAD:thirdparties)")
352+
if [ "${expected}" = "$(cat "${RUNNER_TEMP}/mo-seed/thirdparties.fingerprint")" ]; then
353+
docker cp "${ctr}:/mo-prebuilt/thirdparties/install" "${RUNNER_TEMP}/mo-seed/thirdparties-install"
354+
echo "MO_PREBUILT_THIRDPARTIES=${RUNNER_TEMP}/mo-seed/thirdparties-install" >> "$GITHUB_ENV"
355+
else
356+
echo "thirdparties fingerprint mismatch; native deps will build from source"
357+
fi
364358
- name: Prepare ENV
365359
env:
366360
GOPROXY: http://goproxy.goproxy.svc.cluster.local,https://goproxy.cn,direct

0 commit comments

Comments
 (0)