All Policies

Verify Git Repositories in CEL expressions

Ensures that Git repositories used for Flux deployments in a cluster originate from a specific, trusted organization. Prevents the use of untrusted or potentially risky Git repositories. Protects the integrity and security of Flux deployments.

Policy Definition

/flux-cel/verify-git-repositories/verify-git-repositories.yaml

 1apiVersion: kyverno.io/v1
 2kind: ClusterPolicy
 3metadata:
 4  name: verify-git-repositories
 5  annotations:
 6    policies.kyverno.io/title: Verify Git Repositories in CEL expressions
 7    policies.kyverno.io/category: Flux in CEL 
 8    policies.kyverno.io/severity: medium
 9    policies.kyverno.io/minversion: 1.11.0
10    kyverno.io/kubernetes-version: "1.26-1.27"
11    policies.kyverno.io/subject: GitRepository
12    policies.kyverno.io/description: >-
13      Ensures that Git repositories used for Flux deployments
14      in a cluster originate from a specific, trusted organization.
15      Prevents the use of untrusted or potentially risky Git repositories.
16      Protects the integrity and security of Flux deployments.
17spec:  
18  validationFailureAction: Audit
19  rules:
20    - name: github-repositories-only
21      match:
22        any:
23        - resources:
24            kinds:
25              - GitRepository
26            operations:
27            - CREATE
28            - UPDATE
29      exclude:
30        any:
31        - resources:
32            namespaces:
33              - flux-system
34      validate:
35        cel:
36          expressions:
37            - expression: "object.spec.url.startsWith('https://github.com/fluxcd/') || object.spec.url.startsWith('ssh://git@github.com:fluxcd/')"
38              message: .spec.url must be from a repository within the organisation X