Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlAlchemy + psycopg2 using ssl certificate

So far I was using just psycopg2 to create my postgresql connection like

connection = psy.connect(host=self.host, port=self.port, dbname=self.database, user=self.user, password=os.environ.get('POSTGRES_READONLY_USER_PASSWORD'), sslmode=self.sslmode, sslrootcert=os.environ.get('CA_FILE_PATH'))

however seeing now that it is deprecated I wanted to switch to sqlalchmey + psycopg2. I am using a CA.pem certificate for ssl, which works fine in the old version

I tried

args = {
        'host' : self.host,
        'user' : self.user,
        'password' : os.environ.get('POSTGRES_READONLY_USER_PASSWORD'),    
        'port' : self.port,
        'dbname' : self.database,
        'sslmode' : 'require',
        'sslrootcert' : os.environ.get('CA_FILE_PATH')
        }

    engine = sqlalchemy.create_engine("postgresql+psycopg2://", connect_args=args)
    connection = engine.connect()

But I am getting an error

Exception has occurred: OperationalError
(psycopg2.OperationalError) connection to server at "postgres.amf" (10.10.10.20), port 5433 failed: certificate present, but not private key file "C:\Users\Administrator\AppData\Roaming/postgresql/postgresql.key"

Anyone knows how I can get this working without the additional private keys ????

like image 275
ThatQuantDude Avatar asked Nov 27 '25 12:11

ThatQuantDude


1 Answers

I had

'sslcert' : os.environ.get('CA_FILE_PATH')

which was supposed to be

'sslrootcert' : os.environ.get('CA_FILE_PATH')
like image 114
ThatQuantDude Avatar answered Nov 30 '25 03:11

ThatQuantDude