Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent CVE-2024-3177 #1007

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8eeff43
create policy and artifact-pkg
May 14, 2024
97c03e0
make sure we are in Audit mode
May 14, 2024
f0b2ee4
add a date to artifact hub
May 14, 2024
99948ec
Merge branch 'kyverno:main' into secrets-not-from-env-vars-cve-2024-3177
kurktchiev Jun 11, 2024
f980aad
Merge branch 'kyverno:main' into secrets-not-from-env-vars-cve-2024-3177
kurktchiev Jul 23, 2024
e4a8eff
Merge branch 'main' into secrets-not-from-env-vars-cve-2024-3177
kurktchiev Jul 29, 2024
901a4ab
add good and bad objects
Jul 29, 2024
da3cc80
add kube version
Jul 29, 2024
127938f
Update other/secrets-not-from-env-vars-cve-2024-3177/secrets-not-from…
kurktchiev Jul 31, 2024
aa97eb2
Update other/secrets-not-from-env-vars-cve-2024-3177/secrets-not-from…
kurktchiev Jul 31, 2024
d2bc6b3
Update other/secrets-not-from-env-vars-cve-2024-3177/artifacthub-pkg.yml
kurktchiev Jul 31, 2024
1f6690e
Update other/secrets-not-from-env-vars-cve-2024-3177/artifacthub-pkg.yml
kurktchiev Jul 31, 2024
e6b2b27
Update other/secrets-not-from-env-vars-cve-2024-3177/artifacthub-pkg.yml
kurktchiev Jul 31, 2024
55366ac
Merge branch 'main' into secrets-not-from-env-vars-cve-2024-3177
kurktchiev Jul 31, 2024
4cddd5f
Update other/secrets-not-from-env-vars-cve-2024-3177/artifacthub-pkg.yml
kurktchiev Jul 31, 2024
3377269
Update other/secrets-not-from-env-vars-cve-2024-3177/secrets-not-from…
kurktchiev Jul 31, 2024
73f9875
updat edescription
Jul 31, 2024
657be9a
fix suggestions
Jul 31, 2024
203e2f1
update digest
Jul 31, 2024
46ea9ed
Merge branch 'main' into secrets-not-from-env-vars-cve-2024-3177
kurktchiev Aug 6, 2024
6876562
add tests
Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Pod
metadata:
name: bad-pod
annotations:
kubernetes.io/enforce-mountable-secrets: "true"
spec:
containers:
- name: my-container
image: nginx
envFrom:
- secretRef:
name: my-secret
initContainers:
- name: init-container
image: busybox
command: ["sh", "-c", "echo init"]
envFrom:
- secretRef:
name: init-secret
ephemeralContainers:
- name: ephemeral-container
image: busybox
command: ["sh", "-c", "echo ephemeral"]
envFrom:
- secretRef:
name: ephemeral-secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: secrets-not-from-env-vars-cve-2024-3177
ready: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: secrets-not-from-env-vars-cve-2024-3177
spec:
steps:
- name: step-01
try:
- apply:
file: ../secrets-not-from-env-vars-cve-2024-3177.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: secrets-not-from-env-vars-cve-2024-3177
spec:
validationFailureAction: Enforce
- assert:
file: chainsaw-step-01-assert-1.yaml
- name: step-02
try:
- apply:
file: good-pod.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Pod
metadata:
name: good-pod
annotations:
kubernetes.io/enforce-mountable-secrets: "true"
spec:
containers:
- name: my-container
image: nginx
env:
- name: EXAMPLE_VAR
value: "example"
initContainers:
- name: init-container
image: busybox
command: ["sh", "-c", "echo init"]
env:
- name: INIT_VAR
value: "init"
ephemeralContainers:
- name: ephemeral-container
image: busybox
command: ["sh", "-c", "echo ephemeral"]
env:
- name: EPHEMERAL_VAR
value: "ephemeral"
22 changes: 22 additions & 0 deletions other/secrets-not-from-env-vars-cve-2024-3177/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: secrets-not-from-env-vars-cve-2024-3177
version: 1.0.0
displayName: secrets-not-from-env-vars-cve-2024-3177
createdAt: "2024-07-31T00:00:00.000Z"
description: >-
Secrets used as environment variables containing sensitive information may, if not carefully controlled, be printed in log output which could be visible to unauthorized people and captured in forwarding applications. This policy specifically blocks CVE-2024-3177
install: |-
```shell
kubectl apply -f https://raw.githubusercontent.com/kyverno/policies/main/other/secrets-not-from-env-vars-cve-2024-3177/secrets-not-from-env-vars-cve-2024-3177.yaml
```
keywords:
- kyverno
- Security
readme: |
Secrets used as environment variables containing sensitive information may, if not carefully controlled, be printed in log output which could be visible to unauthorized people and captured in forwarding applications. This policy specifically blocks CVE-2024-3177.

Refer to the documentation for more details on Kyverno annotations: https://artifacthub.io/docs/topics/annotations/kyverno/
annotations:
kyverno/category: "Security"
kyverno/kubernetesVersion: "1.27"
kyverno/subject: "Pod"
digest: 220166ead57270008b045345679c51dd586f59c7ca2bad24d213c07b9549b099
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: secrets-not-from-env-vars-cve-2024-3177
annotations:
policies.kyverno.io/title: Secrets not from env vars (CVE-2024-3177)
policies.kyverno.io/category: Security
policies.kyverno.io/severity: low
policies.kyverno.io/subject: Pod, Secret
kyverno.io/kubernetes-version: 1.27
kurktchiev marked this conversation as resolved.
Show resolved Hide resolved
kyverno.io/kyverno-version: 1.11.0
policies.kyverno.io/description: >-
Secrets used as environment variables containing sensitive information may, if not carefully controlled,
be printed in log output which could be visible to unauthorized people and captured in forwarding
applications. This policy specifically blocks CVE-2024-3177

Refer to the documentation for more details on Kyverno annotations: https://artifacthub.io/docs/topics/annotations/kyverno/
spec:
validationFailureAction: Audit
background: true
rules:
- name: secrets-not-from-envfrom-cve-2024-3177
match:
any:
- resources:
kinds:
- Pod
validate:
message: "Secrets must not come from envFrom statements. CVE-2024-3177"
pattern:
metadata:
annotations:
kubernetes.io/enforce-mountable-secrets: "true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a conditional check? I.e., if this annotation is set to true, then the pattern must be satisfied?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the annotation at all?

Seems to me that the policy would be more widely applicable without it.

spec:
=(ephemeralContainers):
- name: "*"
=(envFrom):
- X(secretRef): "null"
=(initContainers):
- name: "*"
=(envFrom):
- X(secretRef): "null"
containers:
- name: "*"
=(envFrom):
- X(secretRef): "null"