Refactor provider-kubeconfig.py and add tests#1457
Open
anniegracehu wants to merge 14 commits intocloud-ark:masterfrom
Open
Refactor provider-kubeconfig.py and add tests#1457anniegracehu wants to merge 14 commits intocloud-ark:masterfrom
anniegracehu wants to merge 14 commits intocloud-ark:masterfrom
Conversation
| @@ -856,10 +856,10 @@ def _generate_kubeconfig(self, sa, namespace, filename, api_server_ip='', kubeco | |||
| print("Permissions file should be used with update command.") | |||
Contributor
There was a problem hiding this comment.
- Add a generic help text/explanation for the purpose of provider-kubeconfig.py
- In the tests, verity that the various fields of the generated kubeconfig file are non-empty. And if we are passing any command-line flags (such as API server URL, cluster name, etc.) then the generated kubeconfig file has these values set for the appropriate fields.
- Update the help text for the namespace argument.
- Verify in the code that the scope of permissions for consumer is restricted to that namespace. The generated kubeconfig should have the provided namespace included in it. Verify manually that using this kubeconfig, we should not be able to do create/delete operations in other namespaces (try with creating/deleting a pod in other namespaces).
Collaborator
Author
There was a problem hiding this comment.
I have added the tests and updated the help text!
Made-with: Cursor
f49b13e to
b924df6
Compare
Keep old grouped provider/consumer RBAC as active source, add optional old-vs-new parity assertion for safer review, and document provider perms wildcard handling to match master behavior. Made-with: Cursor
Move PR notes to the GitHub PR description and drop the committed markdown helper file from the branch. Made-with: Cursor
Compute old/new all_resources from their respective rule builders, assert parity under the existing RBAC equivalence flag, and keep runtime behavior sourced from old rules and old all_resources. Made-with: Cursor
Use the current kubeconfig server URL for generated consumer kubeconfig in the cross-namespace authz test, and skip when API connectivity is transient so RBAC assertions only run on reachable clusters. Made-with: Cursor
Keep comment text neutral while preserving old-rule source-of-truth behavior for the shadow parity flow. Made-with: Cursor
Validate that -x sets both cluster entry names and context cluster reference, and ensure the cross-namespace consumer denial test verifies the forbidden error references the target namespace. Made-with: Cursor
…ied pod create. Replace the cross-namespace pod check with a behavior-valid assertion pair for current consumer RBAC: deployment creation succeeds while pod creation is forbidden using the generated consumer kubeconfig. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Provider Kubeconfig Refactor
Summary
Refactors
provider-kubeconfig.pyto use unified RBAC rule lists, fixes several bugs present on master, and adds tests. The script generates provider and consumer kubeconfigs with appropriate RBAC for the KubePlus platform.Bug Fixes (master had these bugs)
nonResourceURL parsing (
_update_rbac)Master used
parts[0]after splitting onnonResourceURL::; the correct value is inparts[1]. For"foo/nonResourceURL::bar": master→"foo/", PR→"bar".Namespace creation (create action)
Master had
create_ns = "kubectl get ns " + ...and ran that same GET command twice when the namespace was not found. The namespace was never created. PR runskubectl create ns <namespace>when the namespace does not exist.Token extraction (
_extract_kubeconfig)Master used
if 'token' in line, which matches any line containing "token" (e.g.Type: kubernetes.io/service-account-token,Labels: kubernetes.io/legacy-token-last-used). PR only treats lines where the key is exactly"token"as token lines.Sleep placement (token extraction)
Master had
time.sleep(2)inside the line-parsing loop, so it ran once per line when the token wasn't found. PR moves it outside the loop so it runs once per retry.Default kubeconfig path
Master used
os.getenv("HOME") + "/.kube/config", which can fail ifHOMEis unset. PR usesos.path.expanduser("~")for robustness.Main Changes (master → PR)
RBAC refactor
rule_listrules ("green") side by sideKUBEPLUS_RBAC_EQ_CHECK=1-permsConfigMap behavior:all_resourcesincludes wildcard entries as beforeall_resourcesexcludes"*"to match master behavior (master effectively omitted wildcard groups from provider perms inventory)Code cleanup
run_commandinstead ofself.run_command.create_role_rolebinding: usewith open(..., encoding="utf-8"),os.path.join.run_command: use context manager, handleNonefromcommunicate().sorted(list(set(x)))→sorted(set(x)).Tests (new; master has none)
New file
tests/test_provider_kubeconfig.py:--helpshows actions, flags, namespace;updatewithout-pexits with error.-s,-x,-freflected in output.test_consumer_cannot_create_pod_in_other_namespaceverifies create in another namespace is forbidden.Integration tests skip when no cluster is reachable (
KUBECONFIGunset).How to test
Follow-up plan