问题描述
Oracle 租户下,USER2 没有存过的权限但是可以执行 USER1 下的存储过程。
问题复现测试案例如下。
创建用户。
obclient > create user user1 identified by 123; Query OK, 0 rows affected (0.033 sec)obclient > create user user2 identified by 123; Query OK, 0 rows affected (0.030 sec)授予用户系统权限。
obclient > grant all privileges to user1; Query OK, 0 rows affected (0.035 sec)obclient > grant create session to user2; Query OK, 0 rows affected (0.036 sec)用户 USER1 创建表和存储过程。
obclient > create table loghistory (userid VARCHAR2(20), logdate DATE DEFAULT SYSDATE);obclient > CREATE OR REPLACE PROCEDURE userlogin IS BEGIN INSERT INTO loghistory (userid) VALUES (USER); commit; END; /用户 USER1 使用 call 和 begin 执行存储过程正常执行。
obclient [USER1]> select * from loghistory; Empty set (0.004 sec)obclient [USER1]> call user1.userlogin(); Query OK, 0 rows affected (0.013 sec)obclient [USER1]> begin user1.userlogin(); end; / Query OK, 1 row affected (0.024 sec)USER1 查询数据。
obclient [USER1]> select * from loghistory;输出结果如下。
+--------+---------------------+ | USERID | LOGDATE | +--------+---------------------+ | USER1 | 2023-07-27 14:59:10 | | USER1 | 2023-07-27 14:59:17 | +--------+---------------------+ 2 rows in set (0.002 sec)用户 USER2 使用 call 执行失败,begin 执行成功。
obclient [USER2]> call user1.userlogin(); ORA-00942: table or view does not existobclient [USER2]> begin user1.userlogin(); end; / Query OK, 1 row affected (0.029 sec)USER1 查询数据。
obclient [USER1]> select * from loghistory;输出结果如下。
+--------+---------------------+ | USERID | LOGDATE | +--------+---------------------+ | USER1 | 2023-07-27 14:59:10 | | USER1 | 2023-07-27 14:59:17 | | USER2 | 2023-07-27 14:59:45 | +--------+---------------------+ 3 rows in set (0.002 sec)
适用版本
OceanBase 数据库 V2.x、V3.x 版本。
问题原因
OceanBase 数据库 BUG。存储过程中所有语句都需要进行权限检查,嵌套存储过程通过 inner call 的方式执行,和其他 SQL 语句的执行路径不同,缺少权限检查。