Skip to content

Commit 218e3ec

Browse files
committed
CONCPP-75 Introducing the option to restrict the list of auth plugins
The name of the option is restrictedAuth Application has to provide comma separated list of allowed plugins. Empty list means everything is allowed. The full list of available plugins is mysql_native_password, client_ed25519, auth_gssapi_client, caching_sha2_password, dialog and mysql_clear_password
1 parent 0a2069d commit 218e3ec

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

README

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ useBulkStmts Use dedicated COM_STMT_BULK_EXECUTE protocol for
119119
connectionAttributes If performance_schema is enabled, permits to send server
120120
some client information in a key:value pair format
121121
(example: connectionAttributes=key1:value1,key2,value2) string
122+
restrictedAuth A comma separated list of allowed to use client-side plugins.
123+
The full list of available plugins is mysql_native_password,
124+
client_ed25519, auth_gssapi_client, caching_sha2_password,
125+
dialog and mysql_clear_password string
122126

123127

124128
Properties is map of strings, and is another way to pass optional parameters.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ The list of supported options:
8989
| **`rewriteBatchedStatements`** |For insert queries, rewrites batchedStatement to execute in a single executeQuery. Example: insert into ab (i) values (?) with first batch values = 1, second = 2 will be rewritten as INSERT INTO ab (i) VALUES (1), (2). If query cannot be rewriten in "multi-values", rewrite will use multi-queries : INSERT INTO TABLE(col1) VALUES (?) ON DUPLICATE KEY UPDATE col2=? with values [1,2] and [2,3]\" will be rewritten as INSERT INTO TABLE(col1) VALUES (1) ON DUPLICATE KEY UPDATE col2=2;INSERT INTO TABLE(col1) VALUES (3) ON DUPLICATE KEY UPDATE col2=4 If active, the useServerPrepStmts option is set to false.|*bool* |false||
9090
| **`useBulkStmts`** |Use dedicated COM_STMT_BULK_EXECUTE protocol for executeBatch if possible. Can be significanlty faster. (works only with server MariaDB >= 10.2.7).|*bool* |false||
9191
| **`connectionAttributes`** |If performance_schema is enabled, permits to send server some client information in a key:value pair format (example: connectionAttributes=key1:value1,key2,value2) This information can be retrieved on server within tables performance_schema.session_connect_attrs and performance_schema.session_account_connect_attrs. This allows an identification of client/application on server|*string* |||
92+
| **`restrictedAuth`** |A comma separated list of allowed to use client-side plugins. The full list of available plugins is mysql_native_password, client_ed25519, auth_gssapi_client, caching_sha2_password, dialog and mysql_clear_password|*string* |||
9293

9394

9495
Properties is map of strings, and is another way to pass optional parameters.

src/options/DefaultOptions.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************************************************************************************
2-
Copyright (C) 2020, 2023 MariaDB Corporation AB
2+
Copyright (C) 2020, 2025 MariaDB Corporation plc
33
44
This library is free software; you can redistribute it and/or
55
modify it under the terms of the GNU Library General Public
@@ -704,6 +704,14 @@ namespace sql
704704
"Default authentication client-side plugin to use",
705705
false,
706706
""}
707+
},
708+
{
709+
"restrictedAuth", {"restrictedAuth",
710+
"1.0.6",
711+
"A comma separated list of allowed to use client-side plugins. The full list of available plugins is"
712+
" mysql_native_password, client_ed25519, auth_gssapi_client, caching_sha2_password, dialog and mysql_clear_password",
713+
false,
714+
""}
707715
}
708716
};
709717

src/options/Options.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************************************************************************************
2-
Copyright (C) 2020 MariaDB Corporation AB
2+
Copyright (C) 2020,2025 MariaDB Corporation plc
33
44
This library is free software; you can redistribute it and/or
55
modify it under the terms of the GNU Library General Public
@@ -139,7 +139,8 @@ namespace mariadb
139139
OPTIONS_FIELD(useResetConnection),
140140
OPTIONS_FIELD(useReadAheadInput),
141141
OPTIONS_FIELD(serverRsaPublicKeyFile),
142-
OPTIONS_FIELD(tlsPeerFP)
142+
OPTIONS_FIELD(tlsPeerFP),
143+
OPTIONS_FIELD(restrictedAuth)
143144
};
144145

145146

@@ -519,6 +520,9 @@ namespace mariadb
519520
if (!(tlsPeerFPList.compare(opt->tlsPeerFPList) == 0)) {
520521
return false;
521522
}
523+
if (!(restrictedAuth.compare(opt->restrictedAuth) == 0)) {
524+
return false;
525+
}
522526
return minPoolSize == opt->minPoolSize;
523527
}
524528

@@ -612,9 +616,11 @@ namespace mariadb
612616
result= 31 *result + (autocommit ? 1 : 0);
613617
result= 31 *result + (!credentialType.empty() ? credentialType.hashCode() : 0);
614618

615-
result= 31 *result + (!nonMappedOptions.empty() ? hashProps(nonMappedOptions) : 0);
619+
result= 31*result + (!nonMappedOptions.empty() ? hashProps(nonMappedOptions) : 0);
620+
621+
result= 31*result + (!tlsPeerFPList.empty() ? tlsPeerFPList.hashCode() : 0);
622+
result= 31*result + (!restrictedAuth.empty() ? restrictedAuth.hashCode() : 0);
616623

617-
result= 31 *result + (!tlsPeerFPList.empty() ? tlsPeerFPList.hashCode() : 0);
618624
return result;
619625
}
620626

src/options/Options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/************************************************************************************
2-
Copyright (C) 2020,2023 MariaDB Corporation AB
2+
Copyright (C) 2020,2025 MariaDB Corporation plc
33
44
This library is free software; you can redistribute it and/or
55
modify it under the terms of the GNU Library General Public
@@ -137,6 +137,7 @@ struct Options
137137
bool useReadAheadInput= true;
138138
SQLString serverRsaPublicKeyFile;
139139
SQLString tlsPeerFP;
140+
SQLString restrictedAuth;
140141

141142
SQLString toString() const;
142143
bool equals(Options* obj);

src/protocol/capi/ConnectProtocol.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ namespace capi
452452
mysql_optionsv(connection.get(), MYSQL_REPORT_DATA_TRUNCATION, &uintOptionSelected);
453453
mysql_optionsv(connection.get(), MYSQL_OPT_LOCAL_INFILE, (options->allowLocalInfile ? &uintOptionSelected : &uintOptionNotSelected));
454454

455+
if (!options.get()->restrictedAuth.empty()) {
456+
mysql_optionsv(connection.get(), MARIADB_OPT_RESTRICTED_AUTH, options.get()->restrictedAuth.c_str());
457+
}
455458
if (mysql_real_connect(connection.get(), NULL, NULL, NULL, NULL, 0, NULL, CLIENT_MULTI_STATEMENTS) == nullptr)
456459
{
457460
throw SQLException(mysql_error(connection.get()), mysql_sqlstate(connection.get()), mysql_errno(connection.get()));

0 commit comments

Comments
 (0)