gravitational / teleport

The easiest, and most secure way to access and protect all of your infrastructure.
https://goteleport.com
GNU Affero General Public License v3.0
17.42k stars 1.74k forks source link

Add pre-commit hook that detects secrets #43395

Closed r0mant closed 1 month ago

r0mant commented 3 months ago

Let's add a git pre-commit hook that prevents folks from accidentally pushing secrets to Github.

Research/investigate what options there are and implement this.

codeknight03 commented 3 months ago

Looks like an interesting quest though looks like it has already been assigned would like to be part of the research or implementation.

doggydogworld commented 3 months ago

After doing some investigating I found two tools that are well supported and open source.

Just to compare them from a UX standpoint

Features

Quick Testing

Created a fake SSH key, TLS private/public key pair, auto-generated password, and canary AWS credentials.

Also did a quick test against all files in the teleport repo to check noise levels and check the upper bound of the execution time. The check did not include git history only the files present in the latest commit.

Neither caught the auto-generated password but this could be configured in both to be more sensitive.

Conclusion

We should use gitleaks for pre-commit hooks.

While trufflehog is very powerful and has a lot of really nice features for reducing noise that does come at a cost to execution time. With the extremely small commit I tested it against it took almost 15 seconds to run. It's important to also recognize that in verified mode it establishes connections which depending on network conditions could slow it down even more. It might be a good idea to look into trufflehog for frequent scans post-commit but it could be too intrusive in the development process as a pre-commit hook.

r0mant commented 3 months ago

@doggydogworld I agree with your assessment, let's use gitleaks.

r0mant commented 1 month ago

We've decided to not do this for the time being given hosted Github does not support server-side pre-commit hooks and making this feature opt-in makes it far less effective. Github's builtin secret scanning on push should do fine for now.