-
Notifications
You must be signed in to change notification settings - Fork 5
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
Research configuration persistence methods #86
Comments
Plugin dedicated configuration fileWe found that OpenSearch's Observability Plugin uses a dedicated configuration file, observability.yml. We found that they use this method from the Setting class that loads the configuration file We searched other uses of the Main configuration file (opensearch.yml)The AuditConfigMigrater class in Security Plugin reads the opensearch.yml, then creates new configuration files and finally edits the opensearch.yml. So, we understand that this is a complete example to use opensearch.yml to persist configuration options for the plugin. Analyses of the Example in AuditConfigMigrater of Security Pluginfinal CommandLine line = parser.parse(options, args);
[...]
final String source = line.getOptionValue("s", opensearchPath);
[...]
// create settings builder
System.out.println("Using source opensearch.yml file from path " + source);
final Settings.Builder settingsBuilder = Settings.builder().loadFromPath(Paths.get(source)); We investigated the Absolute Path:
Path path = Paths.get("/home/mcasas/myfile.txt");
Path absPath = p.toAbsolutePath(); Relative paths
|
As a conclusion, any configuration file can be loaded on runtime using the Settings class builder. The PluginSettings class from the Observability plugin is a great example of how to define, load and validate plugin specific settings. Settings.builder().loadFromPath(defaultSettingYmlFile) This method can be used for reading any configuration in the file system. While taking a look at the Settings class, I noticed the KeyStoreWrapper class, which presumably can be used to load stuff from the keystore. We should take a look at it. |
KeyStoreWrapper classThis class allow us to load an opensearch.keystore file, read the keys and also write new keys. The algorithm used to derive the cipher key from a password is "PBKDF2WithHmacSHA512". Example in TransportNodesReloadSecureSettingsAction class try (KeyStoreWrapper keystore = KeyStoreWrapper.load(environment.configDir())) {
// reread keystore from config file
if (keystore == null) {
return new NodesReloadSecureSettingsResponse.NodeResponse(
clusterService.localNode(),
new IllegalStateException("Keystore is missing")
);
}
// decrypt the keystore using the password from the request
keystore.decrypt(secureSettingsPassword.getChars());
// add the keystore to the original node settings object
final Settings settingsWithKeystore = Settings.builder().put(environment.settings(), false).setSecureSettings(keystore).build();
final List<Exception> exceptions = new ArrayList<>();
// broadcast the new settings object (with the open embedded keystore) to all reloadable plugins
pluginsService.filterPlugins(ReloadablePlugin.class).stream().forEach(p -> {
try {
p.reload(settingsWithKeystore);
} catch (final Exception e) {
logger.warn(
(Supplier<?>) () -> new ParameterizedMessage("Reload failed for plugin [{}]", p.getClass().getSimpleName()),
e
);
exceptions.add(e);
}
}); Example in Bootstrap classstatic SecureSettings loadSecureSettings(Environment initialEnv) throws BootstrapException {
final KeyStoreWrapper keystore;
try {
keystore = KeyStoreWrapper.load(initialEnv.configDir());
} catch (IOException e) {
throw new BootstrapException(e);
}
SecureString password;
try {
if (keystore != null && keystore.hasPassword()) {
password = readPassphrase(System.in, KeyStoreAwareCommand.MAX_PASSPHRASE_LENGTH);
} else {
password = new SecureString(new char[0]);
}
} catch (IOException e) {
throw new BootstrapException(e);
}
try {
if (keystore == null) {
final KeyStoreWrapper keyStoreWrapper = KeyStoreWrapper.create();
keyStoreWrapper.save(initialEnv.configDir(), new char[0]);
return keyStoreWrapper;
} else {
keystore.decrypt(password.getChars());
KeyStoreWrapper.upgrade(keystore, initialEnv.configDir(), password.getChars());
}
} catch (Exception e) {
throw new BootstrapException(e);
} finally {
password.close();
}
return keystore;
} |
More uses of the We have all the information we need for the next step, which is to implement one of these configuration persistence methods in our |
Description
As part of the development of the Command Manager plugin, we need to investigate which of the methods to persist configuration options for the plugin suits our needs best.
opensearch.yml
)./usr/share/wazuh-indexer/bin/opensearch-keystore
&/etc/wazuh-indexer/opensearch.keystore
).The goal of this issue is to:
The text was updated successfully, but these errors were encountered: