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

Make detectors configurable #1084

Merged
merged 19 commits into from
Feb 11, 2023
Merged

Make detectors configurable #1084

merged 19 commits into from
Feb 11, 2023

Conversation

ahrav
Copy link
Collaborator

@ahrav ahrav commented Feb 9, 2023

Allow for the list of detectors used during verification to be configurable via a CLI flag.

  • Add detectors CLI flag that accepts a comma separated list of include and exclude detector names.
  • If the values for the detectors flag are invalid or are names of detectors that we do not support, default to using all detectors.

NOTE: As a benchmark running a scan against the https://github.com/trufflesecurity/trufflehog.git repo using all detectors vs only AWS resulted in a scan that ran ~16s faster.
All detectors ~ 40s
AWS detector only ~24s

Screenshot 2023-02-10 at 4 18 54 PM

@ahrav ahrav marked this pull request as ready for review February 9, 2023 22:49
@ahrav ahrav requested a review from a team as a code owner February 9, 2023 22:49
@ahrav ahrav linked an issue Feb 9, 2023 that may be closed by this pull request
@ahrav ahrav requested a review from a team February 9, 2023 23:08
main.go Outdated Show resolved Hide resolved
@ahrav ahrav requested review from a team and mcastorina February 9, 2023 23:23
main.go Outdated
Comment on lines 211 to 225
var detectorsOption engine.EngineOption

if len(*detectors) > 0 {
detectorsOption = engine.WithDetectors(!*noVerification, engine.Detectors(ctx, strings.Split(*detectors, ","))...)
} else {
detectorsOption = engine.WithDetectors(!*noVerification, engine.DefaultDetectors()...)
}

e := engine.Start(ctx,
engine.WithConcurrency(*concurrency),
engine.WithDecoders(decoders.DefaultDecoders()...),
engine.WithDetectors(!*noVerification, engine.DefaultDetectors()...),
engine.WithDetectors(!*noVerification, conf.Detectors...),
engine.WithFilterUnverified(*filterUnverified),
detectorsOption,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice - so --config config.yaml --detectors AWS would use custom detectors and AWS detectors. Does that make sense, or should it be --config config.yaml --detectors AWS,CustomRegex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that's fine, given the CustomRegex is a bit special due to the fact we pass it via a config. It seems like maybe it should stand on its own? I don't have much of a preference though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, i just noticed your comment has a config either way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah - in the future the config file might have more than one custom detector (or other config options), so being able to filter them by detector type makes sense to me?

Maybe I'm being overly cautious here but it's easier to relax restrictions than to add them so I slightly prefer --detectors AWS,CustomRegex.

@ahrav ahrav requested review from a team February 9, 2023 23:52
Copy link
Collaborator

@trufflesteeeve trufflesteeeve left a comment

Choose a reason for hiding this comment

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

This looks good, though I would strongly suggest we consider misconfigurations here to be an error that we should not continue with the scan, but rather let the user know the name of every expected detector type that didn't match with an actual detector.

@dustin-decker
Copy link
Contributor

dustin-decker commented Feb 10, 2023

We might also want to consider an inverse option, like use all detectors except for x,y,z
That's the more common use case I think

@ahrav
Copy link
Collaborator Author

ahrav commented Feb 10, 2023

We might also want to consider an inverse option, like use all detectors except for x,y,z That's the more common use case I think

Will add that functionality in, and update the CLI flags.

@ahrav ahrav merged commit 67784f6 into main Feb 11, 2023
@ahrav ahrav deleted the configure-detectors branch February 11, 2023 00:30
dustin-decker added a commit that referenced this pull request Feb 11, 2023
dustin-decker added a commit that referenced this pull request Feb 11, 2023
javajawa added a commit to mewbotorg/mewbot that referenced this pull request Feb 12, 2023
Sourced from trufflesecurity/trufflehog's releases.

v3.27.0
What's Changed
Bump golang.org/x/oauth2 from 0.3.0 to 0.4.0 by @​dependabot in trufflesecurity/trufflehog#1039
add bodyclose linter to help prevent file handle leaks by @​dustin-decker in trufflesecurity/trufflehog#1048
braintree detector: use production API URL instead of the test sandbo… by @​swdbo in trufflesecurity/trufflehog#1054
Update float detector with correct User-Agent and regex by @​ahrav in trufflesecurity/trufflehog#1061
update webex detector regex by @​ahrav in trufflesecurity/trufflehog#1062
Handle errors in a thread safe manner by @​ahrav in trufflesecurity/trufflehog#1052
Add TruffleHog version input for GitHub action by @​mcastorina in trufflesecurity/trufflehog#1064
Revert "Add TruffleHog version input for GitHub action (#1064)" by @​mcastorina in trufflesecurity/trufflehog#1068
Pull gitparse config options out of pkg consts by @​bill-rich in trufflesecurity/trufflehog#1072
Add include exclude spaces for confluence source. by @​ahrav in trufflesecurity/trufflehog#1073
Add max commit size by @​bill-rich in trufflesecurity/trufflehog#1079
Make archive handler configurable by @​bill-rich in trufflesecurity/trufflehog#1077
[chore] - Add tests for errors by @​ahrav in trufflesecurity/trufflehog#1071
Skip repo and continue scanning when encountering an error by @​mcastorina in trufflesecurity/trufflehog#1080
[chore] - Dont pre-allocate errors slice by @​ahrav in trufflesecurity/trufflehog#1083
Add Type() to detector interface by @​trufflesteeeve in trufflesecurity/trufflehog#1088
[chore] Remove logrus from engine package by @​mcastorina in trufflesecurity/trufflehog#1085
[chore] Remove logrus from github source by @​mcastorina in trufflesecurity/trufflehog#1086
Bump github.com/joho/godotenv from 1.4.0 to 1.5.1 by @​dependabot in trufflesecurity/trufflehog#1075
[chore] Remove logrus from circleci, filesystem, gitlab, and s3 sources by @​mcastorina in trufflesecurity/trufflehog#1089
[chore] - Remove monolithic config struct by @​ahrav in trufflesecurity/trufflehog#1091
Make detectors configurable by @​ahrav in trufflesecurity/trufflehog#1084
New Contributors
@​swdbo made their first contribution in trufflesecurity/trufflehog#1054
Full Changelog: trufflesecurity/trufflehog@v3.26.0...v3.27.0

v3.26.0
What's Changed
Add openssh-client to trufflehog container by @​mcastorina in trufflesecurity/trufflehog#1045
Bump github.com/rabbitmq/amqp091-go from 1.5.0 to 1.6.0 by @​dependabot in trufflesecurity/trufflehog#1036
filesystem support for exclude and include filters (2nd attemp) by @​mac2000 in trufflesecurity/trufflehog#1033
Fix the typo "programatic" by @​nezakoo in trufflesecurity/trufflehog#1046
Add file to confluence proto. by @​ahrav in trufflesecurity/trufflehog#1049
Remove false positive detection for CustomRegex by @​mcastorina in trufflesecurity/trufflehog#1050
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.

Run certain Detector Type
4 participants