Skip to content

Commit

Permalink
remove kube-rbac-proxy container from deployment
Browse files Browse the repository at this point in the history
csi-operator is not exporting any metrics exclusively and orchestrated
csi already exports metrics on it's own which isn't tunneled through
the operator.

kube-rbac-proxy prominently used to authenticate api access to metrics
endpoint available on operator (manager) which isn't mandatory for us
and this commit removes the same.

note that controller-runtime itself exports some metrics and this commit
doesn't bind any port for controller-runtime which disables inbuilt
metrics being available.

https://book.kubebuilder.io/reference/metrics-reference

Signed-off-by: Leela Venkaiah G <lgangava@ibm.com>
  • Loading branch information
leelavg committed Feb 20, 2025
1 parent 31a93b4 commit 7b1003b
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 342 deletions.
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ WATCH_NAMESPACE ?= ""

IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG)

KUBE_RBAC_PROXY_IMG ?= gcr.io/kubebuilder/kube-rbac-proxy:v0.16.0

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29.0

Expand Down Expand Up @@ -45,12 +43,12 @@ namePrefix: $(NAME_PREFIX)
patches:
- patch: |-
- op: add
path: /spec/template/spec/containers/1/env/-
path: /spec/template/spec/containers/0/env/-
value:
name: CSI_SERVICE_ACCOUNT_PREFIX
value: $(NAME_PREFIX)
- op: add
path: /spec/template/spec/containers/1/env/-
path: /spec/template/spec/containers/0/env/-
value:
name: WATCH_NAMESPACE
value: $(WATCH_NAMESPACE)
Expand All @@ -60,8 +58,6 @@ patches:
images:
- name: controller
newName: ${IMG}
- name: kube-rbac-proxy
newName: ${KUBE_RBAC_PROXY_IMG}
endef
export BUILD_INSTALLER_OVERLAY

Expand Down
36 changes: 2 additions & 34 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package main

import (
"crypto/tls"
"flag"
"fmt"
"os"
Expand All @@ -35,7 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

csiv1alpha1 "github.com/ceph/ceph-csi-operator/api/v1alpha1"
"github.com/ceph/ceph-csi-operator/internal/controller"
Expand All @@ -56,20 +54,12 @@ func init() {
}

func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&secureMetrics, "metrics-secure", false,
"If set the metrics endpoint is served securely")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
opts := zap.Options{
Development: true,
}
Expand All @@ -78,26 +68,6 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// if the enable-http2 flag is false (the default), http/2 should be disabled
// due to its vulnerabilities. More specifically, disabling http/2 will
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
// Rapid Reset CVEs. For more information see:
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
// - https://github.com/advisories/GHSA-4374-p667-p6c8
disableHTTP2 := func(c *tls.Config) {
setupLog.Info("disabling http/2")
c.NextProtos = []string{"http/1.1"}
}

tlsOpts := []func(*tls.Config){}
if !enableHTTP2 {
tlsOpts = append(tlsOpts, disableHTTP2)
}

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: tlsOpts,
})

defaultNamespaces := map[string]cache.Config{}
operatorNamespace, err := utils.GetOperatorNamespace()
if err != nil {
Expand All @@ -118,11 +88,9 @@ func main() {
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
SecureServing: secureMetrics,
TLSOpts: tlsOpts,
// disable metrics
BindAddress: "0",
},
WebhookServer: webhookServer,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "0a62cc8a.ceph.io",
Expand Down
5 changes: 0 additions & 5 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,3 @@ resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- path: manager_auth_proxy_patch.yaml
40 changes: 0 additions & 40 deletions config/manager/manager_auth_proxy_patch.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions config/rbac/auth_proxy_client_clusterrole.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions config/rbac/auth_proxy_role.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions config/rbac/auth_proxy_role_binding.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions config/rbac/auth_proxy_service.yaml

This file was deleted.

7 changes: 0 additions & 7 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
- auth_proxy_service.yaml
- auth_proxy_role.yaml
- auth_proxy_role_binding.yaml
- auth_proxy_client_clusterrole.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
93 changes: 0 additions & 93 deletions deploy/all-in-one/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14840,19 +14840,6 @@ rules:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: ceph-csi-operator
name: ceph-csi-operator-metrics-reader
rules:
- nonResourceURLs:
- /metrics
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ceph-csi-operator-nfs-ctrlplugin-cr
rules:
Expand Down Expand Up @@ -15048,27 +15035,6 @@ rules:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: ceph-csi-operator
name: ceph-csi-operator-proxy-role
rules:
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ceph-csi-operator-rbd-ctrlplugin-cr
rules:
Expand Down Expand Up @@ -15428,22 +15394,6 @@ subjects:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: ceph-csi-operator
name: ceph-csi-operator-proxy-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ceph-csi-operator-proxy-role
subjects:
- kind: ServiceAccount
name: ceph-csi-operator-controller-manager
namespace: ceph-csi-operator-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: ceph-csi-operator-rbd-ctrlplugin-crb
roleRef:
Expand All @@ -15468,24 +15418,6 @@ subjects:
name: ceph-csi-operator-rbd-nodeplugin-sa
namespace: ceph-csi-operator-system
---
apiVersion: v1
kind: Service
metadata:
labels:
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/name: ceph-csi-operator
control-plane: controller-manager
name: ceph-csi-operator-controller-manager-metrics-service
namespace: ceph-csi-operator-system
spec:
ports:
- name: https
port: 8443
protocol: TCP
targetPort: https
selector:
control-plane: controller-manager
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -15509,31 +15441,6 @@ spec:
spec:
containers:
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
- --v=0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.16.0
name: kube-rbac-proxy
ports:
- containerPort: 8443
name: https
protocol: TCP
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --leader-elect
command:
- /manager
Expand Down
Loading

0 comments on commit 7b1003b

Please sign in to comment.