GRANT/REVOKE PROXY

功能描述

授予、召回代理者权限。

注意事项

N/A

语法格式

  1. GRANT PROXY ON user
  2. TO user [, user] ...
  3. [WITH GRANT OPTION]
  4. REVOKE PROXY ON user
  5. FROM user [, user] ...

参数说明

  • {PROXY}

    语法关键词。

  • user

    用户(角色)名。

示例

  1. --创建简单表
  2. opengauss=# CREATE SCHEMA tst_schema1;
  3. opengauss=# SET SEARCH_PATH TO tst_schema1;
  4. opengauss=# CREATE TABLE tst_t1
  5. (
  6. id int,
  7. name varchar(20)
  8. );
  9. INSERT INTO tst_t1 values(20220101, 'proxy_example');
  10. --创建用户
  11. opengauss=# DROP ROLE if EXISTS test_proxy_u1;
  12. opengauss=# CREATE ROLE test_proxy_u1 IDENTIFIED BY 'test_proxy_u1@123';
  13. opengauss=# DROP ROLE if EXISTS test_proxy_u2;
  14. opengauss=# CREATE ROLE test_proxy_u3 IDENTIFIED BY 'test_proxy_u2@123';
  15. opengauss=# DROP ROLE if EXISTS test_proxy_u3;
  16. opengauss=# CREATE ROLE test_proxy_u3 IDENTIFIED BY 'test_proxy_u3@123';
  17. --schema、表权限授予
  18. opengauss=# GRANT ALL ON SCHEMA tst_schema1 TO test_proxy_u2;
  19. opengauss=# GRANT ALL ON SCHEMA tst_schema1 TO test_proxy_u2;
  20. opengauss=# GRANT ALL ON SCHEMA tst_schema1 TO test_proxy_u2;
  21. opengauss=# GRANT ALL ON tst_t1 to test_proxy_u1;
  22. --权限检测(无权限)
  23. opengauss=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
  24. opengauss=> SELECT * FROM tst_schema1.tst_t1;
  25. ERROR: permission denied for relation tst_t1
  26. DETAIL: N/A
  27. --权限检测(拥有代理者权限)
  28. opengauss=> RESET ROLE;
  29. opengauss=# GRANT PROXY ON test_proxy_u1 TO test_proxy_u2;
  30. opengauss=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
  31. opengauss=> SELECT * FROM tst_schema1.tst_t1;
  32. id | name
  33. ----------+---------------
  34. 20220101 | proxy_example
  35. --权限检测(级联式检测usr_1->usr_2->usr_3)
  36. opengauss=> RESET ROLE;
  37. opengauss=# GRANT PROXY ON test_proxy_u2 TO test_proxy_u3;
  38. opengauss=# SET ROLE test_proxy_u3 PASSWORD 'test_proxy_u3@123';
  39. opengauss=> SELECT * FROM tst_schema1.tst_t1;
  40. id | name
  41. ----------+---------------
  42. 20220101 | proxy_example
  43. --对被代理者授予的权限检测(with grant option)
  44. opengauss=> RESET ROLE;
  45. opengauss=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
  46. opengauss=> grant proxy on test_proxy_u1 to test_proxy_u3;
  47. ERROR: must have admin option on role "test_proxy_u1"
  48. opengauss=> RESET ROLE;
  49. RESET
  50. opengauss=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
  51. SET
  52. opengauss=> grant proxy on test_proxy_u1 to test_proxy_u3;
  53. ERROR: must have admin option on role "test_proxy_u1"
  54. opengauss=> RESET ROLE;
  55. opengauss=# grant proxy on test_proxy_u1 to test_proxy_u2 with grant option;
  56. opengauss=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
  57. opengauss=> grant proxy on test_proxy_u1 to test_proxy_u3;
  58. --召回代理权限测试
  59. opengauss=> revoke proxy on test_proxy_u1 from test_proxy_u3;
  60. opengauss=> revoke proxy on test_proxy_u1 from test_proxy_u2;
  61. opengauss=> SET ROLE test_proxy_u3 password 'test_proxy_u3@123';
  62. opengauss=> SELECT * FROM tst_schema1.tst_t1;
  63. ERROR: permission denied for relation tst_t1
  64. DETAIL: N/A