package main
# Single-file check
deny contains msg if {
input.kind == "Deployment"
not input.spec.template.spec.securityContext.runAsNonRoot
msg := sprintf("Deployment %s must run as non-root", [input.metadata.name])
}
# Cross-file check (requires --combine)
deny contains msg if {
some i
input[i].contents.kind == "Deployment"
deploy := input[i].contents
not has_matching_service(deploy)
msg := sprintf("Deployment %s has no matching Service", [deploy.metadata.name])
}
has_matching_service(deploy) if {
some j
input[j].contents.kind == "Service"
input[j].contents.spec.selector.app == deploy.spec.selector.matchLabels.app
}