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

feat: add miscellaneous policies in CEL expressions - Part 3 #1028

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
720bc92
copy prevent-linkerd-pod-injection-override
Chandan-DK May 21, 2024
4f6ca0c
add kyverno tests for prevent-linkerd-pod-injection-override
Chandan-DK May 21, 2024
a74d10b
convert prevent-linkerd-pod-injection-override
Chandan-DK May 21, 2024
dcd4ac5
add metadata section to template
Chandan-DK May 21, 2024
6ac7add
add kyverno tests for prevent-linkerd-pod-injection-override in regul…
Chandan-DK May 21, 2024
51af207
copy prevent-linkerd-port-skipping
Chandan-DK May 21, 2024
66b483f
correct invalid chainsaw test resources to remove errors
Chandan-DK May 21, 2024
562b82d
add kyverno tests
Chandan-DK May 21, 2024
a14f7f8
convert prevent-linkerd-port-skipping
Chandan-DK May 21, 2024
d7003ed
copy require-linkerd-mesh-injection
Chandan-DK May 21, 2024
a7ffe1e
add kyverno tests for require-linkerd-mesh-injection
Chandan-DK May 21, 2024
7acd066
convert require-linkerd-mesh-injection
Chandan-DK May 21, 2024
63a28e7
copy disallow-ingress-nginx-custom-snippets
Chandan-DK May 21, 2024
7cffb72
convert disallow-ingress-nginx-custom-snippets
Chandan-DK May 21, 2024
9321063
copy restrict-annotations
Chandan-DK May 22, 2024
afc2fea
convert restrict-annotations
Chandan-DK May 22, 2024
abd6ab4
copy restrict-ingress-paths
Chandan-DK May 22, 2024
0e01161
add kyverno test for one more failing condition
Chandan-DK May 22, 2024
2788e16
convert restrict-ingress-paths
Chandan-DK May 22, 2024
5d7f145
copy check-routes
Chandan-DK May 22, 2024
bc9172f
convert check-routes
Chandan-DK May 22, 2024
07e3081
copy disallow-deprecated-apis/
Chandan-DK May 22, 2024
6d334db
convert disallow-deprecated-apis
Chandan-DK May 22, 2024
9616cff
copy disallow-default-tlsoptions
Chandan-DK May 22, 2024
63d317e
convert disallow-default-tlsoptions
Chandan-DK May 22, 2024
4dd272d
copy add-psa-namespace-reporting
Chandan-DK May 22, 2024
f83665c
convert add-psa-namespace-reporting
Chandan-DK May 22, 2024
184576b
copy deny-privileged-profile
Chandan-DK May 22, 2024
03609a0
convert deny-privileged-profile
Chandan-DK May 22, 2024
f3a3ca9
add kyverno tests for deny-privileged-profile
Chandan-DK May 22, 2024
2815aa5
copy disallow-jenkins-pipeline-strategy
Chandan-DK May 22, 2024
a7d95dd
convert disallow-jenkins-pipeline-strategy
Chandan-DK May 22, 2024
ca7ed59
copy disallow-security-context-constraint-anyuid
Chandan-DK May 22, 2024
6512fba
convert disallow-security-context-constraint-anyuid
Chandan-DK May 22, 2024
77095fa
copy openshift-cel/disallow-self-provisioner-binding
Chandan-DK May 22, 2024
5c66f1f
convert disallow-self-provisioner-binding
Chandan-DK May 22, 2024
07f18b6
copy enforce-etcd-encryption
Chandan-DK May 22, 2024
4343afc
convert enforce-etcd-encryption
Chandan-DK May 22, 2024
5c9058e
add CI tests for cel policies
Chandan-DK May 22, 2024
bb83cb3
remove comments for CI tests
Chandan-DK May 22, 2024
edf8a45
rename files for clarity
Chandan-DK May 22, 2024
34869cf
Merge branch 'main' into miscellaneous-policies-cel-part-3
Chandan-DK May 22, 2024
cbd81f5
specify CREATE and UPDATE operations explicitly
Chandan-DK Jul 9, 2024
95b5dd0
Merge branch 'main' into miscellaneous-policies-cel-part-3
Chandan-DK Jul 9, 2024
18cd551
remove disallow-self-provisioner-binding as it gives errors that need…
Chandan-DK Jul 9, 2024
a04f06c
Merge branch 'main' into miscellaneous-policies-cel-part-3
MariamFahmy98 Jul 10, 2024
96b2b31
Merge branch 'main' into miscellaneous-policies-cel-part-3
MariamFahmy98 Jul 15, 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
11 changes: 8 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ jobs:
- ^kubeops$
- ^kubevirt$
- ^linkerd$
- ^linkerd-cel$
- ^nginx-ingress$
- ^nginx-ingress-cel$
- ^openshift$
- ^openshift-cel$
- ^other$/^a
- ^other-cel$/^a
- ^other$/^[b-d]
Expand All @@ -72,10 +75,12 @@ jobs:
- ^pod-security$
- ^pod-security-cel$
- ^psa$
- ^psa-cel$
- ^psp-migration$
# - ^tekton
# - ^traefik
# - ^velero
- ^tekton$
- ^traefik$
- ^traefik-cel$
- ^velero$
runs-on: ubuntu-latest
name: ${{ matrix.k8s-version.name }} - ${{ matrix.tests }}
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
linkerd.io/inject: disabled
name: badpod01
spec:
containers:
- image: busybox:1.35
name: busybox
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: baddeploy01
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
annotations:
linkerd.io/inject: disabled
spec:
containers:
- name: busybox
image: busybox:1.35
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: badcronjob01
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
linkerd.io/inject: disabled
spec:
containers:
- name: hello
image: busybox:1.35
command:
- "sleep"
- "3600"
restartPolicy: OnFailure
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: prevent-linkerd-pod-injection-override
spec:
steps:
- name: step-01
try:
- apply:
file: ../prevent-linkerd-pod-injection-override.yaml
- patch:
resource:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: prevent-linkerd-pod-injection-override
spec:
validationFailureAction: Enforce
- assert:
file: policy-ready.yaml
- name: step-02
try:
- apply:
file: good-pod.yaml
- apply:
file: good-podcontrollers.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-pod.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-podcontrollers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
linkerd.io/inject: enabled
name: goodpod01
spec:
containers:
- image: busybox:1.35
name: busybox
---
apiVersion: v1
kind: Pod
metadata:
name: goodpod02
spec:
containers:
- image: busybox:1.35
name: busybox
resources: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: gooddeploy01
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: busybox
image: busybox:1.35
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: busybox
name: gooddeploy02
spec:
replicas: 1
selector:
matchLabels:
app: busybox
template:
metadata:
labels:
app: busybox
annotations:
linkerd.io/inject: enabled
spec:
containers:
- name: busybox
image: busybox:1.35
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: goodcronjob01
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: busybox
spec:
containers:
- name: hello
image: busybox:1.35
command:
- "sleep"
- "3600"
restartPolicy: OnFailure
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: goodcronjob02
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
annotations:
linkerd.io/inject: enabled
spec:
containers:
- name: hello
image: busybox:1.35
command:
- "sleep"
- "3600"
restartPolicy: OnFailure
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: prevent-linkerd-pod-injection-override
status:
ready: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: cli.kyverno.io/v1alpha1
kind: Test
metadata:
name: prevent-linkerd-pod-injection-override
policies:
- ../prevent-linkerd-pod-injection-override.yaml
resources:
- ../.chainsaw-test/bad-pod.yaml
- ../.chainsaw-test/bad-podcontrollers.yaml
- ../.chainsaw-test/good-pod.yaml
- ../.chainsaw-test/good-podcontrollers.yaml
results:
- policy: prevent-linkerd-pod-injection-override
rule: pod-injection-override
kind: Pod
resources:
- badpod01
result: fail
- policy: prevent-linkerd-pod-injection-override
rule: pod-injection-override
kind: Deployment
resources:
- baddeploy01
result: fail
- policy: prevent-linkerd-pod-injection-override
rule: pod-injection-override
kind: CronJob
resources:
- badcronjob01
result: fail
- policy: prevent-linkerd-pod-injection-override
rule: pod-injection-override
kind: Pod
resources:
- goodpod01
- goodpod02
result: pass
- policy: prevent-linkerd-pod-injection-override
rule: pod-injection-override
kind: Deployment
resources:
- gooddeploy01
- gooddeploy02
result: pass
- policy: prevent-linkerd-pod-injection-override
rule: pod-injection-override
kind: CronJob
resources:
- goodcronjob01
- goodcronjob02
result: pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: prevent-linkerd-pod-injection-override-cel
version: 1.0.0
displayName: Prevent Linkerd Pod Injection Override in CEL expressions
description: >-
Setting the annotation on a Pod (or its controller) `linkerd.io/inject` to `disabled` may effectively disable mesh participation for that workload reducing security and visibility. This policy prevents setting the annotation `linkerd.io/inject` to `disabled` for Pods.
install: |-
```shell
kubectl apply -f https://raw.githubusercontent.com/kyverno/policies/main/linkerd-cel/prevent-linkerd-pod-injection-override/prevent-linkerd-pod-injection-override.yaml
```
keywords:
- kyverno
- Linkerd
- CEL Expressions
readme: |
Setting the annotation on a Pod (or its controller) `linkerd.io/inject` to `disabled` may effectively disable mesh participation for that workload reducing security and visibility. This policy prevents setting the annotation `linkerd.io/inject` to `disabled` for Pods.

Refer to the documentation for more details on Kyverno annotations: https://artifacthub.io/docs/topics/annotations/kyverno/
annotations:
kyverno/category: "Linkerd in CEL"
kyverno/kubernetesVersion: "1.26-1.27"
kyverno/subject: "Pod"
digest: 795a7d5ae06f9720bdbcc00ced965d1f7a28540c965628a47abc5621fb8d0033
createdAt: "2024-05-21T15:39:18Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: prevent-linkerd-pod-injection-override
annotations:
policies.kyverno.io/title: Prevent Linkerd Pod Injection Override in CEL expressions
policies.kyverno.io/category: Linkerd in CEL
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod
kyverno.io/kyverno-version: 1.11.0
kyverno.io/kubernetes-version: "1.26-1.27"
policies.kyverno.io/description: >-
Setting the annotation on a Pod (or its controller) `linkerd.io/inject` to
`disabled` may effectively disable mesh participation for that workload reducing
security and visibility. This policy prevents setting the annotation `linkerd.io/inject`
to `disabled` for Pods.
spec:
validationFailureAction: Audit
background: true
rules:
- name: pod-injection-override
match:
any:
- resources:
kinds:
- Pod
operations:
- CREATE
- UPDATE
validate:
cel:
expressions:
- expression: "!has(object.metadata.annotations) || !('linkerd.io/inject' in object.metadata.annotations) || object.metadata.annotations['linkerd.io/inject'] != 'disabled'"
message: "Pods may not disable sidecar injection."

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
foo: bar
config.linkerd.io/skip-inbound-ports: "true"
name: badpod01
spec:
containers:
- image: busybox:1.35
name: busybox
---
apiVersion: v1
kind: Pod
metadata:
annotations:
config.linkerd.io/skip-outbound-ports: "true"
foo: bar
name: badpod02
spec:
containers:
- image: busybox:1.35
name: busybox
---
apiVersion: v1
kind: Pod
metadata:
annotations:
foo: bar
config.linkerd.io/skip-outbound-ports: "true"
config.linkerd.io/skip-inbound-ports: "true"
name: badpod03
spec:
containers:
- image: busybox:1.35
name: busybox
Loading
Loading