mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-14 19:58:45 +00:00
update documentation
This commit is contained in:
parent
ee20fcd4a0
commit
4894577ba1
19 changed files with 105 additions and 56 deletions
|
@ -15,7 +15,7 @@ metadata:
|
||||||
name: add-networkpolicy
|
name: add-networkpolicy
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: "default-deny-ingress"
|
- name: default-deny-ingress
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
|
|
|
@ -24,7 +24,7 @@ spec:
|
||||||
- Namespace
|
- Namespace
|
||||||
generate:
|
generate:
|
||||||
kind: ResourceQuota
|
kind: ResourceQuota
|
||||||
name: "default-resourcequota"
|
name: default-resourcequota
|
||||||
data:
|
data:
|
||||||
spec:
|
spec:
|
||||||
hard:
|
hard:
|
||||||
|
@ -39,7 +39,7 @@ spec:
|
||||||
- Namespace
|
- Namespace
|
||||||
generate:
|
generate:
|
||||||
kind: LimitRange
|
kind: LimitRange
|
||||||
name: "default-limitrange"
|
name: default-limitrange
|
||||||
data:
|
data:
|
||||||
spec:
|
spec:
|
||||||
limits:
|
limits:
|
||||||
|
|
|
@ -13,17 +13,17 @@ This policy matches and mutates pods with `emptyDir` and `hostPath` volumes, to
|
||||||
[add_safe_to_evict_annotation.yaml](best_practices/add_safe_to_evict.yaml)
|
[add_safe_to_evict_annotation.yaml](best_practices/add_safe_to_evict.yaml)
|
||||||
|
|
||||||
````yaml
|
````yaml
|
||||||
apiVersion: "kyverno.io/v1"
|
apiVersion: kyverno.io/v1
|
||||||
kind: ClusterPolicy
|
kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: "add-safe-to-evict"
|
name: add-safe-to-evict
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: "annotate-empty-dir"
|
- name: "annotate-empty-dir"
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- "Pod"
|
- Pod
|
||||||
mutate:
|
mutate:
|
||||||
overlay:
|
overlay:
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -32,11 +32,11 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
volumes:
|
volumes:
|
||||||
- (emptyDir): {}
|
- (emptyDir): {}
|
||||||
- name: "annotate-host-path"
|
- name: annotate-host-path
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- "Pod"
|
- Pod
|
||||||
mutate:
|
mutate:
|
||||||
overlay:
|
overlay:
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -47,5 +47,4 @@ spec:
|
||||||
- (hostPath):
|
- (hostPath):
|
||||||
path: "*"
|
path: "*"
|
||||||
|
|
||||||
````
|
````
|
||||||
|
|
|
@ -4,7 +4,7 @@ All processes inside the pod can be made to run with specific user and groupID b
|
||||||
|
|
||||||
## Policy YAML
|
## Policy YAML
|
||||||
|
|
||||||
[policy_validate_user_group_fsgroup_id.yaml](more/policy_validate_user_group_fsgroup_id.yaml)
|
[policy_validate_user_group_fsgroup_id.yaml](more/restrict_usergroup_fsgroup_id.yaml)
|
||||||
|
|
||||||
````yaml
|
````yaml
|
||||||
apiVersion: kyverno.io/v1
|
apiVersion: kyverno.io/v1
|
||||||
|
@ -46,8 +46,4 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
securityContext:
|
securityContext:
|
||||||
fsGroup: '2000'
|
fsGroup: '2000'
|
||||||
# Alls processes inside the pod can be made to run with specific user and groupID by setting runAsUser and runAsGroup respectively.
|
````
|
||||||
# fsGroup can be specified to make sure any file created in the volume with have the specified groupID.
|
|
||||||
# The above parameters can also be used in a validate policy to restrict user & group IDs.
|
|
||||||
````
|
|
||||||
|
|
|
@ -7,17 +7,17 @@ The volume of type `hostPath` allows pods to use host bind mounts (i.e. director
|
||||||
[disallow_bind_mounts.yaml](best_practices/disallow_bind_mounts.yaml)
|
[disallow_bind_mounts.yaml](best_practices/disallow_bind_mounts.yaml)
|
||||||
|
|
||||||
````yaml
|
````yaml
|
||||||
apiVersion: "kyverno.io/v1"
|
apiVersion: kyverno.io/v1
|
||||||
kind: ClusterPolicy
|
kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: "disallow-bind-mounts"
|
name: disallow-bind-mounts
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: "validate-hostPath"
|
- name: validate-hostPath
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- "Pod"
|
- Pod
|
||||||
validate:
|
validate:
|
||||||
message: "Host path volumes are not allowed"
|
message: "Host path volumes are not allowed"
|
||||||
pattern:
|
pattern:
|
||||||
|
|
|
@ -25,6 +25,6 @@ spec:
|
||||||
pattern:
|
pattern:
|
||||||
spec:
|
spec:
|
||||||
=(volumes):
|
=(volumes):
|
||||||
=(hostPath):
|
- =(hostPath):
|
||||||
path: "!/var/run/docker.sock"
|
path: "!/var/run/docker.sock"
|
||||||
````
|
````
|
||||||
|
|
|
@ -15,18 +15,28 @@ metadata:
|
||||||
name: disallow-host-network-port
|
name: disallow-host-network-port
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-host-network-port
|
- name: validate-host-network
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- Pod
|
- Pod
|
||||||
validate:
|
validate:
|
||||||
message: "Using host networking is not allowed"
|
message: "Use of hostNetwork is not allowed"
|
||||||
|
pattern:
|
||||||
|
spec:
|
||||||
|
=(hostNetwork): false
|
||||||
|
- name: validate-host-port
|
||||||
|
match:
|
||||||
|
resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
validate:
|
||||||
|
message: "Use of hostPort is not allowed"
|
||||||
pattern:
|
pattern:
|
||||||
spec:
|
spec:
|
||||||
(hostNetwork): false
|
|
||||||
containers:
|
containers:
|
||||||
- name: "*"
|
- name: "*"
|
||||||
ports:
|
=(ports):
|
||||||
- hostPort: null
|
- X(hostPort): null
|
||||||
|
|
||||||
````
|
````
|
|
@ -14,7 +14,7 @@ metadata:
|
||||||
name: disallow-latest-tag
|
name: disallow-latest-tag
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: require-tag
|
- name: require-image-tag
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
|
@ -25,7 +25,7 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- image: "*:*"
|
- image: "*:*"
|
||||||
- name: validate-tag
|
- name: validate-image-tag
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
|
|
|
@ -15,7 +15,6 @@ apiVersion: kyverno.io/v1
|
||||||
kind: ClusterPolicy
|
kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: disallow-root-user
|
name: disallow-root-user
|
||||||
annotations:
|
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-runAsNonRoot
|
- name: validate-runAsNonRoot
|
||||||
|
@ -24,7 +23,7 @@ spec:
|
||||||
kinds:
|
kinds:
|
||||||
- Pod
|
- Pod
|
||||||
validate:
|
validate:
|
||||||
message: "Root user is not allowed. Set runAsNonRoot to true"
|
message: "Running as root user is not allowed. Set runAsNonRoot to true"
|
||||||
anyPattern:
|
anyPattern:
|
||||||
- spec:
|
- spec:
|
||||||
securityContext:
|
securityContext:
|
||||||
|
|
|
@ -34,6 +34,7 @@ These policies provide additional best practices and are worthy of close conside
|
||||||
18. [Restrict `NodePort` services](RestrictNodePort.md)
|
18. [Restrict `NodePort` services](RestrictNodePort.md)
|
||||||
19. [Restrict auto-mount of service account credentials](RestrictAutomountSAToken.md)
|
19. [Restrict auto-mount of service account credentials](RestrictAutomountSAToken.md)
|
||||||
20. [Restrict ingress classes](RestrictIngressClasses.md)
|
20. [Restrict ingress classes](RestrictIngressClasses.md)
|
||||||
|
21. [Restrict User Group](CheckUserGroup.md)
|
||||||
|
|
||||||
## Applying the sample policies
|
## Applying the sample policies
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: require-pod-requests-limits
|
name: require-pod-requests-limits
|
||||||
spec:
|
spec:
|
||||||
validationFailureAction: "audit"
|
|
||||||
rules:
|
rules:
|
||||||
- name: validate-resources
|
- name: validate-resources
|
||||||
match:
|
match:
|
||||||
|
|
|
@ -19,7 +19,7 @@ spec:
|
||||||
kinds:
|
kinds:
|
||||||
- Pod
|
- Pod
|
||||||
validate:
|
validate:
|
||||||
message: "Deny automounting API credentials"
|
message: "Auto-mounting of Service Account tokens is not allowed"
|
||||||
pattern:
|
pattern:
|
||||||
spec:
|
spec:
|
||||||
automountServiceAccountToken: false
|
automountServiceAccountToken: false
|
||||||
|
|
|
@ -15,19 +15,18 @@ Although NodePort services can be useful, their use should be limited to service
|
||||||
apiVersion: kyverno.io/v1
|
apiVersion: kyverno.io/v1
|
||||||
kind: ClusterPolicy
|
kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: restrict-node-port
|
name: restrict-nodeport
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-node-port
|
- name: validate-nodeport
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- Service
|
- Service
|
||||||
validate:
|
validate:
|
||||||
message: "Service of type NodePort is not allowed"
|
message: "Services of type NodePort are not allowed"
|
||||||
pattern:
|
pattern:
|
||||||
spec:
|
spec:
|
||||||
type: "!NodePort"
|
type: "!NodePort"
|
||||||
|
|
||||||
````
|
````
|
||||||
|
|
|
@ -12,7 +12,7 @@ metadata:
|
||||||
desired traffic to application pods from select sources.
|
desired traffic to application pods from select sources.
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: "default-deny-ingress"
|
- name: default-deny-ingress
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
|
|
|
@ -16,7 +16,7 @@ spec:
|
||||||
- Namespace
|
- Namespace
|
||||||
generate:
|
generate:
|
||||||
kind: ResourceQuota
|
kind: ResourceQuota
|
||||||
name: "default-resourcequota"
|
name: default-resourcequota
|
||||||
data:
|
data:
|
||||||
spec:
|
spec:
|
||||||
hard:
|
hard:
|
||||||
|
@ -31,7 +31,7 @@ spec:
|
||||||
- Namespace
|
- Namespace
|
||||||
generate:
|
generate:
|
||||||
kind: LimitRange
|
kind: LimitRange
|
||||||
name: "default-limitrange"
|
name: default-limitrange
|
||||||
data:
|
data:
|
||||||
spec:
|
spec:
|
||||||
limits:
|
limits:
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
apiVersion: "kyverno.io/v1"
|
apiVersion: kyverno.io/v1
|
||||||
kind: "ClusterPolicy"
|
kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: "add-safe-to-evict"
|
name: add-safe-to-evict
|
||||||
annotations:
|
annotations:
|
||||||
policies.kyverno.io/category: Workload Management
|
policies.kyverno.io/category: Workload Management
|
||||||
policies.kyverno.io/description: The Kubernetes cluster autoscaler does not evict pods that
|
policies.kyverno.io/description: The Kubernetes cluster autoscaler does not evict pods that
|
||||||
|
@ -9,29 +9,29 @@ metadata:
|
||||||
cluster-autoscaler.kubernetes.io/safe-to-evict=true must be added to the pods.
|
cluster-autoscaler.kubernetes.io/safe-to-evict=true must be added to the pods.
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: "annotate-empty-dir"
|
- name: annotate-empty-dir
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- "Pod"
|
- Pod
|
||||||
mutate:
|
mutate:
|
||||||
overlay:
|
overlay:
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
+(cluster-autoscaler.kubernetes.io/safe-to-evict): "true"
|
+(cluster-autoscaler.kubernetes.io/safe-to-evict): true
|
||||||
spec:
|
spec:
|
||||||
volumes:
|
volumes:
|
||||||
- (emptyDir): {}
|
- (emptyDir): {}
|
||||||
- name: "annotate-host-path"
|
- name: annotate-host-path
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- "Pod"
|
- Pod
|
||||||
mutate:
|
mutate:
|
||||||
overlay:
|
overlay:
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
+(cluster-autoscaler.kubernetes.io/safe-to-evict): "true"
|
+(cluster-autoscaler.kubernetes.io/safe-to-evict): true
|
||||||
spec:
|
spec:
|
||||||
volumes:
|
volumes:
|
||||||
- (hostPath):
|
- (hostPath):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
apiVersion: "kyverno.io/v1"
|
apiVersion: kyverno.io/v1
|
||||||
kind: "ClusterPolicy"
|
kind: ClusterPolicy
|
||||||
metadata:
|
metadata:
|
||||||
name: "disallow-bind-mounts"
|
name: disallow-bind-mounts
|
||||||
annotations:
|
annotations:
|
||||||
policies.kyverno.io/category: Workload Isolation
|
policies.kyverno.io/category: Workload Isolation
|
||||||
policies.kyverno.io/description: The volume of type `hostPath` allows pods to use host bind
|
policies.kyverno.io/description: The volume of type `hostPath` allows pods to use host bind
|
||||||
|
@ -13,11 +13,11 @@ metadata:
|
||||||
|
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: "validate-hostPath"
|
- name: validate-hostPath
|
||||||
match:
|
match:
|
||||||
resources:
|
resources:
|
||||||
kinds:
|
kinds:
|
||||||
- "Pod"
|
- Pod
|
||||||
validate:
|
validate:
|
||||||
message: "Host path volumes are not allowed"
|
message: "Host path volumes are not allowed"
|
||||||
pattern:
|
pattern:
|
||||||
|
|
|
@ -4,7 +4,8 @@ metadata:
|
||||||
name: disallow-helm-tiller
|
name: disallow-helm-tiller
|
||||||
annotations:
|
annotations:
|
||||||
policies.kyverno.io/category: Security
|
policies.kyverno.io/category: Security
|
||||||
policies.kyverno.io/description:
|
policies.kyverno.io/description: Tiller has known security challenges. It requires adminstrative privileges and acts as a shared
|
||||||
|
resource accessible to any authenticated user. Tiller can lead to privilge escalation as restricted users can impact other users.
|
||||||
spec:
|
spec:
|
||||||
rules:
|
rules:
|
||||||
- name: validate-helm-tiller
|
- name: validate-helm-tiller
|
||||||
|
|
45
samples/more/restrict_usergroup_fsgroup_id.yaml
Normal file
45
samples/more/restrict_usergroup_fsgroup_id.yaml
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
apiVersion: kyverno.io/v1
|
||||||
|
kind: ClusterPolicy
|
||||||
|
metadata:
|
||||||
|
name: validate-userid-groupid-fsgroup
|
||||||
|
annotations:
|
||||||
|
policies.kyverno.io/category: Security Context
|
||||||
|
policies.kyverno.io/description: All processes inside the pod can be made to run with specific user
|
||||||
|
and groupID by setting 'runAsUser' and 'runAsGroup' respectively. 'fsGroup' can be specified
|
||||||
|
to make sure any file created in the volume with have the specified groupID. These options can be
|
||||||
|
used to validate the IDs used for user and group.
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- name: validate-userid
|
||||||
|
match:
|
||||||
|
resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
validate:
|
||||||
|
message: "User ID should be 1000"
|
||||||
|
pattern:
|
||||||
|
spec:
|
||||||
|
securityContext:
|
||||||
|
runAsUser: '1000'
|
||||||
|
- name: validate-groupid
|
||||||
|
match:
|
||||||
|
resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
validate:
|
||||||
|
message: "Group ID should be 3000"
|
||||||
|
pattern:
|
||||||
|
spec:
|
||||||
|
securityContext:
|
||||||
|
runAsGroup: '3000'
|
||||||
|
- name: validate-fsgroup
|
||||||
|
match:
|
||||||
|
resources:
|
||||||
|
kinds:
|
||||||
|
- Pod
|
||||||
|
validate:
|
||||||
|
message: "fsgroup should be 2000"
|
||||||
|
pattern:
|
||||||
|
spec:
|
||||||
|
securityContext:
|
||||||
|
fsGroup: '2000'
|
Loading…
Add table
Reference in a new issue