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 evaluation failure message to rego rules #176

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion rule-types/common/license.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,23 @@ def:
import future.keywords.if
default allow := false
fileStr := file.read(input.profile.license_filename)
allow if {
# Read the license file and check if it contains the license type
fileStr := file.read(input.profile.license_filename)
contains(fileStr, input.profile.license_type)
} else if {
# Check if the file exists and the license type is left blank
file.exists(input.profile.license_filename)
input.profile.license_type == ""
}
message := sprintf("License file %v does not exist", [input.profile.license_filename]) if {
not file.exists(input.profile.license_filename)
} else := sprintf("License file %v does not match the expected license type %v", [input.profile.license_filename, input.profile.license_type]) if {
not contains(fileStr, input.profile.license_type)
}
# Defines the configuration for alerting on the rule
alert:
type: security_advisory
Expand Down
13 changes: 13 additions & 0 deletions rule-types/github/actions_check_default_permissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ def:
count(job.permissions) >= 0
}
}
# Get the list of workflows that do not have permissions and create the error message
missing_permissions_workflows = [workflow_name |
filename := workflows[_] # Iterate over each workflow filename
workflowstr := file.read(filename)
workflow := yaml.unmarshal(workflowstr)
not permissions_ok(workflow)
workflow_name = workflow.name
]
# Construct the final message
message := sprintf("Workflows %s do not explicitly set their permissions", [concat(",", missing_permissions_workflows)])
# We don't have a remediation method in place yet.

# Defines the configuration for alerting on the rule
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/artifact_attestation_slsa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def:
default allow := false
default skip := false
default message := "Cannot verify SLSA provenance"
default workflow_ref := "refs/heads/main"
workflow_ref := input.profile.workflow_ref
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/branch_protection_enabled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def:
import future.keywords.if
default allow := false
default message := "No branch protection rule is set"
allow if {
input.ingested.url != ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def:
import future.keywords.if
default allow := false
default message := "Pull requests are not required"
allow if {
input.ingested.required_pull_request_reviews.url != ""
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/codeql_enabled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def:
package minder
default allow := false
default message := "CodeQL is not enabled"
allow {
# List all workflows
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/dependabot_configured.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def:
package minder
default allow := false
default message := "Dependabot is not configured"
# Set allow if we don't need to skip and the rule evaluation passes
allow {
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/scorecard_enabled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def:
package minder
default allow := false
default message := "Scorecard Action is not configured for any workflow"
allow {
# List all workflows
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/secret_push_protection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def:
default allow := false
default skip := false
default message := "Secret push protection is disabled"
allow if {
input.ingested.security_and_analysis.secret_scanning_push_protection.status == "enabled"
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/secret_scanning.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def:
default allow := false
default skip := false
default message := "Secret scanning is disabled"
allow if {
input.ingested.security_and_analysis.secret_scanning.status == "enabled"
Expand Down
2 changes: 2 additions & 0 deletions rule-types/github/security_insights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def:
import rego.v1
default allow := false
default message := "Security Insights file is missing"
allow if {
file.exists(input.profile.filename)
}
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/security_insights_dep_policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def:
import rego.v1
default allow := false
default message := "Dependency policy is missing from the Security Insights file"
allow if {
file.exists(input.profile.filename)
Expand Down
2 changes: 2 additions & 0 deletions rule-types/github/security_policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def:
import rego.v1
default allow := false
default message := "Security policy file is missing"
allow if {
file.exists(input.profile.filename)
}
Expand Down
1 change: 1 addition & 0 deletions rule-types/github/trivy_action_enabled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def:
package minder
default allow := false
default message := "Trivy action is not enabled"
allow {
# List all workflows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def:
package minder
default allow := false
default message := "GitLab Dependency Scanning is not enabled"
allow {
# Read the .gitlab-ci.yml file
Expand Down
1 change: 1 addition & 0 deletions rule-types/gitlab/gitlab_protect_branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def:
package minder
default allow := false
default message := "Branch is not set as protected"
allow {
# Check that there is at least one protected branch
Expand Down
1 change: 1 addition & 0 deletions rule-types/gitlab/gitlab_require_merge_requests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def:
package minder
default allow := false
default message := "Merge requests are not required"
allow {
# Check that there is at least one protected branch
Expand Down
Loading