Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security auto-configuration for packaged installations #75144

Merged
merged 293 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 104 commits
Commits
Show all changes
293 commits
Select commit Hold shift + click to select a range
7d9b6f5
generate password on installation time and show it to the user. We se…
jkakavas Jul 13, 2021
2598dd3
More error handling
albertzaharovits Jul 13, 2021
9c29107
Merge branch 'master' into auto_conf_security
albertzaharovits Jul 14, 2021
e566c3e
Merge branch 'auto_conf_security' into packaged-auto-conf
jkakavas Jul 14, 2021
d104c9b
add undocumented parameter to the autoconfig CLI tool so that users d…
jkakavas Jul 14, 2021
38ba6b5
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 3, 2021
6fd7123
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 9, 2021
3ecbb0f
remove old version of file
jkakavas Aug 9, 2021
576b608
no need to all a CLI tool from postinst
jkakavas Aug 9, 2021
d566434
wip
jkakavas Aug 9, 2021
3aab03e
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 9, 2021
21fcc13
add class to generate and store password hash
jkakavas Aug 10, 2021
6d924e5
more wip
jkakavas Aug 10, 2021
6fd451e
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 20, 2021
0d4ad2f
more wip - commit to run some packaging tests
jkakavas Aug 21, 2021
1239ab7
spotless
jkakavas Aug 21, 2021
75c26e2
sudo -g doesn't work in all OS
jkakavas Aug 21, 2021
b88f1ec
create .elasticsearch.keystore.initial_md5sum
jkakavas Aug 21, 2021
0113694
fix tests?
jkakavas Aug 22, 2021
dcc40e3
fix filtering
jkakavas Aug 22, 2021
776a155
remove auto-config dir on purge
jkakavas Aug 23, 2021
882c191
fix filtering
jkakavas Aug 23, 2021
f0b1a38
spotless
jkakavas Aug 23, 2021
fd4e4f9
further test fixes
jkakavas Aug 23, 2021
ea8dfb9
fix purging
jkakavas Aug 23, 2021
26ec0e3
more
jkakavas Aug 23, 2021
072a672
fix purging?
jkakavas Aug 23, 2021
b58fe80
create first
jkakavas Aug 23, 2021
6cc80bf
correct updated permissions in tests
jkakavas Aug 23, 2021
f6a313d
d
jkakavas Aug 23, 2021
c1fa865
one of these days, packaging tests... one of these days...
jkakavas Aug 23, 2021
776de7c
remove keystore on purge
jkakavas Aug 23, 2021
3a37699
fix group owner
jkakavas Aug 23, 2021
f6ecd0d
Fix test matcher
jkakavas Aug 23, 2021
5c732e2
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 23, 2021
680503f
Revert unecessary changes
jkakavas Aug 23, 2021
5fb7152
fix
jkakavas Aug 23, 2021
bc1c78a
revert unncessary change
jkakavas Aug 23, 2021
1e702a5
make banners shorter
jkakavas Aug 23, 2021
076f1f9
change upgrade test
jkakavas Aug 23, 2021
c88cbc6
hopefully make a meaningful test this time
jkakavas Aug 23, 2021
72fc1fd
one last time..
jkakavas Aug 23, 2021
a97c469
fix ownership
jkakavas Aug 23, 2021
7b70758
typos
jkakavas Aug 23, 2021
7a48d74
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 23, 2021
19df189
simplify postinst
jkakavas Aug 23, 2021
3bf3962
add check for package upgades
jkakavas Aug 23, 2021
9a2f6ef
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 23, 2021
7bbb58d
Possible disable security when upgrading to 8.0.0 (temporarily)
jkakavas Aug 23, 2021
99485ea
minor changes to postinst and some additional tests
jkakavas Aug 24, 2021
7db3187
null check
jkakavas Aug 24, 2021
9ed95b1
meh
jkakavas Aug 24, 2021
2ab4d37
meh^2
jkakavas Aug 24, 2021
9f81dab
one of these days, I'll figure out how to read docs
jkakavas Aug 24, 2021
5f65641
tighten test assertion
jkakavas Aug 24, 2021
423dbd6
Update docs/changelog/75144.yaml
jkakavas Aug 24, 2021
639f5fd
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Aug 24, 2021
f73aa25
Single area label!
jkakavas Aug 24, 2021
d7e8cf4
change changelog
jkakavas Sep 1, 2021
3c8416c
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Sep 1, 2021
5f173f9
Merge branch 'master' into packaged-auto-conf
elasticmachine Sep 2, 2021
15e1eff
Merge branch 'master' into packaged-auto-conf
elasticmachine Sep 2, 2021
2795c3a
Attemp TLS config
albertzaharovits Sep 3, 2021
bc28f81
Checkstyle
albertzaharovits Sep 3, 2021
d0a1122
Crazy typo
albertzaharovits Sep 3, 2021
48c7c80
move does not support attributes
albertzaharovits Sep 3, 2021
d0c9270
Archives
albertzaharovits Sep 3, 2021
d0ad3c1
Nit
albertzaharovits Sep 3, 2021
c75dda6
Spotless
albertzaharovits Sep 3, 2021
71bd34d
Facepalm
albertzaharovits Sep 3, 2021
fa4b93e
QA OS Make request with https
albertzaharovits Sep 3, 2021
83d4036
Merge branch 'master' into config_tls_when_node_starts
albertzaharovits Sep 3, 2021
cce8094
working on archive tests
albertzaharovits Sep 3, 2021
9c82a71
Archives tests still
albertzaharovits Sep 3, 2021
7afeee2
ArchiveTests test51
albertzaharovits Sep 3, 2021
169b3e7
ArchiveTests still
albertzaharovits Sep 3, 2021
a05bb85
Commons io FileUtils
albertzaharovits Sep 3, 2021
b66c345
Commons io precommit
albertzaharovits Sep 4, 2021
230a364
Verbose auto-conf pacakging tests
albertzaharovits Sep 4, 2021
26ad69a
More info about why the node doesn't start
albertzaharovits Sep 4, 2021
f9b74fd
Remove explicit CLI tool
jkakavas Sep 6, 2021
4360d08
Updates from feedback
jkakavas Sep 6, 2021
b0cbdfc
fix cert DN and remove references to deleted CLI tool
jkakavas Sep 6, 2021
1feac33
don't exit with 0 all the time
jkakavas Sep 6, 2021
5dc4258
more packaging
jkakavas Sep 6, 2021
c05732d
more packaging2
jkakavas Sep 6, 2021
4dcbc84
remove tripping assertion
jkakavas Sep 10, 2021
4f0a743
Enable nodes running TEST INTEG distribution to call ConfigInitialNod…
jkakavas Sep 10, 2021
3535b00
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 10, 2021
26e7811
fix keystore management tests
jkakavas Sep 10, 2021
7dcfd2f
test20KeystorePasswordOnStandardInput runs before we ever start the n…
jkakavas Sep 10, 2021
f86e6a8
Wait for enough time for ES in docker to complete auto-configuration
jkakavas Sep 10, 2021
11834f1
missing colon that took me 4 hours to spot
jkakavas Sep 10, 2021
bdcd267
more test fixes
jkakavas Sep 10, 2021
d83fd6c
take TLS autoconfiguration in consideration for ArchiveGenerateInitia…
jkakavas Sep 10, 2021
d90104b
guess what
jkakavas Sep 10, 2021
9fd5e77
:/ :(
jkakavas Sep 10, 2021
0ef54aa
Use autoconfigured TLS when needed in Docker, disable it otherwise
jkakavas Sep 11, 2021
da5e3de
fix docker (for good ?) and print debug to retain my sanity
jkakavas Sep 11, 2021
c29e3e7
what's another commit
jkakavas Sep 11, 2021
c8785c4
disable auto-configuration in unrelated docker tests, fix stupid bug …
jkakavas Sep 12, 2021
1498131
On linux too
jkakavas Sep 12, 2021
84046fd
Create user after we verify installation so that upon installation ve…
jkakavas Sep 12, 2021
cd8c285
We might not have an elasticsearch.yml file in Docker
jkakavas Sep 12, 2021
182c45d
revert previous unnecessary changes
jkakavas Sep 12, 2021
8ac2890
spotless
jkakavas Sep 12, 2021
1e439a6
more adjustments
jkakavas Sep 12, 2021
48da88c
more adjustments
jkakavas Sep 12, 2021
dd5f118
this should fix all in linux
jkakavas Sep 12, 2021
9791b77
plugin and configuration tests
jkakavas Sep 12, 2021
71c934e
some more
jkakavas Sep 13, 2021
bc68b30
some more
jkakavas Sep 13, 2021
9cd79e0
config tests
jkakavas Sep 13, 2021
69990d1
add temp debug info
jkakavas Sep 13, 2021
6221408
get the certificate from the right path
jkakavas Sep 13, 2021
a754c1e
add support for auto-configuration to windows batch file
jkakavas Sep 16, 2021
c150a08
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 16, 2021
3f1d58a
Docker packaging tests now use auto-configured TLS
jkakavas Sep 19, 2021
73be68f
CertGenCliTests do not need TLS auto-configuration
jkakavas Sep 19, 2021
a69986c
cleanup
jkakavas Sep 19, 2021
c55d9dd
spotless
jkakavas Sep 19, 2021
deafd2d
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 19, 2021
ec3c51f
fix certgen tests
jkakavas Sep 19, 2021
6ccf723
don't sstop on success
jkakavas Sep 20, 2021
c1771d8
minor updates
jkakavas Sep 20, 2021
749ba9b
fix
jkakavas Sep 21, 2021
084b2f9
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 21, 2021
a8f7c47
Catch Throwables and amend how we populate SANs for certificates
jkakavas Sep 21, 2021
a5baae0
add more tests
jkakavas Sep 21, 2021
28bca9e
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 21, 2021
90a9022
spotless
jkakavas Sep 21, 2021
90bd0f6
minor fixes
jkakavas Sep 21, 2021
7d2219c
cleanup data dir after test to avoid false positives
jkakavas Sep 22, 2021
4449fd5
test adjustments
jkakavas Sep 22, 2021
9ecc182
spotless
jkakavas Sep 22, 2021
9781eba
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 22, 2021
9145898
revert fix for local invocation
jkakavas Sep 22, 2021
ea5932d
spotless
jkakavas Sep 22, 2021
a781149
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 22, 2021
ae591d3
Use legacy MAC algorithm for PKCS12 in tests until we can bump minimu…
jkakavas Sep 22, 2021
10f3474
Main
albertzaharovits Sep 27, 2021
6076aab
Nit rename & javadoc
albertzaharovits Sep 27, 2021
674202d
ReservedRealm security index param remove fallout
albertzaharovits Sep 27, 2021
98e3ed9
Merge branch 'master' into set-auto-conf-password
albertzaharovits Sep 27, 2021
ccd1dbe
WIP
albertzaharovits Sep 27, 2021
c2092d8
ReservedRealm tests
albertzaharovits Sep 28, 2021
0b89640
Merge branch 'master' into set-auto-conf-password
albertzaharovits Sep 28, 2021
e8b390c
Exception serialization test
albertzaharovits Sep 28, 2021
93abfb2
Almost
albertzaharovits Sep 28, 2021
ed8646f
ReservedRealm tests
albertzaharovits Sep 28, 2021
1a3220d
call external class properly
jkakavas Sep 28, 2021
42d88e9
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 28, 2021
6ebcebc
fix elasticsearch-env
jkakavas Sep 29, 2021
405c60d
fix tests for windows
jkakavas Sep 29, 2021
c3124d2
typo
jkakavas Sep 29, 2021
53443bd
NativeUsersStoreTests
albertzaharovits Sep 29, 2021
5645b7d
isElasticUserAutoConfigured
albertzaharovits Sep 29, 2021
125480c
minor fix
jkakavas Sep 29, 2021
8decc71
fix for windows
jkakavas Sep 29, 2021
4a9f987
set read only with attrib on windows
jkakavas Sep 29, 2021
41d6067
undo read only before deletion
jkakavas Sep 29, 2021
1e4648f
test
jkakavas Sep 29, 2021
8ac813e
temp ugly debug
jkakavas Sep 29, 2021
a0cd8de
Address feedback related to packaging tests
jkakavas Sep 29, 2021
de20c38
adjust test after enabling auto-config
jkakavas Sep 29, 2021
ba6720c
windows fixes
jkakavas Sep 30, 2021
6cde022
windows
jkakavas Sep 30, 2021
5798743
add bugurl
jkakavas Sep 30, 2021
38df918
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 30, 2021
ff48940
spotless
jkakavas Sep 30, 2021
7b86021
more spotless
jkakavas Sep 30, 2021
820fd28
wrong password instead of empty
jkakavas Sep 30, 2021
b59c55f
Mute on windows the test that I've been trying all morning to fix on …
jkakavas Sep 30, 2021
b070178
windows debugging
jkakavas Sep 30, 2021
b25cc0a
guess what spotless didn't like
jkakavas Sep 30, 2021
f4e784f
deBUG
jkakavas Sep 30, 2021
8fb6362
debugging windows packaging tests
jkakavas Sep 30, 2021
14e1f36
Negative integ tests
albertzaharovits Sep 30, 2021
a7e4c49
Merge branch 'master' into set-auto-conf-password
albertzaharovits Sep 30, 2021
4128d61
Merge fallout
albertzaharovits Sep 30, 2021
59c2542
Checkstyle
albertzaharovits Sep 30, 2021
299c710
Nit
albertzaharovits Sep 30, 2021
1b2eed3
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Sep 30, 2021
f908c25
path fix
jkakavas Sep 30, 2021
c5eeb4f
temp debug
jkakavas Sep 30, 2021
d646a3b
test fixes
jkakavas Sep 30, 2021
dcb6ee5
spotless
jkakavas Sep 30, 2021
b0377e1
moar spotless
jkakavas Sep 30, 2021
a33a1da
windows file ownership
jkakavas Sep 30, 2021
6f2be87
test fixes
jkakavas Oct 1, 2021
c83160d
Merge remote-tracking branch 'origin/master' into config_tls_when_nod…
jkakavas Oct 1, 2021
4cf3243
remove default from env
jkakavas Oct 1, 2021
4a7e626
Merge remote-tracking branch 'albertzaharovits/config_tls_when_node_s…
jkakavas Oct 1, 2021
0d75418
Merge branch 'packaged-auto-conf' of github.com:jkakavas/elasticsearc…
jkakavas Oct 1, 2021
53e6a2d
merge woes
jkakavas Oct 1, 2021
b28bd52
spotless
jkakavas Oct 1, 2021
be9eefa
test fixes
jkakavas Oct 1, 2021
bc8d9c5
selective mute to check the rest of the tests on windows
jkakavas Oct 1, 2021
1acd0cc
more fixes
jkakavas Oct 1, 2021
8df3cbf
unused import
jkakavas Oct 1, 2021
35b9845
fix autoconfig check for packages
jkakavas Oct 1, 2021
6f752ab
fix certgen
jkakavas Oct 1, 2021
ea66082
Merge remote-tracking branch 'albertzaharovits/set-auto-conf-password…
jkakavas Oct 1, 2021
a8337c2
...
jkakavas Oct 1, 2021
622dffd
fix package upgrade tests
jkakavas Oct 1, 2021
507b3f6
fix package upgrade tests for real now
jkakavas Oct 1, 2021
df561e8
adjustments
jkakavas Oct 2, 2021
514a240
bump leniency
jkakavas Oct 2, 2021
0ca655b
Merge remote-tracking branch 'albertzaharovits/config_tls_when_node_s…
jkakavas Oct 2, 2021
ba30af4
temp debugging
jkakavas Oct 2, 2021
4d1658b
fix docker issues on startup
jkakavas Oct 2, 2021
dd2f567
additional windows debug temp logging
jkakavas Oct 2, 2021
e175b5c
unused imports
jkakavas Oct 2, 2021
99b649c
spotless
jkakavas Oct 2, 2021
178580b
check if FileUtils.deleteDirectory from apache commons does the job o…
jkakavas Oct 3, 2021
99b4ad0
spotless
jkakavas Oct 3, 2021
5d793a3
test fixes
jkakavas Oct 3, 2021
dbf7250
Revert "check if FileUtils.deleteDirectory from apache commons does t…
jkakavas Oct 3, 2021
8bda57f
attempt to explicitly own the dir before removing it
jkakavas Oct 3, 2021
c3547ec
Merge remote-tracking branch 'albertzaharovits/config_tls_when_node_s…
jkakavas Oct 3, 2021
e3d0825
fix tests
jkakavas Oct 3, 2021
8abbf94
almost there
jkakavas Oct 3, 2021
1e981e0
almost, almost, there
jkakavas Oct 3, 2021
7e817d0
more
jkakavas Oct 3, 2021
ceca0f1
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Oct 9, 2021
cbf60bd
spotless
jkakavas Oct 9, 2021
af4d838
Can't use setup passwords for packaged installations
jkakavas Oct 9, 2021
2089d1c
fix tests
jkakavas Oct 9, 2021
6e72adb
add user when needed
jkakavas Oct 9, 2021
27a655c
remove temp dirs correctly in windows
jkakavas Oct 9, 2021
05c2efe
remove temp dirs correctly in windows2
jkakavas Oct 9, 2021
bae98d3
fix deletion
jkakavas Oct 9, 2021
738eb2e
fix autoformat
jkakavas Oct 9, 2021
c72b48d
hello spotless my old friend
jkakavas Oct 9, 2021
40a05af
proper windows cleaning
jkakavas Oct 10, 2021
5e6db81
spotless
jkakavas Oct 10, 2021
0f2d589
sort all first
jkakavas Oct 10, 2021
f721f19
print without deleting for troubleshooting
jkakavas Oct 11, 2021
a8eeff9
blind testing
jkakavas Oct 11, 2021
f0f7b65
spaces are important
jkakavas Oct 11, 2021
c3c6329
dbg
jkakavas Oct 11, 2021
3b0e7ff
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Oct 14, 2021
a77460f
unused import
jkakavas Oct 14, 2021
211391e
fixes
jkakavas Oct 14, 2021
bbb38b9
spotless
jkakavas Oct 14, 2021
ffc4f88
Merge remote-tracking branch 'origin/master' into packaged-auto-conf
jkakavas Oct 14, 2021
ffce3d3
revert unecessary changes and fix merge
jkakavas Oct 14, 2021
bda567b
unused imports
jkakavas Oct 14, 2021
7cdf1e9
Update docs/changelog/75144.yaml
jkakavas Oct 14, 2021
2e19810
fix test
jkakavas Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distribution/packages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def commonPackageConfig(String type, String architecture) {
}
}

// this is package indepdendent configuration
// this is package independent configuration
ospackage {
maintainer 'Elasticsearch Team <[email protected]>'
summary 'Distributed RESTful search engine built for the cloud'
Expand Down
52 changes: 50 additions & 2 deletions distribution/packages/src/common/scripts/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,68 @@ case "$1" in
exit 1
;;
esac

# to pick up /usr/lib/sysctl.d/elasticsearch.conf
if command -v systemctl > /dev/null; then
systemctl restart systemd-sysctl.service || true
fi

if [ "x$IS_UPGRADE" != "xtrue" ]; then
# Don't exit immediately on error, we want to hopefully print some helpful banners
set +e
# Attempt to auto-configure security, this seems to be an installation
if ES_MAIN_CLASS=org.elasticsearch.xpack.security.cli.ConfigInitialNode \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/security-cli \
/usr/share/elasticsearch/bin/elasticsearch-cli -strict <<< ""; then
jkakavas marked this conversation as resolved.
Show resolved Hide resolved
# Above command runs as root and TLS keystores are created group-owned by root. It's simple to correct the ownership here
for dir in "${ES_PATH_CONF}"/auto_config_on*
do
chown root:elasticsearch "${dir}"/http_keystore_local_node.p12
chown root:elasticsearch "${dir}"/http_ca.crt
chown root:elasticsearch "${dir}"/transport_keystore_all_nodes.p12
done
if INITIAL_PASSWORD=$(ES_MAIN_CLASS=org.elasticsearch.xpack.security.enrollment.tool.AutoConfigGenerateElasticPasswordHash \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/security-cli \
/usr/share/elasticsearch/bin/elasticsearch-cli); then
echo "########## Security autoconfiguration information ############"
mark-vieira marked this conversation as resolved.
Show resolved Hide resolved
echo "# #"
echo "# Authentication and Authorization are enabled. #"
echo "# TLS for the transport and the http layers is enabled and configured. #"
echo "# #"
echo "# The password of the elastic superuser will be set to: ${INITIAL_PASSWORD} #"
echo "# upon starting elasticsearch for the first time #"
echo "# #"
echo "##############################################################################"
jkakavas marked this conversation as resolved.
Show resolved Hide resolved
fi
else
if [ $? -eq 63 ]; then
# ExitCodes.NOOP
echo "########## Security autoconfiguration information ############"
echo "# #"
echo "# Security features appear to be already configured. #"
echo "# #"
echo "##############################################################################"
else
echo "########## Security autoconfiguration information ############"
echo "# #"
echo "# Failed to auto-configure security features. #"
echo "# Authentication and Authorization are enabled. #"
echo "# You can use elasticsearch-reset-elastic-password to set a password #"
echo "# for the elastic user. #"
echo "# See <link_here> for instructions on how to configure TLS manually. #"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously we need a value for <link_here>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we probably won't have this link by the time we merge this code. I can add a TODO item to make it less possible that we forget about it.

echo "# #"
echo "##############################################################################"
fi
fi
if command -v systemctl >/dev/null; then
echo "### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd"
echo " sudo systemctl daemon-reload"
echo " sudo systemctl enable elasticsearch.service"
echo "### You can start elasticsearch service by executing"
echo " sudo systemctl start elasticsearch.service"
fi
set -e

elif [ "$RESTART_ON_UPGRADE" = "true" ]; then

echo -n "Restarting elasticsearch service..."
Expand Down
12 changes: 12 additions & 0 deletions distribution/packages/src/common/scripts/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export ES_PATH_CONF=${ES_PATH_CONF:[email protected]@}

REMOVE_DIRS=false
REMOVE_JVM_OPTIONS_DIRECTORY=false
REMOVE_SECURITY_AUTO_CONFIG_DIRECTORY=false
REMOVE_ELASTICSEARCH_KEYSTORE=false
REMOVE_USER_AND_GROUP=false

Expand All @@ -31,6 +32,7 @@ case "$1" in
purge)
REMOVE_DIRS=true
REMOVE_JVM_OPTIONS_DIRECTORY=true
REMOVE_SECURITY_AUTO_CONFIG_DIRECTORY=true
REMOVE_ELASTICSEARCH_KEYSTORE=true
REMOVE_USER_AND_GROUP=true
;;
Expand Down Expand Up @@ -99,6 +101,16 @@ if [ "$REMOVE_DIRS" = "true" ]; then
fi
fi

# delete the security auto config directory if we are purging
if [ "$REMOVE_SECURITY_AUTO_CONFIG_DIRECTORY" = "true" ]; then
for dir in "${ES_PATH_CONF}"/auto_config_on*
do
echo -n "Deleting security auto-configuration directory..."
rm -rf "${dir}"
echo "OK"
done
fi

# delete the elasticsearch keystore if we are purging
if [ "$REMOVE_ELASTICSEARCH_KEYSTORE" = "true" ]; then
if [ -e "${ES_PATH_CONF}/elasticsearch.keystore" ]; then
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog/75144.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 75144
summary: Security auto-configuration for packaged installations
area: "Security"
type: enhancement
issues:
- 75704
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.carrotsearch.randomizedtesting.RandomizedTest.assumeFalse;
import static java.nio.file.StandardOpenOption.APPEND;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static org.elasticsearch.packaging.util.FileMatcher.Fileness.File;
import static org.elasticsearch.packaging.util.FileMatcher.file;
import static org.elasticsearch.packaging.util.FileMatcher.p600;
Expand Down Expand Up @@ -96,8 +98,8 @@ public void test40RunWithCert() throws Exception {
final String keyPath = escapePath(installation.config("certs/mynode/mynode.key"));
final String certPath = escapePath(installation.config("certs/mynode/mynode.crt"));
final String caCertPath = escapePath(installation.config("certs/ca/ca.crt"));

List<String> yaml = List.of(
// Replace possibly auto-configured TLS settings with ones pointing to the material generated with certgen
List<String> newTlsConfig = List.of(
"node.name: mynode",
"xpack.security.transport.ssl.key: " + keyPath,
"xpack.security.transport.ssl.certificate: " + certPath,
Expand All @@ -108,8 +110,15 @@ public void test40RunWithCert() throws Exception {
"xpack.security.transport.ssl.enabled: true",
"xpack.security.http.ssl.enabled: true"
);
List<String> existingConfig = Files.readAllLines(installation.config("elasticsearch.yml"));
List<String> newConfig = existingConfig.stream()
.filter(l -> l.startsWith("node.name:") == false)
.filter(l -> l.startsWith("xpack.security.transport.ssl.") == false)
.filter(l -> l.startsWith("xpack.security.http.ssl.") == false)
.collect(Collectors.toList());
newConfig.addAll(newTlsConfig);

Files.write(installation.config("elasticsearch.yml"), yaml, CREATE, APPEND);
Files.write(installation.config("elasticsearch.yml"), newConfig, TRUNCATE_EXISTING);

assertWhileRunning(() -> {
final String password = setElasticPassword();
Expand All @@ -120,7 +129,7 @@ public void test40RunWithCert() throws Exception {

private String setElasticPassword() {
final Pattern userpassRegex = Pattern.compile("PASSWORD (\\w+) = ([^\\s]+)");
Shell.Result result = installation.executables().setupPasswordsTool.run("auto --batch", null);
Shell.Result result = installation.executables().setupPasswordsTool.run("auto --batch -u https://127.0.0.1:9200", null);
Matcher matcher = userpassRegex.matcher(result.stdout);
assertNotNull(matcher);
while (matcher.find()) {
Expand Down
Loading