diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b0e763d1c5528ea011e7711cb50f89b5e13019b0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.0/template.yaml @@ -0,0 +1,57 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sreplicalimits + annotations: + metadata.gatekeeper.sh/title: "Replica Limits" + metadata.gatekeeper.sh/version: 1.0.0 + description: >- + Requires that objects with the field `spec.replicas` (Deployments, + ReplicaSets, etc.) specify a number of replicas within defined ranges. +spec: + crd: + spec: + names: + kind: K8sReplicaLimits + validation: + # Schema for the `parameters` field + openAPIV3Schema: + type: object + properties: + ranges: + type: array + description: Allowed ranges for numbers of replicas. Values are inclusive. + items: + type: object + description: A range of allowed replicas. Values are inclusive. + properties: + min_replicas: + description: The minimum number of replicas allowed, inclusive. + type: integer + max_replicas: + description: The maximum number of replicas allowed, inclusive. + type: integer + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sreplicalimits + + deployment_name = input.review.object.metadata.name + + violation[{"msg": msg}] { + spec := input.review.object.spec + not input_replica_limit(spec) + msg := sprintf("The provided number of replicas is not allowed for deployment: %v. Allowed ranges: %v", [deployment_name, input.parameters]) + } + + input_replica_limit(spec) { + provided := input.review.object.spec.replicas + count(input.parameters.ranges) > 0 + range := input.parameters.ranges[_] + value_within_range(range, provided) + } + + value_within_range(range, value) { + range.min_replicas <= value + range.max_replicas >= value + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..91893619a6b2e3fcd4d8e8bfea96298b9682a0c5 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.1 +name: k8sreplicalimits +displayName: Replica Limits +createdAt: "2023-03-31T20:34:16Z" +description: Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges. +digest: a8dc0e94f30cdf1f4aff2e69551744b6eaee3f4e60dba3393705f81363a249e5 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/replicalimits +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Replica Limits + Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/replicalimits/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b496235f3abecf1f55185ee32974d0b6bf849b28 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sReplicaLimits +metadata: + name: replica-limits +spec: + match: + kinds: + - apiGroups: ["apps"] + kinds: ["Deployment"] + parameters: + ranges: + - min_replicas: 3 + max_replicas: 50 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f5a2b1d8c2fd4efcb4323e0eb6dd7148e45a8446 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_allowed.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: allowed-deployment +spec: + selector: + matchLabels: + app: nginx + replicas: 3 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1c4899d20e766d2cbea6152ca77febbaf97544bf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_disallowed.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: disallowed-deployment +spec: + selector: + matchLabels: + app: nginx + replicas: 100 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..598efb81493053c2a1364d030f70c88e75467a14 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/suite.yaml @@ -0,0 +1,17 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: replicalimits +tests: +- name: replica-limit + template: template.yaml + constraint: samples/replicalimits/constraint.yaml + cases: + - name: example-allowed + object: samples/replicalimits/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/replicalimits/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..540abc67f290fab77b8c687c70d22489298acd8c --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/template.yaml @@ -0,0 +1,58 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sreplicalimits + annotations: + metadata.gatekeeper.sh/title: "Replica Limits" + metadata.gatekeeper.sh/version: 1.0.1 + description: >- + Requires that objects with the field `spec.replicas` (Deployments, + ReplicaSets, etc.) specify a number of replicas within defined ranges. +spec: + crd: + spec: + names: + kind: K8sReplicaLimits + validation: + # Schema for the `parameters` field + openAPIV3Schema: + type: object + properties: + ranges: + type: array + description: Allowed ranges for numbers of replicas. Values are inclusive. + items: + type: object + description: A range of allowed replicas. Values are inclusive. + properties: + min_replicas: + description: The minimum number of replicas allowed, inclusive. + type: integer + max_replicas: + description: The maximum number of replicas allowed, inclusive. + type: integer + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sreplicalimits + + object_name = input.review.object.metadata.name + object_kind = input.review.kind.kind + + violation[{"msg": msg}] { + spec := input.review.object.spec + not input_replica_limit(spec) + msg := sprintf("The provided number of replicas is not allowed for %v: %v. Allowed ranges: %v", [object_kind, object_name, input.parameters]) + } + + input_replica_limit(spec) { + provided := input.review.object.spec.replicas + count(input.parameters.ranges) > 0 + range := input.parameters.ranges[_] + value_within_range(range, provided) + } + + value_within_range(range, value) { + range.min_replicas <= value + range.max_replicas >= value + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..3b46cf79829b2d206889162a093dcf846b56e601 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.2 +name: k8sreplicalimits +displayName: Replica Limits +createdAt: "2023-10-30T21:00:00Z" +description: Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges. +digest: 858bf59f6c7408f2fb390a181b2f6db5e4d8fbe5eb580aa45b5601d6ae2d4064 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/replicalimits +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Replica Limits + Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/replicalimits/1.0.2/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b496235f3abecf1f55185ee32974d0b6bf849b28 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sReplicaLimits +metadata: + name: replica-limits +spec: + match: + kinds: + - apiGroups: ["apps"] + kinds: ["Deployment"] + parameters: + ranges: + - min_replicas: 3 + max_replicas: 50 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f5a2b1d8c2fd4efcb4323e0eb6dd7148e45a8446 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_allowed.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: allowed-deployment +spec: + selector: + matchLabels: + app: nginx + replicas: 3 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1c4899d20e766d2cbea6152ca77febbaf97544bf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_disallowed.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: disallowed-deployment +spec: + selector: + matchLabels: + app: nginx + replicas: 100 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..598efb81493053c2a1364d030f70c88e75467a14 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/suite.yaml @@ -0,0 +1,17 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: replicalimits +tests: +- name: replica-limit + template: template.yaml + constraint: samples/replicalimits/constraint.yaml + cases: + - name: example-allowed + object: samples/replicalimits/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/replicalimits/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2e44fb2c12693eb66dcb5ddbdb7378ee59d90699 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/template.yaml @@ -0,0 +1,58 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sreplicalimits + annotations: + metadata.gatekeeper.sh/title: "Replica Limits" + metadata.gatekeeper.sh/version: 1.0.2 + description: >- + Requires that objects with the field `spec.replicas` (Deployments, + ReplicaSets, etc.) specify a number of replicas within defined ranges. +spec: + crd: + spec: + names: + kind: K8sReplicaLimits + validation: + # Schema for the `parameters` field + openAPIV3Schema: + type: object + properties: + ranges: + type: array + description: Allowed ranges for numbers of replicas. Values are inclusive. + items: + type: object + description: A range of allowed replicas. Values are inclusive. + properties: + min_replicas: + description: The minimum number of replicas allowed, inclusive. + type: integer + max_replicas: + description: The maximum number of replicas allowed, inclusive. + type: integer + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sreplicalimits + + object_name = input.review.object.metadata.name + object_kind = input.review.kind.kind + + violation[{"msg": msg}] { + spec := input.review.object.spec + not input_replica_limit(spec) + msg := sprintf("The provided number of replicas is not allowed for %v: %v. Allowed ranges: %v", [object_kind, object_name, input.parameters]) + } + + input_replica_limit(spec) { + provided := spec.replicas + count(input.parameters.ranges) > 0 + range := input.parameters.ranges[_] + value_within_range(range, provided) + } + + value_within_range(range, value) { + range.min_replicas <= value + range.max_replicas >= value + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..97858fcf62c811eb8204867c6b2c8e2f93f3fd21 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.0 +name: k8srequiredannotations +displayName: Required Annotations +createdAt: "2022-09-26T17:28:27Z" +description: Requires resources to contain specified annotations, with values matching provided regular expressions. +digest: c4074e5cb8cc492504676bb95bbb9e588745f682949911f99e0b750df0cb3b15 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredannotations +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Annotations + Requires resources to contain specified annotations, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredannotations/1.0.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..033700136def31d98a72719095fc1cbba23d0d3a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/constraint.yaml @@ -0,0 +1,18 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredAnnotations +metadata: + name: all-must-have-certain-set-of-annotations +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Service"] + parameters: + message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations." + annotations: + - key: a8r.io/owner + # Matches email address or github user + allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$ + - key: a8r.io/runbook + # Matches urls including or not http/https + allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$ diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b3b9f95ade50729e64e7e9df0b66151da183461b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/example_allowed.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: allowed-service + annotations: + a8r.io/owner: "dev-team-alfa@contoso.com" + a8r.io/runbook: "https://confluence.contoso.com/dev-team-alfa/runbooks" +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app: foo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62c01b87756f34cdc69e7b420ee2c1824ba5c37c --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: disallowed-service +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app: foo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..48bf7303a725e43c517e38390677e57182eba6ec --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/suite.yaml @@ -0,0 +1,17 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredannotations +tests: +- name: must-have-set-of-annotations + template: template.yaml + constraint: samples/all-must-have-certain-set-of-annotations/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-certain-set-of-annotations/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f4a15e9306bf42ac6c028e2a88679cf54d0ca550 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/template.yaml @@ -0,0 +1,59 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredannotations + annotations: + metadata.gatekeeper.sh/title: "Required Annotations" + metadata.gatekeeper.sh/version: 1.0.0 + description: >- + Requires resources to contain specified annotations, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredAnnotations + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + annotations: + type: array + description: >- + A list of annotations and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required annotation. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8srequiredannotations + + violation[{"msg": msg, "details": {"missing_annotations": missing}}] { + provided := {annotation | input.review.object.metadata.annotations[annotation]} + required := {annotation | annotation := input.parameters.annotations[_].key} + missing := required - provided + count(missing) > 0 + msg := sprintf("you must provide annotation(s): %v", [missing]) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.annotations[key] + expected := input.parameters.annotations[_] + expected.key == key + expected.allowedRegex != "" + not re_match(expected.allowedRegex, value) + msg := sprintf("Annotation <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..424fe5cc168833911bb82a0f88add047281e0aeb --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.1 +name: k8srequiredannotations +displayName: Required Annotations +createdAt: "2023-10-30T21:00:00Z" +description: Requires resources to contain specified annotations, with values matching provided regular expressions. +digest: 332839ec5e037ea20aa5b9a204ad2490ad76d05f5d2b961ace5e90c7b8c864be +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredannotations +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Annotations + Requires resources to contain specified annotations, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredannotations/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..033700136def31d98a72719095fc1cbba23d0d3a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/constraint.yaml @@ -0,0 +1,18 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredAnnotations +metadata: + name: all-must-have-certain-set-of-annotations +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Service"] + parameters: + message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations." + annotations: + - key: a8r.io/owner + # Matches email address or github user + allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$ + - key: a8r.io/runbook + # Matches urls including or not http/https + allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$ diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b3b9f95ade50729e64e7e9df0b66151da183461b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/example_allowed.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: allowed-service + annotations: + a8r.io/owner: "dev-team-alfa@contoso.com" + a8r.io/runbook: "https://confluence.contoso.com/dev-team-alfa/runbooks" +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app: foo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..62c01b87756f34cdc69e7b420ee2c1824ba5c37c --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: disallowed-service +spec: + ports: + - name: http + port: 80 + targetPort: 8080 + selector: + app: foo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..48bf7303a725e43c517e38390677e57182eba6ec --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/suite.yaml @@ -0,0 +1,17 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredannotations +tests: +- name: must-have-set-of-annotations + template: template.yaml + constraint: samples/all-must-have-certain-set-of-annotations/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-certain-set-of-annotations/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..634acb1812c29e6b6f2a57cdaa5e923b8b1d6827 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/template.yaml @@ -0,0 +1,59 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredannotations + annotations: + metadata.gatekeeper.sh/title: "Required Annotations" + metadata.gatekeeper.sh/version: 1.0.1 + description: >- + Requires resources to contain specified annotations, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredAnnotations + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + annotations: + type: array + description: >- + A list of annotations and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required annotation. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8srequiredannotations + + violation[{"msg": msg, "details": {"missing_annotations": missing}}] { + provided := {annotation | input.review.object.metadata.annotations[annotation]} + required := {annotation | annotation := input.parameters.annotations[_].key} + missing := required - provided + count(missing) > 0 + msg := sprintf("you must provide annotation(s): %v", [missing]) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.annotations[key] + expected := input.parameters.annotations[_] + expected.key == key + expected.allowedRegex != "" + not regex.match(expected.allowedRegex, value) + msg := sprintf("Annotation <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..dfa7d5fc29d628f99e0732cf60fa9f450d86579e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.0 +name: k8srequiredlabels +displayName: Required Labels +createdAt: "2022-09-26T17:28:27Z" +description: Requires resources to contain specified labels, with values matching provided regular expressions. +digest: e0f96d5945642406b067a22f152dcf76ac038a8d4f0969668c7e70c2471731db +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Labels + Requires resources to contain specified labels, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.0.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..806e9862ffc696b1ac6b12813501be854cbccdaf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/constraint.yaml @@ -0,0 +1,14 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredLabels +metadata: + name: all-must-have-owner +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Namespace"] + parameters: + message: "All namespaces must have an `owner` label that points to your company username" + labels: + - key: owner + allowedRegex: "^[a-zA-Z]+.agilebank.demo$" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e2d3b9c032ad16eea45ffd913e6632cb60c1875f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_allowed.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: allowed-namespace + labels: + owner: user.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a7a53610a762f25250aa2ea9ddbf13aa900996d3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_disallowed.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..64c5b4130fd473d35a5a3ab6f7f4126f90ccab31 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/suite.yaml @@ -0,0 +1,17 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredlabels +tests: +- name: must-have-owner + template: template.yaml + constraint: samples/all-must-have-owner/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-owner/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-owner/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..77323da6780017ea744665d23b58bfc82dc2780c --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/template.yaml @@ -0,0 +1,71 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredlabels + annotations: + metadata.gatekeeper.sh/title: "Required Labels" + metadata.gatekeeper.sh/version: 1.0.0 + description: >- + Requires resources to contain specified labels, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredLabels + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + labels: + type: array + description: >- + A list of labels and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required label. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8srequiredlabels + + get_message(parameters, _default) = msg { + not parameters.message + msg := _default + } + + get_message(parameters, _default) = msg { + msg := parameters.message + } + + violation[{"msg": msg, "details": {"missing_labels": missing}}] { + provided := {label | input.review.object.metadata.labels[label]} + required := {label | label := input.parameters.labels[_].key} + missing := required - provided + count(missing) > 0 + def_msg := sprintf("you must provide labels: %v", [missing]) + msg := get_message(input.parameters, def_msg) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.labels[key] + expected := input.parameters.labels[_] + expected.key == key + # do not match if allowedRegex is not defined, or is an empty string + expected.allowedRegex != "" + not re_match(expected.allowedRegex, value) + def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + msg := get_message(input.parameters, def_msg) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..c8a953a27bf533765bb03c9fd1413c5f35be9ba8 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.1 +name: k8srequiredlabels +displayName: Required Labels +createdAt: "2023-10-30T21:00:00Z" +description: Requires resources to contain specified labels, with values matching provided regular expressions. +digest: aa4cbb2bbaba13b310108f7944ba8200c0adbaf865f8f3dfd7cbdc3c760b5eea +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Labels + Requires resources to contain specified labels, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..806e9862ffc696b1ac6b12813501be854cbccdaf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/constraint.yaml @@ -0,0 +1,14 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredLabels +metadata: + name: all-must-have-owner +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Namespace"] + parameters: + message: "All namespaces must have an `owner` label that points to your company username" + labels: + - key: owner + allowedRegex: "^[a-zA-Z]+.agilebank.demo$" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e2d3b9c032ad16eea45ffd913e6632cb60c1875f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_allowed.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: allowed-namespace + labels: + owner: user.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a7a53610a762f25250aa2ea9ddbf13aa900996d3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_disallowed.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..64c5b4130fd473d35a5a3ab6f7f4126f90ccab31 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/suite.yaml @@ -0,0 +1,17 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredlabels +tests: +- name: must-have-owner + template: template.yaml + constraint: samples/all-must-have-owner/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-owner/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-owner/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..aa865394c60c4fbb73280a4aa133d3928663ca72 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/template.yaml @@ -0,0 +1,68 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredlabels + annotations: + metadata.gatekeeper.sh/title: "Required Labels" + metadata.gatekeeper.sh/version: 1.0.1 + description: >- + Requires resources to contain specified labels, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredLabels + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + labels: + type: array + description: >- + A list of labels and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required label. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8srequiredlabels + + get_message(parameters, _default) := _default { + not parameters.message + } + + get_message(parameters, _) := parameters.message + + violation[{"msg": msg, "details": {"missing_labels": missing}}] { + provided := {label | input.review.object.metadata.labels[label]} + required := {label | label := input.parameters.labels[_].key} + missing := required - provided + count(missing) > 0 + def_msg := sprintf("you must provide labels: %v", [missing]) + msg := get_message(input.parameters, def_msg) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.labels[key] + expected := input.parameters.labels[_] + expected.key == key + # do not match if allowedRegex is not defined, or is an empty string + expected.allowedRegex != "" + not regex.match(expected.allowedRegex, value) + def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + msg := get_message(input.parameters, def_msg) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..395e044610d467c7d4c56c1b8e3955bb89b3da78 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.1.0 +name: k8srequiredlabels +displayName: Required Labels +createdAt: "2024-05-10T23:29:29Z" +description: Requires resources to contain specified labels, with values matching provided regular expressions. +digest: 84897cdfe60dbe9c1726581fe0626d254477a176b143a2cff36b5cf24465e8b8 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Labels + Requires resources to contain specified labels, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.1.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..806e9862ffc696b1ac6b12813501be854cbccdaf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/constraint.yaml @@ -0,0 +1,14 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredLabels +metadata: + name: all-must-have-owner +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Namespace"] + parameters: + message: "All namespaces must have an `owner` label that points to your company username" + labels: + - key: owner + allowedRegex: "^[a-zA-Z]+.agilebank.demo$" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e2d3b9c032ad16eea45ffd913e6632cb60c1875f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_allowed.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: allowed-namespace + labels: + owner: user.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a7a53610a762f25250aa2ea9ddbf13aa900996d3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed_label_value.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed_label_value.yaml new file mode 100644 index 0000000000000000000000000000000000000000..36ae7717667a79bae5b5688957df4a70333b2520 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed_label_value.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace + labels: + owner: user diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0995d8ea0e86c61e84f161ef80402b9fe682a14a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/suite.yaml @@ -0,0 +1,21 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredlabels +tests: +- name: must-have-owner + template: template.yaml + constraint: samples/all-must-have-owner/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-owner/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-owner/example_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed-label-value + object: samples/all-must-have-owner/example_disallowed_label_value.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d1447017eb0f84acccff8e51e84dd654aa6b7f20 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/template.yaml @@ -0,0 +1,79 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredlabels + annotations: + metadata.gatekeeper.sh/title: "Required Labels" + metadata.gatekeeper.sh/version: 1.1.0 + description: >- + Requires resources to contain specified labels, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredLabels + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + labels: + type: array + description: >- + A list of labels and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required label. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + code: + - engine: K8sNativeValidation + source: + validations: + - expression: '(has(object.metadata) && variables.params.labels.all(entry, has(object.metadata.labels) && entry.key in object.metadata.labels))' + messageExpression: '"missing required label, requires all of: " + variables.params.labels.map(entry, entry.key).join(", ")' + - expression: '(has(object.metadata) && variables.params.labels.all(entry, has(object.metadata.labels) && entry.key in object.metadata.labels && string(object.metadata.labels[entry.key]).matches(string(entry.allowedRegex))))' + message: "regex mismatch" + - engine: Rego + source: + rego: | + package k8srequiredlabels + + get_message(parameters, _default) := _default { + not parameters.message + } + + get_message(parameters, _) := parameters.message + + violation[{"msg": msg, "details": {"missing_labels": missing}}] { + provided := {label | input.review.object.metadata.labels[label]} + required := {label | label := input.parameters.labels[_].key} + missing := required - provided + count(missing) > 0 + def_msg := sprintf("you must provide labels: %v", [missing]) + msg := get_message(input.parameters, def_msg) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.labels[key] + expected := input.parameters.labels[_] + expected.key == key + # do not match if allowedRegex is not defined, or is an empty string + expected.allowedRegex != "" + not regex.match(expected.allowedRegex, value) + def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + msg := get_message(input.parameters, def_msg) + } + diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..d6315eb056dfd9547ad556f5880bbe2f358cca52 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.1.1 +name: k8srequiredlabels +displayName: Required Labels +createdAt: "2024-05-24T22:47:49Z" +description: Requires resources to contain specified labels, with values matching provided regular expressions. +digest: 5cd5a196b9cee64fbf8bf792d4cee6eb193c448f43adfa6265093687c595a7aa +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Labels + Requires resources to contain specified labels, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.1.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..806e9862ffc696b1ac6b12813501be854cbccdaf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/constraint.yaml @@ -0,0 +1,14 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredLabels +metadata: + name: all-must-have-owner +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Namespace"] + parameters: + message: "All namespaces must have an `owner` label that points to your company username" + labels: + - key: owner + allowedRegex: "^[a-zA-Z]+.agilebank.demo$" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e2d3b9c032ad16eea45ffd913e6632cb60c1875f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_allowed.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: allowed-namespace + labels: + owner: user.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a7a53610a762f25250aa2ea9ddbf13aa900996d3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_disallowed.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_disallowed_label_value.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_disallowed_label_value.yaml new file mode 100644 index 0000000000000000000000000000000000000000..36ae7717667a79bae5b5688957df4a70333b2520 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/samples/all-must-have-owner/example_disallowed_label_value.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace + labels: + owner: user diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0995d8ea0e86c61e84f161ef80402b9fe682a14a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/suite.yaml @@ -0,0 +1,21 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredlabels +tests: +- name: must-have-owner + template: template.yaml + constraint: samples/all-must-have-owner/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-owner/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-owner/example_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed-label-value + object: samples/all-must-have-owner/example_disallowed_label_value.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7a47afe27d4fc58bde19b284c0c72a162c737bab --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.1/template.yaml @@ -0,0 +1,79 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredlabels + annotations: + metadata.gatekeeper.sh/title: "Required Labels" + metadata.gatekeeper.sh/version: 1.1.1 + description: >- + Requires resources to contain specified labels, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredLabels + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + labels: + type: array + description: >- + A list of labels and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required label. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + code: + - engine: K8sNativeValidation + source: + validations: + - expression: '(has(variables.anyObject.metadata) && variables.params.labels.all(entry, has(variables.anyObject.metadata.labels) && entry.key in variables.anyObject.metadata.labels))' + messageExpression: '"missing required label, requires all of: " + variables.params.labels.map(entry, entry.key).join(", ")' + - expression: '(has(variables.anyObject.metadata) && variables.params.labels.all(entry, has(variables.anyObject.metadata.labels) && entry.key in variables.anyObject.metadata.labels && string(variables.anyObject.metadata.labels[entry.key]).matches(string(entry.allowedRegex))))' + message: "regex mismatch" + - engine: Rego + source: + rego: | + package k8srequiredlabels + + get_message(parameters, _default) := _default { + not parameters.message + } + + get_message(parameters, _) := parameters.message + + violation[{"msg": msg, "details": {"missing_labels": missing}}] { + provided := {label | input.review.object.metadata.labels[label]} + required := {label | label := input.parameters.labels[_].key} + missing := required - provided + count(missing) > 0 + def_msg := sprintf("you must provide labels: %v", [missing]) + msg := get_message(input.parameters, def_msg) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.labels[key] + expected := input.parameters.labels[_] + expected.key == key + # do not match if allowedRegex is not defined, or is an empty string + expected.allowedRegex != "" + not regex.match(expected.allowedRegex, value) + def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + msg := get_message(input.parameters, def_msg) + } + diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..eb0cd9195b42a96561774045c22dd816874b1496 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.1.2 +name: k8srequiredlabels +displayName: Required Labels +createdAt: "2024-08-26T21:23:58Z" +description: Requires resources to contain specified labels, with values matching provided regular expressions. +digest: 707994cb63de5a067bc9808caa5f66eb7831a4a9a19849c7eb2bb24b112e0726 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Labels + Requires resources to contain specified labels, with values matching provided regular expressions. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.1.2/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..806e9862ffc696b1ac6b12813501be854cbccdaf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/constraint.yaml @@ -0,0 +1,14 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredLabels +metadata: + name: all-must-have-owner +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Namespace"] + parameters: + message: "All namespaces must have an `owner` label that points to your company username" + labels: + - key: owner + allowedRegex: "^[a-zA-Z]+.agilebank.demo$" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e2d3b9c032ad16eea45ffd913e6632cb60c1875f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_allowed.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: allowed-namespace + labels: + owner: user.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a7a53610a762f25250aa2ea9ddbf13aa900996d3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_disallowed.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_disallowed_label_value.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_disallowed_label_value.yaml new file mode 100644 index 0000000000000000000000000000000000000000..36ae7717667a79bae5b5688957df4a70333b2520 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/all-must-have-owner/example_disallowed_label_value.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: disallowed-namespace + labels: + owner: user diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ead40234a5fdec6916fe88ee3f4d6cfd47c54d53 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredLabels +metadata: + name: must-have-pizza +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Pod"] + parameters: + message: "All pods must have label of key `pizza` regardless of the label's value" + labels: + - key: pizza diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3a904e3336b84ec43021e70c7da04790862a9195 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/example_allowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Pod +metadata: + name: has-pizza + labels: + pizza: is-great +spec: + containers: + - name: nginx + image: nginx diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fcf5b3e9404af94a7e62a036bda93cd87d2f4926 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/samples/verify-label-key-only/example_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Pod +metadata: + name: does-not-have-pizza + labels: + taco: is-great +spec: + containers: + - name: nginx + image: nginx diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9a0d2d75739d0093c5d12bb20e50a288228ade37 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/suite.yaml @@ -0,0 +1,33 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredlabels +tests: +- name: must-have-owner + template: template.yaml + constraint: samples/all-must-have-owner/constraint.yaml + cases: + - name: example-allowed + object: samples/all-must-have-owner/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/all-must-have-owner/example_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed-label-value + object: samples/all-must-have-owner/example_disallowed_label_value.yaml + assertions: + - violations: yes +- name: must-have-key + template: template.yaml + constraint: samples/verify-label-key-only/constraint.yaml + cases: + - name: label-present + object: samples/verify-label-key-only/example_allowed.yaml + assertions: + - violations: no + - name: label-missing + object: samples/verify-label-key-only/example_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5404fadc723e25d2928797a27b9def9c6eef5c45 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.2/template.yaml @@ -0,0 +1,79 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredlabels + annotations: + metadata.gatekeeper.sh/title: "Required Labels" + metadata.gatekeeper.sh/version: 1.1.2 + description: >- + Requires resources to contain specified labels, with values matching + provided regular expressions. +spec: + crd: + spec: + names: + kind: K8sRequiredLabels + validation: + openAPIV3Schema: + type: object + properties: + message: + type: string + labels: + type: array + description: >- + A list of labels and values the object must specify. + items: + type: object + properties: + key: + type: string + description: >- + The required label. + allowedRegex: + type: string + description: >- + If specified, a regular expression the annotation's value + must match. The value must contain at least one match for + the regular expression. + targets: + - target: admission.k8s.gatekeeper.sh + code: + - engine: K8sNativeValidation + source: + validations: + - expression: '(has(variables.anyObject.metadata) && variables.params.labels.all(entry, has(variables.anyObject.metadata.labels) && entry.key in variables.anyObject.metadata.labels))' + messageExpression: '"missing required label, requires all of: " + variables.params.labels.map(entry, entry.key).join(", ")' + - expression: '(has(variables.anyObject.metadata) && variables.params.labels.all(entry, has(variables.anyObject.metadata.labels) && entry.key in variables.anyObject.metadata.labels && (!has(entry.allowedRegex) || string(variables.anyObject.metadata.labels[entry.key]).matches(string(entry.allowedRegex)))))' + message: "regex mismatch" + - engine: Rego + source: + rego: | + package k8srequiredlabels + + get_message(parameters, _default) := _default { + not parameters.message + } + + get_message(parameters, _) := parameters.message + + violation[{"msg": msg, "details": {"missing_labels": missing}}] { + provided := {label | input.review.object.metadata.labels[label]} + required := {label | label := input.parameters.labels[_].key} + missing := required - provided + count(missing) > 0 + def_msg := sprintf("you must provide labels: %v", [missing]) + msg := get_message(input.parameters, def_msg) + } + + violation[{"msg": msg}] { + value := input.review.object.metadata.labels[key] + expected := input.parameters.labels[_] + expected.key == key + # do not match if allowedRegex is not defined, or is an empty string + expected.allowedRegex != "" + not regex.match(expected.allowedRegex, value) + def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) + msg := get_message(input.parameters, def_msg) + } + diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..e8708471e50b0203d09af8899bc5200cd320bfec --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.0 +name: k8srequiredprobes +displayName: Required Probes +createdAt: "2022-09-26T17:28:27Z" +description: Requires Pods to have readiness and/or liveness probes. +digest: ed31a81fb6d25a0117ba72a4fd0f93dd12a345c07063ffc96b6f3fd9d2952367 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredprobes +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Probes + Requires Pods to have readiness and/or liveness probes. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredprobes/1.0.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..84fde016ae01f909c4c8c85df13032cdfe8311ee --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/constraint.yaml @@ -0,0 +1,12 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredProbes +metadata: + name: must-have-probes +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Pod"] + parameters: + probes: ["readinessProbe", "livenessProbe"] + probeTypes: ["tcpSocket", "httpGet", "exec"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4248b67dd3f55a5defb97030397869522662bcb2 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_allowed.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod1 +spec: + containers: + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + livenessProbe: + tcpSocket: + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6db251904afa8d12fd57eaf9514f42312b08c837 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_disallowed.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod1 +spec: + containers: + - name: nginx-1 + image: nginx:1.7.9 + ports: + - containerPort: 80 + livenessProbe: + # tcpSocket: + # port: 80 + # initialDelaySeconds: 5 + # periodSeconds: 10 + volumeMounts: + - mountPath: /tmp/cache + name: cache-volume + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6e05364873aebe16690bf10b8bc9109f9137e70d --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/samples/must-have-probes/example_disallowed2.yaml @@ -0,0 +1,41 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod2 +spec: + containers: + - name: nginx-1 + image: nginx:1.7.9 + ports: + - containerPort: 80 + readinessProbe: + # httpGet: + # path: / + # port: 80 + # initialDelaySeconds: 5 + # periodSeconds: 10 + livenessProbe: + tcpSocket: + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 + volumeMounts: + - mountPath: /tmp/cache + name: cache-volume + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + # livenessProbe: + # tcpSocket: + # port: 8080 + # initialDelaySeconds: 5 + # periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8e8629a9219142aea7edee9ffc51738d35284531 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/suite.yaml @@ -0,0 +1,21 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredprobes +tests: +- name: required-probes + template: template.yaml + constraint: samples/must-have-probes/constraint.yaml + cases: + - name: example-allowed + object: samples/must-have-probes/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/must-have-probes/example_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/must-have-probes/example_disallowed2.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..26417b1010c3234105210f3a8e8fcdfbd1a3bc6f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.0/template.yaml @@ -0,0 +1,60 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredprobes + annotations: + metadata.gatekeeper.sh/title: "Required Probes" + metadata.gatekeeper.sh/version: 1.0.0 + description: Requires Pods to have readiness and/or liveness probes. +spec: + crd: + spec: + names: + kind: K8sRequiredProbes + validation: + openAPIV3Schema: + type: object + properties: + probes: + description: "A list of probes that are required (ex: `readinessProbe`)" + type: array + items: + type: string + probeTypes: + description: "The probe must define a field listed in `probeType` in order to satisfy the constraint (ex. `tcpSocket` satisfies `['tcpSocket', 'exec']`)" + type: array + items: + type: string + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8srequiredprobes + + probe_type_set = probe_types { + probe_types := {type | type := input.parameters.probeTypes[_]} + } + + violation[{"msg": msg}] { + container := input.review.object.spec.containers[_] + probe := input.parameters.probes[_] + probe_is_missing(container, probe) + msg := get_violation_message(container, input.review, probe) + } + + probe_is_missing(ctr, probe) = true { + not ctr[probe] + } + + probe_is_missing(ctr, probe) = true { + probe_field_empty(ctr, probe) + } + + probe_field_empty(ctr, probe) = true { + probe_fields := {field | ctr[probe][field]} + diff_fields := probe_type_set - probe_fields + count(diff_fields) == count(probe_type_set) + } + + get_violation_message(container, review, probe) = msg { + msg := sprintf("Container <%v> in your <%v> <%v> has no <%v>", [container.name, review.kind.kind, review.object.metadata.name, probe]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..e176a3b0db3b756d6e4ff63f32f4cd895bc29366 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.1 +name: k8srequiredprobes +displayName: Required Probes +createdAt: "2023-05-23T09:47:30Z" +description: Requires Pods to have readiness and/or liveness probes. +digest: 217bec367754aadcce3929828825aca968030e4219045d659553a9cc0173d18d +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredprobes +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Required Probes + Requires Pods to have readiness and/or liveness probes. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredprobes/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..84fde016ae01f909c4c8c85df13032cdfe8311ee --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/constraint.yaml @@ -0,0 +1,12 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sRequiredProbes +metadata: + name: must-have-probes +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["Pod"] + parameters: + probes: ["readinessProbe", "livenessProbe"] + probeTypes: ["tcpSocket", "httpGet", "exec"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4248b67dd3f55a5defb97030397869522662bcb2 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_allowed.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod1 +spec: + containers: + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + livenessProbe: + tcpSocket: + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6db251904afa8d12fd57eaf9514f42312b08c837 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_disallowed.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod1 +spec: + containers: + - name: nginx-1 + image: nginx:1.7.9 + ports: + - containerPort: 80 + livenessProbe: + # tcpSocket: + # port: 80 + # initialDelaySeconds: 5 + # periodSeconds: 10 + volumeMounts: + - mountPath: /tmp/cache + name: cache-volume + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6e05364873aebe16690bf10b8bc9109f9137e70d --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/example_disallowed2.yaml @@ -0,0 +1,41 @@ +apiVersion: v1 +kind: Pod +metadata: + name: test-pod2 +spec: + containers: + - name: nginx-1 + image: nginx:1.7.9 + ports: + - containerPort: 80 + readinessProbe: + # httpGet: + # path: / + # port: 80 + # initialDelaySeconds: 5 + # periodSeconds: 10 + livenessProbe: + tcpSocket: + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 + volumeMounts: + - mountPath: /tmp/cache + name: cache-volume + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + # livenessProbe: + # tcpSocket: + # port: 8080 + # initialDelaySeconds: 5 + # periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/update.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/update.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ff5e91103749cb482f2747543987121009aafba6 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/samples/must-have-probes/update.yaml @@ -0,0 +1,35 @@ +kind: AdmissionReview +apiVersion: admission.k8s.io/v1beta1 +request: + operation: "UPDATE" + object: + apiVersion: v1 + kind: Pod + metadata: + name: test-pod1 + spec: + containers: + - name: nginx-1 + image: nginx:1.7.9 + ports: + - containerPort: 80 + livenessProbe: + # tcpSocket: + # port: 80 + # initialDelaySeconds: 5 + # periodSeconds: 10 + volumeMounts: + - mountPath: /tmp/cache + name: cache-volume + - name: tomcat + image: tomcat + ports: + - containerPort: 8080 + readinessProbe: + tcpSocket: + port: 8080 + initialDelaySeconds: 5 + periodSeconds: 10 + volumes: + - name: cache-volume + emptyDir: {} diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..86c2a229e687707a12fd4afac886e5095fbc8a9e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/suite.yaml @@ -0,0 +1,25 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: requiredprobes +tests: +- name: required-probes + template: template.yaml + constraint: samples/must-have-probes/constraint.yaml + cases: + - name: example-allowed + object: samples/must-have-probes/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/must-have-probes/example_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/must-have-probes/example_disallowed2.yaml + assertions: + - violations: yes + - name: update + object: samples/must-have-probes/update.yaml + assertions: + - violations: no diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4115a6d98985bdf0a1b9d2492b9a2025bcc17a1c --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredprobes/1.0.1/template.yaml @@ -0,0 +1,72 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8srequiredprobes + annotations: + metadata.gatekeeper.sh/title: "Required Probes" + metadata.gatekeeper.sh/version: 1.0.1 + description: Requires Pods to have readiness and/or liveness probes. +spec: + crd: + spec: + names: + kind: K8sRequiredProbes + validation: + openAPIV3Schema: + type: object + properties: + probes: + description: "A list of probes that are required (ex: `readinessProbe`)" + type: array + items: + type: string + probeTypes: + description: "The probe must define a field listed in `probeType` in order to satisfy the constraint (ex. `tcpSocket` satisfies `['tcpSocket', 'exec']`)" + type: array + items: + type: string + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8srequiredprobes + + import data.lib.exclude_update.is_update + + probe_type_set = probe_types { + probe_types := {type | type := input.parameters.probeTypes[_]} + } + + violation[{"msg": msg}] { + # Probe fields are immutable. + not is_update(input.review) + + container := input.review.object.spec.containers[_] + probe := input.parameters.probes[_] + probe_is_missing(container, probe) + msg := get_violation_message(container, input.review, probe) + } + + probe_is_missing(ctr, probe) = true { + not ctr[probe] + } + + probe_is_missing(ctr, probe) = true { + probe_field_empty(ctr, probe) + } + + probe_field_empty(ctr, probe) = true { + probe_fields := {field | ctr[probe][field]} + diff_fields := probe_type_set - probe_fields + count(diff_fields) == count(probe_type_set) + } + + get_violation_message(container, review, probe) = msg { + msg := sprintf("Container <%v> in your <%v> <%v> has no <%v>", [container.name, review.kind.kind, review.object.metadata.name, probe]) + } + libs: + - | + package lib.exclude_update + + is_update(review) { + review.operation == "UPDATE" + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/README.md b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/README.md new file mode 100644 index 0000000000000000000000000000000000000000..47aa0f4774a5d22584abd3a9e3de128d798619ec --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/README.md @@ -0,0 +1,14 @@ +# StorageClass + +The `StorageClass` constraint blocks the creation of PVCs or StatefulSets +where the specified storage class doesn't exist on the cluster, or that no +storage class at all is specified. + +This policy helps prevent workloads from getting stuck indefinitely waiting +for a storage class to provision the persistent storage that will never +happen. This often causes users to get confused as to why their pods are stuck +pending, and requires deleting the StatefulSet and any PVCs it has created along +with redeploying the workload in order to fix. Blocking it up front makes it +much easier to fix before there is a mess to clean up. + +> Please note that this policy requires Gatekeeper v3.9.0 or later. \ No newline at end of file diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..008816904af39d7ca457394b866dc9efeda84aff --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.0 +name: k8sstorageclass +displayName: Storage Class +createdAt: "2022-09-26T17:28:27Z" +description: Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +digest: 97e9617303029b1b3ea86062fb95cdfa9e112eb4d20ea3c6988199ad41c24dc0 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/storageclass +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Storage Class + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/storageclass/1.0.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b49e5dad7012b1bcece4f403fd2ae7c54f877b7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_allowed_pvc.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_allowed_pvc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a8608f53e8f291693d898d77d8dace168ff674b6 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_allowed_pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ok +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: somestorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_allowed_ss.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_allowed_ss.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1bd5db795668c8d223c863890eec673346a364f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_allowed_ss.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: volumeclaimstorageclass +spec: + selector: + matchLabels: + app: volumeclaimstorageclass + serviceName: volumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: volumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "somestorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_pvc_badname.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_pvc_badname.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ec75200c432f180b0c205bd27ce205286f92e438 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_pvc_badname.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: badstorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: badstorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_pvc_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_pvc_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f9cc12ec6aabe17cc8fba85b70c3f40c08866bb --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_pvc_nonamename.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nostorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_ssvct_badnamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_ssvct_badnamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58c98fd7d7471efe189dbcce640ec9bd6128cfa3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_ssvct_badnamename.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: badvolumeclaimstorageclass +spec: + selector: + matchLabels: + app: badvolumeclaimstorageclass + serviceName: badvolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: badvolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "badstorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_ssvct_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_ssvct_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ece7c23dd071ccfe0d4345952aaa8a67e872b61b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_disallowed_ssvct_nonamename.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: novolumeclaimstorageclass +spec: + selector: + matchLabels: + app: novolumeclaimstorageclass + serviceName: novolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: novolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0cdee0aa32d49726217bd0e4c1603a7138b40003 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/samples/storageclass/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: somestorageclass +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4d21438ad619b255348cab121d166a73b663c3ef --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/suite.yaml @@ -0,0 +1,38 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: storageclass +tests: +- name: storageclass + template: template.yaml + constraint: samples/storageclass/constraint.yaml + cases: + - name: example-allowed-pvc + object: samples/storageclass/example_allowed_pvc.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-allowed-ss + object: samples/storageclass/example_allowed_ss.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-disallowed-pvc-badname + object: samples/storageclass/example_disallowed_pvc_badname.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-badnamename + object: samples/storageclass/example_disallowed_ssvct_badnamename.yaml + assertions: + - violations: yes + - name: example-disallowed-pvc-nonamename + object: samples/storageclass/example_disallowed_pvc_nonamename.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-nonamename + object: samples/storageclass/example_disallowed_ssvct_nonamename.yaml + assertions: + - violations: yes + diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d7fd5e1664611605c9a90fe542e627c90e5d0de --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "storage.k8s.io" + version: "v1" + kind: "StorageClass" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f7792ecf03038062479c33fc169a91f2388896e2 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.0/template.yaml @@ -0,0 +1,113 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sstorageclass + annotations: + metadata.gatekeeper.sh/title: "Storage Class" + metadata.gatekeeper.sh/version: 1.0.0 + description: >- + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +spec: + crd: + spec: + names: + kind: K8sStorageClass + validation: + openAPIV3Schema: + type: object + description: >- + Requires storage classes to be specified when used. + properties: + includeStorageClassesInMessage: + type: boolean + default: true + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sstorageclass + + is_pvc(obj) { + obj.apiVersion == "v1" + obj.kind == "PersistentVolumeClaim" + } + + is_statefulset(obj) { + obj.apiVersion == "apps/v1" + obj.kind == "StatefulSet" + } + + violation[{"msg": msg}] { + not data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"] + msg := sprintf("StorageClasses not synced. Gatekeeper may be misconfigured. Please have a cluster-admin consult the documentation.", []) + } + + storageclass_found(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + } + + violation[{"msg": pvc_storageclass_badname_msg}] { + is_pvc(input.review.object) + not storageclass_found(input.review.object.spec.storageClassName) + } + pvc_storageclass_badname_msg := sprintf("pvc did not specify a valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + input.review.object.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a valid storage class name <%v>.", + [input.review.object.spec.storageClassName] + ) + + violation[{"msg": pvc_storageclass_noname_msg}] { + is_pvc(input.review.object) + not input.review.object.spec.storageClassName + } + pvc_storageclass_noname_msg := sprintf("pvc did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a storage class name.", + [] + ) + + violation[{"msg": statefulset_vct_badname_msg(vct)}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not storageclass_found(vct.spec.storageClassName) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + not input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>.", [ + vct.spec.storageClassName + ]) + } + + violation[{"msg": statefulset_vct_noname_msg}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not vct.spec.storageClassName + } + statefulset_vct_noname_msg := sprintf("statefulset did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "statefulset did not specify a storage class name.", + [] + ) + + #FIXME pod generic ephemeral might be good to validate some day too. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/README.md b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/README.md new file mode 100644 index 0000000000000000000000000000000000000000..89e4178d7e0184695661f070d56f16195b788f9c --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/README.md @@ -0,0 +1,14 @@ +# StorageClass + +The `StorageClass` constraint blocks the creation of PVCs or StatefulSets +where the specified storage class doesn't exist on the cluster, or that no +storage class at all is specified. + +This policy helps prevent workloads from getting stuck indefinitely waiting +for a storage class to provision the persistent storage that will never +happen. This often causes users to get confused as to why their pods are stuck +pending, and requires deleting the StatefulSet and any PVCs it has created along +with redeploying the workload in order to fix. Blocking it up front makes it +much easier to fix before there is a mess to clean up. + +> Please note that this policy requires Gatekeeper v3.9.0 or later. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..0c28530988adcf9cefed25b30160cf0695d80288 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.0.1 +name: k8sstorageclass +displayName: Storage Class +createdAt: "2022-11-08T23:45:23Z" +description: Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +digest: 60bc85a9f37888ca1025e0f74d7453fca2296d83a1a71c0752d25afc3b2b1aae +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/storageclass +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Storage Class + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/storageclass/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b49e5dad7012b1bcece4f403fd2ae7c54f877b7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_allowed_pvc.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_allowed_pvc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a8608f53e8f291693d898d77d8dace168ff674b6 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_allowed_pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ok +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: somestorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_allowed_ss.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_allowed_ss.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1bd5db795668c8d223c863890eec673346a364f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_allowed_ss.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: volumeclaimstorageclass +spec: + selector: + matchLabels: + app: volumeclaimstorageclass + serviceName: volumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: volumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "somestorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_pvc_badname.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_pvc_badname.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ec75200c432f180b0c205bd27ce205286f92e438 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_pvc_badname.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: badstorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: badstorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_pvc_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_pvc_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f9cc12ec6aabe17cc8fba85b70c3f40c08866bb --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_pvc_nonamename.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nostorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_ssvct_badnamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_ssvct_badnamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58c98fd7d7471efe189dbcce640ec9bd6128cfa3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_ssvct_badnamename.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: badvolumeclaimstorageclass +spec: + selector: + matchLabels: + app: badvolumeclaimstorageclass + serviceName: badvolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: badvolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "badstorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_ssvct_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_ssvct_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ece7c23dd071ccfe0d4345952aaa8a67e872b61b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_disallowed_ssvct_nonamename.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: novolumeclaimstorageclass +spec: + selector: + matchLabels: + app: novolumeclaimstorageclass + serviceName: novolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: novolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0cdee0aa32d49726217bd0e4c1603a7138b40003 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/samples/storageclass/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: somestorageclass +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4d21438ad619b255348cab121d166a73b663c3ef --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/suite.yaml @@ -0,0 +1,38 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: storageclass +tests: +- name: storageclass + template: template.yaml + constraint: samples/storageclass/constraint.yaml + cases: + - name: example-allowed-pvc + object: samples/storageclass/example_allowed_pvc.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-allowed-ss + object: samples/storageclass/example_allowed_ss.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-disallowed-pvc-badname + object: samples/storageclass/example_disallowed_pvc_badname.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-badnamename + object: samples/storageclass/example_disallowed_ssvct_badnamename.yaml + assertions: + - violations: yes + - name: example-disallowed-pvc-nonamename + object: samples/storageclass/example_disallowed_pvc_nonamename.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-nonamename + object: samples/storageclass/example_disallowed_ssvct_nonamename.yaml + assertions: + - violations: yes + diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d7fd5e1664611605c9a90fe542e627c90e5d0de --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "storage.k8s.io" + version: "v1" + kind: "StorageClass" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a86883b18902a6baaf408daa1dfab3fb9273755d --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.0.1/template.yaml @@ -0,0 +1,123 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sstorageclass + annotations: + metadata.gatekeeper.sh/title: "Storage Class" + metadata.gatekeeper.sh/version: 1.0.1 + metadata.gatekeeper.sh/requiresSyncData: | + "[ + [ + { + "groups":["storage.k8s.io"], + "versions": ["v1"], + "kinds": ["StorageClass"] + } + ] + ]" + description: >- + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +spec: + crd: + spec: + names: + kind: K8sStorageClass + validation: + openAPIV3Schema: + type: object + description: >- + Requires storage classes to be specified when used. + properties: + includeStorageClassesInMessage: + type: boolean + default: true + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sstorageclass + + is_pvc(obj) { + obj.apiVersion == "v1" + obj.kind == "PersistentVolumeClaim" + } + + is_statefulset(obj) { + obj.apiVersion == "apps/v1" + obj.kind == "StatefulSet" + } + + violation[{"msg": msg}] { + not data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"] + msg := sprintf("StorageClasses not synced. Gatekeeper may be misconfigured. Please have a cluster-admin consult the documentation.", []) + } + + storageclass_found(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + } + + violation[{"msg": pvc_storageclass_badname_msg}] { + is_pvc(input.review.object) + not storageclass_found(input.review.object.spec.storageClassName) + } + pvc_storageclass_badname_msg := sprintf("pvc did not specify a valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + input.review.object.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a valid storage class name <%v>.", + [input.review.object.spec.storageClassName] + ) + + violation[{"msg": pvc_storageclass_noname_msg}] { + is_pvc(input.review.object) + not input.review.object.spec.storageClassName + } + pvc_storageclass_noname_msg := sprintf("pvc did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a storage class name.", + [] + ) + + violation[{"msg": statefulset_vct_badname_msg(vct)}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not storageclass_found(vct.spec.storageClassName) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + not input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>.", [ + vct.spec.storageClassName + ]) + } + + violation[{"msg": statefulset_vct_noname_msg}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not vct.spec.storageClassName + } + statefulset_vct_noname_msg := sprintf("statefulset did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "statefulset did not specify a storage class name.", + [] + ) + + #FIXME pod generic ephemeral might be good to validate some day too. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/README.md b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f398931a96ea9234e25619dee13af924e1063961 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/README.md @@ -0,0 +1,17 @@ +# StorageClass + +The `StorageClass` constraint blocks the creation of PVCs or StatefulSets +where the specified storage class doesn't exist on the cluster, or that no +storage class at all is specified. + +This policy helps prevent workloads from getting stuck indefinitely waiting +for a storage class to provision the persistent storage that will never +happen. This often causes users to get confused as to why their pods are stuck +pending, and requires deleting the StatefulSet and any PVCs it has created along +with redeploying the workload in order to fix. Blocking it up front makes it +much easier to fix before there is a mess to clean up. + +Optionally accepts an `allowedStorageClasses` parameter to restrict PVCs and +StatefulSets to a subset list of allowed storage classes. + +> Please note that this policy requires Gatekeeper v3.9.0 or later. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..24db9a2161ba480c79d1499d1dce2a313b460266 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.1.0 +name: k8sstorageclass +displayName: Storage Class +createdAt: "2023-04-06T23:24:34Z" +description: Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +digest: 0f856a003b9581ae6f61a980c01d86d4c53395f74dbc12fe9cbbc406aacc2f90 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/storageclass +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Storage Class + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/storageclass/1.1.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ddd6acaa5d8bea08e129cb21362c61ae6be69df7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/constraint.yaml @@ -0,0 +1,15 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: allowed-storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true + allowedStorageClasses: + - allowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7982eca543622cede2d9556323de76d61b52101a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_allowed.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: allowed-storage-class-pvc +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: allowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7f679bb30afcc2ca5ad4f0c6b4e3c123331074e0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_disallowed.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: disallowed-storage-class-pvc +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: disallowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..930822f4a48b60dcfd46da9b450c0ad45601efac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: allowed-storage-class +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b49e5dad7012b1bcece4f403fd2ae7c54f877b7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_allowed_pvc.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_allowed_pvc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a8608f53e8f291693d898d77d8dace168ff674b6 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_allowed_pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ok +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: somestorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_allowed_ss.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_allowed_ss.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1bd5db795668c8d223c863890eec673346a364f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_allowed_ss.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: volumeclaimstorageclass +spec: + selector: + matchLabels: + app: volumeclaimstorageclass + serviceName: volumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: volumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "somestorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_pvc_badname.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_pvc_badname.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ec75200c432f180b0c205bd27ce205286f92e438 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_pvc_badname.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: badstorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: badstorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_pvc_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_pvc_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f9cc12ec6aabe17cc8fba85b70c3f40c08866bb --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_pvc_nonamename.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nostorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_ssvct_badnamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_ssvct_badnamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58c98fd7d7471efe189dbcce640ec9bd6128cfa3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_ssvct_badnamename.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: badvolumeclaimstorageclass +spec: + selector: + matchLabels: + app: badvolumeclaimstorageclass + serviceName: badvolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: badvolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "badstorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_ssvct_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_ssvct_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ece7c23dd071ccfe0d4345952aaa8a67e872b61b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_disallowed_ssvct_nonamename.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: novolumeclaimstorageclass +spec: + selector: + matchLabels: + app: novolumeclaimstorageclass + serviceName: novolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: novolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0cdee0aa32d49726217bd0e4c1603a7138b40003 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/samples/storageclass/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: somestorageclass +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9cccc2ebb76108a213e41bc88a0aede0ff3facd8 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/suite.yaml @@ -0,0 +1,53 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: storageclass +tests: +- name: storageclass + template: template.yaml + constraint: samples/storageclass/constraint.yaml + cases: + - name: example-allowed-pvc + object: samples/storageclass/example_allowed_pvc.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-allowed-ss + object: samples/storageclass/example_allowed_ss.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-disallowed-pvc-badname + object: samples/storageclass/example_disallowed_pvc_badname.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-badnamename + object: samples/storageclass/example_disallowed_ssvct_badnamename.yaml + assertions: + - violations: yes + - name: example-disallowed-pvc-nonamename + object: samples/storageclass/example_disallowed_pvc_nonamename.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-nonamename + object: samples/storageclass/example_disallowed_ssvct_nonamename.yaml + assertions: + - violations: yes +- name: storageclass-allowlist + template: template.yaml + constraint: samples/storageclass-allowlist/constraint.yaml + cases: + - name: allowed-storage-class-pvc + object: samples/storageclass-allowlist/example_allowed.yaml + inventory: + - samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: disallowed-storage-class-pvc + object: samples/storageclass-allowlist/example_disallowed.yaml + inventory: + - samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d7fd5e1664611605c9a90fe542e627c90e5d0de --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "storage.k8s.io" + version: "v1" + kind: "StorageClass" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..26d281615160b678190e5b6e8af44b9f83c65ad5 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.0/template.yaml @@ -0,0 +1,155 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sstorageclass + annotations: + metadata.gatekeeper.sh/title: "Storage Class" + metadata.gatekeeper.sh/version: 1.1.0 + metadata.gatekeeper.sh/requiresSyncData: | + "[ + [ + { + "groups":["storage.k8s.io"], + "versions": ["v1"], + "kinds": ["StorageClass"] + } + ] + ]" + description: >- + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +spec: + crd: + spec: + names: + kind: K8sStorageClass + validation: + openAPIV3Schema: + type: object + description: >- + Requires storage classes to be specified when used. + properties: + includeStorageClassesInMessage: + type: boolean + default: true + allowedStorageClasses: + type: array + description: "An optional allow-list of storage classes. If specified, any storage class not in the `allowedStorageClasses` parameter is disallowed." + items: + type: string + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sstorageclass + + is_pvc(obj) { + obj.apiVersion == "v1" + obj.kind == "PersistentVolumeClaim" + } + + is_statefulset(obj) { + obj.apiVersion == "apps/v1" + obj.kind == "StatefulSet" + } + + violation[{"msg": msg}] { + not data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"] + msg := sprintf("StorageClasses not synced. Gatekeeper may be misconfigured. Please have a cluster-admin consult the documentation.", []) + } + + storageclass_allowed(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + # support both direct use of * and as the default value + object.get(input.parameters, "allowedStorageClasses", ["*"])[_] == "*" + } + + storageclass_allowed(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + input.parameters.allowedStorageClasses[_] == name + } + + violation[{"msg": pvc_storageclass_badname_msg}] { + is_pvc(input.review.object) + not storageclass_allowed(input.review.object.spec.storageClassName) + } + pvc_storageclass_badname_msg := sprintf("pvc did not specify a valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) == null + args := [ + input.review.object.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf("pvc did not specify an allowed and valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) != null + sc := {n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]} & {x | x = object.get(input.parameters, "allowedStorageClasses", [])[_]} + args := [ + input.review.object.spec.storageClassName, + concat(", ", sc) + ] + } else := sprintf( + "pvc did not specify a valid storage class name <%v>.", + [input.review.object.spec.storageClassName] + ) + + violation[{"msg": pvc_storageclass_noname_msg}] { + is_pvc(input.review.object) + not input.review.object.spec.storageClassName + } + pvc_storageclass_noname_msg := sprintf("pvc did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a storage class name.", + [] + ) + + violation[{"msg": statefulset_vct_badname_msg(vct)}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not storageclass_allowed(vct.spec.storageClassName) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) == null + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) != null + sc := {n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]} & {x | x = object.get(input.parameters, "allowedStorageClasses", [])[_]} + msg := sprintf( + "statefulset did not specify an allowed and valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", sc) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + not input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>.", [ + vct.spec.storageClassName + ]) + } + + violation[{"msg": statefulset_vct_noname_msg}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not vct.spec.storageClassName + } + statefulset_vct_noname_msg := sprintf("statefulset did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "statefulset did not specify a storage class name.", + [] + ) + + #FIXME pod generic ephemeral might be good to validate some day too. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/README.md b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f398931a96ea9234e25619dee13af924e1063961 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/README.md @@ -0,0 +1,17 @@ +# StorageClass + +The `StorageClass` constraint blocks the creation of PVCs or StatefulSets +where the specified storage class doesn't exist on the cluster, or that no +storage class at all is specified. + +This policy helps prevent workloads from getting stuck indefinitely waiting +for a storage class to provision the persistent storage that will never +happen. This often causes users to get confused as to why their pods are stuck +pending, and requires deleting the StatefulSet and any PVCs it has created along +with redeploying the workload in order to fix. Blocking it up front makes it +much easier to fix before there is a mess to clean up. + +Optionally accepts an `allowedStorageClasses` parameter to restrict PVCs and +StatefulSets to a subset list of allowed storage classes. + +> Please note that this policy requires Gatekeeper v3.9.0 or later. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..ded49fa1501f12c3639d76c2973fdf078ef6c51e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.1.1 +name: k8sstorageclass +displayName: Storage Class +createdAt: "2023-06-12T20:47:48Z" +description: Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +digest: ebe3175effd0c3b2850bc0bce4b1abe02f33329455431e07b807a5d9d87674c2 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/storageclass +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Storage Class + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/storageclass/1.1.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ddd6acaa5d8bea08e129cb21362c61ae6be69df7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/constraint.yaml @@ -0,0 +1,15 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: allowed-storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true + allowedStorageClasses: + - allowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7982eca543622cede2d9556323de76d61b52101a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_allowed.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: allowed-storage-class-pvc +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: allowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7f679bb30afcc2ca5ad4f0c6b4e3c123331074e0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_disallowed.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: disallowed-storage-class-pvc +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: disallowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..930822f4a48b60dcfd46da9b450c0ad45601efac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: allowed-storage-class +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b49e5dad7012b1bcece4f403fd2ae7c54f877b7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_allowed_pvc.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_allowed_pvc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a8608f53e8f291693d898d77d8dace168ff674b6 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_allowed_pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ok +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: somestorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_allowed_ss.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_allowed_ss.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1bd5db795668c8d223c863890eec673346a364f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_allowed_ss.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: volumeclaimstorageclass +spec: + selector: + matchLabels: + app: volumeclaimstorageclass + serviceName: volumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: volumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "somestorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_pvc_badname.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_pvc_badname.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ec75200c432f180b0c205bd27ce205286f92e438 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_pvc_badname.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: badstorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: badstorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_pvc_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_pvc_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f9cc12ec6aabe17cc8fba85b70c3f40c08866bb --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_pvc_nonamename.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nostorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_ssvct_badnamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_ssvct_badnamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58c98fd7d7471efe189dbcce640ec9bd6128cfa3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_ssvct_badnamename.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: badvolumeclaimstorageclass +spec: + selector: + matchLabels: + app: badvolumeclaimstorageclass + serviceName: badvolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: badvolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "badstorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_ssvct_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_ssvct_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ece7c23dd071ccfe0d4345952aaa8a67e872b61b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_disallowed_ssvct_nonamename.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: novolumeclaimstorageclass +spec: + selector: + matchLabels: + app: novolumeclaimstorageclass + serviceName: novolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: novolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0cdee0aa32d49726217bd0e4c1603a7138b40003 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/samples/storageclass/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: somestorageclass +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9cccc2ebb76108a213e41bc88a0aede0ff3facd8 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/suite.yaml @@ -0,0 +1,53 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: storageclass +tests: +- name: storageclass + template: template.yaml + constraint: samples/storageclass/constraint.yaml + cases: + - name: example-allowed-pvc + object: samples/storageclass/example_allowed_pvc.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-allowed-ss + object: samples/storageclass/example_allowed_ss.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-disallowed-pvc-badname + object: samples/storageclass/example_disallowed_pvc_badname.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-badnamename + object: samples/storageclass/example_disallowed_ssvct_badnamename.yaml + assertions: + - violations: yes + - name: example-disallowed-pvc-nonamename + object: samples/storageclass/example_disallowed_pvc_nonamename.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-nonamename + object: samples/storageclass/example_disallowed_ssvct_nonamename.yaml + assertions: + - violations: yes +- name: storageclass-allowlist + template: template.yaml + constraint: samples/storageclass-allowlist/constraint.yaml + cases: + - name: allowed-storage-class-pvc + object: samples/storageclass-allowlist/example_allowed.yaml + inventory: + - samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: disallowed-storage-class-pvc + object: samples/storageclass-allowlist/example_disallowed.yaml + inventory: + - samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d7fd5e1664611605c9a90fe542e627c90e5d0de --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "storage.k8s.io" + version: "v1" + kind: "StorageClass" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1bf0748ca3be500aeb24d3ef07196eb0e6cb68b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.1/template.yaml @@ -0,0 +1,155 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sstorageclass + annotations: + metadata.gatekeeper.sh/title: "Storage Class" + metadata.gatekeeper.sh/version: 1.1.1 + metadata.gatekeeper.sh/requires-sync-data: | + "[ + [ + { + "groups":["storage.k8s.io"], + "versions": ["v1"], + "kinds": ["StorageClass"] + } + ] + ]" + description: >- + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +spec: + crd: + spec: + names: + kind: K8sStorageClass + validation: + openAPIV3Schema: + type: object + description: >- + Requires storage classes to be specified when used. + properties: + includeStorageClassesInMessage: + type: boolean + default: true + allowedStorageClasses: + type: array + description: "An optional allow-list of storage classes. If specified, any storage class not in the `allowedStorageClasses` parameter is disallowed." + items: + type: string + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sstorageclass + + is_pvc(obj) { + obj.apiVersion == "v1" + obj.kind == "PersistentVolumeClaim" + } + + is_statefulset(obj) { + obj.apiVersion == "apps/v1" + obj.kind == "StatefulSet" + } + + violation[{"msg": msg}] { + not data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"] + msg := sprintf("StorageClasses not synced. Gatekeeper may be misconfigured. Please have a cluster-admin consult the documentation.", []) + } + + storageclass_allowed(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + # support both direct use of * and as the default value + object.get(input.parameters, "allowedStorageClasses", ["*"])[_] == "*" + } + + storageclass_allowed(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + input.parameters.allowedStorageClasses[_] == name + } + + violation[{"msg": pvc_storageclass_badname_msg}] { + is_pvc(input.review.object) + not storageclass_allowed(input.review.object.spec.storageClassName) + } + pvc_storageclass_badname_msg := sprintf("pvc did not specify a valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) == null + args := [ + input.review.object.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf("pvc did not specify an allowed and valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) != null + sc := {n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]} & {x | x = object.get(input.parameters, "allowedStorageClasses", [])[_]} + args := [ + input.review.object.spec.storageClassName, + concat(", ", sc) + ] + } else := sprintf( + "pvc did not specify a valid storage class name <%v>.", + [input.review.object.spec.storageClassName] + ) + + violation[{"msg": pvc_storageclass_noname_msg}] { + is_pvc(input.review.object) + not input.review.object.spec.storageClassName + } + pvc_storageclass_noname_msg := sprintf("pvc did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a storage class name.", + [] + ) + + violation[{"msg": statefulset_vct_badname_msg(vct)}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not storageclass_allowed(vct.spec.storageClassName) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) == null + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) != null + sc := {n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]} & {x | x = object.get(input.parameters, "allowedStorageClasses", [])[_]} + msg := sprintf( + "statefulset did not specify an allowed and valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", sc) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + not input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>.", [ + vct.spec.storageClassName + ]) + } + + violation[{"msg": statefulset_vct_noname_msg}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not vct.spec.storageClassName + } + statefulset_vct_noname_msg := sprintf("statefulset did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "statefulset did not specify a storage class name.", + [] + ) + + #FIXME pod generic ephemeral might be good to validate some day too. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/README.md b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f398931a96ea9234e25619dee13af924e1063961 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/README.md @@ -0,0 +1,17 @@ +# StorageClass + +The `StorageClass` constraint blocks the creation of PVCs or StatefulSets +where the specified storage class doesn't exist on the cluster, or that no +storage class at all is specified. + +This policy helps prevent workloads from getting stuck indefinitely waiting +for a storage class to provision the persistent storage that will never +happen. This often causes users to get confused as to why their pods are stuck +pending, and requires deleting the StatefulSet and any PVCs it has created along +with redeploying the workload in order to fix. Blocking it up front makes it +much easier to fix before there is a mess to clean up. + +Optionally accepts an `allowedStorageClasses` parameter to restrict PVCs and +StatefulSets to a subset list of allowed storage classes. + +> Please note that this policy requires Gatekeeper v3.9.0 or later. diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..dfed41af18986c7fe921104ccab0d3c4d4d454ba --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/artifacthub-pkg.yml @@ -0,0 +1,22 @@ +version: 1.1.2 +name: k8sstorageclass +displayName: Storage Class +createdAt: "2023-11-06T20:56:52Z" +description: Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +digest: 549bc0b8e3aea2c4410798d4f5357a3dbd2bd4225b580104b44fd4659b840b4d +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/storageclass +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Storage Class + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ is supported. +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/storageclass/1.1.2/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ddd6acaa5d8bea08e129cb21362c61ae6be69df7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/constraint.yaml @@ -0,0 +1,15 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: allowed-storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true + allowedStorageClasses: + - allowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7982eca543622cede2d9556323de76d61b52101a --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_allowed.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: allowed-storage-class-pvc +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: allowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7f679bb30afcc2ca5ad4f0c6b4e3c123331074e0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_disallowed.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: disallowed-storage-class-pvc +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: disallowed-storage-class diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..930822f4a48b60dcfd46da9b450c0ad45601efac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: allowed-storage-class +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6b49e5dad7012b1bcece4f403fd2ae7c54f877b7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/constraint.yaml @@ -0,0 +1,13 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sStorageClass +metadata: + name: storageclass +spec: + match: + kinds: + - apiGroups: [""] + kinds: ["PersistentVolumeClaim"] + - apiGroups: ["apps"] + kinds: ["StatefulSet"] + parameters: + includeStorageClassesInMessage: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_allowed_pvc.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_allowed_pvc.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a8608f53e8f291693d898d77d8dace168ff674b6 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_allowed_pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ok +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: somestorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_allowed_ss.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_allowed_ss.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b1bd5db795668c8d223c863890eec673346a364f --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_allowed_ss.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: volumeclaimstorageclass +spec: + selector: + matchLabels: + app: volumeclaimstorageclass + serviceName: volumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: volumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "somestorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_pvc_badname.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_pvc_badname.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ec75200c432f180b0c205bd27ce205286f92e438 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_pvc_badname.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: badstorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + storageClassName: badstorageclass diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_pvc_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_pvc_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f9cc12ec6aabe17cc8fba85b70c3f40c08866bb --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_pvc_nonamename.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nostorageclass +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_ssvct_badnamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_ssvct_badnamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58c98fd7d7471efe189dbcce640ec9bd6128cfa3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_ssvct_badnamename.yaml @@ -0,0 +1,30 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: badvolumeclaimstorageclass +spec: + selector: + matchLabels: + app: badvolumeclaimstorageclass + serviceName: badvolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: badvolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + storageClassName: "badstorageclass" + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_ssvct_nonamename.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_ssvct_nonamename.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ece7c23dd071ccfe0d4345952aaa8a67e872b61b --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_disallowed_ssvct_nonamename.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: novolumeclaimstorageclass +spec: + selector: + matchLabels: + app: novolumeclaimstorageclass + serviceName: novolumeclaimstorageclass + replicas: 1 + template: + metadata: + labels: + app: novolumeclaimstorageclass + spec: + containers: + - name: main + image: registry.k8s.io/nginx-slim:0.8 + volumeMounts: + - name: data + mountPath: /usr/share/nginx/html + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_inventory_allowed_storageclass.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_inventory_allowed_storageclass.yaml new file mode 100644 index 0000000000000000000000000000000000000000..0cdee0aa32d49726217bd0e4c1603a7138b40003 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/samples/storageclass/example_inventory_allowed_storageclass.yaml @@ -0,0 +1,7 @@ +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: somestorageclass +provisioner: foo +parameters: +allowVolumeExpansion: true diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9cccc2ebb76108a213e41bc88a0aede0ff3facd8 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/suite.yaml @@ -0,0 +1,53 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: storageclass +tests: +- name: storageclass + template: template.yaml + constraint: samples/storageclass/constraint.yaml + cases: + - name: example-allowed-pvc + object: samples/storageclass/example_allowed_pvc.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-allowed-ss + object: samples/storageclass/example_allowed_ss.yaml + inventory: + - samples/storageclass/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: example-disallowed-pvc-badname + object: samples/storageclass/example_disallowed_pvc_badname.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-badnamename + object: samples/storageclass/example_disallowed_ssvct_badnamename.yaml + assertions: + - violations: yes + - name: example-disallowed-pvc-nonamename + object: samples/storageclass/example_disallowed_pvc_nonamename.yaml + assertions: + - violations: yes + - name: example-disallowed-ssvct-nonamename + object: samples/storageclass/example_disallowed_ssvct_nonamename.yaml + assertions: + - violations: yes +- name: storageclass-allowlist + template: template.yaml + constraint: samples/storageclass-allowlist/constraint.yaml + cases: + - name: allowed-storage-class-pvc + object: samples/storageclass-allowlist/example_allowed.yaml + inventory: + - samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml + assertions: + - violations: no + - name: disallowed-storage-class-pvc + object: samples/storageclass-allowlist/example_disallowed.yaml + inventory: + - samples/storageclass-allowlist/example_inventory_allowed_storageclass.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9d7fd5e1664611605c9a90fe542e627c90e5d0de --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "storage.k8s.io" + version: "v1" + kind: "StorageClass" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8c11c1bc8920d96b874c741a5543764be4f877f7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/storageclass/1.1.2/template.yaml @@ -0,0 +1,153 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8sstorageclass + annotations: + metadata.gatekeeper.sh/title: "Storage Class" + metadata.gatekeeper.sh/version: 1.1.2 + metadata.gatekeeper.sh/requires-sync-data: | + "[ + [ + { + "groups":["storage.k8s.io"], + "versions": ["v1"], + "kinds": ["StorageClass"] + } + ] + ]" + description: >- + Requires storage classes to be specified when used. Only Gatekeeper 3.9+ and non-ephemeral containers are supported. +spec: + crd: + spec: + names: + kind: K8sStorageClass + validation: + openAPIV3Schema: + type: object + description: >- + Requires storage classes to be specified when used. + properties: + includeStorageClassesInMessage: + type: boolean + default: true + allowedStorageClasses: + type: array + description: "An optional allow-list of storage classes. If specified, any storage class not in the `allowedStorageClasses` parameter is disallowed." + items: + type: string + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8sstorageclass + + is_pvc(obj) { + obj.apiVersion == "v1" + obj.kind == "PersistentVolumeClaim" + } + + is_statefulset(obj) { + obj.apiVersion == "apps/v1" + obj.kind == "StatefulSet" + } + + violation[{"msg": msg}] { + not data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"] + msg := sprintf("StorageClasses not synced. Gatekeeper may be misconfigured. Please have a cluster-admin consult the documentation.", []) + } + + storageclass_allowed(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + # support both direct use of * and as the default value + object.get(input.parameters, "allowedStorageClasses", ["*"])[_] == "*" + } + + storageclass_allowed(name) { + data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][name] + input.parameters.allowedStorageClasses[_] == name + } + + violation[{"msg": pvc_storageclass_badname_msg}] { + is_pvc(input.review.object) + not storageclass_allowed(input.review.object.spec.storageClassName) + } + pvc_storageclass_badname_msg := sprintf("pvc did not specify a valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) == null + args := [ + input.review.object.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf("pvc did not specify an allowed and valid storage class name <%v>. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) != null + sc := {n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]} & {x | x = object.get(input.parameters, "allowedStorageClasses", [])[_]} + args := [ + input.review.object.spec.storageClassName, + concat(", ", sc) + ] + } else := sprintf( + "pvc did not specify a valid storage class name <%v>.", + [input.review.object.spec.storageClassName] + ) + + violation[{"msg": pvc_storageclass_noname_msg}] { + is_pvc(input.review.object) + not input.review.object.spec.storageClassName + } + pvc_storageclass_noname_msg := sprintf("pvc did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "pvc did not specify a storage class name.", + [] + ) + + violation[{"msg": statefulset_vct_badname_msg(vct)}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not storageclass_allowed(vct.spec.storageClassName) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) == null + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + input.parameters.includeStorageClassesInMessage + object.get(input.parameters, "allowedStorageClasses", null) != null + sc := {n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]} & {x | x = object.get(input.parameters, "allowedStorageClasses", [])[_]} + msg := sprintf( + "statefulset did not specify an allowed and valid storage class name <%v>. Must be one of [%v]", [ + vct.spec.storageClassName, + concat(", ", sc) + ]) + } + statefulset_vct_badname_msg(vct) := msg { + not input.parameters.includeStorageClassesInMessage + msg := sprintf( + "statefulset did not specify a valid storage class name <%v>.", [ + vct.spec.storageClassName + ]) + } + + violation[{"msg": statefulset_vct_noname_msg}] { + is_statefulset(input.review.object) + vct := input.review.object.spec.volumeClaimTemplates[_] + not vct.spec.storageClassName + } + statefulset_vct_noname_msg := sprintf("statefulset did not specify a storage class name. Must be one of [%v]", args) { + input.parameters.includeStorageClassesInMessage + args := [ + concat(", ", [n | data.inventory.cluster["storage.k8s.io/v1"]["StorageClass"][n]]) + ] + } else := sprintf( + "statefulset did not specify a storage class name.", + [] + ) diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..a69514a6842a4a567e20692ee8061b2d97002769 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.0 +name: k8suniqueingresshost +displayName: Unique Ingress Host +createdAt: "2022-09-26T17:28:27Z" +description: |- + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +digest: 8d99a6a21bb9a5521c8979ad1bed01f6ecb1d85f9bf1a6d7113cdd5085a8652f +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueingresshost +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Ingress Host + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueingresshost/1.0.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b4d7f852f1582c7eb62617d3dc2c902b90db1561 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/constraint.yaml @@ -0,0 +1,9 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueIngressHost +metadata: + name: unique-ingress-host +spec: + match: + kinds: + - apiGroups: ["extensions", "networking.k8s.io"] + kinds: ["Ingress"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1e819e200ef6052aa0e32b8a499314d5c07806f0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_allowed.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-allowed + namespace: default +spec: + rules: + - host: example-allowed-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-allowed-host1.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c61893ed691e8e571d35a3b9bd1d7690e4c2e0ad --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ca131f1307da94b9b6decff7ef50e5e9f1a06fc --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_disallowed2.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-host3.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..06bc70922c6a906cfb729e8da5ee92366bd43162 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_inventory_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_inventory_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_inventory_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3f826aeebb5d4fbda9556f0d777cb8d10730a5ac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/samples/unique-ingress-host/example_inventory_disallowed2.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..630838d1d6f51f658b377500d651e45cb5c68a4e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/suite.yaml @@ -0,0 +1,25 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueingresshost +tests: +- name: unique-ingress-host + template: template.yaml + constraint: samples/unique-ingress-host/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-ingress-host/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-ingress-host/example_disallowed.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/unique-ingress-host/example_disallowed2.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed2.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ce25235acfa0b71b9a0675c7fda144a2ca67d346 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/sync.yaml @@ -0,0 +1,17 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "extensions" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1" + kind: "Ingress" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..33390d465a7d1dd5b334533b8a852ec27eb1339d --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.0/template.yaml @@ -0,0 +1,37 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueingresshost + annotations: + metadata.gatekeeper.sh/title: "Unique Ingress Host" + metadata.gatekeeper.sh/version: 1.0.0 + description: >- + Requires all Ingress rule hosts to be unique. + + Does not handle hostname wildcards: + https://kubernetes.io/docs/concepts/services-networking/ingress/ +spec: + crd: + spec: + names: + kind: K8sUniqueIngressHost + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueingresshost + + identical(obj, review) { + obj.metadata.namespace == review.object.metadata.namespace + obj.metadata.name == review.object.metadata.name + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Ingress" + re_match("^(extensions|networking.k8s.io)$", input.review.kind.group) + host := input.review.object.spec.rules[_].host + other := data.inventory.namespace[_][otherapiversion]["Ingress"][name] + re_match("^(extensions|networking.k8s.io)/.+$", otherapiversion) + other.spec.rules[_].host == host + not identical(other, input.review) + msg := sprintf("ingress host conflicts with an existing ingress <%v>", [host]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..5dfb9cfef61881e4e066b2bee42bc93dbcc30c80 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.1 +name: k8suniqueingresshost +displayName: Unique Ingress Host +createdAt: "2022-11-08T23:45:23Z" +description: |- + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +digest: 05d10c126ac78a6569c29e96887af7b23498fdf2feb0cf1250bbf187c61a1df4 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueingresshost +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Ingress Host + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueingresshost/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b4d7f852f1582c7eb62617d3dc2c902b90db1561 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/constraint.yaml @@ -0,0 +1,9 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueIngressHost +metadata: + name: unique-ingress-host +spec: + match: + kinds: + - apiGroups: ["extensions", "networking.k8s.io"] + kinds: ["Ingress"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1e819e200ef6052aa0e32b8a499314d5c07806f0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_allowed.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-allowed + namespace: default +spec: + rules: + - host: example-allowed-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-allowed-host1.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c61893ed691e8e571d35a3b9bd1d7690e4c2e0ad --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ca131f1307da94b9b6decff7ef50e5e9f1a06fc --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_disallowed2.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-host3.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..06bc70922c6a906cfb729e8da5ee92366bd43162 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_inventory_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_inventory_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_inventory_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3f826aeebb5d4fbda9556f0d777cb8d10730a5ac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/samples/unique-ingress-host/example_inventory_disallowed2.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..630838d1d6f51f658b377500d651e45cb5c68a4e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/suite.yaml @@ -0,0 +1,25 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueingresshost +tests: +- name: unique-ingress-host + template: template.yaml + constraint: samples/unique-ingress-host/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-ingress-host/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-ingress-host/example_disallowed.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/unique-ingress-host/example_disallowed2.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed2.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ce25235acfa0b71b9a0675c7fda144a2ca67d346 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/sync.yaml @@ -0,0 +1,17 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "extensions" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1" + kind: "Ingress" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..366b195c80b9d126491f52491905c92eb7e2d416 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.1/template.yaml @@ -0,0 +1,52 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueingresshost + annotations: + metadata.gatekeeper.sh/title: "Unique Ingress Host" + metadata.gatekeeper.sh/version: 1.0.1 + metadata.gatekeeper.sh/requiresSyncData: | + "[ + [ + { + "groups":["extensions"], + "versions": ["v1beta1"], + "kinds": ["Ingress"] + }, + { + "group": ["networking.k8s.io"], + "version": ["v1beta1", "v1"], + "kind": ["Ingress"] + } + ] + ]" + description: >- + Requires all Ingress rule hosts to be unique. + + Does not handle hostname wildcards: + https://kubernetes.io/docs/concepts/services-networking/ingress/ +spec: + crd: + spec: + names: + kind: K8sUniqueIngressHost + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueingresshost + + identical(obj, review) { + obj.metadata.namespace == review.object.metadata.namespace + obj.metadata.name == review.object.metadata.name + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Ingress" + re_match("^(extensions|networking.k8s.io)$", input.review.kind.group) + host := input.review.object.spec.rules[_].host + other := data.inventory.namespace[_][otherapiversion]["Ingress"][name] + re_match("^(extensions|networking.k8s.io)/.+$", otherapiversion) + other.spec.rules[_].host == host + not identical(other, input.review) + msg := sprintf("ingress host conflicts with an existing ingress <%v>", [host]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..2048b7d69d9e05edce599277060ef5f30b658f97 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.2 +name: k8suniqueingresshost +displayName: Unique Ingress Host +createdAt: "2022-12-14T02:34:11Z" +description: |- + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +digest: df9eb5f0e313c41b9c1650a73288e1eba162d4ec279861c7fb854fbe297d1fa3 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueingresshost +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Ingress Host + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueingresshost/1.0.2/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b4d7f852f1582c7eb62617d3dc2c902b90db1561 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/constraint.yaml @@ -0,0 +1,9 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueIngressHost +metadata: + name: unique-ingress-host +spec: + match: + kinds: + - apiGroups: ["extensions", "networking.k8s.io"] + kinds: ["Ingress"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1e819e200ef6052aa0e32b8a499314d5c07806f0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_allowed.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-allowed + namespace: default +spec: + rules: + - host: example-allowed-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-allowed-host1.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c61893ed691e8e571d35a3b9bd1d7690e4c2e0ad --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ca131f1307da94b9b6decff7ef50e5e9f1a06fc --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed2.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-host3.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..06bc70922c6a906cfb729e8da5ee92366bd43162 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3f826aeebb5d4fbda9556f0d777cb8d10730a5ac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed2.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..630838d1d6f51f658b377500d651e45cb5c68a4e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/suite.yaml @@ -0,0 +1,25 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueingresshost +tests: +- name: unique-ingress-host + template: template.yaml + constraint: samples/unique-ingress-host/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-ingress-host/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-ingress-host/example_disallowed.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/unique-ingress-host/example_disallowed2.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed2.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ce25235acfa0b71b9a0675c7fda144a2ca67d346 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/sync.yaml @@ -0,0 +1,17 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "extensions" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1" + kind: "Ingress" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..cc1e11a03d6225d53c3c543fe1de7d07effa03c4 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.2/template.yaml @@ -0,0 +1,52 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueingresshost + annotations: + metadata.gatekeeper.sh/title: "Unique Ingress Host" + metadata.gatekeeper.sh/version: 1.0.2 + metadata.gatekeeper.sh/requiresSyncData: | + "[ + [ + { + "groups": ["extensions"], + "versions": ["v1beta1"], + "kinds": ["Ingress"] + }, + { + "groups": ["networking.k8s.io"], + "versions": ["v1beta1", "v1"], + "kinds": ["Ingress"] + } + ] + ]" + description: >- + Requires all Ingress rule hosts to be unique. + + Does not handle hostname wildcards: + https://kubernetes.io/docs/concepts/services-networking/ingress/ +spec: + crd: + spec: + names: + kind: K8sUniqueIngressHost + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueingresshost + + identical(obj, review) { + obj.metadata.namespace == review.object.metadata.namespace + obj.metadata.name == review.object.metadata.name + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Ingress" + re_match("^(extensions|networking.k8s.io)$", input.review.kind.group) + host := input.review.object.spec.rules[_].host + other := data.inventory.namespace[_][otherapiversion]["Ingress"][name] + re_match("^(extensions|networking.k8s.io)/.+$", otherapiversion) + other.spec.rules[_].host == host + not identical(other, input.review) + msg := sprintf("ingress host conflicts with an existing ingress <%v>", [host]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..3b20ce27ff051a16b1a523178129b3d4d9bcd9b7 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.3 +name: k8suniqueingresshost +displayName: Unique Ingress Host +createdAt: "2023-06-12T20:51:47Z" +description: |- + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +digest: 00196c02161e0cdcfa9d71ea5e2cd620f97d37a12250cc1bccb0c1187b9056c2 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueingresshost +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Ingress Host + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueingresshost/1.0.3/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b4d7f852f1582c7eb62617d3dc2c902b90db1561 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/constraint.yaml @@ -0,0 +1,9 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueIngressHost +metadata: + name: unique-ingress-host +spec: + match: + kinds: + - apiGroups: ["extensions", "networking.k8s.io"] + kinds: ["Ingress"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1e819e200ef6052aa0e32b8a499314d5c07806f0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_allowed.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-allowed + namespace: default +spec: + rules: + - host: example-allowed-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-allowed-host1.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c61893ed691e8e571d35a3b9bd1d7690e4c2e0ad --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ca131f1307da94b9b6decff7ef50e5e9f1a06fc --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_disallowed2.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-host3.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..06bc70922c6a906cfb729e8da5ee92366bd43162 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_inventory_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_inventory_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_inventory_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3f826aeebb5d4fbda9556f0d777cb8d10730a5ac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/samples/unique-ingress-host/example_inventory_disallowed2.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..630838d1d6f51f658b377500d651e45cb5c68a4e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/suite.yaml @@ -0,0 +1,25 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueingresshost +tests: +- name: unique-ingress-host + template: template.yaml + constraint: samples/unique-ingress-host/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-ingress-host/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-ingress-host/example_disallowed.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/unique-ingress-host/example_disallowed2.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed2.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ce25235acfa0b71b9a0675c7fda144a2ca67d346 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/sync.yaml @@ -0,0 +1,17 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "extensions" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1" + kind: "Ingress" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2f6c2efa61d5cbe618e13d6d24912673ab7f3723 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.3/template.yaml @@ -0,0 +1,52 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueingresshost + annotations: + metadata.gatekeeper.sh/title: "Unique Ingress Host" + metadata.gatekeeper.sh/version: 1.0.3 + metadata.gatekeeper.sh/requires-sync-data: | + "[ + [ + { + "groups": ["extensions"], + "versions": ["v1beta1"], + "kinds": ["Ingress"] + }, + { + "groups": ["networking.k8s.io"], + "versions": ["v1beta1", "v1"], + "kinds": ["Ingress"] + } + ] + ]" + description: >- + Requires all Ingress rule hosts to be unique. + + Does not handle hostname wildcards: + https://kubernetes.io/docs/concepts/services-networking/ingress/ +spec: + crd: + spec: + names: + kind: K8sUniqueIngressHost + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueingresshost + + identical(obj, review) { + obj.metadata.namespace == review.object.metadata.namespace + obj.metadata.name == review.object.metadata.name + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Ingress" + re_match("^(extensions|networking.k8s.io)$", input.review.kind.group) + host := input.review.object.spec.rules[_].host + other := data.inventory.namespace[_][otherapiversion]["Ingress"][name] + re_match("^(extensions|networking.k8s.io)/.+$", otherapiversion) + other.spec.rules[_].host == host + not identical(other, input.review) + msg := sprintf("ingress host conflicts with an existing ingress <%v>", [host]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..5959274812039524aa5d20417d4b7d596e8e4a72 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.4 +name: k8suniqueingresshost +displayName: Unique Ingress Host +createdAt: "2023-10-30T21:00:00Z" +description: |- + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +digest: 8c335b1ae3f5d162beea4b6f747c632a871c98ea62b762ac4ae4d90259cdfb5d +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueingresshost +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Ingress Host + Requires all Ingress rule hosts to be unique. + Does not handle hostname wildcards: https://kubernetes.io/docs/concepts/services-networking/ingress/ +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueingresshost/1.0.4/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..b4d7f852f1582c7eb62617d3dc2c902b90db1561 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/constraint.yaml @@ -0,0 +1,9 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueIngressHost +metadata: + name: unique-ingress-host +spec: + match: + kinds: + - apiGroups: ["extensions", "networking.k8s.io"] + kinds: ["Ingress"] diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1e819e200ef6052aa0e32b8a499314d5c07806f0 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_allowed.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-allowed + namespace: default +spec: + rules: + - host: example-allowed-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-allowed-host1.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c61893ed691e8e571d35a3b9bd1d7690e4c2e0ad --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1ca131f1307da94b9b6decff7ef50e5e9f1a06fc --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_disallowed2.yaml @@ -0,0 +1,27 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-disallowed2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 + - host: example-host3.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx2 + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..06bc70922c6a906cfb729e8da5ee92366bd43162 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_inventory_disallowed.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example + namespace: default +spec: + rules: + - host: example-host.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_inventory_disallowed2.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_inventory_disallowed2.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3f826aeebb5d4fbda9556f0d777cb8d10730a5ac --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/samples/unique-ingress-host/example_inventory_disallowed2.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-host-example2 + namespace: default +spec: + rules: + - host: example-host2.example.com + http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: nginx + port: + number: 80 diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..630838d1d6f51f658b377500d651e45cb5c68a4e --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/suite.yaml @@ -0,0 +1,25 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueingresshost +tests: +- name: unique-ingress-host + template: template.yaml + constraint: samples/unique-ingress-host/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-ingress-host/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-ingress-host/example_disallowed.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed.yaml + assertions: + - violations: yes + - name: example-disallowed2 + object: samples/unique-ingress-host/example_disallowed2.yaml + inventory: + - samples/unique-ingress-host/example_inventory_disallowed2.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..ce25235acfa0b71b9a0675c7fda144a2ca67d346 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/sync.yaml @@ -0,0 +1,17 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "extensions" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1beta1" + kind: "Ingress" + - group: "networking.k8s.io" + version: "v1" + kind: "Ingress" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c534b2a206302e1df875d2ae216d3420c69c1c26 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueingresshost/1.0.4/template.yaml @@ -0,0 +1,52 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueingresshost + annotations: + metadata.gatekeeper.sh/title: "Unique Ingress Host" + metadata.gatekeeper.sh/version: 1.0.4 + metadata.gatekeeper.sh/requires-sync-data: | + "[ + [ + { + "groups": ["extensions"], + "versions": ["v1beta1"], + "kinds": ["Ingress"] + }, + { + "groups": ["networking.k8s.io"], + "versions": ["v1beta1", "v1"], + "kinds": ["Ingress"] + } + ] + ]" + description: >- + Requires all Ingress rule hosts to be unique. + + Does not handle hostname wildcards: + https://kubernetes.io/docs/concepts/services-networking/ingress/ +spec: + crd: + spec: + names: + kind: K8sUniqueIngressHost + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueingresshost + + identical(obj, review) { + obj.metadata.namespace == review.object.metadata.namespace + obj.metadata.name == review.object.metadata.name + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Ingress" + regex.match("^(extensions|networking.k8s.io)$", input.review.kind.group) + host := input.review.object.spec.rules[_].host + other := data.inventory.namespace[_][otherapiversion]["Ingress"][name] + regex.match("^(extensions|networking.k8s.io)/.+$", otherapiversion) + other.spec.rules[_].host == host + not identical(other, input.review) + msg := sprintf("ingress host conflicts with an existing ingress <%v>", [host]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..e9f71c23b310b38e18215d7a170b95874262e752 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.0 +name: k8suniqueserviceselector +displayName: Unique Service Selector +createdAt: "2022-09-16T16:22:28Z" +description: |- + Requires Services to have unique selectors within a namespace. Selectors are considered the same if they have identical keys and values. Selectors may share a key/value pair so long as there is at least one distinct key/value pair between them. + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +digest: 619dceb345b6050715f8c7526c61cbca56b0f5b2fb5113365f29dfc42e626073 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueserviceselector +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Service Selector + Requires Services to have unique selectors within a namespace. Selectors are considered the same if they have identical keys and values. Selectors may share a key/value pair so long as there is at least one distinct key/value pair between them. + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueserviceselector/1.0.0/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3a00cd8b1bdf03072c6ecfe825cda65f31f616b5 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/constraint.yaml @@ -0,0 +1,6 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueServiceSelector +metadata: + name: unique-service-selector + labels: + owner: admin.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1d69847d93c2fe0728338442b164f56216bde5ae --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_allowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-disallowed + namespace: default +spec: + ports: + - port: 443 + selector: + key: other-value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6062ce7ff85327372e064760f504fcaee656a8c9 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-disallowed + namespace: default +spec: + ports: + - port: 443 + selector: + key: value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..19c1aa7ea0541864a063d4a568fd86c2d8fc8efe --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/samples/unique-service-selector/example_inventory_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-example + namespace: default +spec: + ports: + - port: 443 + selector: + key: value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..abefd5d0e805c2c870aca8069178fbb454b03fb2 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/suite.yaml @@ -0,0 +1,19 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueserviceselector +tests: +- name: unique-service-selector + template: template.yaml + constraint: samples/unique-service-selector/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-service-selector/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-service-selector/example_disallowed.yaml + inventory: + - samples/unique-service-selector/example_inventory_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2b63aa7d942f9ab6f8f9b58884d52399da3a7e44 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.0/template.yaml @@ -0,0 +1,59 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueserviceselector + annotations: + metadata.gatekeeper.sh/title: "Unique Service Selector" + metadata.gatekeeper.sh/version: 1.0.0 + description: >- + Requires Services to have unique selectors within a namespace. + Selectors are considered the same if they have identical keys and values. + Selectors may share a key/value pair so long as there is at least one + distinct key/value pair between them. + + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +spec: + crd: + spec: + names: + kind: K8sUniqueServiceSelector + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueserviceselector + + make_apiversion(kind) = apiVersion { + g := kind.group + v := kind.version + g != "" + apiVersion = sprintf("%v/%v", [g, v]) + } + + make_apiversion(kind) = apiVersion { + kind.group == "" + apiVersion = kind.version + } + + identical(obj, review) { + obj.metadata.namespace == review.namespace + obj.metadata.name == review.name + obj.kind == review.kind.kind + obj.apiVersion == make_apiversion(review.kind) + } + + flatten_selector(obj) = flattened { + selectors := [s | s = concat(":", [key, val]); val = obj.spec.selector[key]] + flattened := concat(",", sort(selectors)) + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Service" + input.review.kind.version == "v1" + input.review.kind.group == "" + input_selector := flatten_selector(input.review.object) + other := data.inventory.namespace[namespace][_]["Service"][name] + not identical(other, input.review) + other_selector := flatten_selector(other) + input_selector == other_selector + msg := sprintf("same selector as service <%v> in namespace <%v>", [name, namespace]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..b88597a5d2094f6180fe738c9fbc3e8318aab586 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.1 +name: k8suniqueserviceselector +displayName: Unique Service Selector +createdAt: "2022-11-08T23:45:23Z" +description: |- + Requires Services to have unique selectors within a namespace. Selectors are considered the same if they have identical keys and values. Selectors may share a key/value pair so long as there is at least one distinct key/value pair between them. + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +digest: 5fdf21c0eb998edd9eb8f590f21122f59906eb8a6b261d5322b31f9e2c305790 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueserviceselector +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Service Selector + Requires Services to have unique selectors within a namespace. Selectors are considered the same if they have identical keys and values. Selectors may share a key/value pair so long as there is at least one distinct key/value pair between them. + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueserviceselector/1.0.1/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3a00cd8b1bdf03072c6ecfe825cda65f31f616b5 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/constraint.yaml @@ -0,0 +1,6 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueServiceSelector +metadata: + name: unique-service-selector + labels: + owner: admin.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1d69847d93c2fe0728338442b164f56216bde5ae --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_allowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-disallowed + namespace: default +spec: + ports: + - port: 443 + selector: + key: other-value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6062ce7ff85327372e064760f504fcaee656a8c9 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-disallowed + namespace: default +spec: + ports: + - port: 443 + selector: + key: value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..19c1aa7ea0541864a063d4a568fd86c2d8fc8efe --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/samples/unique-service-selector/example_inventory_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-example + namespace: default +spec: + ports: + - port: 443 + selector: + key: value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..abefd5d0e805c2c870aca8069178fbb454b03fb2 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/suite.yaml @@ -0,0 +1,19 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueserviceselector +tests: +- name: unique-service-selector + template: template.yaml + constraint: samples/unique-service-selector/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-service-selector/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-service-selector/example_disallowed.yaml + inventory: + - samples/unique-service-selector/example_inventory_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..433294b0fd6d4d2f87f25485d9060f71e0308caf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "" + version: "v1" + kind: "Service" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f9252daa5de1114d36d4d7b1ba27658c9f03f3d9 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.1/template.yaml @@ -0,0 +1,69 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueserviceselector + annotations: + metadata.gatekeeper.sh/title: "Unique Service Selector" + metadata.gatekeeper.sh/version: 1.0.1 + metadata.gatekeeper.sh/requiresSyncData: | + "[ + [ + { + "groups":[""], + "versions": ["v1"], + "kinds": ["Service"] + } + ] + ]" + description: >- + Requires Services to have unique selectors within a namespace. + Selectors are considered the same if they have identical keys and values. + Selectors may share a key/value pair so long as there is at least one + distinct key/value pair between them. + + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +spec: + crd: + spec: + names: + kind: K8sUniqueServiceSelector + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueserviceselector + + make_apiversion(kind) = apiVersion { + g := kind.group + v := kind.version + g != "" + apiVersion = sprintf("%v/%v", [g, v]) + } + + make_apiversion(kind) = apiVersion { + kind.group == "" + apiVersion = kind.version + } + + identical(obj, review) { + obj.metadata.namespace == review.namespace + obj.metadata.name == review.name + obj.kind == review.kind.kind + obj.apiVersion == make_apiversion(review.kind) + } + + flatten_selector(obj) = flattened { + selectors := [s | s = concat(":", [key, val]); val = obj.spec.selector[key]] + flattened := concat(",", sort(selectors)) + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Service" + input.review.kind.version == "v1" + input.review.kind.group == "" + input_selector := flatten_selector(input.review.object) + other := data.inventory.namespace[namespace][_]["Service"][name] + not identical(other, input.review) + other_selector := flatten_selector(other) + input_selector == other_selector + msg := sprintf("same selector as service <%v> in namespace <%v>", [name, namespace]) + } diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/artifacthub-pkg.yml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/artifacthub-pkg.yml new file mode 100644 index 0000000000000000000000000000000000000000..548030cba7674fd7aab6867443abb28e891a4d19 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/artifacthub-pkg.yml @@ -0,0 +1,25 @@ +version: 1.0.2 +name: k8suniqueserviceselector +displayName: Unique Service Selector +createdAt: "2023-06-12T20:47:48Z" +description: |- + Requires Services to have unique selectors within a namespace. Selectors are considered the same if they have identical keys and values. Selectors may share a key/value pair so long as there is at least one distinct key/value pair between them. + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +digest: ccb39d306eae45a9be7a0b1df4f686e2a38e1c73a1f2d4ab37f2f01ef626bdf4 +license: Apache-2.0 +homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/uniqueserviceselector +keywords: + - gatekeeper + - open-policy-agent + - policies +readme: |- + # Unique Service Selector + Requires Services to have unique selectors within a namespace. Selectors are considered the same if they have identical keys and values. Selectors may share a key/value pair so long as there is at least one distinct key/value pair between them. + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +install: |- + ### Usage + ```shell + kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/uniqueserviceselector/1.0.2/template.yaml + ``` +provider: + name: Gatekeeper Library diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/kustomization.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/kustomization.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7d70d11b719ca4d91f8218f217c28b961662a7f3 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - template.yaml diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/constraint.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/constraint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..3a00cd8b1bdf03072c6ecfe825cda65f31f616b5 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/constraint.yaml @@ -0,0 +1,6 @@ +apiVersion: constraints.gatekeeper.sh/v1beta1 +kind: K8sUniqueServiceSelector +metadata: + name: unique-service-selector + labels: + owner: admin.agilebank.demo diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_allowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_allowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1d69847d93c2fe0728338442b164f56216bde5ae --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_allowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-disallowed + namespace: default +spec: + ports: + - port: 443 + selector: + key: other-value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6062ce7ff85327372e064760f504fcaee656a8c9 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-disallowed + namespace: default +spec: + ports: + - port: 443 + selector: + key: value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_inventory_disallowed.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_inventory_disallowed.yaml new file mode 100644 index 0000000000000000000000000000000000000000..19c1aa7ea0541864a063d4a568fd86c2d8fc8efe --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/samples/unique-service-selector/example_inventory_disallowed.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: gatekeeper-test-service-example + namespace: default +spec: + ports: + - port: 443 + selector: + key: value diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/suite.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/suite.yaml new file mode 100644 index 0000000000000000000000000000000000000000..abefd5d0e805c2c870aca8069178fbb454b03fb2 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/suite.yaml @@ -0,0 +1,19 @@ +kind: Suite +apiVersion: test.gatekeeper.sh/v1alpha1 +metadata: + name: uniqueserviceselector +tests: +- name: unique-service-selector + template: template.yaml + constraint: samples/unique-service-selector/constraint.yaml + cases: + - name: example-allowed + object: samples/unique-service-selector/example_allowed.yaml + assertions: + - violations: no + - name: example-disallowed + object: samples/unique-service-selector/example_disallowed.yaml + inventory: + - samples/unique-service-selector/example_inventory_disallowed.yaml + assertions: + - violations: yes diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/sync.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/sync.yaml new file mode 100644 index 0000000000000000000000000000000000000000..433294b0fd6d4d2f87f25485d9060f71e0308caf --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/sync.yaml @@ -0,0 +1,11 @@ +apiVersion: config.gatekeeper.sh/v1alpha1 +kind: Config +metadata: + name: config + namespace: "gatekeeper-system" +spec: + sync: + syncOnly: + - group: "" + version: "v1" + kind: "Service" diff --git a/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/template.yaml b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/template.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8fb9eb2f453a612ae6d4af388e9ace90b3229451 --- /dev/null +++ b/source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/uniqueserviceselector/1.0.2/template.yaml @@ -0,0 +1,69 @@ +apiVersion: templates.gatekeeper.sh/v1 +kind: ConstraintTemplate +metadata: + name: k8suniqueserviceselector + annotations: + metadata.gatekeeper.sh/title: "Unique Service Selector" + metadata.gatekeeper.sh/version: 1.0.2 + metadata.gatekeeper.sh/requires-sync-data: | + "[ + [ + { + "groups":[""], + "versions": ["v1"], + "kinds": ["Service"] + } + ] + ]" + description: >- + Requires Services to have unique selectors within a namespace. + Selectors are considered the same if they have identical keys and values. + Selectors may share a key/value pair so long as there is at least one + distinct key/value pair between them. + + https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service +spec: + crd: + spec: + names: + kind: K8sUniqueServiceSelector + targets: + - target: admission.k8s.gatekeeper.sh + rego: | + package k8suniqueserviceselector + + make_apiversion(kind) = apiVersion { + g := kind.group + v := kind.version + g != "" + apiVersion = sprintf("%v/%v", [g, v]) + } + + make_apiversion(kind) = apiVersion { + kind.group == "" + apiVersion = kind.version + } + + identical(obj, review) { + obj.metadata.namespace == review.namespace + obj.metadata.name == review.name + obj.kind == review.kind.kind + obj.apiVersion == make_apiversion(review.kind) + } + + flatten_selector(obj) = flattened { + selectors := [s | s = concat(":", [key, val]); val = obj.spec.selector[key]] + flattened := concat(",", sort(selectors)) + } + + violation[{"msg": msg}] { + input.review.kind.kind == "Service" + input.review.kind.version == "v1" + input.review.kind.group == "" + input_selector := flatten_selector(input.review.object) + other := data.inventory.namespace[namespace][_]["Service"][name] + not identical(other, input.review) + other_selector := flatten_selector(other) + input_selector == other_selector + msg := sprintf("same selector as service <%v> in namespace <%v>", [name, namespace]) + }