Repository navigation
fix: support GRANT/REVOKE on VIEW with DEFINER/INVOKER security type - #24195
20 commits merged into
Conversation
1. Fix view access bypass via base table ALL/OWNERSHIP: convert predefined TableAll/TableOwnership entries from bare General entries to Compound entries carrying originViews/directView, so they go through view-chain privilege verification. 2. Fix CREATE SQL SECURITY VIEW ignoring explicit security type: add SecurityType field to tree.CreateView, pass it from parser, and override session variable in plan layer when DDL explicitly specifies it. 3. Fix SHOW CREATE VIEW / ALTER VIEW not preserving security type: splice SecurityType into SHOW output when missing from Stmt; ALTER VIEW now inherits old view's SecurityType when not explicitly specified. 4. Fix DEFINER path not expanding role inheritance: add verifyPrivilegeWithRoleInheritance() to BFS-traverse mo_role_grant when the effective role differs from the session role. 5. Update BVT expected results for changed error message wording.
…behavior SHOW CREATE VIEW should only replay the stored Stmt text as-is, not auto-inject SQL SECURITY. This matches MySQL behavior where SHOW CREATE VIEW only shows SQL SECURITY if the original DDL explicitly included it. Remove findViewKeyword() and the splice logic from buildShowCreateView(). Update BVT tests to use explicit DDL syntax (CREATE SQL SECURITY INVOKER VIEW) instead of session variable for SecurityType verification. Revert the 34 result file changes from the previous commit.
2dfbb9c to
a61614e
Compare
…MySQL compat 1. GRANT ON VIEW with wildcard levels (db.*, *.*, *) now filters WGO check by obj_type (table vs view), preventing table-level WGO from being used to issue view wildcard grants. 2. Restore SHOW CREATE VIEW SQL SECURITY splice logic to match MySQL behavior: MySQL always shows SQL SECURITY in SHOW CREATE VIEW output. Use findViewKeyword() with whitespace boundary matching. Update 34 result files for SQL SECURITY DEFINER in output. 3. Add SHOW CREATE VIEW test for session-variable-created INVOKER view (v_invoker) to cover the implicit SecurityType path.
|
我这边再顺着兼容逻辑对了一遍,发现一个会影响升级场景的问题: 具体看下来:
这样在升级后的集群里,如果某个 view 的旧授权记录还是
这会让“兼容旧授权读路径”与“新语法 revoke 写路径”不一致。这里看起来需要在 VIEW revoke 时把 legacy table-typed row 一起删掉,或者先做一次迁移/归一化;否则 upgrade case 下 revoke 实际上不生效。建议补一个回归:先种一条 legacy |
|
我再补一个更直接的 blocker:现在新的 view 执行期校验其实只会在 代码链路大概是这样:
这对普通 create view v_const as select 1;
grant select on view db.v_const to r;这里 plan 里没有任何 也就是说,这个 PR 现在实际保护到的是“通过 view 去访问基表”的场景,但对 constant/expression-only view 直接漏检了。这里看起来至少需要在“statement 来自 view、但没有抽到 base-object tips”时,补一条针对 |
|
我这边还看到一个 现在两条路径不一致:
这样如果用户当前 这个和 direct path 的 current-db 语义是冲突的。这里看起来应该把 |
# Conflicts: # pkg/frontend/authenticate.go # pkg/pb/plan/plan.pb.go # pkg/sql/parsers/dialect/mysql/mysql_sql.go
What type of PR is this?
Which issue(s) this PR fixes:
issue #24187
What this PR does / why we need it:
Support view-level privilege control with
GRANT/REVOKE ON VIEWsyntax, including:objectTypeViewto distinguish view privileges from table privilegesDEFINERandINVOKERsecurity types for views viaview_security_typesession variableviewChain,directView) in plan nodes for privilege checking at execution timeSecurityTypein view metadata (ViewData)