Skip to content

[DPE-7322] Support predefined roles #652

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

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

Conversation

sinclert-canonical
Copy link
Contributor

This PR implements the set of predefined roles proposed in this specification.

In addition to the predefined roles proposed to be on sync with PostgreSQL 16 operators, there is an additional one in order to solve a long time standing time debt: mysqlrouter. This predefined role is proposed in order to stop treating mysqlrouter as a magic word used to assign ALL PRIVILEGES to the created users whose extra-user-roles config argument contained such word. That exact name has been chosen to preserve backwards compatibility.

Additional changes:

  • Implemented MySQL lib function to fully support the usage of extra-user-roles config argument.
  • Harmonized MySQL config arguments to all user underscore (_) instead of mixing dashes and underscores.
  • Removed unused MySQL config dictionary in the unit tests.

@sinclert-canonical sinclert-canonical added the enhancement New feature, UI change, or workload upgrade label Jul 7, 2025
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7322/predefined-roles branch 17 times, most recently from 350dc94 to 90bb3c8 Compare July 14, 2025 08:39
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7322/predefined-roles branch 2 times, most recently from 2bb4cdc to ef8e039 Compare July 15, 2025 12:11
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7322/predefined-roles branch 3 times, most recently from d6ef3e2 to 0d020f4 Compare July 28, 2025 09:10
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7322/predefined-roles branch 6 times, most recently from e9ba0fb to 8000b34 Compare August 6, 2025 14:27
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7322/predefined-roles branch from 8000b34 to 2c8e14b Compare August 11, 2025 09:09
@sinclert-canonical sinclert-canonical force-pushed the sinclert/7322/predefined-roles branch from 2c8e14b to bd05e71 Compare August 11, 2025 10:24
Comment on lines +1516 to +1518
if len(role_name) >= ROLE_MAX_LENGTH:
logger.warning(f"Pruning application database role name {role_name}")
role_name = role_name[:ROLE_MAX_LENGTH]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet is here to decouple this PR from changes that will be proposed on the MySQL Test app.

In short: there is a length limit on how roles can be named in MySQL (32 characters). MySQL Test app default database name is continuous_writes_database, which in addition to the charmed_dba prefix surpasses the limit. I would suggest shorten the default database name to just continuous_writes.

Comment on lines +1217 to +1221
# The granting of all privileges to the MySQL Router role
# can only be restricted when the privileges to the users
# created by such role are restricted as well
# https://github.com/canonical/mysql-router-operator/blob/main/src/mysql_shell/__init__.py#L134-L136
f"GRANT ALL ON *.* TO {role} WITH GRANT OPTION",
Copy link
Contributor Author

@sinclert-canonical sinclert-canonical Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set of privileges is the only difference between what got approved in the spec, and the reality. We need to grant MySQL Router users ALL privileges as they are also used to setup databases / relation users.

My long-term proposal would be to phase out this behavior, so the creation of databases / relation users are done in a centralized place (i.e. MySQL operators), via some custom event or other Juju compatible signaling. However, I recognize the design challenges of that approach, so they are worth discussing + planning whenever we have bandwidth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between LEGACY_ROLE_ROUTER and MODERN_ROLE_ROUTER then?

done in a centralized place (i.e. MySQL operators)

would also prefer this, but this would require the mysql <-> mysql router relation to use a different interface (i.e. not mysql_client)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between LEGACY_ROLE_ROUTER and MODERN_ROLE_ROUTER then?

Just the name. Starting after the merging of this PR, the name charmed_router would be the preferable choice (given the standardized prefix). However, we recognize there may be folks already relying on the mysqlrouter "role" (in truth it is just a magic word) to define their setups.

Paulo and I chatted about dropping the legacy mysqlrouter "role" when we work on supporting MySQL 8.4.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check my understanding: so we would switch mysql router operator from mysqlrouter to charmed_router, but the permissions will be the same?

would it be easier to just stay with mysqlrouter so that newer versions of mysql-router-operator are compatible with older versions of mysql server and then make the switchover in both charms on 8.4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check my understanding: so we would switch mysql router operator from mysqlrouter to charmed_router, but the permissions will be the same?

Yes, unless the centralized creation of databases / relation users work is scoped + agreed + allocated.

would it be easier to just stay with mysqlrouter so that newer versions of mysql-router-operator are compatible with older versions of mysql server and then make the switchover in both charms on 8.4?

Yes, I am not changing the requested role within MySQL Router operators (see VM and K8s). Backwards compatibility is preserved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not changing the requested role within MySQL Router operators

what's the purpose in adding charmed_router then? seems like it might make more sense to add that when we add the new behavior for that role, or on 8.4 if we choose to keep the current behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose in adding charmed_router then?

Standardizing naming for all the predefined roles.

Copy link
Contributor

@carlcsaposs-canonical carlcsaposs-canonical Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but nobody will be using that role? and if we want to change the behavior in the future, it will be a breaking change—or we'll have to use a different role name for the new behavior

not sure if I'm missing something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, UI change, or workload upgrade Libraries: Out of sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants