mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-04 02:21:02 +08:00
* Implement granular db permissions for Postgres (RFD 151) * docs, whitespace * Make sure query is closed, even in case of errors along the way * fix imports
18 lines
762 B
PL/PgSQL
18 lines
762 B
PL/PgSQL
CREATE OR REPLACE PROCEDURE pg_temp.teleport_remove_permissions(username VARCHAR)
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
row_data RECORD;
|
|
BEGIN
|
|
-- Check active connections.
|
|
IF EXISTS (SELECT usename FROM pg_stat_activity WHERE usename = username AND datname = current_database()) THEN
|
|
RAISE NOTICE 'User has active connections to current database';
|
|
ELSE
|
|
-- Loop through table permissions
|
|
FOR row_data IN (SELECT DISTINCT table_schema, table_name FROM information_schema.table_privileges WHERE grantee = username)
|
|
LOOP
|
|
EXECUTE 'REVOKE ALL PRIVILEGES ON ' || quote_ident(row_data.table_schema) || '.' || quote_ident(row_data.table_name) || ' FROM ' || quote_ident(username);
|
|
END LOOP;
|
|
END IF;
|
|
END;
|
|
$$; |