Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,27 @@ jobs:
with:
path: velero-mpol

velero-vpol:
needs: kubernetes-matrix
strategy:
fail-fast: false
matrix:
k8s-version: ${{ fromJSON(needs.kubernetes-matrix.outputs.versions) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Environment
uses: ./.github/actions/setup-env
with:
k8s-version: ${{ matrix.k8s-version }}
node-image: ${{ fromJSON(needs.kubernetes-matrix.outputs.images)[matrix.k8s-version] }}
kind-version: ${{ needs.kubernetes-matrix.outputs.kind-version }}
- name: Run Tests
uses: ./.github/actions/run-tests
with:
path: velero-vpol

flux-vpol:
needs: kubernetes-matrix
strategy:
Expand Down Expand Up @@ -520,6 +541,7 @@ jobs:
- psa-mpol
- psp-migration-mpol
- velero-mpol
- velero-vpol
- flux-vpol
runs-on: ubuntu-latest
if: ${{ success() }}
Expand Down Expand Up @@ -551,6 +573,7 @@ jobs:
- psa-mpol
- psp-migration-mpol
- velero-mpol
- velero-vpol
- flux-vpol
runs-on: ubuntu-latest
if: ${{ failure() || cancelled() }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: velero.io/v1
kind: Schedule
metadata:
name: badschedule01
spec:
schedule: 0 7 * * * *
template:
includedNamespaces:
- 'default'
---
apiVersion: velero.io/v1
kind: Schedule
metadata:
name: badschedule02
spec:
schedule: 0 7 * */ *
template:
includedNamespaces:
- 'default'
---
apiVersion: velero.io/v1
kind: Schedule
metadata:
name: badschedule03
spec:
schedule: 0 24 * * *
template:
includedNamespaces:
- 'default'
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
creationTimestamp: null
name: validate-cron-schedule
spec:
template: false
steps:
- name: step-01
try:
- assert:
file: crd-assert.yaml
- apply:
file: rbac.yaml
- name: step-02
try:
- apply:
file: ../validate-cron-schedule.yaml
- patch:
resource:
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: validate-cron-schedule
spec:
validationActions: [Deny]
- assert:
file: policy-ready.yaml
- name: step-03
try:
- apply:
file: good-schedule.yaml
- apply:
expect:
- check:
($error != null): true
file: bad-schedule.yaml
13 changes: 13 additions & 0 deletions velero-vpol/validate-cron-schedule/.chainsaw-test/crd-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: schedules.velero.io
spec: {}
status:
acceptedNames:
kind: Schedule
listKind: ScheduleList
plural: schedules
singular: schedule
storedVersions:
- v1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: velero.io/v1
kind: Schedule
metadata:
name: goodschedule01
spec:
schedule: 0 7 * * *
template:
includedNamespaces:
- '*'
excludedNamespaces:
- some-namespace
---
apiVersion: velero.io/v1
kind: Schedule
metadata:
name: goodschedule02
spec:
schedule: '*/15 0-6 1,15 * 1-5'
template:
includedNamespaces:
- 'default'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: validate-cron-schedule
status:
conditionStatus:
(conditions[?type == 'RBACPermissionsGranted']):
- message: Policy is ready for reporting.
reason: Succeeded
status: "True"
(conditions[?type == 'WebhookConfigured']):
- message: Webhook configured.
reason: Succeeded
status: "True"
type: WebhookConfigured
21 changes: 21 additions & 0 deletions velero-vpol/validate-cron-schedule/.chainsaw-test/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kyverno:aggregate-to-admission-controller:velero-validate-cron-schedule
labels:
rbac.kyverno.io/aggregate-to-admission-controller: "true"
rules:
- apiGroups: [velero.io]
resources: [schedules]
verbs: [get, list, watch]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kyverno:aggregate-to-reports-controller:velero-validate-cron-schedule
labels:
rbac.kyverno.io/aggregate-to-reports-controller: "true"
rules:
- apiGroups: [velero.io]
resources: [schedules]
verbs: [get, list, watch]
23 changes: 23 additions & 0 deletions velero-vpol/validate-cron-schedule/.kyverno-test/kyverno-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: cli.kyverno.io/v1alpha1
kind: Test
metadata:
name: validate-cron-schedule
policies:
- ../validate-cron-schedule.yaml
resources:
- ../.chainsaw-test/bad-schedule.yaml
- ../.chainsaw-test/good-schedule.yaml
results:
- policy: validate-cron-schedule
kind: Schedule
resources:
- badschedule01
- badschedule02
- badschedule03
result: fail
- policy: validate-cron-schedule
kind: Schedule
resources:
- goodschedule01
- goodschedule02
result: pass
23 changes: 23 additions & 0 deletions velero-vpol/validate-cron-schedule/artifacthub-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: validate-cron-schedule-vpol
version: 1.0.0
displayName: Validate Cron Schedule in CEL expressions
description: >-
A Velero Schedule is given in Cron format and must be accurate to ensure operation. This policy validates that the schedule is a valid Cron format.
install: |-
```shell
kubectl apply -f https://raw.githubusercontent.com/kyverno/policies/main/velero-vpol/validate-cron-schedule/validate-cron-schedule.yaml
```
keywords:
- velero
- kyverno
- CEL Expressions
readme: |
A Velero Schedule is given in Cron format and must be accurate to ensure operation. This policy validates that the schedule is a valid Cron format.

Refer to the documentation for more details on Kyverno annotations: https://artifacthub.io/docs/topics/annotations/kyverno/
annotations:
kyverno/category: "Velero in CEL"
kyverno/kubernetesVersion: "1.34-1.35"
kyverno/subject: "Schedule"
digest: caa5f1e5bb9a77e57d2ef4279e2b174e5cb54ce75f6f7d1e9a9621ee77b6aabf
createdAt: "2026-11-21T09:24:20Z"
31 changes: 31 additions & 0 deletions velero-vpol/validate-cron-schedule/validate-cron-schedule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: validate-cron-schedule
annotations:
policies.kyverno.io/title: Validate Schedule in CEL expressions
policies.kyverno.io/category: Velero in CEL
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Schedule
kyverno.io/kyverno-version: 1.17.0
policies.kyverno.io/minversion: 1.17.0
kyverno.io/kubernetes-version: "1.34-1.35"
policies.kyverno.io/description: >-
A Velero Schedule is given in Cron format and must be accurate to ensure
operation. This policy validates that the schedule is a valid Cron format.
spec:
validationActions:
- Audit
evaluation:
background:
enabled: true
matchConstraints:
resourceRules:
- apiGroups: ["velero.io"]
apiVersions: [v1]
operations: [CREATE, UPDATE]
resources: [schedules]
validations:
- message: The backup schedule must be in a valid cron format.
expression: >-
object.spec.schedule.matches('^((?:\\*|[0-5]?[0-9](?:(?:-[0-5]?[0-9])|(?:,[0-5]?[0-9])+)?)(?:\\/[0-9]+)?)\\s+((?:\\*|(?:1?[0-9]|2[0-3])(?:(?:-(?:1?[0-9]|2[0-3]))|(?:,(?:1?[0-9]|2[0-3]))+)?)(?:\\/[0-9]+)?)\\s+((?:\\*|(?:[1-9]|[1-2][0-9]|3[0-1])(?:(?:-(?:[1-9]|[1-2][0-9]|3[0-1]))|(?:,(?:[1-9]|[1-2][0-9]|3[0-1]))+)?)(?:\\/[0-9]+)?)\\s+((?:\\*|(?:[1-9]|1[0-2])(?:(?:-(?:[1-9]|1[0-2]))|(?:,(?:[1-9]|1[0-2]))+)?)(?:\\/[0-9]+)?)\\s+((?:\\*|[0-7](?:-[0-7]|(?:,[0-7])+)?)(?:\\/[0-9]+)?)$')
Loading