running.rego 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package pod.running
  2. import future.keywords.contains
  3. import future.keywords.every
  4. import future.keywords.if
  5. import future.keywords.in
  6. # TODO: this file needs a lot of work to capture all pod statuses and container statuses.
  7. # It currently only checks if a pod is in a "Running" status and if all containers are in
  8. # running status.
  9. POLICY_ID := "pod_running"
  10. POLICY_VERSION := "v0.0.1"
  11. POLICY_SEVERITY := "high"
  12. POLICY_TITLE := sprintf("Pod %s in namespace %s should be running", [input.metadata.name, input.metadata.namespace])
  13. POLICY_SUCCESS_MESSAGE := sprintf("Success: pod is running", [])
  14. allow if {
  15. input.status.phase == "Running"
  16. every containerStatus in input.status.containerStatuses {
  17. containerStatus.state.running
  18. }
  19. }
  20. FAILURE_MESSAGE contains msg1 if {
  21. input.status.phase != "Running"
  22. msg1 := sprintf("Pod %s does not have a Running status", [input.metadata.name])
  23. }
  24. FAILURE_MESSAGE contains msg2 if {
  25. some containerStatus in input.status.containerStatuses
  26. not containerStatus.state.running
  27. msg2 := sprintf("Container %s in pod %s is not running", [containerStatus.name, input.metadata.name])
  28. }