Skip to content
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

Add behavioural tests for Cluster Menu K8s Resources in Sidebar menu not being shown #7280

Merged
merged 10 commits into from
Mar 22, 2023

Conversation

Nokel81
Copy link
Collaborator

@Nokel81 Nokel81 commented Mar 3, 2023

This PR fixes an oversight in #6657. Namely, I previously assumed that all the applicable resources rules would be merged together on the server side before sending a response back for a given SelfSubjectRulesReview. That, however, is not the case and instead it seems that most kubernetes distros (or at least K0s) just find all the applicable rules and then send them all back in a list.

To reproduce this yourself:

  1. Create an LDK
  2. Share it with a space
  3. Pause the updater and remove the rules targeting lens space Members and Admins
  4. Add two new ClusterRoles's, one called namespace-get which allows the get verb on namespaces and one called namespace-list which allows the list verb on namespaces
  5. Add two new ClusterRoleBindings, one for each of the above, targeting your own user.
  6. Connect to the shared version of the LDK and run the following command in the terminal.
    • curl -H "Content-Type: application/json" -X POST 127.0.0.1:8001/apis/authorization.k8s.io/v1/selfsubjectrulesreviews --data '{ "apiVersion": "authorization.k8s.io/v1", "kind": "SelfSubjectRulesReview", "spec": { "namespace": "default" }}'
  7. See something like the following:
status:
  resourceRules:
    - apiGroups:
        - ''
      resourceNames: null
      resources:
        - 'namespaces'
      verbs:
        - 'list'
    - apiGroups:
        - 'policy'
      resourceNames:
        - '00-k0s-privileged'
      resources:
        - 'podsecuritypolicies'
      verbs:
         - 'use'
    - apiGroups:
        - 'authorization.k8s.io'
      resourceNames: null
      resources:
        - 'selfsubjectaccessreviews'
        - 'selfsubjectrulesreviews'
      verbs:
        - 'create'
    - apiGroups:
        - ''
      resourceNames: null
      resources:
        - 'namespaces'
      verbs:
        - 'get'

@Nokel81 Nokel81 added bug Something isn't working area/rbac Something related to Kube RBAC permissions labels Mar 3, 2023
@Nokel81 Nokel81 added this to the 6.4.2 milestone Mar 3, 2023
@Nokel81 Nokel81 requested a review from a team as a code owner March 3, 2023 22:10
@Nokel81 Nokel81 requested review from jansav and ixrock and removed request for a team March 3, 2023 22:10
@Nokel81 Nokel81 linked an issue Mar 5, 2023 that may be closed by this pull request
Copy link
Contributor

@jakolehm jakolehm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this PR touches too many places for a hotfix (patch release).

Comment on lines 170 to 173
const {
fakeTime = true,
} = options;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that there's case where we want to support behavioural unit tests without fake time.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@jweak jweak modified the milestones: 6.4.2, 6.4.3 Mar 6, 2023
@msa0311 msa0311 changed the title Fix Pods sidebar menu not being shown Fix Cluster Menu K8s Resources in Sidebar menu not being shown Mar 6, 2023
@Nokel81 Nokel81 changed the base branch from release/v6.4 to master March 6, 2023 15:18
@Nokel81 Nokel81 force-pushed the attempt-2-fix-pods-missing-sidebar branch from 7e0556b to 931048e Compare March 6, 2023 16:58
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2023

Conflicts have been resolved. A maintainer will review the pull request shortly.

@jim-docker jim-docker modified the milestones: 6.4.3, 6.4.4 Mar 6, 2023
@Nokel81 Nokel81 modified the milestones: 6.4.4, 6.5.0 Mar 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@Nokel81 Nokel81 force-pushed the attempt-2-fix-pods-missing-sidebar branch from 931048e to c7ef585 Compare March 7, 2023 20:27
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2023

Conflicts have been resolved. A maintainer will review the pull request shortly.

@Nokel81 Nokel81 force-pushed the attempt-2-fix-pods-missing-sidebar branch from c7ef585 to b3773c8 Compare March 7, 2023 20:42
@github-actions
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@Nokel81 Nokel81 force-pushed the attempt-2-fix-pods-missing-sidebar branch from b3773c8 to c5e1778 Compare March 10, 2023 16:22
@github-actions
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

@Nokel81 Nokel81 changed the title Fix Cluster Menu K8s Resources in Sidebar menu not being shown Add behavioural tests for Cluster Menu K8s Resources in Sidebar menu not being shown Mar 10, 2023
@github-actions
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Nokel81 added 10 commits March 13, 2023 10:08
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
Signed-off-by: Sebastian Malton <sebastian@malton.name>
@Nokel81 Nokel81 force-pushed the attempt-2-fix-pods-missing-sidebar branch from 93abc4c to 7c48248 Compare March 13, 2023 14:08
@github-actions
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link
Contributor

@jim-docker jim-docker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all refactoring? (I don't see any tests added)

I guess my comments are for the previous review, and not really an issue if "CreateCanI" is called more than once, so "CanI" can change, if some auth/api error gets corrected.

Comment on lines +33 to +37
} catch (error) {
logger.error(`[AUTHORIZATION-REVIEW]: failed to create access review: ${error}`, { resourceAttributes });

return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's an error do we know for sure the answer is false? Seems strange that the caller doesn't know there was an error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't, but since these are currently only used for optimizations it is fine if they are turned off in case of error.

Plus this has always been the case.

Comment on lines +35 to +37
logger.warn(`[AUTHORIZATION-NAMESPACE-REVIEW]: allowing all resources in namespace="${namespace}" due to incomplete SelfSubjectRulesReview: ${status?.evaluationError}`);

return () => true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller has no idea here, or in the catch below, that api.createSelfSubjectRulesReview() failed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is safer to show all the resources of this fails then to show none.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm really questioning whether that decision should be made here or by the caller, which might be able to show a helpful notification to the end-user. Now there is no indication to the user why there are suddenly all these resources listed in the sidebar that perhaps can't be listed.

@Nokel81
Copy link
Collaborator Author

Nokel81 commented Mar 22, 2023

packages/core/src/features/cluster/refresh-accessibility-technical.test.ts was added

The diff is large so it is hidden by default.

@Nokel81 Nokel81 merged commit 8a80607 into master Mar 22, 2023
@Nokel81 Nokel81 deleted the attempt-2-fix-pods-missing-sidebar branch March 22, 2023 02:00
@Nokel81 Nokel81 mentioned this pull request Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rbac Something related to Kube RBAC permissions bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants