# Accessing settings in the keystore

**URL:** https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763
**Category:** Elasticsearch
**Created:** [January 9, 2018, 10:19pm UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763 "2018-01-09T22:19:41Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 9, 2018, 10:19pm UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/1 "2018-01-09T22:19:41Z")

</div>

How can properties be read from the keystore from inside a plugin? The only  
current usage in the main repo is the s3 repository, but that code is  
complex (in terms of the amount of calls) and I rather not have to debug  
it. Simply want to read the value.

I am still on 5.x if that matters.

Cheers,

Ivan

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [January 9, 2018, 10:33pm UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/2 "2018-01-09T22:33:10Z")

</div>

Are you wanting to read an existing secure setting, or your own plugins setting? If your own, you need to create a SecureSetting instance, return that from getSettings() on your plugin, and then use that Setting object to read the value of the setting from Settings once your plugin is initialized.

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 9, 2018, 11:16pm UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/3 "2018-01-09T23:16:38Z")

</div>

I already found out the answer, but since this mailing list does not send  
an email to the sender, I could not reply. Not sure if I can reply to my  
original sent email or would that create a new thread.

At first I got it working but creating a KeystoreWrapper and then  
decrypting it with an empty password, but I thought that surely that method  
cannot be correct. Then I found the SecureString class.

There should be a development mailing list for those that like work on the  
_cough_undocumented_cough_ internals. 😉

Thanks,

Ivan

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 10, 2018, 12:39am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/4 "2018-01-10T00:39:24Z")

</div>

Not sure if this is a bug that has been resolved or not, but the keystore  
only saves one of the values. Using version 5.5.3

integTestCluster {  
keystoreSetting 'foo', 'abc'  
keystoreSetting 'bar', 'xyz'  
keystoreSetting 'baz', 'qwerty'  
}

public class MyPlugin extends Plugin implements IngestPlugin {

```
static final Setting<SecureString> FOO =

```

SecureSetting.secureString("foo", null);  
static final Setting BAR =  
SecureSetting.secureString("bar", null);  
static final Setting BAZ =  
SecureSetting.secureString("baz", null);

```
@Override
public Map<String, Processor.Factory>

```

getProcessors(Processor.Parameters parameters) {  
Logger logger = Loggers.getLogger(getClass());

```
    SecureString foo = FOO.get(parameters.env.settings());
    SecureString bar = BAR.get(parameters.env.settings());
    SecureString baz = BAZ.get(parameters.env.settings());

    logger.warn("all settings {}",

```

parameters.env.settings().toDelimitedString('\n'));  
logger.warn("foo: {} for {}", foo, FOO.getKey());  
logger.warn("bar: {} for {}", bar, BAR.getKey());  
logger.warn("baz: {} for {}", bar, BAZ.getKey());

```
    return new HashMap<>();
}

@Override
public List<Setting<?>> getSettings() {
    return Arrays.asList(FOO, BAR, BAZ);
}

```

}

returns  
foo: qwerty for foo  
bar: qwerty for bar  
baz: qwerty for baz

integTestCluster {  
keystoreSetting 'foo', '1'  
keystoreSetting 'bar', '2'  
keystoreSetting 'baz', '3'  
}

returns  
foo: 3 for foo  
bar: 3 for bar  
baz: 3 for baz

Hopefully you can comment before I open an issue.

Thanks,

Ivan

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 10, 2018, 12:48am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/5 "2018-01-10T00:48:25Z")

</div>

And just to eliminate gradle issues:

project.afterEvaluate {  
logger.warn(integTestCluster.keystoreSettings.toString())  
}

[bar:2, foo:1, baz:3]

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [January 10, 2018, 12:54am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/6 "2018-01-10T00:54:43Z")

</div>

I believe this was already fixed. Let me find the issue.

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [January 10, 2018, 1:03am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/7 "2018-01-10T01:03:23Z")

</div>

Here you go, fixed in 5.6.0:

> <https://github.com/elastic/elasticsearch/pull/26243>

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 10, 2018, 1:18am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/8 "2018-01-10T01:18:32Z")

</div>

Looks like I need to ugprade, at least it is not to 6.x. I looked for  
"keystore" issues, so this one escaped me. Although it makes sense, that  
bug would have taken me a bit to find!

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [January 10, 2018, 1:36am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/9 "2018-01-10T01:36:57Z")

</div>

Groovy is a horrible drug. 🙂

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [February 7, 2018, 1:37am UTC](https://discuss.elastic.co/t/accessing-settings-in-the-keystore/114763/10 "2018-02-07T01:37:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
