expiry_two_weeks.rego 982 B

123456789101112131415161718192021222324252627282930
  1. package certificates.expiry_two_weeks
  2. import future.keywords
  3. POLICY_ID := sprintf("certificates_expiry_two_weeks_%s_%s", [input.metadata.namespace, input.metadata.name])
  4. POLICY_VERSION := "v0.0.1"
  5. POLICY_SEVERITY := "high"
  6. POLICY_TITLE := sprintf("Certificate %s/%s should have longer than 2 weeks left before expiry", [input.metadata.namespace, input.metadata.name])
  7. POLICY_SUCCESS_MESSAGE := sprintf("Success: certificate %s/%s has longer than 2 weeks before expiry", [input.metadata.namespace, input.metadata.name])
  8. allow if {
  9. not rfc3339_expiry_within_2_weeks(input.status.notAfter)
  10. }
  11. FAILURE_MESSAGE contains msg if {
  12. rfc3339_expiry_within_2_weeks(input.status.notAfter)
  13. msg := sprintf("Certificate expires at %s, which is less than 2 weeks from now", [input.status.notAfter])
  14. }
  15. rfc3339_lt(a, b) if {
  16. time.parse_rfc3339_ns(a) < time.parse_rfc3339_ns(b)
  17. }
  18. rfc3339_expiry_within_2_weeks(a) if {
  19. time.add_date(time.parse_rfc3339_ns(a), 0, 0, -14) < time.now_ns()
  20. }