2019-10-23 14:06:03 -07:00
# Sample Policies
2019-10-08 18:40:15 -07:00
2020-11-12 12:32:10 -05:00
Sample policies are designed to be applied to your Kubernetes clusters with minimal changes.
2019-10-09 18:40:52 -07:00
2019-10-23 14:26:29 -07:00
The policies are mostly validation rules in `audit` mode i.e. your existing workloads will not be impacted, but will be audited for policy complaince.
2019-10-23 14:06:03 -07:00
## Best Practice Policies
2019-10-14 12:27:17 -07:00
2019-10-23 14:06:03 -07:00
These policies are highly recommended.
2019-10-09 18:40:52 -07:00
2019-11-08 19:25:43 -08:00
1. [Disallow root user ](DisallowRootUser.md )
2020-11-11 20:30:59 -05:00
1. [Disallow privileged containers ](DisallowPrivilegedContainers.md )
1. [Disallow new capabilities ](DisallowNewCapabilities.md )
1. [Disallow kernel parameter changes ](DisallowSysctls.md )
1. [Disallow use of bind mounts (`hostPath` volumes) ](DisallowBindMounts.md )
1. [Disallow docker socket bind mount ](DisallowDockerSockMount.md )
1. [Disallow `hostNetwork` and `hostPort` ](DisallowHostNetworkPort.md )
1. [Disallow `hostPID` and `hostIPC` ](DisallowHostPIDIPC.md )
1. [Disallow use of default namespace ](DisallowDefaultNamespace.md )
1. [Disallow latest image tag ](DisallowLatestTag.md )
1. [Disallow Helm Tiller ](DisallowHelmTiller.md )
1. [Require read-only root filesystem ](RequireReadOnlyRootFS.md )
1. [Require pod resource requests and limits ](RequirePodRequestsLimits.md )
1. [Require pod `livenessProbe` and `readinessProbe` ](RequirePodProbes.md )
1. [Add default network policy ](AddDefaultNetworkPolicy.md )
1. [Add namespace quotas ](AddNamespaceQuotas.md )
1. [Add `safe-to-evict` for pods with `emptyDir` and `hostPath` volumes ](AddSafeToEvict.md )
2019-10-09 18:40:52 -07:00
2019-10-23 14:06:03 -07:00
## Additional Policies
2019-10-09 18:40:52 -07:00
2020-11-12 12:32:10 -05:00
These policies provide additional best practices and are worthy of close consideration. These policies may require specific changes for your workloads and environments.
2019-10-14 14:06:20 -07:00
2020-11-11 20:30:59 -05:00
1. [Restrict image registries ](RestrictImageRegistries.md )
1. [Restrict `NodePort` services ](RestrictNodePort.md )
1. [Restrict auto-mount of service account credentials ](RestrictAutomountSAToken.md )
1. [Restrict ingress classes ](RestrictIngressClasses.md )
1. [Restrict User Group ](CheckUserGroup.md )
1. [Require pods are labeled ](RequireLabels.md )
1. [Require pods have certain labels ](RequireCertainLabels.md )
2020-11-12 12:31:03 -05:00
1. [Require Deployments have multiple replicas ](RequireDeploymentsHaveReplicas.md )
2019-11-11 18:10:34 -08:00
## Applying the sample policies
To apply these policies to your cluster, install Kyverno and import the policies as follows:
2020-11-12 12:32:10 -05:00
### Install Kyverno**
2019-11-11 18:10:34 -08:00
````sh
2020-11-12 18:23:20 -05:00
kubectl create -f https://raw.githubusercontent.com/kyverno/kyverno/main/definitions/release/install.yaml
2019-11-11 18:10:34 -08:00
````
2020-11-12 12:32:10 -05:00
2019-11-11 18:10:34 -08:00
< small > [(installation docs) ](../documentation/installation.md )</ small >
2020-11-12 12:32:10 -05:00
### Apply Kyverno Policies**
2019-11-11 18:10:34 -08:00
To start applying policies to your cluster, first clone the repo:
````bash
2020-10-07 15:09:52 -07:00
git clone https://github.com/kyverno/kyverno.git
2019-11-11 18:10:34 -08:00
cd kyverno
````
2020-11-12 18:23:20 -05:00
Import best practices from [here ](best_pratices ):
2019-11-11 18:10:34 -08:00
````bash
kubectl create -f samples/best_practices
````
2020-11-12 18:23:20 -05:00
Import additional policies from [here ](more ):
2019-11-11 18:10:34 -08:00
````bash
kubectl create -f samples/more/
````