Skip to content

ROX-12238: Isolate O.S. matchers to re-use by node scanning #904

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

Merged
merged 2 commits into from
Sep 8, 2022

Conversation

jvdm
Copy link
Contributor

@jvdm jvdm commented Sep 3, 2022

Create singletons for two different types of "matcher" (O.S. features and active vulnerability), and add a new matcher interface called PrefixMatcher that offers a method to retrieve the list of directories to look for files.

Node scanning will exclusively use the O.S. matcher. And the list of directories will be used by the node scanner to determine which directories to walk and extract files from. This allows node scanning to be specific on the directories to walk and ignore the other files that are irrelevant during the extraction. Notice that, some analyzers (also known as detectors) do not have a deterministic set of files to scan, they look at prefixes, we still need to walk in directories.

Tests

UT and CI

@jvdm jvdm requested review from c-du and daynewlee September 3, 2022 01:34
@jvdm jvdm force-pushed the jvdm/ROX-12238/1/pull branch from 6f6fbcc to 88479b1 Compare September 3, 2022 01:42
@ghost
Copy link

ghost commented Sep 3, 2022

Images are ready for the commit at 83625f1.

To use the images, use the tag 2.25.0-83-g83625f1128.

@jvdm jvdm force-pushed the jvdm/ROX-12238/1/pull branch from 88479b1 to a0e0142 Compare September 5, 2022 19:48
@jvdm jvdm changed the title Isolate O.S. matchers to re-use by node scanning ROX-12238: Isolate O.S. matchers to re-use by node scanning Sep 5, 2022
@RTann RTann self-requested a review September 7, 2022 04:51
Matcher

// GetCommonPrefixDirs returns a list with common directory prefixes from all
// file prefixes in this matcher, but excluding the root directory. The returned
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate how the common directory prefixes are selected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


instance = matcher.NewOrMatcher(allMatchers...)
// SingletonMatcher returns the singleton matcher instance to use for extracting
// files for analyzing image container. It includes matching for O.S. features
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It is more common to use OS instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -39,6 +66,33 @@ func (w *allowlistMatcher) Match(fullPath string, _ os.FileInfo, _ io.ReaderAt)
return false, false
}

func (w *allowlistMatcher) GetCommonPrefixDirs() []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: w *allowlistMatcher, w should be a or m?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}
}
dirs := pre[""].AsSlice()
ret := dirs[:0]
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the common dir prefix just steps one level down from the root directory and it returns exactly one common prefix per first level dir referenced. And yes, that could be a good balance for how common the common prefix could be. Can you add more comments?
You can also rename the dirs as firstLevelDirs or dirsUnderRoot to make it more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

}

func findCommonDirPrefixes(prefixes []string) []string {
pre := make(map[string]set.StringSet)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about prefixToSubdirsMap?

Copy link
Contributor Author

@jvdm jvdm Sep 7, 2022

Choose a reason for hiding this comment

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

I want to clarify that the method is doing a search in a trie-like structure finding paths with single-children nodes. Do you think replacing find with search would be better, or do you still think a "map" verb in the name would be clearer?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was proposing the alt name for the pre. I am ok with both names for the functions.

Copy link
Contributor Author

@jvdm jvdm Sep 8, 2022

Choose a reason for hiding this comment

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

Gotcha. Let me update it, but I will remove the map suffix, since golang is typed, and decorating the name with its type, in this case, is redundant.

@jvdm jvdm force-pushed the jvdm/ROX-12238/1/pull branch from a0e0142 to 41b9775 Compare September 7, 2022 19:07
@jvdm jvdm requested a review from c-du September 7, 2022 21:12
@jvdm
Copy link
Contributor Author

jvdm commented Sep 7, 2022

/retest

@jvdm jvdm force-pushed the jvdm/ROX-12238/1/pull branch from 41b9775 to c257e53 Compare September 7, 2022 21:58
@jvdm
Copy link
Contributor Author

jvdm commented Sep 7, 2022

/test slim-e2e-tests

@jvdm jvdm force-pushed the jvdm/ROX-12238/1/pull branch from c257e53 to 83625f1 Compare September 8, 2022 16:42
@jvdm jvdm merged commit db786ab into master Sep 8, 2022
@jvdm jvdm deleted the jvdm/ROX-12238/1/pull branch September 8, 2022 18:08
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.

2 participants