-
Notifications
You must be signed in to change notification settings - Fork 707
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
find namespaces incorrectly swapped client context and incorrectly using pinniped proxy #5755
Comments
We have a user who seems to be hitting this issue, so I'm prioritising it :) |
I can reproduce this locally, even with an admin user. Steps to reproduce:
Checking the network requests in the browser tab shows
followed by the sign-out action (which we trigger on an unauthorized response). |
I've been working through the code in this section of functionality (since it changed significantly 3 months ago) to understand where the issues lie. From what I've understood so far, the main issue is that the configured service account for a cluster (which is required for users who do not have perms to list namespaces on an additional cluster) is never used. Example below. The backup check for namespaces is correct for single cluster but incorrect for multiclusterKubeapps initially checks if it can use the users credential (an But in reality, the current code only ever uses the pod service account in this backup case. This is even mentioned in the comment in the code: kubeapps/cmd/kubeapps-apis/plugins/pkg/resources/namespaces.go Lines 45 to 54 in a90a69e
So, when switching to a different cluster, the list of namespaces obtained before filtering for the user, is the list of namespaces from the cluster on which Kubeapps is installed. This was extremely difficult to determine (for me) due to the fact that in our dev environment we have the same namespace
Create a rolebinding for kubeapps-user in both namespaces on both clusters:
Verify that kubeapps-user can access secrets in the namespaces on both clusters
Check in the Kubeapps UI and notice that the namespace for the default cluster is displayed, but when switching to the additional cluster, the namespace for that cluster is not. The initial request using the user's credentialsAs mentioned, the initial request for the list of namespaces on a cluster should first attempted using the users' credential. Though in the code, it is the kubeapps/cmd/kubeapps-apis/plugins/pkg/resources/namespaces.go Lines 34 to 42 in a90a69e
which is generated from the kubeapps/cmd/kubeapps-apis/plugins/resources/v1alpha1/server.go Lines 45 to 46 in a90a69e
So at first I expected this not to work, as it is configured to go via pinniped-proxy (as the OP mentioned), but as it turns out, the client is created with the request context which includes the user token, so the request still gets through works (either succeeding if the user has perms, or resulting in the expected 401 if not). It is just confusing that the cluster service account is configured to be used here for the user request that goes through pinniped, even though it is not used. ProposalSo, with that in mind, I intend to update the code so that:
If I have time, I'll additionally try to simplify the code here (there are a lot of functions that create functions being passed around, which can be hard to reason about, IMO), and possibly add a CI test for this with multicluster (that doesn't use the |
…es. (#5940) <!-- Before you open the request please review the following guidelines and tips to help it be more easily integrated: - Describe the scope of your change - i.e. what the change does. - Describe any known limitations with your change. - Please run any tests or examples that can exercise your modified code. Thank you for contributing! --> ### Description of the change <!-- Describe the scope of your change - i.e. what the change does. --> The main change here is to ensure that the request for namespaces uses the *user* client first, then the service account client. For a detailed analysis of the issue it is fixing, see my [comment on 5755](#5755 (comment)) While there, I have tried to clarify the code a little, so that it is clearer when the user client is being used (it now matches the comments again). I also fixed an RBAC issue in the dev environment (so that `kubeapps-user@example.com` is permitted to access, in addition to `oidc:kubeapps-user@example.com`, since the former is what pinniped uses). ### Benefits <!-- What benefits will be realized by the code change? --> Back to expected behavior when authenticated as a non-privileged user with or without a service account token configured in Kubeapps' clusters configuration. ### Possible drawbacks <!-- Describe any known limitations with your change --> ### Applicable issues <!-- Enter any applicable Issues here (You can reference an issue using #) --> - fixes #5755 ### Additional information <!-- If there's anything else that's important and relevant to your pull request, mention that information here.--> I've tested this pretty thoroughly locally with multiple clusters using both unprivileged and privileged users (with additional log lines showing exactly what token is being used when), but only in the namespaces call-site. --------- Signed-off-by: Michael Nelson <minelson@vmware.com>
Describe the bug
In a multicluster environment, the UI needs to be able to find the namespaces that a logged-in user has access for a given namespace. This is done via the context switcher in the header.
The backend method fetching the namespaces does so by first using the logged-in user permissions, and if the user does not have permissions to list namespaces, the code should try with the provided servicetoken.
there are several issues with the current code:
To Reproduce
To reproduce those issues, the logged-in user should not have cluster admin role, but be a namespace admin only.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: