Re: [PATCH v15] GSSAPI encryption support

Lists: pgsql-hackers
From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH v1] GSSAPI encryption support
Date: 2015-07-02 18:22:13
Message-ID: jlg1tgq1ktm.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello -hackers,

As previously discussed on this list, I have coded up GSSAPI encryption
support. If it is easier for anyone, this code is also available for
viewing on my github:
https://github.com/postgres/postgres/compare/master...frozencemetery:feature/gssencrypt

Fallback support is present in both directions for talking to old client
and old servers; GSSAPI encryption is by default auto-upgraded to where
available (for compatibility), but both client and server contain
settings for requiring it.

There are 8 commits in this series; I have tried to err on the side of
creating too much separation rather than too little. A patch for each
is attached. This is v1 of the series.

Thanks!

Attachment Content-Type Size
v1-1-build-Define-with_gssapi-for-use-in-Makefiles.patch text/x-diff 1.4 KB
v1-2-client-Disable-GSS-encryption-on-old-servers.patch text/x-diff 3.8 KB
v1-3-client-GSSAPI-encryption-and-decryption.patch text/x-diff 7.4 KB
v1-4-server-GSSAPI-encryption-and-decryption.patch text/x-diff 9.8 KB
v1-5-Error-when-receiving-plaintext-on-GSS-encrypted-conn.patch text/x-diff 3.4 KB
v1-6-server-hba-option-for-requiring-GSSAPI-encryption.patch text/x-diff 3.4 KB
v1-7-client-gss_enc_require-parameter-to-force-GSS-encryp.patch text/x-diff 3.0 KB
v1-8-Document-GSSAPI-encryption.patch text/x-diff 6.8 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-07-06 13:53:07
Message-ID: 20150706135307.GN12131@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> As previously discussed on this list, I have coded up GSSAPI encryption
> support. If it is easier for anyone, this code is also available for
> viewing on my github:
> https://github.com/postgres/postgres/compare/master...frozencemetery:feature/gssencrypt
>
> Fallback support is present in both directions for talking to old client
> and old servers; GSSAPI encryption is by default auto-upgraded to where
> available (for compatibility), but both client and server contain
> settings for requiring it.
>
> There are 8 commits in this series; I have tried to err on the side of
> creating too much separation rather than too little. A patch for each
> is attached. This is v1 of the series.

Excellent, thanks! I've got other things to tend to at the moment, but
this is definitely something I'm interested in and will work on (likely
in August).

If we could get a reviewer or two to take a look and take the patch out
for a test-drive, at least, that would be a huge help.

Thanks again!

Stephen


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-08-21 13:18:18
Message-ID: CAB7nPqRGQ60PWLb-CLLrvMoQwPAbnu-961W+xGPvG62RMSkcZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jul 3, 2015 at 3:22 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:

> Hello -hackers,
>
> As previously discussed on this list, I have coded up GSSAPI encryption
> support. If it is easier for anyone, this code is also available for
> viewing on my github:
>
> https://github.com/postgres/postgres/compare/master...frozencemetery:feature/gssencrypt
>
> Fallback support is present in both directions for talking to old client
> and old servers; GSSAPI encryption is by default auto-upgraded to where
> available (for compatibility), but both client and server contain
> settings for requiring it.
>
> There are 8 commits in this series; I have tried to err on the side of
> creating too much separation rather than too little. A patch for each
> is attached. This is v1 of the series.
>

I just had a quick look at this patch, and here are some comments:
+ <para>
+ If the client has probed <acronym>GSSAPI</acronym> encryption support
and
+ the connection is <acronym>GSSAPI</acronym>-authenticated, then after
the
+ server sends AuthenticationOk, all traffic between the client and
server
+ will be <acronym>GSSAPI</acronym>-encrypted. Because
+ <acronym>GSSAPI</acronym> does not provide framing,
+ <acronym>GSSAPI</acronym>-encrypted messages are modeled after
protocol-3
+ messages: the first byte is the caracter g, then four bytes of length,
and
+ then an encrypted message.
+ </para>
Message formats should be described in protocol.sgml in the section for
message formats.

+ network. In the <filename>pg_hba.conf</> file, the GSS authenticaion
+ method has a parameter to require encryption; otherwise, connections
+ will be encrypted if available and requiested by the client. On the
s/authenticaion/authentication
s/requiested/requested

+ Whether to require GSSAPI encryption. Default is off, which causes
+ GSSAPI encryption to be enabled if available and requested for
+ compatability with old clients. It is recommended to set this
unless
+ old clients are present.
s/compatability/compatibility

Going through the docs, the overall approach taken by the patch looks neat,
and the default values as designed for both the client and the server are
good things to do. Now actually looking at the code I am suspecting that
some code portions could be largely simplified in the authentication
protocol code, though I don't have the time yet to look at that in details.

Also, when trying to connect with GSSAPI, I found the following problem:
psql: lost synchronization with server: got message type "S", length 22
This happens whatever the value of require_encrypt on server-side is,
either 0 or 1.
Regards,
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-08-21 19:06:15
Message-ID: jlgmvxk31i0.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Fri, Jul 3, 2015 at 3:22 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>
>> There are 8 commits in this series; I have tried to err on the side of
>> creating too much separation rather than too little. A patch for each
>> is attached. This is v1 of the series.
>
> I just had a quick look at this patch, and here are some comments:

Hi! Thanks for taking it for a spin.

> + <para>
> + If the client has probed <acronym>GSSAPI</acronym> encryption support and
> + the connection is <acronym>GSSAPI</acronym>-authenticated, then after the
> + server sends AuthenticationOk, all traffic between the client and server
> + will be <acronym>GSSAPI</acronym>-encrypted. Because
> + <acronym>GSSAPI</acronym> does not provide framing,
> + <acronym>GSSAPI</acronym>-encrypted messages are modeled after protocol-3
> + messages: the first byte is the caracter g, then four bytes of length, and
> + then an encrypted message.
> + </para>
>
> Message formats should be described in protocol.sgml in the section for
> message formats.

ACK. In next version of patch.

> + network. In the <filename>pg_hba.conf</> file, the GSS authenticaion
> + method has a parameter to require encryption; otherwise, connections
> + will be encrypted if available and requiested by the client. On the
> s/authenticaion/authentication
> s/requiested/requested
>
> + Whether to require GSSAPI encryption. Default is off, which causes
> + GSSAPI encryption to be enabled if available and requested for
> + compatability with old clients. It is recommended to set this
> unless
> + old clients are present.
> s/compatability/compatibility

Thanks for catching these. They'll be included in a new version of the
series, which I'll post once you and I have resolved the issue at the
bottom.

> Going through the docs, the overall approach taken by the patch looks neat,
> and the default values as designed for both the client and the server are
> good things to do. Now actually looking at the code I am suspecting that
> some code portions could be largely simplified in the authentication
> protocol code, though I don't have the time yet to look at that in details.

If there are ways to make it simpler without sacrificing clarity, I
welcome them. Fresh eyes could definitely help with that!

> Also, when trying to connect with GSSAPI, I found the following problem:
> psql: lost synchronization with server: got message type "S", length 22
> This happens whatever the value of require_encrypt on server-side is,
> either 0 or 1.

Well that's not good! Since I'm not seeing this failure (even after
rebuilding my setup with patches applied to master), can you give me
more information here? Since it's independent of require_encrypt, can
you verify it doesn't happen on master without my patches? What
messages went over the wire to/from the server before this occurred (and
what was it trying to send at the time)? Did you have valid
credentials?


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-08-22 05:47:56
Message-ID: CAB7nPqTfCC3Dg1eMHPmNoPRmt+rU_Jsf=kFfHVw8iPVVLOaqbg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Aug 22, 2015 at 4:06 AM, Robbie Harwood wrote:
>
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
> > Going through the docs, the overall approach taken by the patch looks neat,
> > and the default values as designed for both the client and the server are
> > good things to do. Now actually looking at the code I am suspecting that
> > some code portions could be largely simplified in the authentication
> > protocol code, though I don't have the time yet to look at that in details.
>
> If there are ways to make it simpler without sacrificing clarity, I
> welcome them. Fresh eyes could definitely help with that!

I'll look at that more at next week or the week after.

> > Also, when trying to connect with GSSAPI, I found the following problem:
> > psql: lost synchronization with server: got message type "S", length 22
> > This happens whatever the value of require_encrypt on server-side is,
> > either 0 or 1.
>
> Well that's not good! Since I'm not seeing this failure (even after
> rebuilding my setup with patches applied to master), can you give me
> more information here? Since it's independent of require_encrypt, can
> you verify it doesn't happen on master without my patches?

Well, I imagine that I have done nothing complicated... I have simply
set up a Kerberos KDC on a dev box, created necessary credentials on
this box in a keytab file that I have used afterwards to initialize a
Kerberos context with kinit for the psql client. On master things
worked fine, I was able to connect via gssapi. But with your patch the
communication protocol visibly lost track of the messages. I took a
memo about that, it's a bit rough, does not use pg_ident, but if that
can help:
http://michael.otacoo.com/manuals/postgresql/kerberos/

> What messages went over the wire to/from the server before this occurred (and
> what was it trying to send at the time)?

I haven't checked what were the messages sent over the network yet.

> Did you have valid credentials?

Yep. I just tried on master before switching to a build with your
patch that failed. After moving back to master things worked again.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-08 19:12:49
Message-ID: jlg37yo7mj2.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Fri, Jul 3, 2015 at 3:22 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>
>> Hello -hackers,
>>
>> As previously discussed on this list, I have coded up GSSAPI encryption
>> support. If it is easier for anyone, this code is also available for
>> viewing on my github:
>>
>> https://github.com/postgres/postgres/compare/master...frozencemetery:feature/gssencrypt
>>
>> Fallback support is present in both directions for talking to old client
>> and old servers; GSSAPI encryption is by default auto-upgraded to where
>> available (for compatibility), but both client and server contain
>> settings for requiring it.
>>
>> There are 8 commits in this series; I have tried to err on the side of
>> creating too much separation rather than too little. A patch for each
>> is attached. This is v1 of the series.
>
> I just had a quick look at this patch, and here are some comments:
> + <para>
> + If the client has probed <acronym>GSSAPI</acronym> encryption support
> and
> + the connection is <acronym>GSSAPI</acronym>-authenticated, then after
> the
> + server sends AuthenticationOk, all traffic between the client and
> server
> + will be <acronym>GSSAPI</acronym>-encrypted. Because
> + <acronym>GSSAPI</acronym> does not provide framing,
> + <acronym>GSSAPI</acronym>-encrypted messages are modeled after
> protocol-3
> + messages: the first byte is the caracter g, then four bytes of length,
> and
> + then an encrypted message.
> + </para>
> Message formats should be described in protocol.sgml in the section for
> message formats.
>
> + network. In the <filename>pg_hba.conf</> file, the GSS authenticaion
> + method has a parameter to require encryption; otherwise, connections
> + will be encrypted if available and requiested by the client. On the
> s/authenticaion/authentication
> s/requiested/requested
>
> + Whether to require GSSAPI encryption. Default is off, which causes
> + GSSAPI encryption to be enabled if available and requested for
> + compatability with old clients. It is recommended to set this
> unless
> + old clients are present.
> s/compatability/compatibility

As promised, here's a V2 to address your issues with comments. I
haven't heard back on the issues you found in testing, so no other
changes are present.

This means that only the last patch has changed. For convenience, I
will therefore only provide this new patch. I have also updated the
version available from my github.

Thanks!

Attachment Content-Type Size
v2-8-Document-GSSAPI-encryption.patch text/x-diff 8.0 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-09 06:57:38
Message-ID: CAB7nPqTQM5dfhMh6yskkt=w1032iJ8ggnJu9y+tZBmwwhzEZKw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Sep 9, 2015 at 4:12 AM, Robbie Harwood wrote:
> Michael Paquier writes:
> As promised, here's a V2 to address your issues with comments. I
> haven't heard back on the issues you found in testing, so no other
> changes are present.

Well, the issue is still here: login through gssapi fails with your
patch, not with HEAD. This patch is next on my review list by the way
so I'll see what I can do about it soon even if I am in the US for
Postgres Open next week. Still, how did you test it? I am just
creating by myself a KDC, setting up a valid credential with kinit,
and after setting up Postgres for this purpose the protocol
communication just fails.

> This means that only the last patch has changed. For convenience, I
> will therefore only provide this new patch. I have also updated the
> version available from my github.

Thanks, this looks better. I have updated my local branch by replacing
the last patch of the previous series by this one, so I'll base any
potential hacking on this one.
Regards,
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-09 16:44:49
Message-ID: jlgsi6n8rum.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Wed, Sep 9, 2015 at 4:12 AM, Robbie Harwood wrote:
>> Michael Paquier writes:
>> As promised, here's a V2 to address your issues with comments. I
>> haven't heard back on the issues you found in testing, so no other
>> changes are present.
>
> Well, the issue is still here: login through gssapi fails with your
> patch, not with HEAD. This patch is next on my review list by the way
> so I'll see what I can do about it soon even if I am in the US for
> Postgres Open next week. Still, how did you test it? I am just
> creating by myself a KDC, setting up a valid credential with kinit,
> and after setting up Postgres for this purpose the protocol
> communication just fails.

My KDC is setup through freeIPA; I create a service for postgres,
acquire a keytab, set it in the config file, and fire up the server. It
should go without saying that this is working for me, which is why I
asked you for more information so I could try to debug. I wrote a post
on this back in June when this was still in development:
http://mivehind.net/page/view-page-slug/16/postgres-kerberos


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-10 07:27:53
Message-ID: CAB7nPqQ7daftDPRTxvyPBFLmZnX-0vTku+H1ft7tqNmSxca3BA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 10, 2015 at 1:44 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
>> On Wed, Sep 9, 2015 at 4:12 AM, Robbie Harwood wrote:
>>> Michael Paquier writes:
>>> As promised, here's a V2 to address your issues with comments. I
>>> haven't heard back on the issues you found in testing, so no other
>>> changes are present.
>>
>> Well, the issue is still here: login through gssapi fails with your
>> patch, not with HEAD. This patch is next on my review list by the way
>> so I'll see what I can do about it soon even if I am in the US for
>> Postgres Open next week. Still, how did you test it? I am just
>> creating by myself a KDC, setting up a valid credential with kinit,
>> and after setting up Postgres for this purpose the protocol
>> communication just fails.
>
> My KDC is setup through freeIPA; I create a service for postgres,
> acquire a keytab, set it in the config file, and fire up the server. It
> should go without saying that this is working for me, which is why I
> asked you for more information so I could try to debug. I wrote a post
> on this back in June when this was still in development:
> http://mivehind.net/page/view-page-slug/16/postgres-kerberos

Hm. OK. I'll give it a try with freeipa and your patch with Fedora for
example. Could you as well try the configuration I have used? In any
case, it seems to me that we have a real problem with your patch: the
gss authentication protocol is broken with your patch and *not* HEAD
when using a custom kdc like the one I have set up manually on one of
my VMs.
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-11 07:40:50
Message-ID: CAB7nPqTgr+aOZFmbORwxX9sZ7f3re4FuQFZyqdHP8AnOZPqrgw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Sep 10, 2015 at 4:27 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Thu, Sep 10, 2015 at 1:44 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>
>>> On Wed, Sep 9, 2015 at 4:12 AM, Robbie Harwood wrote:
>>>> Michael Paquier writes:
>>>> As promised, here's a V2 to address your issues with comments. I
>>>> haven't heard back on the issues you found in testing, so no other
>>>> changes are present.
>>>
>>> Well, the issue is still here: login through gssapi fails with your
>>> patch, not with HEAD. This patch is next on my review list by the way
>>> so I'll see what I can do about it soon even if I am in the US for
>>> Postgres Open next week. Still, how did you test it? I am just
>>> creating by myself a KDC, setting up a valid credential with kinit,
>>> and after setting up Postgres for this purpose the protocol
>>> communication just fails.
>>
>> My KDC is setup through freeIPA; I create a service for postgres,
>> acquire a keytab, set it in the config file, and fire up the server. It
>> should go without saying that this is working for me, which is why I
>> asked you for more information so I could try to debug. I wrote a post
>> on this back in June when this was still in development:
>> http://mivehind.net/page/view-page-slug/16/postgres-kerberos
> Hm. OK. I'll give it a try with freeipa and your patch with Fedora for
> example. Could you as well try the configuration I have used? In any
> case, it seems to me that we have a real problem with your patch: the
> gss authentication protocol is broken with your patch and *not* HEAD
> when using a custom kdc like the one I have set up manually on one of
> my VMs.

Looking more at this stuff. Your post assumes that you have an IPA
server available (I am not really familiar with this software stack)
already configured at hand so as you do not need to worry about any
low-level configuration and a KDC is provided as well, among other
things like ntpd or an apache instance. Well, the thing is that we
just need is a KDC for this patch to have an environment suitable for
testing, and some magic commands with kadmin.local, kinit, etc, and
not the whole set of features that an IPA server provides (when
kicking ipa-server-install one needs to provide a realm name, a KDC
admin password, so that's basically just a wrapper setting up
krb5.conf, which is handy when you want to have the full set in your
hands actually, though just to test this patch it does not seem worth
it). And I imagine that you do have an IPA server already set
facilitating your work.

Still, I gave it a try on a Fedora host, giving up after facing
several failures when trying to install the server. because of several
features.

Note that by duckduckging around I have bumped into some more
documentation to set up KDC with Postgres:
http://gpdb.docs.pivotal.io/4320/admin_guide/kerberos.html
This may be useful when testing this patch as well.
Regards,
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-16 19:22:59
Message-ID: jlgvbba5fu4.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Thu, Sep 10, 2015 at 4:27 PM, Michael Paquier <michael(dot)paquier(at)gmail(dot)com> wrote:
>> On Thu, Sep 10, 2015 at 1:44 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>>> On Wed, Sep 9, 2015 at 4:12 AM, Robbie Harwood wrote:
>>>>> Michael Paquier writes:
>>>>> As promised, here's a V2 to address your issues with comments. I
>>>>> haven't heard back on the issues you found in testing, so no other
>>>>> changes are present.
>>>>
>>>> Well, the issue is still here: login through gssapi fails with your
>>>> patch, not with HEAD. This patch is next on my review list by the
>>>> way so I'll see what I can do about it soon even if I am in the US
>>>> for Postgres Open next week. Still, how did you test it? I am just
>>>> creating by myself a KDC, setting up a valid credential with kinit,
>>>> and after setting up Postgres for this purpose the protocol
>>>> communication just fails.
>>>
>>> My KDC is setup through freeIPA; I create a service for postgres,
>>> acquire a keytab, set it in the config file, and fire up the server.
>>> It should go without saying that this is working for me, which is
>>> why I asked you for more information so I could try to debug. I
>>> wrote a post on this back in June when this was still in
>>> development:
>>> http://mivehind.net/page/view-page-slug/16/postgres-kerberos
>>
>> Hm. OK. I'll give it a try with freeipa and your patch with Fedora
>> for example. Could you as well try the configuration I have used? In
>> any case, it seems to me that we have a real problem with your patch:
>> the gss authentication protocol is broken with your patch and *not*
>> HEAD when using a custom kdc like the one I have set up manually on
>> one of my VMs.
>
> Looking more at this stuff. Your post assumes that you have an IPA
> server available (I am not really familiar with this software stack)
> already configured at hand so as you do not need to worry about any
> low-level configuration and a KDC is provided as well, among other
> things like ntpd or an apache instance. Well, the thing is that we
> just need is a KDC for this patch to have an environment suitable for
> testing, and some magic commands with kadmin.local, kinit, etc, and
> not the whole set of features that an IPA server provides (when
> kicking ipa-server-install one needs to provide a realm name, a KDC
> admin password, so that's basically just a wrapper setting up
> krb5.conf, which is handy when you want to have the full set in your
> hands actually, though just to test this patch it does not seem worth
> it). And I imagine that you do have an IPA server already set
> facilitating your work.
>
> Still, I gave it a try on a Fedora host, giving up after facing
> several failures when trying to install the server. because of several
> features.

I'm sorry to hear that FreeIPA didn't work for you. I'd be remiss if I
didn't suggest you file bugs against the project for things that are
broken, though that's somewhat orthogonal to the patchset at hand.

I gave your setup a try; I spun up a fc22 machine (krb5v1.13.2), and
installed the KDC as per your instructions. I only did two things
differently: I'm using the default unit file for krb5kdc, and I'm using
the postgres base dir /var/lib/pgsql/data (this is a Fedora default and
I'm sure it doesn't matter for purposes of this).

I have no issues, no sync loss; nothing is amiss as far as I can see.
If there is actually a problem here, I need more information from you.
At the very least, as previously mentioned, I need to know what messages
went over the wire to/from the server before it occurred, and what
command (if it it made it to command processing) it was in the midst of
sending.

Thanks,
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-09-29 14:53:31
Message-ID: jlgsi5xb7kk.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:

>>>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>>>
>>>>> Well, the issue is still here: login through gssapi fails with
>>>>> your patch, not with HEAD. This patch is next on my review list by
>>>>> the way so I'll see what I can do about it soon even if I am in
>>>>> the US for Postgres Open next week. Still, how did you test it? I
>>>>> am just creating by myself a KDC, setting up a valid credential
>>>>> with kinit, and after setting up Postgres for this purpose the
>>>>> protocol communication just fails.
>
> I have no issues, no sync loss; nothing is amiss as far as I can see.
> If there is actually a problem here, I need more information from you.
> At the very least, as previously mentioned, I need to know what
> messages went over the wire to/from the server before it occurred, and
> what command (if it it made it to command processing) it was in the
> midst of sending.

Any follow-up on this? I'd really like my code to be bug-free.


From: Andres Freund <andres(at)anarazel(dot)de>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-10-03 16:18:10
Message-ID: 20151003161810.GD30738@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

I quickly read through the patch, trying to understand what exactly is
happening here. To me the way the patch is split doesn't make much sense
- I don't mind incremental patches, but right now the steps don't
individually make sense.

On 2015-07-02 14:22:13 -0400, Robbie Harwood wrote:
> +#include <assert.h>

postgres.h should be the first header included.

> +size_t
> +be_gss_encrypt(Port *port, char msgtype, const char **msgptr, size_t len)
> +{
> + OM_uint32 major, minor;
> + gss_buffer_desc input, output;
> + uint32 len_n;
> + int conf;
> + char *ptr = *((char **)msgptr);

trivial nitpick, missing spaces...

> +int
> +be_gss_inplace_decrypt(StringInfo inBuf)
> +{
> + OM_uint32 major, minor;
> + gss_buffer_desc input, output;
> + int qtype, conf;
> + size_t msglen = 0;
> +
> + input.length = inBuf->len;
> + input.value = inBuf->data;
> + output.length = 0;
> + output.value = NULL;
> +
> + major = gss_unwrap(&minor, MyProcPort->gss->ctx, &input, &output,
> + &conf, NULL);
> + if (GSS_ERROR(major))
> + {
> + pg_GSS_error(ERROR, gettext_noop("wrapping GSS message failed"),
> + major, minor);
> + return -1;
> + }
> + else if (conf == 0)
> + {
> + ereport(COMMERROR,
> + (errcode(ERRCODE_PROTOCOL_VIOLATION),
> + errmsg("Expected GSSAPI confidentiality but it was not received")));
> + return -1;
> + }

Hm. Aren't we leaking the gss buffer here?

> + qtype = ((char *)output.value)[0]; /* first byte is message type */
> + inBuf->len = output.length - 5; /* message starts */
> +
> + memcpy((char *)&msglen, ((char *)output.value) + 1, 4);
> + msglen = ntohl(msglen);
> + if (msglen - 4 != inBuf->len)
> + {
> + ereport(COMMERROR,
> + (errcode(ERRCODE_PROTOCOL_VIOLATION),
> + errmsg("Length value inside GSSAPI-encrypted packet was malformed")));
> + return -1;
> + }

and here?

Arguably it doesn't matter that much, since we'll usually disconnect
around here, but ...

> + memcpy(inBuf->data, ((char *)output.value) + 5, inBuf->len);
> + inBuf->data[inBuf->len] = '\0'; /* invariant */
> + gss_release_buffer(&minor, &output);
> +
> + return qtype;
> +}

> diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
> index a4b37ed..5a929a8 100644
> --- a/src/backend/libpq/pqcomm.c
> +++ b/src/backend/libpq/pqcomm.c
> @@ -1485,6 +1485,19 @@ socket_putmessage(char msgtype, const char *s, size_t len)
> {
> if (DoingCopyOut || PqCommBusy)
> return 0;
> +
> +#ifdef ENABLE_GSS
> + /* Do not wrap auth requests. */
> + if (MyProcPort->hba->auth_method == uaGSS && gss_encrypt &&
> + msgtype != 'R' && msgtype != 'g')
> + {
> + len = be_gss_encrypt(MyProcPort, msgtype, &s, len);
> + if (len < 0)
> + goto fail;
> + msgtype = 'g';
> + }
> +#endif

Putting encryption specific code here feels rather wrong to me.

> diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h
> index 6171ef3..58712fc 100644
> --- a/src/include/libpq/libpq-be.h
> +++ b/src/include/libpq/libpq-be.h
> @@ -30,6 +30,8 @@
> #endif
>
> #ifdef ENABLE_GSS
> +#include "lib/stringinfo.h"
> +

Conditionally including headers providing generic infrastructure strikes
me as a recipe for build failures in different configurations.

> /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
> diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
> index c408e5b..e788cc8 100644
> --- a/src/include/libpq/libpq.h
> +++ b/src/include/libpq/libpq.h
> @@ -99,4 +99,8 @@ extern char *SSLCipherSuites;
> extern char *SSLECDHCurve;
> extern bool SSLPreferServerCiphers;
>
> +#ifdef ENABLE_GSS
> +extern bool gss_encrypt;
> +#endif

> --- a/src/backend/utils/misc/guc.c
> +++ b/src/backend/utils/misc/guc.c
>
> +#ifdef ENABLE_GSS
> +static void assign_gss_encrypt(bool newval, void *extra);
> +#endif
> +
>
> /*
> * Options for enum values defined in this module.
> @@ -1618,6 +1622,15 @@ static struct config_bool ConfigureNamesBool[] =
> NULL, NULL, NULL
> },
>
> + {
> + {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
> + gettext_noop("Whether client wants encryption for this connection."),
> + NULL,
> + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
> + },
> + &gss_encrypt, false, NULL, assign_gss_encrypt, NULL
> + },
> +
> /* End-of-list marker */
> {
> {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
> @@ -10114,4 +10127,10 @@ show_log_file_mode(void)
> return buf;
> }

The guc should always be present, not just when gss is built in. It
should error out when not supported. As is you're going to get linker
errors around gss_encrypt, assign_gss_encrypt.

> From e55795e0638ca37447ef200f21f74db80b07ebf4 Mon Sep 17 00:00:00 2001
> From: "Robbie Harwood (frozencemetery)" <rharwood(at)redhat(dot)com>
> Date: Fri, 12 Jun 2015 13:27:50 -0400
> Subject: Error when receiving plaintext on GSS-encrypted connections

I don't see why this makes sense as a separate patch.

> Subject: server: hba option for requiring GSSAPI encryption
>
> Also includes logic for failing clients that do not request encryption
> in the startup packet when encryption is required.
> ---
> src/backend/libpq/hba.c | 9 +++++++++
> src/backend/utils/init/postinit.c | 7 ++++++-
> src/backend/utils/misc/guc.c | 12 +++++++++++-
> src/include/libpq/hba.h | 1 +
> 4 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
> index 23c8b5d..90fe57f 100644
> --- a/src/backend/libpq/hba.c
> +++ b/src/backend/libpq/hba.c
> @@ -1570,6 +1570,15 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, int line_num)
> else
> hbaline->include_realm = false;
> }
> + else if (strcmp(name, "require_encrypt") == 0)
> + {
> + if (hbaline->auth_method != uaGSS)
> + INVALID_AUTH_OPTION("require_encrypt", "gssapi");
> + if (strcmp(val, "1") == 0)
> + hbaline->require_encrypt = true;
> + else
> + hbaline->require_encrypt = false;
> + }

So this is a new, undocumented, option that makes a connection require
encryption? But despite the generic name, it's gss specific?

> @@ -1628,7 +1629,7 @@ static struct config_bool ConfigureNamesBool[] =
> NULL,
> GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
> },
> - &gss_encrypt, false, NULL, assign_gss_encrypt, NULL
> + &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
> },
>
> /* End-of-list marker */
> @@ -10133,4 +10134,13 @@ assign_gss_encrypt(bool newval, void *extra)
> gss_encrypt = newval;
> }
>
> +static bool
> +check_gss_encrypt(bool *newval, void **extra, GucSource source)
> +{
> + if (MyProcPort && MyProcPort->hba && MyProcPort->hba->require_encrypt &&
> + !*newval)
> + return false;
> + return true;
> +}

Doing such checks in a guc assign hook seems like a horrible idea. Yes,
there's some precedent, but still.

Greetings,

Andres Freund


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-10-06 06:13:20
Message-ID: CAB7nPqTJD-tTrM1Vu8P55_4kKVeDX8DFz9v1D_XsQQvR_xA5qQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Oct 4, 2015 at 1:18 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> Hi,
>
> I quickly read through the patch, trying to understand what exactly is
> happening here. To me the way the patch is split doesn't make much sense
> - I don't mind incremental patches, but right now the steps don't
> individually make sense.

I agree with Andres. While I looked a bit at this patch, I just had a
look at them a whole block and not individually.

> On 2015-07-02 14:22:13 -0400, Robbie Harwood wrote:
> [Andres' comments]

Here are some comments on top of what Andres has mentioned.

--- a/configure.in
+++ b/configure.in
@@ -636,6 +636,7 @@ PGAC_ARG_BOOL(with, gssapi, no, [build with GSSAPI support],
krb_srvtab="FILE:\$(sysconfdir)/krb5.keytab"
])
AC_MSG_RESULT([$with_gssapi])
+AC_SUBST(with_gssapi)

I think that using a new configure variable like that with a dedicated
file fe-secure-gss.c and be-secure-gss.c has little sense done this
way, and that it would be more adapted to get everything grouped in
fe-auth.c for the frontend and auth.c for the backend, or move all the
GSSAPI-related stuff in its own file. I can understand the move
though: this is to imitate OpenSSL in a way somewhat similar to what
has been done for it with a rather generic set if routines, but with
GSSAPI that's a bit different, we do not have such a set of routines,
hence based on this argument moving it to its own file has little
sense. Now, a move that would make sense though is to move all the
GSSAPI stuff in its own file, for example pg_GSS_recvauth and
pg_GSS_error for the backend, and you should do the same for the
frontend with all the pg_GSS_* routines. This should be as well a
refactoring patch on top of the actual feature.

diff --git a/src/interfaces/libpq/fe-secure-gss.c
b/src/interfaces/libpq/fe-secure-gss.c
new file mode 100644
index 0000000..afea9c3
--- /dev/null
+++ b/src/interfaces/libpq/fe-secure-gss.c
@@ -0,0 +1,92 @@
+#include <assert.h>
You should add a proper header to those new files.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-10-09 18:04:43
Message-ID: jlgr3l33olg.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:

> Hi,

Hi, thanks for the review; I really appreciate your time in going
through this. I have questions about some of your comments, so I'll
wait a bit before sending a v3. (By the way, there is a v2 of this I've
already posted, though you seem to have replied to the v1. The only
difference is in documentation, though.)

> I quickly read through the patch, trying to understand what exactly is
> happening here. To me the way the patch is split doesn't make much sense
> - I don't mind incremental patches, but right now the steps don't
> individually make sense.

That's fair. Can you suggest a better organization?

> On 2015-07-02 14:22:13 -0400, Robbie Harwood wrote:
>> +#include <assert.h>
>
> postgres.h should be the first header included.

Okay, will fix.

>> +size_t
>> +be_gss_encrypt(Port *port, char msgtype, const char **msgptr, size_t len)
>> +{
>> + OM_uint32 major, minor;
>> + gss_buffer_desc input, output;
>> + uint32 len_n;
>> + int conf;
>> + char *ptr = *((char **)msgptr);
>
> trivial nitpick, missing spaces...

Got it.

>> +int
>> +be_gss_inplace_decrypt(StringInfo inBuf)
>> +{
>> + OM_uint32 major, minor;
>> + gss_buffer_desc input, output;
>> + int qtype, conf;
>> + size_t msglen = 0;
>> +
>> + input.length = inBuf->len;
>> + input.value = inBuf->data;
>> + output.length = 0;
>> + output.value = NULL;
>> +
>> + major = gss_unwrap(&minor, MyProcPort->gss->ctx, &input, &output,
>> + &conf, NULL);
>> + if (GSS_ERROR(major))
>> + {
>> + pg_GSS_error(ERROR, gettext_noop("wrapping GSS message failed"),
>> + major, minor);
>> + return -1;
>> + }
>> + else if (conf == 0)
>> + {
>> + ereport(COMMERROR,
>> + (errcode(ERRCODE_PROTOCOL_VIOLATION),
>> + errmsg("Expected GSSAPI confidentiality but it was not received")));
>> + return -1;
>> + }
>
> Hm. Aren't we leaking the gss buffer here?
>
>> + qtype = ((char *)output.value)[0]; /* first byte is message type */
>> + inBuf->len = output.length - 5; /* message starts */
>> +
>> + memcpy((char *)&msglen, ((char *)output.value) + 1, 4);
>> + msglen = ntohl(msglen);
>> + if (msglen - 4 != inBuf->len)
>> + {
>> + ereport(COMMERROR,
>> + (errcode(ERRCODE_PROTOCOL_VIOLATION),
>> + errmsg("Length value inside GSSAPI-encrypted packet was malformed")));
>> + return -1;
>> + }
>
> and here?
>
> Arguably it doesn't matter that much, since we'll usually disconnect
> around here, but ...

Probably better to be cautious about it. Will fix.

>> diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
>> index a4b37ed..5a929a8 100644
>> --- a/src/backend/libpq/pqcomm.c
>> +++ b/src/backend/libpq/pqcomm.c
>> @@ -1485,6 +1485,19 @@ socket_putmessage(char msgtype, const char *s, size_t len)
>> {
>> if (DoingCopyOut || PqCommBusy)
>> return 0;
>> +
>> +#ifdef ENABLE_GSS
>> + /* Do not wrap auth requests. */
>> + if (MyProcPort->hba->auth_method == uaGSS && gss_encrypt &&
>> + msgtype != 'R' && msgtype != 'g')
>> + {
>> + len = be_gss_encrypt(MyProcPort, msgtype, &s, len);
>> + if (len < 0)
>> + goto fail;
>> + msgtype = 'g';
>> + }
>> +#endif
>
> Putting encryption specific code here feels rather wrong to me.

Do you have a suggestion about where this code *should* go? I need to
filter on the message type since some can't be encrypted. I was unable
to find another place, but I may have missed it.

>> diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h
>> index 6171ef3..58712fc 100644
>> --- a/src/include/libpq/libpq-be.h
>> +++ b/src/include/libpq/libpq-be.h
>> @@ -30,6 +30,8 @@
>> #endif
>>
>> #ifdef ENABLE_GSS
>> +#include "lib/stringinfo.h"
>> +
>
> Conditionally including headers providing generic infrastructure strikes
> me as a recipe for build failures in different configurations.

That's fair, will fix.

>> /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
>> diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
>> index c408e5b..e788cc8 100644
>> --- a/src/include/libpq/libpq.h
>> +++ b/src/include/libpq/libpq.h
>> @@ -99,4 +99,8 @@ extern char *SSLCipherSuites;
>> extern char *SSLECDHCurve;
>> extern bool SSLPreferServerCiphers;
>>
>> +#ifdef ENABLE_GSS
>> +extern bool gss_encrypt;
>> +#endif
>
>> --- a/src/backend/utils/misc/guc.c
>> +++ b/src/backend/utils/misc/guc.c
>>
>> +#ifdef ENABLE_GSS
>> +static void assign_gss_encrypt(bool newval, void *extra);
>> +#endif
>> +
>>
>> /*
>> * Options for enum values defined in this module.
>> @@ -1618,6 +1622,15 @@ static struct config_bool ConfigureNamesBool[] =
>> NULL, NULL, NULL
>> },
>>
>> + {
>> + {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
>> + gettext_noop("Whether client wants encryption for this connection."),
>> + NULL,
>> + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
>> + },
>> + &gss_encrypt, false, NULL, assign_gss_encrypt, NULL
>> + },
>> +
>> /* End-of-list marker */
>> {
>> {NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL
>> @@ -10114,4 +10127,10 @@ show_log_file_mode(void)
>> return buf;
>> }
>
> The guc should always be present, not just when gss is built in. It
> should error out when not supported. As is you're going to get linker
> errors around gss_encrypt, assign_gss_encrypt.

If that is the style I will conform to it.

>> From e55795e0638ca37447ef200f21f74db80b07ebf4 Mon Sep 17 00:00:00 2001
>> From: "Robbie Harwood (frozencemetery)" <rharwood(at)redhat(dot)com>
>> Date: Fri, 12 Jun 2015 13:27:50 -0400
>> Subject: Error when receiving plaintext on GSS-encrypted connections
>
> I don't see why this makes sense as a separate patch.

As previously stated, if there is another organization you prefer,
please suggest it. As stated in my first email, I have attempted to err
on the side of having too many patches since splitting changesets later
is nontrivial, and squashing is easy.

>> Subject: server: hba option for requiring GSSAPI encryption
>>
>> Also includes logic for failing clients that do not request encryption
>> in the startup packet when encryption is required.
>> ---
>> src/backend/libpq/hba.c | 9 +++++++++
>> src/backend/utils/init/postinit.c | 7 ++++++-
>> src/backend/utils/misc/guc.c | 12 +++++++++++-
>> src/include/libpq/hba.h | 1 +
>> 4 files changed, 27 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
>> index 23c8b5d..90fe57f 100644
>> --- a/src/backend/libpq/hba.c
>> +++ b/src/backend/libpq/hba.c
>> @@ -1570,6 +1570,15 @@ parse_hba_auth_opt(char *name, char *val, HbaLine *hbaline, int line_num)
>> else
>> hbaline->include_realm = false;
>> }
>> + else if (strcmp(name, "require_encrypt") == 0)
>> + {
>> + if (hbaline->auth_method != uaGSS)
>> + INVALID_AUTH_OPTION("require_encrypt", "gssapi");
>> + if (strcmp(val, "1") == 0)
>> + hbaline->require_encrypt = true;
>> + else
>> + hbaline->require_encrypt = false;
>> + }
>
> So this is a new, undocumented, option that makes a connection require
> encryption? But despite the generic name, it's gss specific?

It was not my intent to leave it undocumented; I believe I documented it
as part of my changes. If there is a place I have missed where it
should be documented, please tell me and I will happily document it there.

>> @@ -1628,7 +1629,7 @@ static struct config_bool ConfigureNamesBool[] =
>> NULL,
>> GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
>> },
>> - &gss_encrypt, false, NULL, assign_gss_encrypt, NULL
>> + &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
>> },
>>
>> /* End-of-list marker */
>> @@ -10133,4 +10134,13 @@ assign_gss_encrypt(bool newval, void *extra)
>> gss_encrypt = newval;
>> }
>>
>> +static bool
>> +check_gss_encrypt(bool *newval, void **extra, GucSource source)
>> +{
>> + if (MyProcPort && MyProcPort->hba && MyProcPort->hba->require_encrypt &&
>> + !*newval)
>> + return false;
>> + return true;
>> +}
>
> Doing such checks in a guc assign hook seems like a horrible idea. Yes,
> there's some precedent, but still.

Where would you prefer they go? Isn't this what check hooks are for -
checking that it's valid to assign?

Thanks!
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-10-09 18:10:16
Message-ID: jlgoag73oc7.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Sun, Oct 4, 2015 at 1:18 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:
>> Hi,
>>
>> I quickly read through the patch, trying to understand what exactly is
>> happening here. To me the way the patch is split doesn't make much sense
>> - I don't mind incremental patches, but right now the steps don't
>> individually make sense.
>
> I agree with Andres. While I looked a bit at this patch, I just had a
> look at them a whole block and not individually.

I'm hearing block from both of you! Okay, if block is desired, I'll
squish for v3. Sorry for the inconvenience.

>> On 2015-07-02 14:22:13 -0400, Robbie Harwood wrote:
>> [Andres' comments]
>
> Here are some comments on top of what Andres has mentioned.
>
> --- a/configure.in
> +++ b/configure.in
> @@ -636,6 +636,7 @@ PGAC_ARG_BOOL(with, gssapi, no, [build with GSSAPI support],
> krb_srvtab="FILE:\$(sysconfdir)/krb5.keytab"
> ])
> AC_MSG_RESULT([$with_gssapi])
> +AC_SUBST(with_gssapi)
>
> I think that using a new configure variable like that with a dedicated
> file fe-secure-gss.c and be-secure-gss.c has little sense done this
> way, and that it would be more adapted to get everything grouped in
> fe-auth.c for the frontend and auth.c for the backend, or move all the
> GSSAPI-related stuff in its own file. I can understand the move
> though: this is to imitate OpenSSL in a way somewhat similar to what
> has been done for it with a rather generic set if routines, but with
> GSSAPI that's a bit different, we do not have such a set of routines,
> hence based on this argument moving it to its own file has little
> sense. Now, a move that would make sense though is to move all the
> GSSAPI stuff in its own file, for example pg_GSS_recvauth and
> pg_GSS_error for the backend, and you should do the same for the
> frontend with all the pg_GSS_* routines. This should be as well a
> refactoring patch on top of the actual feature.

My understanding is that frontend and backend code need to be separate
(for linking), so it's automatically in two places. I really don't want
to put encryption-related code in files called "auth.c" and "fe-auth.c"
since those files are presumably for authentication, not encryption.

I'm not sure what you mean about "rather generic set if routines";
GSSAPI is a RFC-standardized interface. I think I also don't understand
the last half of your above paragraph.

> diff --git a/src/interfaces/libpq/fe-secure-gss.c
> b/src/interfaces/libpq/fe-secure-gss.c
> new file mode 100644
> index 0000000..afea9c3
> --- /dev/null
> +++ b/src/interfaces/libpq/fe-secure-gss.c
> @@ -0,0 +1,92 @@
> +#include <assert.h>
> You should add a proper header to those new files.

Sorry, what?


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2015-10-12 11:51:35
Message-ID: CAB7nPqTZDnRSGCj6JoiHKmXHV71DqoRH3fUajBxAFi9EW7=gDA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Oct 10, 2015 at 3:10 AM, Robbie Harwood wrote:
> Michael Paquier writes:
>>> On 2015-07-02 14:22:13 -0400, Robbie Harwood wrote:
>>> [Andres' comments]
>>
>> Here are some comments on top of what Andres has mentioned.
>>
>> --- a/configure.in
>> +++ b/configure.in
>> @@ -636,6 +636,7 @@ PGAC_ARG_BOOL(with, gssapi, no, [build with GSSAPI support],
>> krb_srvtab="FILE:\$(sysconfdir)/krb5.keytab"
>> ])
>> AC_MSG_RESULT([$with_gssapi])
>> +AC_SUBST(with_gssapi)
>>
>> I think that using a new configure variable like that with a dedicated
>> file fe-secure-gss.c and be-secure-gss.c has little sense done this
>> way, and that it would be more adapted to get everything grouped in
>> fe-auth.c for the frontend and auth.c for the backend, or move all the
>> GSSAPI-related stuff in its own file. I can understand the move
>> though: this is to imitate OpenSSL in a way somewhat similar to what
>> has been done for it with a rather generic set if routines, but with
>> GSSAPI that's a bit different, we do not have such a set of routines,
>> hence based on this argument moving it to its own file has little
>> sense. Now, a move that would make sense though is to move all the
>> GSSAPI stuff in its own file, for example pg_GSS_recvauth and
>> pg_GSS_error for the backend, and you should do the same for the
>> frontend with all the pg_GSS_* routines. This should be as well a
>> refactoring patch on top of the actual feature.
>
> My understanding is that frontend and backend code need to be separate
> (for linking), so it's automatically in two places. I really don't want
> to put encryption-related code in files called "auth.c" and "fe-auth.c"
> since those files are presumably for authentication, not encryption.
>
> I'm not sure what you mean about "rather generic set if routines";
> GSSAPI is a RFC-standardized interface. I think I also don't understand
> the last half of your above paragraph.

src/interfaces/libpq/fe-auth.c contains the following set of routines
related to GSS (frontend code in libpq):
- pg_GSS_error_int
- pg_GSS_error
- pg_GSS_continue
- pg_GSS_startup
src/backend/libpq/auth.c contains the following routines related to
GSS (backend code):
- pg_GSS_recvauth
- pg_GSS_error
My point would be simply to move all those routines in two new files
dedicated to GSS, then add your new routines for encryption in it.
Still, the only reason why the OpenSSL routines have been moved out of
be-secure.c to be-secure-openssl.c is to allow other libraries to be
plugged into that, the primary target being SChannel on Windows. And
that's not the case of GSS, so I think that the separation done as in
your patch is not adapted.

>> diff --git a/src/interfaces/libpq/fe-secure-gss.c
>> b/src/interfaces/libpq/fe-secure-gss.c
>> new file mode 100644
>> index 0000000..afea9c3
>> --- /dev/null
>> +++ b/src/interfaces/libpq/fe-secure-gss.c
>> @@ -0,0 +1,92 @@
>> +#include <assert.h>
>> You should add a proper header to those new files.
>
> Sorry, what?

All the files in the source tree need to have a header like that:
/*-------------------------------------------------------------------------
*
* file_name.c
* Description
*
* Portions Copyright (c) 2015, PostgreSQL Global Development Group
*
* IDENTIFICATION
* path/to/file/file_name.c
*
*-------------------------------------------------------------------------
*/
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-13 22:34:28
Message-ID: jlgvbaao0sr.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alright, here's v3. As requested, it's one patch now. Other things
addressed herein include:

- postgres.h/assert.h ordering fix
- spacing around casts
- leaking of GSS buffer in be_gss_inplace_decrypt
- libpq-be.h not having a conditional internal include
- always exposing guc veriable gss_encrypt
- copyright/description headers on all new files
- movement of GSSAPI methods from fe-auth.c and auth.c to fe-gss.c and
be-gss.c respectively
- renaming GSSAPI files to fe-gss.c and be-gss.c (drops -secure)

Andres, one thing you mentioned as "feels rather wrong" was the
GSSAPI-specific code in pqcomm.c; while looking at that again, I have a
slightly better explanation than what I said previously.

Essentially, the problem is that socket_putmessage_noblock() needs to
know the size of the message to put in the buffer but we can't know
that until we've encrypted the message. socket_putmessage_noblock()
calls socket_putmessage() after ensuring the call will not block;
however, other code paths simply call directly into socket_putmessage()
and so socket_putmessage() needs to have a path to encryption as well.

If you have other potential solutions to this problem, I would love to
hear them; right now though I don't see a better way.

Patch follows. Thanks!

Attachment Content-Type Size
v3-GSSAPI-encryption-support.patch text/x-diff 62.0 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-15 12:08:19
Message-ID: CAB7nPqQLo6P+6Pbop2HJ6w1NHC7qr8v1e_zRwMypZuphuFwMkA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Oct 14, 2015 at 7:34 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Alright, here's v3. As requested, it's one patch now. Other things
> addressed herein include:
> Essentially, the problem is that socket_putmessage_noblock() needs to
> know the size of the message to put in the buffer but we can't know
> that until we've encrypted the message. socket_putmessage_noblock()
> calls socket_putmessage() after ensuring the call will not block;
> however, other code paths simply call directly into socket_putmessage()
> and so socket_putmessage() needs to have a path to encryption as well.
>
> If you have other potential solutions to this problem, I would love to
> hear them; right now though I don't see a better way.
>
> Patch follows. Thanks!

After giving a quick shot at this patch, I am still seeing the same problem:
psql: lost synchronization with server: got message type "S", length 22
(And unpatched works, I will try to put my head into your code...)
Regards,
--
Michael


From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-15 12:23:56
Message-ID: CAMsr+YE-WaD4kV4vYe0WxQhgD=hJ-EHd7oJ3=ZUF614t1HMPMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 14 October 2015 at 06:34, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Alright, here's v3. As requested, it's one patch now.

I hate to ask, but have you looked at how this interacts with Windows?

We support Windows SSPI (on a domain-member host) authenticating to a
PostgreSQL server using gssapi with spnego.

We also support a PostgreSQL client on *nix authenticating using
gssapi with spnego to a PostgreSQL server that's requesting sspi mode.

The relevant code is all a bit tangled, since there's support in there
for using Kerberos libraries on Windows instead of SSPI too. I doubt
anybody uses that last one, tests it, or cares about it, though, given
the painful hoop-jumping, registry key permission changes, etc
required to make it work.

For bonus fun, RC4, DES, AES128 or AES256 are available/used for
Kerberos encryption on Windows. See
http://blogs.msdn.com/b/openspecification/archive/2011/05/31/windows-configurations-for-kerberos-supported-encryption-type.aspx
. Though given that Win7 defaults to AES256 it's probably reasonable
to simply not care about anything else.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-15 17:07:51
Message-ID: jlg1tcw6owo.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Craig Ringer <craig(at)2ndquadrant(dot)com> writes:

> On 14 October 2015 at 06:34, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Alright, here's v3. As requested, it's one patch now.
>
> I hate to ask, but have you looked at how this interacts with Windows?
>
> We support Windows SSPI (on a domain-member host) authenticating to a
> PostgreSQL server using gssapi with spnego.
>
> We also support a PostgreSQL client on *nix authenticating using
> gssapi with spnego to a PostgreSQL server that's requesting sspi mode.
>
> The relevant code is all a bit tangled, since there's support in there
> for using Kerberos libraries on Windows instead of SSPI too. I doubt
> anybody uses that last one, tests it, or cares about it, though, given
> the painful hoop-jumping, registry key permission changes, etc
> required to make it work.
>
> For bonus fun, RC4, DES, AES128 or AES256 are available/used for
> Kerberos encryption on Windows. See
> http://blogs.msdn.com/b/openspecification/archive/2011/05/31/windows-configurations-for-kerberos-supported-encryption-type.aspx
> . Though given that Win7 defaults to AES256 it's probably reasonable
> to simply not care about anything else.

The short - and probably most important - answer is that no, I haven't
tested it, and it would be difficult for me to do so quickly.

In more depth:

Looking at
http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html
suggests that SSPI follows a separate codepath from the GSS code;
certainly it's a different auth request, which means it shouldn't
trigger the encryption path.

There is no reason that using GSSAPI from, e.g., MIT Kerberos for
Windows, should not work here. Even more broadly than that, GSSAPI is a
RFC-standardized protocol with rigorously tested interop etc. etc.,
though whether anyone outside of MIT cares about MIT Kerberos for
Windows I have no idea. As for encryption types, MIT out-of-the-box
supports aes256 + aes128 (in several variants), rc4-hmac and friends,
camellia in several variants, and des3-cbc-sha1. A much wider selection
is available on setting the appropriately named "allow_weak_crypto" in
krb5.conf, though I would hope that would not be needed.

I think the important takeaway here is that I haven't actually changed
how *authentication* works; these changes only affect GSSAPI
post-authentication add encryption functions as defined by that
specification. So if the authentication was working before, and the
GSSAPI implementation is following RFC, I would hope that this would
work still.

Thanks,
--Robbie


From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-16 06:07:43
Message-ID: CAMsr+YH0jamGmOM=mwziYQg=J-0XVp4BosPEv1n+UMaNMj4aMA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16 October 2015 at 01:07, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:

> The short - and probably most important - answer is that no, I haven't
> tested it, and it would be difficult for me to do so quickly.

IIRC it's pretty easy to fire up AWS instances that're primary domain
controllers, and then join a Pg box to them with Kerberos. I realise
that's different to having the time and desire to do it, though.

> Looking at
> http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html
> suggests that SSPI follows a separate codepath from the GSS code;
> certainly it's a different auth request, which means it shouldn't
> trigger the encryption path.

It's a different auth request, but the handling in be-auth.c is
co-mingled to handle the cases:

* We're compiled with Kerberos, handling SSPI from Windows
* We're compiled with Kerberos, handling a GSSAPI request
* We're compiled with SSPI, and we're using Windows SSPI to handle a
GSSAPI auth request
* We're compiled with SSPI, and we're using it to handle a SSP client request

SSPI is a wrapper. For Windows Domain members it carries
GSSAPI/Kerberos data with the spnego extension. (For local loopback it
does NTLM, but you don't need to care about that).

> There is no reason that using GSSAPI from, e.g., MIT Kerberos for
> Windows, should not work here.

Except that *nobody* does it. The EDB installer builds Pg with SSPI,
and that's what the overwhelming majority of Windows users use.

Personally I don't care if this patch doesn't add support for GSSAPI
encryption for sspi connections, only that it doesn't break them.

> Even more broadly than that, GSSAPI is a
> RFC-standardized protocol with rigorously tested interop etc. etc.,
> though whether anyone outside of MIT cares about MIT Kerberos for
> Windows I have no idea.

It's maintained enough that AFAIK it works, and Pg supports compiling
with it. No idea if anyone tests it with Pg anymore.

> I think the important takeaway here is that I haven't actually changed
> how *authentication* works; these changes only affect GSSAPI
> post-authentication add encryption functions as defined by that
> specification. So if the authentication was working before, and the
> GSSAPI implementation is following RFC, I would hope that this would
> work still.

Hope so.

I'll put this on my "hope to test it at some stage" list, but I don't
have a prebuilt environment for it and have a lot to get ready for the
next CF, so it'll be a while...

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-16 13:34:59
Message-ID: 20151016133459.GL3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Craig Ringer (craig(at)2ndquadrant(dot)com) wrote:
> On 16 October 2015 at 01:07, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> > Looking at
> > http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html
> > suggests that SSPI follows a separate codepath from the GSS code;
> > certainly it's a different auth request, which means it shouldn't
> > trigger the encryption path.
>
> It's a different auth request, but the handling in be-auth.c is
> co-mingled to handle the cases:

be-auth.c? You mean src/backend/libpq/auth.c?

> * We're compiled with Kerberos, handling SSPI from Windows
> * We're compiled with Kerberos, handling a GSSAPI request

Eh, *kerberos* was removed with 9.4.0. I'm guessing you mean GSSAPI
above.

> * We're compiled with SSPI, and we're using Windows SSPI to handle a
> GSSAPI auth request
> * We're compiled with SSPI, and we're using it to handle a SSP client request
>
> SSPI is a wrapper. For Windows Domain members it carries
> GSSAPI/Kerberos data with the spnego extension. (For local loopback it
> does NTLM, but you don't need to care about that).

I have to admit that I'm not following what you're getting at here.

src/backend/libpq/auth.c and src/interfaces/libpq/fe-auth.c have pretty
clearly independent paths for SSPI and GSSAPI and which is used
(server-side) is based on what the auth method in pg_hba.conf is. In a
properly set up environment, the client could be using either, but it's
not like we try to figure out (or care) which the client is using from
the server's perspective.

Now, if you set up GSSAPI on the client side and tell it to require
encryption and you're using SSPI on the server side (or the other way
around) it's not likely to work without changes to the SSPI code paths,
which we should be looking at doing. I've not looked at the patch in
much depth yet, but hopefully there's a straight-forward way to say
"we're using SSPI on (client/server) and that doesn't support
encryption yet, so don't try to require it" and throw an error if
someone does. I don't think we necessairly have to have encryption with
SSPI working initially (and that's assuming SSPI can actually do
encryption the way GSSAPI can, I don't know that it can).

> > There is no reason that using GSSAPI from, e.g., MIT Kerberos for
> > Windows, should not work here.
>
> Except that *nobody* does it. The EDB installer builds Pg with SSPI,
> and that's what the overwhelming majority of Windows users use.

Apparently *somebody* uses MIT KfW; I doubt MIT would have put out
KfW 4.0 if no one wanted it. I agree that it's clearly a small number
of environments (I don't know of any currently) and it's entirely
possible that none of them use PG with GSSAPI on Windows for
authentication.

> Personally I don't care if this patch doesn't add support for GSSAPI
> encryption for sspi connections, only that it doesn't break them.

Agreed and we should certainly test it, but I'm not seeing what you're
getting at as the concern.

> > Even more broadly than that, GSSAPI is a
> > RFC-standardized protocol with rigorously tested interop etc. etc.,
> > though whether anyone outside of MIT cares about MIT Kerberos for
> > Windows I have no idea.
>
> It's maintained enough that AFAIK it works, and Pg supports compiling
> with it. No idea if anyone tests it with Pg anymore.

The EDB installers were changed to use SSPI instead of MIT KfW (or
perhaps just dropped building with GSSAPI, Dave would probably remember
better than I do) because KfW wasn't being maintained or updated any
more and the latest version had known security issues. That was quite a
while ago and it looks like MIT has decided to revive KfW (note the
drought between about 2007 and 2012 or so though..) with KfW 4.0.

I doubt anyone's tried building or running PG with GSSAPI under Windows
though. I agree it'd be good to test and see and perhaps even the EDB
installers could be changed to add support for it back in (not sure if
Dave really wants to though as it was a bit of a pain..). However,
presumably MIT has updated KfW and contains to maintain it because
someone is using it.

Really, though, assuming that GSSAPI as provided by KfW works per the
spec-defined API, I don't see why it wouldn't work under Windows just
the same as it does under *nix, it's not like we have any
Windows-specific code in backend/libpq/auth.c or
interfaces/libpq/fe-auth.c for GSSAPI except a MingW-specific symbol
definition.

> > I think the important takeaway here is that I haven't actually changed
> > how *authentication* works; these changes only affect GSSAPI
> > post-authentication add encryption functions as defined by that
> > specification. So if the authentication was working before, and the
> > GSSAPI implementation is following RFC, I would hope that this would
> > work still.
>
> Hope so.
>
> I'll put this on my "hope to test it at some stage" list, but I don't
> have a prebuilt environment for it and have a lot to get ready for the
> next CF, so it'll be a while...

Ditto.

Thanks!

Stephen


From: Craig Ringer <craig(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-16 14:51:06
Message-ID: CAMsr+YG1+HQ-V_kdBKkFX+XRV+bND0pJOygns-nbAuHEn2pj2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16 October 2015 at 21:34, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> * Craig Ringer (craig(at)2ndquadrant(dot)com) wrote:
>> On 16 October 2015 at 01:07, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> > Looking at
>> > http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html
>> > suggests that SSPI follows a separate codepath from the GSS code;
>> > certainly it's a different auth request, which means it shouldn't
>> > trigger the encryption path.
>>
>> It's a different auth request, but the handling in be-auth.c is
>> co-mingled to handle the cases:
>
> be-auth.c? You mean src/backend/libpq/auth.c?

Ahem. Yes.

Also, I was actually thinking of the libpq front-end code, as it turns
out. The backend's handling of each method is much better separated.

>> * We're compiled with Kerberos, handling SSPI from Windows
>> * We're compiled with Kerberos, handling a GSSAPI request
>
> Eh, *kerberos* was removed with 9.4.0. I'm guessing you mean GSSAPI
> above.

Yes, being sloppy.

> src/backend/libpq/auth.c and src/interfaces/libpq/fe-auth.c have pretty
> clearly independent paths for SSPI and GSSAPI

fe-auth.c doesn't. See pg_fe_sendauth(...)'s case AUTH_REQ_GSS: and
AUTH_REQ_SSPI:

Not what I call clearly independent. I've had to deal with that tangle
of joy a few times...

> and which is used
> (server-side) is based on what the auth method in pg_hba.conf is.

Yep, agreed there. I was thinking that the backend overlapped more,
like the frontend does.

> In a
> properly set up environment, the client could be using either, but it's
> not like we try to figure out (or care) which the client is using from
> the server's perspective.

Exactly. I want to make sure we still don't have to care.

> Now, if you set up GSSAPI on the client side and tell it to require
> encryption and you're using SSPI on the server side (or the other way
> around) it's not likely to work without changes to the SSPI code paths,
> which we should be looking at doing.

So long as setting up gssapi auth on the backend without requiring
encryption still works with sspi clients, like it did before, I'm
happy. My concern is avoiding a regression in what works, not
requiring that the new functionality be supported everywhere.

>> > There is no reason that using GSSAPI from, e.g., MIT Kerberos for
>> > Windows, should not work here.
>>
>> Except that *nobody* does it. The EDB installer builds Pg with SSPI,
>> and that's what the overwhelming majority of Windows users use.
>
> Apparently *somebody* uses MIT KfW

Yeah, I meant nobody uses it with Pg on Windows.

> I doubt anyone's tried building or running PG with GSSAPI under Windows
> though. I agree it'd be good to test and see and perhaps even the EDB
> installers could be changed to add support for it back in (not sure if
> Dave really wants to though as it was a bit of a pain..).

It's a lot of a pain, and not just because of maintenance. Kerberos on
Windows needs access to various innards that you don't need when just
using SSPI to delegate SSO to the OS. It's less secure, fiddly, and
annoying. At least it was last time I had to deal with it, when I was
working around some SSPI bugs in psqlODBC before landing up patching
them in the driver instead.

--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Craig Ringer <craig(at)2ndquadrant(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-17 02:11:05
Message-ID: 20151017021105.GP3685@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Craig Ringer (craig(at)2ndquadrant(dot)com) wrote:
> On 16 October 2015 at 21:34, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> >> It's a different auth request, but the handling in be-auth.c is
> >> co-mingled to handle the cases:
> >
> > be-auth.c? You mean src/backend/libpq/auth.c?
>
> Ahem. Yes.

No worries. :)

> Also, I was actually thinking of the libpq front-end code, as it turns
> out. The backend's handling of each method is much better separated.

Ok.

> > src/backend/libpq/auth.c and src/interfaces/libpq/fe-auth.c have pretty
> > clearly independent paths for SSPI and GSSAPI
>
> fe-auth.c doesn't. See pg_fe_sendauth(...)'s case AUTH_REQ_GSS: and
> AUTH_REQ_SSPI:
>
> Not what I call clearly independent. I've had to deal with that tangle
> of joy a few times...

Hmm, yea, the actual choice of how to respond to the auth method the
server wants us to use is kind of tricky, but once we've settled on one
or the other, the rest of the code is pretty independent.

Still, I agree with your point that we need to be careful to not break
what we have there by, say, trying to move to encrypted GSSAPI with an
SSPI server.

I'm not sure that I want to really change that fe-auth.c code but I
really think there may be a simpler way to have the same behavior. That
mishmash of #ifdef's and swith/case statements strikes me as possibly
being overly cute. Clear blocks of "we got this message, this is what
we do when we're compiled with X, or Y, or X+Y" would probably be a lot
easier to follow.

> > In a
> > properly set up environment, the client could be using either, but it's
> > not like we try to figure out (or care) which the client is using from
> > the server's perspective.
>
> Exactly. I want to make sure we still don't have to care.

Agreed.

> > Now, if you set up GSSAPI on the client side and tell it to require
> > encryption and you're using SSPI on the server side (or the other way
> > around) it's not likely to work without changes to the SSPI code paths,
> > which we should be looking at doing.
>
> So long as setting up gssapi auth on the backend without requiring
> encryption still works with sspi clients, like it did before, I'm
> happy. My concern is avoiding a regression in what works, not
> requiring that the new functionality be supported everywhere.

Great, we're definitely agreed on that.

> >> > There is no reason that using GSSAPI from, e.g., MIT Kerberos for
> >> > Windows, should not work here.
> >>
> >> Except that *nobody* does it. The EDB installer builds Pg with SSPI,
> >> and that's what the overwhelming majority of Windows users use.
> >
> > Apparently *somebody* uses MIT KfW
>
> Yeah, I meant nobody uses it with Pg on Windows.

It'd be nice if it did, in case any of those users *do* end up wanting
to use PG.

> > I doubt anyone's tried building or running PG with GSSAPI under Windows
> > though. I agree it'd be good to test and see and perhaps even the EDB
> > installers could be changed to add support for it back in (not sure if
> > Dave really wants to though as it was a bit of a pain..).
>
> It's a lot of a pain, and not just because of maintenance. Kerberos on
> Windows needs access to various innards that you don't need when just
> using SSPI to delegate SSO to the OS. It's less secure, fiddly, and
> annoying. At least it was last time I had to deal with it, when I was
> working around some SSPI bugs in psqlODBC before landing up patching
> them in the driver instead.

Yeah, I remember working with KfW back-in-the-day. I never played with
the new 4.0 version, so perhaps it's better, but I'm not particularly
anxious to get into that mess again..

As for this patch, the reason I've not been as involved (beyond being
ridiculously busy) is that Michael's environment, which at least appears
perfectly reasonable (and works with PG unpatched) isn't working. If we
can get that working (and I've not looked at what's happening, so I have
no idea how easy or hard that would be), then I'd be a lot more excited
to spend time doing review of the patch.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-19 18:01:01
Message-ID: jlgwpuin3fm.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> As for this patch, the reason I've not been as involved (beyond being
> ridiculously busy) is that Michael's environment, which at least appears
> perfectly reasonable (and works with PG unpatched) isn't working. If we
> can get that working (and I've not looked at what's happening, so I have
> no idea how easy or hard that would be), then I'd be a lot more excited
> to spend time doing review of the patch.

I would also really like to see this fixed. Unfortunately, I haven't
been able to replicate; I followed Michael's (very nicely written)
writeup and didn't see the issues that Michael did. The only thing I
know about the problem is that it logs:

> psql: lost synchronization with server: got message type "S", length 22

which unfortunately could be a great many things. I've said this a
couple times now, but I really do need more information - a traffic
dump, a list of commands that were run, etc.; unfortunately, the surface
here is pretty large, and while I totally am willing to believe there
are bugs in the code I've written, I do not yet see them.


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-21 06:54:28
Message-ID: CAB7nPqT+URED7yZUPc_Soj=vfhf_r7MJD7=VonWpOFiiJE6zgg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Oct 20, 2015 at 3:01 AM, Robbie Harwood wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>> psql: lost synchronization with server: got message type "S", length 22
>
> which unfortunately could be a great many things. I've said this a
> couple times now, but I really do need more information - a traffic
> dump, a list of commands that were run, etc.; unfortunately, the surface
> here is pretty large, and while I totally am willing to believe there
> are bugs in the code I've written, I do not yet see them.

--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -129,6 +129,58 @@ pqParseInput3(PGconn *conn)
return;
}

+#ifdef ENABLE_GSS
+ /* We want to be ready in both IDLE and BUSY states
for encryption */
+ if (id == 'g' && !conn->gss_disable_enc && conn->gctx)
+ {
+ ssize_t encEnd, next;
[...]
+ }
+ else if (!conn->gss_disable_enc && conn->gss_auth_done &&
+ !conn->gss_decrypted_cur && id != 'E')
+ /* This could be a sync error, so let's handle
it as such. */
+ handleSyncLoss(conn, id, msgLength);
+#endif

Hm. The out-of-sync error I am seeing in my environment is caused by
this block when parsing 'g' messages coming from the backend that are
considered as being GSSAPI-encrypted messages. I am still looking at
that...
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-21 07:53:32
Message-ID: CAB7nPqTL1SjaYn7pwb86mW1M+469=ofyyRt1Oh9dyFC_bAf_iw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie,

On Wed, Oct 21, 2015 at 3:54 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Tue, Oct 20, 2015 at 3:01 AM, Robbie Harwood wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> psql: lost synchronization with server: got message type "S", length 22
>>
>> which unfortunately could be a great many things. I've said this a
>> couple times now, but I really do need more information - a traffic
>> dump, a list of commands that were run, etc.; unfortunately, the surface
>> here is pretty large, and while I totally am willing to believe there
>> are bugs in the code I've written, I do not yet see them.
>
> --- a/src/interfaces/libpq/fe-protocol3.c
> +++ b/src/interfaces/libpq/fe-protocol3.c
> @@ -129,6 +129,58 @@ pqParseInput3(PGconn *conn)
> return;
> }
>
> +#ifdef ENABLE_GSS
> + /* We want to be ready in both IDLE and BUSY states
> for encryption */
> + if (id == 'g' && !conn->gss_disable_enc && conn->gctx)
> + {
> + ssize_t encEnd, next;
> [...]
> + }
> + else if (!conn->gss_disable_enc && conn->gss_auth_done &&
> + !conn->gss_decrypted_cur && id != 'E')
> + /* This could be a sync error, so let's handle
> it as such. */
> + handleSyncLoss(conn, id, msgLength);
> +#endif
>
> Hm. The out-of-sync error I am seeing in my environment is caused by
> this block when parsing 'g' messages coming from the backend that are
> considered as being GSSAPI-encrypted messages. I am still looking at
> that...

@@ -604,6 +604,11 @@ pqPutMsgEnd(PGconn *conn)
memcpy(conn->outBuffer + conn->outMsgStart, &msgLen, 4);
}

+#ifdef ENABLE_GSS
+ if (pggss_encrypt(conn) < 0)
+ return EOF;
+#endif

@@ -1528,10 +1541,20 @@ socket_putmessage(char msgtype, const char *s,
size_t len)
if (internal_putbytes(s, len))
goto fail;
PqCommBusy = false;
+#ifdef ENABLE_GSS
+ /* if we're GSSAPI encrypting, s was allocated in be_gss_encrypt */
+ if (msgtype == 'g')
+ pfree((char *)s);
+#endif

Looking at this patch in more details... Why is it necessary to wrap
all the encrypted messages into a dedicated message type 'g'? Cannot
we rely on the context on client and backend that should be set up
after authentication to perform the encryption and decryption
operations? This patch is enforcing the message type in
socket_putmessage for backend and pggss_encrypt/pqPutMsgEnd for
frontend, this just feels wrong and I think that the patch could be
really simplified, this includes the crafting added in fe-protocol3.c
that should be IMO reserved only for messages received from the
backend and should not be made aware of any protocol-level logic.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-21 16:28:29
Message-ID: jlgbnbskwya.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> Robbie,
>
> +#ifdef ENABLE_GSS
> + if (pggss_encrypt(conn) < 0)
> + return EOF;
> +#endif
>
> @@ -1528,10 +1541,20 @@ socket_putmessage(char msgtype, const char *s,
> size_t len)
> if (internal_putbytes(s, len))
> goto fail;
> PqCommBusy = false;
> +#ifdef ENABLE_GSS
> + /* if we're GSSAPI encrypting, s was allocated in be_gss_encrypt */
> + if (msgtype == 'g')
> + pfree((char *)s);
> +#endif
>
> Looking at this patch in more details... Why is it necessary to wrap
> all the encrypted messages into a dedicated message type 'g'? Cannot
> we rely on the context on client and backend that should be set up
> after authentication to perform the encryption and decryption
> operations? This patch is enforcing the message type in
> socket_putmessage for backend and pggss_encrypt/pqPutMsgEnd for
> frontend, this just feels wrong and I think that the patch could be
> really simplified, this includes the crafting added in fe-protocol3.c
> that should be IMO reserved only for messages received from the
> backend and should not be made aware of any protocol-level logic.

Well, it's not strictly necessary in the general case, but it makes
debugging a *lot* easier to have it present, and it simplifies some of
the handling logic. For instance, in the part quoted above, with
socket_putmessage() and socket_putmessage_noblock(), we need some way to
tell whether a message blob has already been encrypted.

Some enforcement of message type *will need to be carried out* anyway to
avoid security issues with tampering on the wire, whether that be by
sanity-checking the stated message type and then handling accordingly,
or trying to decrypt and detonating the connection if it fails.

GSSAPI does not define a wire protocol for the transport of messages the
way, e.g., TLS does, so there must be some handling of incomplete
messages, multiple messages at once, etc. There is already adequate
handling of these present in postgres already, so I have structured the
code to take advantage of it. That said, I could absolutely reimplement
them - but it would not be simpler, I'm reasonably sure.


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-21 16:39:27
Message-ID: jlg7fmgkwg0.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Tue, Oct 20, 2015 at 3:01 AM, Robbie Harwood wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> psql: lost synchronization with server: got message type "S", length 22
>>
>> which unfortunately could be a great many things. I've said this a
>> couple times now, but I really do need more information - a traffic
>> dump, a list of commands that were run, etc.; unfortunately, the surface
>> here is pretty large, and while I totally am willing to believe there
>> are bugs in the code I've written, I do not yet see them.
>
> --- a/src/interfaces/libpq/fe-protocol3.c
> +++ b/src/interfaces/libpq/fe-protocol3.c
> @@ -129,6 +129,58 @@ pqParseInput3(PGconn *conn)
> return;
> }
>
> +#ifdef ENABLE_GSS
> + /* We want to be ready in both IDLE and BUSY states
> for encryption */
> + if (id == 'g' && !conn->gss_disable_enc && conn->gctx)
> + {
> + ssize_t encEnd, next;
> [...]
> + }
> + else if (!conn->gss_disable_enc && conn->gss_auth_done &&
> + !conn->gss_decrypted_cur && id != 'E')
> + /* This could be a sync error, so let's handle
> it as such. */
> + handleSyncLoss(conn, id, msgLength);
> +#endif
>
> Hm. The out-of-sync error I am seeing in my environment is caused by
> this block when parsing 'g' messages coming from the backend that are
> considered as being GSSAPI-encrypted messages. I am still looking at
> that...

If you're hitting the else-block, that suggests a GSSAPI context is not
present at the time a GSSAPI message was received, I think.


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-22 07:47:09
Message-ID: CAB7nPqSRFG=U3Q_R-7FPvMjNH4TsGfTdZPa7c6x868iw_h0cvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 22, 2015 at 1:28 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
>> Robbie,
>>
>> +#ifdef ENABLE_GSS
>> + if (pggss_encrypt(conn) < 0)
>> + return EOF;
>> +#endif
>>
>> @@ -1528,10 +1541,20 @@ socket_putmessage(char msgtype, const char *s,
>> size_t len)
>> if (internal_putbytes(s, len))
>> goto fail;
>> PqCommBusy = false;
>> +#ifdef ENABLE_GSS
>> + /* if we're GSSAPI encrypting, s was allocated in be_gss_encrypt */
>> + if (msgtype == 'g')
>> + pfree((char *)s);
>> +#endif
>>
>> Looking at this patch in more details... Why is it necessary to wrap
>> all the encrypted messages into a dedicated message type 'g'? Cannot
>> we rely on the context on client and backend that should be set up
>> after authentication to perform the encryption and decryption
>> operations? This patch is enforcing the message type in
>> socket_putmessage for backend and pggss_encrypt/pqPutMsgEnd for
>> frontend, this just feels wrong and I think that the patch could be
>> really simplified, this includes the crafting added in fe-protocol3.c
>> that should be IMO reserved only for messages received from the
>> backend and should not be made aware of any protocol-level logic.
>
> Well, it's not strictly necessary in the general case, but it makes
> debugging a *lot* easier to have it present, and it simplifies some of
> the handling logic. For instance, in the part quoted above, with
> socket_putmessage() and socket_putmessage_noblock(), we need some way to
> tell whether a message blob has already been encrypted.
> Some enforcement of message type *will need to be carried out* anyway to
> avoid security issues with tampering on the wire, whether that be by
> sanity-checking the stated message type and then handling accordingly,
> or trying to decrypt and detonating the connection if it fails.
> GSSAPI does not define a wire protocol for the transport of messages the
> way, e.g., TLS does, so there must be some handling of incomplete
> messages, multiple messages at once, etc. There is already adequate
> handling of these present in postgres already, so I have structured the
> code to take advantage of it. That said, I could absolutely reimplement
> them - but it would not be simpler, I'm reasonably sure.

Hm, and that's why you chose this way of going. My main concern about
this patch is that it adds on top of the existing Postgres protocol a
layer to encrypt and decrypt the messages between server and client
based on GSSAPI. All messages transmitted between client and server
are changed to 'g' messages on the fly and switched back to their
original state at reception. This is symbolized by the four routines
you added in the patch in this purpose, two for frontend and two for
backend, each one for encryption and decryption. I may be wrong of
course, but it seems to me that this approach will not survive
committer-level screening because of the fact that context-level
things invade higher level protocol messages.

IMO, we would live better with something at a lower level, like in
be-secure.c and fe-secure.c to exchange the encrypted and decrypted
packages using the GSSAPI context created at authentication, that's
where the context-level switches are living after all.

So I am thinking that this patch needs a rework, and should be
returned with feedback.
Stephen, others, what do you think?
--
Michael


From: Andres Freund <andres(at)anarazel(dot)de>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-22 09:00:26
Message-ID: 20151022090026.GB8952@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2015-10-22 16:47:09 +0900, Michael Paquier wrote:
> Hm, and that's why you chose this way of going. My main concern about
> this patch is that it adds on top of the existing Postgres protocol a
> layer to encrypt and decrypt the messages between server and client
> based on GSSAPI. All messages transmitted between client and server
> are changed to 'g' messages on the fly and switched back to their
> original state at reception. This is symbolized by the four routines
> you added in the patch in this purpose, two for frontend and two for
> backend, each one for encryption and decryption. I may be wrong of
> course, but it seems to me that this approach will not survive
> committer-level screening because of the fact that context-level
> things invade higher level protocol messages.

Agreed. At least one committer here indeed thinks this approach is not
acceptable (and I've said so upthread).

Greetings,

Andres Freund


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-22 11:48:22
Message-ID: CAB7nPqTfLmQpF7hJyd_UspOLtu1GFpXzMSyV6grk7iNeuxUpPQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 22, 2015 at 6:00 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> On 2015-10-22 16:47:09 +0900, Michael Paquier wrote:
>> Hm, and that's why you chose this way of going. My main concern about
>> this patch is that it adds on top of the existing Postgres protocol a
>> layer to encrypt and decrypt the messages between server and client
>> based on GSSAPI. All messages transmitted between client and server
>> are changed to 'g' messages on the fly and switched back to their
>> original state at reception. This is symbolized by the four routines
>> you added in the patch in this purpose, two for frontend and two for
>> backend, each one for encryption and decryption. I may be wrong of
>> course, but it seems to me that this approach will not survive
>> committer-level screening because of the fact that context-level
>> things invade higher level protocol messages.
>
> Agreed. At least one committer here indeed thinks this approach is not
> acceptable (and I've said so upthread).

OK, so marked as returned with feedback.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-22 14:36:19
Message-ID: jlgwpufj7h8.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:

> On 2015-10-22 16:47:09 +0900, Michael Paquier wrote:
>> Hm, and that's why you chose this way of going. My main concern about
>> this patch is that it adds on top of the existing Postgres protocol a
>> layer to encrypt and decrypt the messages between server and client
>> based on GSSAPI. All messages transmitted between client and server
>> are changed to 'g' messages on the fly and switched back to their
>> original state at reception. This is symbolized by the four routines
>> you added in the patch in this purpose, two for frontend and two for
>> backend, each one for encryption and decryption. I may be wrong of
>> course, but it seems to me that this approach will not survive
>> committer-level screening because of the fact that context-level
>> things invade higher level protocol messages.
>
> Agreed. At least one committer here indeed thinks this approach is not
> acceptable (and I've said so upthread).

Okay, I'll make some changes. Before I do, though, since this is not
the approach I came up with, can you explicitly state what you're
looking for here? It subjectively seems that I'm getting a lot of
feedback of "this feels wrong" without suggestion for improvement.

To be clear, what I need to know is:

- What changes do you want to see in the wire protocol? (And how will
fallback be supported if that's affected?)

- Since this seems to be an important sticking point, what files am I
encouraged to change (or prohibited from changing)? (Fallback makes
this complex.)

- I've been assuming that we care about fallback, but I'd like to be
told that it's something postgres actually wants to see because it's
the most intricate part of these changes. (I'm reasonably confident
that the code becomes simpler without it, and I myself have no use for
it.)

If I understand what you're asking for (and the above is intended to be
sure that I will), this will not be a trivial rework, so I want to be
really sure before doing that because writing this code a third time is
something I don't relish.

Thanks,
--Robbie


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Craig Ringer <craig(at)2ndquadrant(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-26 08:33:14
Message-ID: CAB7nPqQPMz8A2E=fBggsSsnR8ZH6RMDCLvuHQ11Bt3cxmKXeOQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Oct 22, 2015 at 11:36 PM, Robbie Harwood wrote:
> To be clear, what I need to know is:
> - What changes do you want to see in the wire protocol? (And how will
> fallback be supported if that's affected?)

Hm. Something essential will be to send the length of the wrapped
gss_buffer_t object to be sent in the first 4 bytes of the message so
as the receiver can know how much it has to unwrap and can perform
sanity checks on what has been received.

> - Since this seems to be an important sticking point, what files am I
> encouraged to change (or prohibited from changing)? (Fallback makes
> this complex.)

If we want to make that stick into Postgres, I think that we are going
to need be_gss_read and be_gss_write in be-secure.c, and pqgss_write
and pqgss_read in fe-secure.c, the use the context initialized at
authentication time to wrap and unwrap messages between the server and
client.

> - I've been assuming that we care about fallback, but I'd like to be
> told that it's something postgres actually wants to see because it's
> the most intricate part of these changes. (I'm reasonably confident
> that the code becomes simpler without it, and I myself have no use for
> it.)

As a first shot for this patch, I would not mind if there is no
fallback at protocol level, it seems to me that it is challenging
enough to get a solid core feature first. Perhaps others have
different opinions?

> If I understand what you're asking for (and the above is intended to be
> sure that I will), this will not be a trivial rework, so I want to be
> really sure before doing that because writing this code a third time is
> something I don't relish.

This makes sense. Let's be sure that we come up with a clear picture
of what to do first.
--
Michael


From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-10-28 16:34:31
Message-ID: CAMkU=1y9Dj8nrhOizsE860JcqrWErq_aTJ-Z_qpmXxAJDu8Byw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Sep 29, 2015 at 7:53 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>
>>>>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>>>>
>>>>>> Well, the issue is still here: login through gssapi fails with
>>>>>> your patch, not with HEAD. This patch is next on my review list by
>>>>>> the way so I'll see what I can do about it soon even if I am in
>>>>>> the US for Postgres Open next week. Still, how did you test it? I
>>>>>> am just creating by myself a KDC, setting up a valid credential
>>>>>> with kinit, and after setting up Postgres for this purpose the
>>>>>> protocol communication just fails.
>>
>> I have no issues, no sync loss; nothing is amiss as far as I can see.
>> If there is actually a problem here, I need more information from you.
>> At the very least, as previously mentioned, I need to know what
>> messages went over the wire to/from the server before it occurred, and
>> what command (if it it made it to command processing) it was in the
>> midst of sending.
>
> Any follow-up on this? I'd really like my code to be bug-free.

I don't know if this is worth posting as the patch is currently
returned with feedback and you are redoing it in a different way, but
with your patch I get this error when connecting:

lost synchronization with server: got message type "T", length 27
The connection to the server was lost. Attempting reset: Failed.

I only get the error when connection to a patched server from a
patched libpq. If either is unpatched, then there is no problem.

Let me know if this is worth looking into.

Cheers,

Jeff


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v2] GSSAPI encryption support
Date: 2015-10-28 17:41:03
Message-ID: jlg7fm6zya8.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jeff Janes <jeff(dot)janes(at)gmail(dot)com> writes:

> On Tue, Sep 29, 2015 at 7:53 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>>
>>>>>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>>>>>
>>>>>>> Well, the issue is still here: login through gssapi fails with
>>>>>>> your patch, not with HEAD. This patch is next on my review list by
>>>>>>> the way so I'll see what I can do about it soon even if I am in
>>>>>>> the US for Postgres Open next week. Still, how did you test it? I
>>>>>>> am just creating by myself a KDC, setting up a valid credential
>>>>>>> with kinit, and after setting up Postgres for this purpose the
>>>>>>> protocol communication just fails.
>>>
>>> I have no issues, no sync loss; nothing is amiss as far as I can see.
>>> If there is actually a problem here, I need more information from you.
>>> At the very least, as previously mentioned, I need to know what
>>> messages went over the wire to/from the server before it occurred, and
>>> what command (if it it made it to command processing) it was in the
>>> midst of sending.
>>
>> Any follow-up on this? I'd really like my code to be bug-free.
>
> I don't know if this is worth posting as the patch is currently
> returned with feedback and you are redoing it in a different way, but
> with your patch I get this error when connecting:
>
> lost synchronization with server: got message type "T", length 27
> The connection to the server was lost. Attempting reset: Failed.
>
> I only get the error when connection to a patched server from a
> patched libpq. If either is unpatched, then there is no problem.
>
> Let me know if this is worth looking into.

Definitely good to know, and I appreciate your testing. It's probably
not worth looking into right now, but please do test the next version of
the code as well.

Thanks!
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Craig Ringer <craig(at)2ndquadrant(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v3] GSSAPI encryption support
Date: 2015-10-30 19:38:47
Message-ID: jlglhakxi2g.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andreas, can you please weigh in here since your voice is important to
this process?

Robbie Harwood <rharwood(at)redhat(dot)com> writes:

> Andres Freund <andres(at)anarazel(dot)de> writes:
>
>> On 2015-10-22 16:47:09 +0900, Michael Paquier wrote:
>>> Hm, and that's why you chose this way of going. My main concern about
>>> this patch is that it adds on top of the existing Postgres protocol a
>>> layer to encrypt and decrypt the messages between server and client
>>> based on GSSAPI. All messages transmitted between client and server
>>> are changed to 'g' messages on the fly and switched back to their
>>> original state at reception. This is symbolized by the four routines
>>> you added in the patch in this purpose, two for frontend and two for
>>> backend, each one for encryption and decryption. I may be wrong of
>>> course, but it seems to me that this approach will not survive
>>> committer-level screening because of the fact that context-level
>>> things invade higher level protocol messages.
>>
>> Agreed. At least one committer here indeed thinks this approach is not
>> acceptable (and I've said so upthread).
>
> Okay, I'll make some changes. Before I do, though, since this is not
> the approach I came up with, can you explicitly state what you're
> looking for here? It subjectively seems that I'm getting a lot of
> feedback of "this feels wrong" without suggestion for improvement.
>
> To be clear, what I need to know is:
>
> - What changes do you want to see in the wire protocol? (And how will
> fallback be supported if that's affected?)
>
> - Since this seems to be an important sticking point, what files am I
> encouraged to change (or prohibited from changing)? (Fallback makes
> this complex.)
>
> - I've been assuming that we care about fallback, but I'd like to be
> told that it's something postgres actually wants to see because it's
> the most intricate part of these changes. (I'm reasonably confident
> that the code becomes simpler without it, and I myself have no use for
> it.)
>
> If I understand what you're asking for (and the above is intended to be
> sure that I will), this will not be a trivial rework, so I want to be
> really sure before doing that because writing this code a third time is
> something I don't relish.
>
> Thanks,
> --Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v4] GSSAPI encryption support
Date: 2016-02-10 21:06:59
Message-ID: jlg4mdg8ebw.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

For your consideration, here is a new version of GSSAPI encryption
support. For those who prefer, it's also available on my github:
https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5551de47a4c60aab7179e

Some thoughts:

- The overall design is different this time - GSS encryption sits in
parallel construction to SSL encryption rather than at the protocol
level - so a strict diff probably isn't useful.

- The GSSAPI authentication code has been moved without modification.
In doing so, the temptation to modify it (flags, error checking, that
big comment at the top about things from Athena, etc.) is very large.
I do not know whether these changes are best suited to another patch
in this series or should be reviewed separately. I am also hesitant
to add things beyond the core before I am told this is the right
approach.

- There's no fallback here. I wrote fallback support for versions 1-3,
and the same design could apply here without too much trouble, but I
am hesitant to port it over before the encryption design is approved.
I strongly suspect you will not want to merge this without fallback
support, and that makes sense to me.

- The client and server code look a lot like each other. This
resemblance is not exact, and my understanding is that server and
client need to compile independently, so I do not know of a way to
rectify this. Suggestions are welcome.

Thanks!

Attachment Content-Type Size
v4-GSSAPI-encryption-support.patch text/x-diff 56.1 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v4] GSSAPI encryption support
Date: 2016-02-11 13:42:11
Message-ID: CAB7nPqS+zyHHE61cxy_DQnFL_Nk2N6V1w1E07bg53shm1++p-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Feb 11, 2016 at 6:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> For your consideration, here is a new version of GSSAPI encryption
> support. For those who prefer, it's also available on my github:
> https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5551de47a4c60aab7179e

Yeah! Glad to see you back.

> Some thoughts:
>
> - The overall design is different this time - GSS encryption sits in
> parallel construction to SSL encryption rather than at the protocol
> level - so a strict diff probably isn't useful.
>
> - The GSSAPI authentication code has been moved without modification.
> In doing so, the temptation to modify it (flags, error checking, that
> big comment at the top about things from Athena, etc.) is very large.
> I do not know whether these changes are best suited to another patch
> in this series or should be reviewed separately. I am also hesitant
> to add things beyond the core before I am told this is the right
> approach.

I would recommend a different patch if code needs to be moved around.
The move may make sense taken as an independent piece of the
integration.

> - There's no fallback here. I wrote fallback support for versions 1-3,
> and the same design could apply here without too much trouble, but I
> am hesitant to port it over before the encryption design is approved.
> I strongly suspect you will not want to merge this without fallback
> support, and that makes sense to me.
>
> - The client and server code look a lot like each other. This
> resemblance is not exact, and my understanding is that server and
> client need to compile independently, so I do not know of a way to
> rectify this. Suggestions are welcome.

At quick glance, I like the direction this is taking. You moved all
the communication protocol at a lower level where SSL and secure reads
are located, so this results in a neat integration.

+ * Portions Copyright (c) 2015-2016, Red Hat, Inc.
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
I think that this part may be a problem... Not sure the feeling of the
others regarding additional copyright notices.

It would be good to add that to the next CF, I will be happy to get a
look at it.
--
Michael


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v4] GSSAPI encryption support
Date: 2016-02-11 18:13:27
Message-ID: CA+TgmoZm_hwQtBL4ywNHjAnboPc2j3oR_fA6tbb8Cw+z2Gwphg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Feb 11, 2016 at 8:42 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> + * Portions Copyright (c) 2015-2016, Red Hat, Inc.
> + * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
> I think that this part may be a problem... Not sure the feeling of the
> others regarding additional copyright notices.

Yep. "PostgreSQL Global Development Group" means "whoever it was that
contributed", not a specific legal organization.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v4] GSSAPI encryption support
Date: 2016-02-11 18:56:06
Message-ID: jlglh6r5b5l.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Thu, Feb 11, 2016 at 6:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>
>> - The GSSAPI authentication code has been moved without modification.
>> In doing so, the temptation to modify it (flags, error checking, that
>> big comment at the top about things from Athena, etc.) is very large.
>> I do not know whether these changes are best suited to another patch
>> in this series or should be reviewed separately. I am also hesitant
>> to add things beyond the core before I am told this is the right
>> approach.
>
> I would recommend a different patch if code needs to be moved around.
> The move may make sense taken as an independent piece of the
> integration.

Sorry, are you suggesting separate patch for moving the GSS auth code,
or separate patch for changes to said code? I am happy to move it if
so, just want to be sure.

> + * Portions Copyright (c) 2015-2016, Red Hat, Inc.
> + * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
> I think that this part may be a problem... Not sure the feeling of the
> others regarding additional copyright notices.

Good catch. That's an accident (force of habit). Since I'm pretty sure
this version won't be merged anyway, I'll drop it from the next one.

> It would be good to add that to the next CF, I will be happy to get a
> look at it.

Sounds good. Thanks for looking at it!


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v4] GSSAPI encryption support
Date: 2016-02-12 01:30:50
Message-ID: CAB7nPqTHDxcDgtT4bT0OLhq1KtHzzNm5zdvWS+uR-QSDAKO7zQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Feb 12, 2016 at 3:56 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>> On Thu, Feb 11, 2016 at 6:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>> - The GSSAPI authentication code has been moved without modification.
>>> In doing so, the temptation to modify it (flags, error checking, that
>>> big comment at the top about things from Athena, etc.) is very large.
>>> I do not know whether these changes are best suited to another patch
>>> in this series or should be reviewed separately. I am also hesitant
>>> to add things beyond the core before I am told this is the right
>>> approach.
>>
>> I would recommend a different patch if code needs to be moved around.
>> The move may make sense taken as an independent piece of the
>> integration.
>
> Sorry, are you suggesting separate patch for moving the GSS auth code,
> or separate patch for changes to said code? I am happy to move it if
> so, just want to be sure.

This is based on my first impressions on the patch. Let's discuss more
those points once I got a more in-depth look at the patch with what it
actually does. In short, there is no need to put more efforts in the
coding now :) Sorry to confuse you.

>> + * Portions Copyright (c) 2015-2016, Red Hat, Inc.
>> + * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
>> I think that this part may be a problem... Not sure the feeling of the
>> others regarding additional copyright notices.
>
> Good catch. That's an accident (force of habit). Since I'm pretty sure
> this version won't be merged anyway, I'll drop it from the next one.
>
>> It would be good to add that to the next CF, I will be happy to get a
>> look at it.
>
> Sounds good. Thanks for looking at it!

Okay, let's do this.
--
Michael


From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v4] GSSAPI encryption support
Date: 2016-02-12 17:01:45
Message-ID: 56BE0FF9.70302@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Robbie,

On 2/10/16 4:06 PM, Robbie Harwood wrote:
> Hello friends,
>
> For your consideration, here is a new version of GSSAPI encryption
> support. For those who prefer, it's also available on my github:
> https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5551de47a4c60aab7179e

It tried out this patch and ran into a few problems:

1) It didn't apply cleanly to HEAD. It did apply cleanly on a455878
which I figured was recent enough for testing. I didn't bisect to find
the exact commit that broke it.

2) While I was able to apply the patch and get it compiled it seemed
pretty flaky - I was only able to logon about 1 in 10 times on average.
Here was my testing methodology:

a) Build Postgres from a455878 (without your patch), install/configure
Kerberos and get everything working. I was able the set the auth method
to gss in pg_hba.conf and logon successfully every time.

b) On the same system rebuild Postgres from a455878 including your patch
and attempt authentication.

The problems arose after step 2b. Sometimes I would try to logon twenty
times without success and sometimes it only take five or six attempts.
I was never able to logon successfully twice in a row.

When not successful the client always output this incomplete message
(without terminating LF):

psql: expected authentication request from server, but received

From the logs I can see the server is reporting EOF from the client,
though the client does not core dump and prints the above message before
exiting.

I have attached files that contain server logs at DEBUG5 and tcpdump
output for both the success and failure cases.

Please let me know if there's any more information you would like me to
provide.

--
-David
david(at)pgmasters(dot)net

Attachment Content-Type Size
gssauth-fail.log text/plain 14.7 KB
gssauth-success.log text/plain 12.5 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: David Steele <david(at)pgmasters(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-15 17:45:09
Message-ID: jlgtwl9g95m.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Steele <david(at)pgmasters(dot)net> writes:

> Hi Robbie,
>
> On 2/10/16 4:06 PM, Robbie Harwood wrote:
>> Hello friends,
>>
>> For your consideration, here is a new version of GSSAPI encryption
>> support. For those who prefer, it's also available on my github:
>> https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5551de47a4c60aab7179e
>
> It tried out this patch and ran into a few problems:
>
> 1) It didn't apply cleanly to HEAD. It did apply cleanly on a455878
> which I figured was recent enough for testing. I didn't bisect to find
> the exact commit that broke it.

It applied to head of master (57c932475504d63d8f8a68fc6925d7decabc378a)
for me (`patch -p1 < v4-GSSAPI-encryption-support.patch`). I rebased it
anyway and cut a v5 anyway, just to be sure. It's attached, and
available on github as well:
https://github.com/frozencemetery/postgres/commit/dc10e3519f0f6c67f79abd157dc8ff1a1c293f53

> 2) While I was able to apply the patch and get it compiled it seemed
> pretty flaky - I was only able to logon about 1 in 10 times on average.
> Here was my testing methodology:
>
> a) Build Postgres from a455878 (without your patch), install/configure
> Kerberos and get everything working. I was able the set the auth method
> to gss in pg_hba.conf and logon successfully every time.
>
> b) On the same system rebuild Postgres from a455878 including your patch
> and attempt authentication.
>
> The problems arose after step 2b. Sometimes I would try to logon twenty
> times without success and sometimes it only take five or six attempts.
> I was never able to logon successfully twice in a row.
>
> When not successful the client always output this incomplete message
> (without terminating LF):
>
> psql: expected authentication request from server, but received
>
> From the logs I can see the server is reporting EOF from the client,
> though the client does not core dump and prints the above message before
> exiting.
>
> I have attached files that contain server logs at DEBUG5 and tcpdump
> output for both the success and failure cases.
>
> Please let me know if there's any more information you would like me to
> provide.

What I can't tell from looking at your methodology is whether both the
client and server were running my patches or no. There's no fallback
here (I'd like to talk about how that should work, with example from
v1-v3, if people have ideas). This means that both the client and the
server need to be running my patches for the moment. Is this your
setup?

Thanks for taking it for a spin!
--Robbie

Attachment Content-Type Size
v5-GSSAPI-encryption-support.patch text/x-diff 56.0 KB

From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-19 14:24:17
Message-ID: 56C72591.6000805@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2/15/16 12:45 PM, Robbie Harwood wrote:
> David Steele <david(at)pgmasters(dot)net> writes:
>
>> 1) It didn't apply cleanly to HEAD. It did apply cleanly on a455878
>> which I figured was recent enough for testing. I didn't bisect to find
>> the exact commit that broke it.
>
> It applied to head of master (57c932475504d63d8f8a68fc6925d7decabc378a)
> for me (`patch -p1 < v4-GSSAPI-encryption-support.patch`). I rebased it
> anyway and cut a v5 anyway, just to be sure. It's attached, and
> available on github as well:
> https://github.com/frozencemetery/postgres/commit/dc10e3519f0f6c67f79abd157dc8ff1a1c293f53

It could have been my mistake. I'll give it another try when you have a
new patch.

>> 2) While I was able to apply the patch and get it compiled it seemed
>> pretty flaky - I was only able to logon about 1 in 10 times on average.
>> Here was my testing methodology:
>
> What I can't tell from looking at your methodology is whether both the
> client and server were running my patches or no. There's no fallback
> here (I'd like to talk about how that should work, with example from
> v1-v3, if people have ideas). This means that both the client and the
> server need to be running my patches for the moment. Is this your
> setup?

I was testing on a system with no version of PostgreSQL installed. I
applied your patch to master and then ran both server and client from
that patched version. Is there something I'm missing?

--
-David
david(at)pgmasters(dot)net


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: David Steele <david(at)pgmasters(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-24 19:12:38
Message-ID: jlg1t81excp.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Steele <david(at)pgmasters(dot)net> writes:

> On 2/15/16 12:45 PM, Robbie Harwood wrote:
>> David Steele <david(at)pgmasters(dot)net> writes:
>>
>>> 1) It didn't apply cleanly to HEAD. It did apply cleanly on a455878
>>> which I figured was recent enough for testing. I didn't bisect to find
>>> the exact commit that broke it.
>>
>> It applied to head of master (57c932475504d63d8f8a68fc6925d7decabc378a)
>> for me (`patch -p1 < v4-GSSAPI-encryption-support.patch`). I rebased it
>> anyway and cut a v5 anyway, just to be sure. It's attached, and
>> available on github as well:
>> https://github.com/frozencemetery/postgres/commit/dc10e3519f0f6c67f79abd157dc8ff1a1c293f53
>
> It could have been my mistake. I'll give it another try when you have a
> new patch.

Please do let me know how v5 goes. If you run into trouble, in addition
to the logs you helpfully provided before, I'd like a traffic dump (pcap
preferable; I need tcp/udp port 88 for Kerberos and tcp port 5432 or
whatever you're running postgres on) if possible. Thanks!

>>> 2) While I was able to apply the patch and get it compiled it seemed
>>> pretty flaky - I was only able to logon about 1 in 10 times on average.
>>> Here was my testing methodology:
>>
>> What I can't tell from looking at your methodology is whether both the
>> client and server were running my patches or no. There's no fallback
>> here (I'd like to talk about how that should work, with example from
>> v1-v3, if people have ideas). This means that both the client and the
>> server need to be running my patches for the moment. Is this your
>> setup?
>
> I was testing on a system with no version of PostgreSQL installed. I
> applied your patch to master and then ran both server and client from
> that patched version. Is there something I'm missing?

Not that I can immediately see. As long as the client and server are
both patched, everything should work. My process is the same as with
previous versions of this patchset [0], and though I'm using FreeIPA
there is no reason it shouldn't work with any other KDC (MIT, for
instance[1]) provided the IPA calls are converted.

I am curious, though - I haven't changed any of the authentication code
in v4/v5 from what's in ~master, so how often can you log in using
GSSAPI using master?

[0]: https://mivehind.net/2015/06/11/kerberized-postgresql/
[1]: http://web.mit.edu/kerberos/krb5-devel/doc/admin/install_kdc.html


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: David Steele <david(at)pgmasters(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-25 07:06:05
Message-ID: CAB7nPqSu55_AgoiYYfhaO-aHkN5qEVMDt_b1-GFQYw9Yvo=F8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 16, 2016 at 2:45 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> David Steele <david(at)pgmasters(dot)net> writes:
>> On 2/10/16 4:06 PM, Robbie Harwood wrote:
>>> Hello friends,
>>>
>>> For your consideration, here is a new version of GSSAPI encryption
>>> support. For those who prefer, it's also available on my github:
>>> https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5551de47a4c60aab7179e
>>
>> It tried out this patch and ran into a few problems:
>>
>> 1) It didn't apply cleanly to HEAD. It did apply cleanly on a455878
>> which I figured was recent enough for testing. I didn't bisect to find
>> the exact commit that broke it.
>
> It applied to head of master (57c932475504d63d8f8a68fc6925d7decabc378a)
> for me (`patch -p1 < v4-GSSAPI-encryption-support.patch`). I rebased it
> anyway and cut a v5 anyway, just to be sure. It's attached, and
> available on github as well:
> https://github.com/frozencemetery/postgres/commit/dc10e3519f0f6c67f79abd157dc8ff1a1c293f53

v5 is applying fine for me. There were two diff hunks in routine.sgml
but nothing to worry about.

>> 2) While I was able to apply the patch and get it compiled it seemed
>> pretty flaky - I was only able to logon about 1 in 10 times on average.
>> Here was my testing methodology:
>>
>> a) Build Postgres from a455878 (without your patch), install/configure
>> Kerberos and get everything working. I was able the set the auth method
>> to gss in pg_hba.conf and logon successfully every time.
>>
>> b) On the same system rebuild Postgres from a455878 including your patch
>> and attempt authentication.
>>
>> The problems arose after step 2b. Sometimes I would try to logon twenty
>> times without success and sometimes it only take five or six attempts.
>> I was never able to logon successfully twice in a row.
>>
>> When not successful the client always output this incomplete message
>> (without terminating LF):
>>
>> psql: expected authentication request from server, but received
>>
>> From the logs I can see the server is reporting EOF from the client,
>> though the client does not core dump and prints the above message before
>> exiting.
>>
>> I have attached files that contain server logs at DEBUG5 and tcpdump
>> output for both the success and failure cases.
>>
>> Please let me know if there's any more information you would like me to
>> provide.
>
> What I can't tell from looking at your methodology is whether both the
> client and server were running my patches or no. There's no fallback
> here (I'd like to talk about how that should work, with example from
> v1-v3, if people have ideas). This means that both the client and the
> server need to be running my patches for the moment. Is this your
> setup?

We need to be careful here, backward-compatibility is critical for
both the client and the server, or to put it in other words, an
uptables client should still be able to connect a patched server, and
vice-versa. This is an area where it is important to not break any
third-part tool, either using libpq or reimplementing the frontend
protocol.

So I finally began to dive into your new patch... And after testing
this is breaking the authentication protocol for GSS. I have been able
to connect to a server once, but at the second attempt and after
connection is failing with the following error:
psql: expected authentication request from server, but received ioltas

Also, something that is missing is the parametrization that has been
discussed the last time this patch was on the mailing list. Where is
the capacity to control if a client is connecting to a server that is
performing encryption and downgrade to non-ecrypted connection should
the server not be able to support it? Enforcing a client to require
encryption support using pg_hba.conf was as well a good thing. Some
more infrastructure is needed here, I thought that there was an
agreement previously regarding that.

Also, and to make the review a bit easier, it would be good to split
the patch into smaller pieces (thanks for waiting on my input here,
this became quite clear after looking at this code). Basically,
pg_GSS_error is moved to a new file, bringing with it pg_GSS_recvauth
because the error routine is being used by the new ones you are
introducing: be_gssapi_write, etc. The split that this patch is doing
is a bit confusing, all the GSS-related stuff is put within one single
file:
- read/write routines
- authentication routine
- constants
- routines for error handling
Mixing read/write routines with the authentication routine looks
wrong, because the read-write routines just need to create a
dependency with for example be-secure.c on the backend. In short,
where before authentication and secure read/writes after
authentication get linked to each other, and create a dependency that
did not exist before.

For the sake of clarity I would suggest the following split:
- be-gss-common.c, where all the constants and the error handling
routine are located.
- Let authrecv in auth.c
- Move only the read/write routines to the new file be-[secure-]gssapi.c
Splitting the patches into one that moves around the routines, and a
second that introduces the new logic would bring more clarity.

As In understood from the patch, enforcing encryption is not good
either, and any patched clients would not be able to 9.5 or older
servers. Regarding the parametrization, I liked the previous v1-v3
layout to control the encryption, and this allows to set up the
session context on backend and frontend at authentication. The
connection errors are also something to look at, I guess that David
and I ran into the same thing. I am wondering how this patch is tested
to be honest.
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: David Steele <david(at)pgmasters(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-25 07:08:56
Message-ID: CAB7nPqTn65qwpePPUjf=V8wgW3+Dqx8Ck+JrPDN0Djbr9S2MUA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Feb 24, 2016 at 7:12 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> David Steele <david(at)pgmasters(dot)net> writes:
>
>> On 2/15/16 12:45 PM, Robbie Harwood wrote:
>>> David Steele <david(at)pgmasters(dot)net> writes:
>>>
>>>> 1) It didn't apply cleanly to HEAD. It did apply cleanly on a455878
>>>> which I figured was recent enough for testing. I didn't bisect to find
>>>> the exact commit that broke it.
>>>
>>> It applied to head of master (57c932475504d63d8f8a68fc6925d7decabc378a)
>>> for me (`patch -p1 < v4-GSSAPI-encryption-support.patch`). I rebased it
>>> anyway and cut a v5 anyway, just to be sure. It's attached, and
>>> available on github as well:
>>> https://github.com/frozencemetery/postgres/commit/dc10e3519f0f6c67f79abd157dc8ff1a1c293f53
>>
>> It could have been my mistake. I'll give it another try when you have a
>> new patch.
>
> Please do let me know how v5 goes. If you run into trouble, in addition
> to the logs you helpfully provided before, I'd like a traffic dump (pcap
> preferable; I need tcp/udp port 88 for Kerberos and tcp port 5432 or
> whatever you're running postgres on) if possible. Thanks!
>
>>>> 2) While I was able to apply the patch and get it compiled it seemed
>>>> pretty flaky - I was only able to logon about 1 in 10 times on average.
>>>> Here was my testing methodology:
>>>
>>> What I can't tell from looking at your methodology is whether both the
>>> client and server were running my patches or no. There's no fallback
>>> here (I'd like to talk about how that should work, with example from
>>> v1-v3, if people have ideas). This means that both the client and the
>>> server need to be running my patches for the moment. Is this your
>>> setup?
>>
>> I was testing on a system with no version of PostgreSQL installed. I
>> applied your patch to master and then ran both server and client from
>> that patched version. Is there something I'm missing?
>
> Not that I can immediately see. As long as the client and server are
> both patched, everything should work. My process is the same as with
> previous versions of this patchset [0], and though I'm using FreeIPA
> there is no reason it shouldn't work with any other KDC (MIT, for
> instance[1]) provided the IPA calls are converted.

I used a custom krb5kdc set up manually, and all my connection
attempts are working on HEAD, not with your patch (both client and
server patched).

> I am curious, though - I haven't changed any of the authentication code
> in v4/v5 from what's in ~master, so how often can you log in using
> GSSAPI using master?

My guess is that there is something not been correctly cleaned up when
closing the connection. The first attempt worked for me, not after.
--
Michael


From: David Steele <david(at)pgmasters(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-25 15:07:13
Message-ID: 56CF18A1.5060906@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2/25/16 2:08 AM, Michael Paquier wrote:
> On Wed, Feb 24, 2016 at 7:12 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>
>> Not that I can immediately see. As long as the client and server are
>> both patched, everything should work. My process is the same as with
>> previous versions of this patchset [0], and though I'm using FreeIPA
>> there is no reason it shouldn't work with any other KDC (MIT, for
>> instance[1]) provided the IPA calls are converted.
>
> I used a custom krb5kdc set up manually, and all my connection
> attempts are working on HEAD, not with your patch (both client and
> server patched).

I've got the same setup with the same results.

>> I am curious, though - I haven't changed any of the authentication code
>> in v4/v5 from what's in ~master, so how often can you log in using
>> GSSAPI using master?
>
> My guess is that there is something not been correctly cleaned up when
> closing the connection. The first attempt worked for me, not after.

I was able to get in again after a number of failed attempts, though the
number varied.

--
-David
david(at)pgmasters(dot)net


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-25 20:02:11
Message-ID: jlga8moftj0.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Tue, Feb 16, 2016 at 2:45 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> David Steele <david(at)pgmasters(dot)net> writes:
>>> On 2/10/16 4:06 PM, Robbie Harwood wrote:
>>>> Hello friends,
>>>>
>>>> For your consideration, here is a new version of GSSAPI encryption
>>>> support. For those who prefer, it's also available on my github:
>>>> https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5551de47a4c60aab7179e
>>>
>>> It tried out this patch and ran into a few problems:
>>>
>>> 2) While I was able to apply the patch and get it compiled it seemed
>>> pretty flaky - I was only able to logon about 1 in 10 times on average.
>>>
>>> When not successful the client always output this incomplete message
>>> (without terminating LF):
>>>
>>> psql: expected authentication request from server, but received
>>>
>>> From the logs I can see the server is reporting EOF from the client,
>>> though the client does not core dump and prints the above message before
>>> exiting.
>>>
>>> I have attached files that contain server logs at DEBUG5 and tcpdump
>>> output for both the success and failure cases.
>>>
>>> Please let me know if there's any more information you would like me to
>>> provide.
>>
>> What I can't tell from looking at your methodology is whether both the
>> client and server were running my patches or no. There's no fallback
>> here (I'd like to talk about how that should work, with example from
>> v1-v3, if people have ideas). This means that both the client and the
>> server need to be running my patches for the moment. Is this your
>> setup?
>
> We need to be careful here, backward-compatibility is critical for
> both the client and the server, or to put it in other words, an
> uptables client should still be able to connect a patched server, and
> vice-versa. This is an area where it is important to not break any
> third-part tool, either using libpq or reimplementing the frontend
> protocol.

Which is why in my introduction to the v4 patch I explicitly mentioned
that this was missing. I wanted to talk about how this should be
implemented, since I feel that I received no feedback on that design
From last time. It's not hard to port that design over, if desired.

> So I finally began to dive into your new patch... And after testing
> this is breaking the authentication protocol for GSS. I have been able
> to connect to a server once, but at the second attempt and after
> connection is failing with the following error:
> psql: expected authentication request from server, but received ioltas

Interesting. I will see if I can find anything. The capture posted
earlier (thanks David!) suggests that the client doesn't expect the
encrypted data.

I suspect what has happened is a race between the client buffering data
From the socket and the client processing the completion of GSSAPI
authentication. This kind of issue is why my v1 handled GSSAPI at the
protocol level, not at the transport level. I think we end up with
encrypted data in the buffer that's supposed to be decrypted, and since
the GSSAPI blob starts with \x00, it doesn't know what to do.

I'll cut a v6 with most of the changes we've talked about here. It
should address this issue, but I suspect that no one will be happy about
how, since the client essentially needs to "un-read" some data.

As a side note, this would also explain why I can't reproduce the issue,
since I'm running in very low-latency environments (three VMs on my
laptop).

> Also, something that is missing is the parametrization that has been
> discussed the last time this patch was on the mailing list. Where is
> the capacity to control if a client is connecting to a server that is
> performing encryption and downgrade to non-ecrypted connection should
> the server not be able to support it? Enforcing a client to require
> encryption support using pg_hba.conf was as well a good thing. Some
> more infrastructure is needed here, I thought that there was an
> agreement previously regarding that.

This does not match my impression of the discussion, but I would be
happy to be wrong about that since it is less work for me.

> Also, and to make the review a bit easier, it would be good to split
> the patch into smaller pieces (thanks for waiting on my input here,
> this became quite clear after looking at this code). Basically,
> pg_GSS_error is moved to a new file, bringing with it pg_GSS_recvauth
> because the error routine is being used by the new ones you are
> introducing: be_gssapi_write, etc. The split that this patch is doing
> is a bit confusing, all the GSS-related stuff is put within one single
> file:
> - read/write routines
> - authentication routine
> - constants
> - routines for error handling
> Mixing read/write routines with the authentication routine looks
> wrong, because the read-write routines just need to create a
> dependency with for example be-secure.c on the backend. In short,
> where before authentication and secure read/writes after
> authentication get linked to each other, and create a dependency that
> did not exist before.
>
> For the sake of clarity I would suggest the following split:
> - be-gss-common.c, where all the constants and the error handling
> routine are located.
> - Let authrecv in auth.c
> - Move only the read/write routines to the new file be-[secure-]gssapi.c
> Splitting the patches into one that moves around the routines, and a
> second that introduces the new logic would bring more clarity.

So... auth.c is now going to depend on be-gss-common.c, and
be-secure-gssapi.c is also going to depend on be-gss-common.c. That
doesn't seem better in terms of dependencies: now I'm creating two that
didn't exist before.

That said, I would believe that it makes everything clearer. I will do
that shortly.

> I am wondering how this patch is tested to be honest.

We've already had this conversation; please let's stay constructive.


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: David Steele <david(at)pgmasters(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v5] GSSAPI encryption support
Date: 2016-02-26 06:36:47
Message-ID: CAB7nPqRsBLvHC4O-GXBkvVM2YnvzPaa37NvYV04+kcTz01kxtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Feb 26, 2016 at 5:02 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>> We need to be careful here, backward-compatibility is critical for
>> both the client and the server, or to put it in other words, an
>> uptables client should still be able to connect a patched server, and
>> vice-versa. This is an area where it is important to not break any
>> third-part tool, either using libpq or reimplementing the frontend
>> protocol.
>
> Which is why in my introduction to the v4 patch I explicitly mentioned
> that this was missing. I wanted to talk about how this should be
> implemented, since I feel that I received no feedback on that design
> From last time. It's not hard to port that design over, if desired.

I gave my opinion about the parametrization here a couple of months
back, and thought that it was rather a neat design. I still think so:
http://www.postgresql.org/message-id/CAB7nPqRGQ60PWLb-CLLrvMoQwPAbnu-961W+xGPvG62RMSkcZQ@mail.gmail.com
In short:
1) Introduction of new pg_hba parameter require_encrypt, defaulting to
off, enforcing the clients to have encryption. This way an
administrator of a new server can prevent connections of old clients
if he/she wants to have all the connections excrypted.
2) Client-side parameter, that you named previously gss_encrypt, to
let a client decide if he wishes to do encryption or not.

>> So I finally began to dive into your new patch... And after testing
>> this is breaking the authentication protocol for GSS. I have been able
>> to connect to a server once, but at the second attempt and after
>> connection is failing with the following error:
>> psql: expected authentication request from server, but received ioltas
>
> Interesting. I will see if I can find anything. The capture posted
> earlier (thanks David!) suggests that the client doesn't expect the
> encrypted data.
>
> I suspect what has happened is a race between the client buffering data
> From the socket and the client processing the completion of GSSAPI
> authentication. This kind of issue is why my v1 handled GSSAPI at the
> protocol level, not at the transport level. I think we end up with
> encrypted data in the buffer that's supposed to be decrypted, and since
> the GSSAPI blob starts with \x00, it doesn't know what to do.
>
> I'll cut a v6 with most of the changes we've talked about here. It
> should address this issue, but I suspect that no one will be happy about
> how, since the client essentially needs to "un-read" some data.

Let's be sure that we come out with something rock-solid here, the
code paths taken for authentication do not require an authenticated
user, so any bugs introduced could have dangerous consequences for the
backend.

> As a side note, this would also explain why I can't reproduce the issue,
> since I'm running in very low-latency environments (three VMs on my
> laptop).

I'm doing my tests in single VM, with both krb5kdc and Postgres
running together.

>> Also, something that is missing is the parametrization that has been
>> discussed the last time this patch was on the mailing list. Where is
>> the capacity to control if a client is connecting to a server that is
>> performing encryption and downgrade to non-ecrypted connection should
>> the server not be able to support it? Enforcing a client to require
>> encryption support using pg_hba.conf was as well a good thing. Some
>> more infrastructure is needed here, I thought that there was an
>> agreement previously regarding that.
>
> This does not match my impression of the discussion, but I would be
> happy to be wrong about that since it is less work for me.

OK, good to know. I had the opposite impression actually :) See above.

>> Also, and to make the review a bit easier, it would be good to split
>> the patch into smaller pieces (thanks for waiting on my input here,
>> this became quite clear after looking at this code). Basically,
>> pg_GSS_error is moved to a new file, bringing with it pg_GSS_recvauth
>> because the error routine is being used by the new ones you are
>> introducing: be_gssapi_write, etc. The split that this patch is doing
>> is a bit confusing, all the GSS-related stuff is put within one single
>> file:
>> - read/write routines
>> - authentication routine
>> - constants
>> - routines for error handling
>> Mixing read/write routines with the authentication routine looks
>> wrong, because the read-write routines just need to create a
>> dependency with for example be-secure.c on the backend. In short,
>> where before authentication and secure read/writes after
>> authentication get linked to each other, and create a dependency that
>> did not exist before.
>>
>> For the sake of clarity I would suggest the following split:
>> - be-gss-common.c, where all the constants and the error handling
>> routine are located.
>> - Let authrecv in auth.c
>> - Move only the read/write routines to the new file be-[secure-]gssapi.c
>> Splitting the patches into one that moves around the routines, and a
>> second that introduces the new logic would bring more clarity.
>
> So... auth.c is now going to depend on be-gss-common.c, and
> be-secure-gssapi.c is also going to depend on be-gss-common.c. That
> doesn't seem better in terms of dependencies: now I'm creating two that
> didn't exist before.
>
> That said, I would believe that it makes everything clearer. I will do
> that shortly.

That's a personal suggestion on the matter. If you feel that the way
you did the separation is better, nothing prevents you from submitting
the patch as such. IMO making a clear separation between the
authentication code path and the read/write code path matters, and
this separation exists today. In any case, a patch doing the
refactoring, and a second patch adding the feature would greatly
facilitate the review. After looking at the patch once this is pretty
clear.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: [PATCH v6] GSSAPI encryption support
Date: 2016-03-08 22:44:38
Message-ID: jlgegbkmvxl.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

Here's yet another version of GSSAPI encryption support. It's also
available for viewing on my github:

https://github.com/frozencemetery/postgres/tree/feature/gssencrypt6

Let me hit the highlights of this time around:

- Fallback code is back! It's almost unchanged from early versions of
this patchset. Corresponding doc changes for this and the next item
are of course included.

- Minor protocol change. I did not realize that connection parameters
were not read until after auth was complete, which means that in this
version I go back to sending the AUTH_REQ_OK in the clear. Though I
found this initially irritating since it required re-working the
should_crypto conditions, it ends up being a net positive since I can
trade a library call for a couple variables.

- Client buffer flush on completion of authentication. This should
prevent the issue with the client getting unexpected message type of
NUL due to encrypted data not getting decrypted. I continue to be
unable to replicate this issue, but since the codepath triggers in the
"no data buffered case" all the math is sound. (Famous last words I'm
sure.)

- Code motion is its own patch. This was requested and hopefully
clarifies what's going on.

- Some GSSAPI authentication fixes have been applied. I've been staring
at this code too long now and writing this made me feel better. If it
should be a separate change that's fine and easy to do.

Thanks!

Attachment Content-Type Size
v6-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 13.4 KB
v6-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 36.6 KB
v6-0003-GSSAPI-authentication-cleanup.patch text/x-diff 4.8 KB

From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-09 16:55:17
Message-ID: 56E05575.9060200@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Robbie,

On 3/8/16 5:44 PM, Robbie Harwood wrote:
> Hello friends,
>
> Here's yet another version of GSSAPI encryption support. It's also
> available for viewing on my github:

I got this warning when applying the first patch in the set:

../other/v6-0001-Move-common-GSSAPI-code-into-its-own-files.patch:245:
new blank line at EOF.
+
warning: 1 line adds whitespace errors.

I know it's minor but I'm always happier when patches apply cleanly.

The build went fine but when testing I was unable to logon at all. I'm
using the same methodology as in
http://www.postgresql.org/message-id/56BE0FF9.70302@pgmasters.net except
that I'm running against 51c0f63 and using the v6 patch set.

psql simply hangs and never returns. I have attached a pcap of the
psql/postgres session generated with:

tcpdump -i lo -nnvvXSs 1514 port 5432 -w gssapi.pcap

If you would like me to capture more information please let me know
specifically how you would like me to capture it.

I reverted to v5 and got the same behavior I was seeing with v4 and v5,
namely that I can only logon occasionally and usually get this error:

psql: expected authentication request from server, but received

Using a fresh build from 51c0f63 I can logon reliably every time so I
don't think there's an issue in my environment.

--
-David
david(at)pgmasters(dot)net

Attachment Content-Type Size
gssapi.pcap application/octet-stream 2.6 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: David Steele <david(at)pgmasters(dot)net>, pgsql-hackers(at)postgresql(dot)org
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-09 20:14:20
Message-ID: jlgvb4v76jn.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Steele <david(at)pgmasters(dot)net> writes:

> On 3/8/16 5:44 PM, Robbie Harwood wrote:
>>
>> Here's yet another version of GSSAPI encryption support. It's also
>> available for viewing on my github:
>
> I got this warning when applying the first patch in the set:
>
> ../other/v6-0001-Move-common-GSSAPI-code-into-its-own-files.patch:245:
> new blank line at EOF.
> +
> warning: 1 line adds whitespace errors.

Hah, so it does. Thanks for catching it; will fix.

> The build went fine but when testing I was unable to logon at all. I'm
> using the same methodology as in
> http://www.postgresql.org/message-id/56BE0FF9.70302@pgmasters.net except
> that I'm running against 51c0f63 and using the v6 patch set.
>
> psql simply hangs and never returns. I have attached a pcap of the
> psql/postgres session generated with:
>
> tcpdump -i lo -nnvvXSs 1514 port 5432 -w gssapi.pcap
>
> If you would like me to capture more information please let me know
> specifically how you would like me to capture it.

Thank you for the pcap! (I'm using wireshark so formats it can open are
greatly appreciated.) This suggests that the hang is my client code's
fault, but just in case: I assume nothing unusual was logged on the
server?

v6-0002-Connection-encryption-support-for-GSSAPI.patch in fe-connect.c
at around line 2518 adds a call to appendBinaryPQExpBuffer and sets
conn->inEnd. Can you try without those lines?

Can you also (e.g., with gdb or by adding printf calls) tell me what the
values of conn->inStart, conn->inEnd, and conn->inCursor any time
(should only be once) that those lines are triggered?

> I reverted to v5 and got the same behavior I was seeing with v4 and v5,
> namely that I can only logon occasionally and usually get this error:
>
> psql: expected authentication request from server, but received
>
> Using a fresh build from 51c0f63 I can logon reliably every time so I
> don't think there's an issue in my environment.

Agreed, I'm sure I've caused it somehow, though I don't know what's
wrong yet. (And if it weren't my fault but you didn't get useful errors
out, that'd be my fault anyway for not checking enough stuff!)

I don't know if this would say anything relevant, but it might be
interesting to see what the results are of applying [1] to the v5 code.
It's the same approach to solving the problem, though it happens at a
different time due to the aforementioned protocol change between v5 and
v6.

Thanks,
--Robbie

[1] https://github.com/frozencemetery/postgres/commit/82c89227a6b499ac9273044f91cff747c154629f


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: David Steele <david(at)pgmasters(dot)net>, pgsql-hackers(at)postgresql(dot)org
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-14 20:10:51
Message-ID: jlgegbcq0qc.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Steele <david(at)pgmasters(dot)net> writes:

> Hi Robbie,
>
> On 3/8/16 5:44 PM, Robbie Harwood wrote:
>> Hello friends,
>>
>> Here's yet another version of GSSAPI encryption support. It's also
>> available for viewing on my github:
>
> The build went fine but when testing I was unable to logon at all. I'm
> using the same methodology as in
> http://www.postgresql.org/message-id/56BE0FF9.70302@pgmasters.net except
> that I'm running against 51c0f63 and using the v6 patch set.
>
> psql simply hangs and never returns. I have attached a pcap of the
> psql/postgres session generated with:
>
> tcpdump -i lo -nnvvXSs 1514 port 5432 -w gssapi.pcap
>
> If you would like me to capture more information please let me know
> specifically how you would like me to capture it.

Please disregard my other email. I think I've found the issue; will
post a new version in a moment.


From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-14 20:13:48
Message-ID: 56E71B7C.6050108@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3/14/16 4:10 PM, Robbie Harwood wrote:
> David Steele <david(at)pgmasters(dot)net> writes:
>
>> Hi Robbie,
>>
>> On 3/8/16 5:44 PM, Robbie Harwood wrote:
>>> Hello friends,
>>>
>>> Here's yet another version of GSSAPI encryption support. It's also
>>> available for viewing on my github:
>>
>> The build went fine but when testing I was unable to logon at all. I'm
>> using the same methodology as in
>> http://www.postgresql.org/message-id/56BE0FF9.70302@pgmasters.net except
>> that I'm running against 51c0f63 and using the v6 patch set.
>>
>> psql simply hangs and never returns. I have attached a pcap of the
>> psql/postgres session generated with:
>>
>> tcpdump -i lo -nnvvXSs 1514 port 5432 -w gssapi.pcap
>>
>> If you would like me to capture more information please let me know
>> specifically how you would like me to capture it.
>
> Please disregard my other email. I think I've found the issue; will
> post a new version in a moment.

Strange timing since I was just testing this. Here's what I got:

$ pg/bin/psql -h localhost -U vagrant(at)PGMASTERS(dot)NET postgres
conn->inStart = 179, conn->inEnd = 179, conn->inCursor = 179
psql (9.6devel)
Type "help" for help.

postgres=>

This was after commenting out:

// appendBinaryPQExpBuffer(&conn->gwritebuf,
// conn->inBuffer + conn->inStart,
// conn->inEnd - conn->inStart);
// conn->inEnd = conn->inStart;

The good news I can log on every time now!

--
-David
david(at)pgmasters(dot)net


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH v7] GSSAPI encryption support
Date: 2016-03-14 23:11:42
Message-ID: jlgbn6gpscx.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

New week, new version. GitHub link:
https://github.com/frozencemetery/postgres/tree/feature/gssencrypt7

Changes in this version:

- Removed extra whitespace in auth code movement.

- Fixed connection desync issue. A diff of this and v6 will reveal
three issues:

- First, that pg_GSS_read() didn't properly handle having a full
buffer when called because pqsecure_raw_read() doesn't handle reads of
size 0. I've elected to change my own code here only, but it may be
desirable to change pqsecure_raw_read() as well depending on whether
other people are likely to hit that.

- Second, that I was shunting data into the wrong buffer (don't know
how this was overlooked; it has "write" right there in the name).

- Third, that I'm now immediately decrypting that data into
conn->inBuffer rather than deferring that step until later. This
removes the hang because now the connection will not erroneously get
stuck polling while data is buffered.

Thanks!

Attachment Content-Type Size
v7-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 13.4 KB
v7-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 37.1 KB
v7-0003-GSSAPI-authentication-cleanup.patch text/x-diff 4.8 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: David Steele <david(at)pgmasters(dot)net>, pgsql-hackers(at)postgresql(dot)org
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-14 23:20:47
Message-ID: jlg8u1kprxs.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Steele <david(at)pgmasters(dot)net> writes:

> On 3/14/16 4:10 PM, Robbie Harwood wrote:
>
>> David Steele <david(at)pgmasters(dot)net> writes:
>>
>>> On 3/8/16 5:44 PM, Robbie Harwood wrote:
>>>
>>>> Here's yet another version of GSSAPI encryption support. It's also
>>>> available for viewing on my github:
>>>
>>> psql simply hangs and never returns. I have attached a pcap of the
>>> psql/postgres session generated with:
>>
>> Please disregard my other email. I think I've found the issue; will
>> post a new version in a moment.
>
> Strange timing since I was just testing this. Here's what I got:
>
> $ pg/bin/psql -h localhost -U vagrant(at)PGMASTERS(dot)NET postgres
> conn->inStart = 179, conn->inEnd = 179, conn->inCursor = 179
> psql (9.6devel)
> Type "help" for help.
>
> postgres=>

Thanks, that certainly is interesting! I did finally manage to
reproduce the issue on my end, but the rate of incidence is much lower
than what you and Michael were seeing: I have to run connections in a
loop for about 10-20 minutes before it makes itself apparent (and no,
it's not due to entropy). Apparently I just wasn't patient enough.

> This was after commenting out:
>
> // appendBinaryPQExpBuffer(&conn->gwritebuf,
> // conn->inBuffer + conn->inStart,
> // conn->inEnd - conn->inStart);
> // conn->inEnd = conn->inStart;
>
> The good news I can log on every time now!

Since conn->inStart == conn->inEnd in the case you were testing, the
lines you commented out would have been a no-op anyway (that's the
normal case of operation, as far as I can tell). That said, the chances
of hitting the race for me seemed very dependent on how much code wants
to run in that conditional: I got it up to 30-40 minutes when I added a
lot of printf()s (can't just run in gdb because it's nondeterministic
and rr has flushing bugs at the moment).

All that is to say: thank you very much for investigating that!


From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-14 23:33:33
Message-ID: 56E74A4D.4000502@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3/14/16 7:20 PM, Robbie Harwood wrote:

> David Steele <david(at)pgmasters(dot)net> writes:
>
>>
>> Strange timing since I was just testing this. Here's what I got:
>>
>> $ pg/bin/psql -h localhost -U vagrant(at)PGMASTERS(dot)NET postgres
>> conn->inStart = 179, conn->inEnd = 179, conn->inCursor = 179
>> psql (9.6devel)
>> Type "help" for help.
>>
>> postgres=>
>
> Thanks, that certainly is interesting! I did finally manage to
> reproduce the issue on my end, but the rate of incidence is much lower
> than what you and Michael were seeing: I have to run connections in a
> loop for about 10-20 minutes before it makes itself apparent (and no,
> it's not due to entropy). Apparently I just wasn't patient enough.

I'm running client and server on the same VM - perhaps that led to less
latency than your setup?

> All that is to say: thank you very much for investigating that!

My pleasure!

--
-David
david(at)pgmasters(dot)net


From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-15 14:12:34
Message-ID: 56E81852.1060005@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3/8/16 5:44 PM, Robbie Harwood wrote:

> Here's yet another version of GSSAPI encryption support.

OK, everything seems to be working fine with a 9.6 client and server so
next I tested older clients and I got this error:

$ /usr/lib/postgresql/9.1/bin/psql -h localhost \
-U vagrant(at)PGMASTERS(dot)NET postgres
psql: FATAL: GSSAPI did no provide required flags

There's a small typo in the error message, BTW.

Here's the output from the server logs:

DEBUG: forked new backend, pid=7746 socket=9
DEBUG: postgres child[7746]: starting with (
DEBUG: postgres
DEBUG: )
DEBUG: InitPostgres
DEBUG: my backend ID is 2
DEBUG: StartTransaction
DEBUG: name: unnamed; blockState: DEFAULT; state: INPROGR,
xid/subid/cid: 0/1/0, nestlvl: 1, children:
DEBUG: Processing received GSS token of length 667
DEBUG: gss_accept_sec_context major: 0, minor: 0, outlen: 161,
outflags: 1b2
DEBUG: sending GSS response token of length 161
DEBUG: sending GSS token of length 161
FATAL: GSSAPI did no provide required flags
DEBUG: shmem_exit(1): 1 before_shmem_exit callbacks to make
DEBUG: shmem_exit(1): 6 on_shmem_exit callbacks to make
DEBUG: proc_exit(1): 3 callbacks to make
DEBUG: exit(1)
DEBUG: shmem_exit(-1): 0 before_shmem_exit callbacks to make
DEBUG: shmem_exit(-1): 0 on_shmem_exit callbacks to make
DEBUG: proc_exit(-1): 0 callbacks to make
DEBUG: reaping dead processes
DEBUG: server process (PID 7746) exited with exit code 1

I got the same result with a 9.4 client so didn't try any others.

--
-David
david(at)pgmasters(dot)net


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: David Steele <david(at)pgmasters(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-15 16:53:46
Message-ID: CAB7nPqTjnLWBOepE+Oy5WZBjcq7sRJ9_uKvvXuThst9dvBxkZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Mar 15, 2016 at 3:12 PM, David Steele <david(at)pgmasters(dot)net> wrote:
> On 3/8/16 5:44 PM, Robbie Harwood wrote:
>> Here's yet another version of GSSAPI encryption support.

This looks far more stable than last versions, cool to see the
progress. pgbench -C does not complain on my side so that's a good
thing. This is not yet a detailed review, there are a couple of things
that I find strange in what you did and are potential subject to bugs,
but I need a bit of time to let that mature a bit. This is not
something yet committable, but I really like the direction that the
patch is taking.

For now, regarding 0002:
/*
- * Flush message so client will see it, except for AUTH_REQ_OK, which need
- * not be sent until we are ready for queries.
+ * In most cases, we do not need to send AUTH_REQ_OK until we are ready
+ * for queries, but if we are doing GSSAPI encryption that request must go
+ * out now.
*/
- if (areq != AUTH_REQ_OK)
- pq_flush();
+ pq_flush();
Er, this sends unconditionally the message without caring about the
protocol, and so this is incorrect, no?

+#ifdef ENABLE_GSS
+ if (conn->gss->buf.data)
+ pfree(conn->gss->buf.data);
+ if (conn->gss->writebuf.data)
+ pfree(conn->gss->writebuf.data);
+#endif
You should use resetStringInfo here.

> OK, everything seems to be working fine with a 9.6 client and server so
> next I tested older clients and I got this error:
>
> $ /usr/lib/postgresql/9.1/bin/psql -h localhost \
> -U vagrant(at)PGMASTERS(dot)NET postgres
> psql: FATAL: GSSAPI did no provide required flags
>
> There's a small typo in the error message, BTW.

And in 0003, the previous error is caused by that:
+ target_flags = GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG |
+ GSS_C_SEQUENCE_FLAG | GSS_C_CONF_FLAG | GSS_C_INTEG_FLAG;
+ if ((gflags & target_flags) != target_flags)
+ {
+ ereport(FATAL, (errmsg("GSSAPI did no provide required flags")));
+ return STATUS_ERROR;
+ }
Yeah, this is a recipe for protocol incompatibility and here the
connection context is not yet fully defined I believe. We need to be
careful.

- maj_stat = gss_accept_sec_context(
- &min_stat,
+ maj_stat = gss_accept_sec_context(&min_stat,
This is just noise.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-15 19:41:14
Message-ID: jlgtwk7il5x.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Tue, Mar 15, 2016 at 3:12 PM, David Steele <david(at)pgmasters(dot)net> wrote:
>> On 3/8/16 5:44 PM, Robbie Harwood wrote:
>>> Here's yet another version of GSSAPI encryption support.
>>
>> This looks far more stable than last versions, cool to see the
>> progress. pgbench -C does not complain on my side so that's a good
>> thing. This is not yet a detailed review, there are a couple of
>> things that I find strange in what you did and are potential subject
>> to bugs, but I need a bit of time to let that mature a bit. This is
>> not something yet committable, but I really like the direction that
>> the patch is taking.

Thanks! I must admit a preference for receiving all feedback at once
(reduces back-and-forth overhead), but if you feel there are still
design-type problems then that's very reasonable. (I also admit to
feeling the pressure of feature freeze in less than a month.)

> For now, regarding 0002:
> /*
> - * Flush message so client will see it, except for AUTH_REQ_OK, which need
> - * not be sent until we are ready for queries.
> + * In most cases, we do not need to send AUTH_REQ_OK until we are ready
> + * for queries, but if we are doing GSSAPI encryption that request must go
> + * out now.
> */
> - if (areq != AUTH_REQ_OK)
> - pq_flush();
> + pq_flush();
> Er, this sends unconditionally the message without caring about the
> protocol, and so this is incorrect, no?

My impression from reading the old version of the comment above it was
that on other protocols it could go either way. I think last time I
made it conditional; I can do so again if it is desired. It's certainly
not /incorrect/ to send it immediately; there's just a question of
performance by minimizing the number of writes as far as I can tell.

> +#ifdef ENABLE_GSS
> + if (conn->gss->buf.data)
> + pfree(conn->gss->buf.data);
> + if (conn->gss->writebuf.data)
> + pfree(conn->gss->writebuf.data);
> +#endif
> You should use resetStringInfo here.

That will leak since resetStringInfo() doesn't free the underlying
representation.

>> OK, everything seems to be working fine with a 9.6 client and server so
>> next I tested older clients and I got this error:
>>
>> $ /usr/lib/postgresql/9.1/bin/psql -h localhost \
>> -U vagrant(at)PGMASTERS(dot)NET postgres
>> psql: FATAL: GSSAPI did no provide required flags
>>
>> There's a small typo in the error message, BTW.

Thanks, will fix. I forgot that MIT doesn't provide GSS_C_REPLAY_FLAG
and GSS_C_SEQUENCE_FLAG by default. Removing those from auth.c should
temporarily resolve the problem, which is what I'll do in the next
version. (Tested with MIT krb5.)

On the subject of older code, I realized (one of those wake up in the
middle of the night-type moments) that the old server has a potential
problem with new clients now in that we try to decrypt the "help I don't
recognize connection parameter gss_encrypt" error message. v8 will have
some sort of a fix, though I don't know what yet. The only thing I've
come up with so far is to have the client decrypt check the first time
through for packets beginning with 'E'. Pretty much anything I can do
will end up being a poor substitute for being at the protocol layer
anyway.

> And in 0003, the previous error is caused by that:
> + target_flags = GSS_C_MUTUAL_FLAG | GSS_C_REPLAY_FLAG |
> + GSS_C_SEQUENCE_FLAG | GSS_C_CONF_FLAG | GSS_C_INTEG_FLAG;
> + if ((gflags & target_flags) != target_flags)
> + {
> + ereport(FATAL, (errmsg("GSSAPI did no provide required flags")));
> + return STATUS_ERROR;
> + }
> Yeah, this is a recipe for protocol incompatibility and here the
> connection context is not yet fully defined I believe. We need to be
> careful.

Nope, it's done. This is happening immediately prior to username
checks. By the time we exit the do/while the context is fully
complete.

> - maj_stat = gss_accept_sec_context(
> - &min_stat,
> + maj_stat = gss_accept_sec_context(&min_stat,
>
> This is just noise.

You're not wrong, though I do think it makes the code more readable by
enforcing style and this is a "cleanup" commit. I'll take it out if it
bothers you.


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-15 19:54:36
Message-ID: 20160315195436.GE3127@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
> > - maj_stat = gss_accept_sec_context(
> > - &min_stat,
> > + maj_stat = gss_accept_sec_context(&min_stat,
> >
> > This is just noise.
>
> You're not wrong, though I do think it makes the code more readable by
> enforcing style and this is a "cleanup" commit. I'll take it out if it
> bothers you.

First, thanks much for working on this, I've been following along the
discussions and hope to be able to help move it to commit, once it's
ready.

Secondly, generally, speaking, we prefer that 'cleanup' type changes
(particularly whitespace-only ones) are in independent commits which are
marked as just whitespace/indentation changes. We have a number of
organizations which follow our code changes and it makes it more
difficult on them to include whitespace/indentation changes with code
changes.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, David Steele <david(at)pgmasters(dot)net>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v6] GSSAPI encryption support
Date: 2016-03-15 20:35:26
Message-ID: jlgr3fbiinl.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> Robbie,
>
> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>> > - maj_stat = gss_accept_sec_context(
>> > - &min_stat,
>> > + maj_stat = gss_accept_sec_context(&min_stat,
>> >
>> > This is just noise.
>>
>> You're not wrong, though I do think it makes the code more readable by
>> enforcing style and this is a "cleanup" commit. I'll take it out if it
>> bothers you.
>
> First, thanks much for working on this, I've been following along the
> discussions and hope to be able to help move it to commit, once it's
> ready.
>
> Secondly, generally, speaking, we prefer that 'cleanup' type changes
> (particularly whitespace-only ones) are in independent commits which are
> marked as just whitespace/indentation changes. We have a number of
> organizations which follow our code changes and it makes it more
> difficult on them to include whitespace/indentation changes with code
> changes.

Thanks for the clarification. I'll be sure to take it out!


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH v8] GSSAPI encryption support
Date: 2016-03-20 04:09:27
Message-ID: jlg37rlg58o.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

A new version of my GSSAPI encryption patchset is available, both in
this email and on my github:
https://github.com/frozencemetery/postgres/tree/feature/gssencrypt8

What changed:

- Fixed fallback in the new server/old client case. The server flag
checking has been reduced. In the (distant) future when all old
clients are gone, the checking should be increased in strength once
again.

- Fixed fallback in the old server/new client case. This consists of
checking whether the first message we receive after auth is done is an
error, and raising it without decrypting if it is so that reconnection
can happen if desired. The quality of the fallback path has also
generally been improved.

- Removed overzealous whitespace cleanup. I'm a packager and have been
bitten by upstreams doing this; I should have known better.

- Made flushing the AUTH_REQ_OK message conditional again.

- Fixed typo in server error message for insufficient GSSAPI protection.

Thanks!

Attachment Content-Type Size
v8-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 13.4 KB
v8-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 38.0 KB
v8-0003-GSSAPI-authentication-cleanup.patch text/x-diff 4.6 KB

From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v8] GSSAPI encryption support
Date: 2016-03-25 13:10:37
Message-ID: 56F538CD.5030904@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3/20/16 12:09 AM, Robbie Harwood wrote:
> Hello friends,
>
> A new version of my GSSAPI encryption patchset is available, both in
> this email and on my github:
> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt8

Excellent, Robbie! I've run this patch through my test cases and
everything works.

Now that it's working I'll be writing up an actual review so expect that
by Monday.

--
-David
david(at)pgmasters(dot)net


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: David Steele <david(at)pgmasters(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v8] GSSAPI encryption support
Date: 2016-03-25 13:15:27
Message-ID: CAB7nPqTfDrdHbJ6bteauaxQw9vmkbjSEzuoYHsuGg_YExaobJQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Mar 25, 2016 at 10:10 PM, David Steele <david(at)pgmasters(dot)net> wrote:
> Excellent, Robbie! I've run this patch through my test cases and
> everything works.
>
> Now that it's working I'll be writing up an actual review so expect that
> by Monday.

(I haven't given up on this patch yet, sorry for the low activity on
this thread)
--
Michael


From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v8] GSSAPI encryption support
Date: 2016-03-29 13:22:26
Message-ID: 56FA8192.4010605@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi Robbie,

On 3/20/16 12:09 AM, Robbie Harwood wrote:

> A new version of my GSSAPI encryption patchset is available

Here's a more thorough review:

* PATCH - Move common GSSAPI code into its own files

diff --git a/src/backend/libpq/be-gssapi-common.c

+ if (msg_ctx)
+
+ /*
+ * More than one message available. XXX: Should we loop and read all
+ * messages? (same below)
+ */

It seems like it would be a good idea to pull all error messages if only
for debugging purposes.

+ /* Fetch mechanism minor status message */
+ msg_ctx = 0;
+ gss_display_status(&lmin_s, min_stat, GSS_C_MECH_CODE,
+ GSS_C_NO_OID, &msg_ctx, &gmsg);
+ strlcpy(msg_minor, gmsg.value, sizeof(msg_minor));
+ gss_release_buffer(&lmin_s, &gmsg);
+
+ if (msg_ctx)
+ ereport(WARNING,
+ (errmsg_internal("incomplete GSS minor error report")));

Same here.

* PATCH - Connection encryption support for GSSAPI

+++ b/doc/src/sgml/client-auth.sgml

data sent over the database connection will be sent unencrypted unless
- <acronym>SSL</acronym> is used.
+ <acronym>SSL</acronym> is used, or <acronym>GSSAPI</acronym> encryption
+ is in use.

Perhaps "... unless SSL or GSSAPI encryption is used."

+ <term><literal>require_encrypt</literal></term>
+ <listitem>
+ <para>
+ Whether to require GSSAPI encryption. Default is off, which causes
+ GSSAPI encryption to be enabled if available and requested for
+ compatability with old clients. It is recommended to set this
unless
+ old clients are present.

Some rewording:

Require GSSAPI encryption. The default is off which enables GSSAPI
encryption only when available and requested to maintain compatability
with older clients. This setting should be enabled unless older clients
are present.

+++ b/doc/src/sgml/libpq.sgml

@@ -1356,6 +1356,18 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
</listitem>
</varlistentry>

+ <term><literal>gss_enc_require</literal></term>
+ <listitem>
+ <para>
+ If set, whether to require GSSAPI encryption support from the
remote
+ server. Defaults to unset, which will cause the client to fall
back
+ to not using GSSAPI encryption if the server does not support
+ encryption through GSSAPI.
+ </para>

Some rewording:

Require GSSAPI encryption support from the remote server when set. By
default clients will fall back to not using GSSAPI encryption if the
server does not support encryption through GSSAPI.

+++ b/doc/src/sgml/runtime.sgml

I think you mean postgresql.conf?

+ <para>
+ GSSAPI connections can also encrypt all data sent across the network.
+ In the <filename>pg_hba.conf</> file, the GSSAPI authentication
method
+ has a parameter to require encryption; otherwise connections will be
+ encrypted if available and requested by the client. On the
client side,
+ there is also a parameter to require GSSAPI encryption support
from the
+ server.
+ </para>

I think a link to the client parameter would be valuable here.

+++ b/src/backend/libpq/auth.c

+ * In most cases, we do not need to send AUTH_REQ_OK until we are ready
+ * for queries, but if we are doing GSSAPI encryption that request must go
+ * out now.

Why?

+++ b/src/backend/libpq/be-secure-gssapi.c

Some of the functions in this file are missing comment headers and
should have more inline comments for each major section.

+ ret = be_gssapi_should_crypto(port);

Add LF here.

+ port->gss->writebuf.cursor += ret;

And here.

+ /* need to be called again */

And here. Well, you get the idea.

These functions could all use more whitespace and comments.

+++ b/src/backend/utils/misc/guc.c

+ {
+ {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
+ gettext_noop("Whether client wants encryption for this connection."),

Perhaps, "Require encryption for all GSSAPI connections."

+++ b/src/interfaces/libpq/fe-connect.c

+ if (n > 0)
+ conn->inEnd += n;
+ /*
+ * If n < 0, then this wasn't a full request and
+ * either more data will be available later to
+ * complete it or we will error out then.
+ */

Shouldn't this comment block go above the if?

+ /*
+ * We tried to request GSSAPI encryption, but the
+ * server doesn't support it. Retries are permitted
+ * here, so hang up and try again. A connection that
+ * doesn't rupport appname will also not support
+ * GSSAPI encryption.
+ */

typo - "doesn't support appname".

+++ b/src/interfaces/libpq/fe-secure-gssapi.c

Comments are a bit better here than in be-secure-gssapi.c but could
still be better. And again, more whitespace.

* PATCH 3 - GSSAPI authentication cleanup

+++ b/src/backend/libpq/auth.c

+ * GSS_C_REPLAY_FLAG and GSS_C_SEQUENCE_FLAG are missing for compatability
+ * with older clients and should be added in as soon as possible.

Please elaborate here. Why should they be added and what functionality
is missing before they are.

+++ b/src/backend/libpq/be-gssapi-common.c

-#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
-/*
- * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
- * that contain the OIDs required. Redefine here, values copied
- * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
- */
-static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
-{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
-static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
-#endif

Can you explain why it's OK to remove this now? I can see you've
replaced it in gss_init_sec_context() with GSS_C_MUTUAL_FLAG. Have you
tested this on Win32?

Things look pretty good in general but fe-secure-gssapi.c and
be-secure-gssapi.c should both be reworked with better comments and more
whitespace before this patch goes to a committer.

--
-David
david(at)pgmasters(dot)net


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: David Steele <david(at)pgmasters(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v8] GSSAPI encryption support
Date: 2016-03-29 21:05:45
Message-ID: jlgoa9x5712.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

David Steele <david(at)pgmasters(dot)net> writes:

> On 3/20/16 12:09 AM, Robbie Harwood wrote:
>
>> A new version of my GSSAPI encryption patchset is available
>
> Here's a more thorough review:

Thanks for the review! To keep this a manageable size, I'm going to
trim pretty heavily. If I haven't replied to something, please
interpret it to mean that I think it's a good suggestion and will
fix/change in v9.

> +++ b/doc/src/sgml/runtime.sgml
>
> I think you mean postgresql.conf?

Sorry, what does this review comment go with?

> +++ b/src/backend/libpq/auth.c
>
> + * In most cases, we do not need to send AUTH_REQ_OK until we are ready
> + * for queries, but if we are doing GSSAPI encryption that request must go
> + * out now.
>
> Why?

Because otherwise we will send the connection spew (connection
parameters and such) unencrypted, since it will get grouped with the
AUTH_REQ_OK packet. I'll note this in the comment.

> + ret = be_gssapi_should_crypto(port);
>
> Add LF here.
>
>
> + port->gss->writebuf.cursor += ret;
>
> And here.
>
> + /* need to be called again */
>
> And here. Well, you get the idea.

Sorry, what is LF? ASCII newline?

> * PATCH 3 - GSSAPI authentication cleanup
>
> +++ b/src/backend/libpq/auth.c
>
> + * GSS_C_REPLAY_FLAG and GSS_C_SEQUENCE_FLAG are missing for compatability
> + * with older clients and should be added in as soon as possible.
>
> Please elaborate here. Why should they be added and what functionality
> is missing before they are.

It's request reply detection and out-of-sequence detection. We can't
require them because old clients don't request them, and so would be
unable to connect. (There's some history of this in the last couple
versions I've posted, but it's not really interesting beyond "it doesn't
work".) I will clarify this comment.

> +++ b/src/backend/libpq/be-gssapi-common.c
>
> -#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
> -/*
> - * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
> - * that contain the OIDs required. Redefine here, values copied
> - * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
> - */
> -static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
> -{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
> -static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
> -#endif
>
> Can you explain why it's OK to remove this now? I can see you've
> replaced it in gss_init_sec_context() with GSS_C_MUTUAL_FLAG. Have you
> tested this on Win32?

This comment is old enough that it references sources from Athena. If
this is in fact a current krb5 bug (which I doubt, since MIT tests
windows rather heavily), then it should be filed against krb5 instead of
kludged around here. I do not however have win32 machines to test this
with. (GSS_C_MUTUAL_FLAG is unrelated; it just requests that the client
and server are both authenticated to each other.)

Thanks,
--Robbie


From: David Steele <david(at)pgmasters(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v8] GSSAPI encryption support
Date: 2016-03-29 22:45:26
Message-ID: 56FB0586.6010807@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 3/29/16 5:05 PM, Robbie Harwood wrote:
> David Steele <david(at)pgmasters(dot)net> writes:
>
>> On 3/20/16 12:09 AM, Robbie Harwood wrote:
>>
>>> A new version of my GSSAPI encryption patchset is available
>>
>> Here's a more thorough review:
>
> Thanks for the review! To keep this a manageable size, I'm going to
> trim pretty heavily. If I haven't replied to something, please
> interpret it to mean that I think it's a good suggestion and will
> fix/change in v9.
>
>> +++ b/doc/src/sgml/runtime.sgml
>>
>> I think you mean postgresql.conf?
>
> Sorry, what does this review comment go with?

Oops! That was a comment I made then realized I had misunderstood what
was going on. I removed the code but not the comment apparently.

Thanks for the other clarifications.

--
-David
david(at)pgmasters(dot)net


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2016-03-30 04:01:50
Message-ID: jlgh9fo62c1.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

A new version of my GSSAPI encryption patchset is available, both in
this email and on my github:
https://github.com/frozencemetery/postgres/tree/feature/gssencrypt9

This version is intended to address David's review suggestions:

- The only code change (not counting SGML and comments) is that I've
resolved the pre-existing "XXX: Should we loop and read all messages?"
comment in the affirmative by... looping and reading all messages in
pg_GSS_error. Though commented on as part of the first patch, this is
bundled with the rest of the auth cleanup since the first patch is
code motion only.

- Several changes to comments, documentation rewordings, and whitespace
additions. I look forward to finding out what needs even more of the
same treatment. Of all the changesets I've posted thus far, this
might be the one for which it makes the most sense to see what changed
by diffing from the previous changeset.

Thanks!

Attachment Content-Type Size
v9-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 13.4 KB
v9-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 41.2 KB
v9-0003-GSSAPI-authentication-cleanup.patch text/x-diff 6.7 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2016-03-31 05:14:37
Message-ID: CAB7nPqRHGd9SS0RDPZjThEWfqNRJZfKB=UZ5zLDY+zR6P1DaBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Mar 30, 2016 at 1:01 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> A new version of my GSSAPI encryption patchset is available, both in
> this email and on my github:
> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt9
>
> This version is intended to address David's review suggestions:
>
> - The only code change (not counting SGML and comments) is that I've
> resolved the pre-existing "XXX: Should we loop and read all messages?"
> comment in the affirmative by... looping and reading all messages in
> pg_GSS_error. Though commented on as part of the first patch, this is
> bundled with the rest of the auth cleanup since the first patch is
> code motion only.
>
> - Several changes to comments, documentation rewordings, and whitespace
> additions. I look forward to finding out what needs even more of the
> same treatment. Of all the changesets I've posted thus far, this
> might be the one for which it makes the most sense to see what changed
> by diffing from the previous changeset.

Thanks for the new versions. For now I have been having a look at only 0001.

The first thing I have noticed is that 0001 breaks the Windows build
using Visual Studio. When building without GSSAPI, fe-gssapi-common.c
and be-gssapi-common.c should be removed from the list of files used
so that's simple enough to fix. Now when GSSAPI build is enabled,
there are some declaration conflicts with your patch, leading to many
compilation errors. This took me some time to figure out but the cause
is this diff in be-gssapi-common.c:
+#include "libpq/be-gssapi-common.h"
+
+#include "postgres.h"

postgres.h should be declared *before* be-gssapi-common.h. As I
suggested the refactoring and I guess you don't have a Windows
environment at hand, attached is a patch that fixes the build with and
without gssapi for Visual Studio, that can be applied on top of your
0001. Feel free to rebase using it.

Note for others: I had as well to patch the MSVC scripts because in
the newest installations of Kerberos:
- inc/ does not exist anymore, include/ does
- The current VS scripts ignore completely x64 builds, the libraries
linked to are for x86 unconditionally.
I am not sure if there are *any* people building the code with
Kerberos on Windows except I, but as things stand those scripts are
rather broken in my view.

Now looking at 0002 and 0003...
--
Michael

Attachment Content-Type Size
gssapi-enc-fix-msvc.patch text/x-patch 2.1 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2016-03-31 07:48:21
Message-ID: CAB7nPqTDxaPHo_W6-_Ugh47Nm-cCRLKffoZpMWLr731xTj3a8Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Mar 31, 2016 at 2:14 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Wed, Mar 30, 2016 at 1:01 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> A new version of my GSSAPI encryption patchset is available, both in
>> this email and on my github:
>> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt9
>>
>> This version is intended to address David's review suggestions:
>>
>> - The only code change (not counting SGML and comments) is that I've
>> resolved the pre-existing "XXX: Should we loop and read all messages?"
>> comment in the affirmative by... looping and reading all messages in
>> pg_GSS_error. Though commented on as part of the first patch, this is
>> bundled with the rest of the auth cleanup since the first patch is
>> code motion only.
>>
>> - Several changes to comments, documentation rewordings, and whitespace
>> additions. I look forward to finding out what needs even more of the
>> same treatment. Of all the changesets I've posted thus far, this
>> might be the one for which it makes the most sense to see what changed
>> by diffing from the previous changeset.
>
> Thanks for the new versions. For now I have been having a look at only 0001.
>
> The first thing I have noticed is that 0001 breaks the Windows build
> using Visual Studio. When building without GSSAPI, fe-gssapi-common.c
> and be-gssapi-common.c should be removed from the list of files used
> so that's simple enough to fix. Now when GSSAPI build is enabled,
> there are some declaration conflicts with your patch, leading to many
> compilation errors. This took me some time to figure out but the cause
> is this diff in be-gssapi-common.c:
> +#include "libpq/be-gssapi-common.h"
> +
> +#include "postgres.h"
>
> postgres.h should be declared *before* be-gssapi-common.h. As I
> suggested the refactoring and I guess you don't have a Windows
> environment at hand, attached is a patch that fixes the build with and
> without gssapi for Visual Studio, that can be applied on top of your
> 0001. Feel free to rebase using it.
>
> Note for others: I had as well to patch the MSVC scripts because in
> the newest installations of Kerberos:
> - inc/ does not exist anymore, include/ does
> - The current VS scripts ignore completely x64 builds, the libraries
> linked to are for x86 unconditionally.
> I am not sure if there are *any* people building the code with
> Kerberos on Windows except I, but as things stand those scripts are
> rather broken in my view.

(Lonely feeling after typing that)

> Now looking at 0002 and 0003...

(Thanks for the split btw, this is far easier to look at)

Patch 0002 has the same problems, because it introduces the
gssapi-secure stuff (see attached patch that can be applied on top of
0002 fixing the windows build). When gss build is not enabled,
compilation is able to work, now when gss is enabled... See below.

+ <varlistentry id="libpq-connect-gss-enc-require"
xreflabel="gss_enc_require">
+ <term><literal>gss_enc_require</literal></term>
+ <listitem>
Perhaps renaming that gss_require_encrypt?

+++ b/src/backend/libpq/be-secure-gssapi.c
[...]
+#include "libpq/be-gssapi-common.h"
+
+#include "postgres.h"
Those should be reversed.

+ Require GSSAPI encryption. Defaults to off, which enables GSSAPI
+ encryption only when both available and requested to maintain
+ compatability with old clients. This setting should be enabled unless
+ old clients are present.
s/compatability/compatibility/

+ <para>
+ Require GSSAPI encryption support from the remote server when set. By
+ default, clients will fall back to not using GSSAPI encryption if the
+ server does not support encryption through GSSAPI.
+ </para>
Nitpick: the use of the <acronym> markup for GSSAPI may be more
adapted (I know, the docs are a bit lazy on that).

+ iov[0].iov_base = lenbuf;
+ iov[0].iov_len = 4;
+ iov[1].iov_base = output.value;
+ iov[1].iov_len = output.length;
+
+ ret = writev(port->sock, iov, 2);
writev and iovec are not present on Windows, so this code would never
compile there, and it does not sound that this patch is a reason
sufficient enough to drop support of GSSAPI on Windows.

+static ssize_t
+be_gssapi_should_crypto(Port *port)
+{
+ if (port->gss->ctx == GSS_C_NO_CONTEXT)
+ return 0;
+ return gss_encrypt;
+}
This should return a boolean, gss_encrypt being one.

+ if (!gss_encrypt && port->hba->require_encrypt)
+ {
+ ereport(FATAL, (errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
+ errmsg("GSSAPI encryption required from user \"%s\"",
+ port->user_name)));
+ }
Could be clearer here, with some error detail message, like:
"User has requested GSSAPI encryption, but server disallows it".

+static void
+assign_gss_encrypt(bool newval, void *extra)
+{
+ gss_encrypt = newval;
+}
Assigning a variable is done by the GUC machinery, you don't need that.

+ {
+ {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
+ gettext_noop("Require encryption for all GSSAPI connections."),
+ NULL,
+ GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
+ },
+ &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
+ },
Hm. I think that this would be better as PGC_POSTMASTER, the idea
behind this parameter being that the server enforces any connections
from clients to be encrypted. Clients should not have the right to
disable that at will depending on their session, and this is used in
authentication code paths. Also, this parameter is not documented, the
new parameters in pg_hba.conf and client-side are though.

A consequence of that, is that you would not need the following thingy:
+static bool
+check_gss_encrypt(bool *newval, void **extra, GucSource source)
+{
+ if (MyProcPort && MyProcPort->hba && MyProcPort->hba->require_encrypt &&
+ !*newval)
+ return false;
+ return true;
+}
So I'd suggest go with PGC_POSTMASTER first to simplify the code. We
could always relax that later on as need be, but that's not something
I think the code patch should bother much about.

+/*
+ * Only consider encryption when GSS context is complete
+ */
+ssize_t
+pg_GSS_should_crypto(PGconn *conn)
+{
s/crypto/encrypt?

+ /*
+ * We tried to request GSSAPI encryption, but the
+ * server doesn't support it. Retries are permitted
+ * here, so hang up and try again. A connection that
+ * doesn't support appname will also not support
+ * GSSAPI encryption.
+ */
+ const char *sqlstate;
Hm... I'm having second thoughts regarding gss_enc_require... This
code path would happen with a 9.6 client and a ~9.5 server, it seems a
bit treacherous to not ERROR here and fallback to an unencrypted
connection, client want to have an encrypted connection at the end.

I ran as well some tests, and I was able to crash the server. For
example take this SQL sequence:
CREATE TABLE aa (a int);
INSERT INTO aa VALUES (generate_series(1,1000000));
COPY aa TO STDOUT; -- crash
Which resulted in the following crash:
1046 AssertArg(MemoryContextIsValid(context));
(gdb) bt
#0 0x0000000000980552 in repalloc (pointer=0x2aa1bb0, size=8192) at mcxt.c:1046
#1 0x00000000006b75d5 in enlargeStringInfo (str=0x2aa6b70,
needed=7784) at stringinfo.c:286
#2 0x00000000006b7447 in appendBinaryStringInfo (str=0x2aa6b70,
data=0x2b40f25
"\337\321\261\026jy\352\334#\275l)\030\021s\235\f;\237\336\222PZsd\025>ioS\313`9C\375\a\340Z\354E\355\235\276y\307)D\261\344$D\347\323\036\177S\265\374\373\332~\264\377\317\375<\017\330\214P\a\237\321\375\002$=6\326\263\265{\237\344\214\344.W\303\216\373\206\325\257E\223N\t\324\223\030\363\252&\374\241T\322<\343,\233\203\320\252\343\344\f\036*\274\311\066\206\n\337\300\320L,>-A\016D\346\263pv+A>y\324\254k\003)\264\212zc\344\n\223\224\211\243\"\224\343\241Q\264\233\223\303\"\b\275\026%\302\352\065]8\207\244\304\353\220p\364\272\240\307\247l\216}N\325\aUO6\322\352\273"...,
datalen=7783) at stringinfo.c:213
#3 0x00000000006c8359 in be_gssapi_write (port=0x2aa31d0,
ptr=0x2aa8b48, len=8192) at be-secure-gssapi.c:158
#4 0x00000000006b9697 in secure_write (port=0x2aa31d0, ptr=0x2aa8b48,
len=8192) at be-secure.c:248
Which is actually related to your use of StringInfoData, pointing out
that the buffer handling should be reworked.

Also, to sum up with this patch, things behave like that:
1) server enforces encryption, client asks for encryption: all good,
encryption is done.
2) server enforces encryption, client does not ask for it: encryption
is enforced. Perhaps a FATAL on backend would be more adapted to let
the caller know the incompatibility? I am afraid of cases where the
client intentionally does *not* want encryption because of the
overhead that it creates at low-level to encrypt/decrypt the messages.
We'd lose control of that with this patch, and encryption can get
really a lot slower..
3) server does not enforce encryption, client asks for it: FATAL on
backend side.
4) server does not enforce encryption, client not asking for it, no encryption.

-#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
-/*
- * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
- * that contain the OIDs required. Redefine here, values copied
- * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
- */
-static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
-{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
-static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
-#endif
What makes you say that it is fine to remove that? If that's actually
the case, we should remove it as part of a separate patch.
--
Michael

Attachment Content-Type Size
gssapi-enc-fix-msvc-2.patch text/x-diff 2.0 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v1] GSSAPI encryption support
Date: 2016-03-31 07:50:59
Message-ID: CAB7nPqRREY-xCsZrkHiyXDNQnoi6Sjo6rs6huAKGp0J0U5_T-A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Mar 31, 2016 at 4:48 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> [long review]

Note as well that I have switched the patch as "waiting on author" for
the time being. Missing symbols on Windows as well as crashes are
pointing out that this should be returned with feedback for now (sorry
for the late reviews btw).
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v9] GSSAPI encryption support
Date: 2016-03-31 17:04:32
Message-ID: jlg37r660kf.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Thu, Mar 31, 2016 at 2:14 PM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
>> On Wed, Mar 30, 2016 at 1:01 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>> A new version of my GSSAPI encryption patchset is available, both in
>>> this email and on my github:
>>> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt9
>>>
>> postgres.h should be declared *before* be-gssapi-common.h. As I
>> suggested the refactoring and I guess you don't have a Windows
>> environment at hand, attached is a patch that fixes the build with and
>> without gssapi for Visual Studio, that can be applied on top of your
>> 0001. Feel free to rebase using it.

Thank you for the patch to fix 0001. There is basically no way I would
have been able to make it work on Windows myself.

> + iov[0].iov_base = lenbuf;
> + iov[0].iov_len = 4;
> + iov[1].iov_base = output.value;
> + iov[1].iov_len = output.length;
> +
> + ret = writev(port->sock, iov, 2);
>
> writev and iovec are not present on Windows, so this code would never
> compile there, and it does not sound that this patch is a reason
> sufficient enough to drop support of GSSAPI on Windows.

Um. Okay. I guess on Windows I'll make two write calls then, since the
only other option I see is to hit alloc again here.

> + {
> + {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
> + gettext_noop("Require encryption for all GSSAPI connections."),
> + NULL,
> + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
> + },
> + &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
> + },
>
> Hm. I think that this would be better as PGC_POSTMASTER, the idea
> behind this parameter being that the server enforces any connections
> from clients to be encrypted. Clients should not have the right to
> disable that at will depending on their session, and this is used in
> authentication code paths. Also, this parameter is not documented, the
> new parameters in pg_hba.conf and client-side are though.

Negative, setting PGC_POSTMASTER breaks the fallback support; I get

"psql: FATAL: parameter "gss_encrypt" cannot be changed without
restarting the server"

when trying to connect a new client to a new server.

I will add documentation.

> + /*
> + * We tried to request GSSAPI encryption, but the
> + * server doesn't support it. Retries are permitted
> + * here, so hang up and try again. A connection that
> + * doesn't support appname will also not support
> + * GSSAPI encryption.
> + */
> + const char *sqlstate;
> Hm... I'm having second thoughts regarding gss_enc_require... This
> code path would happen with a 9.6 client and a ~9.5 server, it seems a
> bit treacherous to not ERROR here and fallback to an unencrypted
> connection, client want to have an encrypted connection at the end.

I'm confused by what you're saying here.

1. If you have a 9.6 client and a 9.5 server, with no additional
connection parameters the client will reconnect and get an
unencrypted connection. This is the "fallback" support.

2. If the client passes gss_enc_require=1, then it will just fail
because the server cannot provide encryption.

> I ran as well some tests, and I was able to crash the server. For
> example take this SQL sequence:
> CREATE TABLE aa (a int);
> INSERT INTO aa VALUES (generate_series(1,1000000));
> COPY aa TO STDOUT; -- crash
> Which resulted in the following crash:
> 1046 AssertArg(MemoryContextIsValid(context));
> (gdb) bt
> #0 0x0000000000980552 in repalloc (pointer=0x2aa1bb0, size=8192) at mcxt.c:1046
> #1 0x00000000006b75d5 in enlargeStringInfo (str=0x2aa6b70,
> needed=7784) at stringinfo.c:286
> #2 0x00000000006b7447 in appendBinaryStringInfo (str=0x2aa6b70,
> data=0x2b40f25
> "\337\321\261\026jy\352\334#\275l)\030\021s\235\f;\237\336\222PZsd\025>ioS\313`9C\375\a\340Z\354E\355\235\276y\307)D\261\344$D\347\323\036\177S\265\374\373\332~\264\377\317\375<\017\330\214P\a\237\321\375\002$=6\326\263\265{\237\344\214\344.W\303\216\373\206\325\257E\223N\t\324\223\030\363\252&\374\241T\322<\343,\233\203\320\252\343\344\f\036*\274\311\066\206\n\337\300\320L,>-A\016D\346\263pv+A>y\324\254k\003)\264\212zc\344\n\223\224\211\243\"\224\343\241Q\264\233\223\303\"\b\275\026%\302\352\065]8\207\244\304\353\220p\364\272\240\307\247l\216}N\325\aUO6\322\352\273"...,
> datalen=7783) at stringinfo.c:213
> #3 0x00000000006c8359 in be_gssapi_write (port=0x2aa31d0,
> ptr=0x2aa8b48, len=8192) at be-secure-gssapi.c:158
> #4 0x00000000006b9697 in secure_write (port=0x2aa31d0, ptr=0x2aa8b48,
> len=8192) at be-secure.c:248
>
> Which is actually related to your use of StringInfoData, pointing out
> that the buffer handling should be reworked.

This crash is not deterministic. I do observe it though and will try to
debug. Any tips on debugging this are appreciated.

> 2) server enforces encryption, client does not ask for it: encryption
> is enforced. Perhaps a FATAL on backend would be more adapted to let
> the caller know the incompatibility? I am afraid of cases where the
> client intentionally does *not* want encryption because of the
> overhead that it creates at low-level to encrypt/decrypt the messages.
> We'd lose control of that with this patch, and encryption can get
> really a lot slower..

This is really late in the process to bring this up, but alright, let's
talk about it. I think about this in a manner similar to HTTPS: if
support for it is there, you don't want to have to have people think
about using it, you want that security by default. Wherever possible,
it should just happen.

The overhead of reasonable encryption is in general quite low, even more
so since Kerberos will be using symmetric cryptography (typically AES at
the time of writing, which specifically has CPU support in many cases).
Even running on something on lower-power hardware, you will typically
notice other problems (especially since we're working on a performant
database right now) before you notice performance impact due to
encryption.

To back that up, here's an article from a Google employee:
https://www.imperialviolet.org/2010/06/25/overclocking-ssl.html
To summarize, when they turned HTTPS on by default for GMail in 2010, no
new hardware was required and the performance impact was strongly
negligible.

> -#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
> -/*
> - * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
> - * that contain the OIDs required. Redefine here, values copied
> - * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
> - */
> -static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
> -{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
> -static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
> -#endif
> What makes you say that it is fine to remove that? If that's actually
> the case, we should remove it as part of a separate patch.

Please see earlier comments on David's review. I feel that part of a
"GSSAPI auth cleanup" patch it is in the right place.


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v9] GSSAPI encryption support
Date: 2016-03-31 19:45:56
Message-ID: 20160331194556.GA134261@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> > + iov[0].iov_base = lenbuf;
> > + iov[0].iov_len = 4;
> > + iov[1].iov_base = output.value;
> > + iov[1].iov_len = output.length;
> > +
> > + ret = writev(port->sock, iov, 2);
> >
> > writev and iovec are not present on Windows, so this code would never
> > compile there, and it does not sound that this patch is a reason
> > sufficient enough to drop support of GSSAPI on Windows.
>
> Um. Okay. I guess on Windows I'll make two write calls then, since the
> only other option I see is to hit alloc again here.

Hmm, I wouldn't push my luck by using writev here at all. We don't use
writev/readv anywhere, and it's quite possible that they are not present
on older Unixen which we still support.
http://pubs.opengroup.org/onlinepubs/009695399/functions/writev.html
says writev was introduced in "issue 4 version 2", which AFAICT is the
2004 version, but our baseline is SUSv2 (1997). So it's definitely not
workable.

> > + {
> > + {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
> > + gettext_noop("Require encryption for all GSSAPI connections."),
> > + NULL,
> > + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
> > + },
> > + &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
> > + },

Why is this marked NOT_IN_SAMPLE?

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v9] GSSAPI encryption support
Date: 2016-03-31 20:54:57
Message-ID: jlgtwjm4bby.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:

> Robbie Harwood wrote:
>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
>> > + iov[0].iov_base = lenbuf;
>> > + iov[0].iov_len = 4;
>> > + iov[1].iov_base = output.value;
>> > + iov[1].iov_len = output.length;
>> > +
>> > + ret = writev(port->sock, iov, 2);
>> >
>> > writev and iovec are not present on Windows, so this code would never
>> > compile there, and it does not sound that this patch is a reason
>> > sufficient enough to drop support of GSSAPI on Windows.
>>
>> Um. Okay. I guess on Windows I'll make two write calls then, since the
>> only other option I see is to hit alloc again here.
>
> Hmm, I wouldn't push my luck by using writev here at all. We don't use
> writev/readv anywhere, and it's quite possible that they are not present
> on older Unixen which we still support.
> http://pubs.opengroup.org/onlinepubs/009695399/functions/writev.html
> says writev was introduced in "issue 4 version 2", which AFAICT is the
> 2004 version, but our baseline is SUSv2 (1997). So it's definitely not
> workable.

Understood. What do you suggest instead? To give some context here,
writev() is being used here because I have a GSSAPI payload that is
(effectively) opaque and need to include length in it. The only
alternatives I can see are either allocating a new buffer and reading
the payload + length into it (incurs additional memory overhead), or
calling a write/send function twice (incurs syscall overhead at
minimum).

>> > + {
>> > + {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
>> > + gettext_noop("Require encryption for all GSSAPI connections."),
>> > + NULL,
>> > + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
>> > + },
>> > + &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
>> > + },
>
> Why is this marked NOT_IN_SAMPLE?

Well, because it's not something that's supposed to be set in the file
(and indeed, you can't set it there, if I understand
GUC_DISALLOW_IN_FILE). It's used only as a connection parameter, and I
use its presence / absence for the client and server to negotiate GSSAPI
encryption support.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v9] GSSAPI encryption support
Date: 2016-03-31 21:10:39
Message-ID: 8265.1459458639@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>>> + {
>>> + {"gss_encrypt", PGC_USERSET, CONN_AUTH_SECURITY,
>>> + gettext_noop("Require encryption for all GSSAPI connections."),
>>> + NULL,
>>> + GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE
>>> + },
>>> + &gss_encrypt, false, check_gss_encrypt, assign_gss_encrypt, NULL
>>> + },

>> Why is this marked NOT_IN_SAMPLE?

> Well, because it's not something that's supposed to be set in the file
> (and indeed, you can't set it there, if I understand
> GUC_DISALLOW_IN_FILE). It's used only as a connection parameter, and I
> use its presence / absence for the client and server to negotiate GSSAPI
> encryption support.

If that's what it is, it seems fairly broken to have it connected up to a
GUC variable. Especially one that's USERSET; some people will wonder why
frobbing it with SET does nothing, and others will bitch that they think
it should be superuser-only or some such. I'd keep it localized to the
connection logic, myself. There's already logic in ProcessStartupPacket
for connection options that aren't GUC variables, so I'd suggest adding
another case there instead of pretending this is a settable GUC variable.

regards, tom lane


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v9] GSSAPI encryption support
Date: 2016-03-31 23:19:06
Message-ID: CAB7nPqQvb-c9AS4z7p8QqGgeBpvX+g=zWGFLtPBvxj=x=EAwyQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 1, 2016 at 6:10 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> If that's what it is, it seems fairly broken to have it connected up to a
> GUC variable. Especially one that's USERSET; some people will wonder why
> frobbing it with SET does nothing, and others will bitch that they think
> it should be superuser-only or some such. I'd keep it localized to the
> connection logic, myself. There's already logic in ProcessStartupPacket
> for connection options that aren't GUC variables, so I'd suggest adding
> another case there instead of pretending this is a settable GUC variable.

Argh, yes right. That's what we should look for.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v10] GSSAPI encryption support
Date: 2016-04-01 03:31:33
Message-ID: jlgpoua3syy.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

Here is another version of GSSAPI encryption support, both on this email
and on my github:
https://github.com/frozencemetery/postgres/tree/feature/gssencrypt10

This version is intended to address Michael's review:

- Fixed Windows build. Thanks to Michael for patches.

- Fixed buffering of large replies on the serverside. This should fix
the traceback that was being seen. The issue had to do with the
difference between the server and client calling conventions for the
_read and _write functions.

- gss_enc_require renamed to gss_require_encrypt. Slightly longer, but
half the stomach churn.

- Move gss_encrypt out of the GUCs and into connection-specific logic.
Thanks to Tom Lane for pointing me in the right direction here.

- Replace writev() with two calls to _raw_write(). I'm not attached to
this design; if someone has a preference for allocating a buffer and
making a single write from that, I could be persuaded. I don't know
what the performance tradeoffs are.

- Typo fixes. I need to figure out spellchecking in my editor.

- More use of <acronym>.

- Change _should_crypto() functions to return bool. Also rename them to
be the _should_encrypt functions.

- Error message cleanup.

Thanks!

Attachment Content-Type Size
v10-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 15.1 KB
v10-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 42.5 KB
v10-0003-GSSAPI-authentication-cleanup.patch text/x-diff 6.7 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v10] GSSAPI encryption support
Date: 2016-04-01 05:38:52
Message-ID: CAB7nPqTtJrFYy6Z5fyRiKg8DNdQ5bpCH_Qmbarhx0rSoK2RvQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 1, 2016 at 12:31 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> - Fixed Windows build. Thanks to Michael for patches.

This looks fine. I am not seeing build failures now.

> - Fixed buffering of large replies on the serverside. This should fix
> the traceback that was being seen. The issue had to do with the
> difference between the server and client calling conventions for the
> _read and _write functions.

This does not fix the issue. I am still able to crash the server with
the same trace.

> - Move gss_encrypt out of the GUCs and into connection-specific logic.
> Thanks to Tom Lane for pointing me in the right direction here.

+ /* delay processing until after AUTH_REQ_OK has been sent */
+ if (port->gss->gss_encrypt != NULL)
+ port->gss->encrypt = !strcmp(port->gss->gss_encrypt, "on");
You should use parse_bool here, because contrary to libpq, clients
should be able to use other values like "1", "0", "off", 'N', 'Y',
etc.

> - Replace writev() with two calls to _raw_write(). I'm not attached to
> this design; if someone has a preference for allocating a buffer and
> making a single write from that, I could be persuaded. I don't know
> what the performance tradeoffs are.

Relying on pqsecure_raw_write and pqsecure_raw_read is a better bet
IMO, there is already some low-level error handling.

static ConfigVariable *ProcessConfigFileInternal(GucContext context,
bool applySettings, int elevel);

-
/*
Spurious noise.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v10] GSSAPI encryption support
Date: 2016-04-01 19:00:07
Message-ID: jlgmvpd40js.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Fri, Apr 1, 2016 at 12:31 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>
>> - Fixed buffering of large replies on the serverside. This should fix
>> the traceback that was being seen. The issue had to do with the
>> difference between the server and client calling conventions for the
>> _read and _write functions.
>
> This does not fix the issue. I am still able to crash the server with
> the same trace.

Interesting. I guess I'll keep trying to reproduce this.

>> - Move gss_encrypt out of the GUCs and into connection-specific logic.
>> Thanks to Tom Lane for pointing me in the right direction here.
>
> + /* delay processing until after AUTH_REQ_OK has been sent */
> + if (port->gss->gss_encrypt != NULL)
> + port->gss->encrypt = !strcmp(port->gss->gss_encrypt, "on");
>
> You should use parse_bool here, because contrary to libpq, clients
> should be able to use other values like "1", "0", "off", 'N', 'Y',
> etc.

Missed that function somehow. Will fix.

>> - Replace writev() with two calls to _raw_write(). I'm not attached to
>> this design; if someone has a preference for allocating a buffer and
>> making a single write from that, I could be persuaded. I don't know
>> what the performance tradeoffs are.
>
> Relying on pqsecure_raw_write and pqsecure_raw_read is a better bet
> IMO, there is already some low-level error handling.

Indeed, it looks like it should especially lead to better behavior on
Windows.

> static ConfigVariable *ProcessConfigFileInternal(GucContext context,
> bool applySettings, int elevel);
>
> -
> /*
>
> Spurious noise.

Indeed, will fix.


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v11] GSSAPI encryption support
Date: 2016-04-01 22:34:56
Message-ID: jlgh9fl3qlr.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

Song and dance, here's v11 both here and on my github:
https://github.com/frozencemetery/postgres/tree/feature/gssencrypt11

Changes from v10:

- Attempt to address a crash Michael is observing by switching to using
the StringInfo/pqExpBuffer management functions over my own code as
much as possible. Michael, if this doesn't fix it, I'm out of ideas.
Since I still can't reproduce this locally (left a client machine and
a process on the same machine retrying for over an hour on your test
case and didn't see it), could you provide me with some more
information on why repalloc is complaining? Is this a low memory
situation where alloc might have failed? What's your setup look like?
That pointer looks like it's on the heap, is that correct? I really
don't have a handle on what's gone wrong here.

- Switch to using parse_bool for handling gss_encrypt.

- Remove accidental whitespace change.

Thanks!

Attachment Content-Type Size
v11-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 15.1 KB
v11-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 41.8 KB
v11-0003-GSSAPI-authentication-cleanup.patch text/x-diff 6.7 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v11] GSSAPI encryption support
Date: 2016-04-02 13:02:46
Message-ID: CAB7nPqSwnVLci7mZ89K+oNig7QHTi9MLxYnefOmgM=Vpro96ag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Apr 2, 2016 at 7:34 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> - Attempt to address a crash Michael is observing by switching to using
> the StringInfo/pqExpBuffer management functions over my own code as
> much as possible. Michael, if this doesn't fix it, I'm out of ideas.

Nope, it doesn't.

> Since I still can't reproduce this locally (left a client machine and
> a process on the same machine retrying for over an hour on your test
> case and didn't see it), could you provide me with some more
> information on why repalloc is complaining?
> Is this a low memory situation where alloc might have failed?

No, this is an assertion failure, and it seems that you are compiling
this code without --enable-cassert, without the switch the code
actually works.

> What's your setup look like?

Just a simple Linux VM running krb5kdc with 386MB of memory, with
Postgres running locally as well.

> That pointer looks like it's on the heap, is that correct?

appendBinaryStringInfo depends on palloc calls that allocate memory
depending on the memory context used. It looks that what's just
missing in your logic is a private memory context that be_gssapi_write
and be_gssapi_read can use to handle the allocation of the
communication buffers.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v11] GSSAPI encryption support
Date: 2016-04-04 20:15:19
Message-ID: jlgh9fht9k8.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Sat, Apr 2, 2016 at 7:34 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>
>> Since I still can't reproduce this locally (left a client machine and
>> a process on the same machine retrying for over an hour on your test
>> case and didn't see it), could you provide me with some more
>> information on why repalloc is complaining?
>> Is this a low memory situation where alloc might have failed?
>
> No, this is an assertion failure, and it seems that you are compiling
> this code without --enable-cassert, without the switch the code
> actually works.

You are right. I now see the assertion failure.

>> That pointer looks like it's on the heap, is that correct?
>
> appendBinaryStringInfo depends on palloc calls that allocate memory
> depending on the memory context used. It looks that what's just
> missing in your logic is a private memory context that be_gssapi_write
> and be_gssapi_read can use to handle the allocation of the
> communication buffers.

Thank you very much for the pointer! I will work in memory context
management for the next version.


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 00:06:06
Message-ID: jlgy48ssyvl.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

Here's v12, both here and on my github:
https://github.com/frozencemetery/postgres/tree/feature/gssencrypt12

What changed:

- The code is aware of memory contexts now. I actually really like the
memory context stuff; just didn't see any indication of its existence
in the code I had read. Anyway, we allocate server buffers in the
connection-lifetime context. The other alternative that we discussed
on IRC a bit was to avoid palloc()/pfree() entirely in favor of raw
calloc()/free(), but I think if possible I prefer this approach since
I find the StringInfo handy to work with. This eliminates the
traceback for me with --enable-cassert.

- Error cleanup. I've been looking very hard at this code in order to
try to fix the assert, and I've fixed up a couple error paths that
hadn't been taken. This involves replacing the double-send with a
buffer-and-then-send, which turns out to be not only shorter but
easier for me to reason about.

Thanks!

Attachment Content-Type Size
v12-0001-Move-common-GSSAPI-code-into-its-own-files.patch text/x-diff 15.1 KB
v12-0002-Connection-encryption-support-for-GSSAPI.patch text/x-diff 46.3 KB
v12-0003-GSSAPI-authentication-cleanup.patch text/x-diff 6.7 KB

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 05:25:36
Message-ID: CAB7nPqRum7n9W-FXM0JDq-SjsveJt9opM36s6OAKhrM4T1WfKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Apr 5, 2016 at 9:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Here's v12, both here and on my github:
> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt12
>
> What changed:
>
> - The code is aware of memory contexts now. I actually really like the
> memory context stuff; just didn't see any indication of its existence
> in the code I had read. Anyway, we allocate server buffers in the
> connection-lifetime context. The other alternative that we discussed
> on IRC a bit was to avoid palloc()/pfree() entirely in favor of raw
> calloc()/free(), but I think if possible I prefer this approach since
> I find the StringInfo handy to work with. This eliminates the
> traceback for me with --enable-cassert.

Affirnative, I am not seeing the failure anymore.

+#ifdef ENABLE_GSS
+ {
+ MemoryContext save = CurrentMemoryContext;
+ CurrentMemoryContext = TopMemoryContext;
+
+ initStringInfo(&port->gss->buf);
+ initStringInfo(&port->gss->writebuf);
+
+ CurrentMemoryContext = save;
+ }
+#endif
So you are saving everything in the top memory context. I am fine to
give the last word to a committer here but I would just go with
calloc/free to simplify those hunks.

+#ifdef ENABLE_GSS
+ if (conn->gss->buf.data)
+ pfree(conn->gss->buf.data);
+ if (conn->gss->writebuf.data)
+ pfree(conn->gss->writebuf.data);
+#endif
This should happen in its own memory context, no

> - Error cleanup. I've been looking very hard at this code in order to
> try to fix the assert, and I've fixed up a couple error paths that
> hadn't been taken. This involves replacing the double-send with a
> buffer-and-then-send, which turns out to be not only shorter but
> easier for me to reason about.

@@ -775,6 +775,7 @@ infodir
docdir
oldincludedir
includedir
+runstatedir
localstatedir
sharedstatedir
sysconfdir
@@ -896,6 +897,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
What's that? I would recommend re-running autoconf to remove this
portion (committers do it at the end btw, so that's actually no bug
deal).

-#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
-/*
- * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
- * that contain the OIDs required. Redefine here, values copied
- * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
- */
-static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
-{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
-static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
-#endif
Regarding patch 0003 it may be fine to remove that... Robbie, do you
know how long ago this has been fixed upstream? I'd rather not have
this bit removed if this could impact some users.

On 0003, +1 for reading the whole stack of messages. That's definitely
worth a separate patch.

Btw, those seem like small things to me, and my comments have been
addressed, so I have switched the patch as ready for committer. I
guess that Stephen would be the one to look at it.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Magnus Hagander <magnus(at)hagander(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 17:58:52
Message-ID: jlgmvp8rl7n.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Tue, Apr 5, 2016 at 9:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Here's v12, both here and on my github:
>> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt12
>>
> +#ifdef ENABLE_GSS
> + {
> + MemoryContext save = CurrentMemoryContext;
> + CurrentMemoryContext = TopMemoryContext;
> +
> + initStringInfo(&port->gss->buf);
> + initStringInfo(&port->gss->writebuf);
> +
> + CurrentMemoryContext = save;
> + }
> +#endif
>
> So you are saving everything in the top memory context. I am fine to
> give the last word to a committer here but I would just go with
> calloc/free to simplify those hunks.

Yeah, it's definitely worth thinking/talking about; this came up in IRC
discussion as well.

If we go the memory context route, it has to be TopMemoryContext since
nothing else lives long enough (i.e., entire connection).

On the other hand, if we go with calloc/free here, I can't use
StringInfo for these buffers because StringInfo uses palloc. Using
StringInfo is really handy; if I don't use StringInfo, I'd need to
reimplement enlargeStringInfo() for the ad-hoc buffer structure. What
I'm trying to articulate is that it'd simplify the initialization code
since it removes MemoryContext management, but it makes everything else
more complicated.

I prefer the StringInfo approach since I think the abstraction is a good
one, but if you've got a case for explicit calloc()/free() in light of
that, I'd be interested to hear it.

> +#ifdef ENABLE_GSS
> + if (conn->gss->buf.data)
> + pfree(conn->gss->buf.data);
> + if (conn->gss->writebuf.data)
> + pfree(conn->gss->writebuf.data);
> +#endif
>
> This should happen in its own memory context, no

It turns out that's not actually required, but could easily be made
explicit here. According to the README for the memory context system,
pfree() and repalloc() do not require setting CurrentMemoryContext
(since 7.1).

I'm not opposed to making this one explicit if you think it adds
clarity. I would not want to make all the calls to StringInfo functions
explicit just because they can call repalloc, though.

> @@ -775,6 +775,7 @@ infodir
> docdir
> oldincludedir
> includedir
> +runstatedir
> localstatedir
> sharedstatedir
> sysconfdir
> @@ -896,6 +897,7 @@ datadir='${datarootdir}'
> sysconfdir='${prefix}/etc'
> sharedstatedir='${prefix}/com'
> localstatedir='${prefix}/var'
> +runstatedir='${localstatedir}/run'
> What's that? I would recommend re-running autoconf to remove this
> portion (committers do it at the end btw, so that's actually no bug
> deal).

Well, I guess /that/ mistake finally happened. This is what happens
when I run autoreconf on my VMs. Because configure is checked in to
version control, I accidentally committed the whole thing instead of
just the GSSAPI changes. I can back that out.

Side note: it's really irritating to work with having this file under
version control because of how different it ends up being when I
autoreconf (which I need to do because I'm changing the build system).
(I'm also idly curious what system/autotools version is generating this
file because it doesn't match any that I tried.)

> -#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
> -/*
> - * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
> - * that contain the OIDs required. Redefine here, values copied
> - * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
> - */
> -static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
> -{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
> -static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
> -#endif
> Regarding patch 0003 it may be fine to remove that... Robbie, do you
> know how long ago this has been fixed upstream? I'd rather not have
> this bit removed if this could impact some users.

I double-checked with MIT, and we think it was fixed in 2003 in commit
4ce1f7c3a46485e342d3a68b4c60b76c196d1851 which can be viewed at
https://github.com/krb5/krb5/commit/4ce1f7c3a46485e342d3a68b4c60b76c196d1851
and the corresponding bug on their bugtracker was
http://krbdev.mit.edu/rt/Ticket/Display.html?id=1666

In terms of release versions, this was first included in krb5-1.4. For
reference, the oldest Kerberos that MIT upstream supports is 1.12; the
oldest Kerberos that I (maintainer for Red Hat) support in production
(i.e., RHEL-5) is 1.6.1, and even that is slated to go away early 2017.
To my knowledge no one is supporting an older version than that.

In the interest of completion, MIT did express concern that this might
not have been a bug in MIT at all, but rather a toolchain issue. This
workaround has been present since the introduction of GSSAPI auth
support back in 2007. I pinged Magnus on IRC, but I think I missed the
awake window for Sweden, so he's on CC as well.

> On 0003, +1 for reading the whole stack of messages. That's definitely
> worth a separate patch.

Okay! It makes sense to me to move that over.

> Btw, those seem like small things to me, and my comments have been
> addressed, so I have switched the patch as ready for committer. I
> guess that Stephen would be the one to look at it.

Thanks for your comments! This patchset has definitely been much
improved by your input, and I really appreciate that.


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Magnus Hagander <magnus(at)hagander(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 18:43:46
Message-ID: 20160405184346.GA317471@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
> > On Tue, Apr 5, 2016 at 9:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> >> Here's v12, both here and on my github:
> >> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt12

> > So you are saving everything in the top memory context. I am fine to
> > give the last word to a committer here but I would just go with
> > calloc/free to simplify those hunks.
>
> Yeah, it's definitely worth thinking/talking about; this came up in IRC
> discussion as well.
>
> If we go the memory context route, it has to be TopMemoryContext since
> nothing else lives long enough (i.e., entire connection).
[...]
> It turns out that's not actually required, but could easily be made
> explicit here. According to the README for the memory context system,
> pfree() and repalloc() do not require setting CurrentMemoryContext
> (since 7.1).

It seems to me that the right solution for this is to create a new
memory context which is a direct child of TopMemoryContext, so that
palloc can be used, and so that it can be reset separately, and that it
doesn't suffer from resets of other contexts. (I think Michael's point
is that if those chunks were it a context of their own, you wouldn't
need the pfrees but a MemCxtReset would be enough.)

> Side note: it's really irritating to work with having this file under
> version control because of how different it ends up being when I
> autoreconf (which I need to do because I'm changing the build system).
> (I'm also idly curious what system/autotools version is generating this
> file because it doesn't match any that I tried.)

We use stock autoconf from the GNU package and it definitely produces
matching output for me. Maybe your Linux distro includes a patched
version? I know Debian does, but I suppose you're using some Redhat
thing, so no idea.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 20:12:51
Message-ID: jlgfuuzstks.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:

> Robbie Harwood wrote:
>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>
>> > On Tue, Apr 5, 2016 at 9:06 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> >> Here's v12, both here and on my github:
>> >> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt12
>
>> > So you are saving everything in the top memory context. I am fine to
>> > give the last word to a committer here but I would just go with
>> > calloc/free to simplify those hunks.
>>
>> Yeah, it's definitely worth thinking/talking about; this came up in IRC
>> discussion as well.
>>
>> If we go the memory context route, it has to be TopMemoryContext since
>> nothing else lives long enough (i.e., entire connection).
> [...]
>> It turns out that's not actually required, but could easily be made
>> explicit here. According to the README for the memory context system,
>> pfree() and repalloc() do not require setting CurrentMemoryContext
>> (since 7.1).
>
> It seems to me that the right solution for this is to create a new
> memory context which is a direct child of TopMemoryContext, so that
> palloc can be used, and so that it can be reset separately, and that it
> doesn't suffer from resets of other contexts. (I think Michael's point
> is that if those chunks were it a context of their own, you wouldn't
> need the pfrees but a MemCxtReset would be enough.)

Hmm, that's also an option. I read Michael's point as arguing for
calloc()/free() rather than a new context, but I could be wrong.

A question, though: it it valuable for the context to be reset()able
separately? If there were more than just these two buffers going into
it, I could see it being convenient - especially if it were for
different encryption types, for instance - but it seems like it would be
overkill?

This is all new to me so I may be entirely mistaken though.

>> Side note: it's really irritating to work with having this file under
>> version control because of how different it ends up being when I
>> autoreconf (which I need to do because I'm changing the build system).
>> (I'm also idly curious what system/autotools version is generating this
>> file because it doesn't match any that I tried.)
>
> We use stock autoconf from the GNU package and it definitely produces
> matching output for me. Maybe your Linux distro includes a patched
> version? I know Debian does, but I suppose you're using some Redhat
> thing, so no idea.

Hmm, that explains the Debian behavior I was seeing (it does the
above). The Fedora one adds a couple blank lines in places but it's
much less... gratuitous... in its changes.


From: David Steele <david(at)pgmasters(dot)net>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 20:39:48
Message-ID: 57042294.70308@pgmasters.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 4/5/16 1:25 AM, Michael Paquier wrote:

> Btw, those seem like small things to me, and my comments have been
> addressed, so I have switched the patch as ready for committer. I
> guess that Stephen would be the one to look at it.

I have also run this patch through my tests and didn't find any
problems. I agree that it is ready for committer.

I don't see a problem with using the top memory context but whoever
commits it may feel differently. I'm happy to leave that decision up to
them.

--
-David
david(at)pgmasters(dot)net


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 20:58:17
Message-ID: 20160405205817.GA366676@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood wrote:
> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:

> > It seems to me that the right solution for this is to create a new
> > memory context which is a direct child of TopMemoryContext, so that
> > palloc can be used, and so that it can be reset separately, and that it
> > doesn't suffer from resets of other contexts. (I think Michael's point
> > is that if those chunks were it a context of their own, you wouldn't
> > need the pfrees but a MemCxtReset would be enough.)
>
> Hmm, that's also an option. I read Michael's point as arguing for
> calloc()/free() rather than a new context, but I could be wrong.

Yeah, if you weren't using stringinfos that would be an option, but
since you are I think that's out of the question.

> A question, though: it it valuable for the context to be reset()able
> separately? If there were more than just these two buffers going into
> it, I could see it being convenient - especially if it were for
> different encryption types, for instance - but it seems like it would be
> overkill?

If two buffers is all, I think retail pfrees are fine. I haven't
actually read the patch.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 21:15:10
Message-ID: CABUevEwpMhJhaeexGbbauNcOztSgbfcAFY8zHEpDaKj4M3oM9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Apr 5, 2016 at 7:58 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:

> > -#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
> > -/*
> > - * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for MingW
> > - * that contain the OIDs required. Redefine here, values copied
> > - * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
> > - */
> > -static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
> > -{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
> > -static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = &GSS_C_NT_USER_NAME_desc;
> > -#endif
> > Regarding patch 0003 it may be fine to remove that... Robbie, do you
> > know how long ago this has been fixed upstream? I'd rather not have
> > this bit removed if this could impact some users.
>
> I double-checked with MIT, and we think it was fixed in 2003 in commit
> 4ce1f7c3a46485e342d3a68b4c60b76c196d1851 which can be viewed at
>
> https://github.com/krb5/krb5/commit/4ce1f7c3a46485e342d3a68b4c60b76c196d1851
> and the corresponding bug on their bugtracker was
> http://krbdev.mit.edu/rt/Ticket/Display.html?id=1666

That certainly looks like it fixes is. This was way too long ago for me to
remember which versions I was using at the time though.

It looks like it was already OK in the MSVC build back then, and only mingw
was broken. Which makes it even more reasonable that they might've fixed it
now - or a long time ago.

If it works on reasonably modern mingw, then I suggest pushing it to the
buildfarm and see what happens. But it definitely needs at least one round
of building on mingw..

--
Magnus Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 23:00:37
Message-ID: CAB7nPqSFwQxX02n2Xk7hKBYDFBkj=jWTYjTW4BRpTxdzAHNH8w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 6, 2016 at 6:15 AM, Magnus Hagander <magnus(at)hagander(dot)net> wrote:
> On Tue, Apr 5, 2016 at 7:58 PM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>
>> > -#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
>> > -/*
>> > - * MIT Kerberos GSSAPI DLL doesn't properly export the symbols for
>> > MingW
>> > - * that contain the OIDs required. Redefine here, values copied
>> > - * from src/athena/auth/krb5/src/lib/gssapi/generic/gssapi_generic.c
>> > - */
>> > -static const gss_OID_desc GSS_C_NT_USER_NAME_desc =
>> > -{10, (void *) "\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"};
>> > -static GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME =
>> > &GSS_C_NT_USER_NAME_desc;
>> > -#endif
>> > Regarding patch 0003 it may be fine to remove that... Robbie, do you
>> > know how long ago this has been fixed upstream? I'd rather not have
>> > this bit removed if this could impact some users.
>>
>> I double-checked with MIT, and we think it was fixed in 2003 in commit
>> 4ce1f7c3a46485e342d3a68b4c60b76c196d1851 which can be viewed at
>>
>> https://github.com/krb5/krb5/commit/4ce1f7c3a46485e342d3a68b4c60b76c196d1851
>> and the corresponding bug on their bugtracker was
>> http://krbdev.mit.edu/rt/Ticket/Display.html?id=1666

Thanks for the investigation! It would be interesting to see what at
least narwhal in the buildfarm thinks about that.

> That certainly looks like it fixes is. This was way too long ago for me to
> remember which versions I was using at the time though.

So, this is as well an indication that it would actually be fine :)

> It looks like it was already OK in the MSVC build back then, and only mingw
> was broken. Which makes it even more reasonable that they might've fixed it
> now - or a long time ago.
>
> If it works on reasonably modern mingw, then I suggest pushing it to the
> buildfarm and see what happens. But it definitely needs at least one round
> of building on mingw..

What about giving a spin first to patch 0003 as two different patches?
One to remove this check, and one to improve the error reporting
(which is an improvement in itself). Then we could rebase the rest on
top of it.
--
Michael


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-05 23:17:47
Message-ID: CAB7nPqTp+uW7sedffhHRO5+jQu1F_UQtYGsf4015gDwUzpORtA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 6, 2016 at 5:58 AM, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> wrote:
> Robbie Harwood wrote:
>> Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
>> > It seems to me that the right solution for this is to create a new
>> > memory context which is a direct child of TopMemoryContext, so that
>> > palloc can be used, and so that it can be reset separately, and that it
>> > doesn't suffer from resets of other contexts. (I think Michael's point
>> > is that if those chunks were it a context of their own, you wouldn't
>> > need the pfrees but a MemCxtReset would be enough.)
>>
>> Hmm, that's also an option. I read Michael's point as arguing for
>> calloc()/free() rather than a new context, but I could be wrong.
>
> Yeah, if you weren't using stringinfos that would be an option, but
> since you are I think that's out of the question.

To be honest, my first thought about that was to create a private
memory context only dedicated to those buffers, save it in pg_gssinfo
and remove those pfree calls as the memory context would clean up
itself with inheritance. Regarding the calloc/free stuff, should I be
a committer I would have given it a spin to see how the code gets
uglier or better and would have done a final decision depending on
that (you are true about the repalloc/pfree calls in memory contexts
btw, I forgot that).

>> A question, though: it it valuable for the context to be reset()able
>> separately? If there were more than just these two buffers going into
>> it, I could see it being convenient - especially if it were for
>> different encryption types, for instance - but it seems like it would be
>> overkill?
>
> If two buffers is all, I think retail pfrees are fine. I haven't
> actually read the patch.

Those are the only two buffers present per session.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-06 11:21:05
Message-ID: 20160406112105.GG10850@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie,

Just an initial pass over the patch.

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Here's v12, both here and on my github:
> https://github.com/frozencemetery/postgres/tree/feature/gssencrypt12

I've started taking a look at this as it's a capability I've wanted us
to support for a *long* time.

> Subject: [PATCH 1/3] Move common GSSAPI code into its own files

Didn't look too closely at this as it's mostly just moving stuff around.
I'll review it more closely once the other items are addressed though.

> Subject: [PATCH 2/3] Connection encryption support for GSSAPI

> diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
> index 73d493e..94d95bd 100644
> --- a/src/backend/libpq/auth.c
> +++ b/src/backend/libpq/auth.c
> @@ -596,10 +596,12 @@ sendAuthRequest(Port *port, AuthRequest areq)
> pq_endmessage(&buf);
>
> /*
> - * Flush message so client will see it, except for AUTH_REQ_OK, which need
> - * not be sent until we are ready for queries.
> + * In most cases, we do not need to send AUTH_REQ_OK until we are ready
> + * for queries. However, if we are doing GSSAPI encryption, that request
> + * must go out immediately to ensure that all messages which follow the
> + * AUTH_REQ_OK are not grouped with it and can therefore be encrypted.
> */
> - if (areq != AUTH_REQ_OK)
> + if (areq != AUTH_REQ_OK || port->gss != NULL)
> pq_flush();
>
> CHECK_FOR_INTERRUPTS();

Do we actually need to send pq_flush *whenever* port->gss is not null?
Shouldn't this actually be port->gss->encrypt?

> diff --git a/src/backend/libpq/be-secure-gssapi.c b/src/backend/libpq/be-secure-gssapi.c
[...]
> +/*
> + * Wrapper function indicating whether we are currently performing GSSAPI
> + * connection encryption.
> + *
> + * gss->encrypt is set when connection parameters are processed, which happens
> + * immediately after AUTH_REQ_OK is sent.
> + */
> +static bool
> +be_gssapi_should_encrypt(Port *port)
> +{
> + if (port->gss->ctx == GSS_C_NO_CONTEXT)
> + return false;
> + return port->gss->encrypt;
> +}

be_gssapi_should_encrypt returns bool, which seems entirely reasonable,
but...

> +be_gssapi_write(Port *port, void *ptr, size_t len)
> +{
> + OM_uint32 major, minor;
> + gss_buffer_desc input, output;
> + ssize_t ret;
> + int conf;
> + uint32 netlen;
> + char lenbuf[4];
> +
> + ret = be_gssapi_should_encrypt(port);

Why are we storing the result into an ssize_t?

> + if (ret == -1)
> + return -1;
> + else if (ret == 0)
> + return secure_raw_write(port, ptr, len);

And then testing the result against -1...? Or a bare 0 for that matter?

> + /* encrypt the message */
> + output.value = NULL;
> + output.length = 0;
> +
> + input.value = ptr;
> + input.length = len;
> +
> + conf = 0;
> + major = gss_wrap(&minor, port->gss->ctx, 1, GSS_C_QOP_DEFAULT,
> + &input, &conf, &output);
> + if (GSS_ERROR(major))
> + {
> + pg_GSS_error(ERROR,
> + gettext_noop("GSSAPI wrap error"),
> + major, minor);
> + ret = -1;
> + goto cleanup;
> + }
> + else if (conf == 0)
> + {
> + ereport(FATAL, (errmsg("GSSAPI did not provide confidentiality")));
> + ret = -1;
> + goto cleanup;
> + }
> +
> + /* format for on-wire: 4 network-order bytes of length, then payload */
> + netlen = htonl(output.length);
> + memcpy(lenbuf, &netlen, 4);
> +
> + appendBinaryStringInfo(&port->gss->writebuf, lenbuf, 4);
> + appendBinaryStringInfo(&port->gss->writebuf, output.value, output.length);

That strikes me as a bit of overkill, we tend to just cast the pointer
to a (char *) rather than memcpy'ing the data just to get a different
pointer out of it.

> + /* recur to send any buffered data */
> + gss_release_buffer(&minor, &output);
> + return be_gssapi_write(port, ptr, len);

This feels a bit odd to be doing, honestly. We try to take a lot of
care to consider low-memory situation and to be careufl when it comes to
potential for infinite recursion and there's already a way to ask for
this function to be called again, isn't there?

> + cleanup:
> + if (output.value != NULL)
> + gss_release_buffer(&minor, &output);
> +
> + return ret;
> +}

There's no need for any of this. This goto will never be reached as
either a pg_GSS_error(ERROR) or an ereport(FATAL) isn't going to return
control to this path. That's one of the reasons to be careful with
memory allocation and to use appropriate memory contexts, we're going to
longjmp out of this code path and clean up the memory allocations by
free'ing the contexts that we no longer need. That is, on an ERROR
level failure, on FATAL, we're just going to exit, so we don't have to
worry about memory cleanup in that case. Note that in some cases we'll
actually promote an ERROR to a FATAL; that's particularly relevant here
as we tend to do that when we're in backend startup.

> +ssize_t
> +be_gssapi_read(Port *port, void *ptr, size_t len)
> +{
> + OM_uint32 major, minor;
> + gss_buffer_desc input, output;
> + ssize_t ret;
> + int conf = 0;
> +
> + ret = be_gssapi_should_encrypt(port);
> +
> + if (ret == -1)
> + return -1;
> + else if (ret == 0)
> + return secure_raw_read(port, ptr, len);

This has the same issue as be_gssapi_write(), noted above.

> + /* ensure proper behavior under recursion */
> + if (len == 0)
> + return 0;
> +
> + /* report any buffered data, then recur */
> + if (port->gss->buf.cursor > 0)
> + {
> + ret = be_gssapi_read_from_buffer(port, ptr, len);
> + if (ret > 0)
> + {
> + ssize_t r_ret =
> + be_gssapi_read(port, (char *)ptr + ret, len - ret);
> + if (r_ret < 0 && errno != EWOULDBLOCK
> +#ifdef EAGAIN
> + && errno != EAGAIN
> +#endif
> + )
> + /* connection is dead in some way */
> + return r_ret;
> + else if (r_ret < 0)
> + /* no more data right now */
> + return ret;
> + return ret + r_ret;
> + }
> + }

I'm really not excited by all the recursion. Further, I'd segregate the
variable declaration from such a complicated recursive call and probably
throw in another comment or comment-paragraph in there about what's
going on.

> + /* our buffer is now empty */
> + if (port->gss->buf.len < 4)
> + {
> + enlargeStringInfo(&port->gss->buf, 4 - port->gss->buf.len);
> + ret = secure_raw_read(port, port->gss->buf.data + port->gss->buf.len,
> + 4 - port->gss->buf.len);
> + if (ret < 0)
> + return ret;
> +
> + /* write length to buffer */
> + port->gss->buf.len += ret;
> + port->gss->buf.data[port->gss->buf.len] = '\0';
> + if (port->gss->buf.len < 4)
> + {
> + errno = EWOULDBLOCK;
> + return -1;
> + }
> + }
> +
> + /* we know the length of the packet at this point */
> + memcpy((char *)&input.length, port->gss->buf.data, 4);
> + input.length = ntohl(input.length);
> + enlargeStringInfo(&port->gss->buf, input.length - port->gss->buf.len + 4);

I'm aware that enlargeStringInfo() does check and handle the case where
the length ends up >1G, but that feels a bit grotty to me- are you sure
you want the generic enlargeStringInfo() to handle that case?

> + ret = be_gssapi_read_from_buffer(port, ptr, len);
> + cleanup:
> + if (output.value != NULL)
> + gss_release_buffer(&minor, &output);
> +
> + return ret;

Again, probably not much use using the goto's.

Similar comments regarding the libpq side of things.

> Subject: [PATCH 3/3] GSSAPI authentication cleanup

Why wouldn't this be part of patch #2?

Otherwise it looked pretty reasonable.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-06 19:22:15
Message-ID: jlg1t6isftk.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> Just an initial pass over the patch.

Thanks! In the interest of brevity, if I haven't replied to something,
I plan to fix it.

>> /*
>> - * Flush message so client will see it, except for AUTH_REQ_OK, which need
>> - * not be sent until we are ready for queries.
>> + * In most cases, we do not need to send AUTH_REQ_OK until we are ready
>> + * for queries. However, if we are doing GSSAPI encryption, that request
>> + * must go out immediately to ensure that all messages which follow the
>> + * AUTH_REQ_OK are not grouped with it and can therefore be encrypted.
>> */
>> - if (areq != AUTH_REQ_OK)
>> + if (areq != AUTH_REQ_OK || port->gss != NULL)
>> pq_flush();
>>
>> CHECK_FOR_INTERRUPTS();
>
> Do we actually need to send pq_flush *whenever* port->gss is not null?
> Shouldn't this actually be port->gss->encrypt?

I need to flush this any time we might be doing encryption because it
needs to be in a separate request to _secure_write() from what follows
it. We don't know whether we should be doing encryption until
connection parameters are parsed; to put it another way,
port->gss->encrypt will never be true here because it hasn't been parsed
out of port->gss->gss_encrypt yet.

I could parse it earlier, but then I need another variable in the struct
(i.e., to hold whether AUTH_REQ_OK has been sent yet) to check as well.
Additionally, it seemed to me that there might be some value
security-wise in delaying parsing of connection parameters until after
auth is complete, though of course for just a bool this may not be as
important.

>> + /* recur to send any buffered data */
>> + gss_release_buffer(&minor, &output);
>> + return be_gssapi_write(port, ptr, len);
>
> This feels a bit odd to be doing, honestly. We try to take a lot of
> care to consider low-memory situation and to be careufl when it comes to
> potential for infinite recursion and there's already a way to ask for
> this function to be called again, isn't there?

This call should be okay because (1) it's a tail call and (2) we know
the buffer isn't empty.

That said, the other recursion is excessively complicated and I think
it's simpler to eliminate it entirely in favor of being called again.
I'll see what I can do.

>> + /* we know the length of the packet at this point */
>> + memcpy((char *)&input.length, port->gss->buf.data, 4);
>> + input.length = ntohl(input.length);
>> + enlargeStringInfo(&port->gss->buf, input.length - port->gss->buf.len + 4);
>
> I'm aware that enlargeStringInfo() does check and handle the case where
> the length ends up >1G, but that feels a bit grotty to me- are you sure
> you want the generic enlargeStringInfo() to handle that case?

This is a good point. We definitely have to draw the line somewhere; 1G
is a high upper bound. Digging around the server code I don't see a
precedent for what's a good size to stop at. There's
PG_MAX_AUTH_TOKEN_LENGTH, which is 65k, and the password length in
auth.c is 1k. Beyond that, SocketBackend() calls pq_getmessage() with
no maximum length, which causes the enlargeStringInfo() size
restrictions to be the only control (wrapped in a PG_TRY()).

I think what I'm trying to get at here is that I'm open to suggestion,
but don't see a clearly better way to do this. We could use the
PG_TRY() approach here to preserve sync, though I'm not sure it's worth
it considering PQ_RECV_BUFFER_SIZE and PQ_SEND_BUFFER_SIZE are both 8k.

>> Subject: [PATCH 3/3] GSSAPI authentication cleanup
>
> Why wouldn't this be part of patch #2?

It's a cleanup of existing code, not my new code, so I thought the
separation would make it easier to understand. I'm fine with it as part
of #2 so long as it happens, but the impression I had gotten from
earlier reviews was that it should have even more division (i.e., move
the gss_display_status() wrappers into their own patch), not less.

Thanks,
--Robbie


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-06 21:10:31
Message-ID: 1530.1459977031@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:
> I need to flush this any time we might be doing encryption because it
> needs to be in a separate request to _secure_write() from what follows
> it. We don't know whether we should be doing encryption until
> connection parameters are parsed; to put it another way,
> port->gss->encrypt will never be true here because it hasn't been parsed
> out of port->gss->gss_encrypt yet.

Wait a second. So the initial connection-request packet is necessarily
unencrypted under this scheme? That seems like a pretty substantial
step backwards from what happens with SSL. Even granting that stuff
like passwords won't be sent till later, the combination of user name
and database name might already be useful info to an eavesdropper.

I would think a design similar to the SSL one (special protocol version
to cause encryption negotiation before the actual connection request
is sent) would be better.

(If I'm totally misunderstanding the context here, my apologies. I've
not been following this thread.)

>> I'm aware that enlargeStringInfo() does check and handle the case where
>> the length ends up >1G, but that feels a bit grotty to me- are you sure
>> you want the generic enlargeStringInfo() to handle that case?

> This is a good point. We definitely have to draw the line somewhere; 1G
> is a high upper bound. Digging around the server code I don't see a
> precedent for what's a good size to stop at. There's
> PG_MAX_AUTH_TOKEN_LENGTH, which is 65k, and the password length in
> auth.c is 1k. Beyond that, SocketBackend() calls pq_getmessage() with
> no maximum length, which causes the enlargeStringInfo() size
> restrictions to be the only control (wrapped in a PG_TRY()).

Note that SocketBackend() only runs *after* we've accepted the user as
authorized. We should be a lot charier of what we're willing to accept
before authorization, IMO. Note MAX_STARTUP_PACKET_LENGTH, which is
only 10K.

regards, tom lane


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-06 22:15:37
Message-ID: jlgy48qqt86.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>> I need to flush this any time we might be doing encryption because it
>> needs to be in a separate request to _secure_write() from what follows
>> it. We don't know whether we should be doing encryption until
>> connection parameters are parsed; to put it another way,
>> port->gss->encrypt will never be true here because it hasn't been parsed
>> out of port->gss->gss_encrypt yet.
>
> Wait a second. So the initial connection-request packet is necessarily
> unencrypted under this scheme? That seems like a pretty substantial
> step backwards from what happens with SSL. Even granting that stuff
> like passwords won't be sent till later, the combination of user name
> and database name might already be useful info to an eavesdropper.
>
> I would think a design similar to the SSL one (special protocol version
> to cause encryption negotiation before the actual connection request
> is sent) would be better.

(Apologies for the wall of text that follows. My GSSAPI encryption
support has gone through three major redesigns, so I've got a fair bit
to say about it at this point, and it's probably better that I say too
much than too little. The short version is that GSSAPI works
differently than SSL and username is sent in the clear no matter what,
but this isn't a problem.)

Yes, by necessity. The username must be sent in the clear, even if only
as part of the GSSAPI handshake (i.e., the GSSAPI username will appear
in plantext in the GSSAPI blobs which are otherwise encrypted). GSSAPI
performs authentication before it can start encryption.

In this design, the contents of the Startup Message are the only
non-authentication related information sent in the clear. This
contains: username (which we need anyway), database, application_name,
and I add gss_encrypt.

Why does it look this way? Fallback support. We already have GSSAPI
authentication code in the project, and unfortunately we can't fix the
multitude of older clients that won't have encryption support, whatever
form it takes.

What if we didn't need fallback support, though? Doing it with a
special protocol version, as in the SSL/TLS case, would cause a separate
path for authentication to occur, during which everything would look
pretty much the same, except we wouldn't send database. We would then
complete the auth handshake, and in a separate exchange, pass in the
database information. Only then could we perform authorization
checking. Authorization checking is currently coupled with the
authentication as well; we would need a way to bypass the normal auth
sequence and enter encryption.

Bottom line is that designing similarly to SSL/TLS doesn't really make
sense because the two schemes work differently. Typically, usernames
are not considered sensitive information unless one is worried about the
security of the authentication information that goes with them. For
instance, MIT Kerberos will reveal the difference between "username not
found" and the equivalent of "bad password". I don't know how much
admins care about the database names being in the clear; I suspect it
doesn't matter much because just knowing their names isn't enough to
connect. Even if it's something people care about, this is still far
better than no encryption at all (which is the current GSSAPI behavior),
and would be better addressed by supporting connecting without
specifying a database immediately anyway.

>>> I'm aware that enlargeStringInfo() does check and handle the case where
>>> the length ends up >1G, but that feels a bit grotty to me- are you sure
>>> you want the generic enlargeStringInfo() to handle that case?
>
>> This is a good point. We definitely have to draw the line somewhere; 1G
>> is a high upper bound. Digging around the server code I don't see a
>> precedent for what's a good size to stop at. There's
>> PG_MAX_AUTH_TOKEN_LENGTH, which is 65k, and the password length in
>> auth.c is 1k. Beyond that, SocketBackend() calls pq_getmessage() with
>> no maximum length, which causes the enlargeStringInfo() size
>> restrictions to be the only control (wrapped in a PG_TRY()).
>
> Note that SocketBackend() only runs *after* we've accepted the user as
> authorized. We should be a lot charier of what we're willing to accept
> before authorization, IMO. Note MAX_STARTUP_PACKET_LENGTH, which is
> only 10K.

Correct, we're only talking about packets that are sent after
authentication+authorization are complete. Before authentication is
complete, the GSSAPI encryption codepaths are not taken.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-06 23:20:57
Message-ID: 5486.1459984857@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>> Wait a second. So the initial connection-request packet is necessarily
>> unencrypted under this scheme?

> Yes, by necessity. The username must be sent in the clear, even if only
> as part of the GSSAPI handshake (i.e., the GSSAPI username will appear
> in plantext in the GSSAPI blobs which are otherwise encrypted). GSSAPI
> performs authentication before it can start encryption.

Ugh. I had thought we were putting work into this because it represented
something we could recommend as best practice, but now you're telling me
that it's always going to be inferior to what we have already.

> In this design, the contents of the Startup Message are the only
> non-authentication related information sent in the clear. This
> contains: username (which we need anyway), database, application_name,
> and I add gss_encrypt.

And any other GUC value that the user has decided to send via PGOPTIONS.
Whatever the merits of assuming that the username is okay to expose to
eavesdroppers, I dislike having to assume that there are not and never
will be any GUCs whose settings are potentially security-sensitive.

I really think you need to fix this so that the true startup packet
is not sent until the connection has been encrypted. People are used
to assuming that's true with SSL encryption, and if GSSAPI is less
secure that's likely to lead to unexpected security weaknesses somewhere
down the line.

regards, tom lane


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-08 02:17:09
Message-ID: CAB7nPqRPK1f4oAStwsy_Ty_Cjjo8U50HF0bRZi86my7va4nVdg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Apr 7, 2016 at 8:20 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>>> Wait a second. So the initial connection-request packet is necessarily
>>> unencrypted under this scheme?
>
>> Yes, by necessity. The username must be sent in the clear, even if only
>> as part of the GSSAPI handshake (i.e., the GSSAPI username will appear
>> in plantext in the GSSAPI blobs which are otherwise encrypted). GSSAPI
>> performs authentication before it can start encryption.
>
> Ugh. I had thought we were putting work into this because it represented
> something we could recommend as best practice, but now you're telling me
> that it's always going to be inferior to what we have already.

It does not seem necessary to have an equivalent of
pqsecure_open_client, just some extra handling in fe-connect.c to set
up the initial context with a proper message handling... Not that
direct anyway. So should the patch be marked as returned with feedback
at this stage?
--
Michael


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robbie Harwood <rharwood(at)redhat(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-08 18:24:22
Message-ID: CA+TgmoZF2J5C=BghUcpzFGWLSDpRb8eWc2RhiyEze4vj0zbhaQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Apr 7, 2016 at 10:17 PM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
> On Thu, Apr 7, 2016 at 8:20 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>>>> Wait a second. So the initial connection-request packet is necessarily
>>>> unencrypted under this scheme?
>>
>>> Yes, by necessity. The username must be sent in the clear, even if only
>>> as part of the GSSAPI handshake (i.e., the GSSAPI username will appear
>>> in plantext in the GSSAPI blobs which are otherwise encrypted). GSSAPI
>>> performs authentication before it can start encryption.
>>
>> Ugh. I had thought we were putting work into this because it represented
>> something we could recommend as best practice, but now you're telling me
>> that it's always going to be inferior to what we have already.
>
> It does not seem necessary to have an equivalent of
> pqsecure_open_client, just some extra handling in fe-connect.c to set
> up the initial context with a proper message handling... Not that
> direct anyway. So should the patch be marked as returned with feedback
> at this stage?

Yeah, I think so. It doesn't seem we have consensus on this, and it's
too late to be trying to build one now.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-08 18:36:38
Message-ID: 20160408183638.GN10850@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

* Robert Haas (robertmhaas(at)gmail(dot)com) wrote:
> On Thu, Apr 7, 2016 at 10:17 PM, Michael Paquier
> <michael(dot)paquier(at)gmail(dot)com> wrote:
> > On Thu, Apr 7, 2016 at 8:20 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
> >>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> >>>> Wait a second. So the initial connection-request packet is necessarily
> >>>> unencrypted under this scheme?
> >>
> >>> Yes, by necessity. The username must be sent in the clear, even if only
> >>> as part of the GSSAPI handshake (i.e., the GSSAPI username will appear
> >>> in plantext in the GSSAPI blobs which are otherwise encrypted). GSSAPI
> >>> performs authentication before it can start encryption.
> >>
> >> Ugh. I had thought we were putting work into this because it represented
> >> something we could recommend as best practice, but now you're telling me
> >> that it's always going to be inferior to what we have already.
> >
> > It does not seem necessary to have an equivalent of
> > pqsecure_open_client, just some extra handling in fe-connect.c to set
> > up the initial context with a proper message handling... Not that
> > direct anyway. So should the patch be marked as returned with feedback
> > at this stage?
>
> Yeah, I think so. It doesn't seem we have consensus on this, and it's
> too late to be trying to build one now.

Actually, I chatted with Robbie quite a bit over IRC and he's agreed on
reworking this to use the same approach that we use for SSL, but that's
expected to take the better part of a week to do.

While it seems like this particular patch (with myself as committer)
would meet the requirements stated by the RMT for an extension, having
considered it over the past day or so, I don't think we should make it a
policy to allow an extension when it involves a significant rework of
the patch, as is the case here.

Robbie, please be sure to add this to the next commitfest and please
hound me to review it, you know where to find me. :)

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-04-08 18:39:57
Message-ID: CA+Tgmoacxa9iL3jhWBv7JnDUXZNi5DtD8mgavV_LGqQEbPFGBg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 8, 2016 at 2:36 PM, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> While it seems like this particular patch (with myself as committer)
> would meet the requirements stated by the RMT for an extension, having
> considered it over the past day or so, I don't think we should make it a
> policy to allow an extension when it involves a significant rework of
> the patch, as is the case here.

I agree. To be clear, those were intended as necessary but not
necessarily sufficient reasons for extension. I agree that patches
needing significant reworking are not good candidates for extensions.
(But that is my feeling as an RMT member, not an RMT official policy
upon which we have voted.)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-06-15 23:16:56
Message-ID: jlgk2hq3uvr.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Thu, Apr 7, 2016 at 8:20 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>>>
>>>> Wait a second. So the initial connection-request packet is
>>>> necessarily unencrypted under this scheme?
>>
>>> Yes, by necessity. The username must be sent in the clear, even if
>>> only as part of the GSSAPI handshake (i.e., the GSSAPI username will
>>> appear in plantext in the GSSAPI blobs which are otherwise
>>> encrypted). GSSAPI performs authentication before it can start
>>> encryption.
>>
>> Ugh. I had thought we were putting work into this because it
>> represented something we could recommend as best practice, but now
>> you're telling me that it's always going to be inferior to what we
>> have already.
>
> It does not seem necessary to have an equivalent of
> pqsecure_open_client, just some extra handling in fe-connect.c to set
> up the initial context with a proper message handling... Not that
> direct anyway. So should the patch be marked as returned with feedback
> at this stage?

I think in order to satisfy Tom's (valid) concern, there does need to be
a separate handshake - i.e., GSSAPI support in pqsecure_open_client().

If I were to continue as I have been - using the plaintext connection
and auth negotiation path - then at the time of startup the client has
no way of knowing whether to send connection parameters or not.
Personally, I would be in favor of not frontloading these connection
parameters over insecure connections, but it is my impression that the
project does not want to go this way (which is fine).

The way I'm seeing this, when a connection comes in, we take the 'G'
character for GSSAPI much as for SSL. At that time, we need to perform
an *authentication* handshake (because GSSAPI will not do encryption
before authenticating). I expect to use a consistent format for all
GSSAPI packets - four bytes for length, and a payload. (I would prefer
tagging them, but previously preference for not doing this has been
expressed.)

Once GSSAPI authentication is complete, the normal handshake process can
be tunneled through a GSSAPI encryption layer, as is done with TLS. The
server will need to retain some of the earlier authentication data
(e.g., to check that the presented user-name matches GSSAPI
credentials), but there will be no authentication packets exchanged
(more specifically, it will resemble the anonymous case). Authorization
will be checked as normal, and we then proceed in the usual fashion, all
over the GSSAPI tunnel.

On the server, I'll need to implement `hostgss` (by analogy to
`hostssl`), and we'll want to lock authentication on those connections
to GSSAPI-only. Clients will explicitly probe for GSSAPI support as
they do for TLS support (I look forward to the bikeshed on the order of
these) and should have a parameter to require said support. One thing
I'm not clear on is what our behavior should be when the user doesn't
explicitly request GSSAPI and doesn't have a ccache - do we prompt?
Skip probing? I'm not sure what the best option there is.

Before I implement this design, does anyone have any additional concerns
or feedback on it?

Thanks,
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-25 20:58:47
Message-ID: jlg7fc91lko.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:

> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
>> On Thu, Apr 7, 2016 at 8:20 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>>>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>>>>
>>>>> Wait a second. So the initial connection-request packet is
>>>>> necessarily unencrypted under this scheme?
>>>
>>>> Yes, by necessity. The username must be sent in the clear, even if
>>>> only as part of the GSSAPI handshake (i.e., the GSSAPI username will
>>>> appear in plantext in the GSSAPI blobs which are otherwise
>>>> encrypted). GSSAPI performs authentication before it can start
>>>> encryption.
>>>
>>> Ugh. I had thought we were putting work into this because it
>>> represented something we could recommend as best practice, but now
>>> you're telling me that it's always going to be inferior to what we
>>> have already.
>>
>> It does not seem necessary to have an equivalent of
>> pqsecure_open_client, just some extra handling in fe-connect.c to set
>> up the initial context with a proper message handling... Not that
>> direct anyway. So should the patch be marked as returned with feedback
>> at this stage?
>
> I think in order to satisfy Tom's (valid) concern, there does need to be
> a separate handshake - i.e., GSSAPI support in pqsecure_open_client().
>
> If I were to continue as I have been - using the plaintext connection
> and auth negotiation path - then at the time of startup the client has
> no way of knowing whether to send connection parameters or not.
> Personally, I would be in favor of not frontloading these connection
> parameters over insecure connections, but it is my impression that the
> project does not want to go this way (which is fine).
>
> The way I'm seeing this, when a connection comes in, we take the 'G'
> character for GSSAPI much as for SSL. At that time, we need to perform
> an *authentication* handshake (because GSSAPI will not do encryption
> before authenticating). I expect to use a consistent format for all
> GSSAPI packets - four bytes for length, and a payload. (I would prefer
> tagging them, but previously preference for not doing this has been
> expressed.)
>
> Once GSSAPI authentication is complete, the normal handshake process can
> be tunneled through a GSSAPI encryption layer, as is done with TLS. The
> server will need to retain some of the earlier authentication data
> (e.g., to check that the presented user-name matches GSSAPI
> credentials), but there will be no authentication packets exchanged
> (more specifically, it will resemble the anonymous case). Authorization
> will be checked as normal, and we then proceed in the usual fashion, all
> over the GSSAPI tunnel.
>
> On the server, I'll need to implement `hostgss` (by analogy to
> `hostssl`), and we'll want to lock authentication on those connections
> to GSSAPI-only. Clients will explicitly probe for GSSAPI support as
> they do for TLS support (I look forward to the bikeshed on the order of
> these) and should have a parameter to require said support. One thing
> I'm not clear on is what our behavior should be when the user doesn't
> explicitly request GSSAPI and doesn't have a ccache - do we prompt?
> Skip probing? I'm not sure what the best option there is.
>
> Before I implement this design, does anyone have any additional concerns
> or feedback on it?

Does this look reasonable to folks?


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-26 01:48:52
Message-ID: CAB7nPqSmq1tuVGoVQXVb86y9SoaM-wcMDxHD1of9dGc54QYNSQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jul 26, 2016 at 5:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Robbie Harwood <rharwood(at)redhat(dot)com> writes:

Sorry for my late reply.

>> I think in order to satisfy Tom's (valid) concern, there does need to be
>> a separate handshake - i.e., GSSAPI support in pqsecure_open_client().

Having the communication layer in fe-secure.c definitely makes sense.
The startup process though should not use CONNECTION_SSL_STARTUP.

>> If I were to continue as I have been - using the plaintext connection
>> and auth negotiation path - then at the time of startup the client has
>> no way of knowing whether to send connection parameters or not.
>> Personally, I would be in favor of not frontloading these connection
>> parameters over insecure connections, but it is my impression that the
>> project does not want to go this way (which is fine).

Per the discussion upthread I got the opposite impression, the startup
packet should be sent after the connection has been established. SSL
does so: the SSL negotiation goes first, and then the startup packet
is sent. That's the flow with the status changing from
CONNECTION_SSL_START -> CONNECTION_MADE.

>> The way I'm seeing this, when a connection comes in, we take the 'G'
>> character for GSSAPI much as for SSL. At that time, we need to perform
>> an *authentication* handshake (because GSSAPI will not do encryption
>> before authenticating). I expect to use a consistent format for all
>> GSSAPI packets - four bytes for length, and a payload. (I would prefer
>> tagging them, but previously preference for not doing this has been
>> expressed.)

OK.

>> Once GSSAPI authentication is complete, the normal handshake process can
>> be tunneled through a GSSAPI encryption layer, as is done with TLS. The
>> server will need to retain some of the earlier authentication data
>> (e.g., to check that the presented user-name matches GSSAPI
>> credentials), but there will be no authentication packets exchanged
>> (more specifically, it will resemble the anonymous case). Authorization
>> will be checked as normal, and we then proceed in the usual fashion, all
>> over the GSSAPI tunnel.

OK, that sounds good.

>> On the server, I'll need to implement `hostgss` (by analogy to
>> `hostssl`), and we'll want to lock authentication on those connections
>> to GSSAPI-only.

As well as hostnogss, but I guess that's part of the plan.

>> Clients will explicitly probe for GSSAPI support as
>> they do for TLS support (I look forward to the bikeshed on the order of
>> these) and should have a parameter to require said support. One thing
>> I'm not clear on is what our behavior should be when the user doesn't
>> explicitly request GSSAPI and doesn't have a ccache - do we prompt?
>> Skip probing? I'm not sure what the best option there is.

I am not sure I get what you mean here.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-26 15:22:24
Message-ID: jlg7fc8fmq7.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Tue, Jul 26, 2016 at 5:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>
> Sorry for my late reply.

Thanks for the feedback!

>>> If I were to continue as I have been - using the plaintext connection
>>> and auth negotiation path - then at the time of startup the client has
>>> no way of knowing whether to send connection parameters or not.
>>> Personally, I would be in favor of not frontloading these connection
>>> parameters over insecure connections, but it is my impression that the
>>> project does not want to go this way (which is fine).
>
> Per the discussion upthread I got the opposite impression, the startup
> packet should be sent after the connection has been established. SSL
> does so: the SSL negotiation goes first, and then the startup packet
> is sent. That's the flow with the status changing from
> CONNECTION_SSL_START -> CONNECTION_MADE.

We are in agreement, I think. I have structured the referenced
paragraph badly: for this design, I'm suggesting separate GSS startup
path (like SSL) and once a tunnel is established we send the startup
packet. I probably should have just left this paragraph out.

>>> On the server, I'll need to implement `hostgss` (by analogy to
>>> `hostssl`), and we'll want to lock authentication on those connections
>>> to GSSAPI-only.
>
> As well as hostnogss, but I guess that's part of the plan.

Sure, `hostnogss` should be fine. This isn't quadratic, right? We don't
need hostnogssnossl (or thereabouts)?

>>> Clients will explicitly probe for GSSAPI support as they do for TLS
>>> support (I look forward to the bikeshed on the order of these) and
>>> should have a parameter to require said support. One thing I'm not
>>> clear on is what our behavior should be when the user doesn't
>>> explicitly request GSSAPI and doesn't have a ccache - do we prompt?
>>> Skip probing? I'm not sure what the best option there is.
>
> I am not sure I get what you mean here.

Okay. Let me try again:

So there's a connection setting `sslmode` that we'll want something
similar to here (`gssapimode` or so). `sslmode` has six settings, but I
think we only need three for GSSAPI: "disable", "allow", and "prefer"
(which presumably would be the default).

Lets suppose we're working with "prefer". GSSAPI will itself check two
places for credentials: client keytab and ccache. But if we don't find
credentials there, we as the client have two options on how to proceed.

- First, we could prompt for a password (and then call
gss_acquire_cred_with_password() to get credentials), presumably with
an empty password meaning to skip GSSAPI. My memory is that the
current behavior for GSSAPI auth-only is to prompt for password if we
don't find credentials (and if it isn't, there's no reason not to
unless we're opposed to handling the password).

- Second, we could skip GSSAPI and proceed with the next connection
method. This might be confusing if the user is then prompted for a
password and expects it to be for GSSAPI, but we could probably make
it sensible. I think I prefer the first option.

Thanks,
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-26 15:28:11
Message-ID: jlg4m7cfmgk.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:

> So there's a connection setting `sslmode` that we'll want something
> similar to here (`gssapimode` or so). `sslmode` has six settings, but I
> think we only need three for GSSAPI: "disable", "allow", and "prefer"
> (which presumably would be the default).

Apologies, this should say four; I neglected "require".


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-26 15:29:08
Message-ID: 18337.1469546948@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:
> So there's a connection setting `sslmode` that we'll want something
> similar to here (`gssapimode` or so). `sslmode` has six settings, but I
> think we only need three for GSSAPI: "disable", "allow", and "prefer"
> (which presumably would be the default).

FWIW, there is quite a bit of unhappiness around sslmode=prefer, see
for example this thread:
https://www.postgresql.org/message-id/flat/2A5EFBDC-41C6-42A8-8B6D-E69DA60E9962%40eggerapps.at

I do not know if we can come up with a better answer, but I'd caution
you against thinking that that's a problem-free model to emulate.

regards, tom lane


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-26 16:24:39
Message-ID: jlgy44oe5a0.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>> So there's a connection setting `sslmode` that we'll want something
>> similar to here (`gssapimode` or so). `sslmode` has six settings, but I
>> think we only need three for GSSAPI: "disable", "allow", and "prefer"
>> (which presumably would be the default).
>
> FWIW, there is quite a bit of unhappiness around sslmode=prefer, see
> for example this thread:
> https://www.postgresql.org/message-id/flat/2A5EFBDC-41C6-42A8-8B6D-E69DA60E9962%40eggerapps.at
>
> I do not know if we can come up with a better answer, but I'd caution
> you against thinking that that's a problem-free model to emulate.

Understood. We have the slight simplification for GSSAPI of having
mutual authentication always (i.e., no need to worry about
unauthenticated-but-encrypted connections).

My personal view is that we want to try for as much security as we can
without breaking anything [0]. If a user knows that they want a specific
security, they can set "require"; if they don't want it, they can set
"disable". Setting "require" as the default breaks one class of users;
setting "disable" another. And I don't think we can punt the problem to
the user and make it a mandatory parameter, either.

I'm absolutely open to suggestions for how we could do better here,
especially since we're adding support for something new, but having read
the thread you mention I don't immediately see a superior design.

0: For what it's worth, I also don't agree with the assertion that
having the ability to fallback to plaintext from tampering makes the
attempt at encryption useless; rather, it still foils a passive
adversary, even if it doesn't do anything against an active one.


From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-27 02:14:54
Message-ID: CAB7nPqQpNXMVLDX4XGjcoQPzRFF-Hj5MDse=ac9jZP91X0cYcw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Jul 27, 2016 at 12:22 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
>> On Tue, Jul 26, 2016 at 5:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>> Robbie Harwood <rharwood(at)redhat(dot)com> writes:
>>
>> Sorry for my late reply.
>
> Thanks for the feedback!
>
>>>> If I were to continue as I have been - using the plaintext connection
>>>> and auth negotiation path - then at the time of startup the client has
>>>> no way of knowing whether to send connection parameters or not.
>>>> Personally, I would be in favor of not frontloading these connection
>>>> parameters over insecure connections, but it is my impression that the
>>>> project does not want to go this way (which is fine).
>>
>> Per the discussion upthread I got the opposite impression, the startup
>> packet should be sent after the connection has been established. SSL
>> does so: the SSL negotiation goes first, and then the startup packet
>> is sent. That's the flow with the status changing from
>> CONNECTION_SSL_START -> CONNECTION_MADE.
>
> We are in agreement, I think. I have structured the referenced
> paragraph badly: for this design, I'm suggesting separate GSS startup
> path (like SSL) and once a tunnel is established we send the startup
> packet. I probably should have just left this paragraph out.

OK we're good then.

>>>> On the server, I'll need to implement `hostgss` (by analogy to
>>>> `hostssl`), and we'll want to lock authentication on those connections
>>>> to GSSAPI-only.
>>
>> As well as hostnogss, but I guess that's part of the plan.
>
> Sure, `hostnogss` should be fine. This isn't quadratic, right? We don't
> need hostnogssnossl (or thereabouts)?

We don't need to do that far, users could still do the same with two
different lines in pg_hba.conf.

> So there's a connection setting `sslmode` that we'll want something
> similar to here (`gssapimode` or so). `sslmode` has six settings, but I
> think we only need three for GSSAPI: "disable", "allow", and "prefer"
> (which presumably would be the default).

Seeing the debate regarding sslmode these days, I would not say that
"prefer" would be the default, but that's an implementation detail.

> Lets suppose we're working with "prefer". GSSAPI will itself check two
> places for credentials: client keytab and ccache. But if we don't find
> credentials there, we as the client have two options on how to proceed.
>
> - First, we could prompt for a password (and then call
> gss_acquire_cred_with_password() to get credentials), presumably with
> an empty password meaning to skip GSSAPI. My memory is that the
> current behavior for GSSAPI auth-only is to prompt for password if we
> don't find credentials (and if it isn't, there's no reason not to
> unless we're opposed to handling the password).
>
> - Second, we could skip GSSAPI and proceed with the next connection
> method. This might be confusing if the user is then prompted for a
> password and expects it to be for GSSAPI, but we could probably make
> it sensible. I think I prefer the first option.

Ah, right. I completely forgot that GSSAPI had its own handling of
passwords for users registered to it...

Isn't this distinction a good point for not implementing "prefer",
"allow" or any equivalents? By that I mean that we should not have any
GSS connection mode that fallbacks to something else if the first one
fails. So we would live with the two following modes:
- "disable", to only try a non-GSS connection
- "enable", or "require", to only try a GSS connection.
That seems quite acceptable to me as a first implementation to just have that.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-07-27 17:12:27
Message-ID: jlgpopzhuo4.fsf@thriss.redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:

> On Wed, Jul 27, 2016 at 12:22 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>>
>> So there's a connection setting `sslmode` that we'll want something
>> similar to here (`gssapimode` or so). `sslmode` has six settings, but I
>> think we only need three for GSSAPI: "disable", "allow", and "prefer"
>> (which presumably would be the default).
>
> Seeing the debate regarding sslmode these days, I would not say that
> "prefer" would be the default, but that's an implementation detail.
>
>> Lets suppose we're working with "prefer". GSSAPI will itself check two
>> places for credentials: client keytab and ccache. But if we don't find
>> credentials there, we as the client have two options on how to proceed.
>>
>> - First, we could prompt for a password (and then call
>> gss_acquire_cred_with_password() to get credentials), presumably with
>> an empty password meaning to skip GSSAPI. My memory is that the
>> current behavior for GSSAPI auth-only is to prompt for password if we
>> don't find credentials (and if it isn't, there's no reason not to
>> unless we're opposed to handling the password).
>>
>> - Second, we could skip GSSAPI and proceed with the next connection
>> method. This might be confusing if the user is then prompted for a
>> password and expects it to be for GSSAPI, but we could probably make
>> it sensible. I think I prefer the first option.
>
> Ah, right. I completely forgot that GSSAPI had its own handling of
> passwords for users registered to it...
>
> Isn't this distinction a good point for not implementing "prefer",
> "allow" or any equivalents? By that I mean that we should not have any
> GSS connection mode that fallbacks to something else if the first one
> fails. So we would live with the two following modes:
> - "disable", to only try a non-GSS connection
> - "enable", or "require", to only try a GSS connection.
> That seems quite acceptable to me as a first implementation to just
> have that.

If it is the password management that is scary here, we could have a
prefer-type mode which does not prompt, but only uses existing
credentials. Or we could opt to never prompt, which is totally valid.


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [PATCH v12] GSSAPI encryption support
Date: 2016-08-01 15:03:07
Message-ID: 20160801150307.GP4028@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie, all,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
> > On Wed, Jul 27, 2016 at 12:22 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> >> Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
> >>
> >> So there's a connection setting `sslmode` that we'll want something
> >> similar to here (`gssapimode` or so). `sslmode` has six settings, but I
> >> think we only need three for GSSAPI: "disable", "allow", and "prefer"
> >> (which presumably would be the default).
> >
> > Seeing the debate regarding sslmode these days, I would not say that
> > "prefer" would be the default, but that's an implementation detail.
> >
> >> Lets suppose we're working with "prefer". GSSAPI will itself check two
> >> places for credentials: client keytab and ccache. But if we don't find
> >> credentials there, we as the client have two options on how to proceed.
> >>
> >> - First, we could prompt for a password (and then call
> >> gss_acquire_cred_with_password() to get credentials), presumably with
> >> an empty password meaning to skip GSSAPI. My memory is that the
> >> current behavior for GSSAPI auth-only is to prompt for password if we
> >> don't find credentials (and if it isn't, there's no reason not to
> >> unless we're opposed to handling the password).
> >>
> >> - Second, we could skip GSSAPI and proceed with the next connection
> >> method. This might be confusing if the user is then prompted for a
> >> password and expects it to be for GSSAPI, but we could probably make
> >> it sensible. I think I prefer the first option.
> >
> > Ah, right. I completely forgot that GSSAPI had its own handling of
> > passwords for users registered to it...
> >
> > Isn't this distinction a good point for not implementing "prefer",
> > "allow" or any equivalents? By that I mean that we should not have any
> > GSS connection mode that fallbacks to something else if the first one
> > fails. So we would live with the two following modes:
> > - "disable", to only try a non-GSS connection
> > - "enable", or "require", to only try a GSS connection.
> > That seems quite acceptable to me as a first implementation to just
> > have that.
>
> If it is the password management that is scary here, we could have a
> prefer-type mode which does not prompt, but only uses existing
> credentials. Or we could opt to never prompt, which is totally valid.

For my 2c, at least, I'd like the "prefer" option when it comes to
encryption where we try to use encryption if we're doing GSSAPI
authentication. I'm not a big fan of having the GSSAPI layer doing
password prompts, but as long as the *only* thing that does is go
through the Kerberos library to acquire the tickets and still completely
talks GSSAPI with the server, it seems reasonable.

If we end up having to fall back to a non-encrypted GSSAPI
authenticated session then we should make noise about that. If the
authentication is handled through GSSAPI but the connection is not
encrypted, but the user is told that immediately (eg: in the psql
startup), it seems like there's relativly little sensitive information
which has been exposed at that point and the user could destroy the
session then, if they're concerned about it.

Of course, that only works for user sessions, such as with psql, and
doesn't help with application connections, but hopefully application
authors who are using GSSAPI will read the docs sufficiently to know
that they should require an encrypted connection, if their environment
demands it.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v14] GSSAPI encryption support
Date: 2018-05-23 20:00:16
Message-ID: jlg1se287n3.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello -hackers,

Zombie patch is back from the dead. It's been a bit more than two years
since v12 (the last major revision) and almost three since it was
originally submitted. (I do have enough pride to point out that it did
not actually /take/ anywhere close to two years to update it.)

CC'd are reviewers from before; I appreciate their input from before,
but there is of course no obligation for them to page all this back in,
especially if they don't want to. A large chunk of this code is
unchanged from previous iterations of the patch, but this is a major
re-architect. Various things have also been previously fixed as part of
the GSSAPI testing efforts, for which I am grateful.

So: this is GSSAPI encryption support for libpq. Based on feedback on
previous versions, GSSAPI encryption has a separate negotiation step -
similar to SSL negotiation. I've tried to incorporate all other
feedback I've received thus far, but very likely missed things (and
introduced new problems).

To actually see encryption, you'll first need to configure the server as
for GSSAPI authentication. You'll also need to ensure the HBA
configuration has a rule that will permit it. However, there should
hopefully be enough information to set this up in the corresponding docs
changes (and if there isn't, I should fix it). The Kerberos/GSSAPI
implementation shouldn't matter, but I am testing using MIT krb5
(through freeIPA); I wrote a post a while back for my setup here:
https://mivehind.net/2015/06/11/kerberized-postgresql/

Finally, I've submitted this as a single patch because it was requested
previously. I'm happy to break it apart into many commits instead, if
that's helpful.

Thanks,
--Robbie

Attachment Content-Type Size
v14-libpq-GSSAPI-encryption-support.patch text/x-diff 74.5 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v14] GSSAPI encryption support
Date: 2018-05-23 20:03:12
Message-ID: 20180523200311.GN27724@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings Robbie!

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Zombie patch is back from the dead. It's been a bit more than two years
> since v12 (the last major revision) and almost three since it was
> originally submitted. (I do have enough pride to point out that it did
> not actually /take/ anywhere close to two years to update it.)

Neat!

[...]

> Finally, I've submitted this as a single patch because it was requested
> previously. I'm happy to break it apart into many commits instead, if
> that's helpful.

Please be sure to register this on the commitfest app. I'm definitely
interested and likely will have some time to take a look at this before
then, but we should get it registered there in any case.

Thanks!

Stephen


From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v14] GSSAPI encryption support
Date: 2018-05-23 23:39:15
Message-ID: CAEepm=2NkNjV97hThgHOQjk9j719wjFxVozs9LVn3YqW9egFgw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, May 24, 2018 at 8:00 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Zombie patch is back from the dead.

Hi Robbie,

Robots[1] vs zombies:

+ $postgres->RemoveFile('src/backennd/libpq/be-gssapi-common.c');

Typo, breaks on Windows.

runtime.sgml:2032: parser error : Opening and ending tag mismatch:
para line 2026 and sect1
</sect1>
^

Docs malformed.

[1] http://cfbot.cputube.org/robbie-harwood.html

--
Thomas Munro
http://www.enterprisedb.com


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: [PATCH v14] GSSAPI encryption support
Date: 2018-05-23 23:42:51
Message-ID: 20180523234251.GA15445@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, May 23, 2018 at 04:03:12PM -0400, Stephen Frost wrote:
>> Finally, I've submitted this as a single patch because it was requested
>> previously. I'm happy to break it apart into many commits instead, if
>> that's helpful.
>
> Please be sure to register this on the commitfest app. I'm definitely
> interested and likely will have some time to take a look at this before
> then, but we should get it registered there in any case.

This patch got a mention in one of my slides for next week actually,
glad to see this come back. You will need to wait a it for reviews
though, as the actual focus is to stabilize v11.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v15] GSSAPI encryption support
Date: 2018-05-24 20:10:52
Message-ID: jlg603c6chf.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:

> On Thu, May 24, 2018 at 8:00 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>
>> Zombie patch is back from the dead.
>
> Hi Robbie,
>
> Robots[1] vs zombies:
>
> + $postgres->RemoveFile('src/backennd/libpq/be-gssapi-common.c');
>
> Typo, breaks on Windows.
>
> runtime.sgml:2032: parser error : Opening and ending tag mismatch:
> para line 2026 and sect1
> </sect1>
> ^
>
> Docs malformed.
>
> [1] http://cfbot.cputube.org/robbie-harwood.html

Hah, this is great! Looks like I failed to build the docs.

Here's an updated version that should fix those.

Thanks,
--Robbie

Attachment Content-Type Size
v15-libpq-GSSAPI-encryption-support.patch text/x-diff 74.3 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-05-25 18:58:10
Message-ID: jlgr2lz4l6l.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Robbie Harwood <rharwood(at)redhat(dot)com> writes:

> Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:
>
>> On Thu, May 24, 2018 at 8:00 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>>
>>> Zombie patch is back from the dead.
>>
>> Hi Robbie,
>>
>> Robots[1] vs zombies:
>>
>> + $postgres->RemoveFile('src/backennd/libpq/be-gssapi-common.c');
>>
>> Typo, breaks on Windows.
>>
>> runtime.sgml:2032: parser error : Opening and ending tag mismatch:
>> para line 2026 and sect1
>> </sect1>
>> ^
>>
>> Docs malformed.
>>
>> [1] http://cfbot.cputube.org/robbie-harwood.html
>
> Hah, this is great! Looks like I failed to build the docs.
>
> Here's an updated version that should fix those.

Me and the bot are having an argument. This should green Linux but I
dunno about Windows.

Thanks,
--Robbie

Attachment Content-Type Size
v16-libpq-GSSAPI-encryption-support.patch text/x-diff 74.6 KB

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-05 00:16:31
Message-ID: CAEepm=2+FbEJsVX5B6fYW7UBXpF6osaixSXn2A297WgP+rEhxA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, May 26, 2018 at 6:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> Me and the bot are having an argument. This should green Linux but I
> dunno about Windows.

BTW if you're looking for a way to try stuff out on Windows exactly
the way cfbot does it without posting a new patch to the mailing list,
I put some instructions here:

https://wiki.postgresql.org/wiki/Continuous_Integration

The .patch there could certainly be improved (ideally, I think, it'd
run the whole build farm animal script) but it's a start.

--
Thomas Munro
http://www.enterprisedb.com


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v17] GSSAPI encryption support
Date: 2018-06-05 18:20:18
Message-ID: jlg1sdlw0wt.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:

> On Sat, May 26, 2018 at 6:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> Me and the bot are having an argument. This should green Linux but I
>> dunno about Windows.
>
> BTW if you're looking for a way to try stuff out on Windows exactly
> the way cfbot does it without posting a new patch to the mailing list,
> I put some instructions here:
>
> https://wiki.postgresql.org/wiki/Continuous_Integration
>
> The .patch there could certainly be improved (ideally, I think, it'd
> run the whole build farm animal script) but it's a start.

Appreciated. I think I've got it now.

Thanks,
--Robbie

Attachment Content-Type Size
v17-libpq-GSSAPI-encryption-support.patch text/x-diff 74.5 KB

From: Nico Williams <nico(at)cryptonector(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-07 21:00:59
Message-ID: 20180607210058.GE24501@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 05, 2018 at 12:16:31PM +1200, Thomas Munro wrote:
> On Sat, May 26, 2018 at 6:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> > Me and the bot are having an argument. This should green Linux but I
> > dunno about Windows.
>
> BTW if you're looking for a way to try stuff out on Windows exactly
> the way cfbot does it without posting a new patch to the mailing list,
> I put some instructions here:
>
> https://wiki.postgresql.org/wiki/Continuous_Integration
>
> The .patch there could certainly be improved (ideally, I think, it'd
> run the whole build farm animal script) but it's a start.

Cool! Is there any reason that your patch for Travis and AppVeyor
integration is not just committed to master?

Is there a way to get my CF entry building in cfbot, or will it get
there when it gets there?

I know I can just apply your patch, push to my fork, and have Travis and
AppVeyor build it. And I just might, but cfbot is a neato service!

Nico
--


From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Nico Williams <nico(at)cryptonector(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-07 22:11:52
Message-ID: CAEepm=0E8ga2McBB8fuC92+R0Hj=4TxR3kWR2fpJkwGSbcZF4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jun 8, 2018 at 9:00 AM, Nico Williams <nico(at)cryptonector(dot)com> wrote:
> On Tue, Jun 05, 2018 at 12:16:31PM +1200, Thomas Munro wrote:
>> On Sat, May 26, 2018 at 6:58 AM, Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> > Me and the bot are having an argument. This should green Linux but I
>> > dunno about Windows.
>>
>> BTW if you're looking for a way to try stuff out on Windows exactly
>> the way cfbot does it without posting a new patch to the mailing list,
>> I put some instructions here:
>>
>> https://wiki.postgresql.org/wiki/Continuous_Integration
>>
>> The .patch there could certainly be improved (ideally, I think, it'd
>> run the whole build farm animal script) but it's a start.
>
> Cool! Is there any reason that your patch for Travis and AppVeyor
> integration is not just committed to master?

I think that's a good idea and I know that some others are in favour.
The AppVeyor one is not good enough to propose just yet: it's
cargo-culted and skips a test that doesn't pass and only runs the
basic check tests (not contribs, isolation, TAP etc). Fortunately
Andrew Dunstan has recently figured out how to run the official build
farm script inside AppVeyor[1], and it looks like we might be close to
figuring out that one test that doesn't work. That makes me wonder if
we should get the Travis version to use the build farm scripts too.
If we can get all of that sorted out, then yes, I would like to
propose that we stick the .XXX.yml files in the tree. Another thing
not yet explored is Travis's macOS build support.

Someone might argue that we shouldn't depend on particular external
services, or that there are other CI services out there and we should
use those too/instead for some reason, or that we don't want all that
junk at top level in the tree. But it seems to me that as long as
they're dot prefixed files, we could carry control files for any
number of CI services without upsetting anyone. Having them in the
tree would allow anyone who has a publicly accessible git repo
(bitbucket, GitHub, ...) to go to any CI service that interests them
and enable it with a couple of clicks.

Then cfbot would still need to create new branches automatically (that
is fundamentally what it does: converts patches on the mailing list
into branches on GitHub), but it wouldn't need to add those control
files anymore, just the submitted patches.

> Is there a way to get my CF entry building in cfbot, or will it get
> there when it gets there?

Urgh, due to a bug in my new rate limiting logic it stopped pushing
new branches for a day or two. Fixed, and I see it's just picked up
your submission #1319. Usually it picks things up within minutes (it
rescans threads whenever the 'last mail' date changes on the
Commitfest web page), and then also rechecks each submission every
couple of days.

In a nice demonstration of the complexity of these systems, I see that
the build for your submission on Travis failed because apt couldn't
update its package index because repo.mongodb.org's key has expired.
Other recent builds are OK so that seems to be a weird transient
failure; possibly out of data in some cache, or some fraction of their
repo server farm hasn't been updated yet or ... whatever. Bleugh.

> I know I can just apply your patch, push to my fork, and have Travis and
> AppVeyor build it. And I just might, but cfbot is a neato service!

Thanks. The next step is to show cfbot's results in the Commitfest
app, and Magnus and I have started working on that. I gave a talk
about all this at PGCon last week, and the slides are up[2] in case
anyone is interested:

[1] https://www.postgresql.org/message-id/flat/0f3d44a1-1ac5-599c-3e15-16d058d54e9a%402ndQuadrant.com
[2] https://www.pgcon.org/2018/schedule/events/1234.en.html

--
Thomas Munro
http://www.enterprisedb.com


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-07 23:04:21
Message-ID: 20180607230420.GF24501@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Jun 08, 2018 at 10:11:52AM +1200, Thomas Munro wrote:
> On Fri, Jun 8, 2018 at 9:00 AM, Nico Williams <nico(at)cryptonector(dot)com> wrote:
> > Cool! Is there any reason that your patch for Travis and AppVeyor
> > integration is not just committed to master?
>
> I think that's a good idea and I know that some others are in favour.
> The AppVeyor one is not good enough to propose just yet: it's
> cargo-culted and skips a test that doesn't pass and only runs the
> basic check tests (not contribs, isolation, TAP etc). Fortunately
> Andrew Dunstan has recently figured out how to run the official build
> farm script inside AppVeyor[1], and it looks like we might be close to
> figuring out that one test that doesn't work. That makes me wonder if
> we should get the Travis version to use the build farm scripts too.
> If we can get all of that sorted out, then yes, I would like to
> propose that we stick the .XXX.yml files in the tree. Another thing
> not yet explored is Travis's macOS build support.

I use AppVeyor for Heimdal and for jq... Maybe I can help out.

As for Travis' OS X support... the problem there is that their build
farm is very small, so using theirs means waiting and waiting.

> Someone might argue that we shouldn't depend on particular external
> services, or that there are other CI services out there and we should
> use those too/instead for some reason, or that we don't want all that
> junk at top level in the tree. But it seems to me that as long as
> they're dot prefixed files, we could carry control files for any
> number of CI services without upsetting anyone. Having them in the
> tree would allow anyone who has a publicly accessible git repo
> (bitbucket, GitHub, ...) to go to any CI service that interests them
> and enable it with a couple of clicks.

Carrying the .yml files causes no harm beyond dependence, but that's a
nice problem to have when the alternative is to not have a CI at all.

> Then cfbot would still need to create new branches automatically (that
> is fundamentally what it does: converts patches on the mailing list
> into branches on GitHub), but it wouldn't need to add those control
> files anymore, just the submitted patches.

You wouldn't need it to. Instead the CF page could let submitters link
their CI status pages/buttons...

> > Is there a way to get my CF entry building in cfbot, or will it get
> > there when it gets there?
>
> Urgh, due to a bug in my new rate limiting logic it stopped pushing
> new branches for a day or two. Fixed, and I see it's just picked up
> your submission #1319. Usually it picks things up within minutes (it
> rescans threads whenever the 'last mail' date changes on the
> Commitfest web page), and then also rechecks each submission every
> couple of days.

Thanks!

> In a nice demonstration of the complexity of these systems, I see that
> the build for your submission on Travis failed because apt couldn't
> update its package index because repo.mongodb.org's key has expired.
> Other recent builds are OK so that seems to be a weird transient
> failure; possibly out of data in some cache, or some fraction of their
> repo server farm hasn't been updated yet or ... whatever. Bleugh.

Oof.

> > I know I can just apply your patch, push to my fork, and have Travis and
> > AppVeyor build it. And I just might, but cfbot is a neato service!
>
> Thanks. The next step is to show cfbot's results in the Commitfest
> app, and Magnus and I have started working on that. I gave a talk
> about all this at PGCon last week, and the slides are up[2] in case
> anyone is interested:

OK. I think that will be a huge improvement. I find CF to be fantastic
as it is, but this will make it even better.

Thanks,

Nico
--


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-11 13:27:17
Message-ID: CA+TgmoYmPutv1kiU7cbNp7MGCW0ECofVXoGNi6yYPMHB_8z=Mw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Jun 7, 2018 at 6:11 PM, Thomas Munro
<thomas(dot)munro(at)enterprisedb(dot)com> wrote:
>> Cool! Is there any reason that your patch for Travis and AppVeyor
>> integration is not just committed to master?
>
> I think that's a good idea and I know that some others are in favour.

One problem is that was discussed at PGCon it commits us to one
particular build configuration i.e. one set of --with-whatever options
to configure. It's not bad to provide a reasonable set of defaults,
but it means that patches which are best tested with some other set of
values will have to modify the file (I guess?). Patches that need to
be tested with multiple sets of flags are ... maybe just out of luck?

I really don't understand the notion of putting the build script
inside the source tree. It's all fine if there's One Way To Do It but
often TMTOWTDII. If the build configurations are described outside
the source tree then you can have as many of them as you need.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-11 17:13:17
Message-ID: 20180611171315.GA23356@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 11, 2018 at 09:27:17AM -0400, Robert Haas wrote:
> On Thu, Jun 7, 2018 at 6:11 PM, Thomas Munro
> <thomas(dot)munro(at)enterprisedb(dot)com> wrote:
> >> Cool! Is there any reason that your patch for Travis and AppVeyor
> >> integration is not just committed to master?
> >
> > I think that's a good idea and I know that some others are in favour.
>
> One problem is that was discussed at PGCon it commits us to one
> particular build configuration i.e. one set of --with-whatever options
> to configure. It's not bad to provide a reasonable set of defaults,
> but it means that patches which are best tested with some other set of
> values will have to modify the file (I guess?). Patches that need to
> be tested with multiple sets of flags are ... maybe just out of luck?

Hmm, that's not really true. You can have a build and test matrix with
more than one row in it.

For example, look at: https://travis-ci.org/heimdal/heimdal

You'll see that Heimdal's Travis-CI integration has four builds:

- Linux w/ GCC
- Linux w/ Clang
- OS X w/ Clang
- Linux code coverage w/ GCC

We could easily add more options for Heimdal, if we felt we needed to
build and test more with Travis-CI.

Appveyor also has matrix support (though I'm not using it in Heimdal's
Appveyor-CI integration).

Now, of course if we had a very large set of configurations to test,
things might get slow, and the CIs might find it abusive. It would be
best to use a maximal build configuration and go from there. So, for
example, two configurations, one with and w/o JIT, but with all the
optional libraries (GSS, LDAP, ICU, Perl, Python, ...), and with two
different compilers (GCC and Clang, with Clang only for the JIT), plus
one OS X build (with JIT), and so on:

- Linux w/ GCC
- Linux w/ Clang ( JIT)
- Linux w/ Clang (no JIT)
- Linux code coverage
- OS X w/ Clang ( JIT)

and similarly for Windows on Appveyor.

> I really don't understand the notion of putting the build script
> inside the source tree. It's all fine if there's One Way To Do It but
> often TMTOWTDII. If the build configurations are described outside
> the source tree then you can have as many of them as you need.

Well, all the free CIs like Travis and Appveyor do it this way. You
don't have to *use* it just because the .yml files are in the source
tree. But you have to have the .yml files in the source tree in order
to use these CIs. It'd be nice to be able to point somewhere else for
them, but whatever, that's not something we get much choice in at this
time.

The .yml files are unobstrusive anyways, and it's handy to have them
in-tree anyways. It also makes it easier to do things like:

- get build passing/failing buttons on wiki / build status pages

- make sure that the .yml files stay up to date as the source tree gets
changed

It also makes it somewhat easier to get hooked on github and such, but
a bit of discipline will make that a non-issue.

Nico
--


From: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
To: Nico Williams <nico(at)cryptonector(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-11 17:31:12
Message-ID: 10fecbaa-24d0-cd86-952d-92827929a85c@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 06/11/2018 01:13 PM, Nico Williams wrote:
>
> Well, all the free CIs like Travis and Appveyor do it this way. You
> don't have to *use* it just because the .yml files are in the source
> tree. But you have to have the .yml files in the source tree in order
> to use these CIs. It'd be nice to be able to point somewhere else for
> them, but whatever, that's not something we get much choice in at this
> time.
>

That's not true, at least for Appveyor (can't speak about travis - I
have no first hand experience). For appveyor, you can supply a custom
appveyor.yml file, which can be a complete URL. In fact, if you use a
plain git source as opposed to one of the managed git services it
supports, you have to do it that way - it ignores an appveyor.yml in
your repo. I found this out the very hard way over the last few days,
and they very kindly don't warn you at all about this.

cheers

andrew

--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Cc: Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-06-11 20:11:10
Message-ID: jlg602phyn5.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

Nico was kind enough to provide me with some code review. This should
those concerns (clarify short-read behavior and fixing error checking on
GSS functions).

Thanks,
--Robbie

Attachment Content-Type Size
v18-libpq-GSSAPI-encryption-support.patch text/x-diff 74.7 KB

From: Nico Williams <nico(at)cryptonector(dot)com>
To: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v16] GSSAPI encryption support
Date: 2018-06-11 20:52:46
Message-ID: 20180611205245.GB23356@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 11, 2018 at 01:31:12PM -0400, Andrew Dunstan wrote:
> On 06/11/2018 01:13 PM, Nico Williams wrote:
> >Well, all the free CIs like Travis and Appveyor do it this way. You
> >don't have to *use* it just because the .yml files are in the source
> >tree. But you have to have the .yml files in the source tree in order
> >to use these CIs. It'd be nice to be able to point somewhere else for
> >them, but whatever, that's not something we get much choice in at this
> >time.
>
> That's not true, at least for Appveyor (can't speak about travis - I have no
> first hand experience). For appveyor, you can supply a custom appveyor.yml
> file, which can be a complete URL. In fact, if you use a plain git source as
> opposed to one of the managed git services it supports, you have to do it
> that way - it ignores an appveyor.yml in your repo. I found this out the
> very hard way over the last few days, and they very kindly don't warn you at
> all about this.

OK, that's.. nice, maybe, I guess, but I'd still want version control
for these yml files -- why not have them in-tree? I'd rather have them
in-tree unless there's a good reason not to have them there.

In other projects I definitely find it better to have these files
in-tree.

Nico
--


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-06-11 23:00:27
Message-ID: 20180611230026.GC23356@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Jun 11, 2018 at 04:11:10PM -0400, Robbie Harwood wrote:
> Nico was kind enough to provide me with some code review. This should
> those concerns (clarify short-read behavior and fixing error checking on
> GSS functions).

Besides the bug you fixed and which I told you about off-list (on IRC,
specifically), I only have some commentary that does not need any
action:

- support for non-Kerberos/default GSS mechanisms

This might require new values for gssmode: prefer-<mechanism-name>
and require-<mechanism-name>. One could always use SPNEGO if there
are multiple mechanisms to choose from. And indeed, you could just
use SPNEGO if the user has credentials for multiple mechanism.

(Because GSS has no standard mechanism _names_, this means making
some up. This is one obnoxious shortcoming of the GSS-API...)

- when the SCRAM channel binding work is done, it might be good to add
an option for TLS + GSS w/ channel binding to TLS and no gss wrap
tokens

Nico
--


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Nico Williams <nico(at)cryptonector(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-06-12 16:36:01
Message-ID: jlgr2lcgdxq.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Nico Williams <nico(at)cryptonector(dot)com> writes:

> On Mon, Jun 11, 2018 at 04:11:10PM -0400, Robbie Harwood wrote:
>> Nico was kind enough to provide me with some code review. This should
>> those concerns (clarify short-read behavior and fixing error checking on
>> GSS functions).
>
> Besides the bug you fixed and which I told you about off-list (on IRC,
> specifically), I only have some commentary that does not need any
> action:
>
> - support for non-Kerberos/default GSS mechanisms
>
> This might require new values for gssmode: prefer-<mechanism-name>
> and require-<mechanism-name>. One could always use SPNEGO if there
> are multiple mechanisms to choose from. And indeed, you could just
> use SPNEGO if the user has credentials for multiple mechanism.
>
> (Because GSS has no standard mechanism _names_, this means making
> some up. This is one obnoxious shortcoming of the GSS-API...)

As long as it's better than passing raw OIDs on the CLI...

> - when the SCRAM channel binding work is done, it might be good to add
> an option for TLS + GSS w/ channel binding to TLS and no gss wrap
> tokens

I think both of these are neat ideas if they'll be used. Getting GSSAPI
encryption in shouldn't preclude either in its present form (should make
it easier, I hope), but I'm glad to hear of possible future work as
well!

Thanks,
--Robbie


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-06-12 16:39:24
Message-ID: 20180612163923.GE23356@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Jun 12, 2018 at 12:36:01PM -0400, Robbie Harwood wrote:
> Nico Williams <nico(at)cryptonector(dot)com> writes:
> > On Mon, Jun 11, 2018 at 04:11:10PM -0400, Robbie Harwood wrote:
> >> Nico was kind enough to provide me with some code review. This should
> >> those concerns (clarify short-read behavior and fixing error checking on
> >> GSS functions).
> >
> > Besides the bug you fixed and which I told you about off-list (on IRC,
> > specifically), I only have some commentary that does not need any
> > action:
> >
> > - support for non-Kerberos/default GSS mechanisms
> >
> > This might require new values for gssmode: prefer-<mechanism-name>
> > and require-<mechanism-name>. One could always use SPNEGO if there
> > are multiple mechanisms to choose from. And indeed, you could just
> > use SPNEGO if the user has credentials for multiple mechanism.
> >
> > (Because GSS has no standard mechanism _names_, this means making
> > some up. This is one obnoxious shortcoming of the GSS-API...)
>
> As long as it's better than passing raw OIDs on the CLI...

Rite?

I think this can be a follow-on patch, though trying SPNEGO if the user
has credentials for multiple mechanisms (and SPNEGO is indicated) seems
simple enough to do now (no interface changes).

> > - when the SCRAM channel binding work is done, it might be good to add
> > an option for TLS + GSS w/ channel binding to TLS and no gss wrap
> > tokens
>
> I think both of these are neat ideas if they'll be used. Getting GSSAPI
> encryption in shouldn't preclude either in its present form (should make
> it easier, I hope), but I'm glad to hear of possible future work as
> well!

This one can (must) wait. It has some security benefits. You get to
use GSS/Kerberos for authentication, but you get an forward security
you'd get from TLS (if the GSS mechanism doesn't provide it, which
Kerberos today does not).

Nico
--


From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Cc: Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-08-05 13:19:07
Message-ID: 82e75cb9-9676-6852-74de-1454a5cc97d7@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Sorry if this sounds facetious, but:

What is the point of this patch? What's the advantage of GSSAPI
encryption over SSL? I was hoping to find the answer by reading the
documentation changes, but all I can see is "how" to set it up, and
nothing about "why".

- Heikki


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-08-06 14:36:34
Message-ID: 20180806143633.GJ27724@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Heikki,

* Heikki Linnakangas (hlinnaka(at)iki(dot)fi) wrote:
> Sorry if this sounds facetious, but:
>
> What is the point of this patch? What's the advantage of GSSAPI encryption
> over SSL? I was hoping to find the answer by reading the documentation
> changes, but all I can see is "how" to set it up, and nothing about "why".

If you've already got an existing Kerberos environment, then it's a lot
nicer to leverage that rather than having to also implement a full PKI
to support and use SSL-based encryption.

There's also something to be said for having alternatives to OpenSSL.

Thanks!

Stephen


From: Nico Williams <nico(at)cryptonector(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-08-06 18:26:55
Message-ID: 20180806182654.GU5695@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Aug 06, 2018 at 10:36:34AM -0400, Stephen Frost wrote:
> * Heikki Linnakangas (hlinnaka(at)iki(dot)fi) wrote:
> > Sorry if this sounds facetious, but:
> >
> > What is the point of this patch? What's the advantage of GSSAPI encryption
> > over SSL? I was hoping to find the answer by reading the documentation
> > changes, but all I can see is "how" to set it up, and nothing about "why".
>
> If you've already got an existing Kerberos environment, then it's a lot
> nicer to leverage that rather than having to also implement a full PKI
> to support and use SSL-based encryption.
>
> There's also something to be said for having alternatives to OpenSSL.

Those two reasons would be my motivation if I were implementing this,
and they are some of the reasons I did a code review.

Nico
--


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-08-06 21:23:28
Message-ID: jlgd0uvyysv.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Heikki Linnakangas (hlinnaka(at)iki(dot)fi) wrote:
>
>> What is the point of this patch? What's the advantage of GSSAPI
>> encryption over SSL? I was hoping to find the answer by reading the
>> documentation changes, but all I can see is "how" to set it up, and
>> nothing about "why".
>
> If you've already got an existing Kerberos environment, then it's a
> lot nicer to leverage that rather than having to also implement a full
> PKI to support and use SSL-based encryption.
>
> There's also something to be said for having alternatives to OpenSSL.

This exactly.

If you're in a position where you're using Kerberos (or most other
things from the GSSAPI) for authentication, the encryption comes at
little to no additional setup cost. And then you get all the security
benefits outlined in the docs changes.

Thanks,
--Robbie


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v18] GSSAPI encryption support
Date: 2018-10-02 01:32:58
Message-ID: 20181002013258.GY11712@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Aug 06, 2018 at 05:23:28PM -0400, Robbie Harwood wrote:
> If you're in a position where you're using Kerberos (or most other
> things from the GSSAPI) for authentication, the encryption comes at
> little to no additional setup cost. And then you get all the security
> benefits outlined in the docs changes.

Please note that the last patch set does not apply anymore, so I have
moved it to CF 2018-11 and marked it as waiting on author.
--
Michael


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v19] GSSAPI encryption support
Date: 2018-10-02 21:11:44
Message-ID: jlgk1n0dpf3.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Michael Paquier <michael(at)paquier(dot)xyz> writes:

> On Mon, Aug 06, 2018 at 05:23:28PM -0400, Robbie Harwood wrote:
>> If you're in a position where you're using Kerberos (or most other
>> things from the GSSAPI) for authentication, the encryption comes at
>> little to no additional setup cost. And then you get all the security
>> benefits outlined in the docs changes.
>
> Please note that the last patch set does not apply anymore, so I have
> moved it to CF 2018-11 and marked it as waiting on author.

Indeed. Please find v19 attached. It's just a rebase; no architecture
changes.

I'll set commitfest status back to "Needs Review" once I've sent this
mail.

Thanks,
--Robbie

Attachment Content-Type Size
v19-libpq-GSSAPI-encryption-support.patch text/x-diff 73.8 KB

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: rharwood(at)redhat(dot)com
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Stephen Frost <sfrost(at)snowman(dot)net>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, nico(at)cryptonector(dot)com
Subject: Re: [PATCH v19] GSSAPI encryption support
Date: 2018-11-29 18:14:54
Message-ID: CA+q6zcXE6QuP2u=LW0MUG5fOsE7=kQva4kuNcm37hJ=yEzo+tg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> On Tue, Oct 2, 2018 at 11:12 PM Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>
> Michael Paquier <michael(at)paquier(dot)xyz> writes:
>
> > On Mon, Aug 06, 2018 at 05:23:28PM -0400, Robbie Harwood wrote:
> >> If you're in a position where you're using Kerberos (or most other
> >> things from the GSSAPI) for authentication, the encryption comes at
> >> little to no additional setup cost. And then you get all the security
> >> benefits outlined in the docs changes.
> >
> > Please note that the last patch set does not apply anymore, so I have
> > moved it to CF 2018-11 and marked it as waiting on author.
>
> Indeed. Please find v19 attached. It's just a rebase; no architecture
> changes.

Unfortunately, patch needs another rebase, could you do this? In the meantime
I'll move it to the next CF.


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: rharwood(at)redhat(dot)com
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, nico(at)cryptonector(dot)com
Subject: Re: [PATCH v19] GSSAPI encryption support
Date: 2018-12-03 21:20:47
Message-ID: 20181203212047.GM3415@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings Robbie,

* Dmitry Dolgov (9erthalion6(at)gmail(dot)com) wrote:
> > On Tue, Oct 2, 2018 at 11:12 PM Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
> >
> > Michael Paquier <michael(at)paquier(dot)xyz> writes:
> >
> > > On Mon, Aug 06, 2018 at 05:23:28PM -0400, Robbie Harwood wrote:
> > >> If you're in a position where you're using Kerberos (or most other
> > >> things from the GSSAPI) for authentication, the encryption comes at
> > >> little to no additional setup cost. And then you get all the security
> > >> benefits outlined in the docs changes.
> > >
> > > Please note that the last patch set does not apply anymore, so I have
> > > moved it to CF 2018-11 and marked it as waiting on author.
> >
> > Indeed. Please find v19 attached. It's just a rebase; no architecture
> > changes.
>
> Unfortunately, patch needs another rebase, could you do this? In the meantime
> I'll move it to the next CF.

This patch needs a few minor changes to get it back to working, but I'm
happy to say that with those changes, it seems to be working rather well
for me.

I'm working on a more comprehensive review but I wanted to go ahead and
get these first minor items out of the way:

Needs the same treatment done in ab69ea9, for all the WaitLatchOrSocket
calls in be-secure-gssapi.c:

- WaitLatchOrSocket(MyLatch, WL_SOCKET_WRITEABLE, port->sock, 0,
+ WaitLatchOrSocket(MyLatch, WL_SOCKET_WRITEABLE | WL_EXIT_ON_PM_DEATH, port->sock, 0,
WAIT_EVENT_GSS_OPEN_SERVER);

(and I have to wonder- if we want nearly all callers of
WaitLatch/WaitLatchOrSocket to use WL_EXIT_ON_PM_DEATH, maybe we should
make that the default and allow it to be overridden..? Also, does
ModifyWaitEvent() need to also do some checking here..? Should
be_tls_read()'s waitfor settings also include WL_EXIT_ON_PM_DEATH?)

Needed a minor adjustment in src/interfaces/libpq/fe-connect.c due to
conflict with 6e5f8d4.

Otherwise, it's building and running with all flavors of client and
server-side GSS-related options (require/disable/prefer and
host/hostgss/hostnogss).

Not surprisingly, trying to connect from a newer psql w/
PGGSSMODE=require (explicitly requesting encryption from the server)
with an older server blows up, but there's not much we can do for that.
Using prefer works, with an extra roundtrip to discover the server
doesn't understand GSSAPI encryption and then falling back.

Also, when connecting from an older psql to a newer server, if
pg_hba.conf has 'host' or 'hostnogss', everything works great (though
without GSSAPI encryption, of course), while an entry of 'hostgss'
returns the typical 'no pg_hba.conf entry found', as you'd expect.

Just in general, it seems like the code could use a lot more
comments. :) Also, it needs some pgindent run over it.

That's about all I have time to cover for today, but maybe you could try
to spruce up the comments (I'm at least a fan of function-level
comments, in particular, explaining how they're to be used, et al..),
see if you can get pgindent run over the changes and make the
above-mentioned fixes and then perhaps we can get cfbot to do its thing,
ask the other folks on the thread who were having issues before to retry
with this patch, if possible, and I'll start doing a more thorough code
review later this week.

Thanks!

Stephen


From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Nico Williams <nico(at)cryptonector(dot)com>
Subject: Re: [PATCH v19] GSSAPI encryption support
Date: 2018-12-03 21:55:23
Message-ID: CAEepm=2EQgjRTo4vxCzziwQ_R0UnExPpXcfz7_eY2J4t7mbc-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Dec 4, 2018 at 10:20 AM Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> (and I have to wonder- if we want nearly all callers of
> WaitLatch/WaitLatchOrSocket to use WL_EXIT_ON_PM_DEATH, maybe we should
> make that the default and allow it to be overridden..? ...

That is what I proposed. It was Heikki who talked me into the opt-in
solution, but using an assertion to make sure you handle it one way or
the other:

https://www.postgresql.org/message-id/6417314e-93d5-ed2d-9012-8d6e9ed21778%40iki.fi

Perhaps I should have sought more opinions. Please feel free to start
a new thread on that if you don't like the way it was done.

--
Thomas Munro
http://www.enterprisedb.com


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, nico(at)cryptonector(dot)com
Subject: Re: [PATCH v19] GSSAPI encryption support
Date: 2018-12-04 23:46:53
Message-ID: jlgsgzc26tu.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> Greetings Robbie,
>
> * Dmitry Dolgov (9erthalion6(at)gmail(dot)com) wrote:
>> > On Tue, Oct 2, 2018 at 11:12 PM Robbie Harwood <rharwood(at)redhat(dot)com> wrote:
>> >
>> > Michael Paquier <michael(at)paquier(dot)xyz> writes:
>> >
>> > > On Mon, Aug 06, 2018 at 05:23:28PM -0400, Robbie Harwood wrote:
>> > >> If you're in a position where you're using Kerberos (or most other
>> > >> things from the GSSAPI) for authentication, the encryption comes at
>> > >> little to no additional setup cost. And then you get all the security
>> > >> benefits outlined in the docs changes.
>> > >
>> > > Please note that the last patch set does not apply anymore, so I have
>> > > moved it to CF 2018-11 and marked it as waiting on author.
>> >
>> > Indeed. Please find v19 attached. It's just a rebase; no architecture
>> > changes.
>>
>> Unfortunately, patch needs another rebase, could you do this? In the meantime
>> I'll move it to the next CF.
>
> This patch needs a few minor changes to get it back to working, but I'm
> happy to say that with those changes, it seems to be working rather well
> for me.

Thanks Stephen!

Dmitry, I will make an update (and address Stephen's feedback) hopefully
soon.

Thanks,
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: [PATCH v20] GSSAPI encryption support
Date: 2018-12-18 19:12:46
Message-ID: jlgy38mir81.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello friends,

Attached please find version 20 of the GSSAPI encryption support. This
has been rebased onto master (thanks Stephen for calling out ab69ea9).
Other changes since v19 from Stephen's review:

- About 100 lines of new comments

- pgindent run over code (only the stuff I'm changing; it reports other
problems on master, but if I understand correctly, that's not on me to
fix here)

Thanks for the feedback! And speaking of feedback, this patch is in the
"Needs Review" state so if people have additional feedback, that would
be appreciated. I've CC'd people who I can remember reviewing before;
they should of course feel no obligation to review again if time
commitments/interests do not allow.

Thanks,
--Robbie

Attachment Content-Type Size
v20-libpq-GSSAPI-encryption-support.patch text/x-diff 79.2 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-11 12:53:35
Message-ID: 20190211125335.GN6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings Robbie,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Attached please find version 20 of the GSSAPI encryption support. This
> has been rebased onto master (thanks Stephen for calling out ab69ea9).
> Other changes since v19 from Stephen's review:
>
> - About 100 lines of new comments

Thanks for that.

> - pgindent run over code (only the stuff I'm changing; it reports other
> problems on master, but if I understand correctly, that's not on me to
> fix here)

That's correct.

> Thanks for the feedback! And speaking of feedback, this patch is in the
> "Needs Review" state so if people have additional feedback, that would
> be appreciated. I've CC'd people who I can remember reviewing before;
> they should of course feel no obligation to review again if time
> commitments/interests do not allow.

I've looked over this again and have been playing with it off-and-on for
a while now. One thing I was actually looking at implementing before we
push to commit this was to have similar information to what SSL provides
on connection, specifically what printSSLInfo() prints by way of
cipher, bits, etc for the client-side and then something like
pg_stat_ssl for the server side.

I went ahead and added a printGSSENCInfo(), and then PQgetgssSASLSSF(),
which calls down into gss_inquire_sec_context_by_oid() for
GSS_C_SEC_CONTEXT_SASL_SSF to get the bits (which also required
including gssapi_ext.h), and now have psql producing:

---
psql (12devel)
GSS Encrypted connection (bits: 256)
Type "help" for help.
---

I was curious though- is there a good way to get at the encryption type
used..? I haven't had much luck in reading the RFPs and poking around,
but perhaps I'm just not looking in the right place. Also, what
information do you think would be particularly useful on the server
side? I was thinking that the princ used to authenticate, the
encryption type/cipher, and bits used, at least, would be meaningful.
I'm also guessing that we may need to add something to make these
functions not fail on older systems which don't provide the SASL SSF
OID..? I haven't looked into that yet but we should.

I don't think these things are absolutely required to push the patch
forward, just to be clear, but it's helping my confidence level, at
least, and would make it closer to on-par with our current SSL
implementation. They also seem, well, reasonably straight-forward to
add and quite useful.

I've attached my WIP patch for adding the bits, patched over-top of your
v20 (would be neat if there was a way to tell cfbot to ignore it...).

Thoughts?

Thanks!

Stephen

Attachment Content-Type Size
print-gssapi-sasl-ssf-psql.patch text/x-diff 6.8 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-12 01:16:00
Message-ID: jlg7ee5zu0f.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>
>> Attached please find version 20 of the GSSAPI encryption support.
>> This has been rebased onto master (thanks Stephen for calling out
>> ab69ea9).
>
> I've looked over this again and have been playing with it off-and-on
> for a while now. One thing I was actually looking at implementing
> before we push to commit this was to have similar information to what
> SSL provides on connection, specifically what printSSLInfo() prints by
> way of cipher, bits, etc for the client-side and then something like
> pg_stat_ssl for the server side.
>
> I went ahead and added a printGSSENCInfo(), and then
> PQgetgssSASLSSF(), which calls down into
> gss_inquire_sec_context_by_oid() for GSS_C_SEC_CONTEXT_SASL_SSF to get
> the bits (which also required including gssapi_ext.h), and now have
> psql producing:

Neat! Two things here:

First, because this is a SASL extension, it requires existing mechanism
integration with SASL. For instance, NTLM (through gss-ntlmssp) doesn't
implement it. PQgetgssSASLSSF() logs an error message here, which I
don't think is quite right - probably you should only log an error
message if you don't get back GSS_S_COMPLETE or GSS_S_UNAVAILABLE.

(NTLM is an example here; I cannot in good conscience recommend its use,
and neither does Microsoft.)

Also, this is an MIT-specific extension: Heimdal doesn't support it.
While I (a krb5 developer) am fine with a hard MIT dependency, the
project doesn't currently have this. (And if we went that road, I'd
like to use gss_acquire_cred_from() instead of the setenv() in
be-secure-gssapi.c.)

> ---
> psql (12devel)
> GSS Encrypted connection (bits: 256)
> Type "help" for help.
> ---
>
> I was curious though- is there a good way to get at the encryption
> type used..? I haven't had much luck in reading the RFPs and poking
> around, but perhaps I'm just not looking in the right place.

It's something of a layering issue. GSSAPI might not be using Kerberos,
and even if it is, Kerberos has algorithm agility.

A call to gss_inquire_context() produces mech type, so you could print
something like "GSS Encrypted connection (Kerberos 256 bits)" or "GSS
encrypted connection (NTLM)". I think this'd be pretty reasonable.

For Kerberos-specific introspection, MIT krb5 and Heimdal both support
an interface called lucid contexts that allows this kind of
introspection (and some other gross layering violations) for use with
the kernel. Look at gssapi_krb5.h (it's called that in both). I don't
think it's worth supporting rfc1964 at this point (it's 1DES-only).

> Also, what information do you think would be particularly useful on
> the server side? I was thinking that the princ used to authenticate,
> the encryption type/cipher, and bits used, at least, would be
> meaningful.

I'm wary about indicating number of bits especially with the
asymmetric/symmetric divide and the importance of which algorithm
they're used with, but that may be a non-concern - especially if it
attains parity with the TLS code.

Principal used is definitely good (helps debugging the user mapping
rules, if nothing else). Mechanism is also nice. I can't think of
anything else right now that you haven't mentioned.

I think there's value in auth indcatorsp
http://web.mit.edu/kerberos/krb5-latest/doc/admin/auth_indicator.html
but supporting them would be a separate follow-on patch.

> I'm also guessing that we may need to add something to
> make these functions not fail on older systems which don't provide the
> SASL SSF OID..? I haven't looked into that yet but we should.

MIT krb5 gained support in 2017, which corresponds to krb5-1.16; Heimdal
has no support for it. There probably isn't a shortcut for a
buildsystem check, unfortunately: Heimdal has
gss_inquire_sec_context_by_oid() in another file (they don't have
gssapi_ext.h), and it's the OID is MIT-only and not a #define-d
constant.

(With my downstream maintainer hat on, I'd further ask that any such
check not just be a version check in order to allow backporting; in
particular, the el7 krb5-1.15 branch does include support for this OID.)

> I don't think these things are absolutely required to push the patch
> forward, just to be clear, but it's helping my confidence level, at
> least, and would make it closer to on-par with our current SSL
> implementation. They also seem, well, reasonably straight-forward to
> add and quite useful.

Auditability is definitely reasonable. I think there are a couple
additional wrinkles discussed above, but we can probably get them
sorted.

> I've attached my WIP patch for adding the bits, patched over-top of your
> v20 (would be neat if there was a way to tell cfbot to ignore it...).

I don't have additional concerns beyond the above.

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-12 01:41:05
Message-ID: 20190212014105.GO6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> >> Attached please find version 20 of the GSSAPI encryption support.
> >> This has been rebased onto master (thanks Stephen for calling out
> >> ab69ea9).
> >
> > I've looked over this again and have been playing with it off-and-on
> > for a while now. One thing I was actually looking at implementing
> > before we push to commit this was to have similar information to what
> > SSL provides on connection, specifically what printSSLInfo() prints by
> > way of cipher, bits, etc for the client-side and then something like
> > pg_stat_ssl for the server side.
> >
> > I went ahead and added a printGSSENCInfo(), and then
> > PQgetgssSASLSSF(), which calls down into
> > gss_inquire_sec_context_by_oid() for GSS_C_SEC_CONTEXT_SASL_SSF to get
> > the bits (which also required including gssapi_ext.h), and now have
> > psql producing:
>
> Neat! Two things here:
>
> First, because this is a SASL extension, it requires existing mechanism
> integration with SASL. For instance, NTLM (through gss-ntlmssp) doesn't
> implement it. PQgetgssSASLSSF() logs an error message here, which I
> don't think is quite right - probably you should only log an error
> message if you don't get back GSS_S_COMPLETE or GSS_S_UNAVAILABLE.

Ok, that's easy enough to fix.

> (NTLM is an example here; I cannot in good conscience recommend its use,
> and neither does Microsoft.)

Agreed!

> Also, this is an MIT-specific extension: Heimdal doesn't support it.

Is that simply because they've not gotten around to it..? From what I
saw, this approach is in an accepted RFC, so if they want to implement
it, they could do so..?

> While I (a krb5 developer) am fine with a hard MIT dependency, the
> project doesn't currently have this. (And if we went that road, I'd
> like to use gss_acquire_cred_from() instead of the setenv() in
> be-secure-gssapi.c.)

We certainly don't want a hard MIT dependency, but if it's following an
RFC and we can gracefully fall-back if it isn't available then I think
it's acceptable. If there's a better approach which would work with
both MIT and Heimdal and ideally is defined through an RFC, that'd be
better, but I'm guessing there isn't...

> > ---
> > psql (12devel)
> > GSS Encrypted connection (bits: 256)
> > Type "help" for help.
> > ---
> >
> > I was curious though- is there a good way to get at the encryption
> > type used..? I haven't had much luck in reading the RFPs and poking
> > around, but perhaps I'm just not looking in the right place.
>
> It's something of a layering issue. GSSAPI might not be using Kerberos,
> and even if it is, Kerberos has algorithm agility.

Right, I'm aware that Kerberos could be using different encryption
algorithms, similar to SSL and that GSSAPI itself would allow for
different algorithms through different mechanisms- but the question is,
how do we know what the encryption algorithm ultimately used, regardless
of the rest, is?

> A call to gss_inquire_context() produces mech type, so you could print
> something like "GSS Encrypted connection (Kerberos 256 bits)" or "GSS
> encrypted connection (NTLM)". I think this'd be pretty reasonable.

I'm... not impressed with that approach, since "Kerberos" as an
encryption algorithm doesn't mean squat- that could be DES or RC4 for
all we know.

> For Kerberos-specific introspection, MIT krb5 and Heimdal both support
> an interface called lucid contexts that allows this kind of
> introspection (and some other gross layering violations) for use with
> the kernel. Look at gssapi_krb5.h (it's called that in both). I don't
> think it's worth supporting rfc1964 at this point (it's 1DES-only).

I agree that there's no sense in supporting 1DES-only.

I also, frankly, don't agree with the characterization that wanting to
know what the agreed-upon encryption algorithm is constitutes a gross
layering violation, but that's really an independent discussion that we
can have in a pub somewhere. ;)

To get where I'd like us to be, however, it sounds like we need to:

a) determine if we've got encryption (that's easy, assuming I've done it
correctly so far)

b) Figure out if the encryption is being provided by Kerberos (using
gss_inquire_context() would do that, right?)

c) If we're using Kerberos, use the lucid contexts to ask what the
actual encryption algorithm used is

That's a bit obnoxious but it at least seems doable. I don't suppose
you know of any example code out there which provides this? Any idea if
there's work underway on an RFC to make this, well, suck less?

> > Also, what information do you think would be particularly useful on
> > the server side? I was thinking that the princ used to authenticate,
> > the encryption type/cipher, and bits used, at least, would be
> > meaningful.
>
> I'm wary about indicating number of bits especially with the
> asymmetric/symmetric divide and the importance of which algorithm
> they're used with, but that may be a non-concern - especially if it
> attains parity with the TLS code.

This would be why I'd like to also provide the algorithm... :)

> Principal used is definitely good (helps debugging the user mapping
> rules, if nothing else). Mechanism is also nice. I can't think of
> anything else right now that you haven't mentioned.

Good idea to also include mechanism explicitly.

> I think there's value in auth indcatorsp
> http://web.mit.edu/kerberos/krb5-latest/doc/admin/auth_indicator.html
> but supporting them would be a separate follow-on patch.

Hmmm, that does look interesting, but I agree that it could be a
follow-on patch.

> > I'm also guessing that we may need to add something to
> > make these functions not fail on older systems which don't provide the
> > SASL SSF OID..? I haven't looked into that yet but we should.
>
> MIT krb5 gained support in 2017, which corresponds to krb5-1.16; Heimdal
> has no support for it. There probably isn't a shortcut for a
> buildsystem check, unfortunately: Heimdal has
> gss_inquire_sec_context_by_oid() in another file (they don't have
> gssapi_ext.h), and it's the OID is MIT-only and not a #define-d
> constant.

I had been presuming that it'd be a buildsystem check, though it would
have been nice if it could have been something run-time.

> (With my downstream maintainer hat on, I'd further ask that any such
> check not just be a version check in order to allow backporting; in
> particular, the el7 krb5-1.15 branch does include support for this OID.)

I don't have any issue with that provided we can implement the check in
a reasonable way (hint: I'm open to your suggestions on this :).

> > I don't think these things are absolutely required to push the patch
> > forward, just to be clear, but it's helping my confidence level, at
> > least, and would make it closer to on-par with our current SSL
> > implementation. They also seem, well, reasonably straight-forward to
> > add and quite useful.
>
> Auditability is definitely reasonable. I think there are a couple
> additional wrinkles discussed above, but we can probably get them
> sorted.

Fantastic. Do you think you'll have time to work through some of the
above with me over the next couple of weeks? I was just starting to
look into adding things into the beentry to hold information on the
server side.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-12 19:06:44
Message-ID: jlgwom4kerf.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>>>
>>>> Attached please find version 20 of the GSSAPI encryption support.
>>>> This has been rebased onto master (thanks Stephen for calling out
>>>> ab69ea9).
>>>
>>> I've looked over this again and have been playing with it off-and-on
>>> for a while now. One thing I was actually looking at implementing
>>> before we push to commit this was to have similar information to
>>> what SSL provides on connection, specifically what printSSLInfo()
>>> prints by way of cipher, bits, etc for the client-side and then
>>> something like pg_stat_ssl for the server side.
>>>
>>> I went ahead and added a printGSSENCInfo(), and then
>>> PQgetgssSASLSSF(), which calls down into
>>> gss_inquire_sec_context_by_oid() for GSS_C_SEC_CONTEXT_SASL_SSF to
>>> get the bits (which also required including gssapi_ext.h), and now
>>> have psql producing:
>>
>> Also, this is an MIT-specific extension: Heimdal doesn't support it.
>
> Is that simply because they've not gotten around to it..? From what I
> saw, this approach is in an accepted RFC, so if they want to implement
> it, they could do so..?

Yes. Heimdal is less active these days than MIT; they were dormant for
a while, though are active again. They do have an issue open to track
this feature: https://github.com/heimdal/heimdal/issues/400

>> While I (a krb5 developer) am fine with a hard MIT dependency, the
>> project doesn't currently have this. (And if we went that road, I'd
>> like to use gss_acquire_cred_from() instead of the setenv() in
>> be-secure-gssapi.c.)
>
> We certainly don't want a hard MIT dependency, but if it's following an
> RFC and we can gracefully fall-back if it isn't available then I think
> it's acceptable. If there's a better approach which would work with
> both MIT and Heimdal and ideally is defined through an RFC, that'd be
> better, but I'm guessing there isn't...

While I think the concept of SASL SSF is standardized, I don't think the
semantics of this OID are - the OID itself is in the MIT gssapi
extension space.

As a historical note, the reason this interface exists in krb5 is of
course for SASL. In particular, cyrus was reporting treating the SSF of
all krb5 types as if they were DES. So while technically "assume DES"
could be a fallback... we probably shouldn't do that.

>>> ---
>>> psql (12devel)
>>> GSS Encrypted connection (bits: 256)
>>> Type "help" for help.
>>> ---
>>>
>>> I was curious though- is there a good way to get at the encryption
>>> type used..? I haven't had much luck in reading the RFPs and poking
>>> around, but perhaps I'm just not looking in the right place.
>>
>> A call to gss_inquire_context() produces mech type, so you could
>> print something like "GSS Encrypted connection (Kerberos 256 bits)"
>> or "GSS encrypted connection (NTLM)". I think this'd be pretty
>> reasonable.
>
> I'm... not impressed with that approach, since "Kerberos" as an
> encryption algorithm doesn't mean squat- that could be DES or RC4 for
> all we know.

This is a fair concern.

>> For Kerberos-specific introspection, MIT krb5 and Heimdal both
>> support an interface called lucid contexts that allows this kind of
>> introspection (and some other gross layering violations) for use with
>> the kernel. Look at gssapi_krb5.h (it's called that in both). I
>> don't think it's worth supporting rfc1964 at this point (it's
>> 1DES-only).
>
> I agree that there's no sense in supporting 1DES-only.
>
> I also, frankly, don't agree with the characterization that wanting to
> know what the agreed-upon encryption algorithm is constitutes a gross
> layering violation, but that's really an independent discussion that we
> can have in a pub somewhere. ;)

Yeah I won't defend it very hard :)

> To get where I'd like us to be, however, it sounds like we need to:
>
> a) determine if we've got encryption (that's easy, assuming I've done it
> correctly so far)

Yes.

> b) Figure out if the encryption is being provided by Kerberos (using
> gss_inquire_context() would do that, right?)

Right - check and log mech_out there, then proceed if it's
gss_mech_krb5. Probably not worth handling _old and _wrong, especially
since Heimdal doesn't have them and they shouldn't be in use anyway.

> c) If we're using Kerberos, use the lucid contexts to ask what the
> actual encryption algorithm used is

Yes. This'll involve some introspection into krb5.h (for enctype
names), but that's not too hard.

> That's a bit obnoxious but it at least seems doable. I don't suppose
> you know of any example code out there which provides this? Any idea
> if there's work underway on an RFC to make this, well, suck less?

MIT has some in our test suite (t_enctypes). nfs-utils (GPLv2) also
uses this interface (NFS is the intended consumer).

There isn't IETF effort in this regard that I'm aware of, but I'll add
it to the kitten backlog.

>> (With my downstream maintainer hat on, I'd further ask that any such
>> check not just be a version check in order to allow backporting; in
>> particular, the el7 krb5-1.15 branch does include support for this OID.)
>
> I don't have any issue with that provided we can implement the check in
> a reasonable way (hint: I'm open to your suggestions on this :).
>
>>> I don't think these things are absolutely required to push the patch
>>> forward, just to be clear, but it's helping my confidence level, at
>>> least, and would make it closer to on-par with our current SSL
>>> implementation. They also seem, well, reasonably straight-forward to
>>> add and quite useful.
>>
>> Auditability is definitely reasonable. I think there are a couple
>> additional wrinkles discussed above, but we can probably get them
>> sorted.
>
> Fantastic. Do you think you'll have time to work through some of the
> above with me over the next couple of weeks? I was just starting to
> look into adding things into the beentry to hold information on the
> server side.

Sure! I'll go ahead and hack up the checks and lucid stuff and get back
to you.

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-12 19:17:31
Message-ID: 20190212191731.GS6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> >> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> >>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> >>>
> >>>> Attached please find version 20 of the GSSAPI encryption support.
> >>>> This has been rebased onto master (thanks Stephen for calling out
> >>>> ab69ea9).
> >>>
> >>> I've looked over this again and have been playing with it off-and-on
> >>> for a while now. One thing I was actually looking at implementing
> >>> before we push to commit this was to have similar information to
> >>> what SSL provides on connection, specifically what printSSLInfo()
> >>> prints by way of cipher, bits, etc for the client-side and then
> >>> something like pg_stat_ssl for the server side.
> >>>
> >>> I went ahead and added a printGSSENCInfo(), and then
> >>> PQgetgssSASLSSF(), which calls down into
> >>> gss_inquire_sec_context_by_oid() for GSS_C_SEC_CONTEXT_SASL_SSF to
> >>> get the bits (which also required including gssapi_ext.h), and now
> >>> have psql producing:
> >>
> >> Also, this is an MIT-specific extension: Heimdal doesn't support it.
> >
> > Is that simply because they've not gotten around to it..? From what I
> > saw, this approach is in an accepted RFC, so if they want to implement
> > it, they could do so..?
>
> Yes. Heimdal is less active these days than MIT; they were dormant for
> a while, though are active again. They do have an issue open to track
> this feature: https://github.com/heimdal/heimdal/issues/400

Ok, good, when they add it then hopefully it'll be picked up
more-or-less 'for free'.

> >> While I (a krb5 developer) am fine with a hard MIT dependency, the
> >> project doesn't currently have this. (And if we went that road, I'd
> >> like to use gss_acquire_cred_from() instead of the setenv() in
> >> be-secure-gssapi.c.)
> >
> > We certainly don't want a hard MIT dependency, but if it's following an
> > RFC and we can gracefully fall-back if it isn't available then I think
> > it's acceptable. If there's a better approach which would work with
> > both MIT and Heimdal and ideally is defined through an RFC, that'd be
> > better, but I'm guessing there isn't...
>
> While I think the concept of SASL SSF is standardized, I don't think the
> semantics of this OID are - the OID itself is in the MIT gssapi
> extension space.

We can adjust for that pretty easily, presumably, if another OID ends up
being assigned (though if one already exists, isn't it something that
Heimdal, for example, could potentially decide to just support..?).

> As a historical note, the reason this interface exists in krb5 is of
> course for SASL. In particular, cyrus was reporting treating the SSF of
> all krb5 types as if they were DES. So while technically "assume DES"
> could be a fallback... we probably shouldn't do that.

Agreed, we shouldn't do that.

> >> A call to gss_inquire_context() produces mech type, so you could
> >> print something like "GSS Encrypted connection (Kerberos 256 bits)"
> >> or "GSS encrypted connection (NTLM)". I think this'd be pretty
> >> reasonable.
> >
> > I'm... not impressed with that approach, since "Kerberos" as an
> > encryption algorithm doesn't mean squat- that could be DES or RC4 for
> > all we know.
>
> This is a fair concern.

I will say that I'm alright with listing Kerberos in the message if we
think it's useful- but we should also list the actual encryption
algorithm and bits, if possible (which it sounds like it is, so that's
definitely good).

> > To get where I'd like us to be, however, it sounds like we need to:
> >
> > a) determine if we've got encryption (that's easy, assuming I've done it
> > correctly so far)
>
> Yes.
>
> > b) Figure out if the encryption is being provided by Kerberos (using
> > gss_inquire_context() would do that, right?)
>
> Right - check and log mech_out there, then proceed if it's
> gss_mech_krb5. Probably not worth handling _old and _wrong, especially
> since Heimdal doesn't have them and they shouldn't be in use anyway.
>
> > c) If we're using Kerberos, use the lucid contexts to ask what the
> > actual encryption algorithm used is
>
> Yes. This'll involve some introspection into krb5.h (for enctype
> names), but that's not too hard.

Sounds good.

> > That's a bit obnoxious but it at least seems doable. I don't suppose
> > you know of any example code out there which provides this? Any idea
> > if there's work underway on an RFC to make this, well, suck less?
>
> MIT has some in our test suite (t_enctypes). nfs-utils (GPLv2) also
> uses this interface (NFS is the intended consumer).
>
> There isn't IETF effort in this regard that I'm aware of, but I'll add
> it to the kitten backlog.

Fantastic, thanks.

> >> (With my downstream maintainer hat on, I'd further ask that any such
> >> check not just be a version check in order to allow backporting; in
> >> particular, the el7 krb5-1.15 branch does include support for this OID.)
> >
> > I don't have any issue with that provided we can implement the check in
> > a reasonable way (hint: I'm open to your suggestions on this :).
> >
> >>> I don't think these things are absolutely required to push the patch
> >>> forward, just to be clear, but it's helping my confidence level, at
> >>> least, and would make it closer to on-par with our current SSL
> >>> implementation. They also seem, well, reasonably straight-forward to
> >>> add and quite useful.
> >>
> >> Auditability is definitely reasonable. I think there are a couple
> >> additional wrinkles discussed above, but we can probably get them
> >> sorted.
> >
> > Fantastic. Do you think you'll have time to work through some of the
> > above with me over the next couple of weeks? I was just starting to
> > look into adding things into the beentry to hold information on the
> > server side.
>
> Sure! I'll go ahead and hack up the checks and lucid stuff and get back
> to you.

Great! I'll finish fleshing out the basics of how to have this work
server-side and once the checks and lucid stuff are in on the psql side,
it should be pretty straight-forward to copy that same information into
beentry alongside the SSL info, and expose it through
pg_stat_get_activity() into a pg_stat_gss view.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-12 19:33:34
Message-ID: jlgtvh8kdip.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>>>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>>>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>>>>>
>>>>>> Attached please find version 20 of the GSSAPI encryption support.
>>>>>> This has been rebased onto master (thanks Stephen for calling out
>>>>>> ab69ea9).
>>>>>
>>>>> I've looked over this again and have been playing with it
>>>>> off-and-on for a while now. One thing I was actually looking at
>>>>> implementing before we push to commit this was to have similar
>>>>> information to what SSL provides on connection, specifically what
>>>>> printSSLInfo() prints by way of cipher, bits, etc for the
>>>>> client-side and then something like pg_stat_ssl for the server
>>>>> side.
>>>>>
>>>>> I went ahead and added a printGSSENCInfo(), and then
>>>>> PQgetgssSASLSSF(), which calls down into
>>>>> gss_inquire_sec_context_by_oid() for GSS_C_SEC_CONTEXT_SASL_SSF to
>>>>> get the bits (which also required including gssapi_ext.h), and now
>>>>> have psql producing:
>>>>
>>>> While I (a krb5 developer) am fine with a hard MIT dependency, the
>>>> project doesn't currently have this. (And if we went that road,
>>>> I'd like to use gss_acquire_cred_from() instead of the setenv() in
>>>> be-secure-gssapi.c.)
>>>
>>> We certainly don't want a hard MIT dependency, but if it's following
>>> an RFC and we can gracefully fall-back if it isn't available then I
>>> think it's acceptable. If there's a better approach which would
>>> work with both MIT and Heimdal and ideally is defined through an
>>> RFC, that'd be better, but I'm guessing there isn't...
>>
>> While I think the concept of SASL SSF is standardized, I don't think
>> the semantics of this OID are - the OID itself is in the MIT gssapi
>> extension space.
>
> We can adjust for that pretty easily, presumably, if another OID ends
> up being assigned (though if one already exists, isn't it something
> that Heimdal, for example, could potentially decide to just
> support..?).

Yes, exactly - Heimdal would probably just use the MIT OID with the
existing semantics.

Thanks,
--Robbie


From: Andres Freund <andres(at)anarazel(dot)de>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Stephen Frost <sfrost(at)snowman(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-16 04:10:26
Message-ID: 20190216041026.gpkfn4e6wrozliyb@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

On 2018-12-18 14:12:46 -0500, Robbie Harwood wrote:
> From 6915ae2507bf7910c5eecfbd0b84805531c16a07 Mon Sep 17 00:00:00 2001
> From: Robbie Harwood <rharwood(at)redhat(dot)com>
> Date: Thu, 10 May 2018 16:12:03 -0400
> Subject: [PATCH] libpq GSSAPI encryption support
>
> On both the frontend and backend, prepare for GSSAPI encryption
> support by moving common code for error handling into a separate file.
> Fix a TODO for handling multiple status messages in the process.
> Eliminate the OIDs, which have not been needed for some time.
> Add frontend and backend encryption support functions. Keep the
> context initiation for authentication-only separate on both the
> frontend and backend in order to avoid concerns about changing the
> requested flags to include encryption support.
>
> In postmaster, pull GSSAPI authorization checking into a shared
> function. Also share the initiator name between the encryption and
> non-encryption codepaths.
>
> Modify pqsecure_write() to take a non-const pointer. The pointer will
> not be modified, but this change (or a const-discarding cast, or a
> malloc()+memcpy()) is necessary for GSSAPI due to const/struct
> interactions in C.
>
> For HBA, add "hostgss" and "hostnogss" entries that behave similarly
> to their SSL counterparts. "hostgss" requires either "gss", "trust",
> or "reject" for its authentication.
>
> Simiarly, add a "gssmode" parameter to libpq. Supported values are
> "disable", "require", and "prefer". Notably, negotiation will only be
> attempted if credentials can be acquired. Move credential acquisition
> into its own function to support this behavior.
>
> Finally, add documentation for everything new, and update existing
> documentation on connection security.
>
> Thanks to Michael Paquier for the Windows fixes.

Could some of these be split into separate patches that could be more
eagerly merged? This is a somewhat large patch...

> diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
> index a06fc7dc82..f4f196e3b4 100644
> --- a/src/interfaces/libpq/fe-secure.c
> +++ b/src/interfaces/libpq/fe-secure.c
> @@ -220,6 +220,13 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
> n = pgtls_read(conn, ptr, len);
> }
> else
> +#endif
> +#ifdef ENABLE_GSS
> + if (conn->gssenc)
> + {
> + n = pg_GSS_read(conn, ptr, len);
> + }
> + else
> #endif
> {
> n = pqsecure_raw_read(conn, ptr, len);
> @@ -287,7 +294,7 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
> * to determine whether to continue/retry after error.
> */
> ssize_t
> -pqsecure_write(PGconn *conn, const void *ptr, size_t len)
> +pqsecure_write(PGconn *conn, void *ptr, size_t len)
> {
> ssize_t n;
>
> @@ -297,6 +304,13 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
> n = pgtls_write(conn, ptr, len);
> }
> else
> +#endif
> +#ifdef ENABLE_GSS
> + if (conn->gssenc)
> + {
> + n = pg_GSS_write(conn, ptr, len);
> + }
> + else
> #endif
> {
> n = pqsecure_raw_write(conn, ptr, len);

Not a fan of this. Seems like we'll grow more and more such branches
over time? Wouldn't the right thing be to have callbacks in PGconn (and
similarly in the backend)? Seems like if that's done reasonably it'd
also make integration of compression easier, because that could just
layer itself between encryption and wire?

Greetings,

Andres Freund


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org, Stephen Frost <sfrost(at)snowman(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-18 15:02:27
Message-ID: jlgzhqtqgvw.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:

> On 2018-12-18 14:12:46 -0500, Robbie Harwood wrote:
>
>> Subject: [PATCH] libpq GSSAPI encryption support
>
> Could some of these be split into separate patches that could be more
> eagerly merged? This is a somewhat large patch...

What splits do you propose? (It's been a single patch since v3 as per
your request in id:20151003161810(dot)GD30738(at)alap3(dot)anarazel(dot)de and Michael
Paquier's request in
id:CAB7nPqTJD-tTrM1Vu8P55_4kKVeDX8DFz9v1D_XsQQvR_xA5qQ(at)mail(dot)gmail(dot)com).

>> diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
>> index a06fc7dc82..f4f196e3b4 100644
>> --- a/src/interfaces/libpq/fe-secure.c
>> +++ b/src/interfaces/libpq/fe-secure.c
>> @@ -220,6 +220,13 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
>> n = pgtls_read(conn, ptr, len);
>> }
>> else
>> +#endif
>> +#ifdef ENABLE_GSS
>> + if (conn->gssenc)
>> + {
>> + n = pg_GSS_read(conn, ptr, len);
>> + }
>> + else
>> #endif
>> {
>> n = pqsecure_raw_read(conn, ptr, len);
>> @@ -287,7 +294,7 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
>> * to determine whether to continue/retry after error.
>> */
>> ssize_t
>> -pqsecure_write(PGconn *conn, const void *ptr, size_t len)
>> +pqsecure_write(PGconn *conn, void *ptr, size_t len)
>> {
>> ssize_t n;
>>
>> @@ -297,6 +304,13 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
>> n = pgtls_write(conn, ptr, len);
>> }
>> else
>> +#endif
>> +#ifdef ENABLE_GSS
>> + if (conn->gssenc)
>> + {
>> + n = pg_GSS_write(conn, ptr, len);
>> + }
>> + else
>> #endif
>> {
>> n = pqsecure_raw_write(conn, ptr, len);
>
> Not a fan of this. Seems like we'll grow more and more such branches
> over time? Wouldn't the right thing be to have callbacks in PGconn
> (and similarly in the backend)?

Is that really a problem? Each branch is only seven lines, which is a
lot less than adding callback support will be. And we'll only get a new
branch when we want to support a new encryption protocol - unlike
authentication, there aren't too many of those.

> Seems like if that's done reasonably it'd also make integration of
> compression easier, because that could just layer itself between
> encryption and wire?

The current interface would allow a compress/decompress call in a way
that makes sense to me (here for write, ignoring ifdefs):

ssize_t pqsecure_write(PGConn *conn, void *ptr, size_t len)
{
ssize_t n;

if (conn->compress)
{
do_compression(conn, &ptr, &len);
}
if (conn->ssl_in_use)
{
n = pgtls_write(conn, ptr, len);
}
else if (conn->gssenc)
{
n = pg_GSS_write(conn, ptr, len);
}
else
{
n = pqsecure_raw_write(conn, ptr, len);
}

return n;
}

(pqsecure_read would look similarly, with decompression as the last step
instead of the first.)

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-18 15:32:53
Message-ID: 20190218153253.GE6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Andres Freund <andres(at)anarazel(dot)de> writes:
>
> > On 2018-12-18 14:12:46 -0500, Robbie Harwood wrote:
> >
> >> Subject: [PATCH] libpq GSSAPI encryption support
> >
> > Could some of these be split into separate patches that could be more
> > eagerly merged? This is a somewhat large patch...
>
> What splits do you propose? (It's been a single patch since v3 as per
> your request in id:20151003161810(dot)GD30738(at)alap3(dot)anarazel(dot)de and Michael
> Paquier's request in
> id:CAB7nPqTJD-tTrM1Vu8P55_4kKVeDX8DFz9v1D_XsQQvR_xA5qQ(at)mail(dot)gmail(dot)com).

Yeah, I tend to agree with the earlier comments that this can be a
single patch. There's a little bit that could maybe be split out (when
it comes to the bits that are mostly just moving things around and
removing things) but I'm not convinced it's necessary or, really,
particularly worth it.

> >> diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
> >> index a06fc7dc82..f4f196e3b4 100644
> >> --- a/src/interfaces/libpq/fe-secure.c
> >> +++ b/src/interfaces/libpq/fe-secure.c
> >> @@ -220,6 +220,13 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
> >> n = pgtls_read(conn, ptr, len);
> >> }
> >> else
> >> +#endif
> >> +#ifdef ENABLE_GSS
> >> + if (conn->gssenc)
> >> + {
> >> + n = pg_GSS_read(conn, ptr, len);
> >> + }
> >> + else
> >> #endif
> >> {
> >> n = pqsecure_raw_read(conn, ptr, len);
> >> @@ -287,7 +294,7 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
> >> * to determine whether to continue/retry after error.
> >> */
> >> ssize_t
> >> -pqsecure_write(PGconn *conn, const void *ptr, size_t len)
> >> +pqsecure_write(PGconn *conn, void *ptr, size_t len)
> >> {
> >> ssize_t n;
> >>
> >> @@ -297,6 +304,13 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
> >> n = pgtls_write(conn, ptr, len);
> >> }
> >> else
> >> +#endif
> >> +#ifdef ENABLE_GSS
> >> + if (conn->gssenc)
> >> + {
> >> + n = pg_GSS_write(conn, ptr, len);
> >> + }
> >> + else
> >> #endif
> >> {
> >> n = pqsecure_raw_write(conn, ptr, len);
> >
> > Not a fan of this. Seems like we'll grow more and more such branches
> > over time? Wouldn't the right thing be to have callbacks in PGconn
> > (and similarly in the backend)?
>
> Is that really a problem? Each branch is only seven lines, which is a
> lot less than adding callback support will be. And we'll only get a new
> branch when we want to support a new encryption protocol - unlike
> authentication, there aren't too many of those.

Considering this is only the second encryption protocol in the project's
lifetime, I agree that using callbacks would be overkill here. What
other encryption protocols are you thinking we would be adding here? I
think most would be quite hard-pressed to name a second general-purpose
one beyond TLS/SSL, and those who can almost certainly would say GSS,
but a third? Certainly OpenSSH has its own, but it's not intended to be
general purpose and I can't see us adding support for OpenSSH's
encryption protocol to PG.

Adding support for different libraries which implement TLS/SSL wouldn't
be changing this part of the code, if that was perhaps what was being
considered..?

> > Seems like if that's done reasonably it'd also make integration of
> > compression easier, because that could just layer itself between
> > encryption and wire?

Building a general-purpose filtering mechanism for streams is actually
quite a bit of work (we did it for pgBackRest, feel free to check it
out- and all that code is in C these days too) and I don't think it's
really necessary when the options are "optionally compress and
optionally encrypt using one of these two protocols". I don't see any
reason why we'd need to, say, compress a stream multiple times, or
encrypt it multiple times (like with TLS first and then GSS).

> The current interface would allow a compress/decompress call in a way
> that makes sense to me (here for write, ignoring ifdefs):

[...]

> (pqsecure_read would look similarly, with decompression as the last step
> instead of the first.)

That certainly seems reasonable to me.

Thanks!

Stephen


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-20 10:15:32
Message-ID: dffb5116-6c00-d659-e569-b41489ac4c9a@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-02-18 16:32, Stephen Frost wrote:
> Considering this is only the second encryption protocol in the project's
> lifetime, I agree that using callbacks would be overkill here. What
> other encryption protocols are you thinking we would be adding here? I
> think most would be quite hard-pressed to name a second general-purpose
> one beyond TLS/SSL, and those who can almost certainly would say GSS,
> but a third? Certainly OpenSSH has its own, but it's not intended to be
> general purpose and I can't see us adding support for OpenSSH's
> encryption protocol to PG.

I did look into an SSH-based encryption layer at one point. It's
certainly attractive in terms of simplicity over SSL. But your point
stands nonetheless, for two or three plausible implementations, we don't
necessarily need a generic plugin system.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-21 22:21:28
Message-ID: jlg36og4wbb.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>>>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>>>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>>>>>
>>>>>> Attached please find version 20 of the GSSAPI encryption support.
>>>>>> This has been rebased onto master (thanks Stephen for calling out
>>>>>> ab69ea9).
>>>>>
>>>>> I've looked over this again and have been playing with it
>>>>> off-and-on for a while now. One thing I was actually looking at
>>>>> implementing before we push to commit this was to have similar
>>>>> information to what SSL provides on connection, specifically what
>>>>> printSSLInfo() prints by way of cipher, bits, etc for the
>>>>> client-side and then something like pg_stat_ssl for the server
>>>>> side.
>>>>>
>>>>> I went ahead and added a printGSSENCInfo(), and then
>>>>> PQgetgssSASLSSF(), which calls down into
>>>>> gss_inquire_sec_context_by_oid() for GSS_C_SEC_CONTEXT_SASL_SSF to
>>>>> get the bits (which also required including gssapi_ext.h), and now
>>>>> have psql producing:
>>>>>
>>>>> I don't think these things are absolutely required to push the
>>>>> patch forward, just to be clear, but it's helping my confidence
>>>>> level, at least, and would make it closer to on-par with our
>>>>> current SSL implementation. They also seem, well, reasonably
>>>>> straight-forward to add and quite useful.
>>>>
>>>> Auditability is definitely reasonable. I think there are a couple
>>>> additional wrinkles discussed above, but we can probably get them
>>>> sorted.
>>>
>>> Fantastic. Do you think you'll have time to work through some of
>>> the above with me over the next couple of weeks? I was just
>>> starting to look into adding things into the beentry to hold
>>> information on the server side.
>>
>> Sure! I'll go ahead and hack up the checks and lucid stuff and get
>> back to you.
>
> Great! I'll finish fleshing out the basics of how to have this work
> server-side and once the checks and lucid stuff are in on the psql
> side, it should be pretty straight-forward to copy that same
> information into beentry alongside the SSL info, and expose it through
> pg_stat_get_activity() into a pg_stat_gss view.

When the mech is gss_mech_krb5 under MIT krb5:

psql (12devel)
GSSAPI encrypted connection (krb5 using aes256-cts-hmac-sha384-192)
Type "help" for help.

And the same under Heimdal:

psql (12devel)
GSSAPI encrypted connection (krb5 using aes256-cts-hmac-sha1-96)
Type "help" for help

If the mech weren't gss_krb5, or Lucid introspection failed, but we're a
SASL-aware mech (and using MIT):

psql (12devel)
GSSAPI encrypted connection (~256 bits)
Type "help" for help.

The third case (no lucid, no SASL SSF):

psql (12devel)
GSSAPI encrypted connection (unknown mechanism)
Type "help" for help.

Feel free to tweak these strings as needed.

I've also adjusted the layering somewhat and moved the actual printf()
call down into fe-secure-gssapi.c I don't know whether this model makes
more sense in the long run, but for PoC code it was marginally easier to
reason about.

Another thing I've been thinking about here is whether the SASL SSF
logic is useful. It'll only get invoked when the mechanism isn't
gss_mech_krb5, and only under MIT. SPNEGO (krb5), NTLM (gss-ntlmssp),
IAKERB (krb5), and EAP (moonshot) all don't support
GSS_C_SEC_CONTEXT_SASL_SSF; I actually couldn't come up with another
mechanism that does. I defer to you on whether to remove that, though.

I did some testing with Heimdal since we're using some extensions here,
and found out that the current build machinery doesn't support Heimdal.
(The configure.in detection logic only seems to work for MIT and
Solaris.) However, it's possible to explicitly pass in CFLAGS/LDFLAGS
and it worked prior to my changes, so I've preserved that behavior.

Finally, as this patch touches configure.in, configure needs to be
regenerated; I'm not sure what project policy is on when that happens
(and it produces rather a lot of churn on my machine).

Patch attached after the break; apply on top of -20.

Thanks,
--Robbie

Attachment Content-Type Size
Log-encryption-strength-in-libpq-GSSAPI-connections.patch text/x-diff 8.6 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-21 23:39:10
Message-ID: 20190221233910.GO6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> >> Sure! I'll go ahead and hack up the checks and lucid stuff and get
> >> back to you.
> >
> > Great! I'll finish fleshing out the basics of how to have this work
> > server-side and once the checks and lucid stuff are in on the psql
> > side, it should be pretty straight-forward to copy that same
> > information into beentry alongside the SSL info, and expose it through
> > pg_stat_get_activity() into a pg_stat_gss view.
>
> When the mech is gss_mech_krb5 under MIT krb5:
>
> psql (12devel)
> GSSAPI encrypted connection (krb5 using aes256-cts-hmac-sha384-192)
> Type "help" for help.
>
> And the same under Heimdal:
>
> psql (12devel)
> GSSAPI encrypted connection (krb5 using aes256-cts-hmac-sha1-96)
> Type "help" for help
>
> If the mech weren't gss_krb5, or Lucid introspection failed, but we're a
> SASL-aware mech (and using MIT):
>
> psql (12devel)
> GSSAPI encrypted connection (~256 bits)
> Type "help" for help.
>
> The third case (no lucid, no SASL SSF):
>
> psql (12devel)
> GSSAPI encrypted connection (unknown mechanism)
> Type "help" for help.
>
> Feel free to tweak these strings as needed.

That all looks fantastic! Do you see any reason to not say:

GSSAPI encrypted connection (SASL SSF: ~256 bits)

instead, since that's what we are technically reporting there?

> I've also adjusted the layering somewhat and moved the actual printf()
> call down into fe-secure-gssapi.c I don't know whether this model makes
> more sense in the long run, but for PoC code it was marginally easier to
> reason about.

No, I think we need to provide a way for libpq-using applications to get
at that information easily..

> Another thing I've been thinking about here is whether the SASL SSF
> logic is useful. It'll only get invoked when the mechanism isn't
> gss_mech_krb5, and only under MIT. SPNEGO (krb5), NTLM (gss-ntlmssp),
> IAKERB (krb5), and EAP (moonshot) all don't support
> GSS_C_SEC_CONTEXT_SASL_SSF; I actually couldn't come up with another
> mechanism that does. I defer to you on whether to remove that, though.

Oh, hmm, I see. Yeah, since there's no case where that could actually
end up being used today then perhaps it makes sense to remove it- it's
not a terribly good interface anyway since it doesn't provide the
actual encryption algorithm, I had just gone down that route because I
saw how to. The lucid stuff is much better. :)

> I did some testing with Heimdal since we're using some extensions here,
> and found out that the current build machinery doesn't support Heimdal.

Hah!

> (The configure.in detection logic only seems to work for MIT and
> Solaris.) However, it's possible to explicitly pass in CFLAGS/LDFLAGS
> and it worked prior to my changes, so I've preserved that behavior.

Alright. That seems like an independent change, if we decide to make
it easier for people to build with heimdal, but there hasn't been much
call for it, clearly.

> Finally, as this patch touches configure.in, configure needs to be
> regenerated; I'm not sure what project policy is on when that happens
> (and it produces rather a lot of churn on my machine).

There's some magic there due to vendor changes to autoconf, as I recall,
which is likely why you're seeing a lot of churn.

> Patch attached after the break; apply on top of -20.

Ok. I'm pretty amazed at how little code it was to do.. Is there
somewhere that these functions are publicly documented and how they can
be used from a GSSAPI handle is documented?

Thanks a lot for this work!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-22 20:37:24
Message-ID: jlgr2bza7az.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>>>
>>>> Sure! I'll go ahead and hack up the checks and lucid stuff and get
>>>> back to you.
>>>
>>> Great! I'll finish fleshing out the basics of how to have this work
>>> server-side and once the checks and lucid stuff are in on the psql
>>> side, it should be pretty straight-forward to copy that same
>>> information into beentry alongside the SSL info, and expose it
>>> through pg_stat_get_activity() into a pg_stat_gss view.
>>
>> When the mech is gss_mech_krb5 under MIT krb5:
>>
>> psql (12devel)
>> GSSAPI encrypted connection (krb5 using aes256-cts-hmac-sha384-192)
>> Type "help" for help.
>>
>> And the same under Heimdal:
>>
>> psql (12devel)
>> GSSAPI encrypted connection (krb5 using aes256-cts-hmac-sha1-96)
>> Type "help" for help
>>
>> If the mech weren't gss_krb5, or Lucid introspection failed, but we're a
>> SASL-aware mech (and using MIT):
>>
>> psql (12devel)
>> GSSAPI encrypted connection (~256 bits)
>> Type "help" for help.
>>
>> The third case (no lucid, no SASL SSF):
>>
>> psql (12devel)
>> GSSAPI encrypted connection (unknown mechanism)
>> Type "help" for help.
>>
>> Feel free to tweak these strings as needed.
>
> That all looks fantastic! Do you see any reason to not say:
>
> GSSAPI encrypted connection (SASL SSF: ~256 bits)
>
> instead, since that's what we are technically reporting there?

Nope, that'd be fine with me! (We'd probably want to get rid of the ~
in that case; I'd included it since SASL SSF is an approximate bit
measure, but 256 is the exact SSF.)

>> Another thing I've been thinking about here is whether the SASL SSF
>> logic is useful. It'll only get invoked when the mechanism isn't
>> gss_mech_krb5, and only under MIT. SPNEGO (krb5), NTLM
>> (gss-ntlmssp), IAKERB (krb5), and EAP (moonshot) all don't support
>> GSS_C_SEC_CONTEXT_SASL_SSF; I actually couldn't come up with another
>> mechanism that does. I defer to you on whether to remove that,
>> though.
>
> Oh, hmm, I see. Yeah, since there's no case where that could actually
> end up being used today then perhaps it makes sense to remove it- it's
> not a terribly good interface anyway since it doesn't provide the
> actual encryption algorithm, I had just gone down that route because I
> saw how to. The lucid stuff is much better. :)
>
>> I've also adjusted the layering somewhat and moved the actual
>> printf() call down into fe-secure-gssapi.c I don't know whether this
>> model makes more sense in the long run, but for PoC code it was
>> marginally easier to reason about.
>
> No, I think we need to provide a way for libpq-using applications to
> get at that information easily..

Well, it's easier if there's only one type of thing (string) that can be
returned at least. I imagine the interface there has to be pass
buffer-and-size into the function in fe-secure-gssapi.c then? Do you
want me to make that change, or would you prefer to do it as part of the
server logging logic?

>> Patch attached after the break; apply on top of -20.
>
> Ok. I'm pretty amazed at how little code it was to do..

The autotools part took the longest :)

> Is there somewhere that these functions are publicly documented and
> how they can be used from a GSSAPI handle is documented?

Not in the way you're hoping for, I suspect. This interface is only
intended for consumption by NFS - which needs to pass contexts in and
out of the kernel. Unlike GSSAPI, Kerberos5 interfaces aren't
standardized at all - parity between MIT and Heimdal is pretty low on
the krb5_*().

I was just referencing MIT's header files:
https://github.com/krb5/krb5/blob/master/src/lib/gssapi/krb5/gssapi_krb5.h#L229
(with the goal in mind of hitting krb5_enctype_to_name())
https://github.com/krb5/krb5/blob/master/src/include/krb5/krb5.hin#L6284-L6302

(Heimdal doesn't have any documentation/example code, but it works the
same way for lucid stuff; I had to look at the source to see how its
variant of krb5_enctype_to_string() worked.)

Thanks,
--Robbie


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-23 09:19:53
Message-ID: 5ec3f734-810e-36e0-030f-af92efe135da@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I don't know much about GSSAPI, but from what I can tell, this seems an
attractive feature, and the implementation is compact enough. I have
done a bit of work on the internal SSL API refactoring, so I have some
thoughts on this patch.

Looking at the file structure, we would have

be-secure.c
be-secure-openssl.c
be-secure-[othersslimpl].c
be-secure-gssapi.c
be-secure-common.c

This implies a code structure that isn't really there.
be-secure-common.c is used by SSL implementations but not by the GSSAPI
implementation.

Perhaps we should rename be-secure-openssl.c to be-ssl-openssl.c and
be-secure-common.c to be-ssl-common.c.

Or maybe we avoid that, and you rename be-secure-gssapi.c to just
be-gssapi.c and also combine that with the contents of be-gssapi-common.c.

(Or maybe both.)

(And similarly in libpq.)

About pg_hba.conf: The "hostgss" keyword seems a bit confusing. It only
applies to encrypted gss-using connections, not all of them. Maybe
"hostgssenc" or "hostgsswrap"?

I don't see any tests in the patch. We have a Kerberos test suite at
src/test/kerberos/ and an SSL test suite at src/test/ssl/. You can get
some ideas there.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-02-23 16:27:51
Message-ID: 20190223162751.GO6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> I don't know much about GSSAPI, but from what I can tell, this seems an
> attractive feature, and the implementation is compact enough. I have
> done a bit of work on the internal SSL API refactoring, so I have some
> thoughts on this patch.
>
> Looking at the file structure, we would have
>
> be-secure.c
> be-secure-openssl.c
> be-secure-[othersslimpl].c
> be-secure-gssapi.c
> be-secure-common.c
>
> This implies a code structure that isn't really there.
> be-secure-common.c is used by SSL implementations but not by the GSSAPI
> implementation.

be-secure-common.c seems very clearly mis-named, I mean, look at the
comment at the top of the file:

* common implementation-independent SSL support code

Seems we've been conflating SSL and "Secure" and we should probably fix
that.

What I also really don't like is that "secure_read()" is really only
*maybe* secure. be-secure.c is really just an IO-abstraction layer that
lets other things hook in and implement the read/write themselves.

> Perhaps we should rename be-secure-openssl.c to be-ssl-openssl.c and
> be-secure-common.c to be-ssl-common.c.

This might be overly pedantic, but what we do in other parts of the tree
is use these things called directories..

I do think we need to rename be-secure-common since it's just flat out
wrong as-is, but that's independent of the GSSAPI encryption work,
really.

> Or maybe we avoid that, and you rename be-secure-gssapi.c to just
> be-gssapi.c and also combine that with the contents of be-gssapi-common.c.

I don't know why we would need to, or want to, combine
be-secure-gssapi.c and be-gssapi-common.c, they do have different roles
in that be-gssapi-common.c is used even if you aren't doing encryption,
while bs-secure-gssapi.c is specifically for handling the encryption
side of things.

Then again, be-gssapi-common.c does currently only have the one function
in it, and it's not like there's an option to compile for *just* GSS
authentication (and not encryption), or at least, I don't think that
would be a useful option to have.. Robbie?

> (And similarly in libpq.)

I do agree that we should try to keep the frontend and backend code
structures similar in this area, that seems to make sense.

> About pg_hba.conf: The "hostgss" keyword seems a bit confusing. It only
> applies to encrypted gss-using connections, not all of them. Maybe
> "hostgssenc" or "hostgsswrap"?

Not quite sure what you mean here, but 'hostgss' seems to be quite well
in-line with what we do for SSL... as in, we have 'hostssl', we don't
say 'hostsslenc'. I feel like I'm just not understanding what you mean
by "not all of them".

> I don't see any tests in the patch. We have a Kerberos test suite at
> src/test/kerberos/ and an SSL test suite at src/test/ssl/. You can get
> some ideas there.

Yeah, I was going to comment on that as well. We definitely should
implement tests around this.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-03-06 03:55:23
Message-ID: jlg4l8gpsgk.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
>
>> Or maybe we avoid that, and you rename be-secure-gssapi.c to just
>> be-gssapi.c and also combine that with the contents of
>> be-gssapi-common.c.
>
> I don't know why we would need to, or want to, combine
> be-secure-gssapi.c and be-gssapi-common.c, they do have different
> roles in that be-gssapi-common.c is used even if you aren't doing
> encryption, while bs-secure-gssapi.c is specifically for handling the
> encryption side of things.
>
> Then again, be-gssapi-common.c does currently only have the one
> function in it, and it's not like there's an option to compile for
> *just* GSS authentication (and not encryption), or at least, I don't
> think that would be a useful option to have.. Robbie?

Yeah, I think I'm opposed to making that an option.

Worth pointing out here: up until v6, I had this structured differently,
with all the GSSAPI code in fe-gssapi.c and be-gssapi.c. The current
separation was suggested by Michael Paquier for ease of reading and to
keep the code churn down.

>> (And similarly in libpq.)
>
> I do agree that we should try to keep the frontend and backend code
> structures similar in this area, that seems to make sense.

Well, I don't know if it's an argument in either direction, but: on the
frontend we have about twice as much shared code in fe-gssapi-common.c
(pg_GSS_have_ccache() and pg_GSS_load_servicename()).

>> I don't see any tests in the patch. We have a Kerberos test suite at
>> src/test/kerberos/ and an SSL test suite at src/test/ssl/. You can
>> get some ideas there.
>
> Yeah, I was going to comment on that as well. We definitely should
> implement tests around this.

Attached. Please note that I don't really speak perl. There's a pile
of duplicated code in 002_enc.pl that probably should be shared between
the two. (It would also I think be possible for 001_auth.pl to set up
the KDC and for 002_enc.pl to then use it.)

Thanks,
--Robbie

Attachment Content-Type Size
Add-tests-for-GSSAPI-krb5-encryption.patch text/x-diff 5.6 KB

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-03-16 10:21:10
Message-ID: 20190316102110.GU6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings!

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> >> Or maybe we avoid that, and you rename be-secure-gssapi.c to just
> >> be-gssapi.c and also combine that with the contents of
> >> be-gssapi-common.c.
> >
> > I don't know why we would need to, or want to, combine
> > be-secure-gssapi.c and be-gssapi-common.c, they do have different
> > roles in that be-gssapi-common.c is used even if you aren't doing
> > encryption, while bs-secure-gssapi.c is specifically for handling the
> > encryption side of things.
> >
> > Then again, be-gssapi-common.c does currently only have the one
> > function in it, and it's not like there's an option to compile for
> > *just* GSS authentication (and not encryption), or at least, I don't
> > think that would be a useful option to have.. Robbie?
>
> Yeah, I think I'm opposed to making that an option.

Yeah, I tend to agree, seems silly.

> Worth pointing out here: up until v6, I had this structured differently,
> with all the GSSAPI code in fe-gssapi.c and be-gssapi.c. The current
> separation was suggested by Michael Paquier for ease of reading and to
> keep the code churn down.

I'm still a bit on the fence myself regarding the filenames and where
things exist today. I do agree that it might make sense to move things
around to make the code structure clearer but I also think that doesn't
necessairly have to be done at the same time as this patch.

> >> (And similarly in libpq.)
> >
> > I do agree that we should try to keep the frontend and backend code
> > structures similar in this area, that seems to make sense.
>
> Well, I don't know if it's an argument in either direction, but: on the
> frontend we have about twice as much shared code in fe-gssapi-common.c
> (pg_GSS_have_ccache() and pg_GSS_load_servicename()).

Yeah, that's an interesting point, and I do wonder if we will actually
end up having code that's shared between the frontend and backend
eventually (if we can figure out how to pull out the encryption
algorithm info, for example).

> >> I don't see any tests in the patch. We have a Kerberos test suite at
> >> src/test/kerberos/ and an SSL test suite at src/test/ssl/. You can
> >> get some ideas there.
> >
> > Yeah, I was going to comment on that as well. We definitely should
> > implement tests around this.
>
> Attached. Please note that I don't really speak perl. There's a pile
> of duplicated code in 002_enc.pl that probably should be shared between
> the two. (It would also I think be possible for 001_auth.pl to set up
> the KDC and for 002_enc.pl to then use it.)

I don't think the code duplication between the tests is really all that
much of an issue, though I wouldn't complain if someone wanted to work
on improving that situation. Thanks a lot for adding those test though!

One of the things that I really didn't care for in this patch was the
use of the string buffers, without any real checks (except for "oh, you
tried to allocated over 1G"...) to make sure that the other side of the
connection wasn't feeding us ridiculous packets, and with the resizing
of the buffers, etc, that really shouldn't be necessary. After chatting
with Robbie about these concerns while reading through the code, we
agreed that we should be able to use fixed buffer sizes and use the
quite helpful gss_wrap_size_limit() to figure out how much data we can
encrypt without going over our fixed buffer size. As Robbie didn't have
time to implement those changes this past week, I did so, and added a
bunch more comments and such too, and have now gone through and done
more testing. Robbie has said that he should have time this upcoming
week to review the changes that I made, and I'm planning to go back and
review other parts of the patch more closely now as well.

Note that there's an issue with exporting the context to get the
encryption algorithm used that I've asked Robbie to look into, so that's
no longer done and instead we just print that the connection is
encrypted, if it is. If we can't figure out a way to make that work
then obviously I'll pull out that code, and if we can get it to work
then I'll update it to be done through libpq properly, as I had
suggested earlier. That's really more of a nice to have in any case
though, so I may just exclude it for now anyway if it ends up adding any
complications.

So, please find attached a new version, which also includes the tests
and the other bits that Robbie had sent independent patches for.

Thanks!

Stephen

Attachment Content-Type Size
v21-libpq-GSSAPI-encryption-support.patch text/x-diff 106.0 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-03-22 20:26:32
Message-ID: jlgftre3bbb.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> One of the things that I really didn't care for in this patch was the
> use of the string buffers, without any real checks (except for "oh,
> you tried to allocated over 1G"...) to make sure that the other side
> of the connection wasn't feeding us ridiculous packets, and with the
> resizing of the buffers, etc, that really shouldn't be necessary.
> After chatting with Robbie about these concerns while reading through
> the code, we agreed that we should be able to use fixed buffer sizes
> and use the quite helpful gss_wrap_size_limit() to figure out how much
> data we can encrypt without going over our fixed buffer size. As
> Robbie didn't have time to implement those changes this past week, I
> did so, and added a bunch more comments and such too, and have now
> gone through and done more testing. Robbie has said that he should
> have time this upcoming week to review the changes that I made, and
> I'm planning to go back and review other parts of the patch more
> closely now as well.

In general this looks good - there are a couple minor comments inline,
but it's fine.

I wanted to note a couple things about this approach. It now uses one
more buffer than before (in contrast to the previous approach, which
reused a buffer for received data that was encrypted and decrypted).
Since these are static fixed size buffers, this increases the total
steady-state memory usage by 16k as opposed to re-using the buffer.
This may be fine; I don't know how tight RAM is here.

> Note that there's an issue with exporting the context to get the
> encryption algorithm used that I've asked Robbie to look into, so
> that's no longer done and instead we just print that the connection is
> encrypted, if it is. If we can't figure out a way to make that work
> then obviously I'll pull out that code, and if we can get it to work
> then I'll update it to be done through libpq properly, as I had
> suggested earlier. That's really more of a nice to have in any case
> though, so I may just exclude it for now anyway if it ends up adding
> any complications.

Correct. Unfortunately I'd overlooked that the lucid interface won't
meet our needs (destroys the context). So the two options here are:
SASL SSF (and I'll separately push more mechs to add support for that),
or nothing at all.

If you want a patch for that I can make one, but I think there was code
already... just needed a ./configure check program for whether the OID
is defined.

> +ssize_t
> +be_gssapi_write(Port *port, void *ptr, size_t len)
> +{
> + size_t bytes_to_encrypt = len;
> + size_t bytes_encrypted = 0;
> +
> + /*
> + * Loop through encrypting data and sending it out until
> + * secure_raw_write() complains (which would likely mean that the socket
> + * is non-blocking and the requested send() would block, or there was some
> + * kind of actual error) and then return.
> + */
> + while (bytes_to_encrypt || PqGSSSendPointer)
> + {

I guess it's not a view everyone will share, but I think this block is
too long. Maybe a helper function around secure_raw_write() would help?
(The check-and-send part at the start.)

I have similar nits about the other functions that don't fit on my
(86-line high) screen, though I guess a lot of this is due to project
style using a lot of vertical space.

> + if (GSS_ERROR(major))
> + pg_GSS_error(FATAL, gettext_noop("GSSAPI context error"),

I'd prefer this to be a different error message than the init/accept
errors - maybe something like "GSSAPI size check error"?

> + if (GSS_ERROR(major))
> + pg_GSS_error(libpq_gettext("GSSAPI context error"), conn,

Same here.

Again, these are nits, and I think I'm okay with the changes.

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: [PATCH v22] GSSAPI encryption support
Date: 2019-03-30 14:24:04
Message-ID: 20190330142404.GO6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>
> > One of the things that I really didn't care for in this patch was the
> > use of the string buffers, without any real checks (except for "oh,
> > you tried to allocated over 1G"...) to make sure that the other side
> > of the connection wasn't feeding us ridiculous packets, and with the
> > resizing of the buffers, etc, that really shouldn't be necessary.
> > After chatting with Robbie about these concerns while reading through
> > the code, we agreed that we should be able to use fixed buffer sizes
> > and use the quite helpful gss_wrap_size_limit() to figure out how much
> > data we can encrypt without going over our fixed buffer size. As
> > Robbie didn't have time to implement those changes this past week, I
> > did so, and added a bunch more comments and such too, and have now
> > gone through and done more testing. Robbie has said that he should
> > have time this upcoming week to review the changes that I made, and
> > I'm planning to go back and review other parts of the patch more
> > closely now as well.
>
> In general this looks good - there are a couple minor comments inline,
> but it's fine.

Thanks for reviewing!

> I wanted to note a couple things about this approach. It now uses one
> more buffer than before (in contrast to the previous approach, which
> reused a buffer for received data that was encrypted and decrypted).

Yeah, I don't see that as too much of an issue and it certainly seems
cleaner and simpler to reason about to me, which seems worth the modest
additional buffer cost. That's certainly something we could change if
others feel differently.

> Since these are static fixed size buffers, this increases the total
> steady-state memory usage by 16k as opposed to re-using the buffer.
> This may be fine; I don't know how tight RAM is here.

It seems unlikely to be an issue to me- and I would contend that the
prior implementation didn't actually take any steps to prevent the other
side from sending packets of nearly arbitrary size (up to 1G), so while
the steady-state memory usage of the prior implementation was less when
everyone was playing nicely, it could have certainly been abused. I'm a
lot happier having an explicit cap on how much memory will be used, even
if that cap is a bit higher.

> > Note that there's an issue with exporting the context to get the
> > encryption algorithm used that I've asked Robbie to look into, so
> > that's no longer done and instead we just print that the connection is
> > encrypted, if it is. If we can't figure out a way to make that work
> > then obviously I'll pull out that code, and if we can get it to work
> > then I'll update it to be done through libpq properly, as I had
> > suggested earlier. That's really more of a nice to have in any case
> > though, so I may just exclude it for now anyway if it ends up adding
> > any complications.
>
> Correct. Unfortunately I'd overlooked that the lucid interface won't
> meet our needs (destroys the context). So the two options here are:
> SASL SSF (and I'll separately push more mechs to add support for that),
> or nothing at all.

I went ahead and ripped out all of that, including the SASL SSF (which
really didn't seem like it added all that much... but if others feel
like it's useful, then we can add it back in later). That also let me
get rid of the configure/configure.in changes, which was nice. I did
add in a simple pg_stat_gssapi view, modeled on pg_stat_ssl, so that you
can check server-side if GSSAPI was used for authentication and/or
encryption, and what principal was used if GSSAPI was used for
authentication.

I also changed the libpq function to return a boolean to indicate if
encryption was used or not; I don't think it's appropriate to have a
libpq function that will just print stuff to stdout, that should be the
client program's job, so that's handled by psql now.

There were some other bits that had been forgotten to get removed from
when I moved away from using the string buffers, but I went through and
I'm pretty confident that I've cleaned all of that out now.

> If you want a patch for that I can make one, but I think there was code
> already... just needed a ./configure check program for whether the OID
> is defined.
>
> > +ssize_t
> > +be_gssapi_write(Port *port, void *ptr, size_t len)
> > +{
> > + size_t bytes_to_encrypt = len;
> > + size_t bytes_encrypted = 0;
> > +
> > + /*
> > + * Loop through encrypting data and sending it out until
> > + * secure_raw_write() complains (which would likely mean that the socket
> > + * is non-blocking and the requested send() would block, or there was some
> > + * kind of actual error) and then return.
> > + */
> > + while (bytes_to_encrypt || PqGSSSendPointer)
> > + {
>
> I guess it's not a view everyone will share, but I think this block is
> too long. Maybe a helper function around secure_raw_write() would help?
> (The check-and-send part at the start.)

I looked for a way to add a wrapper around secure_raw_write() that would
actually be useful here but honestly, it really didn't seem like it'd
have done anything but make the code unnecessairly complicated. I mean,
there's literally only one call to secure_raw_write() inside of
be_gssapi_write()..

> I have similar nits about the other functions that don't fit on my
> (86-line high) screen, though I guess a lot of this is due to project
> style using a lot of vertical space.

So, I did think about what you wrote here and we did have multiple calls
to be_gssapi_read/write (and similar on the frontend) inside of the
secure_open_gssapi() / pqsecure_open_gss() calls, with each call
location having to handle the various results from read/write. I went
ahead and made wrappers and used them instead, simplifying those
functions and reducing the amount of nearly copy/paste code for handling
return values from read/write. Those wrappers don't work for the
actual secure read/write functions though, since those typically are
just able to pass the actual read/write() return back up to the caller,
unlike the open calls.

> > + if (GSS_ERROR(major))
> > + pg_GSS_error(FATAL, gettext_noop("GSSAPI context error"),
>
> I'd prefer this to be a different error message than the init/accept
> errors - maybe something like "GSSAPI size check error"?
>
> > + if (GSS_ERROR(major))
> > + pg_GSS_error(libpq_gettext("GSSAPI context error"), conn,
>
> Same here.

Ok, I've fixed those.

> Again, these are nits, and I think I'm okay with the changes.

Great, thanks again for reviewing!

Updated patch attached, if you could take another look through it,
that'd be great.

Thanks,

Stephen

Attachment Content-Type Size
v22-libpq-GSSAPI-encryption-support.patch text/x-diff 117.1 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v22] GSSAPI encryption support
Date: 2019-04-01 15:13:24
Message-ID: jlgv9zx4v3f.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>
>> I wanted to note a couple things about this approach. It now uses
>> one more buffer than before (in contrast to the previous approach,
>> which reused a buffer for received data that was encrypted and
>> decrypted).
>
> Yeah, I don't see that as too much of an issue and it certainly seems
> cleaner and simpler to reason about to me, which seems worth the
> modest additional buffer cost. That's certainly something we could
> change if others feel differently.
>
>> Since these are static fixed size buffers, this increases the total
>> steady-state memory usage by 16k as opposed to re-using the buffer.
>> This may be fine; I don't know how tight RAM is here.
>
> It seems unlikely to be an issue to me- and I would contend that the
> prior implementation didn't actually take any steps to prevent the
> other side from sending packets of nearly arbitrary size (up to 1G),
> so while the steady-state memory usage of the prior implementation was
> less when everyone was playing nicely, it could have certainly been
> abused. I'm a lot happier having an explicit cap on how much memory
> will be used, even if that cap is a bit higher.

Yeah, that's definitely a fair point. We could combine the two
approaches, but I don't really see a reason to if it's unlikely to be an
issue - as you say, this is more readable. It can always be a follow-on
if needed.

> I did add in a simple pg_stat_gssapi view, modeled on pg_stat_ssl, so
> that you can check server-side if GSSAPI was used for authentication
> and/or encryption, and what principal was used if GSSAPI was used for
> authentication.

Good idea.

>> Again, these are nits, and I think I'm okay with the changes.
>
> Great, thanks again for reviewing!
>
> Updated patch attached, if you could take another look through it,
> that'd be great.

I'm happy with this! Appreciate you exploring my concerns.

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v22] GSSAPI encryption support
Date: 2019-04-02 16:41:24
Message-ID: 20190402164124.GZ6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> >> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> >>
> >> I wanted to note a couple things about this approach. It now uses
> >> one more buffer than before (in contrast to the previous approach,
> >> which reused a buffer for received data that was encrypted and
> >> decrypted).
> >
> > Yeah, I don't see that as too much of an issue and it certainly seems
> > cleaner and simpler to reason about to me, which seems worth the
> > modest additional buffer cost. That's certainly something we could
> > change if others feel differently.
> >
> >> Since these are static fixed size buffers, this increases the total
> >> steady-state memory usage by 16k as opposed to re-using the buffer.
> >> This may be fine; I don't know how tight RAM is here.
> >
> > It seems unlikely to be an issue to me- and I would contend that the
> > prior implementation didn't actually take any steps to prevent the
> > other side from sending packets of nearly arbitrary size (up to 1G),
> > so while the steady-state memory usage of the prior implementation was
> > less when everyone was playing nicely, it could have certainly been
> > abused. I'm a lot happier having an explicit cap on how much memory
> > will be used, even if that cap is a bit higher.
>
> Yeah, that's definitely a fair point. We could combine the two
> approaches, but I don't really see a reason to if it's unlikely to be an
> issue - as you say, this is more readable. It can always be a follow-on
> if needed.

Agreed, we could do that later if it seems like it would be helpful.

> > I did add in a simple pg_stat_gssapi view, modeled on pg_stat_ssl, so
> > that you can check server-side if GSSAPI was used for authentication
> > and/or encryption, and what principal was used if GSSAPI was used for
> > authentication.
>
> Good idea.

Thanks. :) I definitely like being able to see from the backend side of
things when a connection is encrypted or not, and being able to see the
principal used for authentication is really nice too.

> >> Again, these are nits, and I think I'm okay with the changes.
> >
> > Great, thanks again for reviewing!
> >
> > Updated patch attached, if you could take another look through it,
> > that'd be great.
>
> I'm happy with this! Appreciate you exploring my concerns.

Fantastic, thanks so much for working on this over the years! Unless
there's any further comments, I'm going to push this tomorrow.

Thanks again!

Stephen


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org, Nico Williams <nico(at)cryptonector(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-02 22:10:28
Message-ID: 1f799b02-d766-0328-45d6-73e5674d0bc2@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-02-23 17:27, Stephen Frost wrote:
>> About pg_hba.conf: The "hostgss" keyword seems a bit confusing. It only
>> applies to encrypted gss-using connections, not all of them. Maybe
>> "hostgssenc" or "hostgsswrap"?
> Not quite sure what you mean here, but 'hostgss' seems to be quite well
> in-line with what we do for SSL... as in, we have 'hostssl', we don't
> say 'hostsslenc'. I feel like I'm just not understanding what you mean
> by "not all of them".

Reading the latest patch, I think this is still a bit confusing.
Consider an entry like

hostgss all all 0.0.0.0/0 gss

The "hostgss" part means, the connection is GSS-*encrypted*. The "gss"
entry in the last column means use gss for *authentication*. But didn't
"hostgss" already imply that? No. I understand what's going on, but it
seems quite confusing. They both just say "gss"; you have to know a lot
about the nuances of pg_hba.conf processing to get that.

If you have line like

hostgss all all 0.0.0.0/0 md5

it is not obvious that this means, if GSS-encrypted, use md5. It could
just as well mean, if GSS-authenticated, use md5.

The analogy with SSL is such that we use "hostssl" for connections using
SSL encryption and "cert" for the authentication method. So there we
use two different words for two different aspects of SSL.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-02 22:18:33
Message-ID: CAOuzzgprZ7-gYkzwkPzMOPka62irppKpXNm219q7a_8Fu33TLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

On Tue, Apr 2, 2019 at 18:10 Peter Eisentraut <
peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:

> On 2019-02-23 17:27, Stephen Frost wrote:
> >> About pg_hba.conf: The "hostgss" keyword seems a bit confusing. It only
> >> applies to encrypted gss-using connections, not all of them. Maybe
> >> "hostgssenc" or "hostgsswrap"?
> > Not quite sure what you mean here, but 'hostgss' seems to be quite well
> > in-line with what we do for SSL... as in, we have 'hostssl', we don't
> > say 'hostsslenc'. I feel like I'm just not understanding what you mean
> > by "not all of them".
>
> Reading the latest patch, I think this is still a bit confusing.
> Consider an entry like
>
> hostgss all all 0.0.0.0/0 gss
>
> The "hostgss" part means, the connection is GSS-*encrypted*. The "gss"
> entry in the last column means use gss for *authentication*. But didn't
> "hostgss" already imply that? No. I understand what's going on, but it
> seems quite confusing. They both just say "gss"; you have to know a lot
> about the nuances of pg_hba.conf processing to get that.
>
> If you have line like
>
> hostgss all all 0.0.0.0/0 md5
>
> it is not obvious that this means, if GSS-encrypted, use md5. It could
> just as well mean, if GSS-authenticated, use md5.
>
> The analogy with SSL is such that we use "hostssl" for connections using
> SSL encryption and "cert" for the authentication method. So there we
> use two different words for two different aspects of SSL.

I don’t view it as confusing, but I’ll change it to hostgssenc as was
suggested earlier to address that concern. It’s a bit wordy but if it
helps reduce confusion then that’s a good thing.

Thanks,

Stephen

>


From: Joe Conway <mail(at)joeconway(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-02 22:22:11
Message-ID: 500b1be7-d0aa-96a2-9982-d748609faff5@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 4/2/19 6:18 PM, Stephen Frost wrote:
> Greetings,
>
> On Tue, Apr 2, 2019 at 18:10 Peter Eisentraut
> <peter(dot)eisentraut(at)2ndquadrant(dot)com
> <mailto:peter(dot)eisentraut(at)2ndquadrant(dot)com>> wrote:
>
> On 2019-02-23 17:27, Stephen Frost wrote:
> >> About pg_hba.conf: The "hostgss" keyword seems a bit confusing. 
> It only
> >> applies to encrypted gss-using connections, not all of them.  Maybe
> >> "hostgssenc" or "hostgsswrap"?
> > Not quite sure what you mean here, but 'hostgss' seems to be quite
> well
> > in-line with what we do for SSL...  as in, we have 'hostssl', we don't
> > say 'hostsslenc'.  I feel like I'm just not understanding what you
> mean
> > by "not all of them".
>
> Reading the latest patch, I think this is still a bit confusing.
> Consider an entry like
>
>     hostgss all             all             0.0.0.0/0
> <http://0.0.0.0/0>               gss
>
> The "hostgss" part means, the connection is GSS-*encrypted*.  The "gss"
> entry in the last column means use gss for *authentication*.  But didn't
> "hostgss" already imply that?  No.  I understand what's going on, but it
> seems quite confusing.  They both just say "gss"; you have to know a lot
> about the nuances of pg_hba.conf processing to get that.
>
> If you have line like
>
>     hostgss all             all             0.0.0.0/0
> <http://0.0.0.0/0>               md5
>
> it is not obvious that this means, if GSS-encrypted, use md5.  It could
> just as well mean, if GSS-authenticated, use md5.
>
> The analogy with SSL is such that we use "hostssl" for connections using
> SSL encryption and "cert" for the authentication method.  So there we
> use two different words for two different aspects of SSL.
>
>
> I don’t view it as confusing, but I’ll change it to hostgssenc as was
> suggested earlier to address that concern.  It’s a bit wordy but if it
> helps reduce confusion then that’s a good thing.

Personally I don't find it as confusing as is either, and I find hostgss
to be a good analog of hostssl. On the other hand hostgssenc is long and
unintuitive. So +1 for leaving as is and -1 one for changing it IMHO.

Joe
--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-03 06:49:25
Message-ID: CABUevEyuNNJv=19foa=ycTfTfBUYOEwM8_Uss5OVKrwBAy+Btw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 3, 2019 at 12:22 AM Joe Conway <mail(at)joeconway(dot)com> wrote:

> On 4/2/19 6:18 PM, Stephen Frost wrote:
> > Greetings,
> >
> > On Tue, Apr 2, 2019 at 18:10 Peter Eisentraut
> > <peter(dot)eisentraut(at)2ndquadrant(dot)com
> > <mailto:peter(dot)eisentraut(at)2ndquadrant(dot)com>> wrote:
> >
> > On 2019-02-23 17:27, Stephen Frost wrote:
> > >> About pg_hba.conf: The "hostgss" keyword seems a bit confusing.
> > It only
> > >> applies to encrypted gss-using connections, not all of them.
> Maybe
> > >> "hostgssenc" or "hostgsswrap"?
> > > Not quite sure what you mean here, but 'hostgss' seems to be quite
> > well
> > > in-line with what we do for SSL... as in, we have 'hostssl', we
> don't
> > > say 'hostsslenc'. I feel like I'm just not understanding what you
> > mean
> > > by "not all of them".
> >
> > Reading the latest patch, I think this is still a bit confusing.
> > Consider an entry like
> >
> > hostgss all all 0.0.0.0/0
> > <http://0.0.0.0/0> gss
> >
> > The "hostgss" part means, the connection is GSS-*encrypted*. The
> "gss"
> > entry in the last column means use gss for *authentication*. But
> didn't
> > "hostgss" already imply that? No. I understand what's going on,
> but it
> > seems quite confusing. They both just say "gss"; you have to know a
> lot
> > about the nuances of pg_hba.conf processing to get that.
> >
> > If you have line like
> >
> > hostgss all all 0.0.0.0/0
> > <http://0.0.0.0/0> md5
> >
> > it is not obvious that this means, if GSS-encrypted, use md5. It
> could
> > just as well mean, if GSS-authenticated, use md5.
> >
> > The analogy with SSL is such that we use "hostssl" for connections
> using
> > SSL encryption and "cert" for the authentication method. So there we
> > use two different words for two different aspects of SSL.
> >
> >
> > I don’t view it as confusing, but I’ll change it to hostgssenc as was
> > suggested earlier to address that concern. It’s a bit wordy but if it
> > helps reduce confusion then that’s a good thing.
>
> Personally I don't find it as confusing as is either, and I find hostgss
> to be a good analog of hostssl. On the other hand hostgssenc is long and
> unintuitive. So +1 for leaving as is and -1 one for changing it IMHO.
>

I think for those who are well versed in pg_hba (and maybe gss as well),
it's not confusing. That includes me.

However, for a new user, I can definitely see how it can be considered
confusing. And confusion in *security configuration* is always a bad idea,
even if it's just potential.

Thus +1 on changing it.

If it was on the table it might have been better to keep hostgss and change
the authentication method to gssauth or something, but that ship sailed
*years* ago.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/>
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-03 14:43:33
Message-ID: 20190403144332.GD6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Magnus Hagander (magnus(at)hagander(dot)net) wrote:
> On Wed, Apr 3, 2019 at 12:22 AM Joe Conway <mail(at)joeconway(dot)com> wrote:
> > On 4/2/19 6:18 PM, Stephen Frost wrote:
> > > On Tue, Apr 2, 2019 at 18:10 Peter Eisentraut
> > > <peter(dot)eisentraut(at)2ndquadrant(dot)com
> > > <mailto:peter(dot)eisentraut(at)2ndquadrant(dot)com>> wrote:
> > >
> > > On 2019-02-23 17:27, Stephen Frost wrote:
> > > >> About pg_hba.conf: The "hostgss" keyword seems a bit confusing.
> > > It only
> > > >> applies to encrypted gss-using connections, not all of them.
> > Maybe
> > > >> "hostgssenc" or "hostgsswrap"?
> > > > Not quite sure what you mean here, but 'hostgss' seems to be quite
> > > well
> > > > in-line with what we do for SSL... as in, we have 'hostssl', we
> > don't
> > > > say 'hostsslenc'. I feel like I'm just not understanding what you
> > > mean
> > > > by "not all of them".
> > >
> > > Reading the latest patch, I think this is still a bit confusing.
> > > Consider an entry like
> > >
> > > hostgss all all 0.0.0.0/0
> > > <http://0.0.0.0/0> gss
> > >
> > > The "hostgss" part means, the connection is GSS-*encrypted*. The
> > "gss"
> > > entry in the last column means use gss for *authentication*. But
> > didn't
> > > "hostgss" already imply that? No. I understand what's going on,
> > but it
> > > seems quite confusing. They both just say "gss"; you have to know a
> > lot
> > > about the nuances of pg_hba.conf processing to get that.
> > >
> > > If you have line like
> > >
> > > hostgss all all 0.0.0.0/0
> > > <http://0.0.0.0/0> md5
> > >
> > > it is not obvious that this means, if GSS-encrypted, use md5. It
> > could
> > > just as well mean, if GSS-authenticated, use md5.
> > >
> > > The analogy with SSL is such that we use "hostssl" for connections
> > using
> > > SSL encryption and "cert" for the authentication method. So there we
> > > use two different words for two different aspects of SSL.
> > >
> > >
> > > I don’t view it as confusing, but I’ll change it to hostgssenc as was
> > > suggested earlier to address that concern. It’s a bit wordy but if it
> > > helps reduce confusion then that’s a good thing.
> >
> > Personally I don't find it as confusing as is either, and I find hostgss
> > to be a good analog of hostssl. On the other hand hostgssenc is long and
> > unintuitive. So +1 for leaving as is and -1 one for changing it IMHO.
>
> I think for those who are well versed in pg_hba (and maybe gss as well),
> it's not confusing. That includes me.
>
> However, for a new user, I can definitely see how it can be considered
> confusing. And confusion in *security configuration* is always a bad idea,
> even if it's just potential.
>
> Thus +1 on changing it.

Alright, I've made that change, and also changed "gssmode" to be
"gssencmode" to be both consistent and also clearer (that, imv anyway,
is actually a much better reason to go to using 'gssenc' instead of just
'gss' for this, since "gssmode" could be thought of as being related to
GSS authentication rather than being for GSS encryption).

> If it was on the table it might have been better to keep hostgss and change
> the authentication method to gssauth or something, but that ship sailed
> *years* ago.

Agreed, we certainly can't change that now.

Updated patch attached with the host[no]gss -> host[no]gssenc and
gssmode -> gssencmode changes, along with some other minor improvements.
I'll push this in a few hours unless there's anything else.

Thanks!

Stephen

Attachment Content-Type Size
v23-libpq-GSSAPI-encryption-support.patch text/x-diff 117.1 KB

From: Andres Freund <andres(at)anarazel(dot)de>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-03 20:01:14
Message-ID: 20190403200114.drqcvm77yp3r7lyd@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

On 2019-04-03 10:43:33 -0400, Stephen Frost wrote:
> I'll push this in a few hours unless there's anything else.

The CF entry for this is still open - is there any work missing? Just
trying to do some triage...

https://commitfest.postgresql.org/22/1647/

- Andres


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-03 20:07:39
Message-ID: CAOuzzgrCuZHfwoJ4L7Y7hibBNje59e+KmVvCR8HdmOY7kBvj0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

On Wed, Apr 3, 2019 at 16:01 Andres Freund <andres(at)anarazel(dot)de> wrote:

> Hi,
>
> On 2019-04-03 10:43:33 -0400, Stephen Frost wrote:
> > I'll push this in a few hours unless there's anything else.
>
> The CF entry for this is still open - is there any work missing? Just
> trying to do some triage...
>
> https://commitfest.postgresql.org/22/1647/

No, I was just waiting to make sure the buildfarm was happy, which it seems
to be. I can take care of the entry in 30m or so, or if you’d like to
close it out, that would be fine too.

Thanks!

Stephen

> <https://commitfest.postgresql.org/22/1647/>

<https://commitfest.postgresql.org/22/1647/>


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Andres Freund <andres(at)anarazel(dot)de>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-03 21:47:46
Message-ID: jlgr2aidam5.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> On Wed, Apr 3, 2019 at 16:01 Andres Freund <andres(at)anarazel(dot)de> wrote:
>> On 2019-04-03 10:43:33 -0400, Stephen Frost wrote:
>>
>>> I'll push this in a few hours unless there's anything else.
>>
>> The CF entry for this is still open - is there any work missing? Just
>> trying to do some triage...
>>
>> https://commitfest.postgresql.org/22/1647/
>
> No, I was just waiting to make sure the buildfarm was happy, which it
> seems to be. I can take care of the entry in 30m or so, or if you’d
> like to close it out, that would be fine too.

Thanks for merging! I'll stick around the mailing list/IRC for a while
on the off-chance that anything comes up, but the project should feel
free to reach out to me directly with Kerberos-related issues in the
future.

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-03 21:51:06
Message-ID: CAOuzzgoSOzse4iERd2zOy17ouJye955wNddsu4+0gf=8Rtn2nw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings Robbie,

On Wed, Apr 3, 2019 at 17:47 Robbie Harwood <rharwood(at)redhat(dot)com> wrote:

> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>
> > On Wed, Apr 3, 2019 at 16:01 Andres Freund <andres(at)anarazel(dot)de> wrote:
> >> On 2019-04-03 10:43:33 -0400, Stephen Frost wrote:
> >>
> >>> I'll push this in a few hours unless there's anything else.
> >>
> >> The CF entry for this is still open - is there any work missing? Just
> >> trying to do some triage...
> >>
> >> https://commitfest.postgresql.org/22/1647/
> >
> > No, I was just waiting to make sure the buildfarm was happy, which it
> > seems to be. I can take care of the entry in 30m or so, or if you’d
> > like to close it out, that would be fine too.
>
> Thanks for merging! I'll stick around the mailing list/IRC for a while
> on the off-chance that anything comes up, but the project should feel
> free to reach out to me directly with Kerberos-related issues in the
> future.

Thanks so much for pushing on it for so long, it’s a great feature to have!

I would love to see Kerberos/GSSAPI grow a way to find out what the
encryption used on the connection is, as we had discussed before... Do we
know if that encryption must match the encryption type of the tickets
acquired? Would it be possible to inspect the ticket in the same way that
klist does, to determine the encryption that must be used? And similarly
the key tab on the server side? Though of course there can be more than
one but maybe we can find out which was used?

Just some thoughts for future improvements here.

Thanks!

Stephen

>


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 02:01:48
Message-ID: 20190404020148.GD7693@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 03, 2019 at 05:51:06PM -0400, Stephen Frost wrote:
> Thanks so much for pushing on it for so long, it’s a great feature to have!

Glad to see that the final result is using an API layer in
be-secure.c and that we have tests. Now, shouldn't there be some
documentation in protocol.sgml for the read and write handling of the
encrypted messages? Other drivers could need to implement that stuff,
no? We have that for SSL, with SSLRequest and such.
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 02:09:54
Message-ID: CAOuzzgqS-CL18_zKF7pF-wymG8mUeUZveNYYSrXKQRn1VaJsug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

On Wed, Apr 3, 2019 at 22:02 Michael Paquier <michael(at)paquier(dot)xyz> wrote:

> On Wed, Apr 03, 2019 at 05:51:06PM -0400, Stephen Frost wrote:
> > Thanks so much for pushing on it for so long, it’s a great feature to
> have!
>
> Glad to see that the final result is using an API layer in
> be-secure.c and that we have tests. Now, shouldn't there be some
> documentation in protocol.sgml for the read and write handling of the
> encrypted messages? Other drivers could need to implement that stuff,
> no? We have that for SSL, with SSLRequest and such.

Yes, that’s a fair point. I’ll work on adding documentation to
protocol.sgml for the GSSAPI encrypted setup and message passing.

Thanks,

Stephen

>


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 03:48:00
Message-ID: 20190404034800.GF7693@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 03, 2019 at 10:09:54PM -0400, Stephen Frost wrote:
> Yes, that’s a fair point. I’ll work on adding documentation to
> protocol.sgml for the GSSAPI encrypted setup and message passing.

Thanks. I have added an open item to track.
--
Michael


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 09:20:02
Message-ID: 7b7035e0-3691-ca63-0957-25d17dc11514@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Kerberos tests are now failing for me (macOS). I'm seeing

psql: error: could not connect to server: Over-size error packet sent by
the server.
not ok 3 - GSS encryption without auth

# Failed test 'GSS encryption without auth'
# at t/002_enc.pl line 170.
# got: '2'
# expected: '0'

(and repeated for several other tests).

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 11:50:33
Message-ID: CAOuzzgrztzi+g5vfd-dtNxx+MByZcy9nMVzavYZTgvZGHx98Hg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

On Thu, Apr 4, 2019 at 05:20 Peter Eisentraut <
peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:

> Kerberos tests are now failing for me (macOS). I'm seeing
>
> psql: error: could not connect to server: Over-size error packet sent by
> the server.
> not ok 3 - GSS encryption without auth
>
> # Failed test 'GSS encryption without auth'
> # at t/002_enc.pl line 170.
> # got: '2'
> # expected: '0'
>
> (and repeated for several other tests).

Interesting, they work locally for me on Ubuntu. Unfortunately, I don’t
have macOS. This only happens when encryption is being used, presumably?
GSS authentication is still working fine?

Thanks,

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 14:40:30
Message-ID: 5406.1554388830@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> On Thu, Apr 4, 2019 at 05:20 Peter Eisentraut <
> peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:
>> Kerberos tests are now failing for me (macOS).

> Interesting, they work locally for me on Ubuntu. Unfortunately, I don’t
> have macOS. This only happens when encryption is being used, presumably?
> GSS authentication is still working fine?

The kerberos test suite passes for me on RHEL6 (kerberos 1.10.3),
but I observe some compiler warnings that need to be dealt with:

$ ./configure --with-gssapi ...
$ time make -j8 -s
be-secure-gssapi.c:597: warning: no previous prototype for 'be_gssapi_get_auth'
be-secure-gssapi.c:609: warning: no previous prototype for 'be_gssapi_get_enc'
be-secure-gssapi.c:621: warning: no previous prototype for 'be_gssapi_get_princ'
pgstat.c: In function 'pgstat_bestart':
pgstat.c:2986: warning: implicit declaration of function 'be_gssapi_get_auth'
pgstat.c:2987: warning: implicit declaration of function 'be_gssapi_get_enc'
pgstat.c:2990: warning: implicit declaration of function 'be_gssapi_get_princ'
pgstat.c:2990: warning: passing argument 2 of 'strlcpy' makes pointer from integer without a cast
../../../src/include/port.h:429: note: expected 'const char *' but argument is of type 'int'
All of PostgreSQL successfully made. Ready to install.

I'm not very sure why the integer/pointer confusion in pgstat_bestart
doesn't cause hard crashes when using gss auth --- or does
this suite not actually test that?

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 14:48:19
Message-ID: 20190404144818.GI6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > On Thu, Apr 4, 2019 at 05:20 Peter Eisentraut <
> > peter(dot)eisentraut(at)2ndquadrant(dot)com> wrote:
> >> Kerberos tests are now failing for me (macOS).
>
> > Interesting, they work locally for me on Ubuntu. Unfortunately, I don’t
> > have macOS. This only happens when encryption is being used, presumably?
> > GSS authentication is still working fine?
>
> The kerberos test suite passes for me on RHEL6 (kerberos 1.10.3),
> but I observe some compiler warnings that need to be dealt with:

Interesting, I don't see those with my build. I'll have to figure out
why not. Will fix them in any case.

> $ ./configure --with-gssapi ...
> $ time make -j8 -s
> be-secure-gssapi.c:597: warning: no previous prototype for 'be_gssapi_get_auth'
> be-secure-gssapi.c:609: warning: no previous prototype for 'be_gssapi_get_enc'
> be-secure-gssapi.c:621: warning: no previous prototype for 'be_gssapi_get_princ'
> pgstat.c: In function 'pgstat_bestart':
> pgstat.c:2986: warning: implicit declaration of function 'be_gssapi_get_auth'
> pgstat.c:2987: warning: implicit declaration of function 'be_gssapi_get_enc'
> pgstat.c:2990: warning: implicit declaration of function 'be_gssapi_get_princ'
> pgstat.c:2990: warning: passing argument 2 of 'strlcpy' makes pointer from integer without a cast
> ../../../src/include/port.h:429: note: expected 'const char *' but argument is of type 'int'
> All of PostgreSQL successfully made. Ready to install.
>
> I'm not very sure why the integer/pointer confusion in pgstat_bestart
> doesn't cause hard crashes when using gss auth --- or does
> this suite not actually test that?

Isn't it just saying that because of the implicit declaration..?
Once that's fixed, the integer/pointer warning will go away, but
it's actually a pointer in either case, hence why it isn't crashing.

The test suite does test GSS authentication and GSS encryption.

Thanks,

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 14:52:48
Message-ID: 5945.1554389568@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>> I'm not very sure why the integer/pointer confusion in pgstat_bestart
>> doesn't cause hard crashes when using gss auth --- or does
>> this suite not actually test that?

> Isn't it just saying that because of the implicit declaration..?
> Once that's fixed, the integer/pointer warning will go away, but
> it's actually a pointer in either case, hence why it isn't crashing.

Well, if the caller thinks what is being passed back is an int,
it will do a 32-to-64-bit widening, which is almost certainly
going to result in a corrupted pointer.

> The test suite does test GSS authentication and GSS encryption.

Hm. I'll poke at this more closely.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 15:00:54
Message-ID: 20190404150054.GJ6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> >> I'm not very sure why the integer/pointer confusion in pgstat_bestart
> >> doesn't cause hard crashes when using gss auth --- or does
> >> this suite not actually test that?
>
> > Isn't it just saying that because of the implicit declaration..?
> > Once that's fixed, the integer/pointer warning will go away, but
> > it's actually a pointer in either case, hence why it isn't crashing.
>
> Well, if the caller thinks what is being passed back is an int,
> it will do a 32-to-64-bit widening, which is almost certainly
> going to result in a corrupted pointer.

Oh, good point. Interesting that it still works then.

I've got a fix for the missing prototypes, I hadn't noticed the issue
previously due to always building with SSL enabled as well. I'm testing
with a non-SSL build and will push the fix shortly.

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 15:16:43
Message-ID: 7566.1554391003@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>> Well, if the caller thinks what is being passed back is an int,
>> it will do a 32-to-64-bit widening, which is almost certainly
>> going to result in a corrupted pointer.

> Oh, good point. Interesting that it still works then.

There must be something about the x86_64 ABI that allows this to
accidentally work -- maybe integers are presumed to be sign-extended
to 64 bits by callee not caller? I added some logging and verified
that pgstat.c is seeing the correct string value, so it's working
somehow.

> I've got a fix for the missing prototypes, I hadn't noticed the issue
> previously due to always building with SSL enabled as well.

Yeah, I'd just come to the conclusion that it's because I didn't
include --with-openssl, and libpq-be.h's #ifdef nest doesn't expect
that.

BTW, the kerberos test suite takes nearly 4 minutes for me, is
it supposed to be so slow?

regards, tom lane


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 15:23:54
Message-ID: 48c197bc-aba4-91ed-b2a0-d56f80e35a03@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-04 17:16, Tom Lane wrote:
> BTW, the kerberos test suite takes nearly 4 minutes for me, is
> it supposed to be so slow?

I've seen this on some virtualized machines that didn't have a lot of
entropy.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 15:24:40
Message-ID: 20190404152439.GK6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
> > * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> >> Well, if the caller thinks what is being passed back is an int,
> >> it will do a 32-to-64-bit widening, which is almost certainly
> >> going to result in a corrupted pointer.
>
> > Oh, good point. Interesting that it still works then.
>
> There must be something about the x86_64 ABI that allows this to
> accidentally work -- maybe integers are presumed to be sign-extended
> to 64 bits by callee not caller? I added some logging and verified
> that pgstat.c is seeing the correct string value, so it's working
> somehow.

Huh, I'm not sure. That's certainly interesting though.

> > I've got a fix for the missing prototypes, I hadn't noticed the issue
> > previously due to always building with SSL enabled as well.
>
> Yeah, I'd just come to the conclusion that it's because I didn't
> include --with-openssl, and libpq-be.h's #ifdef nest doesn't expect
> that.

Right, that should be fixed now with the commit I just pushed.

> BTW, the kerberos test suite takes nearly 4 minutes for me, is
> it supposed to be so slow?

Unfortunately, the kerberos test suite requires building a KDC to get
tickets from and that takes a bit of time. On my laptop it takes about
8s:

make -s check 4.67s user 0.85s system 70% cpu 7.819 total

So I'm a bit surprised that it's taking 4 minutes for you. I wonder if
there might be an issue related to the KDC wanting to get some amount of
random data and the system you're on isn't producing random bytes very
fast..?

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 15:32:48
Message-ID: 8476.1554391968@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>> There must be something about the x86_64 ABI that allows this to
>> accidentally work -- maybe integers are presumed to be sign-extended
>> to 64 bits by callee not caller? I added some logging and verified
>> that pgstat.c is seeing the correct string value, so it's working
>> somehow.

> Huh, I'm not sure. That's certainly interesting though.

Oh, no, it's simpler than that: the pointer values that
be_gssapi_get_princ() is returning just happen to be less than 2^31
on my system. I'd dismissed that as being unlikely, but it's the truth.

> So I'm a bit surprised that it's taking 4 minutes for you. I wonder if
> there might be an issue related to the KDC wanting to get some amount of
> random data and the system you're on isn't producing random bytes very
> fast..?

Not sure. This is my usual development box and it also does mail, DNS,
etc for my household, so I'd expect it to have plenty of entropy.
But it's running a pretty old kernel, and old Kerberos too, so maybe
the explanation is in there somewhere.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 15:35:37
Message-ID: 20190404153537.GL6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> Kerberos tests are now failing for me (macOS). I'm seeing
>
> psql: error: could not connect to server: Over-size error packet sent by
> the server.
> not ok 3 - GSS encryption without auth
>
> # Failed test 'GSS encryption without auth'
> # at t/002_enc.pl line 170.
> # got: '2'
> # expected: '0'
>
> (and repeated for several other tests).

Ok, it looks like there's a server-side error happening here, and it
would be good to see what that is, so can you send the server logs?

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 16:16:24
Message-ID: 15827.1554394584@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I wrote:
> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>> So I'm a bit surprised that it's taking 4 minutes for you. I wonder if
>> there might be an issue related to the KDC wanting to get some amount of
>> random data and the system you're on isn't producing random bytes very
>> fast..?

> Not sure. This is my usual development box and it also does mail, DNS,
> etc for my household, so I'd expect it to have plenty of entropy.
> But it's running a pretty old kernel, and old Kerberos too, so maybe
> the explanation is in there somewhere.

Same test on a laptop running Fedora 28 takes a shade under 5 seconds.
The laptop has a somewhat better geekbench rating than my workstation,
but certainly not 50x better. And I really doubt it's got more entropy
sources than the workstation. Gotta be something about the kernel.

Watching the test logs, I see that essentially all the time on the RHEL6
machine is consumed by the two

# Running: /usr/sbin/kdb5_util create -s -P secret0

steps. Is there a case for merging the two scripts so we only have to
do that once? Maybe not, if nobody else sees this.

regards, tom lane


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 16:24:52
Message-ID: 20190404162452.GM6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
> I wrote:
> > Stephen Frost <sfrost(at)snowman(dot)net> writes:
> >> So I'm a bit surprised that it's taking 4 minutes for you. I wonder if
> >> there might be an issue related to the KDC wanting to get some amount of
> >> random data and the system you're on isn't producing random bytes very
> >> fast..?
>
> > Not sure. This is my usual development box and it also does mail, DNS,
> > etc for my household, so I'd expect it to have plenty of entropy.
> > But it's running a pretty old kernel, and old Kerberos too, so maybe
> > the explanation is in there somewhere.
>
> Same test on a laptop running Fedora 28 takes a shade under 5 seconds.
> The laptop has a somewhat better geekbench rating than my workstation,
> but certainly not 50x better. And I really doubt it's got more entropy
> sources than the workstation. Gotta be something about the kernel.
>
> Watching the test logs, I see that essentially all the time on the RHEL6
> machine is consumed by the two
>
> # Running: /usr/sbin/kdb5_util create -s -P secret0
>
> steps. Is there a case for merging the two scripts so we only have to
> do that once? Maybe not, if nobody else sees this.

I do think that mergeing them would be a good idea and I can look into
that, though at least locally that step takes less than a second.. I
wonder if you might strace (or whatever is appropriate) that kdb5_util
and see what's taking so long. I seriously doubt it's the actual
kdb5_util code and strongly suspect it's some kernel call.

Thanks!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Robbie Harwood <rharwood(at)redhat(dot)com>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 17:05:29
Message-ID: 18056.1554397529@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>> Watching the test logs, I see that essentially all the time on the RHEL6
>> machine is consumed by the two
>> # Running: /usr/sbin/kdb5_util create -s -P secret0
>> steps. Is there a case for merging the two scripts so we only have to
>> do that once? Maybe not, if nobody else sees this.

> I do think that mergeing them would be a good idea and I can look into
> that, though at least locally that step takes less than a second.. I
> wonder if you might strace (or whatever is appropriate) that kdb5_util
> and see what's taking so long. I seriously doubt it's the actual
> kdb5_util code and strongly suspect it's some kernel call.

"strace -r" pins the blame pretty firmly on /dev/random:

0.000076 open("/dev/random", O_RDONLY) = 3
0.000227 fcntl(3, F_SETFD, FD_CLOEXEC) = 0
0.000061 fstat(3, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 8), ...}) = 0
0.000068 read(3, "\336&\301\310V\344q\217\264-\262\320w-", 64) = 14
0.000091 read(3, "\326\353I\371$\361", 50) = 6
15.328306 read(3, "\214\301\313]I\325", 44) = 6
17.418929 read(3, "z\251\37\275\365\24", 38) = 6
13.366997 read(3, "6\257I\315f\3", 32) = 6
11.457994 read(3, "\370\275\2765\31(", 26) = 6
23.472194 read(3, "\226\r\314\373\2014", 20) = 6
11.746848 read(3, "\335\336BR\30\322", 14) = 6
20.823940 read(3, "\366\214\r\211\0267", 8) = 6
14.429214 read(3, ",g", 2) = 2
15.494835 close(3) = 0

There's no other part of the trace that takes more than ~ 0.1s.
So this boils down to the old bugaboo about how much entropy
there really is in /dev/random.

regards, tom lane


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 17:14:32
Message-ID: jlgv9ztr8uf.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>> * Tom Lane (tgl(at)sss(dot)pgh(dot)pa(dot)us) wrote:
>>> Well, if the caller thinks what is being passed back is an int,
>>> it will do a 32-to-64-bit widening, which is almost certainly
>>> going to result in a corrupted pointer.
>
>> Oh, good point. Interesting that it still works then.
>
> There must be something about the x86_64 ABI that allows this to
> accidentally work -- maybe integers are presumed to be sign-extended
> to 64 bits by callee not caller? I added some logging and verified
> that pgstat.c is seeing the correct string value, so it's working
> somehow.
>
>> I've got a fix for the missing prototypes, I hadn't noticed the issue
>> previously due to always building with SSL enabled as well.
>
> Yeah, I'd just come to the conclusion that it's because I didn't
> include --with-openssl, and libpq-be.h's #ifdef nest doesn't expect
> that.
>
> BTW, the kerberos test suite takes nearly 4 minutes for me, is
> it supposed to be so slow?

My guess is entropy problems as well. If available, configuring
/dev/urandom passthrough from the host is a generally helpful thing to
do.

My (Fedora, Centos/RHEL 7+) krb5 builds use getrandom() for entropy, so
they shouldn't be slow; I believe Debian also has started doing so
recently as well. I don't know what other distros/OSs do for this.

Thanks,
--Robbie


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 17:15:48
Message-ID: jlgsguxr8sb.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> I wrote:
>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>> So I'm a bit surprised that it's taking 4 minutes for you. I wonder if
>>> there might be an issue related to the KDC wanting to get some amount of
>>> random data and the system you're on isn't producing random bytes very
>>> fast..?
>
>> Not sure. This is my usual development box and it also does mail, DNS,
>> etc for my household, so I'd expect it to have plenty of entropy.
>> But it's running a pretty old kernel, and old Kerberos too, so maybe
>> the explanation is in there somewhere.
>
> Same test on a laptop running Fedora 28 takes a shade under 5 seconds.
> The laptop has a somewhat better geekbench rating than my workstation,
> but certainly not 50x better. And I really doubt it's got more entropy
> sources than the workstation. Gotta be something about the kernel.
>
> Watching the test logs, I see that essentially all the time on the RHEL6
> machine is consumed by the two
>
> # Running: /usr/sbin/kdb5_util create -s -P secret0
>
> steps. Is there a case for merging the two scripts so we only have to
> do that once? Maybe not, if nobody else sees this.

I think that would be a good idea! Unfortunately I don't speak perl
well enough to do that, so I'd just copied-and-modified.

Thanks,
--Robbie


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-04 19:05:16
Message-ID: 6c1cd334-cf1d-58b5-ffe0-5d4688538024@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-04 17:35, Stephen Frost wrote:
> Ok, it looks like there's a server-side error happening here, and it
> would be good to see what that is, so can you send the server logs?

These errors appear several times in the server logs:

FATAL: GSSAPI context error
DETAIL: Miscellaneous failure (see text): Decrypt integrity check
failed for checksum type hmac-sha1-96-aes256, key type
aes256-cts-hmac-sha1-96

FATAL: accepting GSS security context failed
DETAIL: Miscellaneous failure (see text): Decrypt integrity check
failed for checksum type hmac-sha1-96-aes256, key type
aes256-cts-hmac-sha1-96

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-05 02:59:25
Message-ID: 20190405025925.GN6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> Kerberos tests are now failing for me (macOS). I'm seeing
>
> psql: error: could not connect to server: Over-size error packet sent by
> the server.
> not ok 3 - GSS encryption without auth
>
> # Failed test 'GSS encryption without auth'
> # at t/002_enc.pl line 170.
> # got: '2'
> # expected: '0'
>
> (and repeated for several other tests).

Alright, that over-size error was a bug in the error-handling code,
which I've just pushed a fix for. That said...

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> On 2019-04-04 17:35, Stephen Frost wrote:
> > Ok, it looks like there's a server-side error happening here, and it
> > would be good to see what that is, so can you send the server logs?
>
> These errors appear several times in the server logs:
>
> FATAL: GSSAPI context error
> DETAIL: Miscellaneous failure (see text): Decrypt integrity check
> failed for checksum type hmac-sha1-96-aes256, key type
> aes256-cts-hmac-sha1-96
>
> FATAL: accepting GSS security context failed
> DETAIL: Miscellaneous failure (see text): Decrypt integrity check
> failed for checksum type hmac-sha1-96-aes256, key type
> aes256-cts-hmac-sha1-96

This looks like it's a real issue and it's unclear what's going on here.
I wonder- are you certain that you're using all the same Kerberos
libraries for the KDC, the server, and psql?

If you go back to before the GSSAPI encryption patch, does it work..?

I've certainly seen interesting issues on MacOS, in particular, due to
different Kerberos libraries/tools being installed and I wonder if
that's what is going on here. Maybe you could check klist vs. psql wrt
what libraries are linked in?

Thanks,

Stephen


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-05 07:50:20
Message-ID: 7d0584ab-26a8-6731-aeee-9c8e195533e6@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-05 04:59, Stephen Frost wrote:
> Alright, that over-size error was a bug in the error-handling code,
> which I've just pushed a fix for. That said...

Yes, that looks better now.

> This looks like it's a real issue and it's unclear what's going on here.
> I wonder- are you certain that you're using all the same Kerberos
> libraries for the KDC, the server, and psql?

Right, it was built against the OS-provided Kerberos installation
(/usr/bin etc.). If I build against the Homebrew-provided one then the
tests pass.

So maybe that means that this encryption feature is not supported on
that (presumably older) installation? (krb5-config --version says
"Kerberos 5 release 1.7-prerelease") Is that plausible? Is a gentler
failure mode possible?

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-05 12:48:03
Message-ID: 20190405124803.GO6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> On 2019-04-05 04:59, Stephen Frost wrote:
> > Alright, that over-size error was a bug in the error-handling code,
> > which I've just pushed a fix for. That said...
>
> Yes, that looks better now.

Great.

> > This looks like it's a real issue and it's unclear what's going on here.
> > I wonder- are you certain that you're using all the same Kerberos
> > libraries for the KDC, the server, and psql?
>
> Right, it was built against the OS-provided Kerberos installation
> (/usr/bin etc.). If I build against the Homebrew-provided one then the
> tests pass.

All of it was built against the OS-provided Kerberos install, and you
got the failure..?

> So maybe that means that this encryption feature is not supported on
> that (presumably older) installation? (krb5-config --version says
> "Kerberos 5 release 1.7-prerelease") Is that plausible? Is a gentler
> failure mode possible?

On a failure to set up an encrypted connection, we'll actually fall back
to a non-encrypted one, using GSSAPI *just* for authentication, which is
why I was asking if this worked before the encryption patch went in.
Also, which of the tests are still failing, exactly? The authentication
ones or the encryption ones or both?

If we determine that this is some issue with the MacOS-provided Kerberos
libraries, then we could try to detect them and disable GSSAPI
encryption in that case explicitly, I suppose, but I've seen odd things
with the MacOS-provided Kerberos libraries before on released versions
of PG (without any encryption support), so I'm not yet convinced that
this is an issue that's specific to adding support for encryption.

Thanks!

Stephen


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-05 15:31:25
Message-ID: jlga7h4sc36.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> * Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
>> On 2019-04-05 04:59, Stephen Frost wrote:
>>
>>> Alright, that over-size error was a bug in the error-handling code,
>>> which I've just pushed a fix for. That said...
>>
>> Yes, that looks better now.
>
> Great.
>
>>> This looks like it's a real issue and it's unclear what's going on
>>> here. I wonder- are you certain that you're using all the same
>>> Kerberos libraries for the KDC, the server, and psql?
>>
>> Right, it was built against the OS-provided Kerberos installation
>> (/usr/bin etc.). If I build against the Homebrew-provided one then
>> the tests pass.
>
> All of it was built against the OS-provided Kerberos install, and you
> got the failure..?
>
>> So maybe that means that this encryption feature is not supported on
>> that (presumably older) installation? (krb5-config --version says
>> "Kerberos 5 release 1.7-prerelease") Is that plausible? Is a gentler
>> failure mode possible?

Heimdal never had a 1.7 release - they went from 1.5.2 to 7.1.0.

MIT did have a 1.7 release - in 2009.

Apple doesn't open source their Kerberos implementation, so I can't
exactly point a debugger at it. But if it's in fact somehow related to
MIT 1.7-prerelease, I imagine they inherited a bug or two that's been
fixed in the ten years since then.

As for the code: I'm not doing anything complicated. The interface I'm
using is as specified in RFC2743 and RFC2744, which is from 2000 (though
I think technically I'm mostly backward compatible to RFC1509, from
1993), and Kerberos V5 itself is specified in RFC4120 (from 2005).

> On a failure to set up an encrypted connection, we'll actually fall
> back to a non-encrypted one, using GSSAPI *just* for authentication,
> which is why I was asking if this worked before the encryption patch
> went in. Also, which of the tests are still failing, exactly? The
> authentication ones or the encryption ones or both?

Good question.

> If we determine that this is some issue with the MacOS-provided
> Kerberos libraries, then we could try to detect them and disable
> GSSAPI encryption in that case explicitly, I suppose, but I've seen
> odd things with the MacOS-provided Kerberos libraries before on
> released versions of PG (without any encryption support), so I'm not
> yet convinced that this is an issue that's specific to adding support
> for encryption.

If we have to, a version check >1.7 would probably work. That'll remove
the ability to work on RHEL/CentOS 5, but that's probably fine, and I'm
not aware of any other supported OSs that would be impacted.

Thanks,
--Robbie


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-05 20:41:54
Message-ID: f56cacac-0693-23aa-353d-179adbe32f2e@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-05 14:48, Stephen Frost wrote:
> All of it was built against the OS-provided Kerberos install, and you
> got the failure..?

right

> On a failure to set up an encrypted connection, we'll actually fall back
> to a non-encrypted one using GSSAPI *just* for authentication, which is> why I was asking if this worked before the encryption patch went in.

The tests have always worked before. I've run them probably hundreds of
times.

> Also, which of the tests are still failing, exactly? The authentication
> ones or the encryption ones or both?

Only the encryption ones:

not ok 1 - GSS-encrypted access

# Failed test 'GSS-encrypted access'
# at t/002_enc.pl line 170.
# got: '2'
# expected: '0'
ok 2 - GSS encryption disabled
not ok 3 - GSS encryption without auth

# Failed test 'GSS encryption without auth'
# at t/002_enc.pl line 170.
# got: '2'
# expected: '0'
not ok 4 - GSS unencrypted fallback

# Failed test 'GSS unencrypted fallback'
# at t/002_enc.pl line 170.
# got: '2'
# expected: '0'
ok 5 - GSS unencrypted fallback prevention

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-05 21:37:45
Message-ID: 20190405213745.GR6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> On 2019-04-05 14:48, Stephen Frost wrote:
> > On a failure to set up an encrypted connection, we'll actually fall back
> > to a non-encrypted one using GSSAPI *just* for authentication, which is> why I was asking if this worked before the encryption patch went in.
>
> The tests have always worked before. I've run them probably hundreds of
> times.

Ok.

> > Also, which of the tests are still failing, exactly? The authentication
> > ones or the encryption ones or both?
>
> Only the encryption ones:
>
> not ok 1 - GSS-encrypted access
>
> # Failed test 'GSS-encrypted access'
> # at t/002_enc.pl line 170.
> # got: '2'
> # expected: '0'
> ok 2 - GSS encryption disabled
> not ok 3 - GSS encryption without auth
>
> # Failed test 'GSS encryption without auth'
> # at t/002_enc.pl line 170.
> # got: '2'
> # expected: '0'
> not ok 4 - GSS unencrypted fallback
>
> # Failed test 'GSS unencrypted fallback'
> # at t/002_enc.pl line 170.
> # got: '2'
> # expected: '0'
> ok 5 - GSS unencrypted fallback prevention

So, looking back at the error message you got:

FATAL: GSSAPI context error
DETAIL: Miscellaneous failure (see text): Decrypt integrity check
failed for checksum type hmac-sha1-96-aes256, key type
aes256-cts-hmac-sha1-96

FATAL: accepting GSS security context failed
DETAIL: Miscellaneous failure (see text): Decrypt integrity check
failed for checksum type hmac-sha1-96-aes256, key type
aes256-cts-hmac-sha1-96

(assuming that's still what you're getting..?)

What this is saying is basically that the key that the PG server is
using from its keytab and the key used to encrypt the ticket that the
user has (from the KDC) don't match up.

I wonder if somehow the keytab file that the server is using isn't
getting destroyed between the two test runs and so you're ending up with
the server using the key from the old KDC, while the user is using the
new one..? Or something is equally going wrong in the tests.

Could you try doing something like removing the 001_auth.pl, moving the
002_enc.pl to 001_enc.pl, double-check that everything is cleaned up and
that there aren't any old PG servers running, et al, and re-try that
way?

I've also reached out to some colleagues about having one of them test
with MacOS. What version are you on..?

Thanks!

Stephen


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-08 12:05:53
Message-ID: 160445e8-2ccf-7ffd-728f-80597c248a57@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-05 23:37, Stephen Frost wrote:
> I wonder if somehow the keytab file that the server is using isn't
> getting destroyed between the two test runs and so you're ending up with
> the server using the key from the old KDC, while the user is using the
> new one..? Or something is equally going wrong in the tests.
>
> Could you try doing something like removing the 001_auth.pl, moving the
> 002_enc.pl to 001_enc.pl, double-check that everything is cleaned up and
> that there aren't any old PG servers running, et al, and re-try that
> way?

Running just 002_enc.pl by itself passes the tests!

> I've also reached out to some colleagues about having one of them test
> with MacOS. What version are you on..?

macOS 10.14.14 it says.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-09 02:51:14
Message-ID: 20190409025114.GW6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> On 2019-04-05 23:37, Stephen Frost wrote:
> > I wonder if somehow the keytab file that the server is using isn't
> > getting destroyed between the two test runs and so you're ending up with
> > the server using the key from the old KDC, while the user is using the
> > new one..? Or something is equally going wrong in the tests.
> >
> > Could you try doing something like removing the 001_auth.pl, moving the
> > 002_enc.pl to 001_enc.pl, double-check that everything is cleaned up and
> > that there aren't any old PG servers running, et al, and re-try that
> > way?
>
> Running just 002_enc.pl by itself passes the tests!

Great! I think what I'll do is work to incorporate the two tests back
into one script, to avoid whatever the race condition or other confusion
is happening on macOS here.

Thanks so much for testing it!

Stephen


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-09 04:11:05
Message-ID: 6040.1554783065@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
> On 2019-04-05 23:37, Stephen Frost wrote:
>> I've also reached out to some colleagues about having one of them test
>> with MacOS. What version are you on..?

> macOS 10.14.14 it says.

I tried to replicate this on my own laptop (macOS 10.14.4 ... I do not
think there is or ever will be a 10.14.14). I can't, because the
kerberos test fails immediately:

1..4
# setting up Kerberos
# Running: krb5-config --version
# Running: kdb5_util create -s -P secret0
Can't exec "kdb5_util": No such file or directory at /Users/tgl/pgsql/src/test/kerberos/../../../src/test/perl/TestLib.pm line 190.
Bail out! system kdb5_util failed

and indeed, there's no kdb5_util in /usr/bin/ or anywhere else that
I can find. So I speculate that Peter is running some weird hodgepodge
of Apple and Homebrew code, making the question not so much "why does
it fail" as "how did it ever work".

I also notice that the build spews out a bunch of deprecation warnings,
because just as with openSSL, Apple has stuck deprecation attributes
on everything in gssapi/gssapi.h. They want you to use their GSS
"framework" instead.

So I'm not convinced we should spend a lot of effort on fooling with
the test scripts for this. This platform has got much more fundamental
problems than that.

regards, tom lane


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-09 07:32:06
Message-ID: 5bd413ae-719d-4db4-b25a-346f22054930@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-09 04:51, Stephen Frost wrote:
>> Running just 002_enc.pl by itself passes the tests!
> Great! I think what I'll do is work to incorporate the two tests back
> into one script, to avoid whatever the race condition or other confusion
> is happening on macOS here.

That seems reasonable. It also avoids the large amount of duplicate
setup code.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-09 07:34:38
Message-ID: eabbafc2-45c2-ec73-560b-19778c5a8e59@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-09 06:11, Tom Lane wrote:
> I tried to replicate this on my own laptop (macOS 10.14.4 ... I do not
> think there is or ever will be a 10.14.14).

right

> kerberos test fails immediately:
>
> 1..4
> # setting up Kerberos
> # Running: krb5-config --version
> # Running: kdb5_util create -s -P secret0
> Can't exec "kdb5_util": No such file or directory at /Users/tgl/pgsql/src/test/kerberos/../../../src/test/perl/TestLib.pm line 190.
> Bail out! system kdb5_util failed
>
> and indeed, there's no kdb5_util in /usr/bin/ or anywhere else that
> I can find. So I speculate that Peter is running some weird hodgepodge
> of Apple and Homebrew code, making the question not so much "why does
> it fail" as "how did it ever work".

Yes, you need a krb5 installation from either Homebrew or MacPorts.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-09 15:36:24
Message-ID: 20190409153624.t7cozlctjzuf47ja@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 3, 2019 at 08:49:25AM +0200, Magnus Hagander wrote:
> On Wed, Apr 3, 2019 at 12:22 AM Joe Conway <mail(at)joeconway(dot)com> wrote:
> Personally I don't find it as confusing as is either, and I find hostgss
> to be a good analog of hostssl. On the other hand hostgssenc is long and
> unintuitive. So +1 for leaving as is and -1 one for changing it IMHO.
>
>
> I think for those who are well versed in pg_hba (and maybe gss as well), it's
> not confusing. That includes me.
>
> However, for a new user, I can definitely see how it can be considered
> confusing. And confusion in *security configuration* is always a bad idea, even
> if it's just potential.
>
> Thus +1 on changing it.
>
> If it was on the table it might have been better to keep hostgss and change the
> authentication method to gssauth or something, but that ship sailed *years*
> ago.

Uh, did we consider keeping hostgss and changing the auth part at the
end to "gssauth"?

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Joe Conway <mail(at)joeconway(dot)com>, Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-09 17:36:26
Message-ID: jlg7ec3krmt.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:

> On Wed, Apr 3, 2019 at 08:49:25AM +0200, Magnus Hagander wrote:
>> On Wed, Apr 3, 2019 at 12:22 AM Joe Conway <mail(at)joeconway(dot)com> wrote:
>>
>> Personally I don't find it as confusing as is either, and I find
>> hostgss to be a good analog of hostssl. On the other hand hostgssenc
>> is long and unintuitive. So +1 for leaving as is and -1 one for
>> changing it IMHO.
>>
>> I think for those who are well versed in pg_hba (and maybe gss as
>> well), it's not confusing. That includes me.
>>
>> However, for a new user, I can definitely see how it can be
>> considered confusing. And confusion in *security configuration* is
>> always a bad idea, even if it's just potential.
>>
>> Thus +1 on changing it.
>>
>> If it was on the table it might have been better to keep hostgss and
>> change the authentication method to gssauth or something, but that
>> ship sailed *years* ago.
>
> Uh, did we consider keeping hostgss and changing the auth part at the
> end to "gssauth"?

I think that was implicitly rejected because we'd have to keep the
capability to configure "gss" there else break compatibility.

Thanks,
--Robbie


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Robbie Harwood <rharwood(at)redhat(dot)com>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-11 01:47:01
Message-ID: 20190411014700.GY6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
> Bruce Momjian <bruce(at)momjian(dot)us> writes:
> > On Wed, Apr 3, 2019 at 08:49:25AM +0200, Magnus Hagander wrote:
> >> On Wed, Apr 3, 2019 at 12:22 AM Joe Conway <mail(at)joeconway(dot)com> wrote:
> >>
> >> Personally I don't find it as confusing as is either, and I find
> >> hostgss to be a good analog of hostssl. On the other hand hostgssenc
> >> is long and unintuitive. So +1 for leaving as is and -1 one for
> >> changing it IMHO.
> >>
> >> I think for those who are well versed in pg_hba (and maybe gss as
> >> well), it's not confusing. That includes me.
> >>
> >> However, for a new user, I can definitely see how it can be
> >> considered confusing. And confusion in *security configuration* is
> >> always a bad idea, even if it's just potential.
> >>
> >> Thus +1 on changing it.
> >>
> >> If it was on the table it might have been better to keep hostgss and
> >> change the authentication method to gssauth or something, but that
> >> ship sailed *years* ago.
> >
> > Uh, did we consider keeping hostgss and changing the auth part at the
> > end to "gssauth"?
>
> I think that was implicitly rejected because we'd have to keep the
> capability to configure "gss" there else break compatibility.

Right, if we changed the name of the auth method then everyone who is
using the "gss" auth method would have to update their pg_hba.conf
files... That would be very ugly. Also, it wasn't implicitly rejected,
it was discussed up-thread (see the comments between Magnus and I,
specifically, quoted above- "that ship sailed *years* ago") and
explicitly rejected.

Thanks!

Stephen


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Robbie Harwood <rharwood(at)redhat(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-11 13:56:37
Message-ID: CA+TgmobdmxaOWuyA3kfbVYCtB0zKDLP7k8V0-JwWchuKUCey2Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Apr 10, 2019 at 9:47 PM Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> Right, if we changed the name of the auth method then everyone who is
> using the "gss" auth method would have to update their pg_hba.conf
> files... That would be very ugly. Also, it wasn't implicitly rejected,
> it was discussed up-thread (see the comments between Magnus and I,
> specifically, quoted above- "that ship sailed *years* ago") and
> explicitly rejected.

Slightly off-topic, but I am not familiar with GSSAPI and don't quite
understand what the benefits of GSSAPI encryption are as compared with
OpenSSL encryption. I am sure there must be some; otherwise, nobody
would have bothered writing, reviewing, and committing this patch.
Can somebody enlighten me?

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Robbie Harwood <rharwood(at)redhat(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-11 13:58:54
Message-ID: CABUevExwCmq5OmqXX-VUxGBPW2XiHpO4O4f9nsO_QjUfwxzoKw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Apr 11, 2019 at 3:56 PM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> On Wed, Apr 10, 2019 at 9:47 PM Stephen Frost <sfrost(at)snowman(dot)net> wrote:
> > Right, if we changed the name of the auth method then everyone who is
> > using the "gss" auth method would have to update their pg_hba.conf
> > files... That would be very ugly. Also, it wasn't implicitly rejected,
> > it was discussed up-thread (see the comments between Magnus and I,
> > specifically, quoted above- "that ship sailed *years* ago") and
> > explicitly rejected.
>
> Slightly off-topic, but I am not familiar with GSSAPI and don't quite
> understand what the benefits of GSSAPI encryption are as compared with
> OpenSSL encryption. I am sure there must be some; otherwise, nobody
> would have bothered writing, reviewing, and committing this patch.
> Can somebody enlighten me?
>

You don't need to set up an SSL PKI.

Yes you need the similar keys and stuff set up for GSSAPI, but if you
already *have* those (which you do if you are using gss authentication for
example) then it's a lot less extra overhead.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/>
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>


From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Bruce Momjian <bruce(at)momjian(dot)us>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-11 17:40:49
Message-ID: jlg1s2830f2.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> Robbie Harwood (rharwood(at)redhat(dot)com) wrote:
>> Bruce Momjian <bruce(at)momjian(dot)us> writes:
>>> Magnus Hagander wrote:
>>>> Joe Conway <mail(at)joeconway(dot)com> wrote:
>>>>
>>>> If it was on the table it might have been better to keep hostgss
>>>> and change the authentication method to gssauth or something, but
>>>> that ship sailed *years* ago.
>>>
>>> Uh, did we consider keeping hostgss and changing the auth part at
>>> the end to "gssauth"?
>>
>> I think that was implicitly rejected because we'd have to keep the
>> capability to configure "gss" there else break compatibility.
>
> Right, if we changed the name of the auth method then everyone who is
> using the "gss" auth method would have to update their pg_hba.conf
> files... That would be very ugly. Also, it wasn't implicitly
> rejected, it was discussed up-thread (see the comments between Magnus
> and I, specifically, quoted above- "that ship sailed *years* ago") and
> explicitly rejected.

Apologies, you're right of course. I intended to say why *I* had
rejected it but got bit by the passive voice.

Thanks,
--Robbie


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-12 08:22:03
Message-ID: 8416d227-6e9d-092a-4475-b453e1d7d433@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-09 09:32, Peter Eisentraut wrote:
> On 2019-04-09 04:51, Stephen Frost wrote:
>>> Running just 002_enc.pl by itself passes the tests!
>> Great! I think what I'll do is work to incorporate the two tests back
>> into one script, to avoid whatever the race condition or other confusion
>> is happening on macOS here.
>
> That seems reasonable. It also avoids the large amount of duplicate
> setup code.

Another problem is that the two test files cannot be run in parallel
because they use the same hardcoded data directories. That would have
to be replaced by temporary directories.

The race condition alluded to above appears to be simply that at the end
of the test the kdc is shut down by kill -INT but nothing waits for that
to finish before a new one is started by the next test. So there is
potential for all kinds of confusion.

Putting it all in one test file seems to be the easiest way out.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Stephen Frost <sfrost(at)snowman(dot)net>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-12 12:58:55
Message-ID: 20190412125855.GA15472@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 12, 2019 at 10:22:03AM +0200, Peter Eisentraut wrote:
> Another problem is that the two test files cannot be run in parallel
> because they use the same hardcoded data directories. That would have
> to be replaced by temporary directories.

Please note that I have added an open item about the instability of
these tests.

If ones's PG_TEST_EXTRA uses kerberos, just using PROVE_FLAGS="-j4" or
such to run multiple scripts in parallel makes the test failure very
easy to reproduce. That's my case, and I had to disable the test for
now...
--
Michael


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-15 12:24:52
Message-ID: 20190415122452.GC6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Peter Eisentraut (peter(dot)eisentraut(at)2ndquadrant(dot)com) wrote:
> On 2019-04-09 09:32, Peter Eisentraut wrote:
> > On 2019-04-09 04:51, Stephen Frost wrote:
> >>> Running just 002_enc.pl by itself passes the tests!
> >> Great! I think what I'll do is work to incorporate the two tests back
> >> into one script, to avoid whatever the race condition or other confusion
> >> is happening on macOS here.
> >
> > That seems reasonable. It also avoids the large amount of duplicate
> > setup code.
>
> Another problem is that the two test files cannot be run in parallel
> because they use the same hardcoded data directories. That would have
> to be replaced by temporary directories.

The tests are really fast enough with one KDC that I don't think it
makes sense to have two independent tests.

> The race condition alluded to above appears to be simply that at the end
> of the test the kdc is shut down by kill -INT but nothing waits for that
> to finish before a new one is started by the next test. So there is
> potential for all kinds of confusion.

Ah, good to know that's what was happening.

> Putting it all in one test file seems to be the easiest way out.

Please find attached a patch which updates the protocol.sgml docs that
Michael mentioned before, and merges the tests into one test file (while
adding in some additional tests to make sure that the server also agrees
with what our expectations are, using the pg_stat_gssapi view).

I'll push this soon unless there are concerns. If you get a chance to
test the patch out, that would be great. It's working happily for me
locally.

Thanks!

Stephen

Attachment Content-Type Size
gssapi-doc-test-fixes_v1.patch text/x-diff 16.2 KB

From: Robbie Harwood <rharwood(at)redhat(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>, Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Michael Paquier <michael(at)paquier(dot)xyz>, Nico Williams <nico(at)cryptonector(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-15 21:45:31
Message-ID: jlgo957nds4.fsf@redhat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:

> Please find attached a patch which updates the protocol.sgml docs that
> Michael mentioned before, and merges the tests into one test file
> (while adding in some additional tests to make sure that the server
> also agrees with what our expectations are, using the pg_stat_gssapi
> view).

I can't speak to the Perl, but the documentation matches what I think
the code does :)

Thanks,
--Robbie


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-16 04:36:41
Message-ID: 20190416043641.GE2673@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, Apr 15, 2019 at 08:24:52AM -0400, Stephen Frost wrote:
> The tests are really fast enough with one KDC that I don't think it
> makes sense to have two independent tests.

Perhaps you should add a comment about the need of unicity at the top
of 001_auth.pl with a short description of the test?

> Please find attached a patch which updates the protocol.sgml docs that
> Michael mentioned before, and merges the tests into one test file (while
> adding in some additional tests to make sure that the server also agrees
> with what our expectations are, using the pg_stat_gssapi view).

Thanks for addressing all that feedback. Parallel runs look more
stable on my side. At least it seems that I can re-enable it safely.

> I'll push this soon unless there are concerns. If you get a chance to
> test the patch out, that would be great. It's working happily for me
> locally.

+ calling gss_init_sec_context() in a loop and sending the result to the
Some markups should be added here for all function names. Not all the
clients use C either, so you may want to say "or equivalent"?

+test_access($node, 'test1', 'SELECT gss_authenticated AND encrypted
from pg_stat_gssapi where pid = pg_backend_pid();', 0, '', 'succeeds
with mapping with default gssencmode and host hba');
+test_access($node, "test1", 'SELECT gss_authenticated AND encrypted
from pg_stat_gssapi where pid = pg_backend_pid();', 0,
"gssencmode=prefer", "succeeds with GSS-encrypted access preferred
with host hba");
+test_access($node, "test1", 'SELECT gss_authenticated AND encrypted
from pg_stat_gssapi where pid = pg_backend_pid();', 0,
"gssencmode=require", "succeeds with GSS-encrypted access required
with host hba");
If you could rework a bit the indentation of the new code added in
kerberos/t/001_auth.pl that would be nice. I am afraid that the
current format makes debugging harder than necessary.

+$node->append_conf('pg_hba.conf',
+ qq{hostgssenc all all $hostaddr/32 gss map=mymap});
+$node->restart;
A reload should be enough but not race-condition free, which is why a
set of restarts is done in this test right? (I have noticed that it
is done this way since the beginning.)
--
Michael


From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-16 06:57:59
Message-ID: 450e8ba3-e18f-6f00-0e67-9a37fbf5f82f@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2019-04-16 06:36, Michael Paquier wrote:
> +$node->append_conf('pg_hba.conf',
> + qq{hostgssenc all all $hostaddr/32 gss map=mymap});
> +$node->restart;
> A reload should be enough but not race-condition free, which is why a
> set of restarts is done in this test right? (I have noticed that it
> is done this way since the beginning.)

We got rid of all the reloads in these kinds of tests because they have
the effect that if the configuration has an error, the reload just
ignores it.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-20 01:25:14
Message-ID: 20190420012514.GS6197@tamriel.snowman.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Greetings,

* Michael Paquier (michael(at)paquier(dot)xyz) wrote:
> On Mon, Apr 15, 2019 at 08:24:52AM -0400, Stephen Frost wrote:
> > The tests are really fast enough with one KDC that I don't think it
> > makes sense to have two independent tests.
>
> Perhaps you should add a comment about the need of unicity at the top
> of 001_auth.pl with a short description of the test?

I added some comments there that I think explain why it makes sense to
have just one test file there.

> > Please find attached a patch which updates the protocol.sgml docs that
> > Michael mentioned before, and merges the tests into one test file (while
> > adding in some additional tests to make sure that the server also agrees
> > with what our expectations are, using the pg_stat_gssapi view).
>
> Thanks for addressing all that feedback. Parallel runs look more
> stable on my side. At least it seems that I can re-enable it safely.

Great, glad to hear it.

> > I'll push this soon unless there are concerns. If you get a chance to
> > test the patch out, that would be great. It's working happily for me
> > locally.
>
> + calling gss_init_sec_context() in a loop and sending the result to the
> Some markups should be added here for all function names. Not all the
> clients use C either, so you may want to say "or equivalent"?

I added the markups for function names along with a sentence fragment
saying that the functions referenced are the C GSSAPI bindings, and that
equivilants can be used.

> +test_access($node, 'test1', 'SELECT gss_authenticated AND encrypted
> from pg_stat_gssapi where pid = pg_backend_pid();', 0, '', 'succeeds
> with mapping with default gssencmode and host hba');
> +test_access($node, "test1", 'SELECT gss_authenticated AND encrypted
> from pg_stat_gssapi where pid = pg_backend_pid();', 0,
> "gssencmode=prefer", "succeeds with GSS-encrypted access preferred
> with host hba");
> +test_access($node, "test1", 'SELECT gss_authenticated AND encrypted
> from pg_stat_gssapi where pid = pg_backend_pid();', 0,
> "gssencmode=require", "succeeds with GSS-encrypted access required
> with host hba");
> If you could rework a bit the indentation of the new code added in
> kerberos/t/001_auth.pl that would be nice. I am afraid that the
> current format makes debugging harder than necessary.

I ran perltidy on it, sorry, should have done that before.

> +$node->append_conf('pg_hba.conf',
> + qq{hostgssenc all all $hostaddr/32 gss map=mymap});
> +$node->restart;
> A reload should be enough but not race-condition free, which is why a
> set of restarts is done in this test right? (I have noticed that it
> is done this way since the beginning.)

Right, we want this to be a restart as Peter mentions downthread.

I've now pushed these changes and will mark the open item as addressed.

Thanks!

Stephen


From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, Joe Conway <mail(at)joeconway(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, David Steele <david(at)pgmasters(dot)net>, Nico Williams <nico(at)cryptonector(dot)com>, Robbie Harwood <rharwood(at)redhat(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH v20] GSSAPI encryption support
Date: 2019-04-22 02:23:03
Message-ID: 20190422022303.GB2712@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Apr 19, 2019 at 09:25:14PM -0400, Stephen Frost wrote:
> Great, glad to hear it.

What you have committed looks fine seen from here. Thanks for taking
care of the issue, Stephen.
--
Michael