Skip to content

Commit 0ff4b1d

Browse files
committed
Address feedback from code review
Also changed readPkcs12Keystore to determine which end-entity key and cert to return based on if they have a matching public key. The old behavior would simply return the first key and cert as the EE key and cert.
1 parent 035b718 commit 0ff4b1d

File tree

7 files changed

+412
-351
lines changed

7 files changed

+412
-351
lines changed

docs/setup/settings.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ including requests that are proxied for end users. Setting this to `true` when E
8888
lead to proxied requests for end users being executed as the identity tied to the configured certificate.
8989

9090
`elasticsearch.ssl.certificate:` and `elasticsearch.ssl.key:`:: Paths to a PEM-encoded X.509 certificate and its private key, respectively.
91-
When `xpack.security.http.ssl.client_authentication` in Elasticsearch is set to `required`, the certificate and key are used to prove
92-
Kibana's identity when it makes an outbound request to your Elasticsearch cluster.
91+
When `xpack.security.http.ssl.client_authentication` in Elasticsearch is set to `required` or `optional`, the certificate and key are used
92+
to prove Kibana's identity when it makes an outbound request to your Elasticsearch cluster.
9393
+
9494
--
9595
NOTE: These settings cannot be used in conjunction with `elasticsearch.ssl.keystore.path`.
@@ -104,10 +104,10 @@ be specified via `elasticsearch.ssl.keystore.path` and/or `elasticsearch.ssl.tru
104104
`elasticsearch.ssl.key`. This value is optional, as the key may not be encrypted.
105105

106106
`elasticsearch.ssl.keystore.path:`:: Path to a PKCS #12 file that contains an X.509 certificate with its private key. When
107-
`xpack.security.http.ssl.client_authentication` in Elasticsearch is set to `required`, the certificate and key are used to prove Kibana's
108-
identity when it makes an outbound request to your Elasticsearch cluster. If the file contains any additional certificates, those will be
109-
used as a trusted certificate chain for your Elasticsearch cluster. This chain is used to establish trust when Kibana creates an SSL
110-
connection with your Elasticsearch cluster. In addition to this setting, trusted certificates may be specified via
107+
`xpack.security.http.ssl.client_authentication` in Elasticsearch is set to `required` or `optional`, the certificate and key are used to
108+
prove Kibana's identity when it makes an outbound request to your Elasticsearch cluster. If the file contains any additional certificates,
109+
those will be used as a trusted certificate chain for your Elasticsearch cluster. This chain is used to establish trust when Kibana creates
110+
an SSL connection with your Elasticsearch cluster. In addition to this setting, trusted certificates may be specified via
111111
`elasticsearch.ssl.certificateAuthorities` and/or `elasticsearch.ssl.truststore.path`.
112112
+
113113
--

src/core/server/elasticsearch/elasticsearch_config.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ describe('throws when config is invalid', () => {
257257
);
258258
});
259259

260+
it('throws if keystore does not contain a key or certificate', () => {
261+
mockReadPkcs12Keystore.mockReturnValueOnce({});
262+
const value = { ssl: { keystore: { path: 'some-path' } } };
263+
expect(() =>
264+
createElasticsearchConfig(config.schema.validate(value))
265+
).toThrowErrorMatchingInlineSnapshot(
266+
`"Did not find key or certificate in Elasticsearch keystore."`
267+
);
268+
});
269+
260270
it('throws if truststore path is invalid', () => {
261271
const value = { ssl: { keystore: { path: '/invalid/truststore' } } };
262272
expect(() =>

src/core/server/elasticsearch/elasticsearch_config.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,21 @@ export class ElasticsearchConfig {
232232
let certificateAuthorities: string[] | undefined;
233233
const addCAs = (ca: string[] | undefined) => {
234234
if (ca && ca.length) {
235-
certificateAuthorities = certificateAuthorities ? certificateAuthorities.concat(ca) : ca;
235+
certificateAuthorities = [...(certificateAuthorities || []), ...ca];
236236
}
237237
};
238238

239239
if (rawConfig.ssl.keystore?.path) {
240-
const { key: k, cert, ca } = readPkcs12Keystore(
240+
const keystore = readPkcs12Keystore(
241241
rawConfig.ssl.keystore.path,
242242
rawConfig.ssl.keystore.password
243243
);
244-
if (!k && !cert) {
245-
log.warn(
246-
`Did not find key or certificate in keystore; mutual TLS authentication is disabled.`
247-
);
244+
if (!keystore.key && !keystore.cert) {
245+
throw new Error(`Did not find key or certificate in Elasticsearch keystore.`);
248246
}
249-
key = k;
250-
certificate = cert;
251-
addCAs(ca);
247+
key = keystore.key;
248+
certificate = keystore.cert;
249+
addCAs(keystore.ca);
252250
} else {
253251
if (rawConfig.ssl.key) {
254252
key = readFile(rawConfig.ssl.key);

0 commit comments

Comments
 (0)