Fix SHOW QUERIES and KILL QUERY privilege filtering - #18359
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #18359 +/- ##
============================================
- Coverage 43.40% 43.39% -0.01%
Complexity 374 374
============================================
Files 5366 5366
Lines 382885 382885
Branches 49796 49796
============================================
- Hits 166187 166171 -16
- Misses 216698 216714 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PDGGK
left a comment
There was a problem hiding this comment.
The inversion is right, and the root-cause line in the description is accurate: with the old condition the restriction was applied only to users who passed the MAINTAIN check, so the default for an unprivileged user was an unset allowedUsername, which is the see-everything case. Two things I checked that are worth recording, and one suggestion.
No audit-log regression. checkHasGlobalAuth is not side-effect-free — it calls AUDIT_LOGGER.log(...) with context.setResult(result) on every invocation. Inverting the branch does not change whether that call happens, only what runs inside it, so both the CONTROL audit event on KILL QUERY and the recorded pass/fail result are unchanged by this patch. Worth stating explicitly because inverting a condition around an audited check is the kind of change where a reviewer would reasonably worry about exactly that.
The SYSTEM claim holds. PrivilegeType.getAllPrivilegesContainingCurrentPrivilege() returns [MAINTAIN, SYSTEM] for MAINTAIN, so a user holding only SYSTEM still satisfies the MAINTAIN check and keeps cluster-wide visibility after the fix. That is the case I would most expect a fix in this direction to break — an operator with SYSTEM suddenly restricted to their own queries — and it does not break.
Suggestion, not a blocker: consider adopting the table-model shape. The table-model path for the same operation is written the other way round, in TableConfigTaskVisitor.visitKillQuery:
String allowedUsername = context.getSession().getUserName();
if (accessControl.hasGlobalPrivilege(context.getSession().getUserEntity(), PrivilegeType.SYSTEM)) {
allowedUsername = null;
}It starts restricted and widens only on a positive privilege result. The tree version, even after this patch, starts unrestricted and narrows inside an if — so the safe outcome depends on that branch being reached and correct. That is precisely how the original defect was able to exist, and it is why a single missing ! was a privilege escalation rather than a denial of service. If the tree sites were initialized to context.getUsername() and cleared on a successful check, the same class of mistake would fail closed instead of open.
I checked whether the table-model path had the mirror of this bug before suggesting this — it does not, for the reason above.
Two smaller notes:
- The description says SYSTEM "contains the deprecated MAINTAIN privilege". Since
getReplacedPrivilegeType()maps MAINTAIN to SYSTEM, it may be worth a short comment at these two call sites recording that MAINTAIN is retained here for compatibility, so a future cleanup pass does not delete the check and silently widen visibility. - The new ITs keep queries alive across Session fetches, which is the hard part of testing this — good. If it is cheap to add, the case I would most want pinned is a SYSTEM-only user (no explicit MAINTAIN grant) seeing another user's query, since that is the path that depends on the subsumption above rather than on the changed line itself.




Summary
SHOW QUERIESresults to the current user when the user does not satisfy theMAINTAINauthorization check.KILL QUERYto the current user's queries under the same condition.SYSTEMprivilege, which contains the deprecatedMAINTAINprivilege, to view and kill queries from all users.IoTDBShowQueriesITandIoTDBKillQueryITwith queries that remain active across Session fetches.Root cause
TreeAccessCheckVisitor.visitShowQueriesandvisitKillQuerysetallowedUsernamewhen theMAINTAINauthorization check succeeded instead of when it failed. As a result, an unprivileged user could see or kill other users' queries, while a privileged user could be unnecessarily restricted.Impact
Tree-model
SHOW QUERIESandKILL QUERYnow apply the intended visibility and control rules while retaining the existingMAINTAINauthorization check.Validation
SYSTEM; the tests do not grant deprecatedMAINTAINdirectly.