Skip to content

Commit 03e6d71

Browse files
committed
Added missing SSL settings
1 parent 6f3828b commit 03e6d71

File tree

6 files changed

+272
-69
lines changed

6 files changed

+272
-69
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## 11.14.0
2-
- Reviewed and deprecated SSL settings to comply with Logstash's naming convention [#1115](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1115)
2+
- Added SSL settings for: [#1115](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1115)
3+
- `ssl_truststore_type`: The format of the truststore file
4+
- `ssl_keystore_type`: The format of the keystore file
5+
- `ssl_certificate`: OpenSSL-style X.509 certificate file to authenticate the client
6+
- `ssl_key`: OpenSSL-style RSA private key that corresponds to the `ssl_certificate`
7+
- `ssl_cipher_suites`: The list of cipher suites
8+
- Reviewed and deprecated SSL settings to comply with Logstash's naming convention
39
- Deprecated `ssl` in favor of `ssl_enabled`
410
- Deprecated `cacert` in favor of `ssl_certificate_authorities`
511
- Deprecated `keystore` in favor of `ssl_keystore_path`

docs/index.asciidoc

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,19 @@ This plugin supports the following configuration options plus the
359359
| <<plugins-{type}s-{plugin}-sniffing_delay>> |<<number,number>>|No
360360
| <<plugins-{type}s-{plugin}-sniffing_path>> |<<string,string>>|No
361361
| <<plugins-{type}s-{plugin}-ssl>> |<<boolean,boolean>>|__Deprecated__
362+
| <<plugins-{type}s-{plugin}-ssl_certificate>> |<<path,path>>|No
362363
| <<plugins-{type}s-{plugin}-ssl_certificate_authorities>> |list of <<path,path>>|No
363364
| <<plugins-{type}s-{plugin}-ssl_certificate_verification>> |<<boolean,boolean>>|__Deprecated__
365+
| <<plugins-{type}s-{plugin}-ssl_cipher_suites>> |list of <<string,string>>|No
364366
| <<plugins-{type}s-{plugin}-ssl_enabled>> |<<boolean,boolean>>|No
367+
| <<plugins-{type}s-{plugin}-ssl_key>> |<<path,path>>|No
365368
| <<plugins-{type}s-{plugin}-ssl_keystore_password>> |<<password,password>>|No
366369
| <<plugins-{type}s-{plugin}-ssl_keystore_path>> |<<path,path>>|No
370+
| <<plugins-{type}s-{plugin}-ssl_keystore_type>> |<<string,string>>|No
367371
| <<plugins-{type}s-{plugin}-ssl_supported_protocols>> |<<string,string>>|No
368372
| <<plugins-{type}s-{plugin}-ssl_truststore_password>> |<<password,password>>|No
369373
| <<plugins-{type}s-{plugin}-ssl_truststore_path>> |<<path,path>>|No
374+
| <<plugins-{type}s-{plugin}-ssl_truststore_type>> |<<string,string>>|No
370375
| <<plugins-{type}s-{plugin}-ssl_verification_mode>> |<<string,string>>, one of `["full", "none"]`|No
371376
| <<plugins-{type}s-{plugin}-template>> |a valid filesystem path|No
372377
| <<plugins-{type}s-{plugin}-template_api>> |<<string,string>>, one of `["auto", "legacy", "composable"]`|No
@@ -787,6 +792,8 @@ deprecated[8.8.0, Replaced by <<plugins-{type}s-{plugin}-ssl_keystore_path>>]
787792
The keystore used to present a certificate to the server.
788793
It can be either .jks or .p12
789794

795+
NOTE: You cannot use this setting and `ssl_certificate` at the same time.
796+
790797
[id="plugins-{type}s-{plugin}-keystore_password"]
791798
===== `keystore_password`
792799
deprecated[8.8.0, Replaced by <<plugins-{type}s-{plugin}-ssl_keystore_password>>]
@@ -1055,6 +1062,15 @@ Enable SSL/TLS secured communication to Elasticsearch cluster.
10551062
Leaving this unspecified will use whatever scheme is specified in the URLs listed in <<plugins-{type}s-{plugin}-hosts>> or extracted from the <<plugins-{type}s-{plugin}-cloud_id>>.
10561063
If no explicit protocol is specified plain HTTP will be used.
10571064

1065+
[id="plugins-{type}s-{plugin}-ssl_certificate"]
1066+
===== `ssl_certificate`
1067+
* Value type is <<path,path>>
1068+
* There is no default value for this setting.
1069+
1070+
SSL certificate to use to authenticate the client. This certificate should be an OpenSSL-style X.509 certificate file.
1071+
1072+
NOTE: This setting can be used only if `ssl_key` is set.
1073+
10581074
[id="plugins-{type}s-{plugin}-ssl_certificate_authorities"]
10591075
===== `ssl_certificate_authorities`
10601076

@@ -1063,6 +1079,8 @@ If no explicit protocol is specified plain HTTP will be used.
10631079

10641080
The .cer or .pem files to validate the server's certificate.
10651081

1082+
NOTE: You cannot use this setting and `ssl_truststore_path` at the same time.
1083+
10661084
[id="plugins-{type}s-{plugin}-ssl_certificate_verification"]
10671085
===== `ssl_certificate_verification`
10681086
deprecated[8.8.0, Replaced by <<plugins-{type}s-{plugin}-ssl_verification_mode>>]
@@ -1074,6 +1092,14 @@ Option to validate the server's certificate. Disabling this severely compromises
10741092
For more information on disabling certificate verification please read
10751093
https://www.cs.utexas.edu/~shmat/shmat_ccs12.pdf
10761094

1095+
[id="plugins-{type}s-{plugin}-ssl_cipher_suites"]
1096+
===== `ssl_cipher_suites`
1097+
* Value type is a list of <<string,string>>
1098+
* There is no default value for this setting
1099+
1100+
The list of cipher suites to use, listed by priorities.
1101+
Supported cipher suites vary depending on which version of Java is used.
1102+
10771103
[id="plugins-{type}s-{plugin}-ssl_enabled"]
10781104
===== `ssl_enabled`
10791105

@@ -1084,6 +1110,15 @@ Enable SSL/TLS secured communication to Elasticsearch cluster.
10841110
Leaving this unspecified will use whatever scheme is specified in the URLs listed in <<plugins-{type}s-{plugin}-hosts>> or extracted from the <<plugins-{type}s-{plugin}-cloud_id>>.
10851111
If no explicit protocol is specified plain HTTP will be used.
10861112

1113+
[id="plugins-{type}s-{plugin}-ssl_key"]
1114+
===== `ssl_key`
1115+
* Value type is <<path,path>>
1116+
* There is no default value for this setting.
1117+
1118+
OpenSSL-style RSA private key that corresponds to the `ssl_certificate`.
1119+
1120+
NOTE: This setting can be used only if `ssl_certificate` is set.
1121+
10871122
[id="plugins-{type}s-{plugin}-ssl_keystore_password"]
10881123
===== `ssl_keystore_password`
10891124

@@ -1101,6 +1136,16 @@ Set the keystore password
11011136
The keystore used to present a certificate to the server.
11021137
It can be either .jks or .p12
11031138

1139+
NOTE: You cannot use this setting and `ssl_certificate` at the same time.
1140+
1141+
[id="plugins-{type}s-{plugin}-ssl_keystore_type"]
1142+
===== `ssl_keystore_type`
1143+
1144+
* Value can be any of: `jks`, `pkcs12`
1145+
* If not provided, the value will be inferred from the keystore filename.
1146+
1147+
The format of the keystore file. It must be either `jks` or `pkcs12`.
1148+
11041149
[id="plugins-{type}s-{plugin}-ssl_supported_protocols"]
11051150
===== `ssl_supported_protocols`
11061151

@@ -1134,7 +1179,16 @@ Set the truststore password
11341179

11351180
The truststore to validate the server's certificate.
11361181
It can be either .jks or .p12.
1137-
Use either `:truststore` or `:cacert`.
1182+
1183+
NOTE: You cannot use this setting and `ssl_certificate_authorities` at the same time.
1184+
1185+
[id="plugins-{type}s-{plugin}-ssl_truststore_type"]
1186+
===== `ssl_truststore_type`
1187+
1188+
* Value can be any of: `jks`, `pkcs12`
1189+
* If not provided, the value will be inferred from the truststore filename.
1190+
1191+
The format of the truststore file. It must be either `jks` or `pkcs12`.
11381192

11391193
[id="plugins-{type}s-{plugin}-ssl_verification_mode"]
11401194
===== `ssl_verification_mode`

lib/logstash/outputs/elasticsearch/http_client_builder.rb

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,44 @@ def self.setup_ssl(logger, params)
112112

113113
return {:ssl => {:enabled => false}} if params["ssl_enabled"] == false
114114

115-
ssl_certificate_authorities, ssl_truststore_path, ssl_truststore_password, ssl_keystore_path, ssl_keystore_password, ssl_verification_mode =
116-
params.values_at('ssl_certificate_authorities', 'ssl_truststore_path', 'ssl_truststore_password', 'ssl_keystore_path', 'ssl_keystore_password', 'ssl_verification_mode')
115+
ssl_certificate_authorities, ssl_truststore_path, ssl_certificate, ssl_keystore_path = params.values_at('ssl_certificate_authorities', 'ssl_truststore_path', 'ssl_certificate', 'ssl_keystore_path')
117116

118117
if ssl_certificate_authorities && ssl_truststore_path
119-
raise(LogStash::ConfigurationError, "Use either \"ssl_certificate_authorities\" or \"ssl_truststore_path\" when configuring the CA certificate")
118+
raise(LogStash::ConfigurationError, 'Use either "ssl_certificate_authorities/cacert" or "ssl_truststore_path/truststore" when configuring the CA certificate')
119+
end
120+
121+
if ssl_certificate && ssl_keystore_path
122+
raise(LogStash::ConfigurationError, 'Use either "ssl_certificate" or "ssl_keystore_path/keystore" when configuring client certificates')
120123
end
121124

122125
ssl_options = {:enabled => true}
123126

124127
if ssl_certificate_authorities&.any?
125-
raise(LogStash::ConfigurationError, "Multiple \"ssl_certificate_authorities\" files are not supported") if ssl_certificate_authorities.size > 1
128+
raise(LogStash::ConfigurationError, 'Multiple values on "ssl_certificate_authorities" are not supported by this plugin') if ssl_certificate_authorities.size > 1
126129
ssl_options[:ca_file] = ssl_certificate_authorities.first
127-
elsif ssl_truststore_path
128-
ssl_options[:truststore_password] = ssl_truststore_password.value if ssl_truststore_password
129130
end
130131

131-
ssl_options[:truststore] = ssl_truststore_path if ssl_truststore_path
132+
if ssl_truststore_path
133+
ssl_options[:truststore] = ssl_truststore_path
134+
ssl_options[:truststore_type] = params["ssl_truststore_type"] if params.include?("ssl_truststore_type")
135+
ssl_options[:truststore_password] = params["ssl_truststore_password"].value if params.include?("ssl_truststore_password")
136+
end
137+
132138
if ssl_keystore_path
133139
ssl_options[:keystore] = ssl_keystore_path
134-
ssl_options[:keystore_password] = ssl_keystore_password.value if ssl_keystore_password
140+
ssl_options[:keystore_type] = params["ssl_keystore_type"] if params.include?("ssl_keystore_type")
141+
ssl_options[:keystore_password] = params["ssl_keystore_password"].value if params.include?("ssl_keystore_password")
142+
end
143+
144+
ssl_key = params["ssl_key"]
145+
if ssl_certificate && ssl_key
146+
ssl_options[:client_cert] = ssl_certificate
147+
ssl_options[:client_key] = ssl_key
148+
elsif !!ssl_certificate ^ !!ssl_key
149+
raise(LogStash::ConfigurationError, 'You must set both "ssl_certificate" and "ssl_key" for client authentication')
135150
end
136151

152+
ssl_verification_mode = params["ssl_verification_mode"]
137153
unless ssl_verification_mode.nil?
138154
case ssl_verification_mode
139155
when 'none'
@@ -145,6 +161,7 @@ def self.setup_ssl(logger, params)
145161
end
146162
end
147163

164+
ssl_options[:cipher_suites] = params["ssl_cipher_suites"] if params.include?("ssl_cipher_suites")
148165
ssl_options[:trust_strategy] = params["ssl_trust_strategy"] if params.include?("ssl_trust_strategy")
149166

150167
protocols = params['ssl_supported_protocols']

lib/logstash/plugin_mixins/elasticsearch/api_configs.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ module APIConfigs
8080
# Use either `:ssl_truststore_path` or `:ssl_certificate_authorities`
8181
:ssl_truststore_path => { :validate => :path },
8282

83+
# The format of the truststore file. It must be either jks or pkcs12
84+
:ssl_truststore_type => { :validate => %w[pkcs12 jks] },
85+
8386
# Set the truststore password
8487
:truststore_password => { :validate => :password, :deprecated => "Use 'ssl_truststore_password' instead." },
8588

@@ -94,6 +97,9 @@ module APIConfigs
9497
# It can be either .jks or .p12
9598
:ssl_keystore_path => { :validate => :path },
9699

100+
# The format of the keystore file. It must be either jks or pkcs12
101+
:ssl_keystore_type => { :validate => %w[pkcs12 jks] },
102+
97103
# Set the keystore password
98104
:keystore_password => { :validate => :password, :deprecated => "Set 'ssl_keystore_password' instead." },
99105

@@ -102,6 +108,16 @@ module APIConfigs
102108

103109
:ssl_supported_protocols => { :validate => ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], :default => [], :list => true },
104110

111+
# OpenSSL-style X.509 certificate certificate to authenticate the client
112+
:ssl_certificate => { :validate => :path },
113+
114+
# OpenSSL-style RSA private key to authenticate the client
115+
:ssl_key => { :validate => :path },
116+
117+
# The list of cipher suites to use, listed by priorities.
118+
# Supported cipher suites vary depending on which version of Java is used.
119+
:ssl_cipher_suites => { :validate => :string, :list => true },
120+
105121
# This setting asks Elasticsearch for the list of all cluster nodes and adds them to the hosts list.
106122
# Note: This will return ALL nodes with HTTP enabled (including master nodes!). If you use
107123
# this with master nodes, you probably want to disable HTTP on them by setting

spec/unit/outputs/elasticsearch_spec.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,6 @@
705705
include_examples("an encrypted client connection")
706706
end
707707

708-
context "With the 'ssl_enabled' option" do
709-
let(:options) { {"ssl_enabled" => true}}
710-
711-
include_examples("an encrypted client connection")
712-
end
713-
714708
context "With an https host" do
715709
let(:options) { {"hosts" => "https://localhost"} }
716710
include_examples("an encrypted client connection")
@@ -731,15 +725,15 @@
731725
File.delete(cacert)
732726
end
733727

734-
it 'should map new configs into params' do
728+
it "should map new configs into params" do
735729
expect(subject.params).to match hash_including(
736730
"ssl_enabled" => true,
737731
"ssl_verification_mode" => "none",
738732
"ssl_certificate_authorities" => [cacert]
739733
)
740734
end
741735

742-
it 'should set new configs variables' do
736+
it "should set new configs variables" do
743737
expect(subject.instance_variable_get(:@ssl_enabled)).to eql(true)
744738
expect(subject.instance_variable_get(:@ssl_verification_mode)).to eql("none")
745739
expect(subject.instance_variable_get(:@ssl_certificate_authorities)).to eql([cacert])
@@ -769,7 +763,7 @@
769763
File.delete(truststore)
770764
end
771765

772-
it 'should map new configs into params' do
766+
it "should map new configs into params" do
773767
expect(subject.params).to match hash_including(
774768
"ssl_enabled" => true,
775769
"ssl_keystore_path" => keystore,
@@ -781,7 +775,7 @@
781775
expect(subject.params["ssl_truststore_password"].value).to eql("truststore")
782776
end
783777

784-
it 'should set new configs variables' do
778+
it "should set new configs variables" do
785779
expect(subject.instance_variable_get(:@ssl_enabled)).to eql(true)
786780
expect(subject.instance_variable_get(:@ssl_keystore_path)).to eql(keystore)
787781
expect(subject.instance_variable_get(:@ssl_keystore_password).value).to eql("keystore")

0 commit comments

Comments
 (0)