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

NDEV-20544: add remediate policies for RBAC best practices #169

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -22,3 +22,10 @@ spec:
- check:
($error != null): true
file: bad-resource.yaml
# After creating the remediate policy, we can create the bad resources as they will be mutated to become compliant
- apply:
file: ../remediate-restrict-automount-sa-token.yaml
- assert:
file: remediation-policy-assert.yaml
- apply:
file: bad-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remediate-restrict-automount-sa-token
spec:
validationFailureAction: Audit
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remediate-restrict-automount-sa-token
annotations:
policies.kyverno.io/title: Remediate Restrict Auto-Mount of Service Account Tokens
policies.kyverno.io/category: RBAC Best Practices
policies.kyverno.io/description: >-
This policy remediates the restrict-automount-sa-token violation
spec:
background: false
rules:
- name: remediate-restrict-automount-sa-token
match:
any:
- resources:
kinds:
- Pod
preconditions:
all:
- key: "{{ request.\"object\".metadata.labels.\"app.kubernetes.io/part-of\" || '' }}"
operator: NotEquals
value: policy-reporter
mutate:
patchStrategicMerge:
spec:
automountServiceAccountToken: false

Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ rules:
- apiGroups: [""]
resources: ["pods", "nodes/proxy"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: badcr03
rules:
- apiGroups: [""]
resources: ["nodes/proxy"]
verbs: ["get", "watch", "list"]
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ spec:
- check:
($error != null): true
file: bad-resource.yaml
# After creating the remediate policy, we can create the bad resources as they will be mutated to become compliant
- apply:
file: ../remediate-restrict-clusterrole-nodesproxy.yaml
- assert:
file: remediation-policy-assert.yaml
- apply:
file: bad-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remediate-restrict-clusterrole-nodesproxy
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remediate-restrict-clusterrole-nodesproxy
annotations:
policies.kyverno.io/title: Remediate Restrict ClusterRole with Nodes Proxy
policies.kyverno.io/category: RBAC Best Practices
policies.kyverno.io/description: >-
This policy remediates the restrict-clusterrole-nodesproxy violation
spec:
background: false
rules:
- name: remediate-restrict-clusterrole-nodesproxy
match:
any:
- resources:
kinds:
- ClusterRole
mutate:
foreach:
- list: request.object.rules[]
foreach:
- list: element.resources
preconditions:
all:
- key: "{{element}}"
operator: Equals
value: "nodes/proxy"
patchesJson6902: |-
- path: /rules/{{elementIndex0}}/resources/{{elementIndex1}}
op: replace
value: ""


Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ spec:
- check:
($error != null): true
file: bad-resource.yaml
# After creating the remediate policy, we can create the bad resources as they will be mutated to become compliant
- apply:
file: ../remediate-restrict-wildcard-resources.yaml
- assert:
file: remediation-policy-assert.yaml
- apply:
file: bad-resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remediate-restrict-wildcard-resources
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: remediate-restrict-wildcard-resources
annotations:
policies.kyverno.io/title: Remediate Restrict Wildcard in Resources
policies.kyverno.io/category: RBAC Best Practices
policies.kyverno.io/description: >-
This policy remediates the restrict-wildcard-resources violation
spec:
background: false
rules:
- name: remediate-restrict-wildcard-resources
match:
any:
- resources:
kinds:
- Role
- ClusterRole
mutate:
foreach:
- list: request.object.rules[]
foreach:
- list: element.resources
preconditions:
all:
- key: "*"
operator: Equals
value: "{{element}}"
patchesJson6902: |-
- path: /rules/{{elementIndex0}}/resources/{{elementIndex1}}
op: replace
value: ""
Loading