Skip to content

Commit 75b3a55

Browse files
committed
feat: publish more validation modules about kubernetes resources
Signed-off-by: peefy <[email protected]>
1 parent 1aea91f commit 75b3a55

File tree

84 files changed

+599
-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.

84 files changed

+599
-0
lines changed

restrict-ingress-wildcard/README.md

+7

restrict-ingress-wildcard/kcl.mod

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

restrict-ingress-wildcard/kcl.mod.lock

Whitespace-only changes.

restrict-ingress-wildcard/main.k

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"Ingress"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
hosts: [str] = [h for r in item.spec.rules for h in r.host]
9+
assert all host in hosts {
10+
"*" not in host
11+
}, "Wildcards are not permitted as hosts ${hosts}"
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]

restrict-jobs/README.md

+7

restrict-jobs/kcl.mod

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

restrict-jobs/kcl.mod.lock

Whitespace-only changes.

restrict-jobs/main.k

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"Job"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
kinds: [str] = [o.kind for o in item.metadata?.ownerReferences]
9+
assert all kind in kinds {
10+
kind == "CronJob"
11+
}, "Jobs are only allowed if spawned from CronJobs, got kinds ${kinds}"
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]

restrict-load-balancer/README.md

+7

restrict-load-balancer/kcl.mod

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

restrict-load-balancer/kcl.mod.lock

Whitespace-only changes.

restrict-load-balancer/main.k

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KINDS = [
2+
"Service"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
assert item?.spec?.type != "LoadBalance", "Service of type LoadBalancer is not allowed."
9+
item
10+
}
11+
# Validate All resource
12+
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-networkpolicy-empty-podselector"
3+
version = "0.1.0"
4+
description = "`restrict-networkpolicy-empty-podselector` is a KCL validation module"
5+

restrict-networkpolicy-empty-podselector/kcl.mod.lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KINDS = [
2+
"NetworkPolicy"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS and item.metadata.name not in ["default-deny"]:
8+
assert len(item?.spec.podSelector or {}) > 0, "NetworkPolicies must not use an empty podSelector."
9+
item
10+
}
11+
# Validate All resource
12+
items = [validate(i) for i in option("items") or []]

restrict-node-affinity/README.md

+7

restrict-node-affinity/kcl.mod

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

restrict-node-affinity/kcl.mod.lock

Whitespace-only changes.

restrict-node-affinity/main.k

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
assert not item?.spec?.affinity?.nodeAffinity, "Node affinity cannot be used."
9+
item
10+
}
11+
# Validate All resource
12+
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-node-annotation-creation"
3+
version = "0.1.0"
4+
description = "`restrict-node-annotation-creation` is a KCL validation module"
5+

restrict-node-annotation-creation/kcl.mod.lock

Whitespace-only changes.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
KINDS = [
2+
"Node"
3+
]
4+
annotations: [str] = option("params")?.annotations or []
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS and annotations:
9+
set_annotations: {str:str} = item?.metadata?.annotations
10+
assert all l in set_annotations {
11+
l not in annotations
12+
}, "Setting the annotations ${annotations} on a Node is not allowed."
13+
item
14+
}
15+
# Validate All resource
16+
items = [validate(i) for i in option("items") or []]
+7

restrict-node-label-creation/kcl.mod

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

restrict-node-label-creation/kcl.mod.lock

Whitespace-only changes.

restrict-node-label-creation/main.k

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
KINDS = [
2+
"Node"
3+
]
4+
labels: [str] = option("params")?.labels or []
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS and labels:
9+
set_labels: {str:str} = item?.metadata?.labels
10+
assert all l in set_labels {
11+
l not in labels
12+
}, "Setting the labels ${labels} on a Node is not allowed."
13+
item
14+
}
15+
# Validate All resource
16+
items = [validate(i) for i in option("items") or []]

restrict-node-name/README.md

+7

restrict-node-name/kcl.mod

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

restrict-node-name/kcl.mod.lock

Whitespace-only changes.

restrict-node-name/main.k

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
assert not item?.spec?.nodeName, "Setting the nodeName field is prohibited."
9+
item
10+
}
11+
# Validate All resource
12+
items = [validate(i) for i in option("items") or []]

restrict-node-selector/README.md

+7

restrict-node-selector/kcl.mod

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

restrict-node-selector/kcl.mod.lock

Whitespace-only changes.

restrict-node-selector/main.k

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
KINDS = [
2+
"Pod"
3+
]
4+
5+
# Define the validation function
6+
validate = lambda item: {str:} {
7+
if item?.kind in KINDS:
8+
assert not item?.spec?.nodeSelector, "Setting the nodeSelector field is prohibited."
9+
item
10+
}
11+
# Validate All resource
12+
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-role-wildcard-resources"
3+
version = "0.1.0"
4+
description = "`restrict-role-wildcard-resources` is a KCL validation module"
5+

restrict-role-wildcard-resources/kcl.mod.lock

Whitespace-only changes.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"Role"
3+
"ClusterRole"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS:
9+
assert all r in item.rules {
10+
"*" not in r.resources
11+
}, "Use of a wildcard ('*') in any resources is forbidden."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]
+7

restrict-role-wildcard-verbs/kcl.mod

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

restrict-role-wildcard-verbs/kcl.mod.lock

Whitespace-only changes.

restrict-role-wildcard-verbs/main.k

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
KINDS = [
2+
"Role"
3+
"ClusterRole"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS:
9+
assert all r in item.rules {
10+
"*" not in r.verbs
11+
}, "Use of a wildcard ('*') in any verbs is forbidden."
12+
item
13+
}
14+
# Validate All resource
15+
items = [validate(i) for i in option("items") or []]

restrict-scale/README.md

+7

restrict-scale/kcl.mod

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

restrict-scale/kcl.mod.lock

Whitespace-only changes.

restrict-scale/main.k

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
KINDS = [
2+
"Deployment"
3+
]
4+
5+
replicas: int = option("params")?.replicas or 5
6+
7+
# Define the validation function
8+
validate = lambda item: {str:} {
9+
if item?.kind in KINDS:
10+
assert (item.spec?.replicas or 0) <= replicas, "The replica count for this Deployment may not exceed ${replicas}."
11+
item
12+
}
13+
# Validate All resource
14+
items = [validate(i) for i in option("items") or []]

restrict-secret-role-verbs/README.md

+7

restrict-secret-role-verbs/kcl.mod

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

restrict-secret-role-verbs/kcl.mod.lock

Whitespace-only changes.

restrict-secret-role-verbs/main.k

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
KINDS = [
2+
"Role"
3+
"ClusterRole"
4+
]
5+
6+
# Define the validation function
7+
validate = lambda item: {str:} {
8+
if item?.kind in KINDS:
9+
verbs = [v for r in item.rules for v in r.verbs or [] if "secrets" in r.resources]
10+
assert all verb in verbs {
11+
verb not in ["get", "list", "watch"]
12+
}, "Requesting verbs `get`, `list`, or `watch` on Secrets is forbidden."
13+
item
14+
}
15+
# Validate All resource
16+
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-secrets-from-env-from"
3+
version = "0.1.0"
4+
description = "`restrict-secrets-from-env-from` is a KCL validation module"
5+

restrict-secrets-from-env-from/kcl.mod.lock

Whitespace-only changes.

0 commit comments

Comments
 (0)