Rather than a simple check to see if given metadata such as labels and annotations are present, in some cases they need to be present and the values match a specified regular expression. This policy illustrates how to ensure a label with key `corp.org/version` is both present and matches a given regex, in this case ensuring semver is met.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: metadata-match-regexannotations:policies.kyverno.io/title: Metadata Matches Regex in CEL expressionspolicies.kyverno.io/category: Other in CELpolicies.kyverno.io/severity: mediumpolicies.kyverno.io/subject: Pod, Labelpolicies.kyverno.io/minversion: 1.11.0kyverno.io/kubernetes-version: 1.26-1.27policies.kyverno.io/description: Rather than a simple check to see if given metadata such as labels and annotations are present, in some cases they need to be present and the values match a specified regular expression. This policy illustrates how to ensure a label with key `corp.org/version` is both present and matches a given regex, in this case ensuring semver is met.spec:validationFailureAction: Auditbackground: falserules:- name: check-for-regexmatch:any:- resources:kinds:- Podoperations:- CREATE- UPDATEvalidate:cel:expressions:- expression: object.metadata.?labels[?'corp.org/version'].orValue('default').matches('^v[0-9].[0-9].[0-9]$')message: "The label `corp.org/version` is required and must match the specified regex: ^v[0-9].[0-9].[0-9]$"
This policy prevents the use of the default project in an Application.
Services of type LoadBalancer when deployed inside AWS have support for transport encryption if it is enabled via an annotation. This policy requires that Services of type LoadBalancer contain the annotation service.beta.kubernetes.io/aws-load-balancer-ssl-cert with some value.
This policy prevents updates to the project field after an Application is created.