Skip to content

Commit

Permalink
Implementing allowed Ingress hostnames (#162)
Browse files Browse the repository at this point in the history
Co-authored-by: Dario Tranchitella <[email protected]>
  • Loading branch information
paolocarta and prometherion authored Jan 13, 2021
1 parent a2109b7 commit 89c66de
Show file tree
Hide file tree
Showing 17 changed files with 623 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ bin
*.swo
*~

hack/*.kubeconfig
**/*.kubeconfig
.DS_Store

42 changes: 42 additions & 0 deletions api/v1alpha1/ingress_hostnames_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2020 Clastix Labs.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"sort"
)

type IngressHostnamesList []string

func (hostnames IngressHostnamesList) Len() int {
return len(hostnames)
}

func (hostnames IngressHostnamesList) Swap(i, j int) {
hostnames[i], hostnames[j] = hostnames[j], hostnames[i]
}

func (hostnames IngressHostnamesList) Less(i, j int) bool {
return hostnames[i] < hostnames[j]
}

func (hostnames IngressHostnamesList) IsStringInList(value string) (ok bool) {
sort.Sort(hostnames)
i := sort.SearchStrings(hostnames, value)
ok = i < hostnames.Len() && hostnames[i] == value
return
}
6 changes: 6 additions & 0 deletions api/v1alpha1/tenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type IngressClassesSpec struct {
AllowedRegex string `json:"allowedRegex,omitempty"`
}

type IngressHostnamesSpec struct {
Allowed IngressHostnamesList `json:"allowed"`
AllowedRegex string `json:"allowedRegex"`
}

type ContainerRegistriesSpec struct {
Allowed RegistryList `json:"allowed,omitempty"`
AllowedRegex string `json:"allowedRegex,omitempty"`
Expand All @@ -60,6 +65,7 @@ type TenantSpec struct {
ServicesMetadata AdditionalMetadata `json:"servicesMetadata,omitempty"`
StorageClasses *StorageClassesSpec `json:"storageClasses,omitempty"`
IngressClasses *IngressClassesSpec `json:"ingressClasses,omitempty"`
IngressHostnames *IngressHostnamesSpec `json:"ingressHostnames,omitempty"`
ContainerRegistries *ContainerRegistriesSpec `json:"containerRegistries,omitempty"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
NetworkPolicies []networkingv1.NetworkPolicySpec `json:"networkPolicies,omitempty"`
Expand Down
44 changes: 44 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions charts/capsule/crds/tenant-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ spec:
allowedRegex:
type: string
type: object
ingressHostnames:
properties:
allowed:
items:
type: string
type: array
allowedRegex:
type: string
required:
- allowed
- allowedRegex
type: object
limitRanges:
items:
description: LimitRangeSpec defines a min/max usage limit for resources
Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/capsule.clastix.io_tenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ spec:
allowedRegex:
type: string
type: object
ingressHostnames:
properties:
allowed:
items:
type: string
type: array
allowedRegex:
type: string
required:
- allowed
- allowedRegex
type: object
limitRanges:
items:
description: LimitRangeSpec defines a min/max usage limit for resources
Expand Down
5 changes: 5 additions & 0 deletions config/samples/capsule_v1alpha1_tenant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ kind: Tenant
metadata:
name: oil
spec:
ingressHostnames:
allowed:
- my.oil.acmecorp.com
- my.gas.acmecorp.com
allowedRegex: "^.*acmecorp.com$"
ingressClasses:
allowed:
- default
Expand Down
Empty file added config/samples/ingress.yaml
Empty file.
18 changes: 11 additions & 7 deletions docs/operator/use-cases/ingress-hostnames.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ metadata:
kubernetes.io/ingress.class: oil
spec:
rules:
- host: web.oil.acmecorp.com
http:
paths:
- backend:
serviceName: nginx
servicePort: 80
path: /
- host: web.oil.acmecorp.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
```
Any tentative of Alice to use a not valid hostname, e.g. `web.gas.acmecorp.org`, will fail.

# What’s next
Expand Down
Loading

0 comments on commit 89c66de

Please sign in to comment.