Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup a pre-commit secret leak check #143

Open
eric-burel opened this issue Jan 14, 2022 · 0 comments
Open

Setup a pre-commit secret leak check #143

eric-burel opened this issue Jan 14, 2022 · 0 comments

Comments

@eric-burel
Copy link
Collaborator

eric-burel commented Jan 14, 2022

First try pre-commit + gitleaks

Using gitleaks : https://github.com/zricethezav/gitleaks
And pre-commit: https://pre-commit.com/#install

Example script:

   "postinstall": "test -n \"$SKIP_PRE_COMMIT_INSTALL\" && echo 'Skipping pre-commit install' || pre-commit install # Please see 'https://pre-commit.com/#install'",

This needs Python to install "pre-commit" and "go" to run gitleaks. Therefore, a more appropriate alternative would be using Husky + the Docker version of gitleaks, similarly to what we do to run Mongo.

Second try with Husky + Docker

In package.json:

    "prepare": "husky install || echo 'Husky command not installed or not working, are you running in production? You won't be protected when committing code",
    "pre-commit:gitleaks": "docker run -v $(pwd):/path zricethezav/gitleaks:latest detect --source=\"/path\" --report-format json",
    "pre-commit": "# Automatically run by husky on commit",

With husky set to run "npm run pre-commit"

=> very slow, gives false positive

3rd try With protect command

It seems that the command we need is protect. Will test and finish this issue when the commands are ok.
Not sure if it actually catches leak yet, to be tested more extensively:

    "prepare": "husky install || echo 'Husky command not installed or not working, are you running in production? You won't be protected when committing code",
    "detect-leaks": "docker run -v $(pwd):/path zricethezav/gitleaks:latest detect -v --source=\"/path\"",
    "pre-commit:gitleaks": "docker run -v $(pwd):/path zricethezav/gitleaks:latest protect -v  --source=\"/path\" --staged",
    "pre-commit": "echo 'Running yarn pre-commit command' && yarn run pre-commit:gitleaks # Automatically run by husky on commit",
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

No branches or pull requests

1 participant