-
Notifications
You must be signed in to change notification settings - Fork 40k
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
bugfix: prevent API server cache list/watch from other namespaces #25342
Conversation
} | ||
return filter(obj) | ||
|
||
return match && filter(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch in general. Can you please add a unit test for it?
/cc @hongchaodeng |
match := false | ||
for _, segment := range segments { | ||
currPath = path.Join(currPath, segment) | ||
if currPath == key { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if key ends with "/"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more problem: the code is incorrect for exact match case.
For exact match, i.e. filter("/abc", "/abc"), it will be ignored in WatchList(). See etcd_helper and etcd3/watcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.. - but it's only for main directory. So e.g. filter(/ns1/pod1, /ns1/pod1) will return true,
I think that we should base on the fact that here objKey is computed from runtime.Object and we should probably assume what it returns. That said, we should allow for exact match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine here because the results are already filtered out by underlying storage impl.?
@wojtek-t IIUC, when a client LIST a nonexistent key, the cache layer will return a empty list, and if a client WATCH a nonexistent key, the cache layer will never return any events, while it should return 404 in such a case? |
I don't agree. If client WATCH a nonexistent key it should open the watch and wait until such object appears. It may appear at some point. If not, then we will never return anything and this is fine. We definitely want to watch for objects that don't exist now, and this is a very common practice in fact. |
Ok, the behavior when watch sounds good to me. But it seems that we should fix the behavior when list(cache should return KeyNotFound error instead of an empty list)? Since I think the cache layer should not break any assumption the old clients may hold before having such a cache. Thoughts? |
If apiserver without cacher returns something different than apiserver with cacher, then this is definitely a bug and we should make them return the same (change cacher). |
So to clarify - yes, they should be compatible. |
@mqliang - sorry for being super unresponsive last time - I was on vacation and before I was super busy with 1.3 release. |
@wojtek-t Never mind, it's not a urgent PR. Will update this tomorrow. As for the "return KeyNotFound error instead of an empty list when list from a nonexistent namespace" issue, I will fix it after your #27277 are merged. I'd like add a namespace index for namespace scoped resource. It's very helpful for the above issue and for the "kubectl get XXX --namespcace=YYY" use case(it's also very common that many applications build on k8s need list a resource in a namespace). |
@mqliang - thanks |
@wojtek-t Updated. PTAL. |
@mqliang - thanks! LGTM |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
GCE e2e build/test passed for commit 3f7bca9. |
@mqliang - it seems the test you added is flaky:
Can you please take a look? [I'm removing lgtm for now.] |
@mqliang - will you find some time to debug this test? |
@mqliang PR needs rebase |
Already fixed by #28966 - closing this one. |
The previous code has a issue:
Assume we have two namespaces
ns1
andns11
, when client list/watch key/registry/pods/ns1
, API server cache will also return pods inns11
, sincens1
is a prefix ofns11
This PR fix this issue. @wojtek-t