2019-10-23 14:06:03 -07:00
# Sample Policies
2019-10-08 18:40:15 -07:00
2019-11-11 18:10:34 -08: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 )
2019-11-08 20:04:42 -08:00
2. [Disallow privileged containers ](DisallowPrivilegedContainers.md )
2019-10-31 18:43:06 -07:00
3. [Disallow new capabilities ](DisallowNewCapabilities.md )
2019-11-11 17:17:09 -08:00
4. [Disallow kernel parameter changes ](DisallowSysctls.md )
2019-11-11 18:21:16 -08:00
5. [Disallow use of bind mounts (`hostPath` volumes) ](DisallowBindMounts.md )
2019-11-01 15:23:42 -07:00
6. [Disallow docker socket bind mount ](DisallowDockerSockMount.md )
7. [Disallow `hostNetwork` and `hostPort` ](DisallowHostNetworkPort.md )
8. [Disallow `hostPID` and `hostIPC` ](DisallowHostPIDIPC.md )
2019-11-10 15:50:18 -08:00
9. [Disallow use of default namespace ](DisallowDefaultNamespace.md )
2019-11-01 15:23:42 -07:00
10. [Disallow latest image tag ](DisallowLatestTag.md )
2019-11-10 15:50:18 -08:00
11. [Disallow Helm Tiller ](DisallowHelmTiller.md )
2019-11-11 17:17:09 -08:00
12. [Require read-only root filesystem ](RequireReadOnlyRootFS.md )
13. [Require pod resource requests and limits ](RequirePodRequestsLimits.md )
14. [Require pod `livenessProbe` and `readinessProbe` ](RequirePodProbes.md )
2019-11-11 18:21:16 -08:00
15. [Add default network policy ](AddDefaultNetworkPolicy.md )
2019-11-18 16:55:14 -08:00
16. [Add namespace quotas ](AddNamespaceQuotas.md )
2019-11-11 17:17:09 -08:00
17. [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
2019-11-11 18:21:16 -08: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
2019-11-11 14:09:07 -08:00
17. [Restrict image registries ](RestrictImageRegistries.md )
18. [Restrict `NodePort` services ](RestrictNodePort.md )
19. [Restrict auto-mount of service account credentials ](RestrictAutomountSAToken.md )
2019-11-11 17:55:54 -08:00
20. [Restrict ingress classes ](RestrictIngressClasses.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:
**Install Kyverno**
````sh
kubectl create -f https://github.com/nirmata/kyverno/raw/master/definitions/install.yaml
````
< small > [(installation docs) ](../documentation/installation.md )</ small >
**Apply Kyverno Policies**
To start applying policies to your cluster, first clone the repo:
````bash
git clone https://github.com/nirmata/kyverno.git
cd kyverno
````
Import best_practices from [here ](best_pratices ):
````bash
kubectl create -f samples/best_practices
````
Import addition policies from [here ](more ):
````bash
kubectl create -f samples/more/
````