Managing database accounts becomes difficult when an organization has hundreds of developers, applications, and services connecting to the same MySQL environment. Creating a separate MySQL account for every user also means maintaining permissions, passwords, account status, and access changes across two different systems.
OpenID Connect (OIDC) provides a way to use an external identity provider for MySQL authentication. Instead of maintaining a separate database password for every user, Percona Server for MySQL can validate identity tokens issued by providers such as Keycloak, Okta, and Microsoft Entra ID.
Percona also supports proxy users, allowing multiple identity-provider users to share a MySQL account based on their group membership. This is particularly useful when database permissions are managed through organizational groups.
A recent improvement makes this approach more practical for identity providers that issue long group names or group IDs. Percona Server for MySQL 8.4.13-13 includes support for OIDC proxied users with long group names and IDs. The release also includes an installation script for the OIDC plugin.
In this article, we'll configure OIDC authentication, create proxy accounts, map long identity-provider group identifiers to MySQL accounts, and test the complete authentication flow.
What Is OIDC Authentication in Percona Server?
OpenID Connect is an identity layer built on top of OAuth 2.0. It allows applications and services to authenticate users through an external identity provider.
When a user signs in, the identity provider issues a signed JSON Web Token (JWT), specifically an ID token. The client sends this token to Percona Server for MySQL during the authentication handshake.
The server validates the token and determines whether the connection should be accepted.
The OIDC plugin checks information such as:
Token structure and signature.
Issuer claim (iss).
Expiration claim (exp).
Audience claim (aud), when configured.
Subject claim (sub), for direct authentication.
Group membership, when proxy authentication is configured.
If the required checks succeed, the server establishes the database connection without exchanging a traditional MySQL password.
How the authentication flow works
The process involves the identity provider, the MySQL client, and the database server.
User or Application
|
v
Identity Provider
(Keycloak / Okta /
Microsoft Entra ID)
|
v
Signed ID Token
|
v
MySQL Client
|
Secure TLS
|
v
Percona Server for MySQL
|
v
OIDC Plugin
|
+--------+--------+
| |
v v
Validate Read Group
JWT Signature Membership
| |
+--------+--------+
|
v
Proxy User Mapping
|
v
MySQL Proxy Account
|
v
Database Privileges
The database server does not need to maintain an individual password for every identity-provider user. Instead, it validates the token and maps the user to an appropriate database account.
Understanding MySQL Proxy Users
MySQL proxy users allow one account to authenticate on behalf of another account.
In an OIDC configuration, the connecting identity is authenticated through the identity provider. Based on the user's group membership, the plugin selects a MySQL proxy account.
For example, an organization might have these identity-provider groups:
Identity-provider group | MySQL proxy account | Access |
|---|
Database Administrators | db_admin | Administrative operations |
Application Developers | app_dev | Application development |
Reporting Analysts | reporting | Read-only reporting |
Every member of a group can share the corresponding MySQL account and its privileges.
This reduces the number of database accounts that administrators need to maintain.
Why use proxy accounts?
Without proxy authentication, an administrator might create individual database accounts for Alice, Bob, Charlie, and other employees.
Each account needs its own authentication mapping and privilege configuration.
With proxy authentication, all members of the same authorized group can use one database privilege account.
The identity provider remains responsible for deciding who belongs to that group, while MySQL controls what the mapped account can do.
There is an important security distinction: proxy authentication relies on group membership rather than verifying the individual user's sub claim. Use it only when membership in the configured group is an acceptable authorization boundary.
Understanding the 32-Character Account Limit
The original named-group and anonymous proxying modes use the identity-provider group value as the MySQL proxy account name.
MySQL account names have a maximum length of 32 characters.
This creates a problem with providers that issue long group identifiers.
For example, Microsoft Entra ID can include a group Object ID in the token:
8f14e45f-ea2b-4d3c-9a7b-6c5d4e3f2a10
A long identifier cannot be used directly as a MySQL account name.
The group-to-account proxying mode solves this problem by separating the identity-provider group identifier from the MySQL account name.
Instead of requiring both names to match, you define an explicit mapping:
Identity Provider Group ID
|
v
8f14e45f-ea2b-4d3c-9a7b-6c5d4e3f2a10
|
v
OIDC Group Mapping
|
v
MySQL Account
|
v
db_admin
The identity-provider group can be longer than 32 characters, while the MySQL proxy account remains within the MySQL account-name limit.
This is the main approach to use when working with long group names or IDs.
Prerequisites
Before configuring OIDC authentication, prepare the following components:
Percona Server for MySQL 8.4.13-13 or another release that supports the required group-to-account proxying functionality.
An OIDC-compatible identity provider.
An identity-provider application or client configured to issue ID tokens.
A group claim containing the user's group memberships.
A reachable JWKS endpoint or a static set of signing keys.
A MySQL client with the OIDC client authentication plugin.
TLS, a Unix domain socket, or shared memory for secure database connections.
An administrator account with permission to install the plugin and create MySQL users.
The examples use Keycloak as the identity provider. The same approach can be adapted to other compatible providers.
Step 1: Install the OIDC Authentication Plugin
Percona Server provides a server-side authentication plugin named auth_openid_connect.
The corresponding client-side plugin is authentication_openid_connect_client.
Percona Server 8.4.13-13 includes an installation script for the OIDC plugin. You can use the script supplied with that release package, following its included instructions.
For environments where you prefer to manage plugin installation directly, use the MySQL INSTALL PLUGIN statement.
Connect to Percona Server using an administrative account and run:
INSTALL PLUGIN auth_openid_connect
SONAME 'auth_openid_connect.so';
The plugin should load successfully.
Verify its status:
SELECT
PLUGIN_NAME,
PLUGIN_STATUS
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_NAME = 'auth_openid_connect';
Expected result:
+---------------------+---------------+
| PLUGIN_NAME | PLUGIN_STATUS |
+---------------------+---------------+
| auth_openid_connect | ACTIVE |
+---------------------+---------------+
If the plugin is not active, check the server error log and confirm that the shared library exists in the directory specified by plugin_dir.
For persistent installation, configure the plugin to load during server startup in the MySQL configuration file:
[mysqld]
plugin-load-add=auth_openid_connect.so
The client also needs the authentication_openid_connect_client library. Make sure the client installation includes the corresponding plugin.
Register the JWKS refresh function
The server-side plugin provides the update_jwks() user-defined function.
Register it once:
CREATE FUNCTION update_jwks
RETURNS INTEGER
SONAME 'auth_openid_connect.so';
This function allows administrators to refresh the cached public signing keys without changing the identity-provider configuration.
Step 2: Configure the Identity Provider
The identity provider must issue signed ID tokens containing the claims required by Percona Server.
For this example, configure a Keycloak realm with the following values:
Setting | Example |
|---|
Realm | master |
Client ID | mysql-oidc |
Issuer | https://keycloak.example.com/realms/master |
Group claim | groups |
Signing keys | JWKS endpoint |
Create the required groups in Keycloak.
For example:
Database Administrators
Application Developers
Reporting Analysts
Assign users to the appropriate groups.
Configure the group claim
The OIDC plugin expects the configured group claim to be a top-level field in the ID token.
Keycloak commonly places group and role information inside nested claims. The plugin does not traverse nested objects to find the group list.
Configure a Keycloak client scope mapper that emits a top-level claim named groups.
For group membership, use the Group Membership mapper. Enable Full group path when you need the complete group path in the token.
The resulting ID token should contain a structure similar to this:
{
"iss": "https://keycloak.example.com/realms/master",
"sub": "user-12345",
"aud": "mysql-oidc",
"exp": 1790000000,
"groups": [
"/Database Administrators",
"/Application Developers"
]
}
This is an illustrative token payload. The actual token must be signed by the identity provider, and its claims must match the server configuration.
For Microsoft Entra ID, the groups claim may contain group Object IDs rather than friendly group names. This is where group-to-account proxying becomes particularly useful.
Step 3: Configure the OIDC Plugin
Percona Server stores trusted identity-provider settings in the auth_openid_connect_configuration system variable.
For production environments, keep the configuration in a separate JSON file rather than placing a large JSON document directly in the MySQL configuration file.
Create a directory for the OIDC configuration:
sudo mkdir -p /etc/mysql/oidc
sudo chown mysql:mysql /etc/mysql/oidc
sudo chmod 750 /etc/mysql/oidc
Create a file named idps.json:
{
"my-keycloak": {
"issuer-name": "https://keycloak.example.com/realms/master",
"jwks-url": "https://keycloak.example.com/realms/master/protocol/openid-connect/certs",
"audiences": [
"mysql-oidc"
],
"group-claim": "groups"
}
}
The configuration contains four important properties.
Property | Purpose |
|---|
issuer-name | Matches the token's issuer claim |
jwks-url | Provides the public signing keys |
audiences | Restricts which audience values are accepted |
group-claim | Identifies the claim containing group membership |
The top-level key, my-keycloak, is the identity-provider name referenced when creating MySQL users.
Set appropriate ownership and permissions on the file:
sudo chown mysql:mysql /etc/mysql/oidc/idps.json
sudo chmod 640 /etc/mysql/oidc/idps.json
Load the configuration into the running server:
SET GLOBAL auth_openid_connect_configuration =
'FILE:///etc/mysql/oidc/idps.json';
For persistence across restarts, add the configuration to my.cnf:
[mysqld]
plugin-load-add=auth_openid_connect.so
auth_openid_connect_configuration='FILE:///etc/mysql/oidc/idps.json'
Restart the server during a planned maintenance window after updating the configuration file.
The server must be able to reach the JWKS endpoint over HTTPS. If the identity provider rotates its signing keys, the plugin needs to refresh its cached keys.
Step 4: Create MySQL Roles
Before creating proxy accounts, define the database privileges that each group should receive.
For example, create three roles:
CREATE ROLE 'db_admin';
CREATE ROLE 'app_dev';
CREATE ROLE 'reporting';
Grant the appropriate permissions.
The following example uses an application database named ecommerce:
GRANT ALL PRIVILEGES
ON ecommerce.*
TO 'db_admin';
GRANT SELECT, INSERT, UPDATE, DELETE
ON ecommerce.*
TO 'app_dev';
GRANT SELECT
ON ecommerce.*
TO 'reporting';
These are example permissions. In production, avoid granting broad privileges unless the application genuinely requires them.
Separating roles from user accounts makes access management easier. You can change the privileges associated with a role without rewriting the OIDC configuration.
Step 5: Create Proxy Target Accounts
A proxy target account represents the MySQL security identity that the authenticated session will use.
Create these accounts with the mysql_no_login authentication plugin.
This prevents users from authenticating directly as the target accounts.
CREATE USER 'db_admin'
IDENTIFIED WITH 'mysql_no_login';
CREATE USER 'app_dev'
IDENTIFIED WITH 'mysql_no_login';
CREATE USER 'reporting'
IDENTIFIED WITH 'mysql_no_login';
Grant the roles to the corresponding accounts:
GRANT 'db_admin' TO 'db_admin';
GRANT 'app_dev' TO 'app_dev';
GRANT 'reporting' TO 'reporting';
Activate the default role for each account:
SET DEFAULT ROLE 'db_admin'
TO 'db_admin';
SET DEFAULT ROLE 'app_dev'
TO 'app_dev';
SET DEFAULT ROLE 'reporting'
TO 'reporting';
The target accounts now have the database privileges that their proxied sessions should inherit.
Step 6: Configure Group-to-Account Proxying
This is the most important step for supporting long identity-provider group names and IDs.
The group-to-account proxying mode allows the group field in the OIDC account definition to contain an array of pairs.
Each pair contains:
An identity-provider group name or ID.
A MySQL proxy target account.
For example:
[
[
"8f14e45f-ea2b-4d3c-9a7b-6c5d4e3f2a10",
"db_admin"
],
[
"a9c2f671-4d18-42c8-9e51-7b3d5a6f9012",
"app_dev"
],
[
"c5d8e912-73ab-4f61-8a20-9d6e4b2c1075",
"reporting"
]
]
The group identifiers can be longer than 32 characters. The mapped MySQL account names must still respect MySQL's 32-character account-name limit.
Create an anonymous OIDC authentication account:
CREATE USER ''@''
IDENTIFIED WITH 'auth_openid_connect'
AS '{
"identity_provider": "my-keycloak",
"group": [
[
"8f14e45f-ea2b-4d3c-9a7b-6c5d4e3f2a10",
"db_admin"
],
[
"a9c2f671-4d18-42c8-9e51-7b3d5a6f9012",
"app_dev"
],
[
"c5d8e912-73ab-4f61-8a20-9d6e4b2c1075",
"reporting"
]
]
}';
The empty username and host make this an anonymous MySQL account that can match connecting usernames.
The plugin checks the configured group-to-account pairs against the groups claim in the ID token.
When it finds a matching group, it selects the associated proxy target.
Grant the PROXY privilege
The authentication account must have permission to proxy to each target account.
Run:
GRANT PROXY ON 'db_admin' TO ''@'';
GRANT PROXY ON 'app_dev' TO ''@'';
GRANT PROXY ON 'reporting' TO ''@'';
The PROXY privilege is essential. Without it, the plugin cannot establish the session under the selected target account.
The target accounts hold the actual database privileges. The anonymous authentication account is responsible for the OIDC authentication and proxy mapping.
Step 7: Understand How Group Matching Works
The group-to-account mapping is evaluated in the order in which the pairs appear in the JSON array.
Suppose an ID token contains:
{
"groups": [
"a9c2f671-4d18-42c8-9e51-7b3d5a6f9012",
"c5d8e912-73ab-4f61-8a20-9d6e4b2c1075"
]
}
Both groups match entries in the configured mapping.
The plugin selects the first matching pair in the configured array, which maps to app_dev.
The order of the groups in the token does not determine the selection. The order of the configured mapping pairs does.
This is important when a user belongs to multiple groups.
For example, an administrator might belong to both a development group and a reporting group. If the development mapping appears first, the session uses the app_dev account.
Design the mapping order carefully, especially when different groups provide different levels of database access.
If no configured group matches the token, the plugin denies the connection.
Step 8: Obtain an ID Token
The MySQL client needs the ID token issued by the identity provider.
The token must be stored in a file that the operating system account running the client can read.
For production applications, use an appropriate OAuth flow such as Authorization Code with PKCE or Device Authorization.
Do not use the Resource Owner Password Credentials grant for production authentication. It is deprecated in modern OAuth guidance and requires applications to handle user passwords directly.
For example, after obtaining a token through the identity provider's recommended flow, save the raw ID token:
install -m 600 /dev/null /run/user/1000/id_token.jwt
printf '%s' "$ID_TOKEN" \
> /run/user/1000/id_token.jwt
The ID_TOKEN variable should contain the raw compact-serialized JWT, not a JSON response or a value prefixed with Bearer.
The token file must not exceed 10 KB.
Protect the token file because anyone who can read a valid token may be able to use it until it expires.
Step 9: Connect to Percona Server
The MySQL client uses the authentication_openid_connect_client plugin to read the token file and send the token during the authentication handshake.
Connect using the MySQL client:
mysql \
--host=mysql.example.com \
--ssl-mode=REQUIRED \
--user=anyname \
--authentication-openid-connect-client-id-token-file=/run/user/1000/id_token.jwt
The username can be any value because the anonymous OIDC account is used for authentication.
The plugin validates the token and checks the group membership.
For example, if the token contains the group ID mapped to app_dev, the session is established using the app_dev proxy account.
You can verify the result:
SELECT
USER(),
CURRENT_USER();
The two functions return different information:
The result should show the handshake identity separately from the selected proxy target.
For example, the effective account might be app_dev even though the client connected using the username anyname.
Step 10: Test Database Permissions
After authentication succeeds, verify that the session has the expected database permissions.
For an application developer, test a permitted query:
SELECT *
FROM ecommerce.orders
LIMIT 10;
Then test an operation that should not be permitted, such as changing a database user:
CREATE USER 'test_user'@'%'
IDENTIFIED BY 'TemporaryPassword';
The second operation should fail if the app_dev account does not have the required administrative privileges.
Repeat the test with tokens representing the reporting and database administrator groups.
Each group should receive only the privileges assigned to its mapped MySQL account.
This is an important validation step. A successful OIDC connection does not automatically mean the correct privilege account was selected.
Named-Group Proxying vs. Group-to-Account Proxying
Percona supports multiple proxying modes. The right choice depends on the identity-provider claims and how users select their database access.
Mode | Group mapping | Group length | Selection behavior |
|---|
Named-group proxying | Group value maps directly to a MySQL account | Maximum 32 characters | Connecting MySQL username selects the group |
Anonymous proxying | First group in the token maps to an account with the same name | Maximum 32 characters | First token group selects the account |
Group-to-account proxying | Explicit group-to-account pairs | Group can exceed 32 characters | First matching configured pair selects the account |
Group-to-account proxying is generally the better option when the identity provider issues long group names or IDs.
Named-group proxying can be useful when users belong to multiple groups and should explicitly select the account they want to use for a session.
Anonymous proxying requires additional care because it selects the first group in the token. If the identity provider changes the order of group claims, the effective database account can change unexpectedly.
Security Considerations
OIDC removes the need to maintain a separate password for every identity-provider user, but it does not remove the need for careful database authorization.
Proxy modes rely on group membership
Proxy modes do not verify the token's sub claim.
Any valid token from a configured identity provider that contains a matching group can be accepted.
This means group membership becomes the security boundary.
Only trusted administrators should be able to add users to groups that map to privileged database accounts.
Use mysql_no_login for proxy targets
Proxy target accounts should not allow direct authentication.
The mysql_no_login plugin prevents a user from logging in directly as the account. Users must authenticate through the OIDC account and receive the target account through proxying.
This helps prevent bypassing the intended authentication path.
Protect ID tokens
An ID token is a bearer credential. Anyone who obtains it may be able to authenticate until the token expires.
Use secure storage, restrictive file permissions, short token lifetimes, and appropriate client-side controls.
Require secure connections
The OIDC client refuses to send the token over plaintext TCP.
Use TLS for remote connections. A Unix domain socket or shared memory can also provide an accepted secure transport in supported environments.
Keep signing keys current
The plugin retrieves public signing keys from the configured JWKS endpoint and caches them.
It does not automatically refresh keys based on HTTP cache headers. Register and schedule update_jwks() according to the identity provider's signing-key rotation policy.
Common Mistakes to Avoid
Using a long group ID as a MySQL account name
MySQL account names are limited to 32 characters.
Use group-to-account proxying to map long identity-provider group IDs to short MySQL account names.
Using a flat group array
The group-to-account configuration requires an array of two-element pairs.
This is correct:
{
"group": [
["long-group-id", "app_dev"]
]
}
This is incorrect:
{
"group": [
"long-group-id",
"app_dev"
]
}
The plugin denies authentication when the mapping structure is invalid.
Forgetting the PROXY privilege
Creating the OIDC authentication account and target accounts is not enough.
Grant PROXY on every target account to the authentication account.
Assigning privileges to the wrong account
The target account holds the privileges inherited by the session.
Granting database permissions only to the anonymous authentication account does not replace configuring the proxy target correctly.
Using an incorrect token claim
The plugin expects the configured group claim as a top-level string or array of strings.
If Keycloak sends group information inside a nested object, configure a mapper to expose the required top-level claim.
Assuming token expiration closes active sessions
The plugin validates the token at connection time. An established connection remains active when the token later expires.
If an identity is removed from a group, the existing session is not automatically terminated. The new group membership takes effect when the user connects again with a token reflecting the updated membership.
Forgetting JWKS key rotation
The plugin does not automatically refresh cached signing keys.
If the identity provider rotates its keys, an unrefreshed server might reject tokens signed with a new key.
Use update_jwks() or a scheduled refresh process.
Best Practices for Production Environments
Use group-to-account proxying when identity-provider group names or IDs exceed 32 characters.
Map external group identifiers to short, meaningful MySQL account names.
Use mysql_no_login for proxy target accounts to prevent direct authentication.
Grant the PROXY privilege only to the intended OIDC authentication accounts.
Keep database privileges on the proxy target accounts rather than assigning broad permissions to the authentication account.
Use a top-level group claim and verify its structure with real ID tokens.
Protect token files with restrictive operating system permissions.
Use TLS for remote MySQL connections.
Prefer a JWKS endpoint over static signing keys in production.
Schedule JWKS refreshes according to the identity provider's key rotation policy.
Review group membership and privileged mappings regularly.
Test users who belong to multiple groups to confirm that the configured mapping order selects the intended account.
Plan for active sessions when removing users from identity-provider groups.
Keep a separate administrative access path so database administrators can recover from an OIDC configuration problem.
Advantages and Limitations
Advantages
Allows users to authenticate through external identity providers.
Reduces the need to maintain individual MySQL passwords.
Allows multiple identity-provider users to share a database privilege account.
Supports group-based authorization through MySQL proxy users.
Maps long group names and IDs to short MySQL account names.
Supports multiple identity providers.
Refreshes signing keys through the JWKS update function.
Helps centralize identity and database access management.
Limitations
Proxy authentication relies on group membership rather than verifying the individual sub claim.
Proxy target account names remain limited to 32 characters.
The plugin validates tokens only when connections are established.
Active sessions are not automatically disconnected when a token expires or group membership changes.
Clients must use secure transport.
The group claim must have a supported top-level structure.
JWKS signing keys require an explicit refresh strategy.
Summary
Percona Server for MySQL provides OIDC authentication that connects database access with an external identity provider. Its proxy-user support allows multiple users to share MySQL privilege accounts based on group membership.
The group-to-account proxying mode is particularly useful when identity providers issue long group names or IDs. Instead of trying to use an external group identifier as a MySQL account name, administrators can map it to a short database account with the required privileges.
The configuration involves installing the OIDC plugin, trusting the identity provider, creating proxy target accounts, defining group mappings, granting PROXY privileges, and connecting with a signed ID token.
The most important security consideration is that proxy modes use group membership as the authorization boundary. Keep privileged group membership tightly controlled, protect tokens, and verify the effective MySQL account after every authentication test.
For organizations already using Keycloak, Okta, or Microsoft Entra ID, this approach can make MySQL access easier to manage while keeping authentication centralized.
Join the conversation! Your thoughts help the community grow.