Skip to content

feat(docker): implement exclude paths functionality #4057

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

tannerjones4075
Copy link

@tannerjones4075 tannerjones4075 commented Apr 15, 2025

Description:

Add support for excluding paths in Docker source scanning:

  • Add ExcludePaths field to Docker protobuf
  • Implement path exclusion logic in docker.go
  • Add comprehensive test coverage for exact and wildcard path matching
  • Update engine to pass exclude paths configuration
  • Add CLI support for --exclude-paths flag

The implementation supports:

  • Exact path matching (e.g., /var/log/test)
  • Wildcard path matching (e.g., /var/log/test/*)
  • Multiple exclude paths

Tests ensure proper handling of:

  • Exact path exclusions
  • Wildcard exclusions
  • Edge cases and similar paths

References:

https://github.com/trufflesecurity/trufflehog/issues/2216?utm_source=chatgpt.com

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Add support for excluding paths in Docker source scanning:

- Add ExcludePaths field to Docker protobuf

- Implement path exclusion logic in docker.go

- Add comprehensive test coverage for exact and wildcard path matching

- Update engine to pass exclude paths configuration

- Add CLI support for --exclude-paths flag

The implementation supports:

- Exact path matching (e.g., /var/log/test)

- Wildcard path matching (e.g., /var/log/test/*)

- Multiple exclude paths

Tests ensure proper handling of:

- Exact path exclusions

- Wildcard exclusions

- Edge cases and similar paths
@CLAassistant
Copy link

CLAassistant commented Apr 15, 2025

CLA assistant check
All committers have signed the CLA.

@kashifkhan0771
Copy link
Contributor

Thank you for opening this PR @tannerjones4075. Can you sign the CLA?

@tannerjones4075
Copy link
Author

Thank you for opening this PR @tannerjones4075. Can you sign the CLA?

I have signed the CLA :)

Copy link
Collaborator

@rosecodym rosecodym left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! It's a very clear and straightforward improvement. In particular, thank you for the detailed description and the tests. I've found a couple of small improvements I'd like to make before getting this in that I think will substantially reduce our future maintenance burden - please see my inline comments.

@tannerjones4075
Copy link
Author

I appreciate the feedback. I'll make some changes and add another commit.

Copy link
Collaborator

@rosecodym rosecodym left a comment

Choose a reason for hiding this comment

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

I love one of your new tests! But I've added some more commentary to the other one.

@rosecodym
Copy link
Collaborator

rosecodym commented Apr 29, 2025

One thing I didn't mention in earlier reviews - that I probably should have - is that the existing codebase has glob inclusion/exclusion implementation logic you could possibly reuse instead of adding this new regex-based technique. I'm not going to insist on it (because I didn't bring it up earlier) but it's probably worth at least giving it a glance to see if it would be helpful.

@tannerjones4075
Copy link
Author

One thing I didn't mention in earlier reviews - that I probably should have - is that the existing codebase has glob inclusion/exclusion implementation logic you could possibly reuse instead of adding this new regex-based technique. I'm not going to insist on it (because I didn't bring it up earlier) but it's probably worth at least giving it a glance to see if it would be helpful.

I replaced the regex with globfilter. Thanks for the suggestion and I think it reduces complexity and improved maintainability.

Copy link
Collaborator

@rosecodym rosecodym 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 super clean, nice work! I have a couple of small questions, and I see you've got a conflicting sources.pb.go file. Once you've resolved the former, you can resolve the latter by merging from main and then running make protos, but if you're running into trouble with it, I'm happy to do that part for you, since it was my extended review that caused the drift in the first place :)

@rosecodym
Copy link
Collaborator

Let me know if you want me to take this over and do the protobuf merge!

@tannerjones4075
Copy link
Author

Let me know if you want me to take this over and do the protobuf merge!

Yes, the help would be great to get it merged.

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

Successfully merging this pull request may close these issues.

Add --include-paths and --exclude-paths flags for Docker scan
4 participants