Skip to content

Commit a43b0ae

Browse files
authored
ci: admit a hosted form for the release jobs with protected credentials (#771)
* ci: admit hosted release form with protected credentials Teach preflight the hosted release/notify-hub form while retaining the legacy isolated form and pin the hosted released-archive comparison contract. Add negative rows for missing environment, wrong runners, credential sharing, and archive-contract mutations. * test: preserve literal shell escape in hosted release fixture Keep the workflow snippet byte-faithful in the hosted admission rows so the candidate/control proof exercises the real release text. * test: preserve archive command continuations in release fixture Keep the synthetic hosted release fixture byte-faithful to the reviewed released-archive step contract. * ci: preserve legacy release findings during hosted migration Keep isolated runner diagnostics and prebuilt contract text byte-compatible while admitting the paired hosted release form.
1 parent 36dd032 commit a43b0ae

2 files changed

Lines changed: 334 additions & 21 deletions

File tree

‎scripts/ci_preflight.py‎

Lines changed: 156 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,21 @@
9696
PR_FAST_ROWS_SHA256 = '0509b2219786efb6878b193639344c299ff8075ba4532dbe09e80e6e97b60a9a'
9797
# Every migrated job runs on a standard hosted Ubuntu image: x86 on
9898
# ubuntu-24.04 and arm64 on ubuntu-24.04-arm. An unpinned job in a migrated
99-
# workflow must use the x86 image. Only release.yml, which is unchanged here,
100-
# keeps its protected GKP labels and its Bookworm old-glibc path.
99+
# workflow must use the x86 image. The legacy release form keeps its protected
100+
# GKP labels and its Bookworm old-glibc path; the hosted release form uses the
101+
# standard x86 image and the reviewed released-archive comparison.
101102
HOSTED_X86_RUNNER = 'ubuntu-24.04'
102103
HOSTED_ARM_RUNNER = 'ubuntu-24.04-arm'
103104
PR_RUNNER = HOSTED_X86_RUNNER
104105
POST_RUNNER = HOSTED_X86_RUNNER
105-
# The probe and promotion jobs keep their release-only events and environments.
106+
# The probe, promotion and both release forms keep their release-only events
107+
# and environments.
106108
PROTECTED_RUNNER = HOSTED_X86_RUNNER
107109
RELEASE_RUNNER = 'gkp-od-4cpu-8gb-amd64'
108110
PREBUILT_RUNNER = 'gkp-od-16cpu-32gb-amd64-128gb'
109111
PREBUILT_ARM_RUNNER = 'ubuntu-22.04-arm'
110-
# Only release.yml may still name a GKP label: its two protected scale sets.
112+
# Only release.yml may name GKP labels. The legacy form retains both protected
113+
# release labels; the hosted form has only the protected prebuilt cell.
111114
GKP_JOB_RUNNERS = {
112115
'release.yml': {'release': RELEASE_RUNNER, 'notify-hub': RELEASE_RUNNER,
113116
'prebuilt': PREBUILT_RUNNER},
@@ -366,6 +369,12 @@ def post_build_name(count: int) -> str:
366369
'release-ruleset-probe.yml': {'probe': PROTECTED_RUNNER},
367370
'promote-baseline.yml': {'promote': PROTECTED_RUNNER},
368371
}
372+
# Issue #768 moves only release and notify-hub to the standard hosted image. Keep
373+
# this separate from RELEASE_JOB_RUNNERS so the old isolated form remains a
374+
# valid, exact contract.
375+
HOSTED_RELEASE_JOB_RUNNERS = {
376+
'release.yml': {'release': HOSTED_X86_RUNNER, 'notify-hub': HOSTED_X86_RUNNER},
377+
}
369378
# Credential-bearing jobs outside the release pins and gated docs build retain
370379
# standard hosted labels. Existing hosted exceptions above are pinned separately.
371380
STANDARD_RUNNERS = ('ubuntu-24.04', 'ubuntu-24.04-arm')
@@ -2370,6 +2379,38 @@ def _holds_credentials(workflow: str, body: str, *, effective_permissions: bool
23702379
return False
23712380

23722381

2382+
def _job_environment_is(body: str, expected: str) -> bool:
2383+
"""Recognize one exact literal environment name, including mapping form."""
2384+
if not _literal_job_environment(body):
2385+
return False
2386+
values = _job_values(body, 'environment', unquote=False)
2387+
block = _job_block(body, 'environment')
2388+
if block:
2389+
values = _job_values('\n'.join(block[1:]), 'name', unquote=False)
2390+
if len(values) != 1:
2391+
return False
2392+
code, _, _ = _action_yaml_visible(values[0])
2393+
if _ACTION_YAML_QUOTED.fullmatch(code):
2394+
code = code[1:-1]
2395+
return code == expected
2396+
2397+
2398+
def release_credential_findings(workflow: str, name: str = 'release.yml') -> list[str]:
2399+
"""Keep the protected release environment and App credential surface isolated."""
2400+
findings = []
2401+
for job, body in _jobs(workflow).items():
2402+
if job in ('release', 'notify-hub'):
2403+
continue
2404+
# strict=True admits the existing GITHUB_TOKEN-only prebuilt surface,
2405+
# while refusing any other secret, inherited environment, OIDC write,
2406+
# App mint or private-key handoff.
2407+
if _job_environment_is(body, 'release') or _holds_credentials(
2408+
workflow, body, strict=True):
2409+
findings.append(f'{name} job {job} must not receive the protected release '
2410+
'environment or release credentials')
2411+
return findings
2412+
2413+
23732414
def _runner_value(value: str) -> str | list[str]:
23742415
"""Compare literal runner arrays as arrays; expressions remain exact pins."""
23752416
try:
@@ -2828,7 +2869,7 @@ def visit(name: str, inputs: dict[str, str], multiplier: int, stack: tuple[str,
28282869

28292870

28302871
def runner_findings(workflows: dict[str, str]) -> list[str]:
2831-
"""Enforce event-derived fleets, isolated releases and command/core pins."""
2872+
"""Enforce event-derived fleets, release forms and command/core pins."""
28322873
findings = workflow_fleet_findings(workflows) + _gke_cap_findings(workflows)
28332874
routes = workflow_event_routes(workflows)
28342875
for name, workflow in workflows.items():
@@ -2845,6 +2886,7 @@ def runner_findings(workflows: dict[str, str]) -> list[str]:
28452886
gke_pins = GKE_PR_ARM_JOB_LABELS if arm_variant else GKE_JOB_RUNNERS.get(name, {})
28462887
gkp_pins = GKP_JOB_RUNNERS.get(name, {})
28472888
hosted_pins = HOSTED_JOB_RUNNERS.get(name, {})
2889+
hosted_release_pins = HOSTED_RELEASE_JOB_RUNNERS.get(name, {})
28482890
if arm_variant:
28492891
hosted_pins = {**hosted_pins, **gke_pins}
28502892
fixed_hosted = {job: label for job, label in hosted_pins.items()
@@ -2860,6 +2902,24 @@ def runner_findings(workflows: dict[str, str]) -> list[str]:
28602902
if (fixed_release and name != 'promote-baseline.yml'
28612903
and _events(workflow) != {'workflow_dispatch'}):
28622904
findings.append(f'{name} must retain workflow_dispatch only for protected release jobs')
2905+
if name == 'release.yml':
2906+
findings += release_credential_findings(workflow, name)
2907+
release_runner = _job_values(jobs.get('release', ''), 'runs-on',
2908+
unquote=False)
2909+
notify_runner = _job_values(jobs.get('notify-hub', ''), 'runs-on',
2910+
unquote=False)
2911+
if release_runner and notify_runner:
2912+
release_hosted = release_runner == [HOSTED_X86_RUNNER]
2913+
notify_hosted = notify_runner == [HOSTED_X86_RUNNER]
2914+
if release_hosted != notify_hosted:
2915+
findings.append(
2916+
'release.yml release and notify-hub must use the same '
2917+
'hosted or isolated runner form')
2918+
hosted_release_form = (
2919+
release_runner == [HOSTED_X86_RUNNER]
2920+
and notify_runner == [HOSTED_X86_RUNNER])
2921+
else:
2922+
hosted_release_form = False
28632923
if (name == 'promote-baseline.yml'
28642924
and _events(workflow) != {'push', 'workflow_dispatch'}):
28652925
findings.append(f'{name} must retain push and workflow_dispatch '
@@ -2958,15 +3018,19 @@ def runner_findings(workflows: dict[str, str]) -> list[str]:
29583018
# removing comment-only lines; the runner label is exact.
29593019
actual = _job_values(body, 'runs-on', unquote=False)
29603020
expected = [fixed_release[job]]
2961-
if actual != expected:
3021+
hosted_expected = hosted_release_pins.get(job)
3022+
hosted = hosted_release_form and hosted_expected is not None and actual == [hosted_expected]
3023+
if actual != expected and not hosted:
29623024
# The probe and promotion jobs run on the hosted image; the
2963-
# unchanged release jobs keep their isolated GKP labels.
2964-
suffix = ' (hosted)' if fixed_release[job] in STANDARD_RUNNERS else ' (isolated release)'
3025+
# legacy release jobs keep their isolated GKP labels. The
3026+
# hosted release form has its own exact standard pin.
3027+
suffix = (' (hosted)' if fixed_release[job] in STANDARD_RUNNERS
3028+
else ' (isolated release)')
29653029
findings.append(f'{name} job {job} must run on {fixed_release[job]}{suffix}')
29663030
environments = _job_values(workflow, 'env') + _job_values(body, 'env')
29673031
if any(re.search(r'\bPF_CI_LABELS["\']?\s*:', value) for value in environments):
2968-
findings.append(f'{name} job {job} must not set PF_CI_LABELS '
2969-
'on an isolated release job')
3032+
route = 'a hosted release job' if hosted else 'an isolated release job'
3033+
findings.append(f'{name} job {job} must not set PF_CI_LABELS on {route}')
29703034
elif gkp_pin and job in fixed_hosted:
29713035
if raw_runners != [gkp_pin]:
29723036
findings.append(f'{name} job {job} must run on {gkp_pin}')
@@ -3218,9 +3282,10 @@ def _compiler_cache_restore_with(step: str) -> list[str]:
32183282
echo "Eigen3 3.4.0 present at $(dirname "$(dirname "$hdr")")"
32193283
'''
32203284

3221-
# Exact reviewed steps: ARM host commands, x86 transport, identity, all-library
3222-
# inspection and publication order form one contract. Extra steps fail closed.
3223-
RELEASE_PREBUILT_STEPS = r'''
3285+
# The legacy isolated form retains this exact step list. The hosted form below
3286+
# replaces only the glibc check with the reviewed released-archive comparison;
3287+
# both lists remain closed to extra or reordered steps.
3288+
RELEASE_PREBUILT_LEGACY_STEPS = r'''
32243289
# A dry run has no tag yet: it builds the dispatched commit.
32253290
- name: Checkout release commit
32263291
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
@@ -3408,6 +3473,70 @@ def _compiler_cache_restore_with(step: str) -> list[str]:
34083473
'''
34093474

34103475

3476+
RELEASE_PREBUILT_LEGACY_GLIBC_STEP = r''' # Both dry-run and publication inspect every installed .a/.so/.so.*.
3477+
# Keep raw checker output and its actual exit status, including setup errors.
3478+
- name: Check every staged library's glibc floor
3479+
env:
3480+
TRIPLE: ${{ matrix.triple }}
3481+
run: |
3482+
set -euo pipefail
3483+
log="${RUNNER_TEMP}/prebuilt-glibc-${TRIPLE}"
3484+
mkdir -p "${log}"
3485+
if python3 scripts/check_prebuilt_glibc.py "${STAGE_DIR}" > "${log}/stdout.jsonl" 2> "${log}/stderr.txt"; then
3486+
checker_rc=0
3487+
else checker_rc=$?; fi
3488+
printf '%s\n' "${checker_rc}" > "${log}/exitcode.txt"
3489+
cat "${log}/stdout.jsonl"
3490+
cat "${log}/stderr.txt" >&2
3491+
exit "${checker_rc}"'''
3492+
3493+
RELEASE_PREBUILT_ARCHIVE_GLIBC_STEPS = r''' # The glibc comparison baseline is this triple's archive from the v1.10.0
3494+
# release: the real released bytes, pinned by sha256 and unpacked here.
3495+
# The checker below only reads the unpacked libraries.
3496+
- name: Fetch the v1.10.0 baseline archive for the glibc comparison
3497+
env:
3498+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3499+
TRIPLE: ${{ matrix.triple }}
3500+
run: |
3501+
set -euo pipefail
3502+
case "${TRIPLE}" in
3503+
linux-x86_64) digest=cb412fbae9e8ba515de41dc31026c77d6c5e309693247bee26bb93c67d3c3543 ;;
3504+
linux-aarch64) digest=982b16da2d5f5ee7c274615895484fce36bd740052a14d59b66576dca496d7bb ;;
3505+
*) echo "::error::no v1.10.0 baseline archive for ${TRIPLE}" >&2; exit 1 ;;
3506+
esac
3507+
archive="pineforge-v1.10.0-${TRIPLE}.tar.gz"
3508+
root="${RUNNER_TEMP}/glibc-baseline-${TRIPLE}"
3509+
mkdir "${root}" "${root}/download" "${root}/tree"
3510+
gh release download v1.10.0 --repo "${GITHUB_REPOSITORY}" \
3511+
--pattern "${archive}" --dir "${root}/download"
3512+
echo "${digest} ${root}/download/${archive}" | sha256sum -c -
3513+
tar -xzf "${root}/download/${archive}" -C "${root}/tree" \
3514+
--no-same-owner --no-same-permissions
3515+
echo "BASELINE_DIR=${root}/tree" >> "${GITHUB_ENV}"
3516+
3517+
# Both dry-run and publication inspect every installed .a/.so/.so.* and
3518+
# compare their highest glibc tag with the baseline fetched above.
3519+
# Keep raw checker output and its actual exit status, including setup errors.
3520+
- name: Check every staged library's glibc floor
3521+
env:
3522+
TRIPLE: ${{ matrix.triple }}
3523+
run: |
3524+
set -euo pipefail
3525+
log="${RUNNER_TEMP}/prebuilt-glibc-${TRIPLE}"
3526+
mkdir -p "${log}"
3527+
if python3 scripts/check_prebuilt_glibc.py "${STAGE_DIR}" --baseline-root "${BASELINE_DIR}" > "${log}/stdout.jsonl" 2> "${log}/stderr.txt"; then
3528+
checker_rc=0
3529+
else checker_rc=$?; fi
3530+
printf '%s\n' "${checker_rc}" > "${log}/exitcode.txt"
3531+
cat "${log}/stdout.jsonl"
3532+
cat "${log}/stderr.txt" >&2
3533+
exit "${checker_rc}"'''
3534+
3535+
# The new hosted release form is one exact, reviewed real-archive contract.
3536+
RELEASE_PREBUILT_STEPS = RELEASE_PREBUILT_LEGACY_STEPS.replace(
3537+
RELEASE_PREBUILT_LEGACY_GLIBC_STEP, RELEASE_PREBUILT_ARCHIVE_GLIBC_STEPS)
3538+
3539+
34113540
# Git blob identity of the transport, including build and archive-consumer launch.
34123541
# A changed helper requires reviewing its source and controls before repinning.
34133542
# This is a source contract, never an engine/build/glibc verdict.
@@ -3438,6 +3567,12 @@ def release_prebuilt_consumer_findings(source: str) -> list[str]:
34383567
def release_prebuilt_workflow_findings(workflow: str) -> list[str]:
34393568
"""Pin artifact structure and its token-only admission surface."""
34403569
prebuilt = _jobs(workflow).get('prebuilt', '')
3570+
release = _jobs(workflow).get('release', '')
3571+
notify = _jobs(workflow).get('notify-hub', '')
3572+
hosted_release = (
3573+
_job_values(release, 'runs-on', unquote=False) == [HOSTED_X86_RUNNER]
3574+
and _job_values(notify, 'runs-on', unquote=False) == [HOSTED_X86_RUNNER])
3575+
reviewed_steps = RELEASE_PREBUILT_STEPS if hosted_release else RELEASE_PREBUILT_LEGACY_STEPS
34413576
findings = []
34423577
if _job_values(prebuilt, 'needs') != ['release']:
34433578
findings.append('release.yml prebuilt must retain needs: release before build')
@@ -3448,12 +3583,16 @@ def release_prebuilt_workflow_findings(workflow: str) -> list[str]:
34483583
if _job_values(prebuilt, 'uses'):
34493584
findings.append('release.yml prebuilt must not use a reusable workflow')
34503585
if ([_code(step) for step in _steps(prebuilt)]
3451-
!= [_code(step) for step in _steps(RELEASE_PREBUILT_STEPS)]):
3452-
findings.append('release.yml prebuilt must retain the credential-free Bookworm build, '
3453-
'ARM Eigen setup, all-library glibc gate and packed-archive consumer before upload')
3586+
!= [_code(step) for step in _steps(reviewed_steps)]):
3587+
finding = ('release.yml prebuilt must retain the credential-free Bookworm build, '
3588+
'ARM Eigen setup, all-library glibc gate and packed-archive consumer '
3589+
'before upload')
3590+
if hosted_release:
3591+
finding += '; the hosted form also pins its released-archive comparison'
3592+
findings.append(finding)
34543593
marker = " - name: Check every staged library's glibc floor"
34553594
gate = _step_named(_steps(prebuilt), marker)
3456-
required_gate = _step_named(_steps(RELEASE_PREBUILT_STEPS), marker)
3595+
required_gate = _step_named(_steps(reviewed_steps), marker)
34573596
# Compare raw physical lines in the named step. Removing blank/comment
34583597
# lines before comparison can turn a disabled shell continuation into proof.
34593598
if gate.rstrip('\n') != required_gate.rstrip('\n'):

0 commit comments

Comments
 (0)