validating-admission-policies
Create Validating Admission Policies
About this chart
This chart is used to create the ValidatingAdmissionPolicy objects used by all clusters. It consists of policies replicating the kubernetes pod security standards as well as custom policies for particular workloads.
pod-security-standards
The policies in the pod-security-standards folder replicate the profiles defined in the pod security standards, but allow for mor fine grained control by excluding particular policies on a per namespace level.
They are generated from kyverno's upstream policies written in CEL using kyverno-policy-parser.py:
pipx install git+https://gitlab.wikimedia.org/repos/sre/kyverno-policy-parser.git
kyverno-policy-parser --output-dir charts/validating-admission-policies/templates/pod-security-standards/
The script also creates basic chainsaw tests from upstream data but the whole process is far from perfect. So after running the script to update the policies, the resulting diff should be investigated closely (also because it might override necessary local changes).
Each resulting ValidatingAdmissionPolicy has its matching ValidatingAdmissionPolicyBinding which binds the policy to namespaces via namespace labels:
pod-security.wmf.org/profile: Can be set tobaselineorrestrictedwhich binds all policies of the respective profile to the namespace.pod-security.wmf.org/<policy name>: Can be set toexcludeto exclude a particular policy from being bound to the namespace.
Example
The following namespace would:
- apply all
baselinepolicies (asrestrictedincludesbaseline) - apply all
restrictedpolicies exceptrestrict-volume-types-restricted-volumes
Pods scheduled in this namespace would need to adhere to the restricted profile while still being abe to mount arbitrary volume types.
apiVersion: v1
kind: Namespace
metadata:
name: foo
labels:
pod-security.wmf.org/profile: restricted
pod-security.wmf.org/restrict-volume-types-restricted-volumes: exclude
custom-policies
Contains custom policies and bindings.
These are WMF specific hand crafted policies. For consistency sake, they should come with a binding of the same name which allows to include the policy at a namespace level and a small helm template to configure validationActions in a standardized way across all policies:
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: fancy-new-policy
spec:
policyName: fancy-new-policy
matchResources:
namespaceSelector:
matchExpressions:
- key: pod-security.wmf.org/fancy-new-policy
operator: In
values:
- include
validationActions: {{ get (default dict .Values.validationActions) "fancy-new-policy" | default (list "Deny") | toYaml | nindent 4 }}
Testing
Chainsaw is used for end to end testing of all policies. These tests can be run on a local kind cluster or any other compatible kubernetes cluster (keep in mind that chainsaw will create multiple namespaces and resources during tests, it might also fail to clean them up).
You may run make test create a compatible cluster with kind and run all tests. Kind and chainsaw need to be installed though.
Deploy validating-admission-policies with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has validating-admission-policies on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartvalidating-admission-policies is pinned at v0.5.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply