Skip to content

Commit 8371008

Browse files
committed
fix: revalidate Android authority before publication
1 parent 2a105cd commit 8371008

7 files changed

Lines changed: 248 additions & 68 deletions

‎.github/workflows/android-release.yml‎

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ jobs:
5757
runs-on: ubuntu-latest
5858
timeout-minutes: 45
5959
environment: android-release
60+
env:
61+
DIRECT_RELEASE_RECOVERY: ${{ inputs.direct_release_recovery && 'true' || 'false' }}
62+
EXPECTED_WORKFLOW_BRANCH: ${{ inputs.release_publish_branch }}
63+
EXPECTED_RUN_ATTEMPT: ${{ inputs.release_publish_run_attempt }}
64+
EXPECTED_WORKFLOW_FULL_REF: ${{ inputs.release_publish_full_ref }}
65+
EXPECTED_WORKFLOW_SHA: ${{ inputs.release_publish_workflow_sha }}
66+
RELEASE_PUBLISH_RUN_ID: ${{ inputs.release_publish_run_id }}
67+
RELEASE_TAG: ${{ inputs.tag }}
68+
RELEASE_TARGET_SHA: ${{ inputs.release_target_sha }}
6069
steps:
6170
- name: Checkout release tag
6271
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -78,15 +87,7 @@ jobs:
7887
id: release_approval
7988
env:
8089
APPROVAL_PATH: ${{ runner.temp }}/android-release-approval/approval.json
81-
DIRECT_RELEASE_RECOVERY: ${{ inputs.direct_release_recovery && 'true' || 'false' }}
82-
EXPECTED_WORKFLOW_BRANCH: ${{ inputs.release_publish_branch }}
83-
EXPECTED_RUN_ATTEMPT: ${{ inputs.release_publish_run_attempt }}
84-
EXPECTED_WORKFLOW_FULL_REF: ${{ inputs.release_publish_full_ref }}
85-
EXPECTED_WORKFLOW_SHA: ${{ inputs.release_publish_workflow_sha }}
8690
GH_TOKEN: ${{ github.token }}
87-
RELEASE_PUBLISH_RUN_ID: ${{ inputs.release_publish_run_id }}
88-
RELEASE_TAG: ${{ inputs.tag }}
89-
RELEASE_TARGET_SHA: ${{ inputs.release_target_sha }}
9091
run: |
9192
set -euo pipefail
9293
if [[ ! "${RELEASE_TAG}" =~ ^v[0-9]{4}\.[1-9][0-9]*\.[1-9][0-9]*(-[1-9][0-9]*)?$ ]]; then
@@ -109,30 +110,8 @@ jobs:
109110
--source-ref "${EXPECTED_WORKFLOW_FULL_REF}" \
110111
--source-digest "${EXPECTED_WORKFLOW_SHA}" \
111112
--deny-self-hosted-runners
112-
run_json="$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs/${RELEASE_PUBLISH_RUN_ID}" --method GET)"
113-
printf '%s' "${run_json}" | node scripts/validate-release-publish-approval.mjs
114-
tag_sha="$(git rev-parse "${RELEASE_TAG}^{commit}")"
115-
if [[ "${RELEASE_TARGET_SHA}" != "${tag_sha}" ]]; then
116-
echo "Release target SHA ${RELEASE_TARGET_SHA} does not match ${RELEASE_TAG} (${tag_sha})." >&2
117-
exit 1
118-
fi
119-
120-
release_json="$(gh release view "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" --json tagName,isDraft,isPrerelease,createdAt,assets,url)"
121-
if [[ "$(printf '%s' "${release_json}" | jq -r '.tagName')" != "${RELEASE_TAG}" ]]; then
122-
echo "GitHub release tag does not match ${RELEASE_TAG}." >&2
123-
exit 1
124-
fi
125-
if [[ "$(printf '%s' "${release_json}" | jq -r '.isPrerelease')" == "true" ]]; then
126-
echo "Android APK publishing requires a stable GitHub release." >&2
127-
exit 1
128-
fi
129-
release_created_at="$(printf '%s' "${release_json}" | jq -er '.createdAt')"
130-
build_timestamp="$(date -u -d "${release_created_at}" +%Y-%m-%dT%H:%M:%SZ)"
113+
build_timestamp="$(node scripts/validate-release-publish-approval.mjs)"
131114
echo "build_timestamp=${build_timestamp}" >> "${GITHUB_OUTPUT}"
132-
unexpected_assets="$(printf '%s' "${release_json}" | jq -r '[.assets[]? | select(.name | startswith("OpenClaw-Android")) | .name] | join(", ")')"
133-
if [[ -n "${unexpected_assets}" ]]; then
134-
echo "Target release already contains Android assets: ${unexpected_assets}. Immutable recovery accepts them only after rebuilding identical bytes." >&2
135-
fi
136115
137116
- name: Verify release source and Android version
138117
id: release_source
@@ -358,6 +337,12 @@ jobs:
358337
fi
359338
fi
360339
340+
- name: Revalidate release approval before Android provenance
341+
env:
342+
APPROVAL_PATH: ${{ runner.temp }}/android-release-approval/approval.json
343+
GH_TOKEN: ${{ github.token }}
344+
run: node scripts/validate-release-publish-approval.mjs > /dev/null
345+
361346
- name: Attest Android APK provenance
362347
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2
363348
with:
@@ -366,7 +351,7 @@ jobs:
366351
- name: Upload immutable Android release assets
367352
env:
368353
GH_TOKEN: ${{ github.token }}
369-
RELEASE_TAG: ${{ inputs.tag }}
354+
APPROVAL_PATH: ${{ runner.temp }}/android-release-approval/approval.json
370355
run: |
371356
set -euo pipefail
372357
attach_or_verify_asset() {
@@ -385,6 +370,9 @@ jobs:
385370
}
386371
return
387372
fi
373+
# Each irreversible write needs fresh authority after any awaited
374+
# asset lookup. This is a boundary recheck, not an atomic API guard.
375+
node scripts/validate-release-publish-approval.mjs > /dev/null || return 1
388376
gh release upload "${RELEASE_TAG}" "${source_path}#${asset_name}" --repo "${GITHUB_REPOSITORY}"
389377
}
390378

‎docs/reference/RELEASING.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,12 @@ v2 receipt and the live parent identity, including the protected tooling tag or
602602
main ancestry. Normal Android admission accepts an active or successfully completed
603603
parent and the exact stable target release, whether draft or public. Failed or
604604
cancelled parents remain rejected; explicit recovery can separately admit a
605-
completed failed parent. A dispatched run link is pending publication evidence,
606-
not an APK download claim. Monitor and approve the linked Android run separately;
605+
completed failed parent. Before provenance publication and each asset upload,
606+
Android rechecks the live release tag target and stable classification, protected
607+
tooling identity, and exact parent attempt/state. These are fresh boundary checks,
608+
not an atomic GitHub validation-and-write transaction. A dispatched run link is
609+
pending publication evidence, not an APK download claim. Monitor and approve the
610+
linked Android run separately;
607611
if dispatch cannot be confirmed, inspect existing runs before retrying.
608612
For explicit Android recovery, pass `release_publish_run_attempt`,
609613
`release_publish_full_ref`, and `release_publish_workflow_sha` from that same

‎scripts/release-tooling-identity.d.mts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export function validateReleaseToolingIdentity(
2727
},
2828
): ReleaseToolingIdentity;
2929

30+
export function runReleaseToolingGh(args: string[]): string;
31+
3032
export function verifyReleaseToolingIdentity(
3133
input: ReleaseToolingIdentityInput & {
3234
repository: string;

‎scripts/release-tooling-identity.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ function parseJson(raw, label) {
291291
}
292292
}
293293

294-
function runReleaseToolingGh(args) {
294+
export function runReleaseToolingGh(args) {
295295
return execFileSync("gh", args, {
296296
encoding: "utf8",
297297
killSignal: "SIGKILL",

‎scripts/validate-release-publish-approval.mjs‎

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
22
// Validates that a referenced release-publish workflow run is usable for approval.
3+
import { execFileSync } from "node:child_process";
34
import fs from "node:fs";
45
import {
6+
runReleaseToolingGh,
57
validateReleasePublishParentRun,
68
verifyReleaseToolingIdentity,
79
} from "./release-tooling-identity.mjs";
810

9-
const run = JSON.parse(fs.readFileSync(0, "utf8"));
10-
1111
const releasePublishRunId = process.env.RELEASE_PUBLISH_RUN_ID ?? "";
1212
const expectedBranch = process.env.EXPECTED_WORKFLOW_BRANCH ?? "";
1313
const directRecovery = process.env.DIRECT_RELEASE_RECOVERY === "true";
@@ -18,6 +18,8 @@ const expectedRunAttempt = process.env.EXPECTED_RUN_ATTEMPT ?? "";
1818
const expectedWorkflowFullRef = process.env.EXPECTED_WORKFLOW_FULL_REF ?? "";
1919
const expectedWorkflowSha = process.env.EXPECTED_WORKFLOW_SHA ?? "";
2020
const childWorkflowSha = process.env.CHILD_WORKFLOW_SHA ?? "";
21+
const run =
22+
approvalKind === "android" && approvalPath ? null : JSON.parse(fs.readFileSync(0, "utf8"));
2123

2224
function fail(message) {
2325
console.error(message);
@@ -95,8 +97,43 @@ if (approvalPath) {
9597
fail(mismatchMessage);
9698
}
9799
if (approvalKind === "android") {
98-
// The attestation binds the receipt; the live tooling identity and REST
99-
// parent bind its authority now, including after a parent rerun or tag move.
100+
const tag = process.env.RELEASE_TAG;
101+
const target = process.env.RELEASE_TARGET_SHA;
102+
// Match the publisher's live direct/peeled tag contract; release tags may
103+
// be signed annotated tags while protected tooling tags must be lightweight.
104+
const refs = execFileSync(
105+
"git",
106+
["ls-remote", "--tags", "origin", `refs/tags/${tag}`, `refs/tags/${tag}^{}`],
107+
{
108+
encoding: "utf8",
109+
timeout: 60_000,
110+
maxBuffer: 1024 * 1024,
111+
},
112+
)
113+
.trim()
114+
.split("\n")
115+
.map((line) => line.split(/\s+/u));
116+
const targetSha =
117+
refs.find(([, ref]) => ref === `refs/tags/${tag}^{}`)?.[0] ??
118+
refs.find(([, ref]) => ref === `refs/tags/${tag}`)?.[0];
119+
if (targetSha !== target) {
120+
fail(`Release tag ${tag} no longer resolves to approved target ${target}.`);
121+
}
122+
const release = JSON.parse(
123+
runReleaseToolingGh([
124+
"release",
125+
"view",
126+
tag,
127+
"--repo",
128+
process.env.GITHUB_REPOSITORY,
129+
"--json",
130+
"tagName,isPrerelease,createdAt",
131+
]),
132+
);
133+
if (release.tagName !== tag || release.isPrerelease !== false) {
134+
fail("Android publication requires the exact approved stable GitHub release.");
135+
}
136+
const buildTimestamp = new Date(release.createdAt).toISOString().replace(/\.000Z$/u, "Z");
100137
const identity = verifyReleaseToolingIdentity({
101138
allowPrevalidatedRef: /^release\/[0-9]{4}\.(?:[1-9]|1[0-2])\.[1-9][0-9]*$/u.test(
102139
expectedBranch,
@@ -106,6 +143,16 @@ if (approvalPath) {
106143
workflowRef: expectedBranch,
107144
workflowSha: expectedWorkflowSha,
108145
});
146+
// Fetch parent authority last so target/tooling reads cannot retain an
147+
// admission snapshot across a parent failure, cancellation, or rerun.
148+
const currentRun = JSON.parse(
149+
runReleaseToolingGh([
150+
"api",
151+
`repos/${process.env.GITHUB_REPOSITORY}/actions/runs/${releasePublishRunId}`,
152+
"--method",
153+
"GET",
154+
]),
155+
);
109156
validateReleasePublishParentRun({
110157
identity,
111158
releasePublishFullRef: expectedWorkflowFullRef,
@@ -114,11 +161,9 @@ if (approvalPath) {
114161
releasePublishRunAttempt: expectedRunAttempt,
115162
releasePublishRunId,
116163
repository: process.env.GITHUB_REPOSITORY,
117-
run,
164+
run: currentRun,
118165
});
119-
console.log(
120-
`Using attested Android release approval run ${releasePublishRunId}: ${run.html_url}`,
121-
);
166+
process.stdout.write(`${buildTimestamp}\n`);
122167
process.exit(0);
123168
}
124169
}

‎test/scripts/package-acceptance-workflow.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8188,7 +8188,7 @@ printf '%s\\n' "$DEEPSEEK_API_KEY" "$DEEPINFRA_API_KEY"`,
81888188
expect(androidWorkflow).toContain("--verify-apk");
81898189
expect(androidWorkflow).toContain('expected_source_ref="refs/tags/${RELEASE_TAG}"');
81908190
expect(androidWorkflow).toContain("release_target_sha must be a full lowercase commit SHA");
8191-
expect(androidWorkflow).toContain("does not match ${RELEASE_TAG} (${tag_sha})");
8191+
expect(approvalScript).toContain("no longer resolves to approved target");
81928192
expect(androidWorkflow).toContain(
81938193
"must resolve to the same source commit as ${fallback_base_tag}",
81948194
);
@@ -8200,8 +8200,10 @@ printf '%s\\n' "$DEEPSEEK_API_KEY" "$DEEPINFRA_API_KEY"`,
82008200
"OPENCLAW_BUILD_TIMESTAMP: ${{ steps.release_approval.outputs.build_timestamp }}",
82018201
);
82028202
expect(androidWorkflow).toContain("GIT_COMMIT: ${{ inputs.release_target_sha }}");
8203-
expect(androidWorkflow).toContain("--json tagName,isDraft,isPrerelease,createdAt,assets,url");
8204-
expect(androidWorkflow).toContain("release_created_at=");
8203+
expect(approvalScript).toContain("tagName,isPrerelease,createdAt");
8204+
expect(androidWorkflow).toContain(
8205+
'build_timestamp="$(node scripts/validate-release-publish-approval.mjs)"',
8206+
);
82058207
expect(androidWorkflow).toContain(
82068208
"Reusing verified Android APK from ${FALLBACK_ANDROID_BASE_TAG}",
82078209
);

0 commit comments

Comments
 (0)