Datasets:
Add pinned source: gatekeeper-library (part 3)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.0/template.yaml +57 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_allowed.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_disallowed.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/suite.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/template.yaml +58 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/constraint.yaml +13 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_allowed.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_disallowed.yaml +19 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/suite.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/template.yaml +58 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/constraint.yaml +18 -0
- 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 +14 -0
- 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 +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/suite.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/template.yaml +59 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/constraint.yaml +18 -0
- 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 +14 -0
- 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 +11 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/suite.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/template.yaml +59 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/constraint.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_allowed.yaml +6 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_disallowed.yaml +4 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/suite.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/template.yaml +71 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/constraint.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_allowed.yaml +6 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_disallowed.yaml +4 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/suite.yaml +17 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/template.yaml +68 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/artifacthub-pkg.yml +22 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/kustomization.yaml +2 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/constraint.yaml +14 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_allowed.yaml +6 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed.yaml +4 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed_label_value.yaml +6 -0
- source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/suite.yaml +21 -0
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.0/template.yaml
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8sreplicalimits
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Replica Limits"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.0
|
| 8 |
+
description: >-
|
| 9 |
+
Requires that objects with the field `spec.replicas` (Deployments,
|
| 10 |
+
ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sReplicaLimits
|
| 16 |
+
validation:
|
| 17 |
+
# Schema for the `parameters` field
|
| 18 |
+
openAPIV3Schema:
|
| 19 |
+
type: object
|
| 20 |
+
properties:
|
| 21 |
+
ranges:
|
| 22 |
+
type: array
|
| 23 |
+
description: Allowed ranges for numbers of replicas. Values are inclusive.
|
| 24 |
+
items:
|
| 25 |
+
type: object
|
| 26 |
+
description: A range of allowed replicas. Values are inclusive.
|
| 27 |
+
properties:
|
| 28 |
+
min_replicas:
|
| 29 |
+
description: The minimum number of replicas allowed, inclusive.
|
| 30 |
+
type: integer
|
| 31 |
+
max_replicas:
|
| 32 |
+
description: The maximum number of replicas allowed, inclusive.
|
| 33 |
+
type: integer
|
| 34 |
+
targets:
|
| 35 |
+
- target: admission.k8s.gatekeeper.sh
|
| 36 |
+
rego: |
|
| 37 |
+
package k8sreplicalimits
|
| 38 |
+
|
| 39 |
+
deployment_name = input.review.object.metadata.name
|
| 40 |
+
|
| 41 |
+
violation[{"msg": msg}] {
|
| 42 |
+
spec := input.review.object.spec
|
| 43 |
+
not input_replica_limit(spec)
|
| 44 |
+
msg := sprintf("The provided number of replicas is not allowed for deployment: %v. Allowed ranges: %v", [deployment_name, input.parameters])
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
input_replica_limit(spec) {
|
| 48 |
+
provided := input.review.object.spec.replicas
|
| 49 |
+
count(input.parameters.ranges) > 0
|
| 50 |
+
range := input.parameters.ranges[_]
|
| 51 |
+
value_within_range(range, provided)
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
value_within_range(range, value) {
|
| 55 |
+
range.min_replicas <= value
|
| 56 |
+
range.max_replicas >= value
|
| 57 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.0.1
|
| 2 |
+
name: k8sreplicalimits
|
| 3 |
+
displayName: Replica Limits
|
| 4 |
+
createdAt: "2023-03-31T20:34:16Z"
|
| 5 |
+
description: Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 6 |
+
digest: a8dc0e94f30cdf1f4aff2e69551744b6eaee3f4e60dba3393705f81363a249e5
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/replicalimits
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Replica Limits
|
| 15 |
+
Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/replicalimits/1.0.1/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sReplicaLimits
|
| 3 |
+
metadata:
|
| 4 |
+
name: replica-limits
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: ["apps"]
|
| 9 |
+
kinds: ["Deployment"]
|
| 10 |
+
parameters:
|
| 11 |
+
ranges:
|
| 12 |
+
- min_replicas: 3
|
| 13 |
+
max_replicas: 50
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_allowed.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: apps/v1
|
| 2 |
+
kind: Deployment
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-deployment
|
| 5 |
+
spec:
|
| 6 |
+
selector:
|
| 7 |
+
matchLabels:
|
| 8 |
+
app: nginx
|
| 9 |
+
replicas: 3
|
| 10 |
+
template:
|
| 11 |
+
metadata:
|
| 12 |
+
labels:
|
| 13 |
+
app: nginx
|
| 14 |
+
spec:
|
| 15 |
+
containers:
|
| 16 |
+
- name: nginx
|
| 17 |
+
image: nginx:1.14.2
|
| 18 |
+
ports:
|
| 19 |
+
- containerPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/samples/replicalimits/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: apps/v1
|
| 2 |
+
kind: Deployment
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-deployment
|
| 5 |
+
spec:
|
| 6 |
+
selector:
|
| 7 |
+
matchLabels:
|
| 8 |
+
app: nginx
|
| 9 |
+
replicas: 100
|
| 10 |
+
template:
|
| 11 |
+
metadata:
|
| 12 |
+
labels:
|
| 13 |
+
app: nginx
|
| 14 |
+
spec:
|
| 15 |
+
containers:
|
| 16 |
+
- name: nginx
|
| 17 |
+
image: nginx:1.14.2
|
| 18 |
+
ports:
|
| 19 |
+
- containerPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/suite.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: replicalimits
|
| 5 |
+
tests:
|
| 6 |
+
- name: replica-limit
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/replicalimits/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/replicalimits/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/replicalimits/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.1/template.yaml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8sreplicalimits
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Replica Limits"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.1
|
| 8 |
+
description: >-
|
| 9 |
+
Requires that objects with the field `spec.replicas` (Deployments,
|
| 10 |
+
ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sReplicaLimits
|
| 16 |
+
validation:
|
| 17 |
+
# Schema for the `parameters` field
|
| 18 |
+
openAPIV3Schema:
|
| 19 |
+
type: object
|
| 20 |
+
properties:
|
| 21 |
+
ranges:
|
| 22 |
+
type: array
|
| 23 |
+
description: Allowed ranges for numbers of replicas. Values are inclusive.
|
| 24 |
+
items:
|
| 25 |
+
type: object
|
| 26 |
+
description: A range of allowed replicas. Values are inclusive.
|
| 27 |
+
properties:
|
| 28 |
+
min_replicas:
|
| 29 |
+
description: The minimum number of replicas allowed, inclusive.
|
| 30 |
+
type: integer
|
| 31 |
+
max_replicas:
|
| 32 |
+
description: The maximum number of replicas allowed, inclusive.
|
| 33 |
+
type: integer
|
| 34 |
+
targets:
|
| 35 |
+
- target: admission.k8s.gatekeeper.sh
|
| 36 |
+
rego: |
|
| 37 |
+
package k8sreplicalimits
|
| 38 |
+
|
| 39 |
+
object_name = input.review.object.metadata.name
|
| 40 |
+
object_kind = input.review.kind.kind
|
| 41 |
+
|
| 42 |
+
violation[{"msg": msg}] {
|
| 43 |
+
spec := input.review.object.spec
|
| 44 |
+
not input_replica_limit(spec)
|
| 45 |
+
msg := sprintf("The provided number of replicas is not allowed for %v: %v. Allowed ranges: %v", [object_kind, object_name, input.parameters])
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
input_replica_limit(spec) {
|
| 49 |
+
provided := input.review.object.spec.replicas
|
| 50 |
+
count(input.parameters.ranges) > 0
|
| 51 |
+
range := input.parameters.ranges[_]
|
| 52 |
+
value_within_range(range, provided)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
value_within_range(range, value) {
|
| 56 |
+
range.min_replicas <= value
|
| 57 |
+
range.max_replicas >= value
|
| 58 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.0.2
|
| 2 |
+
name: k8sreplicalimits
|
| 3 |
+
displayName: Replica Limits
|
| 4 |
+
createdAt: "2023-10-30T21:00:00Z"
|
| 5 |
+
description: Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 6 |
+
digest: 858bf59f6c7408f2fb390a181b2f6db5e4d8fbe5eb580aa45b5601d6ae2d4064
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/replicalimits
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Replica Limits
|
| 15 |
+
Requires that objects with the field `spec.replicas` (Deployments, ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/replicalimits/1.0.2/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/constraint.yaml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sReplicaLimits
|
| 3 |
+
metadata:
|
| 4 |
+
name: replica-limits
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: ["apps"]
|
| 9 |
+
kinds: ["Deployment"]
|
| 10 |
+
parameters:
|
| 11 |
+
ranges:
|
| 12 |
+
- min_replicas: 3
|
| 13 |
+
max_replicas: 50
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_allowed.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: apps/v1
|
| 2 |
+
kind: Deployment
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-deployment
|
| 5 |
+
spec:
|
| 6 |
+
selector:
|
| 7 |
+
matchLabels:
|
| 8 |
+
app: nginx
|
| 9 |
+
replicas: 3
|
| 10 |
+
template:
|
| 11 |
+
metadata:
|
| 12 |
+
labels:
|
| 13 |
+
app: nginx
|
| 14 |
+
spec:
|
| 15 |
+
containers:
|
| 16 |
+
- name: nginx
|
| 17 |
+
image: nginx:1.14.2
|
| 18 |
+
ports:
|
| 19 |
+
- containerPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/samples/replicalimits/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: apps/v1
|
| 2 |
+
kind: Deployment
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-deployment
|
| 5 |
+
spec:
|
| 6 |
+
selector:
|
| 7 |
+
matchLabels:
|
| 8 |
+
app: nginx
|
| 9 |
+
replicas: 100
|
| 10 |
+
template:
|
| 11 |
+
metadata:
|
| 12 |
+
labels:
|
| 13 |
+
app: nginx
|
| 14 |
+
spec:
|
| 15 |
+
containers:
|
| 16 |
+
- name: nginx
|
| 17 |
+
image: nginx:1.14.2
|
| 18 |
+
ports:
|
| 19 |
+
- containerPort: 80
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/suite.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: replicalimits
|
| 5 |
+
tests:
|
| 6 |
+
- name: replica-limit
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/replicalimits/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/replicalimits/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/replicalimits/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/replicalimits/1.0.2/template.yaml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8sreplicalimits
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Replica Limits"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.2
|
| 8 |
+
description: >-
|
| 9 |
+
Requires that objects with the field `spec.replicas` (Deployments,
|
| 10 |
+
ReplicaSets, etc.) specify a number of replicas within defined ranges.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sReplicaLimits
|
| 16 |
+
validation:
|
| 17 |
+
# Schema for the `parameters` field
|
| 18 |
+
openAPIV3Schema:
|
| 19 |
+
type: object
|
| 20 |
+
properties:
|
| 21 |
+
ranges:
|
| 22 |
+
type: array
|
| 23 |
+
description: Allowed ranges for numbers of replicas. Values are inclusive.
|
| 24 |
+
items:
|
| 25 |
+
type: object
|
| 26 |
+
description: A range of allowed replicas. Values are inclusive.
|
| 27 |
+
properties:
|
| 28 |
+
min_replicas:
|
| 29 |
+
description: The minimum number of replicas allowed, inclusive.
|
| 30 |
+
type: integer
|
| 31 |
+
max_replicas:
|
| 32 |
+
description: The maximum number of replicas allowed, inclusive.
|
| 33 |
+
type: integer
|
| 34 |
+
targets:
|
| 35 |
+
- target: admission.k8s.gatekeeper.sh
|
| 36 |
+
rego: |
|
| 37 |
+
package k8sreplicalimits
|
| 38 |
+
|
| 39 |
+
object_name = input.review.object.metadata.name
|
| 40 |
+
object_kind = input.review.kind.kind
|
| 41 |
+
|
| 42 |
+
violation[{"msg": msg}] {
|
| 43 |
+
spec := input.review.object.spec
|
| 44 |
+
not input_replica_limit(spec)
|
| 45 |
+
msg := sprintf("The provided number of replicas is not allowed for %v: %v. Allowed ranges: %v", [object_kind, object_name, input.parameters])
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
input_replica_limit(spec) {
|
| 49 |
+
provided := spec.replicas
|
| 50 |
+
count(input.parameters.ranges) > 0
|
| 51 |
+
range := input.parameters.ranges[_]
|
| 52 |
+
value_within_range(range, provided)
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
value_within_range(range, value) {
|
| 56 |
+
range.min_replicas <= value
|
| 57 |
+
range.max_replicas >= value
|
| 58 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.0.0
|
| 2 |
+
name: k8srequiredannotations
|
| 3 |
+
displayName: Required Annotations
|
| 4 |
+
createdAt: "2022-09-26T17:28:27Z"
|
| 5 |
+
description: Requires resources to contain specified annotations, with values matching provided regular expressions.
|
| 6 |
+
digest: c4074e5cb8cc492504676bb95bbb9e588745f682949911f99e0b750df0cb3b15
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredannotations
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Required Annotations
|
| 15 |
+
Requires resources to contain specified annotations, with values matching provided regular expressions.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredannotations/1.0.0/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/samples/all-must-have-certain-set-of-annotations/constraint.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sRequiredAnnotations
|
| 3 |
+
metadata:
|
| 4 |
+
name: all-must-have-certain-set-of-annotations
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Service"]
|
| 10 |
+
parameters:
|
| 11 |
+
message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations."
|
| 12 |
+
annotations:
|
| 13 |
+
- key: a8r.io/owner
|
| 14 |
+
# Matches email address or github user
|
| 15 |
+
allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$
|
| 16 |
+
- key: a8r.io/runbook
|
| 17 |
+
# Matches urls including or not http/https
|
| 18 |
+
allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
|
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
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Service
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-service
|
| 5 |
+
annotations:
|
| 6 |
+
a8r.io/owner: "dev-team-alfa@contoso.com"
|
| 7 |
+
a8r.io/runbook: "https://confluence.contoso.com/dev-team-alfa/runbooks"
|
| 8 |
+
spec:
|
| 9 |
+
ports:
|
| 10 |
+
- name: http
|
| 11 |
+
port: 80
|
| 12 |
+
targetPort: 8080
|
| 13 |
+
selector:
|
| 14 |
+
app: foo
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Service
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-service
|
| 5 |
+
spec:
|
| 6 |
+
ports:
|
| 7 |
+
- name: http
|
| 8 |
+
port: 80
|
| 9 |
+
targetPort: 8080
|
| 10 |
+
selector:
|
| 11 |
+
app: foo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/suite.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: requiredannotations
|
| 5 |
+
tests:
|
| 6 |
+
- name: must-have-set-of-annotations
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/all-must-have-certain-set-of-annotations/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/all-must-have-certain-set-of-annotations/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.0/template.yaml
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8srequiredannotations
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Required Annotations"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.0
|
| 8 |
+
description: >-
|
| 9 |
+
Requires resources to contain specified annotations, with values matching
|
| 10 |
+
provided regular expressions.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sRequiredAnnotations
|
| 16 |
+
validation:
|
| 17 |
+
openAPIV3Schema:
|
| 18 |
+
type: object
|
| 19 |
+
properties:
|
| 20 |
+
message:
|
| 21 |
+
type: string
|
| 22 |
+
annotations:
|
| 23 |
+
type: array
|
| 24 |
+
description: >-
|
| 25 |
+
A list of annotations and values the object must specify.
|
| 26 |
+
items:
|
| 27 |
+
type: object
|
| 28 |
+
properties:
|
| 29 |
+
key:
|
| 30 |
+
type: string
|
| 31 |
+
description: >-
|
| 32 |
+
The required annotation.
|
| 33 |
+
allowedRegex:
|
| 34 |
+
type: string
|
| 35 |
+
description: >-
|
| 36 |
+
If specified, a regular expression the annotation's value
|
| 37 |
+
must match. The value must contain at least one match for
|
| 38 |
+
the regular expression.
|
| 39 |
+
targets:
|
| 40 |
+
- target: admission.k8s.gatekeeper.sh
|
| 41 |
+
rego: |
|
| 42 |
+
package k8srequiredannotations
|
| 43 |
+
|
| 44 |
+
violation[{"msg": msg, "details": {"missing_annotations": missing}}] {
|
| 45 |
+
provided := {annotation | input.review.object.metadata.annotations[annotation]}
|
| 46 |
+
required := {annotation | annotation := input.parameters.annotations[_].key}
|
| 47 |
+
missing := required - provided
|
| 48 |
+
count(missing) > 0
|
| 49 |
+
msg := sprintf("you must provide annotation(s): %v", [missing])
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
violation[{"msg": msg}] {
|
| 53 |
+
value := input.review.object.metadata.annotations[key]
|
| 54 |
+
expected := input.parameters.annotations[_]
|
| 55 |
+
expected.key == key
|
| 56 |
+
expected.allowedRegex != ""
|
| 57 |
+
not re_match(expected.allowedRegex, value)
|
| 58 |
+
msg := sprintf("Annotation <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex])
|
| 59 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.0.1
|
| 2 |
+
name: k8srequiredannotations
|
| 3 |
+
displayName: Required Annotations
|
| 4 |
+
createdAt: "2023-10-30T21:00:00Z"
|
| 5 |
+
description: Requires resources to contain specified annotations, with values matching provided regular expressions.
|
| 6 |
+
digest: 332839ec5e037ea20aa5b9a204ad2490ad76d05f5d2b961ace5e90c7b8c864be
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredannotations
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Required Annotations
|
| 15 |
+
Requires resources to contain specified annotations, with values matching provided regular expressions.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredannotations/1.0.1/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/samples/all-must-have-certain-set-of-annotations/constraint.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sRequiredAnnotations
|
| 3 |
+
metadata:
|
| 4 |
+
name: all-must-have-certain-set-of-annotations
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Service"]
|
| 10 |
+
parameters:
|
| 11 |
+
message: "All services must have a `a8r.io/owner` and `a8r.io/runbook` annotations."
|
| 12 |
+
annotations:
|
| 13 |
+
- key: a8r.io/owner
|
| 14 |
+
# Matches email address or github user
|
| 15 |
+
allowedRegex: ^([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}|[a-z]{1,39})$
|
| 16 |
+
- key: a8r.io/runbook
|
| 17 |
+
# Matches urls including or not http/https
|
| 18 |
+
allowedRegex: ^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$
|
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
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Service
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-service
|
| 5 |
+
annotations:
|
| 6 |
+
a8r.io/owner: "dev-team-alfa@contoso.com"
|
| 7 |
+
a8r.io/runbook: "https://confluence.contoso.com/dev-team-alfa/runbooks"
|
| 8 |
+
spec:
|
| 9 |
+
ports:
|
| 10 |
+
- name: http
|
| 11 |
+
port: 80
|
| 12 |
+
targetPort: 8080
|
| 13 |
+
selector:
|
| 14 |
+
app: foo
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Service
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-service
|
| 5 |
+
spec:
|
| 6 |
+
ports:
|
| 7 |
+
- name: http
|
| 8 |
+
port: 80
|
| 9 |
+
targetPort: 8080
|
| 10 |
+
selector:
|
| 11 |
+
app: foo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/suite.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: requiredannotations
|
| 5 |
+
tests:
|
| 6 |
+
- name: must-have-set-of-annotations
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/all-must-have-certain-set-of-annotations/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/all-must-have-certain-set-of-annotations/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/all-must-have-certain-set-of-annotations/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredannotations/1.0.1/template.yaml
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8srequiredannotations
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Required Annotations"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.1
|
| 8 |
+
description: >-
|
| 9 |
+
Requires resources to contain specified annotations, with values matching
|
| 10 |
+
provided regular expressions.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sRequiredAnnotations
|
| 16 |
+
validation:
|
| 17 |
+
openAPIV3Schema:
|
| 18 |
+
type: object
|
| 19 |
+
properties:
|
| 20 |
+
message:
|
| 21 |
+
type: string
|
| 22 |
+
annotations:
|
| 23 |
+
type: array
|
| 24 |
+
description: >-
|
| 25 |
+
A list of annotations and values the object must specify.
|
| 26 |
+
items:
|
| 27 |
+
type: object
|
| 28 |
+
properties:
|
| 29 |
+
key:
|
| 30 |
+
type: string
|
| 31 |
+
description: >-
|
| 32 |
+
The required annotation.
|
| 33 |
+
allowedRegex:
|
| 34 |
+
type: string
|
| 35 |
+
description: >-
|
| 36 |
+
If specified, a regular expression the annotation's value
|
| 37 |
+
must match. The value must contain at least one match for
|
| 38 |
+
the regular expression.
|
| 39 |
+
targets:
|
| 40 |
+
- target: admission.k8s.gatekeeper.sh
|
| 41 |
+
rego: |
|
| 42 |
+
package k8srequiredannotations
|
| 43 |
+
|
| 44 |
+
violation[{"msg": msg, "details": {"missing_annotations": missing}}] {
|
| 45 |
+
provided := {annotation | input.review.object.metadata.annotations[annotation]}
|
| 46 |
+
required := {annotation | annotation := input.parameters.annotations[_].key}
|
| 47 |
+
missing := required - provided
|
| 48 |
+
count(missing) > 0
|
| 49 |
+
msg := sprintf("you must provide annotation(s): %v", [missing])
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
violation[{"msg": msg}] {
|
| 53 |
+
value := input.review.object.metadata.annotations[key]
|
| 54 |
+
expected := input.parameters.annotations[_]
|
| 55 |
+
expected.key == key
|
| 56 |
+
expected.allowedRegex != ""
|
| 57 |
+
not regex.match(expected.allowedRegex, value)
|
| 58 |
+
msg := sprintf("Annotation <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex])
|
| 59 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.0.0
|
| 2 |
+
name: k8srequiredlabels
|
| 3 |
+
displayName: Required Labels
|
| 4 |
+
createdAt: "2022-09-26T17:28:27Z"
|
| 5 |
+
description: Requires resources to contain specified labels, with values matching provided regular expressions.
|
| 6 |
+
digest: e0f96d5945642406b067a22f152dcf76ac038a8d4f0969668c7e70c2471731db
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Required Labels
|
| 15 |
+
Requires resources to contain specified labels, with values matching provided regular expressions.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.0.0/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/constraint.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sRequiredLabels
|
| 3 |
+
metadata:
|
| 4 |
+
name: all-must-have-owner
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Namespace"]
|
| 10 |
+
parameters:
|
| 11 |
+
message: "All namespaces must have an `owner` label that points to your company username"
|
| 12 |
+
labels:
|
| 13 |
+
- key: owner
|
| 14 |
+
allowedRegex: "^[a-zA-Z]+.agilebank.demo$"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_allowed.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-namespace
|
| 5 |
+
labels:
|
| 6 |
+
owner: user.agilebank.demo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/samples/all-must-have-owner/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-namespace
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/suite.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: requiredlabels
|
| 5 |
+
tests:
|
| 6 |
+
- name: must-have-owner
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/all-must-have-owner/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/all-must-have-owner/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/all-must-have-owner/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.0/template.yaml
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8srequiredlabels
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Required Labels"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.0
|
| 8 |
+
description: >-
|
| 9 |
+
Requires resources to contain specified labels, with values matching
|
| 10 |
+
provided regular expressions.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sRequiredLabels
|
| 16 |
+
validation:
|
| 17 |
+
openAPIV3Schema:
|
| 18 |
+
type: object
|
| 19 |
+
properties:
|
| 20 |
+
message:
|
| 21 |
+
type: string
|
| 22 |
+
labels:
|
| 23 |
+
type: array
|
| 24 |
+
description: >-
|
| 25 |
+
A list of labels and values the object must specify.
|
| 26 |
+
items:
|
| 27 |
+
type: object
|
| 28 |
+
properties:
|
| 29 |
+
key:
|
| 30 |
+
type: string
|
| 31 |
+
description: >-
|
| 32 |
+
The required label.
|
| 33 |
+
allowedRegex:
|
| 34 |
+
type: string
|
| 35 |
+
description: >-
|
| 36 |
+
If specified, a regular expression the annotation's value
|
| 37 |
+
must match. The value must contain at least one match for
|
| 38 |
+
the regular expression.
|
| 39 |
+
targets:
|
| 40 |
+
- target: admission.k8s.gatekeeper.sh
|
| 41 |
+
rego: |
|
| 42 |
+
package k8srequiredlabels
|
| 43 |
+
|
| 44 |
+
get_message(parameters, _default) = msg {
|
| 45 |
+
not parameters.message
|
| 46 |
+
msg := _default
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
get_message(parameters, _default) = msg {
|
| 50 |
+
msg := parameters.message
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
|
| 54 |
+
provided := {label | input.review.object.metadata.labels[label]}
|
| 55 |
+
required := {label | label := input.parameters.labels[_].key}
|
| 56 |
+
missing := required - provided
|
| 57 |
+
count(missing) > 0
|
| 58 |
+
def_msg := sprintf("you must provide labels: %v", [missing])
|
| 59 |
+
msg := get_message(input.parameters, def_msg)
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
violation[{"msg": msg}] {
|
| 63 |
+
value := input.review.object.metadata.labels[key]
|
| 64 |
+
expected := input.parameters.labels[_]
|
| 65 |
+
expected.key == key
|
| 66 |
+
# do not match if allowedRegex is not defined, or is an empty string
|
| 67 |
+
expected.allowedRegex != ""
|
| 68 |
+
not re_match(expected.allowedRegex, value)
|
| 69 |
+
def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex])
|
| 70 |
+
msg := get_message(input.parameters, def_msg)
|
| 71 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.0.1
|
| 2 |
+
name: k8srequiredlabels
|
| 3 |
+
displayName: Required Labels
|
| 4 |
+
createdAt: "2023-10-30T21:00:00Z"
|
| 5 |
+
description: Requires resources to contain specified labels, with values matching provided regular expressions.
|
| 6 |
+
digest: aa4cbb2bbaba13b310108f7944ba8200c0adbaf865f8f3dfd7cbdc3c760b5eea
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Required Labels
|
| 15 |
+
Requires resources to contain specified labels, with values matching provided regular expressions.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.0.1/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/constraint.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sRequiredLabels
|
| 3 |
+
metadata:
|
| 4 |
+
name: all-must-have-owner
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Namespace"]
|
| 10 |
+
parameters:
|
| 11 |
+
message: "All namespaces must have an `owner` label that points to your company username"
|
| 12 |
+
labels:
|
| 13 |
+
- key: owner
|
| 14 |
+
allowedRegex: "^[a-zA-Z]+.agilebank.demo$"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_allowed.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-namespace
|
| 5 |
+
labels:
|
| 6 |
+
owner: user.agilebank.demo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/samples/all-must-have-owner/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-namespace
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/suite.yaml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: requiredlabels
|
| 5 |
+
tests:
|
| 6 |
+
- name: must-have-owner
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/all-must-have-owner/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/all-must-have-owner/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/all-must-have-owner/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.0.1/template.yaml
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: templates.gatekeeper.sh/v1
|
| 2 |
+
kind: ConstraintTemplate
|
| 3 |
+
metadata:
|
| 4 |
+
name: k8srequiredlabels
|
| 5 |
+
annotations:
|
| 6 |
+
metadata.gatekeeper.sh/title: "Required Labels"
|
| 7 |
+
metadata.gatekeeper.sh/version: 1.0.1
|
| 8 |
+
description: >-
|
| 9 |
+
Requires resources to contain specified labels, with values matching
|
| 10 |
+
provided regular expressions.
|
| 11 |
+
spec:
|
| 12 |
+
crd:
|
| 13 |
+
spec:
|
| 14 |
+
names:
|
| 15 |
+
kind: K8sRequiredLabels
|
| 16 |
+
validation:
|
| 17 |
+
openAPIV3Schema:
|
| 18 |
+
type: object
|
| 19 |
+
properties:
|
| 20 |
+
message:
|
| 21 |
+
type: string
|
| 22 |
+
labels:
|
| 23 |
+
type: array
|
| 24 |
+
description: >-
|
| 25 |
+
A list of labels and values the object must specify.
|
| 26 |
+
items:
|
| 27 |
+
type: object
|
| 28 |
+
properties:
|
| 29 |
+
key:
|
| 30 |
+
type: string
|
| 31 |
+
description: >-
|
| 32 |
+
The required label.
|
| 33 |
+
allowedRegex:
|
| 34 |
+
type: string
|
| 35 |
+
description: >-
|
| 36 |
+
If specified, a regular expression the annotation's value
|
| 37 |
+
must match. The value must contain at least one match for
|
| 38 |
+
the regular expression.
|
| 39 |
+
targets:
|
| 40 |
+
- target: admission.k8s.gatekeeper.sh
|
| 41 |
+
rego: |
|
| 42 |
+
package k8srequiredlabels
|
| 43 |
+
|
| 44 |
+
get_message(parameters, _default) := _default {
|
| 45 |
+
not parameters.message
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
get_message(parameters, _) := parameters.message
|
| 49 |
+
|
| 50 |
+
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
|
| 51 |
+
provided := {label | input.review.object.metadata.labels[label]}
|
| 52 |
+
required := {label | label := input.parameters.labels[_].key}
|
| 53 |
+
missing := required - provided
|
| 54 |
+
count(missing) > 0
|
| 55 |
+
def_msg := sprintf("you must provide labels: %v", [missing])
|
| 56 |
+
msg := get_message(input.parameters, def_msg)
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
violation[{"msg": msg}] {
|
| 60 |
+
value := input.review.object.metadata.labels[key]
|
| 61 |
+
expected := input.parameters.labels[_]
|
| 62 |
+
expected.key == key
|
| 63 |
+
# do not match if allowedRegex is not defined, or is an empty string
|
| 64 |
+
expected.allowedRegex != ""
|
| 65 |
+
not regex.match(expected.allowedRegex, value)
|
| 66 |
+
def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex])
|
| 67 |
+
msg := get_message(input.parameters, def_msg)
|
| 68 |
+
}
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/artifacthub-pkg.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: 1.1.0
|
| 2 |
+
name: k8srequiredlabels
|
| 3 |
+
displayName: Required Labels
|
| 4 |
+
createdAt: "2024-05-10T23:29:29Z"
|
| 5 |
+
description: Requires resources to contain specified labels, with values matching provided regular expressions.
|
| 6 |
+
digest: 84897cdfe60dbe9c1726581fe0626d254477a176b143a2cff36b5cf24465e8b8
|
| 7 |
+
license: Apache-2.0
|
| 8 |
+
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels
|
| 9 |
+
keywords:
|
| 10 |
+
- gatekeeper
|
| 11 |
+
- open-policy-agent
|
| 12 |
+
- policies
|
| 13 |
+
readme: |-
|
| 14 |
+
# Required Labels
|
| 15 |
+
Requires resources to contain specified labels, with values matching provided regular expressions.
|
| 16 |
+
install: |-
|
| 17 |
+
### Usage
|
| 18 |
+
```shell
|
| 19 |
+
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.1.0/template.yaml
|
| 20 |
+
```
|
| 21 |
+
provider:
|
| 22 |
+
name: Gatekeeper Library
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/kustomization.yaml
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
resources:
|
| 2 |
+
- template.yaml
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/constraint.yaml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: constraints.gatekeeper.sh/v1beta1
|
| 2 |
+
kind: K8sRequiredLabels
|
| 3 |
+
metadata:
|
| 4 |
+
name: all-must-have-owner
|
| 5 |
+
spec:
|
| 6 |
+
match:
|
| 7 |
+
kinds:
|
| 8 |
+
- apiGroups: [""]
|
| 9 |
+
kinds: ["Namespace"]
|
| 10 |
+
parameters:
|
| 11 |
+
message: "All namespaces must have an `owner` label that points to your company username"
|
| 12 |
+
labels:
|
| 13 |
+
- key: owner
|
| 14 |
+
allowedRegex: "^[a-zA-Z]+.agilebank.demo$"
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_allowed.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: allowed-namespace
|
| 5 |
+
labels:
|
| 6 |
+
owner: user.agilebank.demo
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-namespace
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/samples/all-must-have-owner/example_disallowed_label_value.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
apiVersion: v1
|
| 2 |
+
kind: Namespace
|
| 3 |
+
metadata:
|
| 4 |
+
name: disallowed-namespace
|
| 5 |
+
labels:
|
| 6 |
+
owner: user
|
source_data/pinned/gatekeeper-library/commit-a8d4799d8daf/artifacthub/library/general/requiredlabels/1.1.0/suite.yaml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
kind: Suite
|
| 2 |
+
apiVersion: test.gatekeeper.sh/v1alpha1
|
| 3 |
+
metadata:
|
| 4 |
+
name: requiredlabels
|
| 5 |
+
tests:
|
| 6 |
+
- name: must-have-owner
|
| 7 |
+
template: template.yaml
|
| 8 |
+
constraint: samples/all-must-have-owner/constraint.yaml
|
| 9 |
+
cases:
|
| 10 |
+
- name: example-allowed
|
| 11 |
+
object: samples/all-must-have-owner/example_allowed.yaml
|
| 12 |
+
assertions:
|
| 13 |
+
- violations: no
|
| 14 |
+
- name: example-disallowed
|
| 15 |
+
object: samples/all-must-have-owner/example_disallowed.yaml
|
| 16 |
+
assertions:
|
| 17 |
+
- violations: yes
|
| 18 |
+
- name: example-disallowed-label-value
|
| 19 |
+
object: samples/all-must-have-owner/example_disallowed_label_value.yaml
|
| 20 |
+
assertions:
|
| 21 |
+
- violations: yes
|