-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Sertaç Özercan <852750+sozercan@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
250 additions
and
15 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
artifacthub/library/general/uniqueingresshost/1.0.2/artifacthub-pkg.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
2 changes: 2 additions & 0 deletions
2
artifacthub/library/general/uniqueingresshost/1.0.2/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- template.yaml |
9 changes: 9 additions & 0 deletions
9
...cthub/library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/constraint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
27 changes: 27 additions & 0 deletions
27
.../library/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_allowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
17 changes: 17 additions & 0 deletions
17
...brary/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
27 changes: 27 additions & 0 deletions
27
...rary/general/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_disallowed2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
17 changes: 17 additions & 0 deletions
17
...ral/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
17 changes: 17 additions & 0 deletions
17
...al/uniqueingresshost/1.0.2/samples/unique-ingress-host/example_inventory_disallowed2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
25 changes: 25 additions & 0 deletions
25
artifacthub/library/general/uniqueingresshost/1.0.2/suite.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
kind: Suite | ||
apiVersion: test.gatekeeper.sh/v1alpha1 | ||
metadata: | ||
name: uniqueingresshost | ||
tests: | ||
- name: block-endpoint-default-role | ||
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 |
17 changes: 17 additions & 0 deletions
17
artifacthub/library/general/uniqueingresshost/1.0.2/sync.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
52 changes: 52 additions & 0 deletions
52
artifacthub/library/general/uniqueingresshost/1.0.2/template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters