Skip to content

Disabled kinds from filter menu based on access#34205

Merged
avatus merged 3 commits intomasterfrom
avatus/hide_filter_panel
Nov 10, 2023
Merged

Disabled kinds from filter menu based on access#34205
avatus merged 3 commits intomasterfrom
avatus/hide_filter_panel

Conversation

@avatus
Copy link
Copy Markdown
Contributor

@avatus avatus commented Nov 3, 2023

This PR solves two recent issues that came up.
Previously (before the unified resources view), the dashboard tenants would not see any "resource" options in their navigation as each item was hidden based on access. The new unified resources tab didn't have those checks so I've added them in. Dashboard tentants will no longer see any resources tab after this change. Similarly, if a user doesn't have access to any of the types (but isn't a dashboard tenant), they also won't see the resources tab. This is a fix to a regression.

Second, this updates the filter menu in the unified view to only be visible if they have more than 1 kind available to view, and removes kinds they cannot view from the filter menu. (below is an example if I don't have access to databases)

Screenshot 2023-11-03 at 10 10 58 AM

Fixes: https://github.com/gravitational/cloud/issues/6519

Comment thread web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx Outdated
@github-actions github-actions Bot requested review from rudream and ryanclark November 3, 2023 15:12
@avatus avatus added backport-required backport/branch/v14 no-changelog Indicates that a PR does not require a changelog entry labels Nov 3, 2023
Comment thread web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx Outdated
Comment thread web/packages/teleport/src/features.tsx Outdated
@avatus avatus force-pushed the avatus/hide_filter_panel branch from a5baae3 to 94d1dad Compare November 5, 2023 22:51
@avatus avatus changed the title Hide unavailable kinds from filter menu Disabled kinds from filter menu based on access Nov 7, 2023
@avatus
Copy link
Copy Markdown
Contributor Author

avatus commented Nov 7, 2023

This requires a complete review as it's a very different solution now. Previously, I would just hide the kinds if the user didn't have access. Now this disabled the use of the menu item in the filter itself.

@avatus avatus requested review from kimlisa and mcbattirola November 7, 2023 23:06
Copy link
Copy Markdown
Contributor

@kimlisa kimlisa left a comment

Choose a reason for hiding this comment

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

i was just curious what it looked like with all deny rules (asteriks) and this is what i got.

i'm still able to query 🤔 . was this change intentional? unless my cluster is messed up (happens a lot 😅 ), looking at my config, i'm still able to query probably because my labels allow it so... but i thought deny rules had precedence over everything else?

as an example, for listResources and getXXX, we do a preliminary action check like below. i'm not sure unified resources does this check (i see we do invidiual resource check) but maybe i'm blind.

func (a *ServerWithRoles) GetNodes(ctx context.Context, namespace string) ([]types.Server, error) {
	if err := a.action(namespace, types.KindNode, types.VerbList); err != nil {
		return nil, trace.Wrap(err)
	}
image
kind: role
metadata:
  id: 1699427772659522000
  name: deny-all
  revision: f2ad4828-80df-4254-8058-f51de875fd8d
spec:
  allow:
    app_labels:  // <--- these labels is what is enabling me to still query despite my deny rules
      '*': '*'
    db_labels:
      '*': '*'
    db_names:
    - '{{internal.db_names}}'
    - '*'
    db_users:
    - '{{internal.db_users}}'
    - developer
    kubernetes_groups:
    - '{{internal.kubernetes_groups}}'
    - developer
    kubernetes_labels:
      '*': '*'
    kubernetes_resources:
    - kind: '*'
      name: '*'
      namespace: '*'
      verbs:
      - '*'
    kubernetes_users:
    - '{{internal.kubernetes_users}}'
    - dev
    logins:
    - '{{internal.logins}}'
    - ubuntu
    - debian
    node_labels:
      '*': '*'
    rules:
    - resources:
      - event
      verbs:
      - list
      - read
    - resources:
      - session
      verbs:
      - read
      - list
      where: contains(session.participants, user.metadata.name)
    windows_desktop_labels:
      '*': '*'
    windows_desktop_logins:
    - '{{internal.windows_logins}}'
    - developer
  deny:
    rules:
    - resources:
      - '*'
      verbs:
      - '*'
  options:
    cert_format: standard
    create_db_user: false
    create_desktop_user: false
    desktop_clipboard: true
    desktop_directory_sharing: true
    enhanced_recording:
    - command
    - network
    forward_agent: false
    idp:
      saml:
        enabled: true
    max_session_ttl: 8h0m0s
    pin_source_ip: false
    port_forwarding: true
    record_session:
      default: best_effort
      desktop: true
    ssh_file_copy: true
version: v7

Comment thread web/packages/teleport/src/features.tsx Outdated
Comment thread web/packages/teleport/src/config.ts Outdated
Comment thread web/packages/design/src/Menu/MenuItem.jsx Outdated
Comment thread web/packages/teleport/src/UnifiedResources/UnifiedResources.tsx
@avatus
Copy link
Copy Markdown
Contributor Author

avatus commented Nov 8, 2023

i was just curious what it looked like with all deny rules (asteriks) and this is what i got.

This seems unintentional. I've updated this PR to include the actionVerbs check in auth_with_roles.ListUnifiedResources.
Could you poke around again and see if it works as expected now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you should double check for the others, but i know nodes, only does list check in the back

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks like only nodes does list and everyting else is both. thank you

Comment thread lib/auth/auth_with_roles.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i would model these verbList with previous implementations because we don't want to deny access to something we gave access for previously (example is nodes, for some reason, it only checks for rbac list, but now we require read here as well, so access may break for some)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

when did we release this feature again? i'm a little worried about the implication of this bug for previous v14 versions. not sure what the right protocol is, or perhaps i'm just over-thinking

Comment thread lib/auth/auth_with_roles.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would there be any performance issues because it seems we are checking rbac repeatedly for the same resource kind? (can we do it once per resource kind?) i would get a backend person to review this just in case 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@avatus avatus Nov 9, 2023

Choose a reason for hiding this comment

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

You know, I don't even think this is a good solution either. This causes my backend to get 20+ INFO RBAC Access not allowed to list type of messages. (edit: i was able to suppress this by using quietAction instead)

What I'm curious about is why this isn't checked in CanAccess as it seems like it should be there. Perhaps I'm missing context, but I think that the deny rule should be caught in CanAccess (edit: after talking with Nic, we should be checking for verbs because CanAccess is more about access to backend state rather than listing.)

As far as performance goes, running the benchmark with this added took it from from ~2.8s to ~3.2s which is still in line with BenchmarkListNodes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I think we would benefit from building a local cache of which resources the user is allowed to read/list and using that later on instead of checking for every resource.

@kimlisa kimlisa self-requested a review November 9, 2023 02:18
@avatus avatus requested a review from rosstimothy November 9, 2023 02:22
@avatus avatus force-pushed the avatus/hide_filter_panel branch from 1e01124 to 588949a Compare November 9, 2023 06:10
Comment thread lib/auth/auth_with_roles.go Outdated
Comment on lines 153 to 156
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would remove this and make the call directly inline to be consistent with every other invocation in this file.

Comment thread lib/auth/auth_with_roles.go Outdated
Comment on lines 1551 to 1553
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a comment similar to the one in ListResources to provide some context on why this is needed.

Comment thread lib/auth/auth_with_roles.go Outdated
Comment on lines 1555 to 1556
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: reduce the scope of errors where possible

Suggested change
err := a.quietAction(apidefaults.Namespace, resourceKind, actionVerbs...)
if err != nil {
if err := a.quietAction(apidefaults.Namespace, resourceKind, actionVerbs...); err != nil {

Comment thread lib/auth/auth_with_roles.go Outdated
Comment on lines 1567 to 1568
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: reduce the scope of errors where possible

Suggested change
err = checker.CanAccess(resource)
if err != nil {
if err := checker.CanAccess(resource); err != nil {

Comment thread lib/auth/auth_with_roles.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: missing a trace.Wrap on returned errors here

Suggested change
return services.MatchResourceByFilters(resource, filter, nil)
match, err := services.MatchResourceByFilters(resource, filter, nil)
return match, trace.Wrap(err)

@avatus avatus requested a review from rosstimothy November 9, 2023 17:06
Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Backend changes look good to me. Could we just add a test that covers this?

Comment thread lib/auth/auth_with_roles.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return a.checkUnifiedAccess(resource, checker, filter, resourceAccessMap)
match, err := a.checkUnifiedAccess(resource, checker, filter, resourceAccessMap)
return match, trace.Wrap(err)

Comment thread lib/auth/auth_with_roles.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
return a.checkUnifiedAccess(resource, checker, filter, resourceAccessMap)
match, err := a.checkUnifiedAccess(resource, checker, filter, resourceAccessMap)
return match, trace.Wrap(err)

Copy link
Copy Markdown
Contributor

@kimlisa kimlisa left a comment

Choose a reason for hiding this comment

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

lgtm 👍, after tim's comment

@avatus avatus force-pushed the avatus/hide_filter_panel branch from 89df0b0 to d4c95ed Compare November 10, 2023 00:27
@avatus avatus enabled auto-merge November 10, 2023 00:27
@avatus avatus requested a review from rosstimothy November 10, 2023 01:09
@avatus avatus disabled auto-merge November 10, 2023 19:57
@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from ryanclark November 10, 2023 20:48
@avatus avatus enabled auto-merge November 10, 2023 20:53
@avatus avatus added this pull request to the merge queue Nov 10, 2023
Merged via the queue into master with commit 28f57ae Nov 10, 2023
@avatus avatus deleted the avatus/hide_filter_panel branch November 10, 2023 21:29
@public-teleport-github-review-bot
Copy link
Copy Markdown

@avatus See the table below for backport results.

Branch Result
branch/v14 Failed

avatus added a commit that referenced this pull request Nov 10, 2023
* Hide unavailable kinds from filter menu

* Fix hover tooltip
github-merge-queue Bot pushed a commit that referenced this pull request Nov 11, 2023
* Disabled kinds from filter menu based on access (#34205)

* Hide unavailable kinds from filter menu

* Fix hover tooltip

* Add UnifiedResourceKinds to branchv14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-required no-changelog Indicates that a PR does not require a changelog entry size/sm ui

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants