Skip to content

Provision a Repository's Secrets From the Host's Secrets Directory #3932

Closed

Description

@ptr727

Provisioning a repository should also set its GitHub secrets. It reads each value from the host's ~/.secrets/, writes every one it finds to the store that needs it, and reports every one it does not find so the maintainer can add it by hand. Today, provisioning sets every repository setting except secrets, and the values are pasted into the GitHub UI one repository at a time.

What Exists Today

  • The names are already resolved per repository. spec/secrets.json gives the fleet baseline (CODEGEN_APP_CLIENT_ID, CODEGEN_APP_PRIVATE_KEY) and the mechanisms a repository's publish targets and types map to. For example, docker-hub maps to DOCKER_HUB_USERNAME and DOCKER_HUB_ACCESS_TOKEN. Each mechanism also names its stores (actions, dependabot). A registry entry's requiredSecrets adds the names specific to that repository. spec/audit.py already checks the names against this, reporting missing, stale and forbidden ones.
  • repo-config/configure.sh deliberately writes no secret. Its header says an environment's secrets "exist nowhere in this repository", and its check run ends with a manual-verify note about secret values. This issue reverses that choice, so the comment and the README's "Secrets" section change with it.
  • The hardened readers exist. lib/sh/secrets.sh has require_secret (it refuses a missing file, a dangling link, or one that group or other can read) and read_env_value (it reads a single value from an env file, never sourcing it). GOVERNANCE.md "Repo-Scoped Secrets" requires every shell read of a credential to go through these.
  • The ~/.secrets/ convention is HomeAutomation-Config's OPERATIONS.md "Host Secrets". The directory is 700. A credential only a host script reads is 600. A single opaque credential is a file with no extension, read rather than sourced. A missing file is a hard failure, never a fallback to an ambient value. File names are lowercase fields joined by _, per CODESTYLE.md "Script and Utility File Names".

Proposal

  1. Derive the names from spec/secrets.json and the registry, never from a second list. The names each repository needs are the same set the audit resolves, so provisioning and the audit cannot drift. A secret that is common to the fleet is not the same as one every repository requires. DOCKER_HUB_USERNAME has one value fleet-wide, but only a repository with a docker target needs it. Setting it anywhere else is a stale-secret finding today.
  2. One file per credential in ~/.secrets/, read with require_secret. A multi-line value such as the App private key cannot live in an env file anyway. The names below are a starting point (see the open questions):
    • A common value: github_<secret>, for example github_codegen_app_private_key or github_docker_hub_username.
    • A value specific to one repository: github_<repo>_<secret>, the repository name lowercased with its hyphens kept, for example github_plexcleaner_docker_hub_access_token.
    • A specific file wins over a common one, so one repository can override a fleet value.
  3. Write to each store the mechanism names. That is the Actions store, the Dependabot store (gh secret set --app dependabot), and, where the registry declares a GitHub Environment, that environment (--env). Environments have no vocabulary for their secret names yet, which Declare Per-Environment Secrets and Variables Once and Check Them From the Hub #2070 is about, so environment scope depends on Declare Per-Environment Secrets and Variables Once and Check Them From the Hub #2070 or arrives with it.
  4. Pass every value on stdin, never as an argument. For example, gh secret set NAME --repo OWNER/REPO < file. A value in argv is visible in the process list and in anything that logs the invocation. No value is ever echoed, logged, or written to a report.
  5. Report what is missing as a list, after the writes. Each entry is the secret name, the store, and the file path it was looked for under, so the maintainer can create the file and re-run. A missing secret does not stop the run setting the others. It does make the run exit non-zero, so the run never reads as fully provisioned. A file that is present but unsafe (too permissive, empty, or a dangling link) is reported as a refusal, separately from a missing one.
  6. --dry-run lists, per store, each name it would set, its source (common or repository), and each name missing. It never prints a value.
  7. The hub declares the host-secrets type if it becomes a repository whose shell scripts read a credential from disk, as GOVERNANCE.md requires.

Open Questions

Each has a recommendation, to be confirmed before implementation.

  • File naming in ~/.secrets/. The recommendation is the github_ prefix scheme above, which keeps the flat directory the homelab convention uses. The alternative is a subdirectory per repository, which that convention does not use.
  • Overwrite policy. The API never returns a secret's value, so provisioning cannot tell a stale value from a current one. The recommendation is to set every name whose file is present on every run. A single source of truth makes rotation a file edit and one re-run. The alternative is to set only names missing on GitHub and add a --rotate flag to overwrite, which keeps a re-run from touching live values.
  • Where it runs. The recommendation is a secrets group inside configure.sh apply, so provisioning stays one command, plus a configure.sh check line naming any required secret absent from GitHub. The alternative is a separate scripts/ entry point.
  • Secrets on GitHub that nothing claims. The recommendation is to report them, which the audit already does, and never delete them. A deletion is irreversible and stays the maintainer's call.

Done When

  • A test, run against a synthetic secrets directory and a stubbed gh, covers each case: a common value, a repository-specific override, every store, a missing file, and an unsafe file. It also asserts that no value reaches argv, stdout, or stderr.
  • repo-config/README.md "Secrets" lists the file name expected for each common secret and the rule that names a repository-specific one.
  • One live provisioning run sets a test repository's secrets, and spec/audit.py reports that repository's secret names clean afterwards.

🤖 Generated with Claude Code

Activity

  1. added
    enhancement
    script
    on Nov 8, 2026
  2. ptr727 commented on Nov 8, 2026

    @ptr727
    OwnerAuthor

    Decided by the maintainer, 2026-11-08, settling three of the four open questions:

    • File naming: the flat github_ prefix scheme. Common values are github_<secret>, and values specific to one repository are github_<repo>_<secret>.
    • Overwrite policy: every secret whose file is present is set on every run, so ~/.secrets/ is the single source of truth.
    • Entry point: a secrets group inside configure.sh apply, plus a configure.sh check line naming each required secret absent from GitHub.

    Still open: secrets on GitHub that nothing claims. The recommendation stays to report them and never delete them.

  3. ptr727 commented on Nov 8, 2026

    @ptr727
    OwnerAuthor

    Decided by the maintainer, 2026-11-08, settling the last open question:

    • Secrets on GitHub that nothing claims: report them and never delete them. The registry may not know every consumer of a secret, so one that looks unclaimed may still be in use.

    All four open questions are now settled, so #3932 is ready to implement.

  4. added a commit that references this issue on Nov 8, 2026
    209e63d
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

    enhancementscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions