HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

GRANT/REVOKE PROXY

Function

Grants or revokes proxy permissions.

Precautions

N/A

Syntax

GRANT PROXY ON user
    TO user [, user] ...
    [WITH GRANT OPTION]

REVOKE PROXY ON user
    FROM user [, user] ...

Parameter Description

  • {PROXY}

    Syntax keyword.

  • user

    User (role) name.

Examples

--Create a simple table.
MogDB=# CREATE SCHEMA tst_schema1;
MogDB=# SET SEARCH_PATH TO tst_schema1;
MogDB=# CREATE TABLE tst_t1
(
id int,
name varchar(20)
);
INSERT INTO tst_t1 values(20220101, 'proxy_example');

--Create a user.
MogDB=# DROP ROLE if EXISTS test_proxy_u1;
MogDB=# CREATE ROLE test_proxy_u1 IDENTIFIED BY 'test_proxy_u1@123';
MogDB=# DROP ROLE if EXISTS test_proxy_u2;
MogDB=# CREATE ROLE test_proxy_u3 IDENTIFIED BY 'test_proxy_u2@123';
MogDB=# DROP ROLE if EXISTS test_proxy_u3;
MogDB=# CREATE ROLE test_proxy_u3 IDENTIFIED BY 'test_proxy_u3@123';

--Grant schema and table permissions.
MogDB=# GRANT ALL ON SCHEMA tst_schema1 TO test_proxy_u2;
MogDB=# GRANT ALL ON SCHEMA tst_schema1 TO test_proxy_u2;
MogDB=# GRANT ALL ON SCHEMA tst_schema1 TO test_proxy_u2;
MogDB=# GRANT ALL ON tst_t1 to test_proxy_u1;

--Test permissions (no permissions).
MogDB=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
MogDB=> SELECT * FROM tst_schema1.tst_t1;
ERROR:  permission denied for relation tst_t1
DETAIL:  N/A

--Test permissions (with proxy permissions).
MogDB=> RESET ROLE;
MogDB=# GRANT PROXY ON test_proxy_u1 TO test_proxy_u2;
MogDB=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
MogDB=>  SELECT * FROM tst_schema1.tst_t1;
    id    |     name      
----------+---------------
 20220101 | proxy_example
 
 --Test permissions (cascading test: usr_1->usr_2->usr_3).
MogDB=> RESET ROLE;
MogDB=# GRANT PROXY ON test_proxy_u2 TO test_proxy_u3;
MogDB=# SET ROLE test_proxy_u3 PASSWORD 'test_proxy_u3@123';
MogDB=>  SELECT * FROM tst_schema1.tst_t1;
    id    |     name      
----------+---------------
 20220101 | proxy_example
 
--Test permissions granted by the proxy (with grant option).
MogDB=> RESET ROLE;
MogDB=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
MogDB=> grant proxy on test_proxy_u1 to test_proxy_u3;
ERROR:  must have admin option on role "test_proxy_u1"
MogDB=> RESET ROLE;
RESET
MogDB=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
SET
MogDB=> grant proxy on test_proxy_u1 to test_proxy_u3;
ERROR:  must have admin option on role "test_proxy_u1"
MogDB=> RESET ROLE;
MogDB=# grant proxy on test_proxy_u1 to test_proxy_u2 with grant option;
MogDB=# SET ROLE test_proxy_u2 PASSWORD 'test_proxy_u2@123';
MogDB=> grant proxy on test_proxy_u1 to test_proxy_u3;

--Test the proxy permission revoking.
MogDB=> revoke proxy on test_proxy_u1 from test_proxy_u3;
MogDB=> revoke proxy on test_proxy_u1 from test_proxy_u2;
MogDB=>  SET ROLE test_proxy_u3 password 'test_proxy_u3@123';
MogDB=> SELECT * FROM tst_schema1.tst_t1;
ERROR:  permission denied for relation tst_t1
DETAIL:  N/A
Copyright © 2011-2024 www.enmotech.com All rights reserved.