Skip to content

Declare Per-Environment Secrets and Variables Once and Check Them From the Hub #2070

Open

Description

@ptr727

Blog now checks its GitHub Environment secrets and variables against a declared list (ptr727/Blog#285). The hub already checks the repository-scope half of the same problem, and documents the environment-scope half without checking it. This proposes one declarative source for both, checked by the hub-hosted audit, so no repository keeps its own checker or its own prose list.

The gap in the hub today

  • spec/audit.py checks repository-scope secret names, in the Actions and Dependabot stores. It checks them against spec/secrets.json: the fleet baseline, the mechanisms a repository's publish targets and types map to, and the registry entry's requiredSecrets. It reports missing, stale, and forbidden names.
  • repo-config/configure.sh check checks that each environment in the registry exists and carries its branch policy. It also reports an environment the registry does not declare. It leaves secret names to spec/audit.py and reads no environment secrets or variables. Its own comment notes that the API can list those names. Leaving them unchecked is a choice about ownership, not an API limit.
  • Environment-scope names are checked by nothing. spec/secrets.json says so itself. The deploy-ssh mechanism's note says per-environment names have no vocabulary there and that neither validate.py nor audit.py queries an environment store. The file's top-level note says an environments listing, where one exists, is operator documentation that no tool reads. So a clean audit is no evidence that a deploy environment is configured.
  • A repository therefore keeps its own prose list. Blog's AUDIT.md "Environment scope" section names each environment's secrets and variables by hand, with gh commands for a human to run. That list drifted within a day: Blog added a family-site variable and token pair to its environments, and the section does not mention them. Hand-kept lists drift, and nothing notices.

What Blog built

checks/check-github-env.py, with tests in checks/tests/test_check_github_env.py. Blog's ENVIRONMENT.md table "The GitHub Environments" is the declaration. Each row names a value, its kind (variable or secret), and a "Held on" cell listing its stores:

| Value | Kind | Held on | Names |
| --- | --- | --- | --- |
| `SITE_BASE_URL` | variable | `staging`, `production` | the base URL ... |
| `SITE_AUTH_TOKEN` | secret | `staging` | the access token ... |
| `CODEGEN_APP_CLIENT_ID` | secret | `repository`, `dependabot` | the merge bot's App client id ... |

A store is a deployment environment's name, repository for the Actions repository store, or dependabot for the Dependabot secret store. The checker works like this:

  1. Parse the table strictly. Every row either parses or is refused. An earlier version skipped a row it could not match, so a capitalized kind or a missing backtick silently dropped a declared value.

  2. Read the names GitHub holds, through gh api --paginate --hostname github.com repos/<owner>/<repo>/... with --jq '.<key>[].name':

    • actions/secrets
    • actions/variables
    • dependabot/secrets
    • environments, then environments/<name>/secrets and environments/<name>/variables for each one

    Only names leave gh, so a variable's value never reaches the output.

  3. Compare both ways, as (store, kind, name) triples:

    • missing: declared but not held.
    • unlisted: held but not declared.
    • wrong kind: held as a variable where the declaration says secret, or the reverse.

    Every environment GitHub has is read, not just the declared ones. An environment the declaration never names must therefore hold nothing, and a stray value there is reported. The same rule catches a credential leaking into an environment that must not have it, such as an access token on a public production site. That is the "absent from production" assertion Blog's AUDIT.md spells out by hand.

  4. Exit 0 on agreement, 1 on a finding or a malformed declaration, and 2 when GitHub could not be read. A failed query therefore never reads as a pass.

What it had to get right

Each of these was a real defect caught in review, and each applies to any hub version:

  • Pin the target repository and host. gh api repos/{owner}/{repo}/... resolves the placeholder from GH_REPO before the checkout's remote, and GH_HOST moves the host. Either one silently points the check at another repository. Blog's checker resolves owner and repo from origin, against a pattern anchored on the whole URL, and passes --hostname github.com. The hub audit already names its target repository, so the host pin is the part that transfers.
  • Refuse an environment named like a store label. An environment called repository or dependabot would merge its values into that store's findings.
  • Names only, including for variables. The environment variables endpoint returns values. A --jq projection to .name keeps them out of logs, which is the same reason Blog's AUDIT.md insists on --json name.
  • Listing environment secrets needs an admin login. A workflow's GITHUB_TOKEN cannot, so CI cannot run this. That fits spec/audit.py, which is already owner-run.

Proposal

  1. Declare environment-scope names in the hub, next to what already describes the environment. Each registry environments entry already carries name, branchPolicy, and branches, and it could also carry secrets and variables name lists. The same move could give repository-scope variables a declaration, since the registry has requiredSecrets and nothing for variables. Keeping the declaration hub-side follows the audit's own principle that a repository's claim about itself is not evidence.
  2. Extend spec/audit.py to read the environment stores, names only, and report missing, unlisted, and wrong-kind values per environment. The rule that an undeclared environment must be empty comes along with it. The deploy-ssh note and the environments note in spec/secrets.json then become true statements about a checked declaration.
  3. Retire the per-repository copies. Blog's AUDIT.md "Environment scope" section shrinks to a pointer at the audit run, and Blog's checker is deleted once the audit covers the same ground. A repository's own documentation still describes what each value means, which is repository knowledge. The hub declaration holds names, kinds, and stores.

Open question

Where the declaration lives. In the registry, the audit reads its own ground truth and a repository cannot vouch for itself, which is why I would start there. The cost is that adding one environment variable becomes a hub pull request as well as a repository change. The alternative is a small declarative file the repository carries, such as JSON beside its workflows, which the hub-hosted checker reads. That keeps one change in one repository, but it makes the repository its own ground truth. A third option is both: the hub declares which environments and stores exist, and the repository declares the names inside them.

Related

Blog's checker stays in place until this lands, and it is the reference implementation to port from.

Activity

  1. ptr727 commented on Nov 1, 2026

    @ptr727
    OwnerAuthor

    Decision needed (decision triage, 2026-11-01)

    Question: Where should a repository's per-environment secret and variable names be declared so the owner-run spec/audit.py can check them: the hub's registry/repos.json environments[] entries, a file the repository carries, or a split between the two?

    Options, recommended first:

    1. Add secrets/variables name lists to registry entries (recommended): Each registry environment entry already holds the environment's name and branch policy (repos.schema.json:118-139), repo-scope requiredSecrets already lives there and is read by audit.py:1864-1865, and the fleet's rule is that a repository's claim about itself is not evidence. Cost: a new environment value needs a hub PR, rare with one deploy adopter. Unblocks Hand a Variable Set of Environment Values to a Hub Task's Hook Instead of Named Pairs #2174 option 6 and Say Where the Deploy-Site Task Actually Requires the SSH Key #1801 option 2. No work in flight.
    2. Split: hub declares envs and stores, repo declares names: A new name is a one-repo change, but the names are exactly what drifted in Blog, and they become self-attested. No work in flight.
    3. Repo-carried declaration file read by the hub checker: Simplest change flow, but makes the repository its own ground truth, which the audit design rejects, and adds a carried file to spec/files.json and every resync. No work in flight.

    Evidence: spec/secrets.json:47 (deploy-ssh note): no tool queries an environment store. spec/secrets.schema.json:48-62 defines an unread fleet-wide environments object, which the chosen option should retire or absorb. Blog's driftNotes (registry/repos.json:329) leave deploy credentials out of requiredSecrets because the audit would demand them in the Actions store. configure.sh:37 is check-only for environments.

    Blocks: #2174 (its option 6), #1801 (its option 2)

  2. added
    decision
    on Nov 1, 2026
  3. ptr727 commented on Nov 1, 2026

    @ptr727
    OwnerAuthor

    Maintainer answer (decision triage, 2026-11-01): Option 1: add secrets and variables name lists to each registry/repos.json environments[] entry, read by spec/audit.py, and retire or absorb the unread environments object in spec/secrets.schema.json. This is now work for the next burndown round.

  4. removed
    decision
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions