Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing SSL certificates to mysql and postgresql #12

Closed
Cattes opened this issue Jan 30, 2020 · 4 comments · Fixed by #34
Closed

Passing SSL certificates to mysql and postgresql #12

Cattes opened this issue Jan 30, 2020 · 4 comments · Fixed by #34
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Cattes
Copy link

Cattes commented Jan 30, 2020

To pass an ssl certiciat to pymysql one can use

Database(creds=DATABASE_CREDS[creds], sql_dir=SQL_DIR, connect_args={"ssl": DATABASE_CREDS['ssl']})

where DATABASE_CREDS['ssl'] contains a dictionary with the entry "ca": "<path to .pem file>

For Postgresql(psycopg2) I have to pass different arguments to the Databse class:

Database(creds=DATABASE_CREDS[creds], connect_args={"sslmode": "require", "sslrootcert": DATABASE_CREDS['ssl']})

I suggest using an "ssl" key in the database creds dictionary and depending on the driver entry it is passed on as a correctly formatted connect_args dict.

@phainom phainom self-assigned this Feb 19, 2020
@phainom phainom added enhancement New feature or request good first issue Good for newcomers labels Feb 19, 2020
@phainom
Copy link
Collaborator

phainom commented Feb 19, 2020

This is a good callout, I will work on it as soon as possible. Note that you can always pass the connection URL as well, including SSL details.

There is a general problem with supporting different SQL dialects with the additional capabilities dbrequests offers compared to eg records, as it became apparent in #11. Please feel free to join the discussion there.

@phainom
Copy link
Collaborator

phainom commented Mar 3, 2020

The problem here is that the handling of SSL arguments is driver specific, ie for postgres, where a lot of very opinionated DBAPIs are out there, there is a difference for every driver used (eg between psycopg2 and pg8000). SQL alchemy chose to not offer an unified syntax for this and I tend to agree, since this would introduce driver specific code into the Database class, while the gain from it seems negligible?

With #14 there will be a way to easily extend dbrequest with driver specific code, so I would vote for creating child classes implementing this for the different drivers.

@wahani
Copy link
Member

wahani commented Apr 26, 2020

We should resolve this together with #27. What I would suggest is, that we allow the credentials object to comprise the connect_args, which are passed on to the sqlalchemy driver. E.G.

creds = {
    host='1.2.3.4',
    ...,
    ssl='/path/to/ssl/cert',
    other_arg=some_value
}

from which we can build the url + the connect_args={ssl='/path/to/ssl/cert', other_arg=some_value}. This would cover the use case in this issue.

SQL alchemy chose to not offer an unified syntax for this and I tend to agree,

I agree. If we construct the connect_args from the creds dict, we can leave it to the user to specify the appropriate settings, e.g. ssl for MySQL and (sslmode, sslrootcert) for PostgreSQL.

Any objections?

@wahani wahani linked a pull request May 2, 2020 that will close this issue
@Cattes
Copy link
Author

Cattes commented May 6, 2020

I think allowing the creds object to contain additional arguments that are passed on to the respective drivers is a good idea. It is what I first tried when I wanted to add the ssl certificate so it is an intuitive approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants