Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/srv/db/mysql/autousers.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func getCreateProcedureCommand(conn *clientConn, procedureName string) (string,
const (
// procedureVersion is a hard-coded string that is set as procedure
// comments to indicate the procedure version.
procedureVersion = "teleport-auto-user-v4"
procedureVersion = "teleport-auto-user-v5"

// mysqlMaxUsernameLength is the maximum username/role length for MySQL.
//
Expand Down
9 changes: 4 additions & 5 deletions lib/srv/db/mysql/sql/mariadb_activate_user.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE PROCEDURE teleport_activate_user(IN username VARCHAR(80), IN details JSON)
CREATE PROCEDURE teleport_activate_user(IN username TEXT, IN details JSON)
proc_label:BEGIN
DECLARE is_auto_user INT DEFAULT 0;
DECLARE is_active INT DEFAULT 0;
DECLARE is_same_user INT DEFAULT 0;
DECLARE role_index INT DEFAULT 0;
DECLARE cur_role VARCHAR(128) DEFAULT '';
DECLARE cur_role TEXT DEFAULT '';
DECLARE cur_roles TEXT DEFAULT '';
SET @roles = JSON_EXTRACT(details, "$.roles");
SET @teleport_user = JSON_VALUE(details, "$.attributes.user");
Expand Down Expand Up @@ -72,11 +72,10 @@ proc_label:BEGIN
CALL teleport_revoke_roles(username);
SET role_index = 0;
WHILE role_index < JSON_LENGTH(@roles) DO
SELECT JSON_EXTRACT(@roles, CONCAT('$[',role_index,']')) INTO cur_role;
SELECT JSON_UNQUOTE(JSON_EXTRACT(@roles, CONCAT('$[',role_index,']'))) INTO cur_role;
SELECT role_index + 1 INTO role_index;

-- role extracted from JSON already has double quotes.
SET @sql := CONCAT_WS(' ', 'GRANT', cur_role, 'TO', QUOTE(@all_in_one_role));
SET @sql := CONCAT_WS(' ', 'GRANT', QUOTE(cur_role), 'TO', QUOTE(@all_in_one_role));
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/db/mysql/sql/mariadb_deactivate_user.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE PROCEDURE teleport_deactivate_user(IN username VARCHAR(80))
CREATE PROCEDURE teleport_deactivate_user(IN username TEXT)
BEGIN
DECLARE is_active INT DEFAULT 0;
SELECT COUNT(USER) INTO is_active FROM information_schema.processlist WHERE USER = username;
Expand Down
4 changes: 2 additions & 2 deletions lib/srv/db/mysql/sql/mariadb_delete_user.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE PROCEDURE teleport_delete_user(IN username VARCHAR(80))
CREATE PROCEDURE teleport_delete_user(IN username TEXT)
BEGIN
-- Defaults to dropping user.
DECLARE state VARCHAR(5);
DECLARE state TEXT;
DECLARE is_active INT DEFAULT 0;
DECLARE view_count INT DEFAULT 0;
DECLARE procedure_count INT DEFAULT 0;
Expand Down
6 changes: 3 additions & 3 deletions lib/srv/db/mysql/sql/mariadb_revoke_roles.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE PROCEDURE teleport_revoke_roles(IN username VARCHAR(80))
CREATE PROCEDURE teleport_revoke_roles(IN username TEXT)
BEGIN
DECLARE cur_user CHAR(128);
DECLARE cur_role CHAR(128);
DECLARE cur_user TEXT;
DECLARE cur_role TEXT;
DECLARE done INT DEFAULT FALSE;
-- Revoke all roles assigned to the all-in-one role, and all roles assigned
-- to the username (expect 'teleport-auto-user')
Expand Down
9 changes: 4 additions & 5 deletions lib/srv/db/mysql/sql/mysql_activate_user.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CREATE PROCEDURE teleport_activate_user(IN username VARCHAR(32), IN details JSON)
CREATE PROCEDURE teleport_activate_user(IN username TEXT, IN details JSON)
proc_label:BEGIN
DECLARE is_auto_user INT DEFAULT 0;
DECLARE is_active INT DEFAULT 0;
DECLARE is_same_user INT DEFAULT 0;
DECLARE are_roles_same INT DEFAULT 0;
DECLARE role_index INT DEFAULT 0;
DECLARE role VARCHAR(32) DEFAULT '';
DECLARE role TEXT DEFAULT '';
DECLARE cur_roles TEXT DEFAULT '';
SET @roles = details->"$.roles";
SET @teleport_user = details->>"$.attributes.user";
Expand Down Expand Up @@ -57,11 +57,10 @@ proc_label:BEGIN

-- Assign roles.
WHILE role_index < JSON_LENGTH(@roles) DO
SELECT JSON_EXTRACT(@roles, CONCAT('$[',role_index,']')) INTO role;
SELECT JSON_UNQUOTE(JSON_EXTRACT(@roles, CONCAT('$[',role_index,']'))) INTO role;
SELECT role_index + 1 INTO role_index;

-- role extracted from JSON already has double quotes.
SET @sql := CONCAT_WS(' ', 'GRANT', role, 'TO', QUOTE(username));
SET @sql := CONCAT_WS(' ', 'GRANT', QUOTE(role), 'TO', QUOTE(username));
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/db/mysql/sql/mysql_deactivate_user.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE PROCEDURE teleport_deactivate_user(IN username VARCHAR(32))
CREATE PROCEDURE teleport_deactivate_user(IN username TEXT)
BEGIN
DECLARE is_active INT DEFAULT 0;
SELECT COUNT(USER) INTO is_active FROM information_schema.processlist WHERE USER = username;
Expand Down
4 changes: 2 additions & 2 deletions lib/srv/db/mysql/sql/mysql_delete_user.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE PROCEDURE teleport_delete_user(IN username VARCHAR(32))
CREATE PROCEDURE teleport_delete_user(IN username TEXT)
BEGIN
-- Defaults to dropping user.
DECLARE state VARCHAR(5) DEFAULT 'TP003';
DECLARE state TEXT DEFAULT 'TP003';
DECLARE is_active INT DEFAULT 0;

-- Views and procedures rely on the definer to work correctly. Dropping the
Expand Down
4 changes: 2 additions & 2 deletions lib/srv/db/mysql/sql/mysql_revoke_roles.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE PROCEDURE teleport_revoke_roles(IN username VARCHAR(32))
CREATE PROCEDURE teleport_revoke_roles(IN username TEXT)
BEGIN
DECLARE role VARCHAR(32) DEFAULT '';
DECLARE role TEXT DEFAULT '';
DECLARE done INT DEFAULT 0;
DECLARE role_cursor CURSOR FOR SELECT FROM_USER FROM mysql.role_edges WHERE FROM_USER != 'teleport-auto-user' AND TO_USER = username;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
Expand Down
Loading