python-oracledb: cannot mTLS connect to Oracle DB on Amazon RDS service in Thin mode #62
-
Context I can't develop and test directly on my local computer, since the way I access the DB is different there:
I'm already responsible for the maintenance of a project which uses jobs done through pods created in that VPN, so what I do to dev is that I manually create such a pod, and tests things whitin it. The pods for this projet are created through the use of a Docker image which has been prepared to contain the Oracle instantclient software, and the program uses cx_Oracle to connect. To achieve the connection we need to use mTLS, through the use of a .sso wallet file. I read the doc in order to know how to replicate that when using Thin mode of python-oracledb, but I was unable to do so. Code # encoding: utf-8
import oracledb
import os
username = os.environ["ORACLE_USER"]
password = os.environ["ORACLE_PASSWORD"]
dsn = """(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=DB_NAME.ap-southeast-1.rds.amazonaws.com)(PORT=2484))(CONNECT_DATA=(SID=XXXXX)(SERVICE_NAME=XXXXX)))"""
lib_dir = "/opt/instantclient_19_3"
config_dir = "/opt/oracle/network/admin"
wall_loc = "/code/wallet2"
wall_pw = None
# wall_pw = ""
use_thick_mode = False
kwargs = {
"config_dir": config_dir,
"wallet_location": wall_loc,
"wallet_password": wall_pw,
}
if use_thick_mode:
oracledb.init_oracle_client(lib_dir=lib_dir)
kwargs = {}
with oracledb.connect(
user=username,
password=password,
dsn=dsn,
**kwargs,
) as ocon:
with ocon.cursor() as cursor:
sql = """select '['||systimestamp||'] Connectivity OK' from dual"""
for r in cursor.execute(sql):
print(r[0]) Error root@POD_NAME:/code# python test_oracledb_connect2.py
Traceback (most recent call last):
File "src/oracledb/impl/thin/connection.pyx", line 97, in oracledb.thin_impl.ThinConnImpl._connect_with_address
File "src/oracledb/impl/thin/protocol.pyx", line 145, in oracledb.thin_impl.Protocol._connect_phase_one
File "src/oracledb/impl/thin/protocol.pyx", line 279, in oracledb.thin_impl.Protocol._connect_tcp
File "src/oracledb/impl/thin/crypto.pyx", line 118, in oracledb.thin_impl.get_ssl_socket
ssl.SSLError: [SSL] PEM lib (_ssl.c:3932)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test_oracledb_connect2.py", line 31, in <module>
**kwargs,
File "/usr/local/lib/python3.7/site-packages/oracledb/connection.py", line 1000, in connect
return conn_class(dsn=dsn, pool=pool, params=params, **kwargs)
File "/usr/local/lib/python3.7/site-packages/oracledb/connection.py", line 128, in __init__
impl.connect(params_impl)
File "src/oracledb/impl/thin/connection.pyx", line 294, in oracledb.thin_impl.ThinConnImpl.connect
File "src/oracledb/impl/thin/connection.pyx", line 184, in oracledb.thin_impl.ThinConnImpl._connect_with_params
File "src/oracledb/impl/thin/connection.pyx", line 157, in oracledb.thin_impl.ThinConnImpl._connect_with_description
File "src/oracledb/impl/thin/connection.pyx", line 109, in oracledb.thin_impl.ThinConnImpl._connect_with_address
File "/usr/local/lib/python3.7/site-packages/oracledb/errors.py", line 103, in _raise_err
raise exc_type(_Error(message)) from cause
oracledb.exceptions.OperationalError: DPY-6005: cannot connect to database. Connection failed with "[SSL] PEM lib (_ssl.c:3932)" What I've tried When I remove the ewallet file from the expected location, there is an error message that says that the file is missing: oracledb.exceptions.ProgrammingError: DPY-2018: cannot connect to database. Wallet file /code/wallet2/ewallet.pem was not found When I create an empty cwallet.pem file, and put it where oracledb is expecting it when using Thin mode, there is an error message that says that the file does not contain a certificate: oracledb.exceptions.OperationalError: DPY-6005: cannot connect to database. Connection failed with "[X509] no certificate or crl found (_ssl.c:4140)" So I'm confident that oracledb is able to find the file, load its content, and search for a certificate. I'm not too sure what to do regarding the wallet_password value, since I have no info about that from the source of the .pem file: the Amazon site does not say anything about that, so I'm assuming that I don't need to specify anything? francois@francois-laptop#:~/ python create_pem.py --wallet-password "XXXXX" ./
Traceback (most recent call last):
File "create_pem.py", line 45, in <module>
f.write(private_key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8,
AttributeError: 'NoneType' object has no attribute 'private_bytes' Finally, I've also tried to test this using the 1.0.0, 1.0.1, and 1.0.2 version of oracledb (I use 1.0.3 when I ask to install the library without specifying the version), but I always got the same underlying error: "[SSL] PEM lib (_ssl.c:3932)". Question
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
Hi, @FrancoisNoyez, thanks for the detailed descriptions of what you did. If you are using mTLS the Regarding the conversion from .p12 to .pem -- it looks like you don't have a private key in the .p12 file. Where did you get that file from? For Oracle Cloud databases, the wallet is downloaded from console and is a zip file containing these files:
Thick mode doesn't look at |
Beta Was this translation helpful? Give feedback.
-
For the record, this was enhanced in python-oracledb 1.2. See #65 |
Beta Was this translation helpful? Give feedback.
For the record, this was enhanced in python-oracledb 1.2. See #65