aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / scripts / test-release-signing-workflow.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # Static guard for the offline-signing handoff (Drake ruling 1, sc#385): no private release key in CI, ever. |
| 18 | # scripts/test-release-signing-workflow.sh [release.yml] [release-publish.yml] |
| 19 | # release.yml: no AIEN_RELEASE_SIGNING_KEY and no secret other than GITHUB_TOKEN; `ssh-keygen -Y sign` only inside the |
| 20 | # dry-run-sign job (a throwaway key made in that job), which runs only on a manual dry run; every `gh release create` |
| 21 | # makes a --draft; release.yml never publishes, edits or uploads to a release. |
| 22 | # release-publish.yml: manual trigger only; no secret other than GITHUB_TOKEN; never signs; the publish gate |
| 23 | # (scripts/release-publish-gate.sh) runs before the only `gh release edit`; nothing in it can be skipped or made |
| 24 | # non-blocking (no if:, no continue-on-error); the tag input reaches shell only through env. |
| 25 | # Mutation note: the self-checks below inject each forbidden pattern into a copy; each must turn this guard red. |
| 26 | set -euo pipefail |
| 27 | ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 28 | REL="${1:-$ROOT/.github/workflows/release.yml}" |
| 29 | PUB="${2:-$ROOT/.github/workflows/release-publish.yml}" |
| 30 | err() { echo "FAIL: $*" >&2; return 1; } |
| 31 | code() { grep -nvE '^[[:space:]]*#' "$1" || true; } # numbered lines that are not comments |
| 32 | # job_lines <file> <pattern>: "<job>\t<line>" for each non-comment line matching pattern, inside jobs: |
| 33 | job_lines() { |
| 34 | awk -v pat="$2" ' |
| 35 | /^[a-z]/ { injobs = ($0 ~ /^jobs:/); job = ""; next } |
| 36 | injobs && /^ [a-zA-Z_-]+:[[:space:]]*$/ { job = $1; sub(/:$/, "", job); next } |
| 37 | $0 ~ /^[[:space:]]*#/ { next } |
| 38 | $0 ~ pat { printf "%s\t%s\n", job, $0 }' "$1" |
| 39 | } |
| 40 | check_rel() { |
| 41 | local f="$1" bad |
| 42 | ! grep -q 'AIEN_RELEASE_SIGNING_KEY' "$f" || { err "$f names AIEN_RELEASE_SIGNING_KEY"; return 1; } |
| 43 | bad="$(code "$f" | grep -E 'secrets\.' | grep -vE 'secrets\.GITHUB_TOKEN' || true)" |
| 44 | [[ -z "$bad" ]] || { err "$f uses a secret other than GITHUB_TOKEN: $bad"; return 1; } |
| 45 | bad="$(job_lines "$f" 'ssh-keygen[[:space:]].*-Y[[:space:]]+sign' | awk -F'\t' '$1 != "dry-run-sign"' || true)" |
| 46 | [[ -z "$bad" ]] || { err "$f signs outside the dry-run-sign job: $bad"; return 1; } |
| 47 | job_lines "$f" '^ if:' | grep -E '^dry-run-sign ' | grep -q "github.event_name == 'workflow_dispatch' && inputs.dry_run$" \ |
| 48 | || { err "$f dry-run-sign job is not limited to a manual dry run"; return 1; } |
| 49 | bad="$(code "$f" | grep -E 'gh release create' | grep -vE -- '--draft( |$)' || true)" |
| 50 | [[ -z "$bad" ]] || { err "$f creates a release that is not a draft: $bad"; return 1; } |
| 51 | bad="$(code "$f" | grep -E -- '--draft=false|gh release (edit|upload)|gh api .*releases|action-gh-release|upload-release' || true)" |
| 52 | [[ -z "$bad" ]] || { err "$f publishes, edits or uploads to a release: $bad"; return 1; } |
| 53 | } |
| 54 | check_pub() { |
| 55 | local f="$1" bad gate edit |
| 56 | awk '/^on:/ { on = 1; next } on && /^[a-z]/ { on = 0 } on && /^ [a-z_]+:/ { print $1 }' "$f" | grep -vxq 'workflow_dispatch:' \ |
| 57 | && { err "$f has a trigger other than workflow_dispatch"; return 1; } |
| 58 | bad="$(code "$f" | grep -E 'secrets\.' | grep -vE 'secrets\.GITHUB_TOKEN' || true)" |
| 59 | [[ -z "$bad" ]] || { err "$f uses a secret other than GITHUB_TOKEN: $bad"; return 1; } |
| 60 | ! code "$f" | grep -qE 'ssh-keygen[[:space:]].*-Y[[:space:]]+sign' || { err "$f signs"; return 1; } |
| 61 | ! code "$f" | grep -qE '^[0-9]+:[[:space:]]*(- )?(if|continue-on-error):' || { err "$f has an if: or continue-on-error"; return 1; } |
| 62 | gate="$(code "$f" | grep -E 'run: bash scripts/release-publish-gate\.sh release-assets docs/release/allowed_signers$' | head -1 | cut -d: -f1)" |
| 63 | edit="$(code "$f" | grep -E 'gh release edit' | cut -d: -f1)" |
| 64 | [[ -n "$gate" ]] || { err "$f does not run the publish gate against docs/release/allowed_signers"; return 1; } |
| 65 | [[ "$(printf '%s\n' "$edit" | grep -c .)" -eq 1 && "$edit" -gt "$gate" ]] || { err "$f publishes before (or without) the gate"; return 1; } |
| 66 | bad="$(code "$f" | grep -E '\$\{\{ *inputs\.' | grep -vE '^[0-9]+:[[:space:]]+(TAG|ref):' || true)" |
| 67 | [[ -z "$bad" ]] || { err "$f interpolates an input outside env/ref: $bad"; return 1; } |
| 68 | } |
| 69 | check_rel "$REL" |
| 70 | check_pub "$PUB" |
| 71 | |
| 72 | M="$(mktemp -d)"; trap 'rm -rf "$M"' EXIT |
| 73 | n=0 |
| 74 | must_refuse() { local what="$1" kind="$2" src="$3" mut="$4" |
| 75 | cmp -s "$src" "$mut" && { echo "FAIL: mutation did not apply ($what); update this guard" >&2; exit 1; } |
| 76 | if "$kind" "$mut" 2>/dev/null; then echo "FAIL: guard does not catch: $what" >&2; exit 1; fi |
| 77 | n=$((n + 1)); } |
| 78 | sed '/^ - name: Generate Checksums$/i\ - name: sign\n env:\n K: ${{ secrets.AIEN_RELEASE_SIGNING_KEY }}\n run: echo' "$REL" > "$M/r1" |
| 79 | must_refuse "release key secret back in release.yml" check_rel "$REL" "$M/r1" |
| 80 | sed '/^ - name: Generate Checksums$/i\ - name: sign\n env:\n K: ${{ secrets.SOME_KEY }}\n run: echo' "$REL" > "$M/r2" |
| 81 | must_refuse "another secret in release.yml" check_rel "$REL" "$M/r2" |
| 82 | sed 's/^ sha256sum sovereign-\* aien-cli-digests.txt > SHA256SUMS.txt$/&\n ssh-keygen -Y sign -f k -n aien-release SHA256SUMS.txt/' "$REL" > "$M/r3" |
| 83 | must_refuse "signing in the draft-release job" check_rel "$REL" "$M/r3" |
| 84 | sed 's/gh release create "$TAG" --draft --verify-tag/gh release create "$TAG" --verify-tag/' "$REL" > "$M/r4" |
| 85 | must_refuse "non-draft gh release create" check_rel "$REL" "$M/r4" |
| 86 | sed 's/^ --notes-file ..\/release-notes-with-digests.md$/&\n gh release edit "$TAG" --draft=false/' "$REL" > "$M/r5" |
| 87 | must_refuse "release.yml publishing the draft" check_rel "$REL" "$M/r5" |
| 88 | sed "s/^ if: github.event_name == 'workflow_dispatch' \&\& inputs.dry_run\$/ if: always()/" "$REL" > "$M/r6" |
| 89 | must_refuse "dry-run-sign job runs outside a manual dry run" check_rel "$REL" "$M/r6" |
| 90 | sed 's/^ workflow_dispatch:$/ push:\n tags: ["v*"]\n&/' "$PUB" > "$M/p1" |
| 91 | must_refuse "publish workflow on push" check_pub "$PUB" "$M/p1" |
| 92 | sed 's/^ run: bash scripts\/release-publish-gate.sh release-assets docs\/release\/allowed_signers$/ continue-on-error: true\n&/' "$PUB" > "$M/p2" |
| 93 | must_refuse "publish gate made non-blocking" check_pub "$PUB" "$M/p2" |
| 94 | grep -v 'run: bash scripts/release-publish-gate.sh' "$PUB" > "$M/p3" |
| 95 | must_refuse "publish gate removed" check_pub "$PUB" "$M/p3" |
| 96 | sed 's/^ - name: Check the tag name$/ - name: early\n run: gh release edit "$TAG" --draft=false\n&/' "$PUB" > "$M/p4" |
| 97 | must_refuse "publish before the gate" check_pub "$PUB" "$M/p4" |
| 98 | sed 's/^ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}$/&\n K: ${{ secrets.AIEN_RELEASE_SIGNING_KEY }}/' "$PUB" > "$M/p5" |
| 99 | must_refuse "release key secret in the publish workflow" check_pub "$PUB" "$M/p5" |
| 100 | sed 's/^ run: gh release edit "$TAG" --draft=false$/ run: echo ${{ inputs.tag }}; gh release edit "$TAG" --draft=false/' "$PUB" > "$M/p6" |
| 101 | must_refuse "input interpolated into a run line" check_pub "$PUB" "$M/p6" |
| 102 | sed 's/^ run: bash scripts\/release-publish-gate.sh release-assets docs\/release\/allowed_signers$/ run: bash scripts\/release-publish-gate.sh release-assets release-assets\/dry-run-signers/' "$PUB" > "$M/p7" |
| 103 | must_refuse "publish gate pointed at a signer file other than allowed_signers" check_pub "$PUB" "$M/p7" |
| 104 | echo "ok: no release key in CI; release.yml signs only in the manual dry run and only drafts; release-publish.yml is manual, keyless and publishes only after the blocking publish gate; $n mutants refused" |