-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
E2E K8s Context Protection #4391
Comments
Hi @reedjosh, Thank you for raise this issue. Could you please let me know if you are using a project with the latest scaffold? I'm just asking because it was already addressed.
kubebuilder/testdata/project-v4/Makefile Lines 66 to 82 in 19237b5
kubebuilder/testdata/project-v4/test/e2e/e2e_suite_test.go Lines 78 to 108 in 19237b5
If you are using this version, then we might add a logic to exit(1) when it is not possible to load the image. We are looking forward to your reply. |
What if the KUBECONFIG point to a production cluster and the kind cluster exists? I think the image will still be loaded in the cluster (since we set |
Slight tangent, but this check is probably not working as intended.
The prefix kind- is, however, added to the kubeconfig file. e.g.
|
@monteiro-renato I think that's how they ensure that the cluster is not a production cluster. Because usually production clusters are not prefixed with |
Yea, I can see it now. When I got that error a while back I found it weird since I knew that I had a kind cluster running and with the correct context configured. |
But yea, I think OP's concern is still valid. The validation should probably be done against the context configured in the kubeconfig instead of relying on the output of a kind command. |
Hi @monteiro-renato, @damsien, @reedjosh, How can we validate the context or name to determine whether it’s a production environment for the user? Additionally, frameworks generally don’t handle this kind of validation. For example, tools like Terraform, Helm, etc., don’t verify whether a command targets a production environment. At some level, the user must understand the commands they’re running and the clusters they’re targeting. On top of that:
It was already discussed. We cannot validate the context configured by developers when they run the commands and say, "Ah, it's production, and it is not for the e2e tests," just as we do not perform such validation for any Makefile targets or features. I hope that clarifies. I am looking forward to knowing if @reedjosh is or is not using a project with all changes related to this request. (as described in #4391 (comment)) I really would appreciate it if @reedjosh could share this information with us. Thank you. |
Hey @camilamacedo86, We could create a kind cluster based on the project's name and then use kind's |
Hi @camilamacedo86 , I agree that its pretty hard to prevent this & kubebuilder does not need to protect against all of this. I think one improvement that is not too hard to achieve would be to extend the utils.Kubectl to also have the I've personally ran my tests against the wrong context as it was not specified. How did this happen? I've started a long running e2e test and then switched context in my shell. With other clients (controller-runtime / e2e-testframework clients) this is not so much an issue as we create them before the tests with a hardcoded context. |
I'm sorry for the delayed response. I believe we were using Without digging into the code I think that the current method is still broken, and implementing protections and workarounds like Tilt does would be ideal. Tilt checks k8s context names for the The allow_k8s_contexts is then provided in case someone is running minikube or something else without the |
I understand the thinking here, but
|
Had a similar experience when running make test and make test-e2e, wasn't clear the context wasn't kind and the namespace was deleted. |
Hi folks, As discussed in Slack and another issue, adding However, due to the complexities involved in avoiding this scenario and the fact that it still creates confusion for users, I was thinking about how to simplify it and solve the concerns raised. Additionally, since we now scaffold GitHub Actions to run E2E tests, we can improve this by:
This approach would make the test framework more predictable, reduce complexity, and align with best practices for managing dependencies in CI/CD pipelines as address all your concerns. If someone would like to work on this one, please feel free !!! @monteiro-renato, @damsien, @reedjosh, @reedjosh. WDYT? Please feel free to contribute if you wish. |
I think that sounds great! Only final concern is that this also seems to install and thus remove metrics. Would that be subject to the same changes? Thank you for your continued work in making kubebuilder an excellent project! |
Hi @reedjosh, Following the approach outlined in the comment above (#4391 (comment)), external dependencies are no longer installed via the e2e tests. Instead, third-party dependencies are now handled through GitHub Actions, which seems to be the best approach. This means that when you run make test-e2e, the project will be built, loaded with Kind, and the tests will be executed. Any required dependencies, such as CertManager or Prometheus, are managed within the GitHub Actions workflow. Let me know if you have any questions and if the above answers your concerns. |
Do you have a link to that? I would like to understand the reasoning. The protection is really important to also have at runtime. E2e tests are often quite slow - so there is a risk someone switches the context. We for example already protect against many cases at startup (this one is easy). As far as removing CertManager setup etc. - I personally like this setup although we so far setup everything before testing with kind/make. |
Hi @Sijoma,Let’s go step by step to clarify the situation. What is the problem?When running Why is this issue already resolved in the latest scaffold?The latest scaffold has addressed this issue with the following changes: ✅ Prometheus is no longer installed.
Why don’t we set
|
Hi @Sijoma, @reedjosh, @damsien, @jravetch, @monteiro-renato, After further consideration, I’ve updated the pros and cons of the alternative solution proposed in the comment above: link to comment, where we discuss centralizing everything. Honestly, I believe the best course of action here is:
So, I would suggest we close this issue based on the above considerations.
Let me know your thoughts! |
Totally fine for me 👍 . It's a never ending problem. Also agree that adding the context to the Makefile does not help at all.
Just to clarify - I personally meant adding the This would also protect you when you use the IDE to run tests (like I do too). We wrap the utils.Kubectl from Kubebuilder like so. Thank you @camilamacedo86 ! |
What do you want to happen?
The initial E2E suite created via kubebuilder does not protect against using a production kubernetes context.
This can result in removing monitoring and cert manager from production clusters.
Tilt for example only allows the user to run against a context matching
kind-*
by default, and requires the user to intentionally add other contexts.🙏 please add this protection. It is hard to otherwise ensure it doesn't crop up across a company.
Extra Labels
No response
The text was updated successfully, but these errors were encountered: