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.
99
Quality
Pending
Does it follow best practices?
Impact
99%
1.19xAverage score across 31 eval scenarios
Pending
The risk profile of this skill
This document covers Regal rules related to how default values are declared and used.
Relevant Regal rules:
default-over-else — use default rule := value instead of an else branch for fallback valuesdefault-over-not — use default rule := false instead of rule := false if { not other_rule }trailing-default-rule — place default declarations at the top of the rule group, not at the bottomdefault rule := valueUse default to declare fallback values. Declare the default before the conditional rules in the file.
package rate.limiting
import rego.v1
# CORRECT: default at top, conditional overrides below
default user_limit := 10
user_limit := 1000 if data.user_tiers[input.user] == "premium"
user_limit := 100 if data.user_tiers[input.user] == "standard"# WRONG: trailing default (trailing-default-rule violation)
user_limit := 1000 if data.user_tiers[input.user] == "premium"
user_limit := 100 if data.user_tiers[input.user] == "standard"
default user_limit := 10default instead of elsePrefer default rule := false over an else branch for simple fallbacks.
# CORRECT: use default
default allow := false
allow if {
input.role == "admin"
}# WRONG: else branch for fallback (default-over-else violation)
allow if {
input.role == "admin"
} else := falsedefault instead of negationPrefer default rule := false over explicitly checking not other_rule.
# CORRECT: use default
default allow := false
allow if input.role == "admin"# WRONG: negation to set false (default-over-not violation)
allow if input.role == "admin"
allow := false if not allowWhen a rule has multiple conditional values and a fallback, the default is always the fallback:
package api.limits
import rego.v1
# Fallback declared first
default max_requests := 100
# Overrides for specific tiers
max_requests := 10000 if data.tiers[input.user_id] == "enterprise"
max_requests := 1000 if data.tiers[input.user_id] == "pro"Test both the default case and each override:
package api.limits_test
import rego.v1
import data.api.limits
test_default_limit if {
limits.max_requests == 100 with data.tiers as {}
}
test_pro_limit if {
limits.max_requests == 1000 with input as {"user_id": "alice"}
with data.tiers as {"alice": "pro"}
}
test_enterprise_limit if {
limits.max_requests == 10000 with input as {"user_id": "corp"}
with data.tiers as {"corp": "enterprise"}
}docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
scenario-15
scenario-16
scenario-17
scenario-18
scenario-19
scenario-20
scenario-21
scenario-22
scenario-23
scenario-24
scenario-25
scenario-26
scenario-27
scenario-28
scenario-29
scenario-30
scenario-31