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

Password Protected Keystore (Feature Branch) #49210

Closed
wants to merge 115 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
98ad0eb
Reload secure settings with password (#43197)
jkakavas Jul 11, 2019
5b0b591
Merge remote-tracking branch 'origin/master' into feature-pwd-protect…
jkakavas Jul 23, 2019
9398aac
Add passphrase support to elasticsearch-keystore (#38498)
jkakavas Jul 23, 2019
c7882c3
Merge remote-tracking branch 'origin/master' into feature-pwd-protect…
jkakavas Jul 25, 2019
6684375
Restore behavior for force parameter (#44847)
jkakavas Jul 26, 2019
c38fa7a
[ML-DataFrame] Muting tests for backport (#44850)
droberts195 Jul 25, 2019
83db007
Treat PostDataActionResponse.DataCounts.bucketCount as incremental ra…
przemekwitek Jul 25, 2019
2069e38
[ML-DataFrame] Adjust data frame stats BWC following backport (#44852)
droberts195 Jul 25, 2019
e4c35eb
do not assert on indexer state (#44854)
Jul 25, 2019
24e009b
[DOCS] Adds allow no datafeeds query param to the GET, GET stats and …
szabosteve Jul 25, 2019
9c4ea84
[GEO] Fix GeoShapeQueryBuilder to check for valid spatial relations
nknize Jul 25, 2019
cade368
[DOCS] Updates terms in anomaly detection job APIs (#44839)
lcawl Jul 25, 2019
ba34dce
[DOCS] Fixes terms in HLRC data frame transform APIs (#44838)
lcawl Jul 25, 2019
4c65468
[DOCS] Minor edits to HLRC ML APIs (#44865)
lcawl Jul 25, 2019
d420bc4
Fix an NPE when requesting inner hits and _source is disabled. (#44836)
jtibshirani Jul 25, 2019
91c35aa
Add Clone Index API (#44267)
ywelsch Jul 25, 2019
31a8ce9
[DOCS] Updates terms in machine learning calendar APIs (#44866)
lcawl Jul 25, 2019
8bbf546
[DOCS] Adds command reference for elasticsearch-croneval (#43946)
lcawl Jul 25, 2019
a05805a
Add missing ZonedDateTime methods for joda compat layer (#44829)
rjernst Jul 25, 2019
78ca898
Fix issue with Gradle daemons hanging indefinitely on shutdown (#44867)
mark-vieira Jul 25, 2019
c9a9d9e
Asynchronously connect to remote clusters (#44825)
ywelsch Jul 25, 2019
d340467
Adapt BWC condition for clone index API after backport (#44267)
ywelsch Jul 25, 2019
8510717
Add option to filter ILM explain response (#44777)
gwbrown Jul 25, 2019
56e35b8
[DOCS] Clarifies dataframe transform validations
lcawl Jul 25, 2019
f4edb31
Upgrade to Lucene 8.2.0 release (#44859)
iverase Jul 26, 2019
944c998
Document xpack.security.authc.saml.realm for Kibana (#44705)
jkakavas Jul 26, 2019
df9b97a
Force Merge should reject requests with `only_expunge_deletes` and `m…
tlrx Jul 26, 2019
fc1158b
Deprecate setting processors to more than available (#44889)
jasontedor Jul 26, 2019
f8133ec
Ensure cluster is stable in ShrinkIndexIT.testShrinkThenSplitWithFail…
tlrx Jul 26, 2019
62f8f85
[DOCS] Amends data frame analytics resources, GET, and PUT API docs (…
szabosteve Jul 26, 2019
0a15aa1
Implement exponential average search time per hour statistics. (#44683)
przemekwitek Jul 26, 2019
c13dda1
Fix Test Failure in ScalingThreadPoolTests (#44898)
original-brownbear Jul 26, 2019
e37df82
Ensure index is green in SimpleClusterStateIT.testIndicesOptions() (#…
tlrx Jul 26, 2019
fb3d70a
Limit processors by available processors (#44894)
jasontedor Jul 26, 2019
5df6cc8
Fix failing scaling thread pool test
jasontedor Jul 26, 2019
08c02e7
Update serialization version for ILM explain filters
gwbrown Jul 26, 2019
6908663
Geo: refactor geo mapper and query builder (#44884)
imotov Jul 26, 2019
7411325
[DOCS] Updates terms in machine learning datafeed APIs (#44883)
lcawl Jul 26, 2019
aa0c83d
[DOCS] Updates anomaly detection terminology (#44888)
lcawl Jul 26, 2019
b9a17b4
Optimize Min and Max BKD optimizations (#44315)
michalperlak Jul 26, 2019
37b39a6
Guard open connection call in RemoteClusterConnection (#44921)
ywelsch Jul 26, 2019
929ef7f
RestController should not consume request content (#44902)
tlrx Jul 28, 2019
d2d7f26
Remove client feature tracking (#44929)
jasontedor Jul 28, 2019
3c74664
Expand logging when SAML Audience condition fails (#44334)
tvernum Jul 29, 2019
b9b242e
Cleanup Deadcode o.e.indices (#44931)
original-brownbear Jul 29, 2019
f5b7feb
Change version in serialization code to 7.4.0 (#44905)
przemekwitek Jul 29, 2019
270e256
Don't use TypeField for nested filters (#44482)
romseygeek Jul 29, 2019
6f8e1a3
Do not block transport thread on startup (#44939)
ywelsch Jul 29, 2019
f96e253
[ML] Close any opened pipes if there is an error connecting to the pr…
davidkyle Jul 29, 2019
bc8e75c
[Docs] Update daterange-aggregation.asciidoc (#44730)
sandeepkanabar Jul 29, 2019
f241e30
[DOCS] Amends REST API TOC. (#44948)
szabosteve Jul 29, 2019
3eb5d26
Support fixture in repository-gcs:thirdPartyTest and fix GCS fixture …
Jul 29, 2019
7b9675b
[DOCS] Reformat distance feature query (#44916)
jrodewig Jul 29, 2019
5b6e049
[DOCS] Rewrite `prefix` query docs (#41955)
jrodewig Jul 29, 2019
3b49a0d
[ML] Outlier detection should only fetch docs that have the analyzed …
dimitris-athanasiou Jul 29, 2019
da70449
[DOCS] Reformat script query (#44882)
jrodewig Jul 29, 2019
c7e4cbf
TaskListener#onFailure to accept Exception instead of Throwable (#44946)
javanna Jul 29, 2019
e5c3e61
Fix testBlockingIncomingRequests (#44939)
ywelsch Jul 29, 2019
4e7a1a7
[ML] Catch any error thrown while closing data frame analytics proces…
dimitris-athanasiou Jul 29, 2019
8652ef4
[GEO] Refactor DeprecatedParameters in AbstractGeometryFieldMapper (#…
nknize Jul 29, 2019
099d7be
Geo: fix geo query decomposition (#44924)
imotov Jul 29, 2019
025b92e
Fix Snapshot CLI Build Portability (#44919)
original-brownbear Jul 29, 2019
3f80ff8
Rename indexlifecycle to ilm and snapshotlifecycle to slm (#44917)
dakrone Jul 29, 2019
decb1da
Adjust skip version after backport (#44603)
dnhatn Jul 29, 2019
1c86c21
Remove leniency in reset engine from translog (#44711)
dnhatn Jul 29, 2019
c34c064
Fix JodaCompatibleZonedDateTime casts in Painless (#44874)
jdconrad Jul 29, 2019
405c51e
Release Pooled Buffers Earlier for HTTP Requests (#44952)
original-brownbear Jul 30, 2019
03a204b
Explicitly fail if a realm only exists in keystore (#44471)
tvernum Jul 30, 2019
ba57635
Fix aggregators early termination with breadth-first mode (#44963)
jimczi Jul 30, 2019
b8e668a
Mute SnapshotLifecycleServiceTests#testPolicyCRUD
davidkyle Jul 30, 2019
24cb30a
Close nodes properly in Coordinator tests (#44967)
DaveCTurner Jul 30, 2019
ddd179b
Optimize Netty Frame Decoding (#44664)
original-brownbear Jul 30, 2019
88711e1
[DOCS] Adds allow no jobs param to the GET, GET stats and Close APIs …
szabosteve Jul 30, 2019
91472ea
S3 3rd Party Test Goal (#44799)
original-brownbear Jul 30, 2019
49a4f7d
Remove leniency during replay translog in peer recovery (#44989)
dnhatn Jul 30, 2019
ee67c94
[ML][Data Frame] add support for bucket_selector (#44718)
benwtrent Jul 30, 2019
08608d2
Mute WatcherRestIT 20_minimal_body
davidkyle Jul 30, 2019
393bf48
[ML][Data Frames] unify validation exceptions between PUT/_preview (#…
benwtrent Jul 30, 2019
7648868
Geo: move indexShape to AbstractGeometryFieldMapper.Indexer (#44979)
imotov Jul 30, 2019
15c0f23
Move nio channel initialization to event loop (#43780)
Tim-Brooks Jul 30, 2019
501f41f
introduce 7.2.2 as a version (#44375)
jakelandis Jul 30, 2019
8c23c92
[DOCS] Updates terms in machine learning get APIs (#44986)
lcawl Jul 30, 2019
326c247
Assure index ops are successful for SimpleNestedIT (#44815)
mayya-sharipova Jul 30, 2019
8921cf0
[DOCS] Modified section headings, edited text for clarity. (#44988)
Jul 30, 2019
731ddbd
Adds usage stats for vectors: (#44512)
mayya-sharipova Jul 30, 2019
6acea3c
Rename HLRC 'indexlifecycle' components to 'ilm' (#44982)
dakrone Jul 30, 2019
cd5bf44
Small optimizations in VectorsUsageTransportAction
mayya-sharipova Jul 30, 2019
47f9c35
[DOCS] Remove xpack terminology from installation pages (#44973)
lcawl Jul 30, 2019
5efc017
[SPATIAL] New ShapeFieldMapper for indexing cartesian geometries (#44…
nknize Jul 31, 2019
7a0a4a5
Improve errors when TLS files cannot be read (#44787)
tvernum Jul 31, 2019
2ad531a
[Docs] Fix typo in rank-eval.asciidoc (#44978)
Jul 31, 2019
6a30267
Clarify which circuit breaker settings are static (#44992)
danielmitterdorfer Jul 31, 2019
73bbb7f
Mute all GC Disruption Simulating Tests (#45032)
original-brownbear Jul 31, 2019
0c089d6
Stop Recreating Wrapped Handlers in RestController (#44964)
original-brownbear Jul 31, 2019
cc53cc4
Reenable Parallel Restore Test on Windows (#45037)
original-brownbear Jul 31, 2019
fecde5d
Cleanup Various Action- Listener and Runnable Usages (#42273)
original-brownbear Jul 31, 2019
dadac0c
Remove the ability to update datafeed's job_id. (#44752)
przemekwitek Jul 31, 2019
7fcdb41
Indicate that some user APIs handle built-in users (#44857)
jkakavas Jul 31, 2019
fb9f592
Introduce 7.3.1 version (#45049)
polyfractal Jul 31, 2019
0f34e9f
Adjust docs for password protected keystore (#45054)
jkakavas Aug 1, 2019
4ad6b51
Merge branch 'master' into feature-pwd-protected-keystore
williamrandolph Aug 7, 2019
4780880
Merge remote-tracking branch 'origin/master' into feature-pwd-protect…
jkakavas Aug 16, 2019
d1cb96a
Handle pwd protected keystores in all CLI tools (#45289)
jkakavas Aug 16, 2019
e0b949e
Merge master to feature branch
williamrandolph Aug 23, 2019
5d461da
Modify docs for setup passwords and saml metadata cli (#45797)
jkakavas Aug 28, 2019
5be2efb
merging changes from master
williamrandolph Sep 9, 2019
b674115
Merge branch 'master' into feature-pwd-protected-keystore
williamrandolph Sep 19, 2019
ae32d3c
Merging master into feature branch
williamrandolph Oct 2, 2019
e928c27
Merging changes from master to feature branch
williamrandolph Oct 9, 2019
a4a2093
Merge branch 'master' into feature-pwd-protected-keystore
williamrandolph Oct 15, 2019
e0181b4
Merge branch 'master' into feature-pwd-protected-keystore
williamrandolph Oct 16, 2019
0944b31
Merge branch 'master' into feature-pwd-protected-keystore
williamrandolph Oct 24, 2019
0a0db4b
Elasticsearch keystore passphrase for startup scripts (#44775)
williamrandolph Nov 11, 2019
3229641
merging master into keystore feature branch
williamrandolph Nov 15, 2019
2a34fe0
post-merge cleanup for precommit
williamrandolph Nov 15, 2019
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
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ JAVA
ensure curl
ensure unzip
ensure rsync
ensure expect

installed bats || {
# Bats lives in a git repository....
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ task verifyVersions {
* after the backport of the backcompat code is complete.
*/

boolean bwc_tests_enabled = true
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
boolean bwc_tests_enabled = false
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/43197"
if (bwc_tests_enabled == false) {
if (bwc_tests_disabled_issue.isEmpty()) {
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
Expand Down
2 changes: 1 addition & 1 deletion distribution/docker/docker-test-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
cd /usr/share/elasticsearch/bin/
./elasticsearch-users useradd x_pack_rest_user -p x-pack-test-password -r superuser || true
./elasticsearch-users useradd x_pack_rest_user -p x-pack-test-password -r superuser || true
echo "testnode" > /tmp/password
cat /tmp/password | ./elasticsearch-keystore add -x -f -v 'xpack.security.transport.ssl.keystore.secure_password'
cat /tmp/password | ./elasticsearch-keystore add -x -f -v 'xpack.security.http.ssl.keystore.secure_password'
Expand Down
16 changes: 13 additions & 3 deletions distribution/docker/src/docker/bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,18 @@ if [[ -f bin/elasticsearch-users ]]; then
# honor the variable if it's present.
if [[ -n "$ELASTIC_PASSWORD" ]]; then
[[ -f /usr/share/elasticsearch/config/elasticsearch.keystore ]] || (run_as_other_user_if_needed elasticsearch-keystore create)
if ! (run_as_other_user_if_needed elasticsearch-keystore list | grep -q '^bootstrap.password$'); then
(run_as_other_user_if_needed echo "$ELASTIC_PASSWORD" | elasticsearch-keystore add -x 'bootstrap.password')
if ! (run_as_other_user_if_needed elasticsearch-keystore has-passwd --silent) ; then
# keystore is unencrypted
if ! (run_as_other_user_if_needed elasticsearch-keystore list | grep -q '^bootstrap.password$'); then
(run_as_other_user_if_needed echo "$ELASTIC_PASSWORD" | elasticsearch-keystore add -x 'bootstrap.password')
fi
else
# keystore requires password
if ! (run_as_other_user_if_needed echo "$KEYSTORE_PASSWORD" \
| elasticsearch-keystore list | grep -q '^bootstrap.password$') ; then
COMMANDS="$(printf "%s\n%s" "$KEYSTORE_PASSWORD" "$ELASTIC_PASSWORD")"
(run_as_other_user_if_needed echo "$COMMANDS" | elasticsearch-keystore add -x 'bootstrap.password')
fi
fi
fi
fi
Expand All @@ -131,4 +141,4 @@ if [[ "$(id -u)" == "0" ]]; then
fi
fi

run_as_other_user_if_needed /usr/share/elasticsearch/bin/elasticsearch "${es_opts[@]}"
run_as_other_user_if_needed /usr/share/elasticsearch/bin/elasticsearch "${es_opts[@]}" <<<"$KEYSTORE_PASSWORD"
4 changes: 4 additions & 0 deletions distribution/packages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ Closure commonPackageConfig(String type, boolean oss, boolean jdk) {
from "${packagingFiles}/systemd/sysctl/elasticsearch.conf"
fileMode 0644
}
into('/usr/share/elasticsearch/bin') {
from "${packagingFiles}/systemd/systemd-entrypoint"
fileMode 0755
}

// ========= sysV init =========
configurationFile '/etc/init.d/elasticsearch'
Expand Down
7 changes: 6 additions & 1 deletion distribution/packages/src/common/scripts/posttrans
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ if [ ! -f /etc/elasticsearch/elasticsearch.keystore ]; then
chmod 660 /etc/elasticsearch/elasticsearch.keystore
md5sum /etc/elasticsearch/elasticsearch.keystore > /etc/elasticsearch/.elasticsearch.keystore.initial_md5sum
else
/usr/share/elasticsearch/bin/elasticsearch-keystore upgrade
if /usr/share/elasticsearch/bin/elasticsearch-keystore has-passwd --silent ; then
echo "### Warning: unable to upgrade encrypted keystore" 1>&2
echo " Please run elasticsearch-keystore upgrade and enter password" 1>&2
else
/usr/share/elasticsearch/bin/elasticsearch-keystore upgrade
fi
fi

${scripts.footer}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ WorkingDirectory=/usr/share/elasticsearch
User=elasticsearch
Group=elasticsearch

ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet
ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet

# StandardOutput is configured to redirect to journalctl since
# some error messages may be logged in standard output before
Expand Down
10 changes: 10 additions & 0 deletions distribution/packages/src/common/systemd/systemd-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# This wrapper script allows SystemD to feed a file containing a passphrase into
# the main Elasticsearch startup script

if [ -n "$ES_KEYSTORE_PASSPHRASE_FILE" ] ; then
exec /usr/share/elasticsearch/bin/elasticsearch "$@" < "$ES_KEYSTORE_PASSPHRASE_FILE"
else
exec /usr/share/elasticsearch/bin/elasticsearch "$@"
fi
17 changes: 15 additions & 2 deletions distribution/src/bin/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ if [ -z "$ES_TMPDIR" ]; then
ES_TMPDIR=`"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.TempDirectory`
fi

# get keystore password before setting java options to avoid
# conflicting GC configurations for the keystore tools
unset KEYSTORE_PASSWORD
KEYSTORE_PASSWORD=
if ! echo $* | grep -E -q '(^-h |-h$| -h |--help$|--help |^-V |-V$| -V |--version$|--version )' \
&& "`dirname "$0"`"/elasticsearch-keystore has-passwd --silent
then
if ! read -s -r -p "Elasticsearch keystore password: " KEYSTORE_PASSWORD ; then
echo "Failed to read keystore password on console" 1>&2
exit 1
fi
fi

ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_JVM_OPTIONS"`

Expand All @@ -35,7 +48,7 @@ if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null;
-Des.bundled_jdk="$ES_BUNDLED_JDK" \
-cp "$ES_CLASSPATH" \
org.elasticsearch.bootstrap.Elasticsearch \
"$@"
"$@" <<<"$KEYSTORE_PASSWORD"
else
exec \
"$JAVA" \
Expand All @@ -48,7 +61,7 @@ else
-cp "$ES_CLASSPATH" \
org.elasticsearch.bootstrap.Elasticsearch \
"$@" \
<&- &
<<<"$KEYSTORE_PASSWORD" &
retval=$?
pid=$!
[ $retval -eq 0 ] || exit $retval
Expand Down
2 changes: 1 addition & 1 deletion distribution/src/bin/elasticsearch-cli.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ set ES_JAVA_OPTS=-Xms4m -Xmx64m -XX:+UseSerialGC %ES_JAVA_OPTS%
-cp "%ES_CLASSPATH%" ^
"%ES_MAIN_CLASS%" ^
%*

exit /b %ERRORLEVEL%
42 changes: 41 additions & 1 deletion distribution/src/bin/elasticsearch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ setlocal enabledelayedexpansion
setlocal enableextensions

SET params='%*'
SET checkpassword=Y

:loop
FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO (
Expand All @@ -18,6 +19,20 @@ FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO (
SET silent=Y
)

IF "!current!" == "-h" (
SET checkpassword=N
)
IF "!current!" == "--help" (
SET checkpassword=N
)

IF "!current!" == "-V" (
SET checkpassword=N
)
IF "!current!" == "--version" (
SET checkpassword=N
)

IF "!silent!" == "Y" (
SET nopauseonerror=Y
) ELSE (
Expand All @@ -41,6 +56,18 @@ IF ERRORLEVEL 1 (
EXIT /B %ERRORLEVEL%
)

SET KEYSTORE_PASSWORD=
IF "%checkpassword%"=="Y" (
CALL "%~dp0elasticsearch-keystore.bat" has-passwd --silent
IF !ERRORLEVEL! EQU 0 (
SET /P KEYSTORE_PASSWORD=Elasticsearch keystore password:
IF !ERRORLEVEL! NEQ 0 (
ECHO Failed to read keystore password on standard input
EXIT /B !ERRORLEVEL!
)
)
)

if not defined ES_TMPDIR (
for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory"`) do set ES_TMPDIR=%%a
)
Expand All @@ -54,7 +81,20 @@ if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
exit /b 1
)

%JAVA% %ES_JAVA_OPTS% -Delasticsearch -Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" -Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" -Des.distribution.type="%ES_DISTRIBUTION_TYPE%" -Des.bundled_jdk="%ES_BUNDLED_JDK%" -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
rem windows batch pipe will choke on special characters in strings
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^^=^^^^!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^&=^^^&!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^|=^^^|!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^<=^^^<!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^>=^^^>!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^\=^^^\!

ECHO.!KEYSTORE_PASSWORD!| %JAVA% %ES_JAVA_OPTS% -Delasticsearch ^
-Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" ^
-Des.distribution.flavor="%ES_DISTRIBUTION_FLAVOR%" ^
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
-Des.bundled_jdk="%ES_BUNDLED_JDK%" ^
-cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!

endlocal
endlocal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.elasticsearch.cli.EnvironmentAwareCommand;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserException;
Expand All @@ -37,42 +36,29 @@
/**
* A subcommand for the keystore cli which adds a file setting.
*/
class AddFileKeyStoreCommand extends EnvironmentAwareCommand {
class AddFileKeyStoreCommand extends BaseKeyStoreCommand {

private final OptionSpec<Void> forceOption;
private final OptionSpec<String> arguments;

AddFileKeyStoreCommand() {
super("Add a file setting to the keystore");
this.forceOption = parser.acceptsAll(Arrays.asList("f", "force"), "Overwrite existing setting without prompting");
super("Add a file setting to the keystore", false);
this.forceOption = parser.acceptsAll(Arrays.asList("f", "force"),
"Overwrite existing setting without prompting, creating keystore if necessary");
// jopt simple has issue with multiple non options, so we just get one set of them here
// and convert to File when necessary
// see https://github.com/jopt-simple/jopt-simple/issues/103
this.arguments = parser.nonOptions("setting [filepath]");
}

@Override
protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile());
if (keystore == null) {
if (options.has(forceOption) == false &&
terminal.promptYesNo("The elasticsearch keystore does not exist. Do you want to create it?", false) == false) {
terminal.println("Exiting without creating keystore.");
return;
}
keystore = KeyStoreWrapper.create();
keystore.save(env.configFile(), new char[0] /* always use empty passphrase for auto created keystore */);
terminal.println("Created elasticsearch keystore in " + env.configFile());
} else {
keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */);
}

protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
List<String> argumentValues = arguments.values(options);
if (argumentValues.size() == 0) {
throw new UserException(ExitCodes.USAGE, "Missing setting name");
}
String setting = argumentValues.get(0);
if (keystore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
final KeyStoreWrapper keyStore = getKeyStore();
if (keyStore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {
terminal.println("Exiting without modifying keystore.");
return;
Expand All @@ -90,11 +76,11 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
throw new UserException(ExitCodes.USAGE, "Unrecognized extra arguments [" +
String.join(", ", argumentValues.subList(2, argumentValues.size())) + "] after filepath");
}
keystore.setFile(setting, Files.readAllBytes(file));
keystore.save(env.configFile(), new char[0]);
keyStore.setFile(setting, Files.readAllBytes(file));
keyStore.save(env.configFile(), getKeyStorePassword().getChars());
}

@SuppressForbidden(reason="file arg for cli")
@SuppressForbidden(reason = "file arg for cli")
private Path getPath(String file) {
return PathUtils.get(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
package org.elasticsearch.common.settings;

import java.io.BufferedReader;
import java.io.CharArrayWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.elasticsearch.cli.EnvironmentAwareCommand;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserException;
Expand All @@ -37,16 +35,16 @@
/**
* A subcommand for the keystore cli which adds a string setting.
*/
class AddStringKeyStoreCommand extends EnvironmentAwareCommand {
class AddStringKeyStoreCommand extends BaseKeyStoreCommand {

private final OptionSpec<Void> stdinOption;
private final OptionSpec<Void> forceOption;
private final OptionSpec<String> arguments;

AddStringKeyStoreCommand() {
super("Add a string setting to the keystore");
super("Add a string setting to the keystore", false);
this.stdinOption = parser.acceptsAll(Arrays.asList("x", "stdin"), "Read setting value from stdin");
this.forceOption = parser.acceptsAll(Arrays.asList("f", "force"), "Overwrite existing setting without prompting");
this.forceOption = parser.acceptsAll(Arrays.asList("f", "force"),
"Overwrite existing setting without prompting, creating keystore if necessary");
this.arguments = parser.nonOptions("setting name");
}

Expand All @@ -56,26 +54,13 @@ InputStream getStdin() {
}

@Override
protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile());
if (keystore == null) {
if (options.has(forceOption) == false &&
terminal.promptYesNo("The elasticsearch keystore does not exist. Do you want to create it?", false) == false) {
terminal.println("Exiting without creating keystore.");
return;
}
keystore = KeyStoreWrapper.create();
keystore.save(env.configFile(), new char[0] /* always use empty passphrase for auto created keystore */);
terminal.println("Created elasticsearch keystore in " + env.configFile());
} else {
keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */);
}

protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
String setting = arguments.value(options);
if (setting == null) {
throw new UserException(ExitCodes.USAGE, "The setting name can not be null");
}
if (keystore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
final KeyStoreWrapper keyStore = getKeyStore();
if (keyStore.getSettingNames().contains(setting) && options.has(forceOption) == false) {
if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {
terminal.println("Exiting without modifying keystore.");
return;
Expand All @@ -84,26 +69,18 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th

final char[] value;
if (options.has(stdinOption)) {
try (BufferedReader stdinReader = new BufferedReader(new InputStreamReader(getStdin(), StandardCharsets.UTF_8));
CharArrayWriter writer = new CharArrayWriter()) {
int charInt;
while ((charInt = stdinReader.read()) != -1) {
if ((char) charInt == '\r' || (char) charInt == '\n') {
break;
}
writer.write((char) charInt);
}
value = writer.toCharArray();
}
BufferedReader stdinReader = new BufferedReader(new InputStreamReader(getStdin(), StandardCharsets.UTF_8));
value = stdinReader.readLine().toCharArray();
} else {
value = terminal.readSecret("Enter value for " + setting + ": ");
}

try {
keystore.setString(setting, value);
} catch (final IllegalArgumentException e) {
keyStore.setString(setting, value);
} catch (IllegalArgumentException e) {
throw new UserException(ExitCodes.DATA_ERROR, e.getMessage());
}
keystore.save(env.configFile(), new char[0]);
keyStore.save(env.configFile(), getKeyStorePassword().getChars());

}
}
Loading