Repository navigation
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @ifdotpy. Thanks for your PR. I'm waiting for a kcp-dev member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
…luster The local manager cached every type cluster-wide. A Secret informer therefore needed list and watch on Secrets in all namespaces, and namespace RoleBindings could not authorize it. With --secret-namespaces, the local cache lists and watches Secrets only in the given namespaces and in the agent namespace, where the object state is stored. This covers the typed state store and the unstructured related-resource watches. Other types keep the cluster-wide cache. Without the flag nothing changes. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
The cache was scoped, but the manager client read unstructured Secrets (primary objects and related resources) live and cluster-wide, and the pre-delete confirmation used the uncached API reader. With namespace-scoped RBAC these reads failed, and with broader RBAC they reached Secrets outside the configured namespaces. With --secret-namespaces, the local manager now hands out a client that serves Secret reads from the scoped cache and an API reader that sends one namespaced request per allowed namespace. A Secret read in any other namespace returns an error, which also stops a prune. An explicitly empty --secret-namespaces is rejected instead of caching Secrets cluster-wide. Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
A related destination lookup ignored every Get error, so an out-of-scope or forbidden Secret counted as missing: the Agent could write it again or skip its cleanup and release the finalizer. Only NotFound now means absent. With --secret-namespaces, the local client also refuses to create, update, patch or delete a Secret outside the configured namespaces, because the Agent could not read it back to adopt or clean it up. The live reader rejects a paginated List of Secrets without a namespace. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
The syncer applies destination objects with client.Apply when server-side apply is enabled. The scoped client did not override Apply, so an out-of-scope Secret could be created that the Agent then could not find or clean up. Apply now gets the same namespace check as the other writes. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
Status() and SubResource() of the scoped client now check the parent object like the other writes. The apply check parses the API version, so a noncanonical spelling of core v1 is recognized as a Secret. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
The scoped Status() client also exposed a Get method with no reader behind it. It now returns a wrapper with the write methods only. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
The scope recognized Secrets only by the kind Secret. The discovery RESTMapper also maps the lowercase kind "secret" to the Secrets resource, so an unstructured object with that kind passed the scope as a non-Secret and was read cluster-wide. The scope now resolves other core kinds with the client's RESTMapper. A kind other than Secret that maps to Secrets is refused, because the cache and its namespace restriction are keyed by the canonical kind. The live reader also builds a new option slice for each namespace, so it no longer writes into the caller's slice. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
The client removes the List suffix of a kind when the object has list shape, and caches the resolved resource by kind. So a single object with the kind SecretList and an items field reached the Secrets resource, while the scope resolved SecretList to another resource. The scope now accepts only Secret for one object and SecretList for a List call. For every other kind it resolves the kind and the kind without the List suffix, and refuses the request when one of them maps to Secrets. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
The subresource "secrets" of a Namespace parent is the Secret collection of that namespace, and the subresource clients only checked the parent object. The scoped subresource clients now refuse this subresource. Apply let a configuration pass when it had no apiVersion and kind getters. It now resolves a runtime.Object through the scheme, like the client does, and refuses a configuration that it cannot resolve. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
List and DeleteAllOf applied the caller's options to check the namespace and then passed the original options on, which applied them again. An option that returns a different namespace on the second evaluation could so reach a namespace outside --secret-namespaces. The wrappers now resolve the options once and pass the resolved options. The live reader also clears continue, remainingItemCount and resourceVersion of an aggregate list: the result spans several requests, so the metadata of an earlier request does not apply. Refs kcp-dev#195 Signed-off-by: Igor Fominykh <ifdotpy@gmail.com>
1a735d5 to
ca6a721
Compare
|
|
||
| // secretNamespacesSet records that --secret-namespaces was given, so that an empty | ||
| // value is rejected instead of silently caching Secrets cluster-wide. | ||
| secretNamespacesSet bool |
There was a problem hiding this comment.
I think pflag already tells these cases apart. With the nil default, an omitted flag leaves SecretNamespaces nil, and --secret-namespaces= sets it to []string{} (readAsCSV("") returns an empty slice). So we could drop this field and RecordParsedFlags, and check o.SecretNamespaces != nil && len(o.SecretNamespaces) == 0 in Validate(). That also removes the call in main.go, which if forgotten turns the empty check off without any error. TestSecretNamespacesFlag already covers it.
| // SecretNamespaces restricts the local cache for Secrets to these namespaces. The | ||
| // agent's own Namespace is always included because the object state is stored there. | ||
| // When empty, Secrets are cached in all namespaces. | ||
| SecretNamespaces []string |
There was a problem hiding this comment.
If we switch to the nil check, can you add a note here: nil means the flag was not given, an empty slice means it was given empty.
Summary
Today the Agent caches Secrets on the service cluster in all namespaces, so it needs cluster-wide read access to Secrets. #195 asks to limit this.
This PR adds
--secret-namespaces. When set:--namespace(the Agent stores object state there).secrets(the Secret collection of a Namespace parent) and apply configurations whose kind cannot be resolved are refused.Secret(andSecretListfor a List call) is accepted. A request that would reach Secrets with another kind (for example the lowercasesecretthat discovery also maps, orSecretListfor a single object) is refused, because the cache is keyed by the canonical kind.The guarantee covers the client and the API reader of the local manager (
GetClient,GetAPIReader) and the namespaces of the Secret informer. Direct use of the manager's cache, field indexer, REST config or HTTP client is outside of it; the Agent uses the REST config only for discovery and CRDs.Without the flag the Secret cache and reads keep their current scope.
One change applies with and without the flag: when the syncer looks up a related object on the destination side, it now treats only NotFound as "absent". Before, any read error counted as absent, so the object was written again or its cleanup was skipped.
Assumption and limits: the list is static. If target namespaces are created per object (we do this), the flag alone does not remove the cluster-wide read. Cleanup that enumerates Secrets cannot see copies in a namespace that was removed from the set; the getting-started guide describes this. A dynamic namespace set and informers that follow permission changes, as proposed in #195, need a larger design. This PR is a first step.
Tests: per-informer tests check the list and watch paths; scope tests run against a server that forbids cluster-wide Secret requests (client, live reader, excluded namespace, status client, kind aliases); a real flag parser test.
make lintandmake testpass. e2e not run (needs a kcp setup).What Type of PR Is This?
/kind feature
Related Issue(s)
Partially addresses #195
Release Notes