Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discontinue kube-rbac-proxy and disable metrics service #721

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

black-dragon74
Copy link
Member

@black-dragon74 black-dragon74 commented Dec 4, 2024

This patch drops support for kube-rbac-proxy
and uses controller manager's
WithAuthenticationAndAuthorization.

Closes: #643

For more details please refer here

In addition to migration, some of the resources have been re-categorized for better placement and the metrics service is now disabled by default as it did not contain any significant information specific to csi-addons. It can be re-enabled by following the steps outlined in #721 (comment)

@mergify mergify bot added the vendor Pull requests that update vendored dependencies label Dec 4, 2024
@black-dragon74
Copy link
Member Author

Testing

1. Access /metrics endpoint as controller-manager's SA

❯ oc auth can-i get /metrics --as=system:serviceaccount:csi-addons-system:csi-addons-controller-manager
yes

2. Get the metrics using valid SA token

❯ oc exec -it po/metrics-consumer -- sh
$ curl -k -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://csi-addons-controller-manager-metrics-service.csi-addons-system.svc.cluster.local:8443/metrics
# HELP certwatcher_read_certificate_errors_total Total number of certificate read errors
# TYPE certwatcher_read_certificate_errors_total counter
certwatcher_read_certificate_errors_total 0
# HELP certwatcher_read_certificate_total Total number of certificate reads
...
...
...
stripped....

3. Get the metrics using invalid SA token

$ curl -k -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/INVALID)" https://csi-addons-controller-manager-metrics-service.csi-addons-system.svc.cluster.local:8443/metrics
Unauthorized

4. Check POD's containers (no kube-rbac-proxy-container)

❯ oc get po/csi-addons-controller-manager-7886c6d5c9-f2vwh -o jsonpath='{.spec.containers[*].name}'
manager

Regards

TLSOpts: tlsOpts,
}

if secureMetrics {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why someone will use insecure metrics, cant we always use secureMetircs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is enabled by default. The reason why it is controlled by a flag of its own is, in prod env it is recommended to setup proper certs and keys before opting in for secure metrics.

If someone does not want to do that and just wants to check something, they may disable it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document the steps to provide certificates, so that production deployments may replace automatic generated ones?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -128,8 +135,27 @@ func main() {
os.Exit(1)
}

disableHTTP2 := func(config *tls.Config) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one for test clusters or means for production clusters also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Production clusters as well. As of now, curl misses support for HTTP2 on some distros. We can enable it by default once we are sure that all the clients support HTTP2.

Kubebuilder's default scaffolding also follows the same procedure as of now.

Copy link
Collaborator

@nixpanic nixpanic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall, just a few nits regarding comments and documentation

@@ -128,8 +135,27 @@ func main() {
os.Exit(1)
}

disableHTTP2 := func(config *tls.Config) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please leave a comment in the code why it is disabled by default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

TLSOpts: tlsOpts,
}

if secureMetrics {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document the steps to provide certificates, so that production deployments may replace automatic generated ones?

Copy link
Member

@Madhu-1 Madhu-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on other thought, Do we need the metrics? if not lets disable it?

@black-dragon74
Copy link
Member Author

on other thought, Do we need the metrics? if not lets disable it?

It is enabled in all of the other projects by default. Still, we could disable it if not needed. Thoughts @nixpanic ?

@nixpanic
Copy link
Collaborator

on other thought, Do we need the metrics? if not lets disable it?

It is enabled in all of the other projects by default. Still, we could disable it if not needed. Thoughts @nixpanic ?

Metrics enabled by default is fine, I think.

However, the metrics should be useful though. Not sure what the metrics contain, and if there is anything related to the CSI-Addons procedures. If it is only minor things, calling it "metrics for kubernetes-csi-addons" would not really be correct. In that case, the usefulness for the project is little, and disabling sets more appropriate expectations for users.

@black-dragon74
Copy link
Member Author

However, the metrics should be useful though. Not sure what the metrics contain, and if there is anything related to the CSI-Addons procedures.

It includes these metrics and also the metrics for all the CRs that are reconciled by the controllers.

@nixpanic
Copy link
Collaborator

However, the metrics should be useful though. Not sure what the metrics contain, and if there is anything related to the CSI-Addons procedures.

It includes these metrics and also the metrics for all the CRs that are reconciled by the controllers.

In that case, disable it by default. These are not metrics about CSI-Addons procedures, it is too incomplete for that. Once we add metrics about the different CSI-Addons procedures, it can be enabled by default.

@black-dragon74 black-dragon74 force-pushed the migrate-kube-proxy branch 3 times, most recently from 343da07 to 65189b6 Compare December 17, 2024 10:52
@black-dragon74
Copy link
Member Author

black-dragon74 commented Dec 17, 2024

The metrics service is now disabled by default (by setting its bind address to 0). In order to enable it,

  • Set metrics-bind-address=:8443 flag for csi-addons controller pod.
  • Modify config/manager/kustomization.yaml and uncomment the lines 13-18:
#- metrics_service.yaml

#patches:
#- path: manager_metrics_patch.yaml
#  target:
#    kind: Deployment
  • For necessary RBACs uncomment the lines 27-30 in config/rbac/kustomization.yaml
  # The following RBAC configurations are used to protect
  # the metrics endpoint with authn/authz. These configurations
  # ensure that only authorized users and service accounts
  # can access the metrics endpoint.
  # - metrics_auth_role.yaml
  # - metrics_auth_role_binding.yaml
  # - metrics_reader_role.yaml
  # - metrics_reader_role_binding.yaml

cc @nixpanic @Madhu-1

@black-dragon74 black-dragon74 changed the title Discontinue kube-rbac-proxy Discontinue kube-rbac-proxy and disable metrics service Dec 17, 2024
@nixpanic nixpanic requested a review from Madhu-1 December 17, 2024 13:34
@@ -138,7 +174,8 @@ func main() {
RenewDeadline: &leaderElectionRenewDeadline,
RetryPeriod: &leaderElectionRetryPeriod,
WebhookServer: webhook.NewServer(webhook.Options{
Port: 9443,
Port: 9443,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might not need webhook server as well, lets check and address this in followup as well.

This patch drops support for kube-rbac-proxy
and uses controller manager's
WithAuthenticationAndAuthorization.

Closes: csi-addons#643

Signed-off-by: Niraj Yadav <[email protected]>
Signed-off-by: Niraj Yadav <[email protected]>
@mergify mergify bot merged commit 1e99ab9 into csi-addons:main Dec 17, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vendor Pull requests that update vendored dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using NetworkPolicies to allow/deny access to the CSI-driver sidecar
3 participants