-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Check download perms recursively on referenced card-ids #50307
Conversation
|
1301102
to
caea2dd
Compare
(with-download-perms! (mt/id) {:schemas {"PUBLIC" {(mt/id 'venues) :limited | ||
(mt/id 'checkins) :full}}} |
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.
Changed all these since keywords are used in mt/id
everywhere else in the codebase
(streaming-test/do-test! | ||
"A user with limited download perms for a table has their query results limited for queries on that table" | ||
{:query {:database (mt/id) | ||
:type :query | ||
:query {:source-table (mt/id 'venues) | ||
:query {:source-table (mt/id :venues) |
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.
thanks for updating these, much cleaner with keywords.
@@ -32,16 +35,23 @@ | |||
;; Remove the :native key (containing the transpiled MBQL) so that this helper function doesn't think the query is | |||
;; a native query. Actual native queries are dispatched to a different method by the :type key. | |||
(let [{:keys [table-ids card-ids native?]} (query-perms/query->source-ids (dissoc query :native)) | |||
table-perms (if (or native? (seq card-ids)) | |||
table-perms (if native? |
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.
the comment on 35 reads that this query cannot be native, should it be reworded? to something like:
;; Remove the :native key (containing the transpiled MBQL) so that this helper function doesn't mistakenly classify
;; the query as a native query. Actual native queries are dispatched to a different method by the :type key.
Actually, I don't see why the dissoc matters since a different defmethod will handle :native. If it's clear to you tho please update the comment.
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.
Good point, the dissoc is unnecessary now, I've removed it
table-ids))) | ||
card-perms (set | ||
;; If we have any card references in the query, check perms recursively | ||
(map (fn [card-id] |
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.
nit: naming anon functions makes stack traces easier to follow
(map (fn [card-id] | |
(map (fn card-perms-lookup [card-id] |
Fixes #50304
In #49364 I changed
query->source-table-ids
to return sets oftable-ids
andcard-ids
. In that PR, I adjusted download perm enforcement to require full native perms if anycard-ids
were returned from that function, since we previously hadn't been considering referenced cards at all for download perms. (i.e. we were being overly permissive, allowing downloads even for queries joined to cards without download perms).This was too restrictive, though, and ended up blocking downloads for some queries that should be allowed. The more correct behavior is to check download perms recursively for any referenced card IDs in the query, and go with the least-permissive value from that entire set.
I've fixed the logic and added a test to catch this case.