Skip to content

Commit 4296f88

Browse files
authored
Merge pull request #87 from Peefy/publish-more-validation-modules
feat: publish more validation modules
2 parents e70d18b + 30e1d99 commit 4296f88

File tree

77 files changed

+500
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+500
-0
lines changed

disallow-anonymous/kcl.mod

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
name = "disallow-anonymous"
33
version = "0.1.0"
44
description = "`disallow-anonymous` is a kcl validation package"
5+

disallow-anonymous/kcl.mod.lock

Whitespace-only changes.

k8s/1.18/kcl.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ name = "k8s"
33
edition = "*"
44
version = "1.18"
55
description = "`k8s` is a KCL module contains all the built-in Kubernetes resource models (the CRDs are not included here)."
6+

psp-app-armor/kcl.mod

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
name = "psp-app-armor"
33
version = "0.1.0"
44
description = "`psp-app-armor` is a kcl validation package"
5+

psp-app-armor/kcl.mod.lock

Whitespace-only changes.

restrict-automount-sa-token/README.md

+7

restrict-automount-sa-token/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-automount-sa-token"
3+
version = "0.1.1"
4+
description = "`restrict-automount-sa-token` is a KCL validation module"
5+

restrict-automount-sa-token/kcl.mod.lock

Whitespace-only changes.

restrict-automount-sa-token/main.k

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
annotations: {str:str} = item.metadata.annotations
9+
assert item?.spec?.automountServiceAccountToken not in ["true"], "Auto-mounting of Service Account tokens is not allowed."
10+
item
11+
}
12+
# Validate All resource
13+
items = [validate(i) for i in option("items") or []]
+7

restrict-binding-clusteradmin/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-binding-clusteradmin"
3+
version = "0.1.1"
4+
description = "`restrict-binding-clusteradmin` is a KCL validation module"
5+

restrict-binding-clusteradmin/kcl.mod.lock

Whitespace-only changes.

restrict-binding-clusteradmin/main.k

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
KINDS = [
2+
"RoleBinding"
3+
"ClusterRoleBinding"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS:
9+
assert item?.roleRef != "cluster-admin", "Binding to cluster-admin is not allowed."
10+
item
11+
}
12+
# Validate All resource
13+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-binding-system-group-restrict-anonymous"
3+
version = "0.1.1"
4+
description = "`restrict-binding-system-group-restrict-anonymous` is a KCL validation module"
5+

restrict-binding-system-group-restrict-anonymous/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"RoleBinding"
3+
"ClusterRoleBinding"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS and item?.subjects:
9+
assert all s in item.subjects {
10+
s.name != "system:anonymous"
11+
}, "Binding to system:anonymous is not allowed."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-binding-system-group-restrict-masters"
3+
version = "0.1.1"
4+
description = "`restrict-binding-system-group-restrict-masters` is a KCL validation module"
5+

restrict-binding-system-group-restrict-masters/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"RoleBinding"
3+
"ClusterRoleBinding"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS and item?.subjects:
9+
assert all s in item.subjects {
10+
s.name != "system:masters"
11+
}, "Binding to system:masters is not allowed."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-binding-system-group-restrict-subject-name"
3+
version = "0.1.1"
4+
description = "`restrict-binding-system-group-restrict-subject-name` is a KCL validation module"
5+

restrict-binding-system-group-restrict-subject-name/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
KINDS = [
2+
"RoleBinding"
3+
"ClusterRoleBinding"
4+
]
5+
names: [str] = option("params")?.names or []
6+
7+
# Define the validation function
8+
validate = lambda item: {str:} {
9+
if item?.kind in KINDS and item?.subjects:
10+
assert all s in item.subjects {
11+
s.name not in names
12+
}, "Binding to ${names} is not allowed."
13+
item
14+
}
15+
# Validate All resource
16+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-binding-system-group-restrict-unauthenticated"
3+
version = "0.1.1"
4+
description = "`restrict-binding-system-group-restrict-unauthenticated` is a KCL validation module"
5+

restrict-binding-system-group-restrict-unauthenticated/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"RoleBinding"
3+
"ClusterRoleBinding"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS and item?.subjects:
9+
assert all s in item.subjects {
10+
s.name != "system:unauthenticated"
11+
}, "Binding to system:unauthenticated is not allowed."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-clusterrole-nodesproxy"
3+
version = "0.1.1"
4+
description = "`restrict-clusterrole-nodesproxy` is a KCL validation module"
5+

restrict-clusterrole-nodesproxy/kcl.mod.lock

Whitespace-only changes.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"ClusterRole"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
resources = [res for r in item.rules for res in r.resources]
9+
assert all res in resources {
10+
res not in ["nodes/proxy"]
11+
}, "A ClusterRole containing the nodes/proxy resource is not allowed."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-control-plane-scheduling-control-plane"
3+
version = "0.1.1"
4+
description = "`restrict-control-plane-scheduling-control-plane` is a KCL validation module"
5+

restrict-control-plane-scheduling-control-plane/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
keys = [key for t in item.spec.tolerations for key in t.key]
9+
assert all key in keys {
10+
key not in ["node-role.kubernetes.io/control-plane"]
11+
}, "Pods may not use tolerations which schedule on control plane nodes."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-control-plane-scheduling-master"
3+
version = "0.1.1"
4+
description = "`restrict-control-plane-scheduling-master` is a KCL validation module"
5+

restrict-control-plane-scheduling-master/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
keys = [key for t in item.spec.tolerations for key in t.key]
9+
assert all key in keys {
10+
key not in ["node-role.kubernetes.io/master"]
11+
}, "Pods may not use tolerations which schedule on masters nodes."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-control-plane-scheduling-nodes"
3+
version = "0.1.1"
4+
description = "`restrict-control-plane-scheduling-nodes` is a KCL validation module"
5+

restrict-control-plane-scheduling-nodes/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
nodes: [str] = option("params")?.nodes or []
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS:
9+
keys = [key for t in item.spec.tolerations for key in t.key]
10+
assert all key in keys {
11+
key not in nodes
12+
}, "Pods may not use tolerations which schedule on nodes ${nodes}."
13+
item
14+
}
15+
# Validate All resource
16+
items = [validate(i) for i in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-deprecated-k8s-gcr-io-registry"
3+
version = "0.1.1"
4+
description = "`restrict-deprecated-k8s-gcr-io-registry` is a KCL validation module"
5+

restrict-deprecated-k8s-gcr-io-registry/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
get_containers = lambda item: {str:} {
2+
containers = []
3+
if item.kind == "Pod":
4+
containers = (item.spec.containers or []) + (item.spec.initContainers or []) + (item.spec.ephemeralContainers or [])
5+
elif item.kind == "Deployment":
6+
containers = (item.spec.template.spec.containers or []) + (item.spec.template.spec.initContainers or []) + (item.spec.template.spec.ephemeralContainers or [])
7+
containers = [c for c in containers]
8+
}
9+
10+
# Define the validation function
11+
validate = lambda item: {str:} {
12+
containers = get_containers(item)
13+
if containers:
14+
assert all c in containers {
15+
not c.image.startswith("k8s.gcr.io/")
16+
}, "The \"k8s.gcr.io\" image registry is deprecated. \"registry.k8s.io\" should now be used."
17+
item
18+
}
19+
# Validate All resource
20+
items = [validate(i) for i in option("items") or []]
+7
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "restrict-deprecated-registries"
3+
version = "0.1.1"
4+
description = "`restrict-deprecated-registries` is a KCL validation module"
5+

restrict-deprecated-registries/kcl.mod.lock

Whitespace-only changes.

restrict-deprecated-registries/main.k

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
registries: [str] = option("registries")?.nodes or []
2+
3+
get_containers = lambda item: {str:} {
4+
containers = []
5+
if item.kind == "Pod":
6+
containers = (item.spec.containers or []) + (item.spec.initContainers or []) + (item.spec.ephemeralContainers or [])
7+
elif item.kind == "Deployment":
8+
containers = (item.spec.template.spec.containers or []) + (item.spec.template.spec.initContainers or []) + (item.spec.template.spec.ephemeralContainers or [])
9+
containers = [c for c in containers]
10+
}
11+
12+
# Define the validation function
13+
validate = lambda item: {str:} {
14+
containers = get_containers(item)
15+
if containers and registries:
16+
assert all c in containers {
17+
all r in registries {
18+
not c.image.startswith(r)
19+
}
20+
}, "The image registries ${registries} are deprecated."
21+
item
22+
}
23+
# Validate All resource
24+
items = [validate(i) for i in option("items") or []]

restrict-edit-for-endpoints/README.md

+7

0 commit comments

Comments
 (0)