Skip to content

feat: add site-private leak-check hook - #1950

Merged
gerchowl merged 29 commits into
devfrom
feature/1932-site-leak-check
Oct 29, 2026
Merged

gerchowl merged 29 commits into
devfrom
feature/1932-site-leak-check

Conversation

@gerchowl

@gerchowl gerchowl commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add the ADR §10 default-on site leak-check hook. A clone without private patterns exits silently; configured clones scan staged changes or selected working-tree files through gitleaks and publish only file, line and rule ID.

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task
  • refactor -- Code restructuring
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style

Modifiers

  • Breaking change (!)

Changes Made

  • Resolve DEVKIT_LEAK_PATTERNS before .site/leak-patterns.toml. Use merged S4's public vig_utils.site_config.validate_patterns and preserve its safe error messages with exit 2. The S4 ADR amendment defines the single pattern-file contract; a missing selected file is a silent no-check without fallback.

  • Materialize raw blobs from the index for added, copied, modified, renamed and type-changed paths. Use Git's NUL-delimited metadata only for path selection, with no external diff or textconv; stream raw blobs through one git cat-file --batch process, avoiding checkout filters and per-blob process creation. Staged, filename and all-files modes then share one gitleaks directory scanner.

  • Cover full index content at changed paths, including pure renames; skip deleted and untouched paths. Filename mode skips NUL-containing inputs to enforce the text-hook contract, while direct staged and all-files scans include those bytes.

  • Scan selected site bindings and repository ignore files as data. Isolate gitleaks 8.30.1's automatic source-ignore loading by scanning a root .gitleaksignore separately; the private config remains explicit.

  • Define the default-on text/symlink hook once in nix/hooks.nix and mirror both portable configs. Pin gitleaks in Nix-generated hooks, and publish only file, line and rule ID. Document scan boundaries, printed paths, linked worktrees and intentional exceptions.

  • Pass -- in every hook definition before filenames; reject help-looking CLI options and disable option abbreviation. Real installed-hook commits cover -h, --help, --he and --all-files filenames.

  • Own private snapshots in one cleanup routine on success, findings, errors and signals. Block SIGINT/SIGTERM/SIGHUP before deleting, restore the previous mask/handlers, and honour pending signals only after deletion with a conventional exit code and no traceback. Identify unreadable pattern files and report input read/materialization errors using only safe path metadata.

  • Scan symlink link text as regular snapshot content in staged, filename and all-files modes, without following targets. Select links through types: [] plus types_or: [text, symlink], clearing the hook runner's default file-only filter. Preserve raw link text, including repeated separators, and apply path rules to link names.

Changelog Entry

Added

  • Site leak-check hook (#1932)
    • Enable private gitleaks rules for staged and working-tree scans, with silent
      success when no site patterns exist and redacted finding diagnostics.
    • Prevent repository ignore/config bypasses, scan force-added site bindings,
      and reject present pattern files without usable rules.
    • Stream raw index snapshots, including type changes, through one Git batch
      reader despite Git attributes; share S4's safe pattern validation.
    • Block option-looking filename bypasses, clean private snapshots on termination,
      and report filesystem failures with paths and OS reasons without file contents.
    • Scan symlink link text without reading targets and finish snapshot cleanup
      despite repeated termination signals.

Testing

  • Targeted tests pass locally; the brief reserves full-suite execution for CI.
  • Manual testing performed (describe below)

Manual Testing Details

  • Round-six RED: pytest tests/test_site_leak_check.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1932-r6 -q inside the Nix environment with worktree PYTHONPATH first exited 1: 9 failed / 112 passed. Tests were committed before implementation.
  • GREEN inside nix develop: PYTHONPATH="$PWD/packages/vig-utils/src" uv run --with pytest-xdist pytest tests/test_site_leak_check.py tests/test_hardcoded_endpoints.py packages/vig-utils/tests/test_site_config.py -n 4 --basetemp=$HOME/.cache/devkit-pytest/1932-r6 -q exited 0: 379 passed.
  • Both regular-file ↔ symlink type changes are staged as Git status T and must flag the new raw index blob. A 256-file test verifies exact binary content and exactly one batch reader, preventing per-blob process regressions.
  • Cleanup tests pause deterministically after the scanner has exited and before deletion. They deliver SIGTERM followed 10 ms later by SIGHUP in staged and all-files modes, across clean, findings and scanner-error exits. Deletion must complete before a conventional signal exit; no private tree or traceback remains.
  • Cleanup mask mutation: querying the mask instead of blocking termination signals makes the strengthened test fail (exit 1). After restoring production code, all 6 cleanup cases passed (exit 0), explicitly asserting SIGINT/SIGTERM/SIGHUP are blocked inside deletion.
  • Earlier validator, symlink target-isolation, installed-hook option filename, attributes/textconv/smudge, redaction, ignore/config bypass, gitlink/stage/path guard, rename and NUL-boundary regressions remain covered.
  • Commits run inside nix develop with hooks enabled. Container and Nix evaluation suites are reserved for CI.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (tool README and migration guidance)
  • I have updated CHANGELOG.md in the Unreleased section
  • My changes generate no new warnings or errors
  • I have added tests that prove my feature works
  • New and existing targeted unit tests pass locally with my changes
  • Any dependent changes have been merged and published (S4 feat: add per-clone site configuration and initializer hook #1938)

Additional Notes

Rebased onto S3 (#1949) and S4 (#1938). Conflict resolution preserved both S3 and S6 changelog entries in CHANGELOG.md and assets/workspace/.devcontainer/CHANGELOG.md, and preserved all S3/S4/S6 amendments in docs/rfcs/ADR-site-agnostic-projects.md.

S6 consumes S4's public pattern validator; the S4 ADR amendment remains the single rule definition. Rule IDs and matching file paths must be safe for public logs. The snapshot scanner never follows symlink targets; independently selected regular files are scanned normally.

Refs: #1932

@gerchowl
gerchowl force-pushed the feature/1932-site-leak-check branch from 1500caf to 49dddd8 Compare October 29, 2026 01:11
@gerchowl

Copy link
Copy Markdown
Contributor Author

S4 final-round contract for S6: PR #1938 provides vig_utils.site_config.validate_patterns(path: Path) -> None. Missing files return None; invalid files raise ValueError naming file/key without values. It folds TOML keys case-insensitively and rejects case-variant duplicates, rejects top-level extend in any case, and requires at least one usable rule with nonempty string id and regex or path. Other semantics remain with gitleaks. The single normative rule is recorded as the 2026-10-29 S4 pattern-file clarification in ADR Amendments. .site/leak-patterns.toml is unchanged. S6 can import this public function after S4 merges.

gerchowl added a commit that referenced this pull request Oct 29, 2026
## Description

Add `check-site-config` and `site-init` for per-worktree site bindings.
Both commands resolve the git toplevel from any subdirectory and refuse
outside git. Initialization discovers trusted external tools or writes
an unbound template, validates staged files, then publishes them.


## Type of Change


- [x] `feat` -- New feature
- [x] `fix` -- Bug fix
- [ ] `docs` -- Documentation only
- [ ] `chore` -- Maintenance task (deps, config, etc.)
- [ ] `refactor` -- Code restructuring (no behavior change)
- [x] `test` -- Adding or updating tests
- [ ] `ci` -- CI/CD pipeline changes
- [ ] `build` -- Build system or dependency changes
- [ ] `revert` -- Reverts a previous commit
- [ ] `style` -- Code style (formatting, whitespace)

### Modifiers

- [ ] Breaking change (`!`) -- This change breaks backward compatibility

## Changes Made

- Add the managed `just site-init` recipe while preserving `help` as the
default; ignore `.site/` and `.aws/` in scaffolds.
- Validate schema v1, active-site lookup, credential restrictions and
bound location forms. Reject whitespace/control characters, unsafe file
URIs, invalid S3 bucket names and reserved site names; errors name
fields without exposing values.
- Anchor discovery, staging and lookup to the resolved git worktree
root, including linked worktrees. Exclude relative and in-tree PATH
directories and resolved executable targets.
- Detect `.site/` changes recursively and refuse symlinks/special files.
Clean staging and newly created empty directories after failure; enforce
`--force` before publishing.
- Expose `validate_patterns(path: Path) -> None` for S6. Its
self-contained pattern rule is recorded once in the ADR Amendments:
case-insensitive keys without ambiguous variants, at least one usable
id-plus-regex/path rule, no extend, missing files mean no check. Pattern
values are never checked as site credentials or exposed in errors.
- Record the ADR §8/§9 clarification: empty locations are valid unbound
bindings with notices; consumers must refuse unbound bindings with
actionable errors.


## Changelog Entry

### Added

- **Per-clone site bindings and initializer hook**
([#1930](#1930))
- Validate site configuration and initialize bindings from PATH or an
unbound template.
- Discover only external initializers, validate supported location
forms, and accept gitleaks pattern definitions separately from site
bindings.
- Anchor site operations to the git worktree, reject unsafe locations
and reserved names, inspect recursive writes, and share self-contained
pattern validation with the leak checker.


## Testing

- RED: final-round regression suite, 91 failed and 48 passed (exit 1);
tests committed before fixes. Additional userinfo field-name regression:
1 failed and 4 passed (exit 1), also committed before its fix.
- GREEN after rebase: `PYTHONPATH="$PWD/packages/vig-utils/src" uv run
--with pytest-xdist pytest packages/vig-utils/tests/test_site_config.py
-n 4 --basetemp="$HOME/.cache/devkit-pytest/1930"`: 139 passed (exit 0).
- Commit hooks run in `nix develop`: formatting, lint, security,
documentation and manifest checks passed. CI checks run on the pushed
head.

- [ ] Tests pass locally (`just test`)
- [ ] Manual testing performed (describe below)

### Manual Testing Details


## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation accordingly (edit
`docs/templates/`, then run `just docs`)
- [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and
pasted the entry above)
- [ ] My changes generate no new warnings or errors
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published

## Additional Notes

Initializers are trusted external programs, not sandboxed processes.
Recursive metadata checks detect changed entries but cannot prevent
arbitrary writes or an initializer restoring metadata. This limit is
documented in ADR §9. S6 coordination:
#1950 (comment).


Refs: #1930
@gerchowl
gerchowl force-pushed the feature/1932-site-leak-check branch from 49dddd8 to 5d60ccd Compare October 29, 2026 01:42
@gerchowl
gerchowl force-pushed the feature/1932-site-leak-check branch from 5d60ccd to d4c6a5d Compare October 29, 2026 02:26
gerchowl added a commit that referenced this pull request Oct 29, 2026
## Description

Rewrites `docs/MIGRATION.md`'s "Run CI on self-hosted runners" section
to document the shipped site-agnostic runner mechanism
(`CI_RUNNER_SMALL`/`LARGE`/`XLARGE` variables, the fork predicate, size
classes and the `DEVKIT_CI_LANE_SIZES` lane override, and the N/N+1/N+2
deprecation timeline) in place of the stale, pre-migration
`DEVKIT_CI_RUNNER`-comma-list description. Source of truth:
`docs/rfcs/ADR-site-agnostic-projects.md`, cross-checked against the
merged S1/S1b/S1d/S2/S3 code (`resolve-toolchain/action.yml`, `ci.yml`,
`devkit-upgrade.yml`, `init-workspace.sh`).

## Type of Change

- [x] `docs` -- Documentation only

### Modifiers

- [ ] Breaking change (`!`) -- This change breaks backward compatibility

## Changes Made

- Rewrote the variable-selection, fork-safety and deprecation-timeline
content of "Run CI on self-hosted runners", replacing the removed
comma-separated `DEVKIT_CI_RUNNER` mechanism and the site-specific
example label/`gh variable set` value (both replaced with `<label>`)
- Added `####` subsections: Size classes and the lane override, Fork
safety (including decision (f)'s remedy for forks of a private repo, and
the owner-confirmed wording that the fork predicate is
accident-prevention, not the security boundary), Deprecation timeline,
and Known symptoms (the "CI never starts on a private repo" §3 notice
limit, and the whitespace-only/malformed `CI_RUNNER_SMALL` symptom)
- Updated the `.vig-os` manifest key table: rewrote the now-deprecated
`DEVKIT_CI_RUNNER` row and added the missing `DEVKIT_CI_LANE_SIZES` row
- Fixed one stale cross-reference to the old mechanism in the adjacent
"Keep the dev-shell gcroot" section
- Left the already-correct "Seeded hook runner migration" subsection
(S3, #1949) untouched, including its anchor

## Changelog Entry

### Changed

- **Rewrite the self-hosted CI runner migration guide**
([#1933](#1933))
- `docs/MIGRATION.md`'s "Run CI on self-hosted runners" section now
documents the shipped `CI_RUNNER_SMALL`/`LARGE`/`XLARGE` variables, the
per-lane `DEVKIT_CI_LANE_SIZES` override, fork safety (including the
private-fork remedy) and the full N/N+1/N+2 deprecation timeline,
replacing the stale description of the removed `DEVKIT_CI_RUNNER`-only
mechanism
- Add "CI never starts on a private repo" and whitespace-only
`CI_RUNNER_SMALL` symptom entries, and scrub the site-specific example
label from the section and the manifest key table

## Testing

- [x] Tests pass locally (targeted subset, not full `just test` per the
shared-host rule)
- [x] Manual testing performed (describe below)

### Manual Testing Details

- `nix develop --command prek run pymarkdown --files docs/MIGRATION.md
CHANGELOG.md --show-diff-on-failure --color=always` → **Passed**, exit 0
(the repo's actual docs/markdown lint; `fix` mode made no further
changes)
- A one-off script (not committed) extracted every `MIGRATION.md#…`
anchor referenced anywhere in the repo outside
`docs/issues/`/`docs/pull-requests/` (`git grep -n 'MIGRATION.md#'`) and
compared it against the GitHub-slugified headings in the rewritten
`docs/MIGRATION.md`: 16 distinct anchors, all resolve
- `nix develop --command uv run --with pytest-xdist pytest
tests/test_seeded_hook_runner_migration.py::test_migration_docs_and_changelog_match_the_new_contract
tests/test_rust_scaffold.py::test_bypass_notice_links_to_a_real_migration_heading
tests/test_ci_runner.py -n 4` → **280 passed**
- `git diff` scanned for the scrubbed site-specific label — only present
in removed (`-`) lines
- Checked the section contains no site label, hostname, org-specific
runner name, `/mnt/...` path or real IP

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation accordingly (edit
`docs/templates/`, then run `just docs`) -- N/A, no template change
- [x] I have updated `CHANGELOG.md` in the `[Unreleased]` section (and
pasted the entry above)
- [x] My changes generate no new warnings or errors
- [ ] I have added tests that prove my fix is effective or that my
feature works -- N/A, docs-only change
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published

## Additional Notes

No code changes. S6 (#1950, leak-check hook) is still open and may also
touch `MIGRATION.md`; rebasing onto it if it lands first is on me per
the brief.

Refs: #1933
@gerchowl
gerchowl force-pushed the feature/1932-site-leak-check branch from 1a5f265 to bc7e2f0 Compare October 29, 2026 19:11
@gerchowl
gerchowl merged commit 4663c05 into dev Oct 29, 2026
18 checks passed
@gerchowl
gerchowl deleted the feature/1932-site-leak-check branch October 29, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant