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

feat: add trivy secret scanning #440

Conversation

puzzler7
Copy link
Contributor

Adds trivy secret scanning - the reason this wasn't showing up before was because trivy by default doesn't scan for secrets in files with /test in the path. Also reworks the trivy tests to have separate tests for each subcommand.

secrets.py:2:0
  2:0  high  AWS Access Key ID       trivy/aws-access-key-id    
  3:0  high  AWS Secret Access Key   trivy/aws-secret-access-key
 11:0  high  Asymmetric Private Key  trivy/private-key          

Copy link
Collaborator

@TylerJang27 TylerJang27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple discussion points. Looks mostly good

@@ -0,0 +1,158 @@
[
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also delete the expected_issues.json file

Comment on lines +47 to +48
- name: fs-secret
files: [ALL]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we end up turning this on for everyone, couple verification questions:

  1. How does performance compare to something like trufflehog?
  2. How does secret scanning effectiveness compare to something like trufflehog?
  3. What's the relative noisiness for our monorepo?

If any of these answers are in the negative direction, we may want to consider disabling this subcommand by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be disabled by default.

  1. It's slower than trufflehog.
  2. It's about the same, I think.
  3. Almost none - it has the added benefit of default ignoring our many fake secrets in test files.

Despite these, it has a few benefits over trufflehog - you can define your own regexes to search for and you can define regexes to not alert on (e.g. if you only use AWS keys, you can only search for those, making this tool faster). I think having trufflehog enabled for everybody, and then trivy secret scanning available but disabled by default for users looking to customize their secret scanning further is the best way to go.

fs.readFileSync(path.resolve(__dirname, "expected_issues.json")).toString()
);
const callbackGenerator =
(command: string, otherPreCheck?: (driver: TrunkLintDriver) => void): TestCallback =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can otherPreCheck? be a TestCallback type?

Comment on lines +25 to +27
const configExpectedFileIssues = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "config_expected_issues.json")).toString(),
) as FileIssue[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would actually prefer this as a magic number rather than parsing here, just in case if we mess it up accidentally, we'll be asserting something like a 0 issue match, which will always be true

fuzzyLinterCheckTest({
linterName: "trivy",
testName: "config",
args: "-a -y",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove -y. No autofixes

@puzzler7 puzzler7 requested a review from TylerJang27 August 17, 2023 18:03
Copy link
Collaborator

@TylerJang27 TylerJang27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@puzzler7 puzzler7 merged commit a86f500 into main Aug 17, 2023
@puzzler7 puzzler7 deleted the maverick/trunk-8184-make-trivy-secret-scanning-work-and-investigate-other-trivy branch August 17, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants