ci(gitleaks): add pre-commit hook, config with sealed-secrets allowlist, and tests#287
ci(gitleaks): add pre-commit hook, config with sealed-secrets allowlist, and tests#287
Conversation
coretl
left a comment
There was a problem hiding this comment.
Please can we also have a test in tests that inserts a secret into the code base, runs tox -e pre-commit and checks the output?
A bit like this but for pre-commit:
python-copier-template/tests/test_example.py
Lines 226 to 238 in 9d544a5
|
Following is what I have done in the latest commit and have pushed it to this branch.
|
paths line in .gitleaks.toml to extend to all files|
Is the decision to only do this in YAML documented somewhere? I think we'll potentially miss things doing this? |
@wajidzahoor-dls @coretl is it possible to do the bootstapping at devcontainer build time instead of on first run of pre-commit? In my experience it takes a little while which can be an annoying interruption to the commit workflow. |
This is a good point. Probably the most egregious cases are going to have the secret in source code. But, this could increase false positives by quite a bit. |
Many of the false positives are usually SealedSecrets. The allow-list is scoped to YAML/YML to keep the initial change small and avoid deviating too much from gitleaks’ defaults. All of gitleaks’ built-in rules still run ( At the template level this can server as default, but on a per-repo basis we can expand the allow-list beyond YAML by commenting out the Worth noting: the allow-list is regex-based and may occasionally cause false positives or false negatives, but overall it reduces SealedSecrets noise while keeping baseline coverage intact. |
My bad, this was a misunderstanding on my part. I think I read the comment:
To imply that all rules are only applied to YAML rather than just the sealed secret part. Could you update that comment to be clearer? |
I think this should be doable. Maybe we could look at using copier.yml tasks to install pre-commit hooks right after the template is applied (if the repo is already initialized), or lean on .devcontainer so the bootstrap happens automatically when the dev environment is first created. We can create separate branch to explore this further as needed. |
Thank you for the suggestion. I’ve updated the comments in .gitleaks.toml for clarity. |
|
https://pre-commit.com/#pre-commit-install suggests |
Tested locally, and |
…emplate/.gitleaks.toml
2147b27 to
b683927
Compare

Summary
Ag…patterns), scoped to*.yml/*.yaml.pathsline in.gitleaks.tomlfile.How to test
I verified this change with:
This should include output from gitleaks, scanning for potential hardcoded secrets.
For local testing, I used:
Depending on your environment, testing may happen differently:
tox -e pre-commit)Manual spot checks
Secret detection
Allowlist works (YAML only)
Ag…token in a.yaml/.ymlfile → should be allowlisted.Notes
pathsline in.gitleaks.tomlhttps://github.com/gitleaks/gitleaks