backends/sqla: allow pgsql conns via unix sockets#1721
Conversation
c7043d3 to
6308fbf
Compare
Codecov Report
@@ Coverage Diff @@
## develop #1721 +/- ##
========================================
Coverage 57.16% 57.16%
========================================
Files 275 275
Lines 33912 33912
========================================
Hits 19386 19386
Misses 14526 14526
Continue to review full report at Codecov.
|
|
@szoupanos Have you checked this out? |
|
Thanks a lot! A few questions/comments: So, if there are no speed benefits, and what I write at (c) is correct (and the default behaviour & the *nix user can create databases) in many systems, it makes sense to do this change. Otherwise, it seems to me that it increases the installation complexity without any big benefits. Do I miss something? |
|
a) there is no speed gain, only advantages in simplicity and security: postgresql doesn't have to listen on a tcp port which could accidentally be exposed and one does not have to manage yet another (usually weak) password (which could be used by another user on the same system to gain access to the database) sudo su - postgres
createuser tiziano
createdb -O tiziano aiida_tiziano |
SQLA/psycopg2 allows connection via unix sockets instead of TCP/IP.
This allows for secure password-less authentication via PostgreSQL's
socket peer authentication, which is the default on many distros.
Example `pg_hba.conf`:
local all all peer
would allow a user `test` access to the PostgreSQL cluster if a user
`test` exists in PostgreSQL without any password (implicitly assuming
that it is sufficient that the user was already authenticated by the
OS).
Using `pg_ident.conf` one can also map local users to PostgreSQL users
with a different name:
Example `pg_hba.conf`:
local aiida aiida peer map=aiida
Example `pg_ident.conf`:
aiida test aiida
Would allow the user `aiida` access to the database `aiida` and the map
allows the system user `test` to impersonate the database user `aiida`.
psycopg2 automatically tries the local socket connection if no port is
specified, but for that must the connection string not contain the
colon char otherwise required for the host:port separation.
6308fbf to
d16008e
Compare
giovannipizzi
left a comment
There was a problem hiding this comment.
I don't see any disadvantage with this patch! I'm approving it.
@dev-zero maybe you can move the content of the PR to an "advanced" section in the docs, explaining how to setup AiiDA with this approach? (and if needed simplifying the current docs)
SQLA/psycopg2 allows connection via unix sockets instead of TCP/IP.
This allows for secure password-less authentication via PostgreSQL's
socket peer authentication, which is the default on many distros.
Example
pg_hba.conf:would allow a user
testaccess to the PostgreSQL cluster if a usertestexists in PostgreSQL without any password (implicitly assumingthat it is sufficient that the user was already authenticated by the
OS).
Using
pg_ident.confone can also map local users to PostgreSQL userswith a different name:
Example
pg_hba.conf:Example
pg_ident.conf:Would allow the user
aiidaaccess to the databaseaiidaand the mapallows the system user
testto impersonate the database useraiida.psycopg2 automatically tries the local socket connection if no port is
specified, but for that must the connection string not contain the
colon char otherwise required for the host:port separation.