Skip to content

Commit 0a2ed99

Browse files
committed
operator: drop rbac-proxy in favor of controller-runtime's authz/authn
rbac-proxy will be deprecated in 2025 Signed-off-by: Tuomas Katila <[email protected]>
1 parent 31284de commit 0a2ed99

File tree

16 files changed

+105
-157
lines changed

16 files changed

+105
-157
lines changed

cmd/operator/main.go

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/klog/v2/textlogger"
2828
ctrl "sigs.k8s.io/controller-runtime"
2929
"sigs.k8s.io/controller-runtime/pkg/healthz"
30+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
3031
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3132
"sigs.k8s.io/controller-runtime/pkg/webhook"
3233
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -97,12 +98,45 @@ func contains(arr []string, val string) bool {
9798
return false
9899
}
99100

101+
func createTLSCfgs(enableHTTP2 bool) []func(*tls.Config) {
102+
tlsCfgFuncs := []func(*tls.Config){
103+
func(cfg *tls.Config) {
104+
cfg.MinVersion = tls.VersionTLS12
105+
cfg.MaxVersion = tls.VersionTLS12
106+
cfg.CipherSuites = []uint16{
107+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
108+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
109+
}
110+
},
111+
}
112+
113+
// if the enable-http2 flag is false (the default), http/2 should be disabled
114+
// due to its vulnerabilities. More specifically, disabling http/2 will
115+
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
116+
// Rapid Reset CVEs. For more information see:
117+
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
118+
// - https://github.com/advisories/GHSA-4374-p667-p6c8
119+
disableHTTP2 := func(cfg *tls.Config) {
120+
setupLog.Info("disabling http/2")
121+
122+
cfg.NextProtos = []string{"http/1.1"}
123+
}
124+
125+
if !enableHTTP2 {
126+
tlsCfgFuncs = append(tlsCfgFuncs, disableHTTP2)
127+
}
128+
129+
return tlsCfgFuncs
130+
}
131+
100132
func main() {
101133
var (
102134
metricsAddr string
103135
probeAddr string
104136
devicePluginNamespace string
105137
enableLeaderElection bool
138+
enableHTTP2 bool
139+
secureMetrics bool
106140
pm *patcher.Manager
107141
)
108142

@@ -115,6 +149,10 @@ func main() {
115149
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
116150
"Enable leader election for controller manager. "+
117151
"Enabling this will ensure there is only one active controller manager.")
152+
flag.BoolVar(&secureMetrics, "metrics-secure", false,
153+
"Enable role based authentication/authorization for the metrics endpoint")
154+
flag.BoolVar(&enableHTTP2, "enable-http2", false,
155+
"Enable HTTP/2 for the metrics and webhook servers")
118156
flag.Var(&devices, "devices", "Device(s) to set up.")
119157
flag.Parse()
120158

@@ -134,27 +172,33 @@ func main() {
134172
"sgx": sgx.SetupReconciler,
135173
}
136174

137-
tlsCfgFunc := func(cfg *tls.Config) {
138-
cfg.MinVersion = tls.VersionTLS12
139-
cfg.MaxVersion = tls.VersionTLS12
140-
cfg.CipherSuites = []uint16{
141-
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
142-
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
143-
}
175+
tlsCfgFuncs := createTLSCfgs(enableHTTP2)
176+
177+
webhookServer := webhook.NewServer(webhook.Options{
178+
TLSOpts: tlsCfgFuncs,
179+
})
180+
181+
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
182+
// More info:
183+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/server
184+
// - https://book.kubebuilder.io/reference/metrics.html
185+
metricsServerOptions := metricsserver.Options{
186+
BindAddress: metricsAddr,
187+
SecureServing: secureMetrics,
188+
TLSOpts: tlsCfgFuncs,
144189
}
145190

146-
webhookOptions := webhook.Options{
147-
Port: 9443,
148-
TLSOpts: []func(*tls.Config){
149-
tlsCfgFunc,
150-
},
191+
if secureMetrics {
192+
// More info:
193+
// https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/filters#WithAuthenticationAndAuthorization
194+
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
151195
}
152196

153197
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
154198
Scheme: scheme,
155-
Metrics: metricsserver.Options{BindAddress: metricsAddr},
199+
Metrics: metricsServerOptions,
156200
Logger: ctrl.Log.WithName("intel-device-plugins-manager"),
157-
WebhookServer: webhook.NewServer(webhookOptions),
201+
WebhookServer: webhookServer,
158202
HealthProbeBindAddress: probeAddr,
159203
LeaderElection: enableLeaderElection,
160204
LeaderElectionID: "d1c7b6d5.intel.com",

deployments/operator/default/kustomization.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ resources:
1818
- ../manager
1919
- ../webhook
2020
- ../certmanager
21+
# [METRICS] Expose the controller manager metrics service.
22+
- metrics_service.yaml
23+
2124

2225
patches:
23-
# Protect the /metrics endpoint by putting it behind auth.
24-
# If you want your controller-manager to expose the /metrics
25-
# endpoint w/o any authn/z, please comment the following line.
26-
- path: manager_auth_proxy_patch.yaml
26+
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
27+
# More info: https://book.kubebuilder.io/reference/metrics
28+
- path: manager_metrics_patch.yaml
2729
target:
28-
name: controller-manager
29-
# Enable webhook
30+
kind: Deployment
3031
- path: manager_webhook_patch.yaml
3132
target:
33+
kind: Deployment
3234
name: controller-manager
3335
# Enable certmanager integration
3436
- path: webhookcainjection_patch_mutate.yaml

deployments/operator/default/manager_auth_proxy_patch.yaml

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This patch adds the args to allow exposing the metrics endpoint using HTTPS
2+
- op: add
3+
path: /spec/template/spec/containers/0/args/0
4+
value: "--metrics-bind-address=:8443"
5+
- op: add
6+
path: /spec/template/spec/containers/0/args/0
7+
value: "--metrics-secure"

deployments/operator/rbac/auth_proxy_service.yaml renamed to deployments/operator/default/metrics_service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
ports:
1010
- name: https
1111
port: 8443
12-
targetPort: https
12+
protocol: TCP
13+
targetPort: 8443
1314
selector:
1415
control-plane: controller-manager
15-
manager: intel-deviceplugin-operator

deployments/operator/manager/manager.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ spec:
3030
- image: docker.io/intel/intel-deviceplugin-operator:devel
3131
imagePullPolicy: IfNotPresent
3232
name: manager
33+
args:
34+
- "--health-probe-bind-address=:8081"
35+
- "--leader-elect"
3336
livenessProbe:
3437
httpGet:
3538
path: /healthz

deployments/operator/rbac/kustomization.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ resources:
44
- leader_election_role.yaml
55
- leader_election_role_binding.yaml
66
- gpu_manager_role.yaml
7-
# Comment the following 4 lines if you want to disable
8-
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
9-
# which protects your /metrics endpoint.
10-
- auth_proxy_service.yaml
11-
- auth_proxy_role.yaml
12-
- auth_proxy_role_binding.yaml
13-
- auth_proxy_client_clusterrole.yaml
7+
# The following RBAC configurations are used to protect
8+
# the metrics endpoint with authn/authz. These configurations
9+
# ensure that only authorized users and service accounts
10+
# can access the metrics endpoint. Comment the following
11+
# permissions if you want to disable this protection.
12+
# More info: https://book.kubebuilder.io/reference/metrics.html
13+
- metrics_auth_role.yaml
14+
- metrics_auth_role_binding.yaml
15+
- metrics_reader_role.yaml
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRole
33
metadata:
4-
name: proxy-role
4+
name: metrics-auth-role
55
rules:
6-
- apiGroups: ["authentication.k8s.io"]
6+
- apiGroups:
7+
- authentication.k8s.io
78
resources:
89
- tokenreviews
9-
verbs: ["create"]
10-
- apiGroups: ["authorization.k8s.io"]
10+
verbs:
11+
- create
12+
- apiGroups:
13+
- authorization.k8s.io
1114
resources:
1215
- subjectaccessreviews
13-
verbs: ["create"]
16+
verbs:
17+
- create

deployments/operator/rbac/auth_proxy_role_binding.yaml renamed to deployments/operator/rbac/metrics_auth_role_binding.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apiVersion: rbac.authorization.k8s.io/v1
22
kind: ClusterRoleBinding
33
metadata:
4-
name: proxy-rolebinding
4+
name: metrics-auth-rolebinding
55
roleRef:
66
apiGroup: rbac.authorization.k8s.io
77
kind: ClusterRole
8-
name: proxy-role
8+
name: metrics-auth-role
99
subjects:
1010
- kind: ServiceAccount
1111
name: default

deployments/operator/rbac/auth_proxy_client_clusterrole.yaml renamed to deployments/operator/rbac/metrics_reader_role.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ kind: ClusterRole
33
metadata:
44
name: metrics-reader
55
rules:
6-
- nonResourceURLs: ["/metrics"]
7-
verbs: ["get"]
6+
- nonResourceURLs:
7+
- "/metrics"
8+
verbs:
9+
- get

0 commit comments

Comments
 (0)