Skip to content

Commit 22b3453

Browse files
author
Samar Pratap Singh
committed
WL#16269 OpenID Connect (Oauth2 - JWT) Authentication Support
Implements user authentication using OpenID Connect based on the OAuth 2.0 framework of specifications (IETF RFC 6749 and 6750). Change-Id: I11944643d4a6098312edd16550c0160e86905063
1 parent 81355c5 commit 22b3453

28 files changed

+467
-9
lines changed

client/mysql.cc

+29
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static const CHARSET_INFO *charset_info = &my_charset_latin1;
246246

247247
static char *opt_oci_config_file = nullptr;
248248
static char *opt_authentication_oci_client_config_profile = nullptr;
249+
static char *opt_authentication_openid_connect_client_id_token_file = nullptr;
249250
static char *opt_register_factor = nullptr;
250251

251252
static bool opt_tel_plugin = false;
@@ -2080,6 +2081,11 @@ static struct my_option my_long_options[] = {
20802081
"is ~/.oci/config and %HOME/.oci/config on Windows.",
20812082
&opt_oci_config_file, &opt_oci_config_file, nullptr, GET_STR, REQUIRED_ARG,
20822083
0, 0, 0, nullptr, 0, nullptr},
2084+
{"authentication-openid-connect-client-id-token-file", 0,
2085+
"Specifies the location of the ID token file.",
2086+
&opt_authentication_openid_connect_client_id_token_file,
2087+
&opt_authentication_openid_connect_client_id_token_file, nullptr, GET_STR,
2088+
REQUIRED_ARG, 0, 0, 0, nullptr, 0, nullptr},
20832089
{"telemetry-client", 0, "Load the telemetry_client plugin.",
20842090
&opt_tel_plugin, &opt_tel_plugin, nullptr, GET_BOOL, NO_ARG, 0, 0, 0,
20852091
nullptr, 0, nullptr},
@@ -5197,6 +5203,29 @@ static bool init_connection_options(MYSQL *mysql) {
51975203
}
51985204
}
51995205

5206+
/* set authentication_openid_connect_client ID token file option if required
5207+
*/
5208+
if (opt_authentication_openid_connect_client_id_token_file != nullptr) {
5209+
struct st_mysql_client_plugin *openid_connect_plugin =
5210+
mysql_client_find_plugin(mysql, "authentication_openid_connect_client",
5211+
MYSQL_CLIENT_AUTHENTICATION_PLUGIN);
5212+
if (!openid_connect_plugin) {
5213+
put_info("Cannot load the authentication_openid_connect_client plugin.",
5214+
INFO_ERROR);
5215+
return true;
5216+
}
5217+
if (mysql_plugin_options(
5218+
openid_connect_plugin, "id-token-file",
5219+
opt_authentication_openid_connect_client_id_token_file)) {
5220+
put_info(
5221+
"Failed to set id token file for "
5222+
"authentication_openid_connect_client "
5223+
"plugin.",
5224+
INFO_ERROR);
5225+
return true;
5226+
}
5227+
}
5228+
52005229
char error[256]{0};
52015230
#if defined(_WIN32)
52025231
if (set_authentication_kerberos_client_mode(mysql, error, 255)) {
File renamed without changes.
File renamed without changes.

include/mysql.h.pp

+1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
MYSQL_VIO_MEMORY
310310
} protocol;
311311
int socket;
312+
bool is_tls_established;
312313
};
313314
enum net_async_status {
314315
NET_ASYNC_COMPLETE = 0,

include/mysql/client_plugin.h.pp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
MYSQL_VIO_MEMORY
1313
} protocol;
1414
int socket;
15+
bool is_tls_established;
1516
};
1617
enum net_async_status {
1718
NET_ASYNC_COMPLETE = 0,

include/mysql/plugin_auth.h.pp

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
MYSQL_VIO_MEMORY
131131
} protocol;
132132
int socket;
133+
bool is_tls_established;
133134
};
134135
enum net_async_status {
135136
NET_ASYNC_COMPLETE = 0,

include/mysql/plugin_auth_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct MYSQL_PLUGIN_VIO_INFO {
127127
MYSQL_VIO_MEMORY
128128
} protocol;
129129
int socket; /**< it's set, if the protocol is SOCKET or TCP */
130+
bool is_tls_established;
130131
#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
131132
HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
132133
#endif

libmysql/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ ADD_SUBDIRECTORY(fido_client)
304304
# authentication mysql_native_password client plug-in
305305
ADD_SUBDIRECTORY(authentication_native_password)
306306

307+
# authentication openid connect client plug-in
308+
ADD_SUBDIRECTORY(authentication_openid_connect_client)
309+
307310
# Merge several convenience libraries into one big mysqlclient
308311
MERGE_CONVENIENCE_LIBRARIES(mysqlclient ${LIBS_TO_MERGE}
309312
COMPONENT Development

libmysql/authentication_oci_client/authentication_oci_client_plugin.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
#include <iostream>
4242
#include <ostream>
4343

44+
#include "include/base64_encode.h"
4445
#include "sql-common/oci/signing_key.h"
45-
#include "sql-common/oci/ssl.h"
4646
#include "sql-common/oci/utilities.h"
4747

4848
static char *s_oci_config_location = nullptr;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) 2024, Oracle and/or its affiliates.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0,
5+
# as published by the Free Software Foundation.
6+
#
7+
# This program is designed to work with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an additional
11+
# permission to link the program and your derivative works with the
12+
# separately licensed software that they have either included with
13+
# the program or referenced in the documentation.
14+
#
15+
# This program is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License, version 2.0, for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with this program; if not, write to the Free Software
22+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23+
24+
#
25+
# Configuration for building OpenID Connect authentication client Plug-in (client-side)
26+
#
27+
28+
# The client authentication plug-in is part of the community build.
29+
30+
# Skip it if disabled.
31+
IF(NOT WITH_AUTHENTICATION_CLIENT_PLUGINS)
32+
MESSAGE(STATUS "Skipping the OpenID Connect authentication client plugin.")
33+
RETURN()
34+
ENDIF()
35+
36+
DISABLE_MISSING_PROFILE_WARNING()
37+
38+
MYSQL_ADD_PLUGIN(
39+
authentication_openid_connect_client
40+
41+
# Authentication plugin main
42+
authentication_openid_connect_client_plugin.cc
43+
44+
LINK_LIBRARIES mysys OpenSSL::SSL OpenSSL::Crypto
45+
46+
CLIENT_ONLY
47+
MODULE_ONLY MODULE_OUTPUT_NAME "authentication_openid_connect_client"
48+
)
49+
50+
IF(LINUX OR SOLARIS)
51+
SET(PLUGIN_VERSION_FILE
52+
${CMAKE_CURRENT_SOURCE_DIR}/authentication_openid_connect_client.ver)
53+
IF(SOLARIS)
54+
TARGET_LINK_OPTIONS(authentication_openid_connect_client PRIVATE
55+
LINKER:-z,gnu-version-script-compat)
56+
ENDIF()
57+
# hide all symbols in mysys, to avoid ODR violations.
58+
# There is *one* visible symbol: _mysql_client_plugin_declaration_
59+
TARGET_LINK_OPTIONS(authentication_openid_connect_client PRIVATE
60+
LINKER:--version-script=${PLUGIN_VERSION_FILE}
61+
)
62+
SET_TARGET_PROPERTIES(authentication_openid_connect_client
63+
PROPERTIES LINK_DEPENDS ${PLUGIN_VERSION_FILE})
64+
ENDIF()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2024, Oracle and/or its affiliates.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2.0,
5+
# as published by the Free Software Foundation.
6+
#
7+
# This program is designed to work with certain software (including
8+
# but not limited to OpenSSL) that is licensed under separate terms,
9+
# as designated in a particular file or component or in included license
10+
# documentation. The authors of MySQL hereby grant you an additional
11+
# permission to link the program and your derivative works with the
12+
# separately licensed software that they have either included with
13+
# the program or referenced in the documentation.
14+
#
15+
# This program is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License, version 2.0, for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with this program; if not, write to the Free Software
22+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23+
24+
authentication_openid_connect_client
25+
{
26+
global: _mysql_client_plugin_declaration_;
27+
local: *;
28+
};

0 commit comments

Comments
 (0)