diff --git a/.github/workflows/arxiv_interests.yml b/.github/workflows/arxiv_interests.yml index 3b234ab42..c588ebc23 100644 --- a/.github/workflows/arxiv_interests.yml +++ b/.github/workflows/arxiv_interests.yml @@ -70,6 +70,9 @@ jobs: arxiv-interests: if: ${{ inputs.dry_run != true }} runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: # claude-code-action runs `git config` in the workspace at startup and # dies without a checkout — load-bearing even though the fetch is all API. @@ -338,6 +341,9 @@ jobs: memory-push-probe: if: ${{ inputs.dry_run == true }} runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - name: Mint App token (PyAutoMemory, contents write) id: app_token diff --git a/.github/workflows/arxiv_papers.yml b/.github/workflows/arxiv_papers.yml index 5ebf2c648..56be686a5 100644 --- a/.github/workflows/arxiv_papers.yml +++ b/.github/workflows/arxiv_papers.yml @@ -70,6 +70,9 @@ jobs: arxiv-papers: if: ${{ inputs.dry_run != true }} runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: # claude-code-action runs `git config` in the workspace at startup and # dies with "fatal: not in a git directory" if nothing is checked out — @@ -629,6 +632,9 @@ jobs: memory-push-probe: if: ${{ inputs.dry_run == true }} runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - name: Mint App token (PyAutoMemory, contents write) id: app_token diff --git a/.github/workflows/looks_shipped.yml b/.github/workflows/looks_shipped.yml index e686cc2b7..313b8432c 100644 --- a/.github/workflows/looks_shipped.yml +++ b/.github/workflows/looks_shipped.yml @@ -35,6 +35,9 @@ permissions: jobs: looks-shipped: runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/morning_status.yml b/.github/workflows/morning_status.yml index 7ec24d249..c58bc3ff9 100644 --- a/.github/workflows/morning_status.yml +++ b/.github/workflows/morning_status.yml @@ -23,6 +23,9 @@ permissions: jobs: pyauto-update-digest: runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main env: REPOS: >- PyAutoLabs/PyAutoNerves diff --git a/.github/workflows/registry_reconcile.yml b/.github/workflows/registry_reconcile.yml index 1a5ac1b98..c79fc5c61 100644 --- a/.github/workflows/registry_reconcile.yml +++ b/.github/workflows/registry_reconcile.yml @@ -26,6 +26,9 @@ permissions: jobs: reconcile: runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - uses: actions/checkout@v4 # Registry rows point at issues and PRs across the org, private repos diff --git a/.github/workflows/session_hook_propagate.yml b/.github/workflows/session_hook_propagate.yml index aa71a3e85..bb8cdb4b2 100644 --- a/.github/workflows/session_hook_propagate.yml +++ b/.github/workflows/session_hook_propagate.yml @@ -95,6 +95,9 @@ concurrency: jobs: propagate: runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - name: Check out PyAutoMind (the canonical hook and the body map) uses: actions/checkout@v4 diff --git a/.github/workflows/smoke_bootstrap_propagate.yml b/.github/workflows/smoke_bootstrap_propagate.yml index 4c8aa1ab6..77f283cb0 100644 --- a/.github/workflows/smoke_bootstrap_propagate.yml +++ b/.github/workflows/smoke_bootstrap_propagate.yml @@ -35,6 +35,9 @@ concurrency: jobs: propagate: runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/spawn_drift.yml b/.github/workflows/spawn_drift.yml index 27cb2c1aa..b519a1cda 100644 --- a/.github/workflows/spawn_drift.yml +++ b/.github/workflows/spawn_drift.yml @@ -76,6 +76,9 @@ jobs: # that did not cause it. if: github.event_name != 'pull_request' runs-on: ubuntu-latest + # Secrets live in the `mind-main` environment, deployable from main only, so a + # workflow dispatched at an old ref cannot read them (old_branch_workflow_secret_exposure). + environment: mind-main steps: - name: Checkout the live repos + published templates # All four are public: plain clones, no credential. diff --git a/policy/github_tokens.md b/policy/github_tokens.md index a451f1234..9011467fb 100644 --- a/policy/github_tokens.md +++ b/policy/github_tokens.md @@ -33,10 +33,10 @@ Commits made with it are authored as `pyautolabs-bot[bot]` / | Credential | Where | Consumers | Owner | Rotation | |---|---|---|---|---| -| `APP_PRIVATE_KEY` | org secret, visibility `all` | every App mint (table below) | org owner | App key rotation (below) | +| `APP_PRIVATE_KEY` | org secret (PyAutoMind excluded; Mind reads it from its `mind-main` environment) | every App mint (table below) | org owner | App key rotation (below) | | `APP_CLIENT_ID` | org variable, visibility `all` | every App mint | org owner | changes only if the App is recreated | | `PYPI`, `TEST_PYPI` | PyAutoHands repo secrets | Hands `release`, `publish_tombstone` (twine) | maintainer | regenerate on PyPI; trusted publishing (commented OIDC steps in Hands `release.yml`) would retire them, not scheduled | -| `CLAUDE_CODE_OAUTH_TOKEN` | PyAutoMind, PyAutoMemory repo secrets | Mind `arxiv_papers`, `arxiv_interests`, `morning_status`; Memory `queue_filing` | maintainer | `claude setup-token`, update both repos | +| `CLAUDE_CODE_OAUTH_TOKEN` | PyAutoMind `mind-main` environment (main only), PyAutoMemory repo secret | Mind `arxiv_papers`, `arxiv_interests`, `morning_status`; Memory `queue_filing` | maintainer | `claude setup-token`, update both repos | | `PYAUTO_PAPERS_WEBHOOK_URL` | PyAutoMind repo secret | Mind `arxiv_papers` | maintainer | webhook rotation (below) | | dashboard input PAT | the human's browsers (`localStorage`), not a secret | Mind `dashboard.html` → `dashboard-input` issue → `dashboard_input.yml` | maintainer | fine-grained, PyAutoMind Issues RW only, ≤ 90 days ([below](#the-dashboard-input-token-browser-pyautomind565)) | | `PYAUTO_UPDATE_WEBHOOK_URL` | PyAutoMind repo secret | Mind `morning_health`, `morning_status` | maintainer | webhook rotation | @@ -217,6 +217,29 @@ a `run:` or `github-script` block, and runs each validating step with hostile values. A new string input follows the same pattern (`env:`, then validate) and gets a row here. +**Old refs.** "Safe on `main`" is not safe everywhere. A dispatch runs the +workflow file *at the chosen ref*, and Mind keeps about 244 old heads from before +the hardening, whose copies still paste inputs into `run:`. So the secrets those +jobs read live in the **`mind-main` environment**, deployable from `main` only. +Every job that reads `CLAUDE_CODE_OAUTH_TOKEN` or `APP_PRIVATE_KEY` declares +`environment: mind-main` (2026-11-16). That closes the hole only once the +secrets are **environment-only**: +- `CLAUDE_CODE_OAUTH_TOKEN` is set in `mind-main` and deleted as a repo secret; +- PyAutoMind is removed from the org secret `APP_PRIVATE_KEY`'s repository list, + and the key is set in `mind-main`. + +Until then, old refs stay exposed. **The move alone is not enough while Mind +`main` is unprotected.** A pre-hardening `mind_ledger_merge.yml` on an old head +has `contents: write` and an injectable `inputs.branch`, so a dispatch at that +ref can push to `main`, for example a changed `scripts/lifecycle.py` that a +`mind-main` job then runs with the secrets. Close that as well: prune the old +heads that predate the hardening (`5a5d9dd80`), or protect `main`. Protecting +`main` would mean moving `mind_ledger_merge` and the sessions' direct ledger +pushes to a bypass actor first. The webhook secrets (`PYAUTO_*_WEBHOOK_URL`, +org `SLACK_WEBHOOK_URL`) can only post to Slack and stay outside the +environment for now. `tests/test_workflow_environment.py` fails on a job that reads +either secret without the environment. + **Rotation:** make a new token, paste it on each device (🔑 on the page), revoke the old one. If a device is lost: revoke first. diff --git a/tests/test_workflow_environment.py b/tests/test_workflow_environment.py new file mode 100644 index 000000000..e5d5196dc --- /dev/null +++ b/tests/test_workflow_environment.py @@ -0,0 +1,54 @@ +"""Every Mind job that reads the Claude or App secret declares `mind-main`. + +A dispatch runs the workflow file at the ref the caller picks, and old Mind +heads still carry pre-hardening copies (old_branch_workflow_secret_exposure). +The secrets live in the `mind-main` environment, deployable from `main` only, +so a job that reads them must declare it; otherwise it would fail on `main` once +the repo-level copies are gone, or the copies would have to stay where old refs +reach them (policy/github_tokens.md, "Old refs"). +""" + +import re +from pathlib import Path + +import pytest +import yaml + +WORKFLOWS = Path(__file__).resolve().parents[1] / ".github" / "workflows" +FILES = sorted(WORKFLOWS.glob("*.yml")) if WORKFLOWS.is_dir() else [] +_NAMES = r"(CLAUDE_CODE_OAUTH_TOKEN|APP_PRIVATE_KEY)" +#: Any way an expression can reach a guarded secret: dotted or indexed (names +#: are case-insensitive), the whole context serialised, or inherited wholesale. +GUARDED = re.compile( + rf"secrets\s*\.\s*{_NAMES}\b|secrets\s*\[\s*['\"]{_NAMES}['\"]\s*\]" + r"|toJSON\(\s*secrets\s*\)|secrets:\s*inherit", re.I) + + +def _env_name(job): + env = job.get("environment") + return env.get("name") if isinstance(env, dict) else env + + +@pytest.mark.skipif(not FILES, reason="no workflows shipped here") +def test_every_job_reading_a_guarded_secret_declares_mind_main(): + missing = [] + for path in FILES: + wf = yaml.safe_load(path.read_text()) + if GUARDED.search(yaml.safe_dump(wf.get("env") or {})): + missing.append(f"{path.name}: workflow-level env") + for name, job in (wf.get("jobs") or {}).items(): + if GUARDED.search(yaml.safe_dump(job)) and _env_name(job) != "mind-main": + missing.append(f"{path.name}:{name}") + assert not missing, f"guarded secret read outside `environment: mind-main`: {missing}" + + +@pytest.mark.parametrize("expr", [ + "${{ secrets.APP_PRIVATE_KEY }}", "${{ secrets.app_private_key }}", + "${{ secrets['CLAUDE_CODE_OAUTH_TOKEN'] }}", "${{ toJSON(secrets) }}", + "secrets: inherit"]) +def test_the_scan_sees_every_spelling(expr): + assert GUARDED.search(expr) + + +def test_the_scan_ignores_other_secrets(): + assert not GUARDED.search("${{ secrets.PYAUTO_UPDATE_WEBHOOK_URL }}")