Skip to content

Setup a pre-commit secret leak check #143

@eric-burel

Description

@eric-burel

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",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions