Skip to content

Commit a564d1b

Browse files
Replace kube-rbac-proxy to ensure the same level of protection with controller-runtime feature
Utilise Controller-Runtime's WithAuthenticationAndAuthorization feature to protect the metrics endpoint. This approach provides access control, similar to the functionality of kube-rbac-proxy. kube-rbac-proxy image from gcr.io/kubebuilder/kube-rbac-proxy is deprecated and should no longer be used More info: kubernetes-sigs/kubebuilder#3907
1 parent a3946d2 commit a564d1b

File tree

5 files changed

+20
-27
lines changed

5 files changed

+20
-27
lines changed

cmd/manager/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/http"
2424
"os"
2525
"path/filepath"
26+
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
2627
"strings"
2728
"time"
2829

@@ -161,9 +162,20 @@ func main() {
161162
},
162163
}
163164
}
165+
166+
metricsServerOptions := server.Options{
167+
BindAddress: metricsAddr,
168+
SecureServing: true,
169+
170+
// FilterProvider is used to protect the metrics endpoint with authn/authz.
171+
// These configurations ensure that only authorized users and service accounts
172+
// can access the metrics endpoint.
173+
FilterProvider: filters.WithAuthenticationAndAuthorization,
174+
}
175+
164176
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
165177
Scheme: scheme.Scheme,
166-
Metrics: server.Options{BindAddress: metricsAddr},
178+
Metrics: metricsServerOptions,
167179
HealthProbeBindAddress: probeAddr,
168180
LeaderElection: enableLeaderElection,
169181
LeaderElectionID: "9c4404e7.operatorframework.io",

config/base/manager/manager.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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/kustomization.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ 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.
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
2326
- auth_proxy_service.yaml
2427
- auth_proxy_role.yaml
2528
- auth_proxy_role_binding.yaml
2629
- auth_proxy_client_clusterrole.yaml
30+

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)