🚨 Action Required: Ensure that you no longer use gcr.io/kubebuilder images #3907
Replies: 4 comments 3 replies
-
Hi everyone, We’ve been updating this discussion to provide the latest information, including details about the helpers implemented in Kubebuilder. Additionally, we’ve been enhancing it by, for example, adding more comprehensive steps to help you manually update your project if needed. 🖐️ Check out the FAQ section: "How can I manually change my project to switch to Controller-Runtime's built-in auth protection?" for detailed instructions. We will continue to keep this discussion up to date. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, We’ve been updating this discussion to provide the latest information. 🖐️ Check out the FAQ section: Why can't we recommend just replacing the kube-rbac-proxy image with the latest version from another trusted source? We will continue to keep this discussion up to date. |
Beta Was this translation helpful? Give feedback.
-
Hey everybody, For the next release ( You might want to take a look at the related PR #4400 for more details! Best regards, |
Beta Was this translation helpful? Give feedback.
-
@camilamacedo86 Thanks for the migration guide! We were able to migrate, but we have a question about k8s RBAC if you don't mind clearing things up for us. We used the approach where you change
However, we found that we can't make a successful request (it says it's unauthenticated) to the metrics endpoint unless we add a It's worth noting that we don't make use of the metrics from our custom operator yet, we're just following this migration guide. The example project has a Is the idea that the example project isn't supposed to be a complete example that shows reading metrics, because everyone will have a different way they need to read metrics? And a different thing reading them, which would have its own service account that would be bound? |
Beta Was this translation helpful? Give feedback.
-
If your project uses gcr.io/kubebuilder/kube-rbac-proxy it will be affected. Your project may fail to work if the image cannot be pulled. You must move as soon as possible, sometime from early 2025, the GCR will go away.
Key Update
kube-rbac-proxy was historically used to protect the metrics endpoint. However, its usage has been discontinued in Kubebuilder.
The default scaffold now leverages the
WithAuthenticationAndAuthorization
feature provided by Controller-Runtime.This feature provides integrated support for securing metrics endpoints by embedding authentication (authn) and authorization (authz) mechanisms directly into the controller manager's metrics server, replacing the need for (https://github.com/brancz/kube-rbac-proxy) to secure metrics endpoints.
Why This Matters
What You Need to Do
Follow some options.
Option 1 - Upgrade the Project to the Latest Release (Recommended)
Upgrade your project to the latest release by re-scaffolding it and reintegrating your custom code.
PROJECT
config.kube-rbac-proxy
) with options to improve production readiness, such as configuring certificates securely. This approach also allows you to take advantage of other improvements, bug fixes, and the latest updates.Option 2 - Manually Modify Your Project
If you prefer not to fully upgrade, modify your project to use the built-in
authn/authz
protection via Controller-Runtime.Option 3 - Continue Using the
kube-rbac-proxy
Image (Not adopt or promoted by Kubebuilder)If you want to continue using
kube-rbac-proxy
, source the image from an alternative location, at your own risk. Examples include:FAQ
Why does the metrics endpoint need to be protected?
Unprotected metrics endpoints can expose sensitive data, such as system performance and application behavior, to unauthorized users. This can lead to security vulnerabilities where attackers gain insights into the system's operation and exploit weaknesses.
How can the metrics endpoint be protected?
The following are some options with details and info for those who were introduced to support and helpers in Kubebuilder.
(Protection enabled by default from release
v4.1.0
)Use Controller-Runtime's feature WithAuthenticationAndAuthorization to enable
authn/authz
for metrics endpoints. For reference, see the code from the release 4.3.1(Optional helper introduced from release
v4.2.0
)Use NetworkPolicies to secure metrics endpoints.
Example configuration: NetworkPolicy Example
Also, feel free to check the (external code example)
Integrate cert-manager:
Secure the metrics endpoint using TLS encryption with cert-manager. For example, ensure that you use valid certficates such as:
ServiceMonitor
to integrate it with Prometheus:kubebuilder/testdata/project-v4/config/prometheus/monitor_tls_patch.yaml
Lines 10 to 22 in e07823e
Note that we plan add a feature/helper for it in the next release, see the PR: ✨ (go/v4): feat/fix: enhance cert-manager integration for metrics endpoints (follow-up to PR #4243) #4400
Why doesn't Network Policy provide the same level of protection as kube-rbac-proxy?
NetworkPolicy acts as a firewall for pods, controlling traffic flow at the IP or port level. However, it doesn’t handle authentication (
authn
), authorization (authz
), or encryption like kube-rbac-proxy does.How can I manually change my project to switch to Controller-Runtime's built-in auth protection?
Following these steps should help you resolve the issue. However, there may be a few caveats depending on how old the version used to create the project is, especially if it has never been upgraded to the latest versions by re-creating the project and adding your code changes on top.
Remove kube-rbac-proxy configurations:
Ensure that you remove the container with the
name: kube-rbac-proxy
. Example from an old versionEnsure that your manager will have the args for the metrics service and binding at the same port
For example, see the metrics service:
kubebuilder/testdata/project-v4/config/default/metrics_service.yaml
Lines 8 to 17 in e07823e
For example, see the arg to be patch to binding the metrics service:
kubebuilder/testdata/project-v4/config/default/manager_metrics_patch.yaml
Lines 2 to 4 in e07823e
main.go
:Update your
main.go
to implement WithAuthenticationAndAuthorization. Here’s an example:For a full implementation example, see the samples under testdata. For reference, see the code from the release
4.3.1
:kubebuilder/testdata/project-v4/cmd/main.go
Lines 89 to 152 in a9ee390
Note: Please ensure that you disable HTTP/2 by default, as you see in the above example. Disable HTTP/2 still required: kubernetes/kubernetes#121197
5 - Add e2e tests to validate the metrics endpoint.
Projects created with the latest versions are scaffolded with comprehensive E2E tests, including code to validate the metrics endpoint. Example. See: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4/test/e2e/e2e_test.go#L166-L235
Note that you can remove the Prometheus block if you are not providing this integration.
Build your project and ensure the metrics endpoint is working and protected with RBAC as expected. The RBAC permissions scaffolded under
config/rbac
should provide the required permissions. However, if you face issues, you might want to look at the last scaffolds to generate them properly. See that under testdata; we have examples.Steps to Verify Metrics with
curl
manually❓ Why is this happening?
The
kube-rbac-proxy
images have been rebuilt and re-tagged by Kubebuilder for an extended period. However, due to infrastructure changes within the Kubernetes ecosystem and the deprecation of Google Cloud Platform’s Container Registry (details here), continuing to maintain these images is no longer feasible.Additionally, the project has been in the process of being donated to SIG-Auth for an extended period. Despite these efforts, significant requirements still need to be addressed before SIG-Auth can consider adopting the project. The latest review outlined several tasks being tracked here: kube-rbac-proxy issue #238.
For more details, refer to:
Why can't we recommend just replacing the kube-rbac-proxy image with the latest version from another trusted source?
The following are some key reasons.
Please update your configurations accordingly to avoid disruptions. If you have any questions or need further assistance, feel free to ask in this discussion thread or the Kubebuilder Slack channel.
For further information, check the metrics section in the documentation: https://book.kubebuilder.io/reference/metrics.
Beta Was this translation helpful? Give feedback.
All reactions