Teradata / PyTd

A Python Module to make it easy to script powerful interactions with Teradata Database in a DevOps friendly way.
MIT License
108 stars 43 forks source link

Issue when loading the driver #113

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hello,

I have an issue regarding loading the driver where the same code works fine with root but not with another user (wabuser) even if the chown/chmod are set correctly.

With root:

Nov  9 09:57:48 master WAB(teradata.tdodbc)[22925]: Loading ODBC Library: /home/wabuser/terachg/lib/libodbc.so
Nov  9 09:57:48 master WAB(teradata.tdodbc)[22925]: Available drivers: Teradata Database ODBC Driver 16.20,

With wabuser

Nov  9 10:04:40 master WAB(teradata.tdodbc)[24114]: Loading ODBC Library: /home/wabuser/terachg/lib/libodbc.so
Nov  9 10:04:40 master WAB(teradata.tdodbc)[24114]: Available drivers:
 ls -l /home/wabuser/terachg/lib/libodbc.so
-rwxr-xr-x 1 root wabuser 2194000 Nov  9 08:58 /home/wabuser/terachg/lib/libodbc.so

I have tried everything mentioned here, from setting env variables, symblink for .so libs.

I had an error regarding our grsec kernel: grsec: denied untrusted exec (due to not being in trusted group and file in non-root-owned directory) of /opt/teradata/client/16.20/lib64/libodbc.so by /usr/bin/python2.7[python:31551] uid/euid:1001/1001 gid/egid:1001/1001, parent /usr/bin/sudo[sudo:31550] uid/euid:0/0 gid/egid:0/0 but it was solved with chown root:wabuser

The python code portion is as follow:

from teradata.api import DatabaseError
from teradata import UdaExec

udaExec = UdaExec(appName="WALLIX Bastion", 
                                version="1.0.0",logConsole=False,
                                odbcLibPath="/home/wabuser/terachg/lib/libodbc.so")
db = udaExec.connect(method="odbc",system=host,username=admin_login,
                                     password=admin_password,
                                     driver="Teradata Database ODBC Driver 16.20")

Any hint will be appreciated.

Thanks

ghost commented 5 years ago

It seems that I am not the only having this behavior: https://github.com/Teradata/PyTd/issues/61#issuecomment-265264319

ghost commented 5 years ago

The problem seems to be related to a permission denied on the following file/directory: /opt/teradata/client/ODBC_64/.runNumber

as the execution with wabuser and root returns the following:

# sudo -u wabuser -g wabuser PYTHONPATH=$PYTHONPATH python -O
Python 2.7.9 (default, Apr 10 2017, 15:10:54) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import teradata
>>> udaExec = teradata.UdaExec(appName="WALLIX Bastion Password Change", version="1.0.0",logConsole=False,odbcLibPath="/opt/teradata/client/ODBC_64/lib/libodbc.so")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/teradata/udaexec.py", line 111, in __init__
    self._initRunNumber(runNumberFile, runNumber, logMsgs)
  File "/usr/local/lib/python2.7/dist-packages/teradata/udaexec.py", line 321, in _initRunNumber
    with open(self.runNumberFile, 'w') as f:
IOError: [Errno 13] Permission denied: '/opt/teradata/client/ODBC_64/.runNumber'
# PYTHONPATH=$PYTHONPATH python -O
Python 2.7.9 (default, Apr 10 2017, 15:10:54) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import teradata
>>> udaExec = teradata.UdaExec(appName="WALLIX Bastion Password Change", version="1.0.0",logConsole=False,odbcLibPath="/opt/teradata/client/ODBC_64/lib/libodbc.so")
ghost commented 5 years ago

I found a solution to my problem.

I need to set logDir and runNumberFile which are by default written in /opt/teradata/client/ODBC_64/

udaExec = teradata.UdaExec(appName="WALLIX Bastion Password Change", version="1.0.0",logConsole=False,odbcLibPath="/home/wabuser/terachg/lib/libodbc.so",runNumberFile="/var/tmp/.runNumber",logDir="/var/tmp/logs")