|
| 1 | +--- |
| 2 | +tags: |
| 3 | + - Kyverno |
| 4 | +--- |
| 5 | + |
| 6 | +# Kyverno policies |
| 7 | + |
| 8 | +Nais enforces certain cluster policies using kyverno, in addition to different baseline security |
| 9 | +policies you will also find some custom policies for the nais platform. |
| 10 | + |
| 11 | +## 001 - Add spot toleration |
| 12 | + |
| 13 | +This policy adds a toleration for pods to be deployed to nodes on spot |
| 14 | +instances, for cost reasons. |
| 15 | + |
| 16 | +## 002 - Default allow egress |
| 17 | + |
| 18 | +This policy generates a default allow egress NetworkPolicy for all |
| 19 | +Namespaces. It allows all egress traffic except for RFC 1918 private |
| 20 | +address space. This policy is based on the following Kubernetes |
| 21 | +NetworkPolicy: |
| 22 | +https://kubernetes.io/docs/concepts/services-networking/network-policies/#default-allow-all-egress |
| 23 | + |
| 24 | +## 003 - Deny image registries |
| 25 | + |
| 26 | +This policy denies images from registries not on the list of allowed |
| 27 | +registries. |
| 28 | + |
| 29 | +### Message |
| 30 | + |
| 31 | + Image not from an approved registry. Upload the image to an approved registry and try again. |
| 32 | + |
| 33 | +## 004 - Deny creation of Kafka Topics |
| 34 | + |
| 35 | +This policy Denies the creation of Kafka Topics. Documentation: |
| 36 | +https://docs.nais.io/how-to-guides/persistence/kafka/create/ |
| 37 | + |
| 38 | +### Message |
| 39 | + |
| 40 | +Kafka Topic resource is not supported in this cluster\nDocumentation: https://docs.nais.io/how-to-guides/persistence/kafka/create/ |
| 41 | + |
| 42 | +## 005 - Deny deletion of Kafka topics |
| 43 | + |
| 44 | +This policy Denies the deletion of Kafka topics without the |
| 45 | +kafka.nais.io/removeDataWhenResourceIsDeleted annotation. |
| 46 | +Documentation: |
| 47 | +https://docs.nais.io/how-to-guides/persistence/kafka/delete/ |
| 48 | + |
| 49 | +### Message |
| 50 | + |
| 51 | +Deleting Topic is not allowed without the kafka.nais.io/removeDataWhenResourceIsDeleted annotation.\nDocumentation: https://docs.nais.io/how-to-guides/persistence/kafka/delete/ |
| 52 | + |
| 53 | + |
| 54 | +## 006 - Deny specific service types |
| 55 | + |
| 56 | +This policy denies the creation of services with types other than ClusterIP and ExternalName. |
| 57 | +This policy is based on the example policy from the Kyverno documentation. |
| 58 | +https://kyverno.io/docs/writing-policies/deny-service-types/ |
| 59 | + |
| 60 | +### Message |
| 61 | + |
| 62 | +Service type must be one of ClusterIP or ExternalName in this namespace. |
| 63 | + |
| 64 | +## 007 - Replace legacy GitHub registry |
| 65 | + |
| 66 | +This policy rewrites references to the old GitHub registry (docker.pkg.github.com) with the new one (ghcr.io). |
| 67 | + |
| 68 | +## 008 - Verify SLSA Provenance (Keyless) |
| 69 | + |
| 70 | +This policy uses artifact provenance to identify how an artifact was produced |
| 71 | +and from where it originated. SLSA provenance is an industry-standard |
| 72 | +method of representing that provenance. This policy verifies that an |
| 73 | +image has SLSA provenance and was signed by the expected subject and issuer |
| 74 | +when produced through GitHub Actions. It requires configuration based upon |
| 75 | +your own values. |
| 76 | + |
| 77 | +## 009 - Ephemeral containers with allowed images and limited capabilities |
| 78 | + |
| 79 | +This policies ensures that ephemeral containers use allowed images and have limited capabilities. |
| 80 | +When using 'kubectl debug' please set flag `--profile=restricted`. |
| 81 | +For-example: `kubectl debug -it --image=cgr.dev/chainguard/busybox:latest --profile=restricted` |
| 82 | + |
| 83 | +### Message |
| 84 | + |
| 85 | +The fields spec.ephemeralContainers[*].image requires to be set for allowed image |
| 86 | +see `https://docs.nais.io/basics/debug`. |
| 87 | +Running as root is not allowed. The fields spec.ephemeralContainers[*].securityContext.runAsNonRoot |
| 88 | +must be `true`, and spec.ephemeralContainers[*].securityContext.capabilities.drop |
| 89 | +must be set to `- ALL` to reduce capabilities. |
| 90 | +The use of `kubectl debug` requires to set `--profile=restricted`. |
| 91 | + |
| 92 | +## 010 - Aiven operator |
| 93 | + |
| 94 | +This policy denies invalid names and projects, and missing project vpcs. Please see the documentation at https://docs.nais.io/how-to-guides/persistence/redis#creating-a-redis-instance-explicitly or https://docs.nais.io/how-to-guides/persistence/opensearch/create depending on your usecase. |
| 95 | + |
| 96 | +### message |
| 97 | + |
| 98 | +Invalid name. Please see https://docs.nais.io/how-to-guides/persistence/redis#creating-a-redis-instance-explicitly or https://docs.nais.io/how-to-guides/persistence/opensearch/create" |
| 99 | + |
| 100 | + |
| 101 | +## 011 - Validate fields for Kafka resources. |
| 102 | + |
| 103 | +This policy validates that the fields for the given resources has allowed values. |
| 104 | +Currently only validates the pool field. |
| 105 | + |
| 106 | +### Message |
| 107 | +Kafka pool {{ "{{ request.object.spec.pool }}" | quote }} is not supported in this cluster. |
| 108 | +Allowed values: [{{ $valid | join ", " }}] |
| 109 | + |
| 110 | +Please see the documentation at https://docs.nais.io/how-to-guides/persistence/kafka/create/ |
| 111 | + |
| 112 | + |
| 113 | +## 012 - Validate fields for Azure AD resources |
| 114 | + |
| 115 | +This policy validates that Azure AD fields for the given resource has allowed values. Currently only validates the tenant field. |
| 116 | + |
| 117 | +### Message |
| 118 | + |
| 119 | +Azure AD tenant "{{ request.object.spec.tenant }}" is not supported in this cluster. Allowed values: [nav.no] |
| 120 | +Please see the documentation at https://doc.nais.io/security/auth/azure-ad/ |
0 commit comments