Skip to content

Commit

Permalink
chore: Update dependencies and add Kyverno policies for Pod validation
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliagranato committed Aug 26, 2024
1 parent caa732b commit 1c91929
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/chainguard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
run: |
wget https://github.com/chainguard-dev/melange/releases/download/v0.11.2/melange_0.11.2_linux_386.tar.gz
tar -xzf melange_0.11.2_linux_386.tar.gz
cd melange_0.11.2_linux_386
sudo mv melange /usr/local/bin/
melange version
Expand All @@ -36,6 +37,7 @@ jobs:
run: |
wget https://github.com/chainguard-dev/apko/releases/download/v0.14.7/apko_0.14.7_linux_386.tar.gz
tar -xzf apko_0.14.7_linux_386.tar.gz
cd apko_0.14.7_linux_386
sudo mv apko /usr/local/bin/
apko version
Expand Down
2 changes: 1 addition & 1 deletion kyverno/disallow-latest-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
policies.kyverno.io/subject: Pod
policies.kyverno.io/description: "The ':latest' tag is mutable and can lead to unexpected errors if the image changes. A best practice is to use an immutable tag that maps to a specific version of an application Pod. This policy validates that the image specifies a tag and that it is not called `latest`. "
spec:
validationFailureAction: audit
validationFailureAction: Audit
background: true
rules:
- name: require-image-tag
Expand Down
18 changes: 18 additions & 0 deletions kyverno/no-root-containers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: no-root-containers
spec:
rules:
- name: require-non-root
match:
resources:
kinds:
- Pod
validate:
message: "Containers must not run as root"
pattern:
spec:
containers:
- securityContext:
runAsNonRoot: true
19 changes: 19 additions & 0 deletions kyverno/require-labels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-labels
spec:
validationFailureAction: Audit
rules:
- name: check-for-labels
match:
any:
- resources:
kinds:
- Pod
validate:
message: "label 'app' is required"
pattern:
metadata:
labels:
app: "?*"
32 changes: 32 additions & 0 deletions kyverno/require-requests-limits.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-requests-limits
annotations:
policies.kyverno.io/title: Require Limits and Requests
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod
policies.kyverno.io/minversion: 1.6.0
policies.kyverno.io/description: >-
As application workloads share cluster resources, it is important to limit resources requested and consumed by each Pod. It is recommended to require resource requests and limits per Pod, especially for memory and CPU. If a Namespace level request or limit is specified, defaults will automatically be applied to each Pod based on the LimitRange configuration. This policy validates that all containers have something specified for memory and CPU requests and memory limits.
spec:
validationFailureAction: Audit
background: true
rules:
- name: validate-resources
match:
any:
- resources:
kinds:
- Pod
validate:
message: "CPU and memory resource requests and limits are required."
pattern:
spec:
containers:
- resources:
requests:
memory: "?*"
cpu: "?*"
limits:
memory: "?*"

0 comments on commit 1c91929

Please sign in to comment.