77
88import org .apache .http .conn .ssl .NoopHostnameVerifier ;
99import org .apache .http .nio .conn .ssl .SSLIOSessionStrategy ;
10+ import org .apache .logging .log4j .LogManager ;
11+ import org .apache .logging .log4j .Logger ;
1012import org .apache .lucene .util .SetOnce ;
1113import org .elasticsearch .ElasticsearchException ;
1214import org .elasticsearch .common .CheckedSupplier ;
1315import org .elasticsearch .common .Strings ;
1416import org .elasticsearch .common .component .AbstractComponent ;
17+ import org .elasticsearch .common .logging .DeprecationLogger ;
1518import org .elasticsearch .common .settings .Settings ;
1619import org .elasticsearch .env .Environment ;
1720import org .elasticsearch .xpack .core .XPackSettings ;
1821import org .elasticsearch .xpack .core .common .socket .SocketAccess ;
1922import org .elasticsearch .xpack .core .security .SecurityField ;
23+ import org .elasticsearch .xpack .core .security .authc .ldap .LdapRealmSettings ;
24+ import org .elasticsearch .xpack .core .security .authc .saml .SamlRealmSettings ;
2025import org .elasticsearch .xpack .core .ssl .cert .CertificateInfo ;
2126
2227import javax .net .ssl .HostnameVerifier ;
6166 */
6267public class SSLService extends AbstractComponent {
6368
64- private final Settings settings ;
69+ private static final Logger logger = LogManager .getLogger (SSLService .class );
70+ private static final DeprecationLogger deprecationLogger = new DeprecationLogger (logger );
6571
6672 /**
6773 * This is a mapping from "context name" (in general use, the name of a setting key)
@@ -83,6 +89,7 @@ public class SSLService extends AbstractComponent {
8389 private final SSLConfiguration globalSSLConfiguration ;
8490 private final SetOnce <SSLConfiguration > transportSSLConfiguration = new SetOnce <>();
8591 private final Environment env ;
92+ private final Settings settings ;
8693
8794 /**
8895 * Create a new SSLService that parses the settings for the ssl contexts that need to be created, creates them, and then caches them
@@ -119,6 +126,13 @@ Map<SSLConfiguration, SSLContextHolder> loadSSLConfigurations() {
119126 return Collections .emptyMap ();
120127 }
121128
129+ @ Override
130+ SSLConfiguration sslConfiguration (Settings settings ) {
131+ SSLConfiguration sslConfiguration = super .sslConfiguration (settings );
132+ SSLService .this .checkSSLConfigurationForFallback ("monitoring.exporters" , settings , sslConfiguration );
133+ return sslConfiguration ;
134+ }
135+
122136 /**
123137 * Returns the existing {@link SSLContextHolder} for the configuration
124138 * @throws IllegalArgumentException if not found
@@ -405,22 +419,35 @@ Map<SSLConfiguration, SSLContextHolder> loadSSLConfigurations() {
405419
406420 sslSettingsMap .forEach ((key , sslSettings ) -> {
407421 if (sslSettings .isEmpty ()) {
422+ if (shouldCheckForFallbackDeprecation (key )) {
423+ checkSSLConfigurationForFallback (key , sslSettings , new SSLConfiguration (sslSettings , globalSSLConfiguration ));
424+ }
408425 storeSslConfiguration (key , globalSSLConfiguration );
409426 } else {
410427 final SSLConfiguration configuration = new SSLConfiguration (sslSettings , globalSSLConfiguration );
428+ if (shouldCheckForFallbackDeprecation (key )) {
429+ checkSSLConfigurationForFallback (key , sslSettings , configuration );
430+ }
411431 storeSslConfiguration (key , configuration );
412432 sslContextHolders .computeIfAbsent (configuration , this ::createSslContext );
413433 }
414434 });
415435
416436 final Settings transportSSLSettings = settings .getByPrefix (XPackSettings .TRANSPORT_SSL_PREFIX );
417437 final SSLConfiguration transportSSLConfiguration = new SSLConfiguration (transportSSLSettings , globalSSLConfiguration );
438+ final boolean transportSSLEnabled = XPackSettings .TRANSPORT_SSL_ENABLED .get (settings );
439+ if (transportSSLEnabled ) {
440+ checkSSLConfigurationForFallback (XPackSettings .TRANSPORT_SSL_PREFIX , transportSSLSettings , transportSSLConfiguration );
441+ }
418442 this .transportSSLConfiguration .set (transportSSLConfiguration );
419443 storeSslConfiguration (XPackSettings .TRANSPORT_SSL_PREFIX , transportSSLConfiguration );
420444 Map <String , Settings > profileSettings = getTransportProfileSSLSettings (settings );
421445 sslContextHolders .computeIfAbsent (transportSSLConfiguration , this ::createSslContext );
422446 profileSettings .forEach ((key , profileSetting ) -> {
423447 final SSLConfiguration configuration = new SSLConfiguration (profileSetting , transportSSLConfiguration );
448+ if (transportSSLEnabled && key .equals ("transport.profiles.default.xpack.security.ssl" ) == false ) {
449+ checkSSLConfigurationForFallback (key , profileSetting , configuration );
450+ }
424451 storeSslConfiguration (key , configuration );
425452 sslContextHolders .computeIfAbsent (configuration , this ::createSslContext );
426453 });
@@ -435,6 +462,57 @@ private void storeSslConfiguration(String key, SSLConfiguration configuration) {
435462 sslConfigurations .put (key , configuration );
436463 }
437464
465+ private boolean shouldCheckForFallbackDeprecation (String name ) {
466+ if (name .startsWith ("xpack.security.authc.realms." )) {
467+ // try to see if this is actually using TLS
468+ Settings realm = settings .getByPrefix (name .substring (0 , name .indexOf (".ssl" )));
469+ String type = realm .get ("type" );
470+ // only check the types we know use ssl. custom realms may but we don't want to cause confusion
471+ if (LdapRealmSettings .LDAP_TYPE .equals (type ) || LdapRealmSettings .AD_TYPE .equals (type )) {
472+ List <String > urls = realm .getAsList ("url" );
473+ return urls .isEmpty () == false && urls .stream ().anyMatch (s -> s .startsWith ("ldaps://" ));
474+ } else if (SamlRealmSettings .TYPE .equals (type )) {
475+ final String idpMetadataPath = SamlRealmSettings .IDP_METADATA_PATH .get (realm );
476+ return Strings .hasText (idpMetadataPath ) && idpMetadataPath .startsWith ("https://" );
477+ }
478+ } else if (name .startsWith ("xpack.monitoring.exporters." )) {
479+ Settings exporterSettings = settings .getByPrefix (name .substring (0 , name .indexOf (".ssl" )));
480+ List <String > hosts = exporterSettings .getAsList ("host" );
481+ return hosts .stream ().anyMatch (s -> s .startsWith ("https" ));
482+ } else if (name .equals (XPackSettings .HTTP_SSL_PREFIX ) && XPackSettings .HTTP_SSL_ENABLED .get (settings )) {
483+ return true ;
484+ } else if (name .equals ("xpack.http.ssl" ) && XPackSettings .WATCHER_ENABLED .get (settings )) {
485+ return true ;
486+ }
487+ return false ;
488+ }
489+
490+ private void checkSSLConfigurationForFallback (String name , Settings settings , SSLConfiguration config ) {
491+ final SSLConfiguration noFallBackConfig = new SSLConfiguration (settings );
492+ if (config .equals (noFallBackConfig ) == false ) {
493+ List <String > fallbackReliers = new ArrayList <>();
494+ if (config .keyConfig ().equals (noFallBackConfig .keyConfig ()) == false ) {
495+ fallbackReliers .add ("key configuration" );
496+ }
497+ if (config .trustConfig ().equals (noFallBackConfig .trustConfig ()) == false ) {
498+ fallbackReliers .add ("trust configuration" );
499+ }
500+ if (config .cipherSuites ().equals (noFallBackConfig .cipherSuites ()) == false ) {
501+ fallbackReliers .add ("enabled cipher suites" );
502+ }
503+ if (config .sslClientAuth () != noFallBackConfig .sslClientAuth ()) {
504+ fallbackReliers .add ("client authentication" );
505+ }
506+ if (config .supportedProtocols ().equals (noFallBackConfig .supportedProtocols ()) == false ) {
507+ fallbackReliers .add ("supported protocols" );
508+ }
509+ if (config .verificationMode () != noFallBackConfig .verificationMode ()) {
510+ fallbackReliers .add ("certificate verification mode" );
511+ }
512+ deprecationLogger .deprecated ("SSL configuration [{}] relies upon fallback to another configuration for {}, which is " +
513+ "deprecated." , name , fallbackReliers );
514+ }
515+ }
438516
439517 /**
440518 * Returns information about each certificate that is referenced by any SSL configuration.
0 commit comments