Skip to content
Source
Sign inSign up
TanStack/source

Help people move a .env out of a push instead of only refusing it #133

Opentombeckenham opened this issue 0 comments
tombeckenhamcommented

Problem

Push protection refuses a push that adds a .env file (packages/git/src/protocol/policy.ts). That is right, but the refusal only says "keep secrets out of git", and the person must work out the fix themselves.

We'd like Source to handle a .env for people. It can't do that on the server: by the time a push arrives, git has sealed the file into the commit.

  • Stripping it on the server changes the commit id. The local branch and the forge then disagree, every later push is a non-fast-forward, and the local history still holds the file.
  • Keeping it publishes it. Any reader can fetch an object by its id, and the file goes to forks, to GitHub on synced repositories, and into every CI checkout, where no secret value may go.
  • A .env doesn't say enough to become CI secrets. It names no environment, no hosts and no header.
  • A src push that bypasses git has the same divergence problem. It also misses plain git push, which is what agents and most people run.

Proposal

Handle it on the developer's machine, before the commits leave it. Commits that were never pushed can be rewritten safely.

  1. Refusal text. Make the push protection message give the exact steps:

    push protection: .env looks like an environment file; keep secrets out of git.
      Undo the commit:  git rm --cached .env && echo .env >> .gitignore && git commit --amend
      Share the file:   src vault put .env
      Use it in CI:     src secret set -f .env --env development --host <host>

    Small, and it helps people on plain git too.

  2. src push. Wrap git push:

    1. Find the .env files that the outgoing commits (@{u}..HEAD) add.
    2. Offer to move them to the vault or to CI secrets, asking for the environment and the hosts.
    3. Remove the files from those local commits, keep them on disk, and add them to .gitignore.
    4. Run git push.

    The rewrite needs the developer's yes every time, by a prompt or a flag, never silently.

  3. Opt-in pre-push hook. The same check as a hook, installed per repository (from src agent setup or a new src hooks install), so plain git push from people and agents gets it too. Never set the global core.hooksPath: it would override the developer's own hooks.

Open questions

  • Is step 1 enough on its own, or is the rewrite worth its risk?
  • Should src push also catch the known secret formats that push protection scans for (SECRET_PATTERNS), not just .env paths?
  • Hook install: part of src agent setup, or a separate command?

Sign in to join this conversation.