1

I am using Uber's vertica-python native python adaptor (https://github.com/uber/vertica-python), and I am trying to integrate kerberos authentication with it. Is there a way I can do it?

Problem: The database user I want to use with my script has authentication method kerberos set to highest priority, seems that vertica-python adaptor has only password based authentication. I read Vertica documentation it said if the priority is set to use Kerberos then its the only authentication method that Vertica asks for.

dr_dino
  • 115
  • 1
  • 2
  • 7

1 Answers1

0

I'm looking for a similar answer to use Vertica with Airflow. In the other hand I can tell you how I use Vertica with Kerberos and Python, in my case I found the best solution is using ODBC.

First install a ODBC client, if you are using Linux or Mac you can follow next site: unixodbc

Then configure a DSN in your client machine, you can just edit the default file on your home folder like this (examples for Mac and Linux): ~/.odbc.ini:

[ConnectionAliasABC]
Description = Database description
# Driver for MAC
# Driver = /Library/Vertica/ODBC/lib/libverticaodbc.dylib
# Driver for Linux
Driver = /opt/vertica/lib64/libverticaodbc.so
Database = DatabaseName
ServerName = ServerHost
UID = username
Port = 5433
KerberosServiceName = kerberosServiceName
KerberosHostname = kerberosHostname

Then you can use the next code snippet:

    import pyodbc


    # here you should init a kerberos ticket, we use a keytab file for this
    initKerberos()

    odbc_dsn = 'ConnectionAliasABC' # same as the .odbc.ini file section

    print(f'Connecting to Vertica using dsn: {odbc_dsn}')

    connection = pyodbc.connect(f'DSN={odbc_dsn}')
    connection.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
    connection.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
    connection.setdecoding(pyodbc.SQL_WMETADATA, encoding='utf-16')
    connection.setencoding(encoding='utf-8')

    cursor = conn.cursor()
    cursor.execute("SELECT dummy as test_column_name FROM DUAL")
    row = cursor.fetchone()
    print(f'query result: {row[0]}') # this should show an 'X'

Carlos Verdes
  • 3,037
  • 22
  • 20