-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Access SSL contexts using names instead of Settings (#30953)
Historically we have loaded SSL objects (such as SSLContext, SSLIOSessionStrategy) by passing in the SSL settings, constructing a new SSL configuration from those settings and then looking for a cached object that matches those settings. The primary issue with this approach is that it requires a fully configured Settings object to be available any time the SSL context needs to be loaded. If the Settings include SecureSettings (such as passwords for keys or keystores) then this is not true, and the cached SSL object cannot be loaded at runtime. This commit introduces an alternative approach of naming every cached ssl configuration, so that it is possible to load the SSL context for a named configuration (such as "xpack.http.ssl"). This means that the calling code does not need to have ongoing access to the secure settings that were used to load the configuration. This change also allows monitoring exporters to use SSL passwords from secure settings, however an exporter that uses a secure SSL setting (e.g. truststore.secure_password) may not have its SSL settings updated dynamically (this is prevented by a settings validator). Exporters without secure settings can continue to be defined and updated dynamically.
- Loading branch information
Showing
34 changed files
with
844 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
241 changes: 115 additions & 126 deletions
241
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLService.java
Large diffs are not rendered by default.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
.../org/elasticsearch/xpack/core/security/transport/netty4/SecurityNetty4TransportTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.transport.netty4; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.TestEnvironment; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.xpack.core.ssl.SSLConfiguration; | ||
import org.elasticsearch.xpack.core.ssl.SSLService; | ||
import org.elasticsearch.xpack.core.ssl.VerificationMode; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.util.Map; | ||
|
||
import static org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport.getTransportProfileConfigurations; | ||
|
||
public class SecurityNetty4TransportTests extends ESTestCase { | ||
|
||
public void testGetTransportProfileConfigurations() { | ||
final Settings settings = Settings.builder() | ||
.put("path.home", createTempDir()) | ||
.put("xpack.security.transport.ssl.verification_mode", VerificationMode.CERTIFICATE.name()) | ||
.put("transport.profiles.full.xpack.security.ssl.verification_mode", VerificationMode.FULL.name()) | ||
.put("transport.profiles.cert.xpack.security.ssl.verification_mode", VerificationMode.CERTIFICATE.name()) | ||
.put("transport.profiles.none.xpack.security.ssl.verification_mode", VerificationMode.NONE.name()) | ||
.build(); | ||
final Environment env = TestEnvironment.newEnvironment(settings); | ||
SSLService sslService = new SSLService(settings, env); | ||
final SSLConfiguration defaultConfig = sslService.getSSLConfiguration("xpack.security.transport.ssl"); | ||
final Map<String, SSLConfiguration> profileConfigurations = getTransportProfileConfigurations(settings, sslService, defaultConfig); | ||
assertThat(profileConfigurations.size(), Matchers.equalTo(4)); | ||
assertThat(profileConfigurations.keySet(), Matchers.containsInAnyOrder("full", "cert", "none", "default")); | ||
assertThat(profileConfigurations.get("full").verificationMode(), Matchers.equalTo(VerificationMode.FULL)); | ||
assertThat(profileConfigurations.get("cert").verificationMode(), Matchers.equalTo(VerificationMode.CERTIFICATE)); | ||
assertThat(profileConfigurations.get("none").verificationMode(), Matchers.equalTo(VerificationMode.NONE)); | ||
assertThat(profileConfigurations.get("default"), Matchers.sameInstance(defaultConfig)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.