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

[Feature branch] Permissions schema + API change #37473

Merged
merged 39 commits into from
Mar 7, 2024

Conversation

noahmoss
Copy link
Member

@noahmoss noahmoss commented Jan 9, 2024

Feature branch for #26918

DO NOT MERGE until all changes are ready and merged into this PR.

This should only contain changes that have already been code reviewed and fully passed CI.

Copy link
Member Author

noahmoss commented Jan 9, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @noahmoss and the rest of your teammates on Graphite Graphite

@metabase-bot metabase-bot bot added the .Team/AdminWebapp Admin and Webapp team label Jan 9, 2024
@noahmoss noahmoss added no-backport Do not backport this PR to any branch .Team/AdminWebapp Admin and Webapp team and removed .Team/AdminWebapp Admin and Webapp team labels Jan 9, 2024
@noahmoss noahmoss marked this pull request as ready for review January 9, 2024 20:01
@noahmoss noahmoss requested a review from camsaul as a code owner January 9, 2024 20:01
@noahmoss noahmoss force-pushed the perms-refactor-feature-branch branch from 4106a6d to 8d2084f Compare January 9, 2024 22:17
@noahmoss noahmoss force-pushed the perms-refactor-feature-branch branch from 8d2084f to cfc3be1 Compare January 11, 2024 02:31
@escherize escherize force-pushed the perms-refactor-feature-branch branch from c1a657f to 6a1f6ba Compare January 12, 2024 00:07
Copy link

replay-io bot commented Jan 12, 2024

Status In Progress ↗︎ 55 / 56
Commit e237a66
Results
⚠️ 3 Flaky
2319 Passed

@noahmoss noahmoss force-pushed the perms-refactor-feature-branch branch from 6a1f6ba to 7310d65 Compare January 12, 2024 22:26
@noahmoss noahmoss force-pushed the perms-refactor-feature-branch branch 8 times, most recently from eb38571 to f67bb9f Compare January 17, 2024 21:16
noahmoss and others added 14 commits March 6, 2024 16:13
First, I added a new function to `models.data-permissions`,
`full-database-permission-for-user`, that is equivalent to
`full-schema-permission-for-user` but for an entire database rather than
a table. For each group, it gets the *least* permissive permission in
the database, then coalesces the result like  normal.

If permissions look like this:

```
id  |    object     | group_id
-----+---------------+----------
 156 | /db/1/native/ |        1
 155 | /db/1/schema/ |        2
 154 | /db/1/        |        3
 158 | /db/1/schema/ |        4
 159 | /db/1/native/ |        4
```

DataPermissions end up looking like this:

```
id  | group_id |          perm_type          | db_id | schema_name | table_id |   perm_value
-----+----------+-----------------------------+-------+-------------+----------+-----------------
 809 |        1 | perms/data-access           |     1 |             |          | no-self-service
 816 |        1 | perms/download-results      |     1 |             |          | no
 825 |        1 | perms/manage-database       |     1 |             |          | no
 832 |        1 | perms/manage-table-metadata |     1 |             |          | no
 841 |        1 | perms/native-query-editing  |     1 |             |          | yes
 813 |        2 | perms/data-access           |     1 |             |          | unrestricted
 818 |        2 | perms/download-results      |     1 |             |          | no
 829 |        2 | perms/manage-database       |     1 |             |          | no
 834 |        2 | perms/manage-table-metadata |     1 |             |          | no
 845 |        2 | perms/native-query-editing  |     1 |             |          | no
 811 |        3 | perms/data-access           |     1 |             |          | unrestricted
 817 |        3 | perms/download-results      |     1 |             |          | no
 827 |        3 | perms/manage-database       |     1 |             |          | no
 833 |        3 | perms/manage-table-metadata |     1 |             |          | no
 843 |        3 | perms/native-query-editing  |     1 |             |          | yes
 815 |        4 | perms/data-access           |     1 |             |          | unrestricted
 819 |        4 | perms/download-results      |     1 |             |          | no
 831 |        4 | perms/manage-database       |     1 |             |          | no
 835 |        4 | perms/manage-table-metadata |     1 |             |          | no
 847 |        4 | perms/native-query-editing  |     1 |             |          | yes
```

So to match the existing logic (matching permissions to `/db/:id/` OR
BOTH OF `/db/:id/native/` and `/db/:id/schema`) we can just check that
the user has `yes` for `native-query-editing`, plus unrestricted
`data-access`, for *every* table in the database.

Note that we are now filtering tables after selecting them from the
database. There is an existing comment in `metabase.api.search` saying:

> We get to do this slicing and dicing with the result data because the
> pagination of search is for UI improvement, not for performance. We
> intend for the cardinality of the search results to be below the default
> max before this slicing occurs

So I think this ok.

Also, the `api.search-test` namespace was the only user of
`mt/with-all-users-data-perms-graph`. I swapped out the implementation
of that macro with what we've been using in our advanced permissions
tests, and deleted the existing macro from our advanced permissions
tests, to avoid duplication.
Co-authored-by: Noah Moss <noahbmoss@gmail.com>
* Prohibit creating new data permissions

And stop trying to create them.

Co-authored-by: Noah Moss <32746338+noahmoss@users.noreply.github.com>
@noahmoss noahmoss force-pushed the perms-refactor-feature-branch branch from 2664e55 to e237a66 Compare March 6, 2024 21:13
@noahmoss noahmoss merged commit 2e5a99b into master Mar 7, 2024
108 checks passed
@noahmoss noahmoss deleted the perms-refactor-feature-branch branch March 7, 2024 14:47
Copy link

github-actions bot commented Mar 7, 2024

@noahmoss Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch run-cloverage Runs Cloverage (BE test coverage job) on this PR .Team/AdminWebapp Admin and Webapp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants