Re: pg_hba.conf: samehost and samenet

Lists: pgsql-hackers
From: Stef Walter <stef-list(at)memberwebs(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: pg_hba.conf: samehost and samenet
Date: 2009-08-13 22:50:35
Message-ID: 20090813225034.068DC3039745@mx.npubs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I love using postgresql, and have for a long time. I'm involved with
almost a hundred postgresql installs. But this is the first time I've
gotten into the code.

Renumbering networks happens often, and will happen more frequently as
IPv4 space runs low. The IP based restrictions in pg_hba.conf is one of
the places where renumbering can break running installs. In addition
when postgresql is run in BSD jails, 127.0.0.1 is not available for use
in pg_hba.conf.

It would be great if, in the cidr-address field of pg_hba.conf, we could
specify "samehost" and "samenet". These special values use the local
hosts network interface addresses. "samehost" allows an IP assigned to
the local machine. "samenet" allows any host on the subnets connected to
the local machine.

This is similar to the "sameuser" value that's allowed in the database
field.

A change like this would enable admins like myself to distribute
postgresql with something like this in the default pg_hba.conf file:

host all all samenet md5
hostssl all all 0.0.0.0/0 md5

I've attached an initial patch which implements "samehost" and
"samenet". The patch looks more invasive than it really is, due to
necessary indentation change (ie: a if block), and moving some code into
a separate function.

Thanks for your time. How can I help get a feature like this into
postgresql?

Cheers,

Stef

Attachment Content-Type Size
postgres-hba-samenet-1.patch text/x-diff 18.2 KB

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: stef(at)memberwebs(dot)com
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-14 08:42:23
Message-ID: 9837222c0908140142n210021c1tf9ed12d826c1026a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Aug 14, 2009 at 00:50, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
> I love using postgresql, and have for a long time. I'm involved with
> almost a hundred postgresql installs. But this is the first time I've
> gotten into the code.
>
> Renumbering networks happens often, and will happen more frequently as
> IPv4 space runs low. The IP based restrictions in pg_hba.conf is one of
> the places where renumbering can break running installs. In addition
> when postgresql is run in BSD jails, 127.0.0.1 is not available for use
> in pg_hba.conf.
>
> It would be great if, in the cidr-address field of pg_hba.conf, we could
> specify "samehost" and "samenet". These special values use the local
> hosts network interface addresses. "samehost" allows an IP assigned to
> the local machine. "samenet" allows any host on the subnets connected to
> the local machine.
>
> This is similar to the "sameuser" value that's allowed in the database
> field.
>
> A change like this would enable admins like myself to distribute
> postgresql with something like this in the default pg_hba.conf file:
>
> host      all     all   samenet         md5
> hostssl   all     all   0.0.0.0/0       md5

Seems like a reasonable feature - especially the samehost part.

> I've attached an initial patch which implements "samehost" and
> "samenet". The patch looks more invasive than it really is, due to
> necessary indentation change (ie: a if block), and moving some code into
> a separate function.

A couple of comments on the patch:

* In general, don't include configure in the patch. Just configure.in.
Makes it easier to read, and configure is normally built by the
committer anyway.

* How portable is this? For starters is clearly doesn't do Windows,
which would need to be investigated for similar functionality, but how
many others support getifaddr()? From what I can tell it's not in
POSIX, at least.

* The checks for "not supported" should happen at parsing time, not at runtime.

* It needs to include documentation changes

I haven't looked at the guts of the patch yet, those are just a couple
of first questions.

> Thanks for your time. How can I help get a feature like this into
> postgresql?

Please add it to the open commitfest
(https://commitfest.postgresql.org/action/commitfest_view/open). This
will cause it to be reviewed during the next commitfest, and then you
just need to be around to answer any questions that reviewers come up
with :-)

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


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: stef(at)memberwebs(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-14 14:29:27
Message-ID: 8606.1250260167@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander <magnus(at)hagander(dot)net> writes:
> On Fri, Aug 14, 2009 at 00:50, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
>> It would be great if, in the cidr-address field of pg_hba.conf, we could
>> specify "samehost" and "samenet".

> Seems like a reasonable feature - especially the samehost part.

ISTM people have traditionally used 127.0.0.1 and ::1 for "samehost"
behavior. What's being suggested here is a tad more flexible but
hardly a huge advance. As for "samenet", personally I'd be scared to
death of something like that --- who knows how wide the OS will
think your "net" is? (Think cable modem users on 10.x.x.x ...)
Using samenet in a conf file that's being handed out to random users
seems impossibly dangerous.

However, I wouldn't object too much if it weren't for this:

> * How portable is this? For starters is clearly doesn't do Windows,
> which would need to be investigated for similar functionality, but how
> many others support getifaddr()? From what I can tell it's not in
> POSIX, at least.

I don't see it on HPUX, for one. Unless a portable solution can be
found I don't think we can consider this. We're not in the habit
of exposing significant functionality that's only available on some
platforms.

regards, tom lane


From: Stef Walter <stef-list(at)memberwebs(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-14 20:26:32
Message-ID: 20090814202631.31AC9303982F@mx.npubs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander wrote:
>
> A couple of comments on the patch:

Thanks I'll keep these in mind, as things progress and for future patches.

> * In general, don't include configure in the patch. Just configure.in.
> Makes it easier to read, and configure is normally built by the
> committer anyway.
>
> * How portable is this? For starters is clearly doesn't do Windows,
> which would need to be investigated for similar functionality, but how
> many others support getifaddr()? From what I can tell it's not in
> POSIX, at least.

I'll look further into this, and about compat shims. getifaddrs() is on
the BSDs, Linux and Mac OS.

> Please add it to the open commitfest
> (https://commitfest.postgresql.org/action/commitfest_view/open). This
> will cause it to be reviewed during the next commitfest, and then you
> just need to be around to answer any questions that reviewers come up
> with :-)

Cool, I'll do that once we've worked out the kinks here. Is the right
way to go about it?

Cheers,

Stef


From: Stef Walter <stef-list(at)memberwebs(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-14 20:32:33
Message-ID: 20090814203231.CD2B13039746@mx.npubs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane wrote:
> Magnus Hagander <magnus(at)hagander(dot)net> writes:
>> On Fri, Aug 14, 2009 at 00:50, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
>>> It would be great if, in the cidr-address field of pg_hba.conf, we could
>>> specify "samehost" and "samenet".
>
>> Seems like a reasonable feature - especially the samehost part.
>
> ISTM people have traditionally used 127.0.0.1 and ::1 for "samehost"
> behavior.

Yes for sure. As noted in the original email 127.0.0.1 doesn't work as
you would expect in BSD jails. As it currently stands, you have to put
the local IP address to achieve similar access control. This causes
major pains when renumbering or dealing with postgresql hosted in large
amounts of jails.

Another way we could sort of get around most of these renumbering
problems, is by the ability to include host names in pg_hba.conf, rather
than IP addresses. I first set out to implement this, but as advised in
"How to Contribute" looked around the mailing lists for previous
discussion on the topic and found this:

http://archives.postgresql.org/pgsql-hackers/2008-06/msg00569.php

There seems to be no consensus in the postgresql community about this
feature, and its implementation. The last guy who tried to work on it
got scared away, and so I decided to try an approach that might be more
palatable.

I'm willing to put in the work on either approach, and I could revive
discussion about host names in pg_hba.conf if that's more desirable.

What's being suggested here is a tad more flexible but
> hardly a huge advance. As for "samenet", personally I'd be scared to
> death of something like that --- who knows how wide the OS will
> think your "net" is? (Think cable modem users on 10.x.x.x ...)
> Using samenet in a conf file that's being handed out to random users
> seems impossibly dangerous.

I understand what you're saying. In this case it would be handed out to
hosted clients and those sorts of users. ie: a controlled environment.
Obviously this wouldn't go into the default postgresql pg_hba.conf.

> However, I wouldn't object too much if it weren't for this:
>
>> * How portable is this? For starters is clearly doesn't do Windows,
>> which would need to be investigated for similar functionality, but how
>> many others support getifaddr()? From what I can tell it's not in
>> POSIX, at least.
>
> I don't see it on HPUX, for one. Unless a portable solution can be
> found I don't think we can consider this. We're not in the habit
> of exposing significant functionality that's only available on some
> platforms.

True. I could build compatibility getifaddrs for various systems, if the
community thought this patch was worth it, and would otherwise accept
the patch.

Cheers,

Stef


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: stef(at)memberwebs(dot)com
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-14 20:42:12
Message-ID: 28086.1250282532@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stef Walter <stef-list(at)memberwebs(dot)com> writes:
> True. I could build compatibility getifaddrs for various systems, if the
> community thought this patch was worth it, and would otherwise accept
> the patch.

If you can do that I think it'd remove the major objection.

regards, tom lane


From: Stef Walter <stef-list(at)memberwebs(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-19 01:58:11
Message-ID: 20090819015810.7FCF2303974B@mx.npubs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Attached is a new patch, which I hope addresses all the concerns raised.

Magnus Hagander wrote:
>> I've attached an initial patch which implements "samehost" and
>> "samenet". The patch looks more invasive than it really is, due to
>> necessary indentation change (ie: a if block), and moving some code into
>> a separate function.
>
> A couple of comments on the patch:
>
> * In general, don't include configure in the patch. Just configure.in.
> Makes it easier to read, and configure is normally built by the
> committer anyway.

Removed configure and pg_config.h.in from the patch.

> * How portable is this? For starters is clearly doesn't do Windows,
> which would need to be investigated for similar functionality, but how
> many others support getifaddr()? From what I can tell it's not in
> POSIX, at least.

getifaddr() is at least supported on *BSD, Linux and AIX.

In the new patch, I've added support for other unixes like Solaris,
HPUX, IRIC, SCO Unix (using the SIOCGIFCONF ioctl). Also included is
Win32 support (using winsock's SIO_GET_INTERFACE_LIST).

Obviously I don't have all of the above proprietary unixes to test on,
but I've studied documentation, and I believe that the code in the patch
will run on those systems.

> * It needs to include documentation changes

Done.

> Please add it to the open commitfest
> (https://commitfest.postgresql.org/action/commitfest_view/open). This
> will cause it to be reviewed during the next commitfest, and then you
> just need to be around to answer any questions that reviewers come up
> with :-)

I need some sort of a login to add a patch to the commit fest. Is that
something I can get? Or is there someone I should ask to add my patch to
the commit fest? I hope I'm not being dense and missing something
obvious. :)

Cheers,

Stef


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: stef(at)memberwebs(dot)com
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, pgsql-hackers(at)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-19 02:11:46
Message-ID: 9978.1250647906@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Stef Walter <stef-list(at)memberwebs(dot)com> writes:
> Magnus Hagander wrote:
>> Please add it to the open commitfest
>> (https://commitfest.postgresql.org/action/commitfest_view/open). This
>> will cause it to be reviewed during the next commitfest, and then you
>> just need to be around to answer any questions that reviewers come up
>> with :-)

> I need some sort of a login to add a patch to the commit fest. Is that
> something I can get?

Go here:
http://www.postgresql.org/community/signup

The login page for the commitfest app really ought to provide a link
to that ... Robert?

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: stef(at)memberwebs(dot)com, Magnus Hagander <magnus(at)hagander(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-19 02:53:23
Message-ID: 603c8f070908181953o240c02c1i8556ebef720a1b85@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Aug 18, 2009 at 10:11 PM, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Stef Walter <stef-list(at)memberwebs(dot)com> writes:
>> Magnus Hagander wrote:
>>> Please add it to the open commitfest
>>> (https://commitfest.postgresql.org/action/commitfest_view/open). This
>>> will cause it to be reviewed during the next commitfest, and then you
>>> just need to be around to answer any questions that reviewers come up
>>> with :-)
>
>> I need some sort of a login to add a patch to the commit fest. Is that
>> something I can get?
>
> Go here:
> http://www.postgresql.org/community/signup
>
> The login page for the commitfest app really ought to provide a link
> to that ... Robert?

Done.

...Robert


From: Magnus Hagander <magnus(at)hagander(dot)net>
To: stef(at)memberwebs(dot)com
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-19 11:47:39
Message-ID: 9837222c0908190447y59553825w399a01a0d410975f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 19, 2009 at 03:58, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
> Attached is a new patch, which I hope addresses all the concerns raised.

I think you forgot to actually attach the patch....

(others have taken care of the question about login already I see)

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


From: Stef Walter <stef-list(at)memberwebs(dot)com>
To: Magnus Hagander <magnus(at)hagander(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-19 13:02:26
Message-ID: 20090819130221.9EBCE3039742@mx.npubs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Magnus Hagander wrote:
> On Wed, Aug 19, 2009 at 03:58, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
>> Attached is a new patch, which I hope addresses all the concerns raised.
>
> I think you forgot to actually attach the patch....

Whoops. Here it is.

Stef

Attachment Content-Type Size
postgres-hba-samenet-2.patch text/x-diff 18.9 KB

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: stef(at)memberwebs(dot)com
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: pg_hba.conf: samehost and samenet
Date: 2009-08-25 12:19:16
Message-ID: 9837222c0908250519i5a5e1345l2de736752fe00a63@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 19, 2009 at 15:02, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
> Magnus Hagander wrote:
>> On Wed, Aug 19, 2009 at 03:58, Stef Walter<stef-list(at)memberwebs(dot)com> wrote:
>>> Attached is a new patch, which I hope addresses all the concerns raised.
>>
>> I think you forgot to actually attach the patch....
>
> Whoops. Here it is.

Is there any actual advantage to using getifaddr() on Linux, and not
just use SIOCGIFCONF for all Unixen?

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