From 0964a52251220f63432330a361a964f029d1d3d4 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 12 Mar 2018 23:52:21 -0700 Subject: [PATCH 1/3] Packaging: Set elasticsearch homedir This commit adds setting the homedir for the elasticsearch user to the adduser command in the packaging preinstall script. While the elasticsearch user is a system user, it is sometimes conventient to have an existing homedir (even if it is not writeable). For example, running cron as the elasticsearch user will try to change dir to the homedir. closes #14453 --- distribution/packages/src/common/scripts/preinst | 6 ++++-- qa/vagrant/src/test/resources/packaging/utils/packages.bash | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/distribution/packages/src/common/scripts/preinst b/distribution/packages/src/common/scripts/preinst index a9e5295cbc56d..b309d67864cee 100644 --- a/distribution/packages/src/common/scripts/preinst +++ b/distribution/packages/src/common/scripts/preinst @@ -27,6 +27,7 @@ case "$1" in adduser --quiet \ --system \ --no-create-home \ + --home-dir /usr/share/elasticsearch \ --ingroup elasticsearch \ --disabled-password \ --shell /bin/false \ @@ -50,8 +51,9 @@ case "$1" in # Create elasticsearch user if not existing if ! id elasticsearch > /dev/null 2>&1 ; then echo -n "Creating elasticsearch user..." - useradd -r \ - -M \ + useradd --system \ + --no-create-home \ + --home-dir /usr/share/elasticsearch \ --gid elasticsearch \ --shell /sbin/nologin \ --comment "elasticsearch user" \ diff --git a/qa/vagrant/src/test/resources/packaging/utils/packages.bash b/qa/vagrant/src/test/resources/packaging/utils/packages.bash index 01ad9258cdbed..f0a5a66894d2b 100644 --- a/qa/vagrant/src/test/resources/packaging/utils/packages.bash +++ b/qa/vagrant/src/test/resources/packaging/utils/packages.bash @@ -87,6 +87,8 @@ verify_package_installation() { id elasticsearch getent group elasticsearch + # homedir is set in /etc/passwd + assert_file $(getent passwd elasticsearch | cut -d: -f6) d root root 755 assert_file "$ESHOME" d root root 755 assert_file "$ESHOME/bin" d root root 755 From f197957c823c6e580447e6440bd54193268fad19 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 13 Mar 2018 22:49:34 -0700 Subject: [PATCH 2/3] fix homedir option --- distribution/packages/src/common/scripts/preinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/packages/src/common/scripts/preinst b/distribution/packages/src/common/scripts/preinst index b309d67864cee..cb5ab095c2595 100644 --- a/distribution/packages/src/common/scripts/preinst +++ b/distribution/packages/src/common/scripts/preinst @@ -27,7 +27,7 @@ case "$1" in adduser --quiet \ --system \ --no-create-home \ - --home-dir /usr/share/elasticsearch \ + --home /usr/share/elasticsearch \ --ingroup elasticsearch \ --disabled-password \ --shell /bin/false \ From 36ec74738360b9ecc84489d6b98b5d8c76b77831 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 17 Apr 2018 11:18:22 -0700 Subject: [PATCH 3/3] change to nonexistent directory --- distribution/packages/src/common/scripts/preinst | 4 ++-- qa/vagrant/src/test/resources/packaging/utils/packages.bash | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/distribution/packages/src/common/scripts/preinst b/distribution/packages/src/common/scripts/preinst index cb5ab095c2595..2aec2172ad856 100644 --- a/distribution/packages/src/common/scripts/preinst +++ b/distribution/packages/src/common/scripts/preinst @@ -27,7 +27,7 @@ case "$1" in adduser --quiet \ --system \ --no-create-home \ - --home /usr/share/elasticsearch \ + --home /nonexistent \ --ingroup elasticsearch \ --disabled-password \ --shell /bin/false \ @@ -53,7 +53,7 @@ case "$1" in echo -n "Creating elasticsearch user..." useradd --system \ --no-create-home \ - --home-dir /usr/share/elasticsearch \ + --home-dir /nonexistent \ --gid elasticsearch \ --shell /sbin/nologin \ --comment "elasticsearch user" \ diff --git a/qa/vagrant/src/test/resources/packaging/utils/packages.bash b/qa/vagrant/src/test/resources/packaging/utils/packages.bash index f0a5a66894d2b..9fc037632b9de 100644 --- a/qa/vagrant/src/test/resources/packaging/utils/packages.bash +++ b/qa/vagrant/src/test/resources/packaging/utils/packages.bash @@ -87,8 +87,8 @@ verify_package_installation() { id elasticsearch getent group elasticsearch - # homedir is set in /etc/passwd - assert_file $(getent passwd elasticsearch | cut -d: -f6) d root root 755 + # homedir is set in /etc/passwd but to a non existent directory + assert_file_not_exist $(getent passwd elasticsearch | cut -d: -f6) assert_file "$ESHOME" d root root 755 assert_file "$ESHOME/bin" d root root 755