Skip to content

Commit 6e0b31a

Browse files
Merge pull request #318 from nephomaniac/OSD-24275
OSD-24275: Validate machineCIDR is contained in default ingresscontro…
2 parents 426af72 + 49fe4ea commit 6e0b31a

File tree

8 files changed

+567
-28
lines changed

8 files changed

+567
-28
lines changed

build/resources.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const (
3232
roleName string = "validation-webhook"
3333
prometheusRoleName string = "prometheus-k8s"
3434
repoName string = "managed-cluster-validating-webhooks"
35+
// Role and Binding for reading cluster-config-v1 config map...
36+
clusterConfigRole string = "config-v1-reader-wh"
37+
clusterConfigRoleBinding string = "validation-webhook-cluster-config-v1-reader"
3538
// Used to define what phase a resource should be deployed in by package-operator
3639
pkoPhaseAnnotation string = "package-operator.run/phase"
3740
// Defines the 'rbac' package-operator phase for any resources related to RBAC
@@ -211,6 +214,60 @@ func createClusterRoleBinding() *rbacv1.ClusterRoleBinding {
211214
}
212215
}
213216

217+
func createClusterConfigRole() *rbacv1.Role {
218+
return &rbacv1.Role{
219+
TypeMeta: metav1.TypeMeta{
220+
Kind: "Role",
221+
APIVersion: rbacv1.SchemeGroupVersion.String(),
222+
},
223+
ObjectMeta: metav1.ObjectMeta{
224+
Name: clusterConfigRole,
225+
Namespace: "kube-system",
226+
},
227+
Rules: []rbacv1.PolicyRule{
228+
{
229+
APIGroups: []string{
230+
"",
231+
},
232+
Resources: []string{
233+
"configmaps",
234+
},
235+
Verbs: []string{
236+
"get",
237+
},
238+
ResourceNames: []string{
239+
"cluster-config-v1",
240+
},
241+
},
242+
},
243+
}
244+
}
245+
246+
func createClusterConfigRoleBinding() *rbacv1.RoleBinding {
247+
return &rbacv1.RoleBinding{
248+
TypeMeta: metav1.TypeMeta{
249+
Kind: "RoleBinding",
250+
APIVersion: rbacv1.SchemeGroupVersion.String(),
251+
},
252+
ObjectMeta: metav1.ObjectMeta{
253+
Name: clusterConfigRoleBinding,
254+
Namespace: "kube-system",
255+
},
256+
Subjects: []rbacv1.Subject{
257+
{
258+
Kind: "ServiceAccount",
259+
Name: serviceAccountName,
260+
Namespace: *namespace,
261+
},
262+
},
263+
RoleRef: rbacv1.RoleRef{
264+
Name: clusterConfigRole,
265+
Kind: "Role",
266+
APIGroup: rbacv1.GroupName,
267+
},
268+
}
269+
}
270+
214271
func createPrometheusRole() *rbacv1.Role {
215272
return &rbacv1.Role{
216273
TypeMeta: metav1.TypeMeta{
@@ -827,6 +884,7 @@ func sliceContains(needle string, haystack []string) bool {
827884

828885
func main() {
829886
flag.Parse()
887+
utils.BuildRun = true
830888

831889
skip := strings.Split(*excludes, ",")
832890
onlyInclude := strings.Split(*only, "")
@@ -851,6 +909,8 @@ func main() {
851909
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createClusterRoleBinding()})
852910
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createPrometheusRole()})
853911
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createPromethusRoleBinding()})
912+
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createClusterConfigRole()})
913+
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createClusterConfigRoleBinding()})
854914
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createServiceMonitor()})
855915
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createCACertConfigMap()})
856916
templateResources.Add(utils.DefaultLabelSelector(), runtime.RawExtension{Object: createService()})

build/selectorsyncset.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,35 @@ objects:
123123
- kind: ServiceAccount
124124
name: prometheus-k8s
125125
namespace: openshift-monitoring
126+
- apiVersion: rbac.authorization.k8s.io/v1
127+
kind: Role
128+
metadata:
129+
creationTimestamp: null
130+
name: config-v1-reader-wh
131+
namespace: kube-system
132+
rules:
133+
- apiGroups:
134+
- ""
135+
resourceNames:
136+
- cluster-config-v1
137+
resources:
138+
- configmaps
139+
verbs:
140+
- get
141+
- apiVersion: rbac.authorization.k8s.io/v1
142+
kind: RoleBinding
143+
metadata:
144+
creationTimestamp: null
145+
name: validation-webhook-cluster-config-v1-reader
146+
namespace: kube-system
147+
roleRef:
148+
apiGroup: rbac.authorization.k8s.io
149+
kind: Role
150+
name: config-v1-reader-wh
151+
subjects:
152+
- kind: ServiceAccount
153+
name: validation-webhook
154+
namespace: openshift-validation-webhook
126155
- apiVersion: monitoring.coreos.com/v1
127156
kind: ServiceMonitor
128157
metadata:

cmd/main.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import (
2121
"github.com/openshift/managed-cluster-validating-webhooks/pkg/k8sutil"
2222
"github.com/openshift/managed-cluster-validating-webhooks/pkg/localmetrics"
2323
"github.com/openshift/managed-cluster-validating-webhooks/pkg/webhooks"
24+
"github.com/openshift/managed-cluster-validating-webhooks/pkg/webhooks/utils"
2425
)
2526

2627
var log = logf.Log.WithName("handler")
2728

2829
var (
2930
listenAddress = flag.String("listen", "0.0.0.0", "listen address")
3031
listenPort = flag.String("port", "5000", "port to listen on")
31-
testHooks = flag.Bool("testhooks", false, "Test webhook URI uniqueness and quit?")
32+
metricsAddr string
3233

3334
useTLS = flag.Bool("tls", false, "Use TLS? Must specify -tlskey, -tlscert, -cacert")
3435
tlsKey = flag.String("tlskey", "", "TLS Key for TLS")
@@ -39,15 +40,18 @@ var (
3940
metricsPort = "8080"
4041
)
4142

42-
func main() {
43-
var metricsAddr string
43+
func init() {
44+
// Allow export webhook var to share flag value...
45+
flag.BoolVar(&utils.TestHooks, "testhooks", false, "Test webhook URI uniqueness and quit?")
4446
flag.StringVar(&metricsAddr, "metrics-bind-address", ":"+metricsPort, "The address the metric endpoint binds to.")
4547
flag.Parse()
46-
klog.SetOutput(os.Stdout)
48+
}
4749

50+
func main() {
51+
klog.SetOutput(os.Stdout)
4852
logf.SetLogger(klogr.New())
4953

50-
if !*testHooks {
54+
if !utils.TestHooks {
5155
log.Info("HTTP server running at", "listen", net.JoinHostPort(*listenAddress, *listenPort))
5256
}
5357
dispatcher := dispatcher.NewDispatcher(webhooks.Webhooks)
@@ -58,12 +62,12 @@ func main() {
5862
panic(fmt.Errorf("Duplicate webhook trying to listen on %s", realHook.GetURI()))
5963
}
6064
seen[name] = true
61-
if !*testHooks {
65+
if !utils.TestHooks {
6266
log.Info("Listening", "webhookName", name, "URI", realHook.GetURI())
6367
}
6468
http.HandleFunc(realHook.GetURI(), dispatcher.HandleRequest)
6569
}
66-
if *testHooks {
70+
if utils.TestHooks {
6771
os.Exit(0)
6872
}
6973

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ require (
5757
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
5858
github.com/openshift/custom-resource-status v1.1.3-0.20220503160415-f2fdb4999d87 // indirect
5959
github.com/openshift/elasticsearch-operator v0.0.0-20220613183908-e1648e67c298 // indirect
60+
github.com/openshift/installer v0.16.1 // indirect
6061
github.com/pkg/errors v0.9.1 // indirect
6162
github.com/prometheus/client_model v0.6.1 // indirect
6263
github.com/prometheus/common v0.59.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ github.com/openshift/elasticsearch-operator v0.0.0-20220613183908-e1648e67c298 h
187187
github.com/openshift/elasticsearch-operator v0.0.0-20220613183908-e1648e67c298/go.mod h1:6dxhWPY3Wr/0b0eGrFpV7gcyeS+ne48Mo9OQ9dxrLNI=
188188
github.com/openshift/hive/apis v0.0.0-20230327212335-7fd70848a6d5 h1:adHXZ1WFqCvXpargpTa6divneeUuvV2xr/D6NWgbqS8=
189189
github.com/openshift/hive/apis v0.0.0-20230327212335-7fd70848a6d5/go.mod h1:VIxA5HhvBmsqVn7aUVQYs004B9K4U5A+HrFwvRq2nK8=
190+
github.com/openshift/installer v0.16.1 h1:PmjALN9x1NVNVi3SCqfz0ZwVCgOkQLQWo2nHYXREq/A=
191+
github.com/openshift/installer v0.16.1/go.mod h1:VWGgpJgF8DGCKQjbccnigglhZnHtRLCZ6cxqkXN4Ck0=
190192
github.com/openshift/operator-custom-metrics v0.5.1 h1:1pk4YMUV+cmqfV0f2fyxY62cl7Gc76kwudJT+EdcfYM=
191193
github.com/openshift/operator-custom-metrics v0.5.1/go.mod h1:0dYDHi/ubKRWzsC9MmW6bRMdBgo1QSOuAh3GupTe0Sw=
192194
github.com/openshift/osde2e-common v0.0.0-20231010150014-8a4449a371e6 h1:MPcnO0eeWEyjLBA4mMgJ8pv8u7DjKC7yS+a39R+zhqs=

0 commit comments

Comments
 (0)