Issues with building snap packages and psql

Started by Joshua D. Drakeabout 9 years ago10 messages
#1Joshua D. Drake
jd@commandprompt.com

Hello,

CMD has been working on building snap packages. It has been an adventure
and we are very close to having them complete. In fact they are complete
enough that we have published them in the snap repo.

jd@jd-wks:~$ snap find postgres
Name Version Developer Notes Summary
postgresql96 9.6.0 cmd - PostgreSQL is a powerful,
open source object-relational database system.
postgresql95 9.5.3 cmd - PostgreSQL is a powerful,
open source object-relational database system.
postgresql94 9.4.9 cmd - PostgreSQL is a powerful,
open source object-relational database system.
postgresql93 9.3.14 cmd - PostgreSQL is a powerful,
open source object-relational database system.

However, we have found a problem with permissions that we haven't been
able to overcome. The error presents as a simple:

could not save history to file "/home/jd/.psql_history": Permission denied

We tried the work around as presented here:

https://www.commandprompt.com/blog/psql_tip_change_history_location/

It didn't work and I couldn't figure out why. It was especially
confusing because if you are in psql via snap $HOME is set correctly:

postgres=# \! export
export HOME='/home/jd/snap/postgresql96/1'

Then I traced it and saw this:

open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 7
lseek(7, 0, SEEK_CUR) = 0
fstat(7, {st_mode=S_IFREG|0644, st_size=2581, ...}) = 0
mmap(NULL, 2581, PROT_READ, MAP_SHARED, 7, 0) = 0x7f1f9e5fc000
lseek(7, 2581, SEEK_SET) = 2581
munmap(0x7f1f9e5fc000, 2581) = 0
close(7) = 0
[...]
futex(0x1096088, FUTEX_WAIT, 0, NULL) = 0
futex(0x1096088, FUTEX_WAIT, 0, NULL/home/jd/.psqlrc: Permission denied
psql (9.6.0)
Type "help" for help.

postgres=# \q
could not save history to file "/home/jd/.psql_history": Permission denied
  <unfinished ...>
+++ exited with 0 +++

Is psql getting the home directory from /etc/passwd? If so what can we
do about that?

Sincerely,

JD

--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Joshua D. Drake (#1)
Re: Issues with building snap packages and psql

"Joshua D. Drake" <jd@commandprompt.com> writes:

Is psql getting the home directory from /etc/passwd?

Yes, of course.

If so what can we do about that?

Fix your /etc/passwd entry? Seems unlikely that psql is the only
program that believes that entry.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Joshua D. Drake
jd@commandprompt.com
In reply to: Tom Lane (#2)
Re: Issues with building snap packages and psql

On 10/26/2016 10:16 AM, Tom Lane wrote:

"Joshua D. Drake" <jd@commandprompt.com> writes:

Is psql getting the home directory from /etc/passwd?

Yes, of course.

If so what can we do about that?

Fix your /etc/passwd entry? Seems unlikely that psql is the only
program that believes that entry.

It isn't that simple. Snap packages are similar to a chroot. My home
directory *is* /home/jd but snap packages can't write to that because of
the isolation.

Sincerely,

JD

--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Andres Freund
andres@anarazel.de
In reply to: Joshua D. Drake (#1)
Re: Issues with building snap packages and psql

On October 26, 2016 8:09:11 PM GMT+03:00, "Joshua D. Drake" <jd@commandprompt.com> wrote:

postgres=# \! export
export HOME='/home/jd/snap/postgresql96/1'

That doesn't do much. Isn't that just spawning a shell in which you set the variable, which then immediately exits? And this the value isn't set anywhere relevant?

Andres
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Joshua D. Drake
jd@commandprompt.com
In reply to: Andres Freund (#4)
Re: Issues with building snap packages and psql

On 10/26/2016 10:26 AM, Andres Freund wrote:

On October 26, 2016 8:09:11 PM GMT+03:00, "Joshua D. Drake" <jd@commandprompt.com> wrote:

postgres=# \! export
export HOME='/home/jd/snap/postgresql96/1'

That doesn't do much. Isn't that just spawning a shell in which you set the variable, which then immediately exits? And this the value isn't set anywhere relevant?

I was assuming (and TGL corrected me) that psql was going to pull the
$HOME variable to determine where to read/write .psqlrc and .psql_history.

Sincerely,

JD

--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Joshua D. Drake
jd@commandprompt.com
In reply to: Andres Freund (#4)
Re: Issues with building snap packages and psql

Hello,

After some further investigation and collaboration with #postgresql it
looks like what we have here is an actual bug or at least improper
implementation. Apparently, we use getpwuid on the euid to locate the
'home directory'. This is incorrect (as well as inconsistent to our own
documentation) [1]. Our documentation says that dotfiles are
~/.whatever, and ~ on its own in shell means the value of $HOME, it does
NOT mean the current user's homedir from getpwuid.

It is also inconsistent with how other programs behave. For example if
psql uses readline, and you change the value of $HOME, then readline
uses $HOME/.inputrc whereas psql does not use $HOME/.psqlrc.

Sincerely,

JD

1.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01

--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Robert Haas
robertmhaas@gmail.com
In reply to: Joshua D. Drake (#6)
Re: Issues with building snap packages and psql

On Wed, Oct 26, 2016 at 2:22 PM, Joshua D. Drake <jd@commandprompt.com> wrote:

After some further investigation and collaboration with #postgresql it looks
like what we have here is an actual bug or at least improper implementation.
Apparently, we use getpwuid on the euid to locate the 'home directory'. This
is incorrect (as well as inconsistent to our own documentation) [1]. Our
documentation says that dotfiles are ~/.whatever, and ~ on its own in shell
means the value of $HOME, it does NOT mean the current user's homedir from
getpwuid.

It is also inconsistent with how other programs behave. For example if psql
uses readline, and you change the value of $HOME, then readline uses
$HOME/.inputrc whereas psql does not use $HOME/.psqlrc.

Sounds like the same issue that Rudolf Gavlas complained about in
/messages/by-id/CAEH6cQqbdbXoUHJBbX9ixwfjFFsUC-a8hFntKcci=diWgBb3fQ@mail.gmail.com

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8Joshua D. Drake
jd@commandprompt.com
In reply to: Robert Haas (#7)
Re: Issues with building snap packages and psql

On 10/26/2016 11:33 AM, Robert Haas wrote:

On Wed, Oct 26, 2016 at 2:22 PM, Joshua D. Drake <jd@commandprompt.com> wrote:

After some further investigation and collaboration with #postgresql it looks
like what we have here is an actual bug or at least improper implementation.
Apparently, we use getpwuid on the euid to locate the 'home directory'. This
is incorrect (as well as inconsistent to our own documentation) [1]. Our
documentation says that dotfiles are ~/.whatever, and ~ on its own in shell
means the value of $HOME, it does NOT mean the current user's homedir from
getpwuid.

It is also inconsistent with how other programs behave. For example if psql
uses readline, and you change the value of $HOME, then readline uses
$HOME/.inputrc whereas psql does not use $HOME/.psqlrc.

Sounds like the same issue that Rudolf Gavlas complained about in
/messages/by-id/CAEH6cQqbdbXoUHJBbX9ixwfjFFsUC-a8hFntKcci=diWgBb3fQ@mail.gmail.com

It does sound similar, unfortunately the limited response doesn't seem
to address the issue in that we are doing it in a way that nobody (or at
least commonly) else does.

To me this sounds strikingly familiar to how we ignored how everyone
else handled commenting out parameters vs how we thought we were right
until we finally decided everyone else was already correct and changed
it. (metaphorically speaking)

That said, I am not interested in a philosophical argument. It appears
to me that based on the referenced PDF that we are wrong. How do we fix
it? What are the implications of that? I just want to solve the problem.

Sincerely,

JD

--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Joshua D. Drake
jd@commandprompt.com
In reply to: Joshua D. Drake (#8)
Re: Issues with building snap packages and psql

On 10/26/2016 12:10 PM, Joshua D. Drake wrote:

On 10/26/2016 11:33 AM, Robert Haas wrote:

On Wed, Oct 26, 2016 at 2:22 PM, Joshua D. Drake

It is also inconsistent with how other programs behave. For example
if psql
uses readline, and you change the value of $HOME, then readline uses
$HOME/.inputrc whereas psql does not use $HOME/.psqlrc.

Sounds like the same issue that Rudolf Gavlas complained about in
/messages/by-id/CAEH6cQqbdbXoUHJBbX9ixwfjFFsUC-a8hFntKcci=diWgBb3fQ@mail.gmail.com

This problem clearly an improper implementation on our part. We have
found a work around by wrapping the launch of psql so we can set PSQLRC.
At some point, perhaps with v10 we could change this. This problem has
been noted on other ends of the innertubes as well (we submitted this as
a potential bug to Ubuntu and they too found that we don't handle this
correctly).

Sincerely,

JD

--
Command Prompt, Inc. http://the.postgres.company/
+1-503-667-4564
PostgreSQL Centered full stack support, consulting and development.
Everyone appreciates your honesty, until you are honest with them.
Unless otherwise stated, opinions are my own.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Robert Haas
robertmhaas@gmail.com
In reply to: Joshua D. Drake (#9)
Re: Issues with building snap packages and psql

On Thu, Oct 27, 2016 at 12:24 PM, Joshua D. Drake <jd@commandprompt.com> wrote:

This problem clearly an improper implementation on our part. We have found a
work around by wrapping the launch of psql so we can set PSQLRC. At some
point, perhaps with v10 we could change this. This problem has been noted on
other ends of the innertubes as well (we submitted this as a potential bug
to Ubuntu and they too found that we don't handle this correctly).

Yes, I think the evidence is growing that we ought to change this.

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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers