Skip to content

A tracker credential is read-only only when every grant is a known read - #243

Merged
zlareb1 merged 16 commits into
mainfrom
fix/tracker-grant-review-fail-closed
Nov 4, 2026
Merged

zlareb1 merged 16 commits into
mainfrom
fix/tracker-grant-review-fail-closed

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

tracker.source.add, tracker.source.inspect, tracker.source.rotate and tracker.source.set_mapping refuse a credential that holds displaySecretsInShowAndSelect, a grant WITH GRANT OPTION or WITH ADMIN OPTION, or any access type beyond SELECT, SHOW, dictGet and CREATE TEMPORARY TABLE, held directly or through a granted role, nested roles included, and a credential with a granted role that is not a default role. Such credentials were accepted as read-only.

Why

Failing cases: review_grants(["GRANT displaySecretsInShowAndSelect ON *.* TO u"]).read_only, GRANT SELECT ON db.* TO u WITH GRANT OPTION and GRANT r1 TO u WITH ADMIN OPTION were all True.

Pattern: the read-only check was a deny-list compared in a different case and a different part of the line than where the entries appear. The set held displaySecretsInShowAndSelect in mixed case while the code compared upper-cased types, and the two OPTION entries only appear after TO, which the parser drops. A deny-list also passes any access type it does not list.

A granted role was also never inspected: the probe ran a bare SHOW GRANTS, which lists a role by name and not what it grants, so GRANT writer TO loom_ro with writer holding INSERT passed.

Fix: the check is an allow-list. The probe runs SHOW GRANTS (for the role names it reports back) and SHOW GRANTS FINAL, which merges each granted role's grants into the user's. A credential is read-only when every access type in both is SELECT, SHOW (databases, tables, columns, dictionaries), dictGet or CREATE TEMPORARY TABLE, compared upper-case, and no line grants WITH GRANT OPTION or WITH ADMIN OPTION. SHOW GRANTS FINAL drops role lines, so an admin option on a role granted to a role reaches neither statement. The probe also reads system.enabled_roles (one of the tables every user can read), which lists each role in the chain with its admin option, and refuses one that has it. It refuses a granted role that is not a default role, because its chain is not enabled and cannot be seen.

Any other type, any line that is neither GRANT nor REVOKE, a line with an unbalanced quote, a line with more than one ON clause and a GRANT line with no ON or TO, or with no names before it, are refused. Quoted names (columns, roles, users) are blanked out before the line is split, so a backtick-quoted column holding (, , or ON cannot hide the types after it, and column lists (SELECT(a, b)) are split only on commas outside the parentheses. Each type must be a name with at most one column list. CREATE ARBITRARY TEMPORARY TABLE is not read access. GrantReview.write_types is renamed refused, since it also holds grant options and unparsed lines; GrantReview.grants (the raw lines, read by nothing) is removed; not_enabled holds granted roles missing from the enabled roles; roles holds role names unquoted. The dashboard's roles line after a passing check now says the roles grant read access only.

Scope and risk

Touches server/tracker/app/onboarding.py (review_grants, which now also takes the enabled roles, GrantReview.refusal, and probe_credential, which now also runs SHOW GRANTS FINAL and reads system.enabled_roles), the refusal message in server/tracker/app/sources.py, and the dashboard's read-only check row, which now shows the server's message as is instead of appending its own advice. Granted roles are still reported back by name. SHOW GRANTS FINAL merges every granted role, default or not, and follows roles granted to roles (both checked with clickhouse local after SET DEFAULT ROLE NONE), so a role the session has not enabled, or one two levels down, is checked too. Break: a credential holding a type outside the list (for example INTROSPECTION, SHOW ACCESS or CREATE ARBITRARY TEMPORARY TABLE) or any grant WITH GRANT OPTION is now refused with CREDENTIAL_NOT_READONLY, and so is one whose granted role holds such a type, and one granted a role that is not a default role (fixed with SET DEFAULT ROLE ALL TO <user>). A server that does not accept SHOW GRANTS FINAL is refused as SOURCE_UNREACHABLE, with a message that names the statement. The check runs on add, rotate, inspect (also inspect by name, with the stored credential) and set_mapping (stored credential), so a registered source whose credential holds such a grant cannot be inspected by name or remapped until its credential is rotated. Reads of a registered source are not re-checked.

Compatibility, rollout and rollback

  • Wire: no op or field changes. The CREDENTIAL_NOT_READONLY message now reads "holds more than read access (...)", or, for a role that is not a default role, names it and says to run SET DEFAULT ROLE ALL TO <user>.
  • Operator steps: none.
  • Rollback: a revert leaves nothing behind.

Tests

tests/unit/test_tracker_source_add.py::test_grant_review_refuses_what_it_cannot_classify_as_read_only failed before the fix on the displaySecretsInShowAndSelect line and passes now. It also covers both OPTION forms, SHOW NAMED COLLECTIONS, an unknown type, CREATE ARBITRARY TEMPORARY TABLE, quoted columns holding (, , and ON in front of INSERT, an unbalanced quote, quoted role and user names, a role granted WITH ADMIN OPTION, a column list and a REVOKE line. tests/unit/test_tracker_onboarding_host.py::test_probe_reviews_the_grants_a_role_carries drives probe_credential with a fake client whose only INSERT comes from a role and asserts it is refused. It also feeds an admin option on a nested role through system.enabled_roles; test_role_review_refuses_a_role_that_is_not_enabled_or_holds_an_admin_option covers a non-default role and a nested admin option. test_probe_names_the_grant_statement_the_server_refused covers a server that rejects SHOW GRANTS FINAL. test_show_grants_final_carries_what_a_role_chain_grants runs SHOW GRANTS and SHOW GRANTS FINAL through clickhouse local for a non-default role chain with INSERT two levels down and a nested admin option, and asserts the review refuses the INSERT and that neither statement shows the admin option (skipped without the binary). The other grant lines match what a 26.3 server prints for those grants (checked with clickhouse local: displaySecretsInShowAndSelect in mixed case, WITH ADMIN OPTION on a role line, and FINAL dropping the role lines and carrying the role's WITH GRANT OPTION). Ran make format lint typecheck, the tracker source, onboarding, public-copy, doc-link and agent-instruction unit tests, and vitest run src/flows/TrackerSourceDialogs.test.tsx.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked the failing cases against the old code and that the allow-list keeps the documented loom_ro grants read-only.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

🤖 Generated with Claude Code

zlareb1 and others added 15 commits November 4, 2026 04:26
review_grants compared upper-cased access types against a deny-list that
held displaySecretsInShowAndSelect in mixed case, and it dropped the part
after TO where WITH GRANT OPTION and WITH ADMIN OPTION appear, so all
three passed as read-only. The check is now an allow-list: SELECT, SHOW
of databases/tables/columns/dictionaries, dictGet and CREATE TEMPORARY
TABLE; any other type, an option to pass a grant on, or a line it cannot
parse is refused. Column lists no longer split on their inner commas.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…p tables

A backtick-quoted column holding `(`, `,` or ` ON ` hid the access types
after it from the check. Quoted names are now blanked out before the line
is split, an unbalanced quote refuses the line, and each type must be a
name with at most one column list. CREATE ARBITRARY TEMPORARY TABLE is no
longer read access. GrantReview.write_types is now refused, since it also
holds grant options and unparsed lines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The probe now also runs SHOW GRANTS FINAL, which merges the grants of the
user's roles into its own, so a role holding INSERT or a grant option is
refused like a direct grant. The direct SHOW GRANTS still names the roles
reported back. A line with more than one ON clause is refused as unparsed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
GrantReview drops its unread raw-lines field, the roles comment no longer
calls them opaque, and a server that refuses SHOW GRANTS FINAL is told
that loom needs it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
An exception is always truthy, so `e or type(e).__name__` never fell back
to the type name; the message now reads str(e). The source-add roles field
description no longer calls roles opaque to the check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
SHOW GRANTS FINAL merges a role chain's access types but drops the role
lines, so an admin option on a role granted to a role reached neither
statement. The probe now reads system.enabled_roles, which lists every role
in the chain with its admin option, and refuses a granted role that is not
a default role, since its chain is not enabled and cannot be seen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The role-name decoder reverses every backslash escape in one pass, and the
refusal for a granted role missing from system.enabled_roles says it is not
among the enabled roles rather than guessing why.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…es its fix

A line such as `GRANT on TO u` split into no types and no roles and was
skipped; it is now refused. A granted role that is not enabled is kept
apart from the refused grants, so the refusal says to run SET DEFAULT ROLE
ALL instead of asking for a SELECT-only user, and a role granted WITH ADMIN
OPTION is named once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The dashboard appended "create a user with SELECT only" to every
CREDENTIAL_NOT_READONLY message, which was wrong for a role that is not a
default role and doubled the server's advice otherwise; the server message
now holds the advice and the dashboard shows it as is. The SET DEFAULT ROLE
and ALTER USER hints quote a user name that is not a plain identifier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Whitespace in a SHOW GRANTS line collapses only outside quoted names, and
\b and \f decode, so such a role matches its system.enabled_roles row. A
clickhouse-local test pins that SHOW GRANTS FINAL carries the access types
of a non-default role chain two levels down while neither statement shows
its nested admin option. The probe tests share one fake server.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…only

GrantReview.roles holds each role's name rather than its SHOW GRANTS
quoting, so the roles field and the refusal messages name a role the same
way. The dashboard no longer asks the registrant to judge the roles, since
the check reads their grants, and the record contract page says a server
that refuses SHOW GRANTS FINAL is refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…hey cover

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
review_roles mutated the review review_grants returned, and each removed
duplicates; review_grants now takes both inputs and returns the finished
review. The roles field comments read as one sentence each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/tracker-grant-review-fail-closed branch from 969184c to 5934c0e Compare November 4, 2026 04:31
@zlareb1
zlareb1 merged commit 17c6946 into main Nov 4, 2026
38 of 40 checks passed
@zlareb1
zlareb1 deleted the fix/tracker-grant-review-fail-closed branch November 4, 2026 09:24
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant