Skip to content

Commit 9262b0d

Browse files
isrgomeznmariz
authored andcommitted
WL#14710: Support OCI IAM authentication
This worklog adds the authentication support for the Identity Manager (IAM) service of the Oracle's Cloud (OCI).
1 parent 240f24a commit 9262b0d

File tree

16 files changed

+405
-54
lines changed

16 files changed

+405
-54
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Full release notes:
1111
v8.0.27
1212
=======
1313

14+
- WL#14710: Support OCI IAM authentication
1415
- WL#14689: Fallback conversion to str for types incompatible with MySQL
1516
- WL#14664: Allow SSPI Kerberos library usage with c-ext
1617
- BUG#33177337: Connection with chained SSL certs fails with ssl_verify_identity

cpydist/__init__.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
from distutils.version import LooseVersion
4646
from subprocess import check_call, Popen, PIPE
4747

48-
from .utils import ARCH, mysql_c_api_info, write_info_src, write_info_bin
48+
from .utils import (ARCH, ARCH_64BIT, mysql_c_api_info, write_info_src,
49+
write_info_bin)
4950

5051

5152
# Load version information
@@ -251,12 +252,6 @@ def _copy_vendor_libraries(self):
251252
(plugin_path, [os.path.join("plugin", plugin_name)])
252253
)
253254

254-
if bundle_plugin_libs and os.name == "nt":
255-
sasl_libs_path = os.path.join(self.with_mysql_capi, "bin")
256-
sasl_plugin_libs = ["libsasl.dll", "saslSCRAM.dll",
257-
"libcrypto-1_1-x64.dll"]
258-
vendor_libs.append((sasl_libs_path, sasl_plugin_libs))
259-
260255
# authentication_kerberos_client
261256
plugin_name = (
262257
"authentication_kerberos_client.{}".format(plugin_ext)
@@ -269,9 +264,51 @@ def _copy_vendor_libraries(self):
269264
(plugin_path, [os.path.join("plugin", plugin_name)])
270265
)
271266

267+
# authentication_oci_client
268+
plugin_name = (
269+
"authentication_oci_client.{}".format(plugin_ext)
270+
)
271+
plugin_full_path = os.path.join(plugin_path, plugin_name)
272+
self.log.debug("OCI IAM plugin_path: '%s'", plugin_full_path)
273+
if os.path.exists(plugin_full_path):
274+
bundle_plugin_libs = True
275+
vendor_libs.append(
276+
(plugin_path, [os.path.join("plugin", plugin_name)])
277+
)
278+
279+
# vendor libraries
280+
if bundle_plugin_libs and os.name == "nt":
281+
plugin_libs = []
282+
libs_path = os.path.join(self.with_mysql_capi, "bin")
283+
for lib_name in ["libsasl.dll", "saslSCRAM.dll"]:
284+
if os.path.exists(os.path.join(libs_path, lib_name)):
285+
plugin_libs.append(lib_name)
286+
if plugin_libs:
287+
vendor_libs.append((libs_path, plugin_libs))
288+
289+
if ARCH_64BIT:
290+
openssl_libs = ["libssl-1_1-x64.dll",
291+
"libcrypto-1_1-x64.dll"]
292+
else:
293+
openssl_libs = ["libssl-1_1.dll", "libcrypto-1_1.dll"]
294+
if self.with_openssl_lib_dir:
295+
openssl_libs_path = os.path.abspath(self.with_openssl_lib_dir)
296+
if os.path.basename(openssl_libs_path) == "lib":
297+
openssl_libs_path = os.path.split(openssl_libs_path)[0]
298+
if os.path.exists(openssl_libs_path) and \
299+
os.path.exists(os.path.join(openssl_libs_path, "bin")):
300+
openssl_libs_path = os.path.join(openssl_libs_path, "bin")
301+
self.log.info("# openssl_libs_path: %s", openssl_libs_path)
302+
else:
303+
openssl_libs_path = os.path.join(
304+
self.with_mysql_capi, "bin")
305+
vendor_libs.append((openssl_libs_path, openssl_libs))
306+
272307
if not vendor_libs:
273308
return
274309

310+
self.log.debug("# vendor_libs: %s", vendor_libs)
311+
275312
# mysql/vendor
276313
if not os.path.exists(self.vendor_folder):
277314
mkpath(os.path.join(os.getcwd(), self.vendor_folder))
@@ -598,6 +635,20 @@ def run(self):
598635
if os.name == "posix":
599636
ext.extra_compile_args.append("-Wno-unknown-pragmas")
600637

638+
if os.name != "nt":
639+
cmd_gcc_ver = ["gcc", "-v"]
640+
self.log.info("Executing: {0}"
641+
"".format(" ".join(cmd_gcc_ver)))
642+
proc = Popen(cmd_gcc_ver, stdout=PIPE,
643+
universal_newlines=True)
644+
self.log.info(proc.communicate())
645+
cmd_gpp_ver = ["g++", "-v"]
646+
self.log.info("Executing: {0}"
647+
"".format(" ".join(cmd_gcc_ver)))
648+
proc = Popen(cmd_gpp_ver, stdout=PIPE,
649+
universal_newlines=True)
650+
self.log.info(proc.communicate())
651+
601652
# Remove disabled extensions
602653
for ext in disabled:
603654
self.extensions.remove(ext)

cpydist/bdist_msi.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,32 @@ def _finalize_connector_c(self, connc_loc):
159159
if not os.path.isdir(connc_loc):
160160
self.log.error("MySQL C API should be a directory")
161161
sys.exit(1)
162-
162+
self.log.info("# Locating OpeenSSL libraries")
163163
copy_tree(os.path.join(connc_loc, "lib"), self._connc_lib)
164164
copy_tree(os.path.join(connc_loc, "include"), self._connc_include)
165165

166+
self.log.info("# self.with_openssl_lib_dir: %s", self.with_openssl_lib_dir)
166167
if ARCH_64BIT:
167-
for filename in ["libssl-1_1-x64.dll", "libcrypto-1_1-x64.dll"]:
168-
src = os.path.join(connc_loc, "bin", filename)
169-
dst = self._connc_lib
170-
self.log.info("copying {0} -> {1}".format(src, dst))
171-
shutil.copy(src, dst)
168+
openssl_files = ["libssl-1_1-x64.dll", "libcrypto-1_1-x64.dll"]
172169
else:
173-
for filename in ["libssl-1_1.dll", "libcrypto-1_1.dll"]:
170+
openssl_files = ["libssl-1_1.dll", "libcrypto-1_1.dll"]
171+
172+
for filename in openssl_files:
173+
if self.with_openssl_lib_dir:
174+
openssl_lib_dir = os.path.abspath(self.with_openssl_lib_dir)
175+
if os.path.basename(openssl_lib_dir) == "lib":
176+
openssl_lib_dir = os.path.split(openssl_lib_dir)[0]
177+
if os.path.exists(openssl_lib_dir) and \
178+
os.path.exists(os.path.join(openssl_lib_dir, "bin")):
179+
openssl_lib_dir = os.path.join(openssl_lib_dir, "bin")
180+
self.log.info("# openssl_lib_dir: %s", openssl_lib_dir)
181+
src = os.path.join(openssl_lib_dir, filename)
182+
else:
174183
src = os.path.join(connc_loc, "bin", filename)
175-
dst = self._connc_lib
176-
self.log.info("copying {0} -> {1}".format(src, dst))
177-
shutil.copy(src, dst)
184+
self.log.info("Using %s: located in %s", filename, src)
185+
dst = self._connc_lib
186+
self.log.info("copying {0} -> {1}".format(src, dst))
187+
shutil.copy(src, dst)
178188

179189
for lib_file in os.listdir(self._connc_lib):
180190
if os.name == "posix" and not lib_file.endswith('.a'):
@@ -391,6 +401,7 @@ def _create_msi(self, dry_run=0):
391401
params["HaveCExt{}{}".format(*ver)] = 0
392402
params["HaveLdapLibs{}{}".format(*ver)] = 0
393403
params["HaveKerberosLibs{}{}".format(*ver)] = 0
404+
params["HaveOCILibs{}{}".format(*ver)] = 0
394405
params["HavePlugin{}{}".format(*ver)] = 0
395406

396407
if py_ver in self.pyver_bdist_paths:
@@ -413,6 +424,12 @@ def _create_msi(self, dry_run=0):
413424
"authentication_kerberos_client.dll")):
414425
params["HaveKerberosLibs{}{}".format(*ver)] = 1
415426
have_plugins = True
427+
if os.path.exists(
428+
os.path.join(self.pyver_bdist_paths[py_ver],
429+
"mysql", "vendor", "plugin",
430+
"authentication_oci_client.dll")):
431+
params["HaveOCILibs{}{}".format(*ver)] = 1
432+
have_plugins = True
416433
if have_plugins:
417434
params["HavePlugin{}{}".format(*ver)] = 1
418435

cpydist/data/msi/PY36.wxs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,25 @@
135135
</DirectoryRef>
136136

137137
<DirectoryRef Id="VendorDir36">
138-
<?if $(var.HaveLdapLibs36) = 1 ?>
138+
<?if $(var.HaveCExt36) = 1 ?>
139139
<Component Id="Vendor36" Guid="3fdebba4-be39-11ea-b0cc-04ea56793316" Win64="$(var.Win64)">
140+
<?if "$(var.Platform)"="x64" ?>
141+
<File Id="libcrypto_1_136" Name="libcrypto-1_1-x64.dll"
142+
Source="$(var.BDist36)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143+
<File Id="libssl_1_136" Name="libssl-1_1-x64.dll"
144+
Source="$(var.BDist36)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
145+
<?else?>
146+
<File Id="libcrypto_1_136" Name="libcrypto-1_1.dll"
147+
Source="$(var.BDist36)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148+
<File Id="libssl_1_136" Name="libssl-1_1.dll"
149+
Source="$(var.BDist36)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
150+
<?endif?>
151+
<?if $(var.HaveLdapLibs36) = 1 ?>
140152
<File Id="libsasl36" Name="libsasl.dll"
141153
Source="$(var.BDist36)\mysql\vendor\libsasl.dll" DiskId="1"/>
142-
<File Id="libcrypto_1_136" Name="libcrypto-1_1-x64.dll"
143-
Source="$(var.BDist36)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
144154
<File Id="saslSCRAM36" Name="saslSCRAM.dll"
145155
Source="$(var.BDist36)\mysql\vendor\saslSCRAM.dll" DiskId="1"/>
156+
<?endif?>
146157
</Component>
147158
<?endif?>
148159
</DirectoryRef>
@@ -157,6 +168,10 @@
157168
<File Id="authentication_kerberos_client36" Name="authentication_kerberos_client.dll"
158169
Source="$(var.BDist36)\mysql\vendor\plugin\authentication_kerberos_client.dll" DiskId="1"/>
159170
<?endif?>
171+
<?if $(var.HaveOCILibs36) = 1 ?>
172+
<File Id="authentication_oci_client36" Name="authentication_oci_client.dll"
173+
Source="$(var.BDist36)\mysql\vendor\plugin\authentication_oci_client.dll" DiskId="1"/>
174+
<?endif?>
160175
</Component>
161176
<?endif?>
162177
</DirectoryRef>

cpydist/data/msi/PY37.wxs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,25 @@
135135
</DirectoryRef>
136136

137137
<DirectoryRef Id="VendorDir37">
138-
<?if $(var.HaveLdapLibs37) = 1 ?>
138+
<?if $(var.HaveCExt37) = 1 ?>
139139
<Component Id="Vendor37" Guid="103f2914-be39-11ea-98b1-04ea56793316" Win64="$(var.Win64)">
140+
<?if "$(var.Platform)"="x64" ?>
141+
<File Id="libcrypto_1_137" Name="libcrypto-1_1-x64.dll"
142+
Source="$(var.BDist37)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143+
<File Id="libssl_1_137" Name="libssl-1_1-x64.dll"
144+
Source="$(var.BDist37)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
145+
<?else?>
146+
<File Id="libcrypto_1_137" Name="libcrypto-1_1.dll"
147+
Source="$(var.BDist37)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148+
<File Id="libssl_1_137" Name="libssl-1_1.dll"
149+
Source="$(var.BDist37)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
150+
<?endif?>
151+
<?if $(var.HaveLdapLibs37) = 1 ?>
140152
<File Id="libsasl37" Name="libsasl.dll"
141153
Source="$(var.BDist37)\mysql\vendor\libsasl.dll" DiskId="1"/>
142-
<File Id="libcrypto_1_137" Name="libcrypto-1_1-x64.dll"
143-
Source="$(var.BDist37)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
144154
<File Id="saslSCRAM37" Name="saslSCRAM.dll"
145155
Source="$(var.BDist37)\mysql\vendor\saslSCRAM.dll" DiskId="1"/>
156+
<?endif?>
146157
</Component>
147158
<?endif?>
148159
</DirectoryRef>
@@ -157,6 +168,10 @@
157168
<File Id="authentication_kerberos_client37" Name="authentication_kerberos_client.dll"
158169
Source="$(var.BDist37)\mysql\vendor\plugin\authentication_kerberos_client.dll" DiskId="1"/>
159170
<?endif?>
171+
<?if $(var.HaveOCILibs37) = 1 ?>
172+
<File Id="authentication_oci_client37" Name="authentication_oci_client.dll"
173+
Source="$(var.BDist37)\mysql\vendor\plugin\authentication_oci_client.dll" DiskId="1"/>
174+
<?endif?>
160175
</Component>
161176
<?endif?>
162177
</DirectoryRef>

cpydist/data/msi/PY38.wxs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,25 @@
135135
</DirectoryRef>
136136

137137
<DirectoryRef Id="VendorDir38">
138-
<?if $(var.HaveLdapLibs38) = 1 ?>
138+
<?if $(var.HaveCExt38) = 1 ?>
139139
<Component Id="Vendor38" Guid="681a48cd-be38-11ea-84eb-04ea56793316" Win64="$(var.Win64)">
140+
<?if "$(var.Platform)"="x64" ?>
141+
<File Id="libcrypto_1_138" Name="libcrypto-1_1-x64.dll"
142+
Source="$(var.BDist38)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143+
<File Id="libssl_1_138" Name="libssl-1_1-x64.dll"
144+
Source="$(var.BDist38)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
145+
<?else?>
146+
<File Id="libcrypto_1_138" Name="libcrypto-1_1.dll"
147+
Source="$(var.BDist38)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148+
<File Id="libssl_1_138" Name="libssl-1_1.dll"
149+
Source="$(var.BDist38)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
150+
<?endif?>
151+
<?if $(var.HaveLdapLibs38) = 1 ?>
140152
<File Id="libsasl38" Name="libsasl.dll"
141153
Source="$(var.BDist38)\mysql\vendor\libsasl.dll" DiskId="1"/>
142-
<File Id="libcrypto_1_138" Name="libcrypto-1_1-x64.dll"
143-
Source="$(var.BDist38)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
144154
<File Id="saslSCRAM38" Name="saslSCRAM.dll"
145155
Source="$(var.BDist38)\mysql\vendor\saslSCRAM.dll" DiskId="1"/>
156+
<?endif?>
146157
</Component>
147158
<?endif?>
148159
</DirectoryRef>
@@ -157,6 +168,10 @@
157168
<File Id="authentication_kerberos_client38" Name="authentication_kerberos_client.dll"
158169
Source="$(var.BDist38)\mysql\vendor\plugin\authentication_kerberos_client.dll" DiskId="1"/>
159170
<?endif?>
171+
<?if $(var.HaveOCILibs38) = 1 ?>
172+
<File Id="authentication_oci_client38" Name="authentication_oci_client.dll"
173+
Source="$(var.BDist38)\mysql\vendor\plugin\authentication_oci_client.dll" DiskId="1"/>
174+
<?endif?>
160175
</Component>
161176
<?endif?>
162177
</DirectoryRef>

cpydist/data/msi/PY39.wxs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,25 @@
135135
</DirectoryRef>
136136

137137
<DirectoryRef Id="VendorDir39">
138-
<?if $(var.HaveLdapLibs39) = 1 ?>
138+
<?if $(var.HaveCExt39) = 1 ?>
139139
<Component Id="Vendor39" Guid="ba33e641-5337-4e26-9db5-4c8084b48b3f" Win64="$(var.Win64)">
140+
<?if "$(var.Platform)"="x64" ?>
141+
<File Id="libcrypto_1_139" Name="libcrypto-1_1-x64.dll"
142+
Source="$(var.BDist39)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143+
<File Id="libssl_1_139" Name="libssl-1_1-x64.dll"
144+
Source="$(var.BDist39)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
145+
<?else?>
146+
<File Id="libcrypto_1_139" Name="libcrypto-1_1.dll"
147+
Source="$(var.BDist39)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148+
<File Id="libssl_1_139" Name="libssl-1_1.dll"
149+
Source="$(var.BDist39)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
150+
<?endif?>
151+
<?if $(var.HaveLdapLibs39) = 1 ?>
140152
<File Id="libsasl39" Name="libsasl.dll"
141153
Source="$(var.BDist39)\mysql\vendor\libsasl.dll" DiskId="1"/>
142-
<File Id="libcrypto_1_139" Name="libcrypto-1_1-x64.dll"
143-
Source="$(var.BDist39)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
144154
<File Id="saslSCRAM39" Name="saslSCRAM.dll"
145155
Source="$(var.BDist39)\mysql\vendor\saslSCRAM.dll" DiskId="1"/>
156+
<?endif?>
146157
</Component>
147158
<?endif?>
148159
</DirectoryRef>
@@ -157,6 +168,10 @@
157168
<File Id="authentication_kerberos_client39" Name="authentication_kerberos_client.dll"
158169
Source="$(var.BDist39)\mysql\vendor\plugin\authentication_kerberos_client.dll" DiskId="1"/>
159170
<?endif?>
171+
<?if $(var.HaveOCILibs39) = 1 ?>
172+
<File Id="authentication_oci_client39" Name="authentication_oci_client.dll"
173+
Source="$(var.BDist39)\mysql\vendor\plugin\authentication_oci_client.dll" DiskId="1"/>
174+
<?endif?>
160175
</Component>
161176
<?endif?>
162177
</DirectoryRef>

cpydist/data/msi/product.wxs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,8 @@
318318
<Condition Level='0'>Not PYTHON36INSTALLPATH_ALL AND Not PYTHON36INSTALLPATH_CURRENT AND Not Installed</Condition>
319319
<ComponentRef Id="EggInfo36"/>
320320
<ComponentRef Id="MySQLPackage36"/>
321-
<?if $(var.HaveLdapLibs36) = 1 ?>
321+
<?if $(var.HaveCExt36) = 1 ?>
322322
<ComponentRef Id="Vendor36"/>
323-
<?endif?>
324-
<?if $(var.HavePlugin36) = 1 ?>
325323
<ComponentRef Id="VendorPlugin36"/>
326324
<?endif?>
327325
<ComponentRef Id="ConnectorPackage36"/>
@@ -345,10 +343,8 @@
345343
<Condition Level='0'>Not PYTHON37INSTALLPATH_ALL AND Not PYTHON37INSTALLPATH_CURRENT AND Not Installed</Condition>
346344
<ComponentRef Id="EggInfo37"/>
347345
<ComponentRef Id="MySQLPackage37"/>
348-
<?if $(var.HaveLdapLibs37) = 1 ?>
346+
<?if $(var.HaveCExt37) = 1 ?>
349347
<ComponentRef Id="Vendor37"/>
350-
<?endif?>
351-
<?if $(var.HavePlugin37) = 1 ?>
352348
<ComponentRef Id="VendorPlugin37"/>
353349
<?endif?>
354350
<ComponentRef Id="ConnectorPackage37"/>
@@ -372,10 +368,8 @@
372368
<Condition Level='0'>Not PYTHON38INSTALLPATH_ALL AND Not PYTHON38INSTALLPATH_CURRENT AND Not Installed</Condition>
373369
<ComponentRef Id="EggInfo38"/>
374370
<ComponentRef Id="MySQLPackage38"/>
375-
<?if $(var.HaveLdapLibs38) = 1 ?>
371+
<?if $(var.HaveCExt38) = 1 ?>
376372
<ComponentRef Id="Vendor38"/>
377-
<?endif?>
378-
<?if $(var.HavePlugin38) = 1 ?>
379373
<ComponentRef Id="VendorPlugin38"/>
380374
<?endif?>
381375
<ComponentRef Id="ConnectorPackage38"/>
@@ -399,10 +393,8 @@
399393
<Condition Level='0'>Not PYTHON39INSTALLPATH_ALL AND Not PYTHON39INSTALLPATH_CURRENT AND Not Installed</Condition>
400394
<ComponentRef Id="EggInfo39"/>
401395
<ComponentRef Id="MySQLPackage39"/>
402-
<?if $(var.HaveLdapLibs39) = 1 ?>
396+
<?if $(var.HaveCExt39) = 1 ?>
403397
<ComponentRef Id="Vendor39"/>
404-
<?endif?>
405-
<?if $(var.HavePlugin39) = 1 ?>
406398
<ComponentRef Id="VendorPlugin39"/>
407399
<?endif?>
408400
<ComponentRef Id="ConnectorPackage39"/>

cpydist/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def _mysql_c_api_info_win(mysql_capi):
182182
os.path.join(mysql_capi, "lib", "libmysql.dll"))
183183
LOGGER.debug("connc_64bit: {0}".format(connc_64bit))
184184
info["arch"] = "x86_64" if connc_64bit else "i386"
185+
LOGGER.debug("# _mysql_c_api_info_win info: %s", info)
185186

186187
return info
187188

lib/mysql/connector/abstracts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(self, **kwargs):
104104
self._ssl = {}
105105
self._ssl_disabled = DEFAULT_CONFIGURATION["ssl_disabled"]
106106
self._force_ipv6 = False
107+
self._oci_config_file = None
107108

108109
self._use_unicode = True
109110
self._get_warnings = False

0 commit comments

Comments
 (0)