-
Notifications
You must be signed in to change notification settings - Fork 14
Examples
Khash Sajadi edited this page Jun 4, 2019
·
1 revision
These are some examples for common use cases of Copper and are provided to help with understanding how to use Copper DSL with Kubernetes configuration files.
rule NoLatest ensure {
fetch("$.spec.template.spec.containers..image")
.as(:image)
.pick(:tag)
.contains("latest") == false
}
rule MySQLVersionCheck ensure {
fetch("$.spec.template.spec.containers[?(@.name == 'mysql')].image")
.first
.as(:image)
.pick(:tag)
.as(:semver)
.satisfies("~> 5.6") == true
}
rule DeploymentFilenamePolicy ensure {
filename.ext == ".yml" and // extension is yml
filename.name == fetch("$[?(@['kind'] == 'Deployment')].metadata.name").first and
filename.path.split("/").last == "deployments"
}
rule LoadBalancerIPInRange ensure {
fetch("$.spec[?(@['type'] == 'LoadBalancer')].loadBalancerIP")
.first
.as(:ipaddress) in ipaddress("232.12.87.0/24")
}
rule NoDefaultNamespace ensure {
fetch("$.metadata.namespace").first == "foobar"
}
rule NoDockerHub ensure {
fetch("$.spec.template.spec.containers..image")
.as(:image)
.pick(:registry)
.contains("index.docker.io") == false
}
rule PrivateRepoOnly ensure {
fetch("$.spec.template.spec.containers..image")
.as(:image)
.pick(:name)
.extract("(.*)\/.*", 1) // image name is in the namespace/name format
.unique == ["acme"]
}