Skip to content

Commit 23ffa4f

Browse files
committed
setgid on /etc/elasticearch on package install
When creating the keystore explicitly (from executing elasticsearch-keystore create) or implicitly (for plugins that require the keystore to be created on install) on an Elasticsearch package installation, we are running as the root user. This leaves /etc/elasticsearch/elasticsearch.keystore having the wrong ownership (root:root) so that the elasticsearch user can not read the keystore on startup. This commit adds setgid to /etc/elasticsearch on package installation so that when executing this directory (as we would when creating the keystore), we will end up with the correct ownership (root:elasticsearch). Additionally, we set the permissions on the keystore to be 660 so that the elasticsearch user via its group can read this file on startup. Relates #26412
1 parent d6a7e25 commit 23ffa4f

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

core/src/main/java/org/elasticsearch/common/settings/KeyStoreWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public void save(Path configDir) throws Exception {
330330
PosixFileAttributeView attrs = Files.getFileAttributeView(keystoreFile, PosixFileAttributeView.class);
331331
if (attrs != null) {
332332
// don't rely on umask: ensure the keystore has minimal permissions
333-
attrs.setPermissions(PosixFilePermissions.fromString("rw-------"));
333+
attrs.setPermissions(PosixFilePermissions.fromString("rw-rw----"));
334334
}
335335
}
336336

distribution/src/main/packaging/scripts/postinst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ fi
100100
chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
101101
chown -R elasticsearch:elasticsearch /var/log/elasticsearch
102102
chown -R root:elasticsearch /etc/elasticsearch
103+
chmod g+s /etc/elasticsearch
103104
chmod 0750 /etc/elasticsearch
104105

105106
if [ -f /etc/default/elasticsearch ]; then

qa/vagrant/src/test/resources/packaging/utils/packages.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ verify_package_installation() {
9494
assert_file "$ESHOME/bin/elasticsearch-plugin" f root root 755
9595
assert_file "$ESHOME/bin/elasticsearch-translog" f root root 755
9696
assert_file "$ESHOME/lib" d root root 755
97-
assert_file "$ESCONFIG" d root elasticsearch 750
97+
assert_file "$ESCONFIG" d root elasticsearch 2750
9898
assert_file "$ESCONFIG/elasticsearch.yml" f root elasticsearch 660
9999
assert_file "$ESCONFIG/jvm.options" f root elasticsearch 660
100100
assert_file "$ESCONFIG/log4j2.properties" f root elasticsearch 660

0 commit comments

Comments
 (0)