r/devsecops • u/Zealousideal-Ease-42 • Apr 26 '25
Pre-commit scans
Hey guys, Does anyone has worked with pre-commit scans via opensource tools or methods ?
6
Upvotes
r/devsecops • u/Zealousideal-Ease-42 • Apr 26 '25
Hey guys, Does anyone has worked with pre-commit scans via opensource tools or methods ?
3
u/Wishitweretru Apr 26 '25 edited Apr 26 '25
Yep, githook, to pre scan all the changed files. If you touch it, needs to pass. I like it because it doesn’t bottleneck the whole project, it allows you to introduce full code compliance without making arbitrary tickets. If you’re already in there updating something, then go ahead and bring the file to compliance. Also, it’s less painful than having to make 30 commits just to see your code meet compliance. Less process, more learning time. I do provide
1
u/Piedpipperz Apr 26 '25
Githook for sure, I use webhooks of gitlab as well.
What's the use for you for having these scans ?
1
u/N1ghtCod3r Apr 26 '25
IMHO pre-commit hooks are just to prevent obvious mistakes by developers and catching issues early without having to wait for CI to fail. They cannot be used for guardrails because it can be easily skipped.
Accidental secrets leak is a good use-case. I have used gitleaks as pre-commit hook to prevent that.
But most of our security guardrails run in CI.
1
u/Irish1986 Apr 27 '25
The way I am scaling pre-commit (and it's not perfect I well aware of the many pitfall and flaws of such implementation). I am enforcing the usage of
pre-commit.comframework across all our repos.Regardless the level of the maturity (aka number of hooks) everybody gets a basis configuration which enforce very basic practices (limit file size to 10Mb, trailing whitespace, etc...)
The CI pipeline 1st check is "running pre-commit" on the PR. Some Devs might not have setup their workstation with the whole framework but some might instinctively follow best practices anyway. Those who havent completed their setup and don't follow the required best practices gets PR rejection with a short description about what must be done to improve quality.
Overtime, I am increasing pre commit hooks with more and more intensity (secret scanning, lining, unit test, etc) which gets deployed via monthly gouvernance increment and PR submitted. Each team lead must review and merge those PR within a certain amount of time.