Skip to content

Fix: Unify SQL server file access authority - #30212

Merged
XuPeng-SH merged 19 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-30185-sql-file-access
Oct 16, 2026
Merged

XuPeng-SH merged 19 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/fix-30185-sql-file-access

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 14, 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 #30185

What this PR does / why we need it:

Enforce SQL file access at resource acquisition using the current account and
role. Local paths, configured services and dynamic disk providers require
sys/moadmin; remote dynamic providers use explicit caller credentials or the
existing explicitly selected MinIO anonymous mode. Missing acquisition policy,
server-local auxiliary files and ambient credential discovery are rejected.
Provider parsing, backend selection and construction share the same owner.

Async indexed Datalinks accept remote sources only. CREATE/rebuild and eligible
final DML values are checked before installation/commit. Modern UPDATE checks
assigned or recomputed sources, retaining conservative checks for repeated
writable aliases. Local documents can be materialized by foreground load_text
into TEXT before indexing; existing local-Datalink async indexes require
migration/rebuild. Remote-source invalidation retains existing CDC retry behavior.

Fulltext2/HNSW/GPU artifact owners read their own files and persist immutable
binary values through one bounded inserter and the existing transaction. SQL
DEFAULT/source/view/metadata expressions retain caller identity. Disk formats,
64 KiB chunks and row limits are preserved; pending parameters additionally stop
at 8 MiB including IDs, which is not a process-memory bound. Superseded SQL file
INSERT generators and SQL-wide elevation are removed.

This follow-up rebases onto main 8669eedae682f7aea093c6cab3d1b8877f91a8dc,
centralizes the duplicated owned-reader/service close logic in fileservice, and
clarifies current versus historical evidence. Reader close precedes owned-service
close even on failure; concurrent/repeated Close shares the same result. Borrowed
services stay with their registry. It adds no normal-DML policy work, worker,
cache, wire field or CI configuration change.

Compatibility and rollout

Update all SQL-serving CNs; older CNs do not enforce this contract. Tenant local
stages/server INFILE/external paths are intentionally refused; remote tenant
stages and client LOCAL/INLINE input remain supported. Backup now requires
sys/moadmin. Generic ETL Go callers must bind operation policy;
StatementOption.Params() now returns (vector, error). Removed context-free
reader helpers and the MO_NO_DEFAULT_CREDENTIALS switch require downstream
adaptation. OUTFILE's disable switch remains an additional control.

Validation and remaining gate

On Darwin arm64 / Go 1.27.1, on the tested base 97415db10bd, focused helper/consumer and rebased parser/planner
normal tests pass; all five selected packages pass one race run (51 named tests).
The full Datalink owning package also passes normal. Six affected packages pass
fresh vet, molint and configured incremental lint; formatting/err-check/diff
checks pass. Unchanged earlier 23-package checks, real SQL/CDC/two-CN/BVT and
artifact evidence retain their tested revisions. Initial compile/fixture failures
and the Darwin fileservice sync-dir baseline failure remain documented; this
is not a fresh green full-suite claim. The final base adds only window spill-error normalization; unchanged contract evidence is reused with its original revision. Actual gpt-6.1-sol/xhigh design and final
review evidence is recorded in the linked provenance document.

Whole-PR/main performance acceptance remains unresolved and blocks merge.
The latest elapsed −2.13% and CPU −5.14% compare old/new complete validation
within one candidate binary. Component allocation reductions and that comparison
do not establish whole-PR speedup or zero regression. Historical failed cells,
ordinary UPDATE P99 +6.34% and artifact-transport allocation costs remain in the
versioned record. The explicit existing exception permits PR update with this
performance gate unresolved; it does not permit merge acceptance.

GPU CAGRA/IVF-PQ native validation remains unverified under the accepted exception
for PR update. Local CPU fixtures do not establish live cloud/HDFS or ONNX native
coverage. Remote CI is separate; pending checks are not claimed passed.

Design
· Actual design/review provenance
· Validation, failed samples and limits
· Ordinary SQL data
· Datalink SQL data

@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 →

@XuPeng-SH

XuPeng-SH commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 1bcd5a12e63c8cf05a8e81fb61f0034f94167ba1

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 1bcd5a12e63c8cf05a8e81fb61f0034f94167ba1

Assessment: request_changes

Reviewed all 38 changed files and affected callers. Centralized authorization and resource cleanup are reasonable, but compaction grants system authority to caller-controlled expressions, leaving a confirmed authorization bypass.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

  • P1 pkg/sql/colexec/table_function/fulltext2_compact.go:120: A tenant supplies a metadata view to fulltext2_compact whose index_id expression calls save_file using a path stored in a table.
    Impact: WithSystemFileAccess grants sys/moadmin authority to metadata queries as well as generated storage writes. The tenant's view can therefore write server-side files despite direct execution being denied. The file survives a subsequent compaction error. Keep metadata queries under caller identity and confine elevated access to validated, generated spill-file operations.
    Evidence: TestReviewCompactionFileAuthority reproduced this through the real SQL frontend: direct SELECT was denied, but compaction wrote 'unauthorized-write' before failing on missing checksum metadata. Removing only this authority grant in a diagnostic overlay caused denial with no file created. Retained attempt-2/embed-auth.log and embed-control.log match receipts 1791988612307877197-2.json (exit 1) and 1791988685839650688-2.json (exit 0).

Validation:

  • Verified frozen HEAD, unchanged source, identical attempt patches, and 192 native-input plus 46 artifact hashes. Command/source/exit receipts and retained logs are reconciled in attempt-2/receipt-audit.json.

  • Reused the completed attempt-1 focused run across seven packages. Both supplied embedded SQL authorization and tenant CDC/compaction/HNSW tests passed alongside the failing diagnostic.

  • Nine CPU owning packages passed. The combined command exited 1 solely because GPU-only CAGRA/IVFPQ packages exclude all files in CPU mode.

  • Focused lifecycle race tests passed across four packages; cancellation passed 100 race-enabled repetitions. Targeted frontend and compile consumer tests also passed.

  • Source review found bounded identity-copying and session-locking costs on ordinary SQL paths, without added file I/O. No throughput benchmark or quantified performance claim.

Limitations:

  • GPU execution, ONNX runtime, and mixed-version/multi-CN runtime behavior were not validated; the ONNX test skipped.

  • Full frontend/compile package suites and full-package race coverage remain unexecuted. Frozen substantive CI checks were pending; local_validation contained no retained author gates.

  • Linked issue #30185 contents were absent from the supplied evidence.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

mo-bot work · mo-bot-local · reviewing

Commit: 1bcd5a12e63c8cf05a8e81fb61f0034f94167ba1

Review in progress.

@LeftHandCold LeftHandCold changed the title [Bug]: Restrict SQL file access to authorized sessions Fix: Restrict SQL file access to authorized sessions Oct 14, 2026
@XuPeng-SH XuPeng-SH changed the title Fix: Restrict SQL file access to authorized sessions Fix: Unify SQL server file access authority Oct 14, 2026
@XuPeng-SH

XuPeng-SH commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: ef9621dea32e8942fb328d965df167c29f757dfd

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: ef9621dea32e8942fb328d965df167c29f757dfd

Assessment: request_changes

Reviewed the complete 81-file delta and surrounding callers. Centralizing authorization in process and provider classification in fileservice is sound, but two reachable paths violate the intended server-file boundary. Both failures were reproduced through SQL and isolated with diagnostic controls.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P1 pkg/sql/colexec/table_function/fulltext2_compact.go:120: An ordinary tenant supplies a metadata view whose index_id expression calls save_file using a path stored in its own table, then invokes fulltext2_compact with that view.
    Impact: WithSystemFileAccess elevates metadata evaluation as well as generated spill statements. The tenant can create a CN-local file even though directly querying the view is denied. Restrict elevation to generated storage statements and preserve caller authority for metadata queries.
    Evidence: Exact-head TestReviewCompactionFileAuthority created the file containing 'unauthorized-write'; compaction subsequently failed on the missing checksum column, leaving the file intact. attempt-1/authority-embed.log and checks/1791996688911392415-2.json retain the failure. Removing the broad grant in a diagnostic overlay prevented creation.

  • P1 pkg/frontend/table_dump.go:144: An ordinary tenant executes DUMP TABLE using '/unused,remote:x/../dump' instead of the denied canonical local path '/dump'.
    Impact: Authorization interprets the spelling as an argumented remote service, while openLocalTableDump cleans and opens it as a local path. The new guard therefore permits unauthorized directory and manifest creation. Require local-file authority for this non-stage branch; DUMP and LOAD share the helper and both need regression coverage.
    Evidence: TestReviewDumpLocalPathAuthority confirmed that the canonical path was denied without side effects, but the alternate spelling succeeded and created manifest.json. attempt-2/dump-check.log and checks/1791996889508400165-5.json retain the failure. A diagnostic control enforcing local authority prevented creation.

Validation:

  • Verified the frozen head, clean source, complete patch, 192 matching native inputs and 46 retained native artifacts. Reconciled commands, source fingerprints, exit receipts, logs and overlays in attempt-2/review-evidence.json.

  • Reused completed exact-head execution from attempt 1: TestSQLFileAccessAuthorization and TestSQLFileAccessTenantStageCDC passed; the compaction diagnostic failed.

  • 32 targeted tests passed across 12 packages, covering authorization, provider selection, role changes, process serialization, stage operations, plugin reset and writer failure/cancellation. Receipts: 1791997248439156757-2.json and 1791997276448055560-2.json.

  • Both diagnostic controls passed; receipt 1791996967288589163-4.json matches control-check.log. Controls are diagnostic overlays, not complete proposed fixes. Source remained unchanged.

  • Final evidence audit passed: checks/1791997368545612231-2.json and final-audit.log under /home/xupeng/.local/state/mo-bot/jobs/94a4075ec47508b4da29aceb/attempt-2.

Limitations:

  • The ONNX test skipped because its runtime library was unavailable. GPU, fresh race, multi-CN, complete Go-suite and Java BVT execution were not verified.

  • Parsed-path reuse should reduce repeated parsing; ordinary SQL adds bounded identity refresh work. Author benchmark claims lacked matching retained logs, so no independent performance improvement is claimed.

  • The linked issue body was absent from frozen evidence; requirements were assessed from the supplied PR, design document and discussion.

Replace statement-wide file grants with bounded binary parameters under
caller identity, shared provider admission before pattern expansion, and
complete SQL file acquisition guards. Repair owning fixtures and cleanup.

Fixes matrixorigin#30185
Rebase onto main 8795f36 and remove the obsolete test API adaptation. Preserve original assertions and revision-qualified validation and performance evidence.
@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 35c10604218b5fc8f575946a87eb3ba6085f4b63

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 35c10604218b5fc8f575946a87eb3ba6085f4b63

Assessment: request_changes

Centralized acquisition policy, shared resolution and owner-managed artifact persistence are coherent designs. Approval remains blocked by the explicitly unresolved whole-PR performance validation requirement. This is an evidence blocker, not a demonstrated current-head regression; exhaustive implementation acceptance remains incomplete.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

  • P2 pkg/sql/plan/async_datalink.go:110: INSERT or source-column UPDATE of asynchronous indexed Datalinks invokes the added per-row admission path, including the declared concurrent 4096-row, one/16-stage workloads.
    Impact: Validation requirement: close the declared whole-candidate/base timing gate before approval. Supply controlled paired measurements covering indexed/unindexed INSERT, source/status UPDATE and ordinary SQL controls, with matched inputs, commands, terminal logs and all samples. Resolve failed budgets or obtain explicit policy-owner acceptance covering merge readiness.
    Evidence: The current docs/design/sql-file-access-validation.md:20-22 explicitly says whole-PR/main performance remains unresolved and blocks merge. The latest amendment in sql-file-access-review.md:229-234 preserves that blocker and limits the exception to PR updates. The reported -2.13% elapsed improvement compares validators within one candidate binary, not the whole PR against main. Nine historical CSV cells retain failed timing gates; component gains and functional tests do not close this requirement.

Validation:

  • Verified frozen HEAD/base, clean source, the complete 174-file patch and whitespace checks. Recomputed all 16 historical Datalink CSV medians and pair counts; this verifies arithmetic, not benchmark execution.

  • Traced current INSERT/UPDATE eligibility through the barrier filter, scalar validator and shared Datalink/provider resolver; inspected the latest shared reader-ownership amendment.

  • Audit passed: checks/1792160911593681560-4.json, exit 0, matched to review-audit.log. Reports and artifact hashes are retained in /home/xupeng/.local/state/mo-bot/jobs/d50b1ea7f5143679cec5a1a7/attempt-1/review-evidence-manifest.json.

Limitations:

  • The material validation blocker stops acceptance before exhaustive review of the remaining production, test, BVT, native and compatibility closures.

  • No product tests or benchmarks were run. local_validation is empty; historical raw performance receipts were not recovered. Substantive frozen-head CI was pending and is not counted as passing.

  • The linked issue body was not supplied. GPU validation remains an explicitly recorded exception and is not grounds for this finding.

This branch had an error being deployed

1 failed deployment
ci — a6edfbaf Deployed Oct 16, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change kind/bug Something isn't working kind/documentation Improvements or additions to documentation kind/enhancement kind/refactor Code refactor size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Review access controls for SQL file operations

6 participants