Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/arxiv_interests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/arxiv_papers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 —
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/looks_shipped.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/morning_status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/registry_reconcile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/session_hook_propagate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/smoke_bootstrap_propagate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/spawn_drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 25 additions & 2 deletions policy/github_tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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.

Expand Down
54 changes: 54 additions & 0 deletions tests/test_workflow_environment.py
Original file line number Diff line number Diff line change
@@ -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 }}")
Loading