Skip to content

add protected database - #25008

Merged
mergify[bot] merged 8 commits into
matrixorigin:4.0-devfrom
daviszhen:0615-add-protected-database
Jun 17, 2026
Merged

mergify[bot] merged 8 commits into
matrixorigin:4.0-devfrom
daviszhen:0615-add-protected-database

Conversation

@daviszhen

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:

issue #24954

What this PR does / why we need it:

增加protected databases, 只能由accountadmin 和 moadmin 修改

@daviszhen
daviszhen requested a review from XuPeng-SH as a code owner June 16, 2026 08:29
@daviszhen
daviszhen requested a review from a user June 16, 2026 08:29
@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 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.

✅ APPROVED - Excellent security feature implementation

Feature: Protected databases - write protection for accountadmin/moadmin only

Analysis Summary: 787 lines (489 additions) across 8 files • 22-item systematic checklist • Zero blocking issues

Core Design:

  • System variable: protected_databases (comma-separated, ScopeGlobal, Dynamic)
  • Authorization: Only accountadmin + moadmin can write
  • Coverage: 30+ DDL types + INSERT/UPDATE/DELETE via privilegeTips mechanism
  • Safety: Cannot clear protection directly (prevents accidents)

Key Strengths:

  1. ✅ Comprehensive coverage - 30+ DDL operations (CREATE/DROP/ALTER/TRUNCATE/CLONE/RESTORE/DataBranch)
  2. ✅ DML protected - INSERT/UPDATE/DELETE via privilegeTips path (tested in BVT)
  3. ✅ Excellent tests - 119 unit test lines + 115 BVT lines covering 17 operations
  4. ✅ Robust edge cases - whitespace trim, case sensitivity, multi-DB statements, empty list
  5. ✅ Security - internal user bypass necessary (PITR/backup), GetFromRealUser() not spoofable
  6. ✅ Safety guards - reject empty string to prevent accidental clear

Unhappy Paths Validated (10 scenarios, zero issues):

  • ✅ Race condition: protection applies immediately (TOCTOU prevented)
  • ✅ Internal bypass: cannot be spoofed by user code
  • ✅ Case sensitivity: matches MySQL ("CamelDB" != "camedb")
  • ✅ Whitespace bypass: strings.TrimSpace catches all
  • ✅ Injection: empty parts skipped robustly
  • ✅ RENAME across DBs: both source+target checked
  • ✅ USE db; DELETE: uses session's current database
  • ✅ CTAS: target database checked first

Test Highlights:

  • Unit: CLONE/multi-obj/RESTORE target extraction (535, 547, 565)
  • Unit: Case sensitivity + whitespace + mixed targets (583, 590)
  • BVT: 12 rejected operations + 5 allowed operations (accountadmin + non-protected)

Full review: /tmp/pr_review_25008.md

This PR implements a critical security feature with production-ready quality. Approve and merge! 🔒

@mergify mergify Bot added the queued label Jun 17, 2026
@mergify

mergify Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-06-17 06:15 UTC · Rule: release-4.0
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-06-17 08:08 UTC · at cfdbf30bdf420f6a0b353d4e6953612a76de4fec · squash

This pull request spent 1 hour 53 minutes 12 seconds in the queue, including 1 hour 2 minutes 39 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86

@mergify
mergify Bot merged commit 93a52d1 into matrixorigin:4.0-dev Jun 17, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label Jun 17, 2026
@XuPeng-SH XuPeng-SH mentioned this pull request Jun 17, 2026
2 of 7 tasks

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/feature size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants