-
Notifications
You must be signed in to change notification settings - Fork 0
BCH 1033: More alert checks for vulnerabilities. #3
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
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dee0893
feat: add more alert checks
jonathandavies-CS b657949
feat: time frames for other vuln levels
jonathandavies-CS c368127
fix: run regal
jonathandavies-CS a03b094
fix: linting
jonathandavies-CS 4beca4c
fix: better comments
jonathandavies-CS 16caf12
fix: test
jonathandavies-CS f40c715
fix: comment
jonathandavies-CS 6ef0a39
fix: check dismissed state and fix tests
jonathandavies-CS 9592b0a
fix: datetime format
jonathandavies-CS f957588
Update policies/critical_vulnerabilities_dismissal/critical_vulnerabi…
jonathandavies-CS 1bd9c4c
Update policies/medium_vulnerabilities_count/medium_vulnerabilities_c…
jonathandavies-CS a447435
Update policies/critical_vulnerabilities_count/critical_vulnerabiliti…
jonathandavies-CS ee27af0
fix: opa fmt
jonathandavies-CS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
policies/critical_vulnerabilities_count/critical_vulnerabilities_count.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package critical_vulnerabilities_count | ||
|
|
||
| import future.keywords.in | ||
|
|
||
| violation[{}] if { | ||
| # Build a set of alerts that are open and with a critical severity. | ||
| open_alerts := [alert | | ||
| some alert in input.alerts | ||
| alert.state == "open" | ||
| alert.security_vulnerability.severity == "critical" | ||
| ] | ||
|
|
||
| # If there are 2 or more such alerts, then deny. | ||
| count(open_alerts) >= 2 | ||
| } | ||
|
|
||
| title := "Limit amount of critical vulnerabilities" | ||
| description := ` | ||
| Critical severity vulnerabilities should be kept within | ||
| reasonable limits to avoid a wide footprint of risk | ||
| ` |
23 changes: 23 additions & 0 deletions
23
policies/critical_vulnerabilities_count/critical_vulnerabilities_count_test.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package critical_vulnerabilities_count_test | ||
|
|
||
| import data.critical_vulnerabilities_count | ||
|
|
||
| test_too_many_critical_vulnerabilities_fail if { | ||
| count(critical_vulnerabilities_count.violation) == 1 with input as {"alerts": [ | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }, | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }, | ||
| ]} | ||
| } | ||
|
|
||
| test_few_critical_vulnerabilities_pass if { | ||
| count(critical_vulnerabilities_count.violation) == 0 with input as [{ | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }] | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
policies/critical_vulnerabilities_dismissal/critical_vulnerabilities_dismissal.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package critical_vulnerabilities_dismissal | ||
|
|
||
| import data.utils.time_ext | ||
|
|
||
| violation[{}] if { | ||
| working_day_now_ns := time_ext.reduce_day_ns(time.now_ns()) | ||
| seven_days_ago := working_day_now_ns - (7 * time_ext.one_day_ns) | ||
|
|
||
| # Check there exists 1 or more critical alerts that have been open for more than 5 working days. | ||
| some alert in input.alerts | ||
|
|
||
| alert.state == "open" | ||
| alert.security_vulnerability.severity == "critical" | ||
| time.parse_rfc3339_ns(alert.created_at) < seven_days_ago | ||
| } | ||
|
|
||
| title := "Limit amount of critical vulnerabilities within 5 working days" | ||
| description := ` | ||
| Critical severity vulnerabilities should dealth with within | ||
jonathandavies-CS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| five working days to avoid a wide footprint of risk` | ||
83 changes: 83 additions & 0 deletions
83
policies/critical_vulnerabilities_dismissal/critical_vulnerabilities_dismissal_test.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package critical_vulnerabilities_dismissal_test | ||
|
|
||
| import data.critical_vulnerabilities_dismissal | ||
|
|
||
| test_over_five_days_violation if { | ||
| now := time.parse_rfc3339_ns("2025-06-20T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-06-03T09:00:00Z", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_one_day_ok if { | ||
| now := time.parse_rfc3339_ns("2025-06-04T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-06-03T09:00:00Z", # one week earlier | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_five_days_over_weekend_ok if { | ||
| now := time.parse_rfc3339_ns("2025-09-22T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-15T09:00:00Z", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_just_more_than_five_days_violation if { | ||
| now := time.parse_rfc3339_ns("2025-09-22T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-15T08:59:59Z", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_alert_over_weekend_ok if { | ||
| now := time.parse_rfc3339_ns("2025-09-29T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-260T09:00:00Z", | ||
jonathandavies-CS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_alert_over_weekend_marginal_ok if { | ||
| now := time.parse_rfc3339_ns("2025-09-27T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-21T09:00:00Z", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_alert_over_weekend_violation if { | ||
| now := time.parse_rfc3339_ns("2025-09-27T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-18T09:00:00Z", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_alert_over_weekend_marginal_violation if { | ||
| now := time.parse_rfc3339_ns("2025-09-27T09:00:00Z") | ||
| count(critical_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-19T06:00:00Z", | ||
| "security_vulnerability": {"severity": "critical"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
policies/high_vulnerabilities_dismissal/high_vulnerabilities_dismissal.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package high_vulnerabilities_dismissal | ||
|
|
||
| import data.utils.time_ext | ||
|
|
||
| violation[{}] if { | ||
| working_day_now_ns := time_ext.reduce_day_ns(time.now_ns()) | ||
| two_weeks_ago := working_day_now_ns - (14 * time_ext.one_day_ns) | ||
|
|
||
| some alert in input.alerts | ||
| alert.state == "open" | ||
| alert.security_vulnerability.severity == "high" | ||
| time.parse_rfc3339_ns(alert.created_at) < two_weeks_ago | ||
| } | ||
|
|
||
| title := "Limit amount of 'high' vulnerabilities that have not been dismissed within 10 working days" | ||
| description := ` | ||
| 'High' severity vulnerabilities should be dismissed within two weeks (10 working days) | ||
| to avoid a wide footprint of risk | ||
| ` |
43 changes: 43 additions & 0 deletions
43
policies/high_vulnerabilities_dismissal/high_vulnerabilities_dismissal_test.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package high_vulnerabilities_dismissal_test | ||
|
|
||
| import data.high_vulnerabilities_dismissal | ||
|
|
||
| test_over_two_weeks_violation if { | ||
| now := time.parse_rfc3339_ns("2025-06-20T09:00:00Z") | ||
| count(high_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-06-03T09:00:00Z", | ||
| "security_vulnerability": {"severity": "high"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_one_day_ok if { | ||
| now := time.parse_rfc3339_ns("2025-06-04T09:00:00Z") | ||
| count(high_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-06-03T09:00:00Z", # one week earlier | ||
| "security_vulnerability": {"severity": "high"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_two_weeks_over_weekend_ok if { | ||
| now := time.parse_rfc3339_ns("2025-09-22T09:00:00Z") | ||
| count(high_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-08T09:00:00Z", | ||
| "security_vulnerability": {"severity": "high"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_just_more_than_two_weeks_violation if { | ||
| now := time.parse_rfc3339_ns("2025-09-22T09:00:00Z") | ||
| count(high_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-09-08T08:59:59Z", | ||
| "security_vulnerability": {"severity": "high"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } |
20 changes: 20 additions & 0 deletions
20
policies/low_vulnerabilities_dismissal/low_vulnerabilities_dismissal.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package low_vulnerabilities_dismissal | ||
|
|
||
| import data.utils.time_ext | ||
|
|
||
| violation[{}] if { | ||
| working_day_now_ns := time_ext.reduce_day_ns(time.now_ns()) | ||
| three_months_ago := working_day_now_ns - (84 * time_ext.one_day_ns) | ||
|
|
||
| # Check there exists a low alert that has been open for more than 5 working days. | ||
| some alert in input.alerts | ||
| alert.state == "open" | ||
| alert.security_vulnerability.severity == "low" | ||
| time.parse_rfc3339_ns(alert.created_at) < three_months_ago | ||
| } | ||
|
|
||
| title := "Limit amount of 'low' vulnerabilities that have not been dismissed within three months" | ||
| description := ` | ||
| 'Low' severity vulnerabilities should be dismissed within three months (60 working days) | ||
| to avoid a wide footprint of risk | ||
| ` |
24 changes: 24 additions & 0 deletions
24
policies/low_vulnerabilities_dismissal/low_vulnerabilities_dismissal_test.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package low_vulnerabilities_dismissal_test | ||
|
|
||
| import data.low_vulnerabilities_dismissal | ||
|
|
||
| test_over_three_months_violation if { | ||
| now := time.parse_rfc3339_ns("2025-06-20T09:00:00Z") | ||
| count(low_vulnerabilities_dismissal.violation) == 1 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-03-19T09:00:00Z", | ||
| "security_vulnerability": {"severity": "low"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } | ||
|
|
||
| test_one_month_ok if { | ||
| now := time.parse_rfc3339_ns("2025-06-20T09:00:00Z") | ||
|
|
||
| count(low_vulnerabilities_dismissal.violation) == 0 with input as {"alerts": [{ | ||
| "state": "open", | ||
| "created_at": "2025-05-20T09:00:00Z", | ||
| "security_vulnerability": {"severity": "low"}, | ||
| }]} | ||
| with time.now_ns as now | ||
| } |
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
policies/medium_vulnerabilities_count/medium_vulnerabilities_count.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package medium_vulnerabilities_count | ||
|
|
||
| import future.keywords.in | ||
|
|
||
| violation[{}] if { | ||
| # Build a set of alerts that are open and with a medium severity. | ||
| open_alerts := [alert | | ||
| some alert in input.alerts | ||
| alert.state == "open" | ||
| alert.security_vulnerability.severity == "medium" | ||
| ] | ||
|
|
||
| count(open_alerts) >= 5 | ||
| } | ||
|
|
||
| title := "Limit amount of medium vulnerabilities" | ||
| description := `Medium severity vulnerabilities should be kept within | ||
| reasonable limits to avoid a wide footprint of risk` |
35 changes: 35 additions & 0 deletions
35
policies/medium_vulnerabilities_count/medium_vulnerabilities_count_test.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package medium_vulnerabilities_count_test | ||
|
|
||
| import data.medium_vulnerabilities_count | ||
|
|
||
| test_too_many_medium_vulnerabilities_fail if { | ||
| count(medium_vulnerabilities_count.violation) == 1 with input as {"alerts": [ | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }, | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }, | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }, | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }, | ||
| { | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }, | ||
| ]} | ||
| } | ||
|
|
||
| test_few_medium_vulnerabilities_pass if { | ||
| count(medium_vulnerabilities_count.violation) == 0 with input as [{ | ||
| "state": "open", | ||
| "security_vulnerability": {"severity": "medium"}, | ||
| }] | ||
jonathandavies-CS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
20 changes: 20 additions & 0 deletions
20
policies/medium_vulnerabilities_dismissal/medium_vulnerabilities_dismissal.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package medium_vulnerabilities_dismissal | ||
|
|
||
| import data.utils.time_ext | ||
|
|
||
| violation[{}] if { | ||
| working_day_now_ns := time_ext.reduce_day_ns(time.now_ns()) | ||
| one_month_ago := working_day_now_ns - (28 * time_ext.one_day_ns) | ||
|
|
||
| # Check there exists a medium alert that has been open for more than a month | ||
| some alert in input.alerts | ||
| alert.state == "open" | ||
| alert.security_vulnerability.severity == "medium" | ||
| time.parse_rfc3339_ns(alert.created_at) < one_month_ago | ||
| } | ||
|
|
||
| title := "Limit amount of 'medium' vulnerabilities that have not been dismissed within one month" | ||
| description := ` | ||
| 'Medium' severity vulnerabilities should be dismissed within one month (20 working days) | ||
| to avoid a wide footprint of risk | ||
| ` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.