diff --git a/.github/workflows/hermes-drift.yml b/.github/workflows/hermes-drift.yml index 16fef16..a6dfb5c 100644 --- a/.github/workflows/hermes-drift.yml +++ b/.github/workflows/hermes-drift.yml @@ -36,12 +36,12 @@ jobs: upstream-contract: runs-on: ubuntu-latest steps: - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: NousResearch/hermes-agent path: .hermes-agent-upstream - - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + - uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2877524..6be4d56 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,7 +48,7 @@ jobs: version: ${{ steps.identity.outputs.version }} steps: - name: Check out the triggering main revision - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false @@ -62,7 +62,7 @@ jobs: EXPECTED_SHA: ${{ github.sha }} run: just release-attach-trigger - name: Install uv - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true @@ -155,7 +155,7 @@ jobs: sha256sum release-source.bundle > release-source.sha256 - name: Upload the immutable release source if: steps.intent.outputs.released == 'true' - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: ${{ steps.identity.outputs.source_artifact_name }} path: | @@ -175,18 +175,12 @@ jobs: outputs: enabled: ${{ steps.verify.outputs.enabled }} steps: - - name: Mint a current-repository administration-read token - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 - with: - client-id: ${{ vars.SOURCE_PROMOTION_APP_CLIENT_ID }} - private-key: ${{ secrets.SOURCE_PROMOTION_APP_PRIVATE_KEY }} - permission-administration: read - name: Fail closed unless immutable releases are enabled id: verify env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} + GH_TOKEN: ${{ secrets.SOURCE_PROMOTION_TOKEN }} run: | + : "${GH_TOKEN:?SOURCE_PROMOTION_TOKEN must be configured in source-promotion}" enabled="$(gh api "repos/$GITHUB_REPOSITORY/immutable-releases" --jq '.enabled')" test "$enabled" = "true" echo "enabled=true" >> "$GITHUB_OUTPUT" @@ -199,13 +193,13 @@ jobs: contents: read steps: - name: Check out a fresh trigger workspace - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false ref: ${{ github.sha }} - name: Install uv - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true @@ -214,7 +208,7 @@ jobs: with: just-version: "1.58.0" - name: Download the immutable release source - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.materialize.outputs.source_artifact_name }} - name: Restore and verify the exact release source @@ -255,13 +249,13 @@ jobs: contents: read steps: - name: Check out a fresh isolated trigger workspace - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false ref: ${{ github.sha }} - name: Install uv - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true @@ -270,7 +264,7 @@ jobs: with: just-version: "1.58.0" - name: Download the immutable release source - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.materialize.outputs.source_artifact_name }} - name: Restore and verify the exact release source @@ -318,7 +312,7 @@ jobs: test "$(git rev-list -n 1 "$TAG")" = "$RELEASE_SHA" test -z "$(git status --porcelain --untracked-files=no)" - name: Upload isolated Hermes evidence only - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: hermes-evidence-${{ needs.materialize.outputs.release_sha }} path: hermes-source-sha.txt @@ -338,13 +332,13 @@ jobs: version: ${{ needs.materialize.outputs.version }} steps: - name: Check out a fresh build workspace - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false ref: ${{ github.sha }} - name: Install uv - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true @@ -353,11 +347,11 @@ jobs: with: just-version: "1.58.0" - name: Download the immutable release source - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.materialize.outputs.source_artifact_name }} - name: Download isolated Hermes evidence - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: hermes-evidence-${{ needs.materialize.outputs.release_sha }} - name: Restore and verify the exact release source @@ -417,7 +411,7 @@ jobs: sha256sum release-source.bundle release-manifest.json dist/* \ > release-payload.sha256 - name: Upload the tested release payload - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: ${{ needs.materialize.outputs.artifact_name }} path: | @@ -443,29 +437,23 @@ jobs: version: ${{ needs.materialize.outputs.version }} steps: - name: Check out the guarded parent revision without credentials - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false ref: ${{ github.sha }} - - name: Mint the dedicated source-promotion token - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 - with: - client-id: ${{ vars.SOURCE_PROMOTION_APP_CLIENT_ID }} - private-key: ${{ secrets.SOURCE_PROMOTION_APP_PRIVATE_KEY }} - permission-contents: write - name: Download the tested release payload - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.materialize.outputs.artifact_name }} - name: Validate and atomically push only the tested source env: - GH_TOKEN: ${{ steps.app-token.outputs.token }} + GH_TOKEN: ${{ secrets.SOURCE_PROMOTION_TOKEN }} RELEASE_SHA: ${{ needs.materialize.outputs.release_sha }} TAG: ${{ needs.materialize.outputs.tag }} TRIGGER_SHA: ${{ github.sha }} run: | + : "${GH_TOKEN:?SOURCE_PROMOTION_TOKEN must be configured in source-promotion}" sha256sum --check release-payload.sha256 git bundle verify release-source.bundle git fetch release-source.bundle \ @@ -513,7 +501,7 @@ jobs: id-token: write steps: - name: Download the tested release payload - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.promote-source.outputs.artifact_name }} - name: Recheck the immutable payload before publication @@ -534,13 +522,13 @@ jobs: receipt_artifact_name: ${{ steps.receipt.outputs.artifact_name }} steps: - name: Check out the published source identity - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false ref: ${{ needs.promote-source.outputs.release_sha }} - name: Download the published release payload - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.promote-source.outputs.artifact_name }} - name: Verify PyPI bytes and finalize the discoverable receipt @@ -560,7 +548,7 @@ jobs: --receipt release-receipt.json echo "artifact_name=release-receipt-$RELEASE_SHA" >> "$GITHUB_OUTPUT" - name: Upload the finalized discoverable receipt - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: ${{ steps.receipt.outputs.artifact_name }} path: release-receipt.json @@ -574,11 +562,11 @@ jobs: contents: write steps: - name: Download the published release payload - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.promote-source.outputs.artifact_name }} - name: Download the finalized discoverable receipt - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ needs.verify-pypi.outputs.receipt_artifact_name }} path: final-receipt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3cb189b..44eccbd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,8 @@ jobs: unittest: runs-on: ubuntu-latest steps: - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true @@ -27,8 +27,8 @@ jobs: package: runs-on: ubuntu-latest steps: - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true @@ -56,13 +56,13 @@ jobs: env: DEPLOYED_HERMES_REVISION: f80f453ae0679347e38abc917c7f94f717bf96c5 steps: - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: NousResearch/hermes-agent ref: f80f453ae0679347e38abc917c7f94f717bf96c5 path: .hermes-agent-deployed - - uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 + - uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0 with: python-version: "3.11" enable-cache: true diff --git a/AGENTS.md b/AGENTS.md index 4818dcc..58afef6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -82,3 +82,13 @@ tests together so consuming Hermes plugins have a reliable migration path. Keep `skills/hermes-plugins/references/plugin-kit.md` aligned with public API and contract changes so the repo-owned authoring skill does not teach stale behavior. + +Release authentication uses `SOURCE_PROMOTION_TOKEN` from the main-only +`source-promotion` environment. A suitable PAT or existing GitHub credential +is valid; a particular token-minting mechanism is not a release invariant. +Keep the Administration-read immutability check, tested-source identity, +atomic guarded push, PyPI OIDC and published-byte verification intact. +Never expose the promotion credential to source-testing/build jobs, silently +fall back to the default Actions token, or change branch-policy bypasses as +part of credential wiring. An environment restriction narrows availability, +not the underlying token's permissions. diff --git a/README.md b/README.md index e80bfff..f25ba5b 100644 --- a/README.md +++ b/README.md @@ -848,7 +848,7 @@ fails closed. Major releases are published but their receipt is always The workflow first creates the version/CHANGELOG commit and tag locally, then bundles that exact final source before executing tests. Fresh, separate jobs -restore the bundle for unit/public tests, the mutable upstream-Hermes contract, +restore the bundle for unit/public tests, the pinned Hermes contract, and the one artifact build. The build job is gated on both test jobs and never checks out or executes Hermes code. Every lane verifies the release SHA, tag, parent, and clean tracked source before continuing. @@ -877,27 +877,34 @@ prerequisites have been reviewed: release intent is materialized but before source promotion, and verifies `isImmutable` after publication. Non-releasing commits never enter a protected environment; -- a protected environment named exactly `source-promotion` contains variable - `SOURCE_PROMOTION_APP_CLIENT_ID` and secret - `SOURCE_PROMOTION_APP_PRIVATE_KEY` for a dedicated GitHub App installed only - on this repository. The App has repository Administration read and Contents - write permissions; no PAT is used; -- the `main` ruleset requires the ordinary test workflow and names that - dedicated GitHub App as its sole source-promotion bypass actor. Generic - Actions credentials and the default `GITHUB_TOKEN` must not bypass it; -- the existing `0.7.0` source baseline has a reviewed immutable `v0.7.0` tag. - -This change does not create or mutate any of those external controls. At review -time immutable releases were disabled, the required environments/ruleset/App -were not configured, and the PyPI project did not yet exist; a pending Trusted -Publisher supports that first OIDC publication. Keep -`SEMANTIC_RELEASE_ENABLED` unset until the full checklist is configured and a -generic-token rejection plus dedicated-App promotion have been exercised in an -isolated validation. A missing switch, control, baseline tag, test, build, -metadata check, source identity, or artifact hash stops before publication. The -final release receipt is the discoverable boundary for downstream -qualification; polling and recovery from a missed notification belong to that -downstream system. +- an environment named exactly `source-promotion`, restricted to the `main` + branch, contains secret `SOURCE_PROMOTION_TOKEN`. Use an approved PAT or + existing GitHub credential with repository Administration read and Contents + write access. The two guarded steps pass it as `GH_TOKEN`; they fail before + any operation if it is absent. No App client ID or private key is required; +- the source-promotion identity is authorized under the repository's branch + and tag policies. A PAT does not inherently bypass those policies, and this + workflow must not remove protections or grant a generic Actions bypass; +- the source baseline has its reviewed, matching immutable version tag. + +Prefer a repository-limited fine-grained PAT. Reusing an operator credential +retains that credential's existing scopes; the environment restriction limits +where it is available, not what it can access. Keep it confined to the two +guarded jobs, never the source-testing/build jobs. Provision it through the +secure secret-management path, not plaintext files, command-line arguments, or +workflow logs. Branch rulesets are managed separately; this credential change +does not create a bypass. + +`GH_TOKEN` is a CLI environment variable, not a token type. The default Actions +`GITHUB_TOKEN` still handles the final GitHub Release, but is not a fallback +for this Administration-read/source-promotion credential. PyPI publication +continues to use OIDC, not the GitHub token. + +A missing switch, credential, control, baseline tag, test, build, metadata +check, source identity, or artifact hash stops before publication. The final +release receipt is the discoverable boundary for downstream qualification; +source/build success alone is insufficient. Polling and recovery from a +missed notification belong to that downstream system. ## License diff --git a/tests/test_release_contract.py b/tests/test_release_contract.py index 42751ba..b47aa33 100644 --- a/tests/test_release_contract.py +++ b/tests/test_release_contract.py @@ -2,6 +2,7 @@ import hashlib import json +import os import subprocess import tarfile import tempfile @@ -547,38 +548,63 @@ def test_publishing_job_has_only_oidc_write_permission(self) -> None: self.assertEqual(publish["environment"]["name"], "pypi") self.assertEqual(publish["needs"], "promote-source") - def test_invalid_history_is_strict_and_activation_is_fail_closed(self) -> None: - self.assertIn( - "semantic-release --strict version --no-push --no-vcs-release", - self.workflow, - ) - self.assertIn("SEMANTIC_RELEASE_ENABLED", self.workflow) - immutable_control = yaml.safe_dump( - self.release_config["jobs"]["immutable-release-control"] - ) - self.assertIn("immutable-releases", immutable_control) - self.assertIn("permission-administration: read", immutable_control) - self.assertIn("isImmutable", self.workflow) - self.assertIn("validate-history", self.workflow) - self.assertIn('"$version" = "$previous_version"', self.workflow) - self.assertIn("Reject an already-published PyPI version", self.workflow) - self.assertIn("404) ;;", self.workflow) - self.assertIn("--connect-timeout", self.workflow) - self.assertIn("--max-time", self.workflow) - - def test_source_promotion_uses_protected_github_app_identity(self) -> None: - promote = self.release_config["jobs"]["promote-source"] - promote_text = yaml.safe_dump(promote) - self.assertEqual(promote["environment"], "source-promotion") - self.assertIn( - "actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1", - promote_text, - ) - self.assertIn("SOURCE_PROMOTION_APP_CLIENT_ID", promote_text) - self.assertIn("SOURCE_PROMOTION_APP_PRIVATE_KEY", promote_text) - self.assertNotIn("github.token", promote_text) - self.assertIn("persist-credentials: 'false'", promote_text) - self.assertNotIn("personal_access_token", promote_text.lower()) + def test_immutable_control_requires_credentials_and_positive_api_evidence(self) -> None: + step = next( + step + for step in self.release_config["jobs"]["immutable-release-control"]["steps"] + if step.get("id") == "verify" + ) + for token, enabled, api_status, admitted in ( + ("", "true", "0", False), + ("test-credential", "false", "0", False), + ("test-credential", "true", "17", False), + ("test-credential", "true", "0", True), + ): + with self.subTest(token_present=bool(token), enabled=enabled, api_status=api_status): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + output = root / "output" + probe = root / "api-called" + result = subprocess.run( + [ + "bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c", + 'gh() { printf called > "$PROBE"; ' + 'printf "%s\\n" "$CONTROL_VALUE"; return "$CONTROL_STATUS"; }\n' + + step["run"], + ], + env={ + "PATH": os.defpath, + "GH_TOKEN": token, + "GITHUB_REPOSITORY": "example/kit", + "GITHUB_OUTPUT": str(output), + "PROBE": str(probe), + "CONTROL_VALUE": enabled, + "CONTROL_STATUS": api_status, + }, + capture_output=True, text=True, check=False, + ) + self.assertEqual(result.returncode == 0, admitted) + self.assertEqual(probe.exists(), bool(token)) + self.assertEqual( + output.read_text() if output.exists() else "", + "enabled=true\n" if admitted else "", + ) + + def test_missing_promotion_credential_stops_before_payload_or_git_operations(self) -> None: + step = self.release_config["jobs"]["promote-source"]["steps"][-1] + with tempfile.TemporaryDirectory() as directory: + probe = Path(directory) / "payload-reached" + result = subprocess.run( + [ + "bash", "--noprofile", "--norc", "-e", "-o", "pipefail", "-c", + 'sha256sum() { printf reached > "$PROBE"; return 1; }\n' + step["run"], + ], + cwd=directory, + env={"PATH": os.defpath, "GH_TOKEN": "", "PROBE": str(probe)}, + capture_output=True, text=True, check=False, + ) + self.assertNotEqual(result.returncode, 0) + self.assertFalse(probe.exists()) def test_no_release_intent_never_enters_a_protected_environment(self) -> None: jobs = self.release_config["jobs"]