Skip to content

[4.2-dev] Fix SHOW metadata access for table-level grants - #32878

Merged
XuPeng-SH merged 10 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/32855-show-metadata-4.2
Nov 18, 2026
Merged

XuPeng-SH merged 10 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/32855-show-metadata-4.2

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32855. Backports #30304 to 4.2-dev. The original report is #30279.

What this PR does / why we need it:

A user with SELECT on a table can query its rows, yet the database-level SHOW privilege check rejects inspection of its columns and CREATE TABLE definition. This backport binds each SHOW statement to its actual target database and consults object privileges after an ordinary database-level denial. SHOW TABLES uses the same visibility rules so a grant on one table exposes only the permitted names. Subscription publication allowlists and view-definition restrictions still apply.

The release branch needs the execution-time role lookup and identity propagation that main already had when #30304 landed. The new code resolves active and inherited roles against the executing transaction, bounds role traversal, and reuses the result within one physical execution. Prepared SHOW statements refresh the relevant metadata and authorization when executed, including after a revoke or a publication change.

Protocol compatibility. Release protocol 12 corresponds to main's protocol 41 for object-only SHOW TABLES admission and filtering. Release protocol 11 keeps the database-level gate and its existing listing behavior. The mapping is specific to this capability.

Historical SQL validation (original backport head dd7b10f9c4360e486a4008b8fdbc27178718a219). Three SQL regression suites ran on macOS arm64. The privilege suite passed 1,746 checks with 2 ignored, publication/subscription passed 1,693, and dml/show passed 613 with 23 ignored. The issue-specific subsets passed 25/25 and 22/22. Coverage includes exact visible names, table metadata access, revoke/regrant, prepared execution, and publication changes. Four additional plain SHOW TABLES executions through an isolated two-CN proxy returned exactly the 64 expected names after worker labels changed. Statement history recorded success but did not retain physical placement.

Validation limits. Arbitrary in-flight protocol downgrade was not tested. Timing samples did not establish a reliable latency comparison. A separate stress query adding a large generated series encountered a remote execution failure under forced placement. Its behavior on the unmodified release base has not been established.

CI repair validation (08b9738). Completed the Apache 2.0 headers in two added test files identified by SCA run 44226249385, job 134540120015, attempt 1. Newly ran license-eye -c .licenserc.yml header check using CI-pinned v0.4.0: 4,888 valid, zero invalid; the focused two-file check, git diff --check, and formatting checks also passed. Package declarations, imports, and test code are byte-for-byte unchanged from dd7b10f9c4360e486a4008b8fdbc27178718a219; the SQL validation above is reused. No runtime tests were rerun for this comment-only repair; the remaining SCA analyzers will run in the new CI.

SCA error-path repair (8e010d7). Run 44229764080, attempt 1 passed license checks and reported SA5001 in the new role-root query helper; CI Required propagated that failure. The helper now checks the SQL error before deferring cleanup and explicitly closes partial results on failure. Added error cases for account, primary-role grant, and all-role grant queries assert original-error propagation and released result memory. Newly passed on macOS arm64 with CI Go 1.26.4: owning-package build/vet; mo-cgo-test identity matrix, full package normal/race, and identity -race -count=100; compiler tests TestCurrentRolesExecutionCacheScopeAndGeneration and TestShowRolesCompiledCacheGeneration; CI-pinned golangci-lint 2.6.2 with .golangci.yml on ./pkg/sql/colexec/table_function (0 issues); focused license and formatting checks. Native dependencies were built from this release tree. Original SQL evidence is reused; full Linux CI awaits the new push.

Review repair validation (bbd3093). Object-only SHOW fallback now accepts an explicit set of row-local predicate operators; subqueries, function calls and unknown forms are rejected before execution. SHOW TABLES carries its database/object admission into planning: database admission avoids role traversal, object admission cannot select an unfiltered legacy plan, and prepared rebuilds refresh admission against the prepared database. Newly passed with Go 1.26.4/native CGO on macOS arm64: frontend/planner/AST build, vet and owning-package tests; each of four predicate/admission/prepared/rollback tests with -race -count=100; and the authenticated SQL regression TestShowMetadataAdmissionIsolation with -short -tags matrixone_test -race. That regression proves exact visible names, rejected unauthorized predicate reads, database SHOW grants, and prepared execution after revoke. An original-head production-source overlay fails the same regression precisely because the malicious SHOW returns no error. Final protocol-transition edits are covered by the deterministic in-planning downgrade test; unchanged-input public SQL evidence is reused. CI-pinned golangci-lint 2.6.2 reports 0 issues, headers and artifact checks pass. Full BVT and a 4,097-role SQL fixture were not rerun; the typed planner test verifies that database admission installs no role-closure CTE.

SCA test-probe repair (771106f). Run 44266293888, attempt 1 reported rowserrcheck/sqlclosecheck in the new SQL regression. Expected-error SHOW probes now use ExecContext, retaining the exact rejection assertion and the successful-listing Rows checks. Newly passed with Go 1.26.4/native CGO: owning pkg/tests/issues/isolated vet and all configured golangci-lint 2.6.2 checks (0 issues); TestShowMetadataAdmissionIsolation with -short -tags matrixone_test -race -count=1 (20.058s); header and diff checks. The package is test-only, and the regression command compiled its test binary. Production code and earlier review validation are reused unchanged.

Review repair validation (1487d93). SHOW COLUMNS uses the same target database for authorization and planning, and prepared SHOW metadata keeps the database selected at PREPARE. Object-authorized SHOW TABLES reads visibility at the statement authorization snapshot while the user's SI data snapshot stays intact.

Newly passed on macOS arm64 with Go 1.26.4 and native CGO: frontend/planner/AST build, vet and package tests, focused frontend/planner race tests, and the public SQL regression TestShowMetadataAdmissionIsolation with -short -tags matrixone_test -race -count=1 (33.756s). The regression covers RC and SI, database precedence, text and binary PREPARE across USE, and revocation during an open transaction. The tagged test vet, golangci-lint 2.6.2 for the changed diff, and the PR artifact check also passed. Earlier CI evidence applies to 771106ffdbafdab15b88b09dddc0bfab69236771. Linux and multi-CN verification for the repair will run on the new commit.

Object identity regression validation (23dbcfa799d651e289361b20620a92ff4790588f). Object-authorized SHOW COLUMNS and SHOW CREATE TABLE now resolve and read the target in the statement authorization snapshot. Text and binary EXECUTE refresh admission before planning, and the user transaction keeps its data snapshot.

Newly passed on macOS arm64 with Go 1.26.4 and native CGO: frontend, planner and AST build/vet and package tests, tagged vet for the isolated SQL test package, frontend package race, 100 focused race rounds of TestRebuildPreparedShowRefreshesAdmission, and changed-line golangci-lint 2.6.2 (0 issues). TestShowMetadataAdmissionIsolation passed with -short -tags matrixone_test -race -count=1 in RC and SI, including direct and prepared metadata for the replacement object and an independent SI data read. The same final test fails on an overlay of the reviewed production files because it observes the old object. Linux CI will run on this commit.

Pipeline cancellation validation (8e9a5a47468411168bbe496ffb7015764ffb24c1). The execution owner classifies cancellation before cleanup. Merge and vector aggregation preserve the terminal result and release blocked siblings and shared role loaders with the originating failure. A graceful local stop still leaves the shared execution cache usable.

Newly passed on macOS arm64 with Go 1.26.4 and native CGO. The mo-cgo-test normal suites passed for compile, table functions and pipeline, and full race suites passed for compile and table functions. Five focused race tests each passed 100 rounds, covering independent child cancellation, graceful stop, vector branch lifecycle, retry generations and shared cache retirement. The original head reproduces the missing parent cancellation with the same race regression. Build, vet, changed-line golangci-lint 2.6.2 and the artifact check passed. The test runner used the OS temporary directory because the local file service filters the hidden ancestor in the default Loom temp path. Linux CI will run on this commit.

Conflict resolution and validation (250e9da34224f8e76dd1cae4777d80cfe5c16e98). Rebased onto official 4.2-dev at f4dc8554a3bd4f92d1e009cb2dcb2bd227036861. The scope uses the release branch's pre-cleanup cancellation classification and diagnostics. Merge and vector aggregation retain the terminal error and release blocked role loaders. MORPC 11 remains the immediate predecessor of this PR's protocol 12.

Newly passed on Darwin/arm64 with Go 1.26.4 and native CGo. Build, vet, and normal and race suites passed for compile, table functions, and pipeline. Nine focused compiler tests each passed 100 race repetitions, covering independent child errors, local stop, serial and parallel reader failures, and retry and registration boundaries. The authenticated TestShowMetadataAdmissionIsolation passed in RC and SI under race. The PR artifact check passed. The prior head's Linux run completed successfully on attempt 2. Linux verification of this rebase will run on the new head. Prior Linux CI

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 8e010d79ec2e098b11a741051b10347ba84cf52e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

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.

mo-bot review · mo-bot-local · review

Commit: 8e010d79ec2e098b11a741051b10347ba84cf52e

Assessment: request_changes

The backport fixes ordinary table-only SHOW access and refreshes prepared subscription metadata. It reuses the upstream visibility rules, but the new admission path lets user-supplied SHOW predicates bypass table authorization. SHOW TABLES also needs to carry its admission decision into planning and preserve access for users already authorized at database scope.

Model: gpt-6.2-sol / xhigh

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

  • P1 pkg/frontend/authenticate.go:8689: A user with only a table-level grant runs SHOW TABLES or SHOW COLUMNS with a WHERE predicate that reads another table through a subquery.
    Impact: The new fallback admits the SHOW, and the presence or absence of returned metadata rows can disclose information from a table the user cannot query directly.
    Evidence: The parser accepts a general WHERE expression. pkg/sql/plan/build_show.go:1144 attaches it to the generated SELECT, and pkg/sql/plan/query_builder.go:6806 binds its subqueries. The plan authorization check at pkg/frontend/authenticate.go:9105 returns early because SHOW is database-scoped. The backport makes this gap reachable by table-only users. Authorize reads introduced by the user's predicate separately from the generated catalog reads, or reject predicates that introduce such reads.

  • P2 pkg/sql/plan/build_show.go:340: An operator lowers the advertised protocol on the same CN after object-only SHOW TABLES admission and before that statement is planned.
    Impact: The statement can use the protocol 11 listing without satisfying the protocol 11 database privilege gate, exposing names of ungranted sibling tables.
    Evidence: Frontend admission reads the mutable protocol at pkg/frontend/show_metadata_privilege.go:88, and planning reads it again to decide whether to add the visibility filter. The existing query service can update that runtime value in place. Carry the admission decision into planning and fail closed if an object-admitted statement cannot use the filtered plan.

  • P2 pkg/sql/colexec/table_function/current_roles.go:165: A user already authorized by a database-level SHOW grant runs a local SHOW TABLES with more than 4,096 active or inherited roles.
    Impact: A listing that succeeds on the released branch fails with a role-closure limit error, even when the primary role alone grants access to the whole database.
    Evidence: The existing database privilege checker can return as soon as the primary role grants access at pkg/frontend/authenticate.go:8257. The new planner still installs the visibility CTE for every eligible local listing, which forces complete role traversal and raises the new limit error. Preserve the database-authorized route while retaining bounded role resolution for object-only visibility.

Validation:

  • Verified the frozen head, merge base, clean checkout, and 52-file delta. Compared the upstream fix and the released v4.2.8 and hotfix source. Recorded all three discussion entries.

  • Isolation preflight and the native prerequisite build passed. Focused tests passed across frontend, planner, compiler, table functions, process and pipeline codecs, and sysview. Additional retry, compiler-pool reuse, and subscription-view checks passed. Commands, exits, source fingerprints, and log hashes are recorded in validation-reconciliation.json.

  • The frozen CI snapshot records successful shared build, unit, static-analysis, and multi-CN BVT checks.

Limitations:

  • The findings are based on source tracing. The local runs exercised the committed regression tests and lifecycle controls. Release-binary upgrade, full BVT, and repeated race runs were not independently repeated.

@XuPeng-SH

XuPeng-SH commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 8e9a5a47468411168bbe496ffb7015764ffb24c1

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

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.

mo-bot review · mo-bot-local · review

Commit: 8e9a5a47468411168bbe496ffb7015764ffb24c1

Assessment: approve

The backport binds SHOW admission and metadata reads to the same authorized target and statement snapshot. Prepared execution refreshes admission while preserving the user's transaction snapshot. The final repair preserves terminal pipeline errors through cleanup and unblocks sibling pipelines and shared role loaders. The prior findings are resolved on this head.

Model: gpt-6.2-sol / xhigh

Session: 01a1eecd-3287-70c0-bb93-ab923faf5f3f · slot 0 · generation 2

Validation:

  • Passed 36 focused race tests across five packages, the full short table-function race suite, and the authenticated MySQL regression in both RC and SI.

  • The short compiler race suite reported three Parquet fanout failures. All three reproduced with the same assertion failures on the pinned merge base under the same test configuration.

  • Verified the clean frozen source, native input provenance, additive pipeline descriptor change, and protocol 11 release and hotfix boundary. Reconciled logs and receipts in validation-reconciliation.json and accounted for all 15 discussion entries.

Limitations:

  • Release-binary upgrades, forced-placement multi-CN SQL, and latency were not independently measured.

@mergify mergify Bot added the queued label Nov 18, 2026
@mergify

mergify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

❌ Left the queue · Matrixone CI execution / UT Test on Ubuntu/x86 fails with this pull request

1 h 13 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 18 Nov, 19:46 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ❌ Checks failed · in place
  • 🚫 Left the queue 20:59 · e3dddfb

The failure is in this pull request. It failed tested alone on top of 4.2-dev.

Reason

The merge conditions cannot be satisfied due to failing checks

  • CI Required

Failing checks:

To get back in the queue

  • Push a fix: the pull request is queued again once its queue conditions match.
  • If the failure is a flake, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

iamlinjunhong and others added 9 commits November 19, 2026 06:16
Backport the SHOW metadata behavior from matrixorigin#30304 onto the release branch.
Bind the selected database, evaluate current object grants at execution
time, and preserve publication allowlists and view definition privileges.

Use release protocol 12 for object-only SHOW TABLES admission and row
filtering. Protocol 11 retains its database-level admission and listing.
Propagate the active role identity and transaction context and bound role
closure loads per physical execution, including retry and cancellation.

Refs matrixorigin#32855.
@XuPeng-SH

XuPeng-SH commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: e30e171b280d3616918e880dbc21f0c714b0c3f4

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

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.

mo-bot review · mo-bot-local · review

Commit: e30e171b280d3616918e880dbc21f0c714b0c3f4

Assessment: approve

The backport binds SHOW authorization and metadata reads to the same target and statement snapshot. Prepared execution refreshes authorization while preserving the user’s transaction snapshot. The latest change classifies recovered pipeline errors before cleanup, preserving terminal failures and allowing graceful local stops.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • Verified the frozen diff, native build inputs, isolation preflight, and additive pipeline descriptor change. Confirmed protocol 11 on v4.2.8 and the cited hotfix revisions, and protocol 12 on the candidate.

  • Focused race checks passed, including authenticated SHOW in read committed and snapshot isolation. Three cancellation checks each passed 100 race repetitions, including the recovered-reader probe.

  • The full table-function race suite and the pipeline and sysview package tests passed.

  • Reconciled all 18 discussion entries and recorded the receipts and logs in validation-reconciliation.json.

Limitations:

  • The full compiler race suite failed three Parquet planning assertions. The same assertions failed on the earlier release base, and the affected test files and planning implementation match across the rebase.

  • The frozen evidence contains no terminal CI result for this head. Release-binary upgrades, forced multi-CN SQL placement, and latency were not independently measured.

@XuPeng-SH

Copy link
Copy Markdown
Contributor

Independent QA challenge validation

Validated the current head e30e171b280d3616918e880dbc21f0c714b0c3f4 against base f4dc8554a3bd4f92d1e009cb2dcb2bd227036861 on Darwin/arm64 with fresh standalone instances and newly built binaries (Go 1.26.4).

Scope: custom black-box SQL probes, custom white-box probes, base/head differential checks, concurrent GRANT/REVOKE, and focused latency measurements. No existing unit tests or BVT suites were run.

Result

No reproducible privilege escalation, denied-object metadata leak, stale prepared authorization, or cancellation/cache lifecycle failure was observed in the covered cases. The main item worth follow-up is the cost of deep role-inheritance chains.

1. Base/head correctness differential

Using a three-level inherited role chain r1 -> r2 -> r3, with table-level SELECT granted to r3:

Operation Base Head
SELECT from the granted table succeeds succeeds
SHOW COLUMNS on the granted table 20101 returns the correct columns
SHOW CREATE TABLE on the granted table 20101 returns the correct DDL
SHOW TABLES 20101 returns only authorized names

This confirms that the custom witness fails on the base and exercises the intended fix on the head.

Negative and boundary checks on the head also passed:

  • SHOW COLUMNS and SHOW CREATE TABLE on an ungranted table remain denied.
  • SHOW TABLES ... LIKE 'denied' returns no row and does not leak the denied name.
  • Explicit FROM db uses the actual target database even when the session default database differs.
  • Unqualified metadata lookup does not fall back to another database that happens to be authorized.
  • Object-only permission on a view does not bypass the view-definition restriction on SHOW CREATE VIEW.
  • Closing a role cycle is rejected with 4027, rather than hanging or overflowing role traversal.

2. Prepared execution and concurrent authorization changes

A persistent prepared SHOW TABLES reflected every authorization change at execution time:

  1. Initially returned only allowed.
  2. After revoking the inherited grant, access was denied.
  3. After granting a different table through another inherited role, only that newly authorized name appeared.
  4. After restoring the original grant, both authorized names appeared.

A concurrent probe then ran 400 direct/prepared SHOW statements across four connections while another session performed 200 GRANT/REVOKE transitions. Outcomes were 354 visible and 46 ordinary privilege denials, with zero unexpected errors, cache-key errors, or hangs.

3. Custom white-box and unhappy-path probes

Only newly added TestPR32878QA* probes were selected; the package completed successfully in 0.923s. They covered:

  • role-graph deduplication and cycles;
  • the 4096-role boundary and fail-closed rejection at 4097;
  • cancellation before catalog expansion;
  • 32 concurrent consumers collapsing to one loader;
  • independent waiter cancellation without affecting the loader;
  • close unblocking loader/waiters while preserving the originating error;
  • panic-to-error conversion and sticky loader failure;
  • rejection when the transaction identity/read-view cache key changes.

4. Measured scalability risk: serial role-closure depth

Focused local medians (50 iterations for depth 3, 20 for depth 64):

Head case Median P95
depth-3 SHOW COLUMNS 7.595 ms 14.041 ms
depth-64 SHOW COLUMNS 115.468 ms 567.886 ms
depth-3 SHOW TABLES 27.692 ms 84.795 ms
depth-64 SHOW TABLES 221.083 ms 324.166 ms
depth-64 prepared SHOW TABLES 214.216 ms 407.302 ms
ordinary SELECT control about 0.11 ms about 0.17 ms

The shared admin-path median did not regress in the corresponding comparison: base SHOW COLUMNS was 1.916 ms (100 iterations), versus head 1.845 ms (50 iterations).

The scalability result is consistent with the implementation: currentRoleClosure expands one graph level at a time and waits for each catalog query before starting the next level (current_roles.go:111-128, 153-178). Deep chains therefore serialize many catalog reads; the current 4096-role fail-safe bounds work but does not bound latency tightly. This is a performance risk, not a correctness failure, and is most relevant to deployments with deep role inheritance. A cheap first-query visibility precheck or a less depth-serial closure lookup may be worth considering if that shape is supported operationally.

5. Compatibility item to confirm (source-only)

For protocol 11, MetadataVisibilityCTE / SubscriptionMetadataVisibilitySQL include only the current role and its directly granted roles (show_metadata.go:26-29, 64-70), whereas protocol 12 uses the full closure. A privilege attached at inheritance depth >= 3 may therefore still be invisible to the compatibility-mode metadata policy. I did not dynamically exercise protocol 11; if one-level inheritance is the explicit compatibility contract, this is expected rather than a defect.

Publication allowlisting was traced statically but was not dynamically exercised in this round. Remote RPC/retry, multi-CN cancellation, and vector-aggregation paths are also outside the executed coverage; no claim is made that those paths were dynamically validated.

This branch was successfully deployed

No deployments
ci — 75104d80 Deployed Nov 18, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants