mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-03 07:40:28 +08:00
* add AWS RDS MariaDB e2e tests * fix spurious teardown error logs * if a role or user doesn't exist, that is not an error nor is it worth logging during auto user teardown. * check for admin option * add some extra secret fetching checkings * only drop redshift user if the user exists
24 lines
973 B
PL/PgSQL
24 lines
973 B
PL/PgSQL
CREATE OR REPLACE PROCEDURE teleport_delete_user(username varchar)
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
BEGIN
|
|
-- Only drop if the user doesn't have other active sessions.
|
|
-- Update to pg_stat_activity is delayed for a few hundred ms. Use
|
|
-- stv_sessions instead:
|
|
-- https://docs.aws.amazon.com/redshift/latest/dg/r_STV_SESSIONS.html
|
|
IF EXISTS (SELECT user_name FROM stv_sessions WHERE user_name = CONCAT('IAM:', username)) THEN
|
|
RAISE EXCEPTION 'TP000: User has active connections';
|
|
ELSE
|
|
BEGIN
|
|
EXECUTE 'DROP USER IF EXISTS ' || QUOTE_IDENT(username);
|
|
EXCEPTION WHEN OTHERS THEN
|
|
-- Redshift only support OTHERS as exception condition, so we handle
|
|
-- any error that might happen.
|
|
|
|
-- Drop user/role will fail if user has dependent objects.
|
|
-- In this scenario, fallback into disabling the user.
|
|
CALL teleport_deactivate_user(username);
|
|
END;
|
|
END IF;
|
|
END;$$;
|