Re: scram and \password

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Noah Misch <noah(at)leadboat(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Joe Conway <mail(at)joeconway(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: scram and \password
Date: 2017-04-26 10:22:36
Message-ID: 57f8c243-2362-e7b8-4c56-e752ba6edf6c@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 04/25/2017 06:26 PM, Heikki Linnakangas wrote:
> Thoughts? Unless someone has better ideas or objections, I'll go
> implement that.

This is what I came up with in the end. Some highlights and differences
vs the plan I posted earlier:

* If algorithm is not given explicitly, PQencryptPasswordConn() queries
"SHOW password_encryption", and uses that. That is documented, and it is
also documented that it will *not* issue queries, and hence will not
block, if the algorithm is given explicitly. That's an important
property for some applications. If you want the default behavior without
blocking, query "SHOW password_encryption" yourself, and pass the result
as the 'algorithm'.

* In the previous draft, I envisioned an algorithm-specific 'options'
argument. I left it out, on second thoughts (more on that below).

* The old PQencryptPassword() function is unchanged, and always uses
md5. Per public opinion.

We talked about the alternative where PQencryptPasswordConn() would not
look at password_encryption, but would always use the strongest possible
algorithm supported by the server. That would avoid querying the server.
But then I started thinking how this would work, if we make the number
of iterations in the SCRAM verifier configurable in the future. The
client would not know the desired number of iterations based only on the
server version, it would need to query the server, and we would be back
to square one. We could add an "options" argument to
PQencryptPasswordConn() that the application could use to pass that
information, but documenting how to fetch that information, if you don't
want PQencryptPasswordConn() to block, gets tedious, and puts a lot of
burden to applications. That is why I left out the "options" argument,
after all.

I'm now thinking that if we add password hashing options like the
iteration count in the future, they will be tacked on to
password_encryption. For example, "password_encryption='scram-sha-256,
iterations=10000". That way, "password_encryption" will always contain
enough information to construct password verifiers.

What will happen to existing applications using PQencryptPasswordConn()
if a new password_encryption algorithm (or options) is added in the
future? With this scheme, the application doesn't need to know what
algorithms exist. An application can pass algorithm=NULL, to use the
server default, or do "show password_encryption" and pass that, for the
non-blocking behavior. If you use an older libpq against a new server,
so that libpq doesn't know about the algorithm used by the server, you
get an error.

For reviewer convenience, I put up the patched docs at
http://hlinnaka.iki.fi/temp/scram-wip-docs/libpq-misc.html#libpq-pqencryptpasswordconn.

Thoughts? Am I missing anything?

As an alternative, I considered making password_encryption GUC_REPORT,
so that libpq would always know it without having to issue a query. But
it feels wrong to send that option to the client on every connection,
when it's only needed in the rare case that you use
PQencryptPasswordConn(). And if we added new settings like the iteration
count in the future, those would need to be GUC_REPORT too.

- Heikki

Attachment Content-Type Size
0001-Move-scram_build_verifier-to-src-common.patch application/x-download 9.6 KB
0002-Add-PQencryptPasswordConn-function-to-libpq.patch application/x-download 11.8 KB
0003-Use-new-PQencryptPasswordConn-function-in-psql-and-c.patch application/x-download 1.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Antonin Houska 2017-04-26 10:28:02 Re: Partition-wise aggregation/grouping
Previous Message Amit Khandekar 2017-04-26 09:17:16 Re: Declarative partitioning - another take