Velero allows on backup and restore operations and is designed to be run with full cluster admin permissions. It allows on cross namespace restore operations, which means you can restore backup of namespace A to namespace B. This policy protect restore operation into system or any protected namespaces, listed in deny condition section. It checks the Restore CRD object and its namespaceMapping field. If destination match protected namespace then operation fails and warning message is throw.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: block-velero-restoreannotations:policies.kyverno.io/title: Block Velero Restore to Protected Namespace in CEL expressionspolicies.kyverno.io/category: Velero in CELpolicies.kyverno.io/subject: Restorekyverno.io/kyverno-version: 1.11.0kyverno.io/kubernetes-version: 1.26-1.27policies.kyverno.io/description: Velero allows on backup and restore operations and is designed to be run with full cluster admin permissions. It allows on cross namespace restore operations, which means you can restore backup of namespace A to namespace B. This policy protect restore operation into system or any protected namespaces, listed in deny condition section. It checks the Restore CRD object and its namespaceMapping field. If destination match protected namespace then operation fails and warning message is throw.spec:validationFailureAction: Auditbackground: falserules:- name: block-velero-restore-to-protected-namespacematch:any:- resources:kinds:- velero.io/v1/Restoreoperations:- CREATE- UPDATEvalidate:cel:variables:- name: namespaceMappingValuesexpression: "has(object.spec.namespaceMapping) ? object.spec.namespaceMapping.map(nsmap, object.spec.namespaceMapping[nsmap]) : []"expressions:- expression: "!variables.namespaceMappingValues.exists(val, val in ['kube-system', 'kube-node-lease'])"messageExpression: "'Warning! Restore to protected namespace: ' + variables.namespaceMappingValues.join(', ') + ' is not allowed!'"
This policy performs some best practices validation on Application fields. Path or chart must be specified but never both. And destination.name or destination.server must be specified but never both.
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.