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

Add ruletype for OSPS-QA-03 #307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add ruletype for OSPS-QA-03 #307

wants to merge 1 commit into from

Conversation

eleftherias
Copy link
Contributor

Fix #289

I intentionally didn't add it to the profile because the definition isn't final.

@eleftherias eleftherias requested a review from a team as a code owner January 31, 2025 16:20
skip if {
# Skip if no package manager file exists
every package_manager in package_manager_files {
required_files := file.ls_glob(sprintf("./%s", [package_manager.name]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the glob library we're using in Minder doesn't support ** patterns, which is why this only looks at the root directory. This is probably something we want to change in the Minder code.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah -- we could also use file.walk for this:

Suggested change
required_files := file.ls_glob(sprintf("./%s", [package_manager.name]))
all_files := file.walk(".")
package_manager_files = [ filepath |
filepath := all_files[_];
glob.match("**/" + package_manager[_].name, ["/"], filepath)
]

Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

This rule looks handy overall. Can we get a copy in the common dir too? With regular verbiage and i meant common because this Will most likely work with gitlab too.

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

This seems handy!

I'm not sure whether QA-03 will be loosened to allow e.g. requirements.txt, but I think we should keep this rule in the common area even if QA-03 becomes less strict.

skip if {
# Skip if no package manager file exists
every package_manager in package_manager_files {
required_files := file.ls_glob(sprintf("./%s", [package_manager.name]))
Copy link
Member

Choose a reason for hiding this comment

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

Yeah -- we could also use file.walk for this:

Suggested change
required_files := file.ls_glob(sprintf("./%s", [package_manager.name]))
all_files := file.walk(".")
package_manager_files = [ filepath |
filepath := all_files[_];
glob.match("**/" + package_manager[_].name, ["/"], filepath)
]

Comment on lines +55 to +67
allow if {
# Ensure that we find the required file
some package_manager in package_manager_files
package_files := file.ls_glob(sprintf("./%s", [package_manager.name]))
count(package_files) > 0

# Get the directory for the package file
some package_path in package_files
dir := trim_suffix(package_path, sprintf("/%s", [package_manager.name]))

# Ensure a lockfile exists for the required file in the same directory
lockfile_exists(dir, package_manager.lockfiles)
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this an allow if or a constraints if the lockfile is missing? i.e. if I have:

./go.mod
./go.sum
./package.json

(No lockfile for NPM)

Is this a "pass" or a "fail"? I suspect it's a fail for the NPM ecosystem, even if it's a pass for the Go ecosystem.

]

skip if {
# Skip if no package manager file exists
Copy link
Member

Choose a reason for hiding this comment

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

Looking at QA-03, I think if there's a language in the repo identified by GitHub, we should be ensuring that there are package files, rather than ignoring repos that also don't check in Gemfile/etc.

We could find the set of detected languages with a call to the repo config data source. At least for npm and Go, I know that a go.mod / package.json is needed to declare a module at all, whether or not it has dependencies, so checking for those files makes sense.

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.

Implement Security Baseline criterion OSPS-QA-03
3 participants