diff --git a/infrastructure/ontime-operator/namespace-prefix-policy.yaml b/infrastructure/ontime-operator/namespace-prefix-policy.yaml index 6db1f9f..42210ca 100644 --- a/infrastructure/ontime-operator/namespace-prefix-policy.yaml +++ b/infrastructure/ontime-operator/namespace-prefix-policy.yaml @@ -41,7 +41,7 @@ spec: resourceRules: - apiGroups: ["cloud.getontime.no"] apiVersions: ["v1"] - operations: ["CREATE", "UPDATE", "DELETE"] + operations: ["CREATE", "UPDATE"] resources: ["stages"] matchConditions: - name: 'only-stage-editor' @@ -61,5 +61,38 @@ spec: resourceRules: - apiGroups: ["cloud.getontime.no"] apiVersions: ["v1"] - operations: ["CREATE", "UPDATE", "DELETE"] + operations: ["CREATE", "UPDATE"] + resources: ["stages"] +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicy +metadata: + name: "force-stage-ns-prefix-for-stage-editor-delete" +spec: + failurePolicy: Fail + matchConstraints: + resourceRules: + - apiGroups: ["cloud.getontime.no"] + apiVersions: ["v1"] + operations: ["DELETE"] + resources: ["stages"] + matchConditions: + - name: 'only-stage-editor' + expression: "request.userInfo.username == 'system:serviceaccount:ontime-operator:stage-editor'" + validations: + - expression: "request.namespace.startsWith('team-')" + message: "Stages must be created in namespaces starting with 'team-'" +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicyBinding +metadata: + name: "force-stage-ns-prefix-for-stage-editor-delete-binding" +spec: + policyName: "force-stage-ns-prefix-for-stage-editor-delete" + validationActions: [Deny] + matchResources: + resourceRules: + - apiGroups: ["cloud.getontime.no"] + apiVersions: ["v1"] + operations: ["DELETE"] resources: ["stages"] \ No newline at end of file