GRANT OPTION Lets Grantees Re-Grant

WITH GRANT OPTION lets the grantee re-grant to a third role, and REVOKE with CASCADE tears the whole chain down from the source.

SqlSecurity Boundaries

Code

snippet
-- WITH GRANT OPTION lets grantees re-grant downstream:转授链从此可能变长
CREATE ROLE report_owner;
CREATE ROLE report_reader;

GRANT SELECT ON sales TO report_owner WITH GRANT OPTION;

-- 以 report_owner 身份把权限转授下去
SET ROLE report_owner;
GRANT SELECT ON sales TO report_reader;
RESET ROLE;

-- information_schema 里能看到下游授权:grantor 是 report_owner 而不是表主
SELECT grantor, grantee, privilege_type
FROM information_schema.role_table_grants
WHERE table_name = 'sales' AND grantee = 'report_reader';

-- 撤销源头授权时 CASCADE 连带撤销 re-grant 出去的下游权限
REVOKE SELECT ON sales FROM report_owner CASCADE;
SELECT count(*) AS remaining_grants
FROM information_schema.role_table_grants
WHERE table_name = 'sales' AND grantee = 'report_reader';

What happens step by step

The file runs SELECT / CREATE statements, touching information_schema.role_table_grants and report_owner.

Breaking the statements into their working parts: a WHERE clause narrowing which rows one statement affects; COUNT aggregation.

Applying it

Run the statement against the information_schema.role_table_grants table.

Statements that matter

SELECT grantor, grantee, privilege_type
FROM information_schema.role_table_grants
WHERE table_name = 'sales' AND grantee = 'report_reader';
SELECT count(*) AS remaining_grants
FROM information_schema.role_table_grants
WHERE table_name = 'sales' AND grantee = 'report_reader';
GRANT SELECT ON sales TO report_owner WITH GRANT OPTION;

Interactive Tools for This Topic

FAQ

What are the relations in play here?
The references are `information_schema.role_table_grants`, `report_owner`.