Skip to content

Commit 417cef2

Browse files
committed
feat: add all model source code on github packages
Signed-off-by: peefy <[email protected]>
1 parent 1cfe236 commit 417cef2

File tree

271 files changed

+5043
-4
lines changed

Some content is hidden

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

271 files changed

+5043
-4
lines changed

.gitignore

+17-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1-
.vscode/
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
vendor/
16+
.kclvm
17+
.DS_store

add-app-armor-annotation/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Introduction
2+
3+
`add-app-armor-annotation` is a kcl mutation package, which can be used to add apparmor annotations for the Kubernetes resources.
4+
5+
In the earlier Pod Security Policy controller, it was possible to define
6+
a setting which would enable AppArmor for all the containers within a Pod so
7+
they may be assigned the desired profile. Assigning an AppArmor profile, accomplished
8+
via an annotation, is useful in that it allows secure defaults to be defined and may
9+
also result in passing other validation rules such as those in the Pod Security Standards.
10+
This policy mutates Pods to add an annotation for every container to enabled AppArmor
11+
at the runtime/default level.
12+
13+
The KCL code is as follows:
14+
15+
```python
16+
capabilities: [str] = option("params")?.capabilities or ["SETUID", "SETFCAP"]
17+
items = [item | {
18+
if item.kind == "Pod":
19+
spec.containers: [{
20+
metadata.annotations: {
21+
"container.apparmor.security.beta.kubernetes.io/${container.name}": "runtime/default"
22+
}
23+
} for container in item.spec.containers]
24+
} for item in option("items") or []]
25+
```
26+
27+
## How to Use
28+
29+
Add the source into your `KCLRun` resource and use the [kubectl kcl plugin](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kubectl-kcl-plugin) or the [kcl operator](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator) to integrate this model.
30+
31+
```yaml
32+
apiVersion: krm.kcl.dev/v1alpha1
33+
kind: KCLRun
34+
metadata:
35+
name: add-app-armor-annotation
36+
spec:
37+
source: oci://ghcr.io/kcl-lang/add-app-armor-annotation
38+
```

add-app-armor-annotation/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-app-armor-annotation"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-app-armor-annotation` is a kcl mutation package, which can be used to add apparmor annotations for the Kubernetes resources."

add-app-armor-annotation/main.k

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
capabilities: [str] = option("params")?.capabilities or ["SETUID", "SETFCAP"]
2+
items = [item | {
3+
if item.kind == "Pod":
4+
spec.containers: [{
5+
metadata.annotations: {
6+
"container.apparmor.security.beta.kubernetes.io/${container.name}": "runtime/default"
7+
}
8+
} for container in item.spec.containers]
9+
} for item in option("items") or []]
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: krm.kcl.dev/v1alpha1
2+
kind: KCLRun
3+
metadata:
4+
name: add-app-armor-annotation
5+
annotations:
6+
krm.kcl.dev/version: 0.0.1
7+
krm.kcl.dev/type: mutation
8+
documentation: >-
9+
In the earlier Pod Security Policy controller, it was possible to define
10+
a setting which would enable AppArmor for all the containers within a Pod so
11+
they may be assigned the desired profile. Assigning an AppArmor profile, accomplished
12+
via an annotation, is useful in that it allows secure defaults to be defined and may
13+
also result in passing other validation rules such as those in the Pod Security Standards.
14+
This policy mutates Pods to add an annotation for every container to enabled AppArmor
15+
at the runtime/default level.
16+
spec:
17+
source: ./examples/mutation/add-app-armor-annotation/main.k
18+
---
19+
apiVersion: v1
20+
kind: Pod
21+
metadata:
22+
name: nginx
23+
spec:
24+
containers:
25+
- name: nginx
26+
image: nginx:1.14.2
27+
ports:
28+
- containerPort: 80

add-capabilities/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Introduction
2+
3+
`add-capabilities` is a kcl mutation package.
4+
5+
## How to Use
6+
7+
Add the source into your `KCLRun` resource and use the [kubectl kcl plugin](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kubectl-kcl-plugin) or the [kcl operator](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator) to integrate this model.
8+
9+
```yaml
10+
apiVersion: krm.kcl.dev/v1alpha1
11+
kind: KCLRun
12+
metadata:
13+
name: add-capabilities
14+
spec:
15+
source: oci://ghcr.io/kcl-lang/add-capabilities
16+
```

add-capabilities/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-capabilities"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-capabilities` is a kcl mutation package."

add-capabilities/main.k

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
capabilities: [str] = option("params")?.capabilities or ["SETUID", "SETFCAP"]
2+
items = [item | {
3+
if item.kind == "Pod":
4+
spec.containers: [{
5+
"securityContext": {"capabilities": {"add" += [c] if c not in (container?.securityContext?.capabilities?.drop or []) else [] for c in capabilities}}
6+
} for container in item.spec.containers]
7+
} for item in option("items") or []]

add-capabilities/suite/good.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: krm.kcl.dev/v1alpha1
2+
kind: KCLRun
3+
metadata:
4+
name: add-capabilities
5+
annotations:
6+
krm.kcl.dev/version: 0.0.1
7+
krm.kcl.dev/type: mutation
8+
documentation: >-
9+
In the earlier Pod Security Policy controller, it was possible to configure a policy
10+
to add capabilities to containers within a Pod. This made it easier to assign some basic defaults
11+
rather than blocking Pods or to simply provide capabilities for certain workloads if not specified.
12+
This policy mutates Pods to add the capabilities SETFCAP and SETUID so long as they are not listed
13+
as dropped capabilities first.
14+
spec:
15+
source: ./examples/mutation/add-capabilities/main.k
16+
---
17+
apiVersion: v1
18+
kind: Pod
19+
metadata:
20+
name: nginx
21+
spec:
22+
containers:
23+
- name: nginx
24+
image: nginx:1.14.2
25+
ports:
26+
- containerPort: 80

add-certificates-volume/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Introduction
2+
3+
`add-certificates-volume` is a kcl mutation package.
4+
5+
## How to Use
6+
7+
Add the source into your `KCLRun` resource and use the [kubectl kcl plugin](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kubectl-kcl-plugin) or the [kcl operator](https://kcl-lang.io/docs/user_docs/guides/working-with-k8s/mutate-manifests/kcl-operator) to integrate this model.
8+
9+
```yaml
10+
apiVersion: krm.kcl.dev/v1alpha1
11+
kind: KCLRun
12+
metadata:
13+
name: add-certificates-volume
14+
spec:
15+
source: oci://ghcr.io/kcl-lang/add-certificates-volume
16+
```

add-certificates-volume/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-certificates-volume"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-certificates-volume` is a kcl mutation package."

add-certificates-volume/main.k

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
items = [item | {
2+
if item.kind == "Pod":
3+
spec.volumes += [{
4+
name = "etc-ssl-certs"
5+
configMap.name = "ca-pemstore"
6+
}]
7+
spec.containers: [{
8+
volumeMounts += [{
9+
name = "etc-ssl-certs"
10+
mountPath = "/etc/ssl/certs"
11+
}]
12+
} for container in item.spec.containers]
13+
} for item in option("items") or []]
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: krm.kcl.dev/v1alpha1
2+
kind: KCLRun
3+
metadata:
4+
name: add-certificates-volume
5+
annotations:
6+
krm.kcl.dev/version: 0.0.1
7+
krm.kcl.dev/type: mutation
8+
documentation: >-
9+
In some cases you would need to trust custom CA certificates for all the containers of a Pod.
10+
It makes sense to be in a ConfigMap so that you can automount them by only setting an annotation.
11+
This policy adds a volume to all containers in a Pod containing the certificate if the annotation
12+
called `inject-certs` with value `enabled` is found.
13+
spec:
14+
source: ./examples/mutation/add-certificates-volume/main.k
15+
---
16+
apiVersion: v1
17+
kind: Pod
18+
metadata:
19+
name: nginx
20+
annotations:
21+
inject-certs: "enabled"
22+
spec:
23+
containers:
24+
- name: nginx
25+
image: nginx:1.14.2
26+
ports:
27+
- containerPort: 80

add-default-resources/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Introduction
2+
3+
## Resource
4+
5+
Code source and document is [here](https://github.com/kcl-lang/artifacthub/tree/main/add-default-resources)

add-default-resources/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-default-resources"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-default-resources` is a kcl mutation package"

add-default-resources/main.k

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
items = [item | {
2+
if item.kind == "Pod":
3+
spec.containers: [{
4+
resources.requests: {
5+
memory = "100Mi"
6+
cpu = "100m"
7+
}
8+
} for container in item.spec.containers]
9+
} for item in option("items") or []]

add-default-resources/suite/good.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: krm.kcl.dev/v1alpha1
2+
kind: KCLRun
3+
metadata:
4+
name: add-default-resources
5+
annotations:
6+
krm.kcl.dev/version: 0.0.1
7+
krm.kcl.dev/type: mutation
8+
documentation: >-
9+
Pods which don't specify at least resource requests are assigned a QoS class
10+
of BestEffort which can hog resources for other Pods on Nodes. At a minimum,
11+
all Pods should specify resource requests in order to be labeled as the QoS
12+
class Burstable. This sample mutates any container in a Pod which doesn't
13+
specify memory or cpu requests to apply some sane defaults.
14+
spec:
15+
source: ./examples/mutation/add-default-resources/main.k
16+
---
17+
apiVersion: v1
18+
kind: Pod
19+
metadata:
20+
name: nginx
21+
spec:
22+
containers:
23+
- name: nginx
24+
image: nginx:1.14.2
25+
ports:
26+
- containerPort: 80
27+
- name: kcl
28+
image: kcllang/kcl

add-default-securitycontext/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Introduction
2+
3+
## Resource
4+
5+
Code source and document is [here](https://github.com/kcl-lang/artifacthub/tree/main/add-default-securitycontext)

add-default-securitycontext/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-default-securitycontext"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-default-securitycontext` is a kcl mutation package"

add-default-securitycontext/main.k

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
items = [item | {
2+
if item.kind == "Pod":
3+
spec.securityContext: {
4+
runAsNonRoot = True
5+
runAsUser = 1000
6+
runAsGroup = 3000
7+
fsGroup = 2000
8+
}
9+
} for item in option("items") or []]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: krm.kcl.dev/v1alpha1
2+
kind: KCLRun
3+
metadata:
4+
name: add-default-securitycontext
5+
annotations:
6+
krm.kcl.dev/version: 0.0.1
7+
krm.kcl.dev/type: mutation
8+
documentation: >-
9+
A Pod securityContext entry defines fields such as the user and group which should be used to run the Pod.
10+
Sometimes choosing default values for users rather than blocking is a better alternative to not impede
11+
such Pod definitions. This policy will mutate a Pod to set `runAsNonRoot`, `runAsUser`, `runAsGroup`, and
12+
`fsGroup` fields within the Pod securityContext if they are not already set.
13+
spec:
14+
source: ./examples/mutation/add-default-securitycontext/main.k
15+
---
16+
apiVersion: v1
17+
kind: Pod
18+
metadata:
19+
name: nginx
20+
spec:
21+
containers:
22+
- name: nginx
23+
image: nginx:1.14.2
24+
ports:
25+
- containerPort: 80
26+
- name: kcl
27+
image: kcllang/kcl

add-emptydir-sizelimit/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Introduction
2+
3+
## Resource
4+
5+
Code source and document is [here](https://github.com/kcl-lang/artifacthub/tree/main/add-emptydir-sizelimit)

add-emptydir-sizelimit/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-emptydir-sizelimit"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-emptydir-sizelimit` is a kcl mutation package"

add-emptydir-sizelimit/main.k

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
items = [item | {
2+
if item.kind == "Pod":
3+
spec.volumes: [{
4+
if "emptyDir" in v and (v?.emptyDir?.sizeLimit or "") != "100Mi":
5+
emptyDir.sizeLimit = "100Mi"
6+
} for v in item.spec.volumes or []] or Undefined
7+
} for item in option("items") or []]
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: krm.kcl.dev/v1alpha1
2+
kind: KCLRun
3+
metadata:
4+
name: add-emptydir-sizelimit
5+
annotations:
6+
krm.kcl.dev/version: 0.0.1
7+
krm.kcl.dev/type: mutation
8+
documentation: >-
9+
When a Pod requests an emptyDir, by default it does not have a size limit which
10+
may allow it to consume excess or all of the space in the medium backing the volume.
11+
This can quickly overrun a Node and may result in a denial of service for other
12+
workloads. This policy adds a sizeLimit field to all Pods mounting emptyDir
13+
volumes, if not present, and sets it to 100Mi.
14+
spec:
15+
source: ./examples/mutation/add-emptydir-sizelimit/main.k
16+
---
17+
apiVersion: v1
18+
kind: Pod
19+
metadata:
20+
name: nginx
21+
spec:
22+
containers:
23+
- name: nginx
24+
image: nginx:1.14.2
25+
ports:
26+
- containerPort: 80
27+
- name: kcl
28+
image: kcllang/kcl
29+
volumes:
30+
- emptyDir: {}
31+
name: wordpress-persistent-storage

add-image-as-env-var/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Introduction
2+
3+
## Resource
4+
5+
Code source and document is [here](https://github.com/kcl-lang/artifacthub/tree/main/add-image-as-env-var)

add-image-as-env-var/kcl.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "add-image-as-env-var"
3+
edition = "*"
4+
version = "0.1.0"
5+
description = "`add-image-as-env-var` is a kcl mutation package"

0 commit comments

Comments
 (0)