-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from epasham/main
added policy library and included sample policies
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apiVersion: policy.jspolicy.com/v1beta1 | ||
kind: JsPolicy | ||
metadata: | ||
name: "allow-trusted-registries.infy.com" | ||
spec: | ||
type: Validating | ||
operations: ["CREATE", "UPDATE"] | ||
resources: ["pods", "deployments", "daemonsets", "statefulsets"] | ||
javascript: | | ||
const registries = ["registry.k8s.io", "gcr.io"] | ||
// Use template.spec if defined (for Deployments and StatefulSets), or use spec otherwise (for Pods) | ||
podSpec = request.object?.spec?.template?.spec || request.object?.spec | ||
podSpec?.containers?.forEach(function(container, index) { | ||
if (!registries.includes(container.image.split('/')[0])) { | ||
deny("Field spec.containers[" + index + "].image must be pulled from " + registries.toString()) | ||
} | ||
}) | ||
podSpec?.initContainers?.forEach(function(initContainer, index) { | ||
let imageRegistry = initContainer.image.split('/')[0] | ||
if (!registries.includes(initContainer.image.split('/')[0])) { | ||
errors.push("Field spec.initContainers[" + index + "].image must match regex: " + registries.toString()) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: policy.jspolicy.com/v1beta1 | ||
kind: JsPolicy | ||
metadata: | ||
name: "deny-service-type-loadbalancer.example.com" | ||
spec: | ||
operations: ["CREATE", "UPDATE"] | ||
resources: ["services"] | ||
javascript: | | ||
// This policy blocks Service of type LoadBalancer | ||
if (request.object.spec.type === "LoadBalancer") { | ||
deny(`${request.name} => service type ${request.object.spec.type} is not allowed!`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: policy.jspolicy.com/v1beta1 | ||
kind: JsPolicy | ||
metadata: | ||
name: "deny-service-type-nodeport.infy.com" | ||
spec: | ||
operations: ["CREATE", "UPDATE"] | ||
resources: ["services"] | ||
javascript: | | ||
// This policy blocks Service of type NodePort | ||
if (request.object.spec.type === "NodePort") { | ||
deny(`${request.name} => service type ${request.object.spec.type} is not allowed!`); | ||
} |