Skip to content

Commit a7ace73

Browse files
Camila Mcamilamacedo86
authored andcommitted
Replace kube-rbac-proxy with controller-runtime metrics authentication/authorization
This commit removes the use of the kube-rbac-proxy image and replaces it with metrics authentication/authorization provided by controller-runtime. The kube-rbac-proxy image is deprecated and will no longer be maintained, which introduces risks to production environments. For more details, see: kubernetes-sigs/kubebuilder#3907 Key changes: - Updated to configure metrics server options with secure authentication/authorization using controller-runtime filters. - Added support for disabling HTTP/2 by default to mitigate vulnerabilities (e.g., HTTP/2 Stream Cancellation CVE). - Changed the default metrics endpoint to HTTPS (port 8443) and removed the kube-rbac-proxy container from deployment configurations. - Updated RBAC files to include metrics-specific roles and bindings, ensuring secure access to metrics. This aligns with best practices for security and simplifies the metrics setup by leveraging built-in capabilities of controller-runtime.
1 parent e5820ae commit a7ace73

File tree

10 files changed

+59
-52
lines changed

10 files changed

+59
-52
lines changed

cmd/manager/main.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"crypto/tls"
2122
"flag"
2223
"fmt"
2324
"net/http"
@@ -44,6 +45,7 @@ import (
4445
"sigs.k8s.io/controller-runtime/pkg/client"
4546
crfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer"
4647
"sigs.k8s.io/controller-runtime/pkg/healthz"
48+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
4749
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
4850

4951
catalogd "github.com/operator-framework/catalogd/api/v1"
@@ -89,6 +91,7 @@ func podNamespace() string {
8991
func main() {
9092
var (
9193
metricsAddr string
94+
tlsOpts []func(*tls.Config)
9295
enableLeaderElection bool
9396
probeAddr string
9497
cachePath string
@@ -97,7 +100,7 @@ func main() {
97100
caCertDir string
98101
globalPullSecret string
99102
)
100-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
103+
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8443", "The address the metric endpoint binds to.")
101104
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
102105
flag.StringVar(&caCertDir, "ca-certs-dir", "", "The directory of TLS certificate to use for verifying HTTPS connections to the Catalogd and docker-registry web servers.")
103106
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
@@ -161,9 +164,33 @@ func main() {
161164
},
162165
}
163166
}
167+
168+
// http/2 should be disabled due to its vulnerabilities. More specifically,
169+
// disabling http/2 will prevent it from being vulnerable to the HTTP/2 Stream
170+
// Cancellation and Rapid Reset CVEs. For more information see:
171+
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
172+
// - https://github.com/advisories/GHSA-4374-p667-p6c8
173+
disableHTTP2 := func(c *tls.Config) {
174+
setupLog.Info("disabling http/2")
175+
c.NextProtos = []string{"http/1.1"}
176+
}
177+
178+
tlsOpts = append(tlsOpts, disableHTTP2)
179+
180+
metricsServerOptions := server.Options{
181+
BindAddress: metricsAddr,
182+
SecureServing: true,
183+
TLSOpts: tlsOpts,
184+
185+
// FilterProvider is used to protect the metrics endpoint with authn/authz.
186+
// These configurations ensure that only authorized users and service accounts
187+
// can access the metrics endpoint.
188+
FilterProvider: filters.WithAuthenticationAndAuthorization,
189+
}
190+
164191
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
165192
Scheme: scheme.Scheme,
166-
Metrics: server.Options{BindAddress: metricsAddr},
193+
Metrics: metricsServerOptions,
167194
HealthProbeBindAddress: probeAddr,
168195
LeaderElection: enableLeaderElection,
169196
LeaderElectionID: "9c4404e7.operatorframework.io",

config/base/manager/manager.yaml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spec:
5252
- /manager
5353
args:
5454
- "--health-probe-bind-address=:8081"
55-
- "--metrics-bind-address=127.0.0.1:8080"
55+
- "--metrics-bind-address=0.0.0.0:8443"
5656
- "--leader-elect"
5757
image: controller:latest
5858
imagePullPolicy: IfNotPresent
@@ -84,27 +84,6 @@ spec:
8484
cpu: 10m
8585
memory: 64Mi
8686
terminationMessagePolicy: FallbackToLogsOnError
87-
- name: kube-rbac-proxy
88-
securityContext:
89-
allowPrivilegeEscalation: false
90-
capabilities:
91-
drop:
92-
- "ALL"
93-
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0
94-
args:
95-
- --secure-listen-address=0.0.0.0:8443
96-
- --http2-disable
97-
- --upstream=http://127.0.0.1:8080/
98-
- --logtostderr=true
99-
ports:
100-
- containerPort: 8443
101-
protocol: TCP
102-
name: https
103-
resources:
104-
requests:
105-
cpu: 5m
106-
memory: 64Mi
107-
terminationMessagePolicy: FallbackToLogsOnError
10887
serviceAccountName: operator-controller-controller-manager
10988
terminationGracePeriodSeconds: 10
11089
volumes:

config/base/rbac/auth_proxy_role.yaml

Lines changed: 0 additions & 17 deletions
This file was deleted.

config/base/rbac/kustomization.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ resources:
1717
- extension_editor_role.yaml
1818
- extension_viewer_role.yaml
1919

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

config/base/rbac/auth_proxy_role_binding.yaml renamed to config/base/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: controller-manager

config/components/coverage/manager_e2e_coverage_patch.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ spec:
77
template:
88
spec:
99
containers:
10-
- name: kube-rbac-proxy
1110
- name: manager
1211
env:
1312
- name: GOCOVERDIR

config/components/registries-conf/manager_e2e_registries_conf_patch.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ spec:
77
template:
88
spec:
99
containers:
10-
- name: kube-rbac-proxy
1110
- name: manager
1211
volumeMounts:
1312
- name: e2e-registries-conf

0 commit comments

Comments
 (0)