Skip to content

Commit

Permalink
fix logstash-keystore to accept spaces in values when added via stdin (
Browse files Browse the repository at this point in the history
…#17039) (#17041)

This commit preserves spaces in values, ensuring that multi-word strings are stored as intended.
Prior to this change, `logstash-keystore` incorrectly handled values containing spaces,
causing only the first word to be stored.

(cherry picked from commit 5573b5a)

Co-authored-by: kaisecheng <[email protected]>
  • Loading branch information
github-actions[bot] and kaisecheng authored Feb 7, 2025
1 parent 40866b9 commit a19a607
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public char[] readSecret() {
if (useConsole) {
return System.console().readPassword();
} else {
return scanner.next().toCharArray();
return scanner.nextLine().toCharArray();
}
}

Expand Down
14 changes: 14 additions & 0 deletions qa/integration/specs/secret_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
expect(logstash.stderr_and_stdout).to match(/\\"\$\{tag1\}\\"/)
end

it "add value that contains a space" do
# add two key value pairs to keystore
# hello => hello world
# bye => bye
key = "hello"
value = "hello world"
@logstash.run_cmd(["bash", "-c", "echo -e '#{value}\\nbye' | LOGSTASH_KEYSTORE_PASS=#{logstash_keystore_passowrd} #{@logstash.logstash_home}/bin/logstash-keystore --path.settings #{settings_dir} add #{key} bye"])

test_env["LOGSTASH_KEYSTORE_PASS"] = logstash_keystore_passowrd
logstash = @logstash.run_cmd(["bin/logstash", "-e", "input{ generator{ count => 1 tags => ['${#{key}}', '${bye}'] }}", "--path.settings", settings_dir], true, test_env)
expect(logstash.stderr_and_stdout).to match(/#{value}/)
expect(logstash.stderr_and_stdout).to match(/bye/)
end

context "won't start" do
it "with the wrong password when variables are in settings" do
test_env["LOGSTASH_KEYSTORE_PASS"] = "WRONG_PASSWRD"
Expand Down

0 comments on commit a19a607

Please sign in to comment.