-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to locally obfuscate secret in a keystore (#5687)
* Feature: Local Keystore to obfuscate sensitive information on disk This PR allow users to define sensitive information into an obfuscated data store on disk instead of having them defined in plaintext in the yaml configuration. This add a few users facing commands: beat keystore create beat keystore add output.elasticsearch.password beat keystore remove output.elasticsearch.password beat keystore list The current implementation doesn't allow user to configure the secret with a custom password, this will come in future improvements of this feature. * Changelog
- Loading branch information
Showing
22 changed files
with
1,577 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
coverage.out | ||
.python-version | ||
beat.db | ||
*.keystore | ||
|
||
# Editor swap files | ||
*.swp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
from os import path | ||
|
||
from filebeat import BaseTest | ||
from beat.beat import Proc | ||
|
||
|
||
class TestKeystore(BaseTest): | ||
""" | ||
Test Keystore variable replacement | ||
""" | ||
|
||
def setUp(self): | ||
super(BaseTest, self).setUp() | ||
self.keystore_path = self.working_dir + "/data/keystore" | ||
|
||
def test_keystore_with_present_key(self): | ||
""" | ||
Test that we correctly do string replacement with values from the keystore | ||
""" | ||
|
||
key = "elasticsearch_host" | ||
secret = "myeleasticsearchsecrethost" | ||
|
||
self.render_config_template(keystore_path=self.keystore_path, elasticsearch={ | ||
'host': "${%s}:9200" % key | ||
}) | ||
|
||
exit_code = self.run_beat(extra_args=["keystore", "create"]) | ||
assert exit_code == 0 | ||
|
||
self.add_secret(key, secret, True) | ||
proc = self.start_beat() | ||
self.wait_until(lambda: self.log_contains("myeleasticsearchsecrethost")) | ||
assert self.log_contains(secret) | ||
proc.kill_and_wait() | ||
|
||
def test_keystore_with_key_not_present(self): | ||
""" | ||
Test that we return the template key when the key doesn't exist | ||
""" | ||
key = "do_not_exist_elasticsearch_host" | ||
|
||
self.render_config_template(keystore_path=self.keystore_path, elasticsearch={ | ||
'host': "${%s}:9200" % key | ||
}) | ||
|
||
exit_code = self.run_beat() | ||
assert self.log_contains( | ||
"missing field accessing 'output.elasticsearch.hosts.0'") | ||
assert exit_code == 1 | ||
|
||
def add_secret(self, key, value="hello world\n", force=False): | ||
""" | ||
Add new secret using the --stdin option | ||
""" | ||
args = [self.test_binary, | ||
"-systemTest", | ||
"-test.coverprofile", | ||
os.path.join(self.working_dir, "coverage.cov"), | ||
"-c", os.path.join(self.working_dir, self.beat_name + ".yml"), | ||
"-e", "-v", "-d", "*", | ||
"keystore", "add", key, "--stdin", | ||
] | ||
|
||
if force: | ||
args.append("--force") | ||
|
||
proc = Proc(args, os.path.join(self.working_dir, self.beat_name + ".log")) | ||
|
||
os.write(proc.stdin_write, value) | ||
os.close(proc.stdin_write) | ||
|
||
return proc.start().wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.