Rego is the declarative policy language used by Open Policy Agent (OPA). This tile covers writing and testing Rego policies for Kubernetes admission control, Terraform and infrastructure-as-code plan validation, Docker container authorization, HTTP API authorization, RBAC and role-based access control, data filtering, metadata annotations with opa inspect, and OPA policy testing with opa test.
96
94%
Does it follow best practices?
Impact
97%
1.18xAverage score across 32 eval scenarios
Low
Low-risk findings worth noting
_test.rego filename suffix
100%
100%
test_ function prefix
100%
100%
positive and negative test cases
100%
100%
tests pass
80%
100%
import rego.v1
100%
100%
default allow := false
100%
100%
Reads roles from JWT claims
100%
100%
Reads role grants from data
100%
100%
Nested iteration with some
100%
100%
Permission match on action and resource_type
100%
100%
Tests pass
100%
100%
import rego.v1
0%
100%
Partial set rule for violations
85%
100%
Iterates over conflicting pairs with array-of-arrays membership
57%
100%
Reads user roles from data
100%
100%
Tests pass
100%
100%
import rego.v1
100%
100%
default allow := false
100%
100%
JWT decoded with io.jwt.decode
100%
100%
Matches on input.method and input.path
100%
100%
Allow self and manager access
100%
100%
Tests pass
100%
100%
These are not visible to scoring or included in the download.
/home/agent/opa
_test.rego filename suffix
100%
100%
test_ function prefix
100%
100%
positive and negative test cases
100%
100%
tests pass
100%
100%
import rego.v1
0%
100%
Default rule value for fallback limit
0%
100%
Per-tier limit lookup
100%
100%
Tests pass
72%
100%
import rego.v1
0%
100%
Set subtraction to detect unknown fields
25%
100%
Checks for required fields
100%
100%
Tests pass
80%
100%
deny contains msg pattern
100%
100%
Checks input.request.kind.kind
100%
100%
Deny rule for privileged containers
100%
100%
Tests pass
100%
100%
_test.rego filename suffix
100%
100%
test_ function prefix
100%
100%
positive and negative test cases
100%
100%
tests pass
0%
100%
violation contains msg pattern
100%
100%
Uses input.review.object
100%
100%
Uses input.parameters for required labels
100%
100%
Tests pass
15%
100%
package has METADATA block with title and description
100%
100%
package has authors or organizations
0%
100%
decision rules have METADATA with title and description
100%
100%
decision rules have entrypoint: true
0%
100%
rules have custom fields
100%
100%
Tests pass
100%
100%
import rego.v1
100%
100%
METADATA block with custom.severity
100%
100%
Uses rego.metadata.rule() at runtime
100%
57%
Violation is a structured object with severity
100%
40%
Tests pass
90%
0%
Package-level metadata annotation
60%
100%
`allow` rule annotated with `entrypoint: true`
50%
100%
No blank lines between metadata and rule
0%
100%
Tests pass
32%
88%
Incremental violations set using `contains`
100%
100%
Boolean allow rule referencing violations
50%
100%
Checks for privileged and missing limits
100%
100%
Tests pass
0%
100%
Uses `in` for membership check (not `!=` in a loop)
100%
100%
sprintf argument count matches format string
100%
100%
Checks for restricted name and missing annotation
100%
100%
Tests pass
100%
100%
These are not visible to scoring or included in the download.
/home/agent/go/bin/opa
/home/agent/go/pkg/mod/cache/download/github.com/agnivade/levenshtein/@v/list
/home/agent/go/pkg/mod/cache/download/github.com/agnivade/levenshtein/@v/v1.2.1.info
/home/agent/go/pkg/mod/cache/download/github.com/agnivade/levenshtein/@v/v1.2.1.lock
/home/agent/go/pkg/mod/cache/download/github.com/agnivade/levenshtein/@v/v1.2.1.mod
Uses `object.keys()` for provided tags
100%
100%
Set subtraction for missing tags
100%
100%
deny contains msg with sprintf
100%
100%
Tests pass
92%
100%
default declaration at the top
100%
100%
Conditional overrides for each tier
100%
100%
No else branches for fallback
100%
100%
Tests pass
0%
100%
Helper functions take explicit container argument
100%
100%
Separate helpers for privileged and resource limit checks
100%
100%
deny contains msg pattern with container name
53%
100%
Tests pass
0%
100%
Imports the package, not individual rules
100%
100%
No redundant aliases
100%
100%
All imports before rules
100%
100%
Tests pass
100%
100%
These are not visible to scoring or included in the download.
/home/agent/opa
Uses `some ... in` for iteration
100%
100%
Checks each container image against approved registry
100%
100%
deny contains msg pattern
100%
100%
Tests pass
100%
100%
These are not visible to scoring or included in the download.
/home/agent/opa
Uses `in` operator for membership check
0%
100%
Looks up allowed departments from data
100%
100%
import rego.v1 and default allow := false
100%
100%
Tests pass
100%
100%
snake_case for all identifiers
100%
100%
No get_ or list_ prefix on rule names
100%
0%
No package path repetition in rule names
100%
100%
Tests pass
100%
100%
These are not visible to scoring or included in the download.
/home/agent/opa
Test file named `authz_test.rego` with `_test` package suffix
100%
100%
Policy package imported and rules referenced via alias
100%
100%
Unique descriptive test names
100%
100%
Tests pass
100%
100%
main response object
100%
100%
Uppercase action strings and CloudFormation input structure
40%
100%
Helper rules for conditions
13%
100%
Three deny rules covering AccessControl and both BlockPublic settings
100%
100%
Tests pass
92%
100%
import rego.v1
0%
100%
object.get input normalization
0%
100%
Tests pass
100%
100%
_test.rego filename suffix
100%
100%
mocks Terraform plan input with `with input as`
100%
100%
includes both positive and negative test cases
100%
100%
tests pass
100%
100%
Uses walk() built-in
100%
100%
Collects resources from all modules
80%
100%
Deny rule for HTTP in description
100%
100%
Tests pass
92%
100%
These are not visible to scoring or included in the download.
/home/agent/opa
Provider region check via configuration path
100%
100%
EU data residency deny rule
100%
100%
has_replication helper with multiple function heads
100%
100%
Tests pass
100%
100%
Deny when capabilities block is absent (empty list)
100%
100%
Deny when drop does not include ALL
100%
100%
Capabilities read as a list, not an object
100%
100%
Tests use the real list-shaped mock, not a bare-object mock
100%
100%
action != delete exclusion pattern
21%
43%
supports_tags helper
100%
88%
Safe tag access with object.get
100%
100%
Deny for missing and empty tags
33%
100%
Tests pass
100%
100%
Deny on aws_s3_bucket without inline encryption
100%
100%
Deny on separate encryption resource with invalid algorithm
100%
100%
Helper function for algorithm validation
52%
100%
Tests pass
100%
100%
Checks create and update actions
100%
100%
Deny on aws_s3_bucket without versioning enabled
100%
100%
Deny on separate versioning resource with wrong status
83%
100%
Tests pass
100%
100%
Table of Contents