-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,16 @@ | ||
rules: | ||
default: | ||
level: ignore | ||
custom: | ||
naming-convention: | ||
level: error | ||
conventions: | ||
- pattern: '^builtin|lib|defsec|appshield' | ||
targets: | ||
- package | ||
naming: | ||
deny-rule: | ||
level: error | ||
ignore: | ||
files: | ||
- "*_test.rego" |
19 changes: 19 additions & 0 deletions
19
.regal/rules/custom/regal/rules/naming/deny-rule/deny_rule.rego
This file contains 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 @@ | ||
# METADATA | ||
# description: Ensures that no rules in the check are named with the prefix 'deny_' | ||
# related_resources: | ||
# - description: documentation | ||
# ref: https://github.com/aquasecurity/trivy-checks/pull/283 | ||
# schemas: | ||
# - input: schema.regal.ast | ||
package custom.regal.rules.naming["deny-rule"] | ||
|
||
import rego.v1 | ||
|
||
import data.regal.ast | ||
import data.regal.result | ||
|
||
report contains violation if { | ||
some rule in input.rules | ||
startswith(ast.ref_to_string(rule.head.ref), "deny_") | ||
violation := result.fail(rego.metadata.chain(), result.location(rule)) | ||
} |
35 changes: 35 additions & 0 deletions
35
.regal/rules/custom/regal/rules/naming/deny-rule/deny_rule_test.rego
This file contains 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 custom.regal.rules.naming["deny-rule_test"] | ||
|
||
import rego.v1 | ||
|
||
import data.custom.regal.rules.naming["deny-rule"] as rule | ||
|
||
test_rule_named_startswith_not_allowed if { | ||
module := regal.parse_module("example.rego", ` | ||
package policy | ||
deny_foo := true`) | ||
|
||
r := rule.report with input as module | ||
|
||
r == {{ | ||
"category": "naming", | ||
"description": "Ensures that no rules in the check are named with the prefix 'deny_'", | ||
"related_resources": [{ | ||
"description": "documentation", | ||
"ref": "https://github.com/aquasecurity/trivy-checks/pull/283", | ||
}], | ||
"level": "error", | ||
"location": { | ||
"file": "example.rego", | ||
"row": 4, | ||
"col": 2, | ||
"end": { | ||
"row": 4, | ||
"col": 18, | ||
}, | ||
"text": "\tdeny_foo := true", | ||
}, | ||
"title": "deny-rule", | ||
}} | ||
} |
This file contains 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