Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL/MariaDB: Custom callback/trigger support on user activation/deactivation #49716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

disc
Copy link

@disc disc commented Dec 3, 2024

The problem

The Teleport server is unable to authenticate users with a TLS proxy, such as Maxscale, between the Teleport server and the MariaDB/MySQL database. This is because the TLS proxy terminates the original TLS connection and creates a new one with a different TLS certificate, causing a mismatch in the CN attribute. As a result, users created by Teleport in the database with a specific CN attribute cannot log in.

The communication schema is:
Teleport server [Teleport client TLS certificate] -> Maxscale (TLS proxy) [Maxscale TLS certificate] -> MariaDB/MySQL server.

The suggested solution

Updated SQL procedures to call a callback user-created procedure upon user activation or deactivation if exists (a custom trigger on user activation/deactivation) . This allows for customizable actions to be triggered when a user's status changes.

The result I would like to achieve with such changes is updating database users before a login.

Teleport successfully creates users in the MariaDB/MySQL database with REQUIRE SUBJECT /cn={username}, but the TLS proxy creates a new TLS connection and uses another TLS certificate with a different CN attribute and the Teleport users can't login into a database.

The solution is the optional creation of one or two stored procedures by the Teleport administrator in the teleport database:

  • teleport_user_activated_callback(username) with a signature
-- MariaDB:
CREATE PROCEDURE teleport_user_activated_callback(IN username VARCHAR(80))
-- MySQL:
CREATE PROCEDURE teleport_user_activated_callback(IN username VARCHAR(32))
  • teleport_user_deactivated_callback(username) with a signature
-- MariaDB:
CREATE PROCEDURE teleport_user_deactivated_callback(IN username VARCHAR(80)) 
-- MySQL:
CREATE PROCEDURE teleport_user_deactivated_callback(IN username VARCHAR(32)) 

The suggested stored procedures allow database administrators to react to these actions and update the teleport user in a database by changing REQUIRE SUBJECT /CN={username} to another method of authentication, for example:

  • change a REQUIRE SUBJECT
  • replace it with a custom auth plugin IDENTIFIED WITH own_auth_plugin
  • or do something else

Expected workflow:

  1. The teleport user logs into a database.
  2. The database user activates by calling a teleport_activate_user(username) MariaDB/MySQL stored procedure.
  3. The procedure teleport_activate_user calls the client's own teleport_user_activated_callback(username) procedure if it exists and executes the client's business logic on this action.

The same approach is used when the user deactivates in a database:

  1. The database user deactivates by calling a teleport_deactivate_user(username) MariaDB/MySQL stored procedure.
  2. The procedure teleport_deactivate_user(username) calls the client's own teleport_user_deactivated_callback(username) procedure if it exists and executes the client's business logic on this action.

What do you think about such an approach?

@CLAassistant
Copy link

CLAassistant commented Dec 3, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

github-actions bot commented Dec 3, 2024


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@disc disc marked this pull request as ready for review December 3, 2024 18:56
@github-actions github-actions bot requested review from jimbishopp and r0mant December 3, 2024 18:56
@github-actions github-actions bot added database-access Database access related issues and PRs size/sm labels Dec 3, 2024
…ated_callback` mysql procedures once user was activated or deactivated if such procedures are created by a user
@disc disc force-pushed the mysql-user-activated-callback-procedure branch from 3db42cd to 810c423 Compare December 3, 2024 19:09
@disc
Copy link
Author

disc commented Dec 8, 2024

Hello @jimbishopp @r0mant. Could you look into the suggested improvement and share your opinion on this matter?

@disc disc changed the title MySQL/MariaDB: User activated/deactivated callback calls in stored procedures MySQL/MariaDB: Custom callback/trigger support on user activation/deactivation Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database-access Database access related issues and PRs size/sm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants