Skip to content

Commit 09dde42

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 944363b commit 09dde42

19 files changed

+153
-157
lines changed

cmd/operator/main.go

Lines changed: 57 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,9 @@ 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, "If set the metrics endpoint is served securely")
153+
flag.BoolVar(&enableHTTP2, "enable-http2", false,
154+
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
118155
flag.Var(&devices, "devices", "Device(s) to set up.")
119156
flag.Parse()
120157

@@ -134,27 +171,33 @@ func main() {
134171
"sgx": sgx.SetupReconciler,
135172
}
136173

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-
}
174+
tlsCfgFuncs := createTLSCfgs(enableHTTP2)
175+
176+
webhookServer := webhook.NewServer(webhook.Options{
177+
TLSOpts: tlsCfgFuncs,
178+
})
179+
180+
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
181+
// More info:
182+
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/server
183+
// - https://book.kubebuilder.io/reference/metrics.html
184+
metricsServerOptions := metricsserver.Options{
185+
BindAddress: metricsAddr,
186+
SecureServing: secureMetrics,
187+
TLSOpts: tlsCfgFuncs,
144188
}
145189

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

153196
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
154197
Scheme: scheme,
155-
Metrics: metricsserver.Options{BindAddress: metricsAddr},
198+
Metrics: metricsServerOptions,
156199
Logger: ctrl.Log.WithName("intel-device-plugins-manager"),
157-
WebhookServer: webhook.NewServer(webhookOptions),
200+
WebhookServer: webhookServer,
158201
HealthProbeBindAddress: probeAddr,
159202
LeaderElection: enableLeaderElection,
160203
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
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This NetworkPolicy allows ingress traffic
2+
# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those
3+
# namespaces are able to gathering data from the metrics endpoint.
4+
apiVersion: networking.k8s.io/v1
5+
kind: NetworkPolicy
6+
metadata:
7+
name: allow-metrics-traffic
8+
namespace: system
9+
spec:
10+
podSelector:
11+
matchLabels:
12+
control-plane: controller-manager
13+
policyTypes:
14+
- Ingress
15+
ingress:
16+
# This allows ingress traffic from any namespace with the label metrics: enabled
17+
- from:
18+
- namespaceSelector:
19+
matchLabels:
20+
metrics: enabled # Only from namespaces with this label
21+
ports:
22+
- port: 8443
23+
protocol: TCP
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This NetworkPolicy allows ingress traffic to your webhook server running
2+
# as part of the controller-manager from specific namespaces and pods. CR(s) which uses webhooks
3+
# will only work when applied in namespaces labeled with 'webhook: enabled'
4+
apiVersion: networking.k8s.io/v1
5+
kind: NetworkPolicy
6+
metadata:
7+
name: allow-webhook-traffic
8+
namespace: system
9+
spec:
10+
podSelector:
11+
matchLabels:
12+
control-plane: controller-manager
13+
policyTypes:
14+
- Ingress
15+
ingress:
16+
# This allows ingress traffic from any namespace with the label webhook: enabled
17+
- from:
18+
- namespaceSelector:
19+
matchLabels:
20+
webhook: enabled # Only from namespaces with this label
21+
ports:
22+
- port: 443
23+
protocol: TCP
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resources:
2+
- allow-webhook-traffic.yaml
3+
- allow-metrics-traffic.yaml

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

0 commit comments

Comments
 (0)