Skip to content

Commit a63d9ff

Browse files
authored
Merge pull request #1513 from jvanz/issue1201
feat(controller): flag to allow policies in kubewarden namespace
2 parents 1164761 + d75353b commit a63d9ff

18 files changed

Lines changed: 200 additions & 19 deletions

api/policies/v1/admissionpolicy_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ func (r *AdmissionPolicy) GetNamespaceSelector() *metav1.LabelSelector {
133133
}
134134
}
135135

136+
func (r *AdmissionPolicy) GetAllowInsideKubewardenNamespace() bool {
137+
return false
138+
}
139+
136140
func (r *AdmissionPolicy) GetObjectSelector() *metav1.LabelSelector {
137141
return r.Spec.ObjectSelector
138142
}

api/policies/v1/admissionpolicygroup_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (r *AdmissionPolicyGroup) GetNamespaceSelector() *metav1.LabelSelector {
157157
}
158158
}
159159

160+
func (r *AdmissionPolicyGroup) GetAllowInsideKubewardenNamespace() bool {
161+
return false
162+
}
163+
160164
func (r *AdmissionPolicyGroup) GetObjectSelector() *metav1.LabelSelector {
161165
return r.Spec.ObjectSelector
162166
}

api/policies/v1/clusteradmissionpolicy_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ type ClusterAdmissionPolicySpec struct {
8888
// the policy is assigned to.
8989
// +optional
9090
ContextAwareResources []ContextAwareResource `json:"contextAwareResources,omitempty"`
91+
92+
// AllowInsideKubewardenNamespace controls whether the policy should also be
93+
// evaluated for resources in the namespace where Kubewarden is deployed.
94+
// By default (false), an exclusion rule is added to the webhook so that the
95+
// Kubewarden namespace is never targeted, protecting against an accidental
96+
// lockout. Set this to true only if you deliberately want the policy to apply
97+
// inside the Kubewarden namespace.
98+
// Warning: setting this to true may cause a deadlock if the policy prevents
99+
// Kubewarden components from starting.
100+
// +optional
101+
AllowInsideKubewardenNamespace bool `json:"allowInsideKubewardenNamespace,omitempty"`
91102
}
92103

93104
// ClusterAdmissionPolicy is the Schema for the clusteradmissionpolicies API
@@ -212,6 +223,10 @@ func (r *ClusterAdmissionPolicy) GetContextAwareResources() []ContextAwareResour
212223
return r.Spec.ContextAwareResources
213224
}
214225

226+
func (r *ClusterAdmissionPolicy) GetAllowInsideKubewardenNamespace() bool {
227+
return r.Spec.AllowInsideKubewardenNamespace
228+
}
229+
215230
func (r *ClusterAdmissionPolicy) GetBackgroundAudit() bool {
216231
return r.Spec.BackgroundAudit
217232
}

api/policies/v1/clusteradmissionpolicygroup_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ type ClusterAdmissionPolicyGroupSpec struct {
8383
// Default to the empty LabelSelector, which matches everything.
8484
// +optional
8585
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
86+
87+
// AllowInsideKubewardenNamespace controls whether the policy should also be
88+
// evaluated for resources in the namespace where Kubewarden is deployed.
89+
// By default (false), an exclusion rule is added to the webhook so that the
90+
// Kubewarden namespace is never targeted, protecting against an accidental
91+
// lockout. Set this to true only if you deliberately want the policy to apply
92+
// inside the Kubewarden namespace.
93+
// Warning: setting this to true may cause a deadlock if the policy prevents
94+
// Kubewarden components from starting.
95+
// +optional
96+
AllowInsideKubewardenNamespace bool `json:"allowInsideKubewardenNamespace,omitempty"`
8697
}
8798

8899
// ClusterAdmissionPolicyGroup is the Schema for the clusteradmissionpolicies API
@@ -198,6 +209,10 @@ func (r *ClusterAdmissionPolicyGroup) GetNamespaceSelector() *metav1.LabelSelect
198209
return r.Spec.NamespaceSelector
199210
}
200211

212+
func (r *ClusterAdmissionPolicyGroup) GetAllowInsideKubewardenNamespace() bool {
213+
return r.Spec.AllowInsideKubewardenNamespace
214+
}
215+
201216
func (r *ClusterAdmissionPolicyGroup) GetObjectSelector() *metav1.LabelSelector {
202217
return r.Spec.ObjectSelector
203218
}

api/policies/v1/factories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
const (
17-
integrationTestsFinalizer = "integration-tests-safety-net-finalizer"
17+
integrationTestsFinalizer = "kubewarden.io/integration-tests-safety-net-finalizer"
1818
defaultKubewardenRepository = "ghcr.io/kubewarden/policy-server"
1919
maxNameSuffixLength = 8
2020
defaultPolicyGroupRejectionMessage = "policy group default rejection message"

api/policies/v1/policy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type PolicySelectors interface {
118118
GetNamespaceSelector() *metav1.LabelSelector
119119
GetObjectSelector() *metav1.LabelSelector
120120
GetObjectMeta() *metav1.ObjectMeta
121+
GetAllowInsideKubewardenNamespace() bool
121122
}
122123

123124
// +kubebuilder:object:generate:=false

charts/kubewarden-crds/templates/clusteradmissionpolicies.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: apiextensions.k8s.io/v1
23
kind: CustomResourceDefinition
34
metadata:
@@ -77,6 +78,17 @@ spec:
7778
spec:
7879
description: ClusterAdmissionPolicySpec defines the desired state of ClusterAdmissionPolicy.
7980
properties:
81+
allowInsideKubewardenNamespace:
82+
description: |-
83+
AllowInsideKubewardenNamespace controls whether the policy should also be
84+
evaluated for resources in the namespace where Kubewarden is deployed.
85+
By default (false), an exclusion rule is added to the webhook so that the
86+
Kubewarden namespace is never targeted, protecting against an accidental
87+
lockout. Set this to true only if you deliberately want the policy to apply
88+
inside the Kubewarden namespace.
89+
Warning: setting this to true may cause a deadlock if the policy prevents
90+
Kubewarden components from starting.
91+
type: boolean
8092
backgroundAudit:
8193
default: true
8294
description: |-

charts/kubewarden-crds/templates/clusteradmissionpolicygroups.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: apiextensions.k8s.io/v1
23
kind: CustomResourceDefinition
34
metadata:
@@ -78,6 +79,17 @@ spec:
7879
description: ClusterAdmissionPolicyGroupSpec defines the desired state
7980
of ClusterAdmissionPolicyGroup.
8081
properties:
82+
allowInsideKubewardenNamespace:
83+
description: |-
84+
AllowInsideKubewardenNamespace controls whether the policy should also be
85+
evaluated for resources in the namespace where Kubewarden is deployed.
86+
By default (false), an exclusion rule is added to the webhook so that the
87+
Kubewarden namespace is never targeted, protecting against an accidental
88+
lockout. Set this to true only if you deliberately want the policy to apply
89+
inside the Kubewarden namespace.
90+
Warning: setting this to true may cause a deadlock if the policy prevents
91+
Kubewarden components from starting.
92+
type: boolean
8193
backgroundAudit:
8294
default: true
8395
description: |-

config/crd/bases/policies.kubewarden.io_clusteradmissionpolicies.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ spec:
7878
spec:
7979
description: ClusterAdmissionPolicySpec defines the desired state of ClusterAdmissionPolicy.
8080
properties:
81+
allowInsideKubewardenNamespace:
82+
description: |-
83+
AllowInsideKubewardenNamespace controls whether the policy should also be
84+
evaluated for resources in the namespace where Kubewarden is deployed.
85+
By default (false), an exclusion rule is added to the webhook so that the
86+
Kubewarden namespace is never targeted, protecting against an accidental
87+
lockout. Set this to true only if you deliberately want the policy to apply
88+
inside the Kubewarden namespace.
89+
Warning: setting this to true may cause a deadlock if the policy prevents
90+
Kubewarden components from starting.
91+
type: boolean
8192
backgroundAudit:
8293
default: true
8394
description: |-

config/crd/bases/policies.kubewarden.io_clusteradmissionpolicygroups.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ spec:
7979
description: ClusterAdmissionPolicyGroupSpec defines the desired state
8080
of ClusterAdmissionPolicyGroup.
8181
properties:
82+
allowInsideKubewardenNamespace:
83+
description: |-
84+
AllowInsideKubewardenNamespace controls whether the policy should also be
85+
evaluated for resources in the namespace where Kubewarden is deployed.
86+
By default (false), an exclusion rule is added to the webhook so that the
87+
Kubewarden namespace is never targeted, protecting against an accidental
88+
lockout. Set this to true only if you deliberately want the policy to apply
89+
inside the Kubewarden namespace.
90+
Warning: setting this to true may cause a deadlock if the policy prevents
91+
Kubewarden components from starting.
92+
type: boolean
8293
backgroundAudit:
8394
default: true
8495
description: |-

0 commit comments

Comments
 (0)