25 lines
1.3 KiB
SQL
25 lines
1.3 KiB
SQL
-- 报告推送队列:**分公司隔离**(2026-10-24 核查项 6)
|
||
--
|
||
-- 背景:`public.main_system_report_push_queue` 建表时没有 RLS,而租户角色 `canteen_app_rls`
|
||
-- 默认拿到 INSERT/SELECT/UPDATE/DELETE ⇒ 租户连接理论上能读写**其它分公司**的队列行。
|
||
-- 队列本身不含敏感业务数据,但按本项目"schema 级隔离"纪律应当收口。
|
||
--
|
||
-- 口径:
|
||
-- · 有租户上下文(`app.branch_code` 非空)⇒ 只能看/改自己分公司的行;
|
||
-- · 无租户上下文(调度器 / 运维 / 主系统对账)⇒ 放行(否则 worker 跨分公司处理会被拦死);
|
||
-- · 用 FORCE 让表 owner 也受限(本项目核心表同款作风),策略里对空上下文开白。
|
||
|
||
ALTER TABLE public.main_system_report_push_queue ENABLE ROW LEVEL SECURITY;
|
||
ALTER TABLE public.main_system_report_push_queue FORCE ROW LEVEL SECURITY;
|
||
|
||
DROP POLICY IF EXISTS report_push_queue_branch_isolation ON public.main_system_report_push_queue;
|
||
CREATE POLICY report_push_queue_branch_isolation ON public.main_system_report_push_queue
|
||
USING (
|
||
COALESCE(current_setting('app.branch_code', true), '') = ''
|
||
OR branch_code = current_setting('app.branch_code', true)
|
||
)
|
||
WITH CHECK (
|
||
COALESCE(current_setting('app.branch_code', true), '') = ''
|
||
OR branch_code = current_setting('app.branch_code', true)
|
||
);
|