Skip to content

Commit 4d79a59

Browse files
authored
Add 'SslProfileExtension' SPI interface (#134609)
This new SPI extension point allows plugins to define new SSL profiles (contexts) that will be automatically loaded and managed by the SSLService Each extension defines the settings prefix(s) that it uses (e.g. "foo.bar.ssl") and then the SSL Service reads those settings and constructs `SslConfiguration` and `SslProfile` objects from those settings. The `SslProfile` is provided back to the extension for its use
1 parent 43f7c0d commit 4d79a59

File tree

17 files changed

+415
-53
lines changed

17 files changed

+415
-53
lines changed

docs/changelog/134609.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 134609
2+
summary: Add 'SslProfileExtension' SPI interface
3+
area: TLS
4+
type: enhancement
5+
issues: []

x-pack/plugin/core/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
exports org.elasticsearch.xpack.core.sql;
192192
exports org.elasticsearch.xpack.core.ssl.action;
193193
exports org.elasticsearch.xpack.core.ssl.cert;
194+
exports org.elasticsearch.xpack.core.ssl.extension;
194195
exports org.elasticsearch.xpack.core.ssl.rest;
195196
exports org.elasticsearch.xpack.core.ssl;
196197
exports org.elasticsearch.xpack.core.template;

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.common.settings.Setting;
2929
import org.elasticsearch.common.settings.Settings;
3030
import org.elasticsearch.common.settings.SettingsFilter;
31-
import org.elasticsearch.common.ssl.SslConfiguration;
3231
import org.elasticsearch.common.util.BigArrays;
3332
import org.elasticsearch.core.Booleans;
3433
import org.elasticsearch.env.Environment;
@@ -110,6 +109,7 @@
110109
import org.elasticsearch.xpack.core.security.authz.RoleMappingMetadata;
111110
import org.elasticsearch.xpack.core.ssl.SSLConfigurationReloader;
112111
import org.elasticsearch.xpack.core.ssl.SSLService;
112+
import org.elasticsearch.xpack.core.ssl.extension.SslProfileExtension;
113113
import org.elasticsearch.xpack.core.termsenum.action.TermsEnumAction;
114114
import org.elasticsearch.xpack.core.termsenum.action.TransportTermsEnumAction;
115115
import org.elasticsearch.xpack.core.termsenum.rest.RestTermsEnumAction;
@@ -185,6 +185,8 @@ public Void run() {
185185
private static SetOnce<XPackLicenseState> licenseState = new SetOnce<>();
186186
private static SetOnce<LicenseService> licenseService = new SetOnce<>();
187187

188+
private final List<SslProfileExtension> sslExtensions = new ArrayList<>();
189+
188190
public XPackPlugin(final Settings settings) {
189191
super();
190192
// FIXME: The settings might be changed after this (e.g. from "additionalSettings" method in other plugins)
@@ -465,6 +467,8 @@ public List<Setting<?>> getSettings() {
465467
List<Setting<?>> settings = super.getSettings();
466468
settings.add(SourceOnlySnapshotRepository.SOURCE_ONLY);
467469

470+
settings.addAll(SSLService.getExtensionSettings(this.sslExtensions));
471+
468472
// Don't register the license setting if there is an alternate implementation loaded as an extension.
469473
// this relies on the order in which methods are called - loadExtensions, (this method) getSettings, then createComponents
470474
if (getSharedLicenseService() == null) {
@@ -496,9 +500,9 @@ public Collection<IndexSettingProvider> getAdditionalIndexSettingProviders(Index
496500
* of SSLContexts when configuration files change on disk.
497501
*/
498502
private SSLService createSSLService(Environment environment, ResourceWatcherService resourceWatcherService) {
499-
final Map<String, SslConfiguration> sslConfigurations = SSLService.getSSLConfigurations(environment);
503+
final SSLService.LoadedSslConfigurations sslConfigurations = SSLService.getSSLConfigurations(environment, this.sslExtensions);
500504
// Must construct the reloader before the SSL service so that we don't miss any config changes, see #54867
501-
final SSLConfigurationReloader reloader = new SSLConfigurationReloader(resourceWatcherService, sslConfigurations.values());
505+
final SSLConfigurationReloader reloader = new SSLConfigurationReloader(resourceWatcherService, sslConfigurations);
502506
final SSLService sslService = new SSLService(environment, sslConfigurations);
503507
reloader.setSSLService(sslService);
504508
setSslService(sslService);
@@ -507,6 +511,11 @@ private SSLService createSSLService(Environment environment, ResourceWatcherServ
507511

508512
@Override
509513
public void loadExtensions(ExtensionLoader loader) {
514+
loadLicenseService(loader);
515+
this.sslExtensions.addAll(loader.loadExtensions(SslProfileExtension.class));
516+
}
517+
518+
private void loadLicenseService(ExtensionLoader loader) {
510519
List<MutableLicenseService> licenseServices = loader.loadExtensions(MutableLicenseService.class);
511520
if (licenseServices.size() > 1) {
512521
throw new IllegalStateException(MutableLicenseService.class + " may not have multiple implementations");

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloader.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ protected boolean blockingAllowed() {
4545
}
4646
};
4747

48-
public SSLConfigurationReloader(ResourceWatcherService resourceWatcherService, Collection<SslConfiguration> sslConfigurations) {
49-
startWatching(reloadConsumer(sslServiceFuture), resourceWatcherService, sslConfigurations);
48+
public SSLConfigurationReloader(ResourceWatcherService resourceWatcherService, SSLService.LoadedSslConfigurations sslConfiguration) {
49+
startWatching(reloadConsumer(sslServiceFuture), resourceWatcherService, sslConfiguration);
5050
}
5151

5252
// for testing
5353
SSLConfigurationReloader(
5454
Consumer<SslConfiguration> reloadConsumer,
5555
ResourceWatcherService resourceWatcherService,
56-
Collection<SslConfiguration> sslConfigurations
56+
SSLService.LoadedSslConfigurations sslConfiguration
5757
) {
58-
startWatching(reloadConsumer, resourceWatcherService, sslConfigurations);
58+
startWatching(reloadConsumer, resourceWatcherService, sslConfiguration);
5959
}
6060

6161
public void setSSLService(SSLService sslService) {
@@ -84,10 +84,10 @@ private static Consumer<SslConfiguration> reloadConsumer(Future<SSLService> futu
8484
private static void startWatching(
8585
Consumer<SslConfiguration> reloadConsumer,
8686
ResourceWatcherService resourceWatcherService,
87-
Collection<SslConfiguration> sslConfigurations
87+
SSLService.LoadedSslConfigurations sslConfigurations
8888
) {
8989
Map<Path, List<SslConfiguration>> pathToConfigurationsMap = new HashMap<>();
90-
for (SslConfiguration sslConfiguration : sslConfigurations) {
90+
for (SslConfiguration sslConfiguration : sslConfigurations.configurations()) {
9191
final Collection<Path> filesToMonitor = sslConfiguration.getDependentFiles();
9292
for (Path file : filesToMonitor) {
9393
pathToConfigurationsMap.compute(file, (path, list) -> {

0 commit comments

Comments
 (0)