Create Policy
Create Policy



######
#IF
# application named "sampleapp"
# deploying to an account "production"
# THEN
# The image, if present MUST start with "docker.opsmx.com"
#
# Other applications/pipelines can be saved without these restrictions
package opa.spinnaker.pipelines.new
deny[msg] {
count(input.new.stages)>0
input.new.application == "sampleapp"
input.new.stages[_].account == "production"
images := input.new.stages[_].manifests[_].spec.template.spec.containers[_].image
not startswith(images, "docker.opsmx.com/")
msg := sprintf("[%v] being deployed to be from docker.opsmx.com", [images])
}# This policy verifies the deployment is not happening during a blackout window.
# The blackout window can be configured by changing hour
package opa.pipelines.datetimeslot
deny["Pipeline has no start time"] {
startTime := input.startTime
startTime == 0
}
weekday {
day := time.weekday(time.now_ns())
day != "Saturday"
day != "Sunday"
}
deny["No deployments allowed between 09am - 04pm on weekdays"] {
[hour, minute, second] := time.clock([time.now_ns(), tz])
tz = "Africa/Lagos"
hour >= 9
hour < 16
weekday
}