Skip to content

Commit 933293a

Browse files
authored
feat: add elasticsearch ssl options (#5499)
1 parent 6943524 commit 933293a

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

server/modules/search/elasticsearch/definition.yml

+14-5
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,37 @@ props:
2020
title: Host(s)
2121
hint: Comma-separated list of Elasticsearch hosts to connect to, including the port, username and password if necessary. (e.g. http://localhost:9200, https://user:pass@es1.example.com:9200)
2222
order: 2
23+
verifyTLSCertificate:
24+
title: Verify TLS Certificate
25+
type: Boolean
26+
default: true
27+
order: 3
28+
tlsCertPath:
29+
title: TLS Certificate Path
30+
type: String
31+
hint: Absolute path to the TLS certificate on the server.
32+
order: 4
2333
indexName:
2434
type: String
2535
title: Index Name
2636
hint: The index name to use during creation
2737
default: wiki
28-
order: 3
38+
order: 5
2939
analyzer:
3040
type: String
3141
title: Analyzer
3242
hint: 'The token analyzer in elasticsearch'
3343
default: simple
34-
order: 4
44+
order: 6
3545
sniffOnStart:
3646
type: Boolean
3747
title: Sniff on start
3848
hint: 'Should Wiki.js attempt to detect the rest of the cluster on first connect? (Default: off)'
3949
default: false
40-
order: 5
50+
order: 7
4151
sniffInterval:
4252
type: Number
4353
title: Sniff Interval
4454
hint: '0 = disabled, Interval in seconds to check for updated list of nodes in cluster. (Default: 0)'
4555
default: 0
46-
order: 6
47-
56+
order: 8

server/modules/search/elasticsearch/engine.js

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('lodash')
22
const stream = require('stream')
33
const Promise = require('bluebird')
4+
const fs = require('fs')
45
const pipeline = Promise.promisify(stream.pipeline)
56

67
/* global WIKI */
@@ -24,6 +25,7 @@ module.exports = {
2425
nodes: this.config.hosts.split(',').map(_.trim),
2526
sniffOnStart: this.config.sniffOnStart,
2627
sniffInterval: (this.config.sniffInterval > 0) ? this.config.sniffInterval : false,
28+
ssl: getTlsOptions(this.config),
2729
name: 'wiki-js'
2830
})
2931
break
@@ -33,6 +35,7 @@ module.exports = {
3335
nodes: this.config.hosts.split(',').map(_.trim),
3436
sniffOnStart: this.config.sniffOnStart,
3537
sniffInterval: (this.config.sniffInterval > 0) ? this.config.sniffInterval : false,
38+
ssl: getTlsOptions(this.config),
3639
name: 'wiki-js'
3740
})
3841
break
@@ -351,3 +354,21 @@ module.exports = {
351354
WIKI.logger.info(`(SEARCH/ELASTICSEARCH) Index rebuilt successfully.`)
352355
}
353356
}
357+
358+
function getTlsOptions(conf) {
359+
if (!conf.tlsCertPath) {
360+
return {
361+
rejectUnauthorized: conf.verifyTLSCertificate
362+
}
363+
}
364+
365+
const caList = []
366+
if (conf.verifyTLSCertificate) {
367+
caList.push(fs.readFileSync(conf.tlsCertPath))
368+
}
369+
370+
return {
371+
rejectUnauthorized: conf.verifyTLSCertificate,
372+
ca: caList
373+
}
374+
}

0 commit comments

Comments
 (0)