@@ -963,6 +963,136 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() {
963
963
assertThat (issues , empty ());
964
964
}
965
965
966
+ public void testCheckSslServerEnabled () {
967
+ String httpSslEnabledKey = "xpack.security.http.ssl.enabled" ;
968
+ String transportSslEnabledKey = "xpack.security.transport.ssl.enabled" ;
969
+ String problemSettingKey1 = "xpack.security.http.ssl.keystore.path" ;
970
+ String problemSettingValue1 = "some/fake/path" ;
971
+ String problemSettingKey2 = "xpack.security.http.ssl.truststore.path" ;
972
+ String problemSettingValue2 = "some/other/fake/path" ;
973
+ final Settings nodeSettings = Settings .builder ()
974
+ .put (transportSslEnabledKey , "true" )
975
+ .put (problemSettingKey1 , problemSettingValue1 )
976
+ .put (problemSettingKey2 , problemSettingValue2 )
977
+ .build ();
978
+ final XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY , () -> 0 );
979
+ final ClusterState clusterState = ClusterState .EMPTY_STATE ;
980
+ final DeprecationIssue expectedIssue = new DeprecationIssue (DeprecationIssue .Level .CRITICAL ,
981
+ "cannot set ssl properties without explicitly enabling or disabling ssl" ,
982
+ "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_security_changes" ,
983
+ String .format (Locale .ROOT ,
984
+ "setting [%s] is unset but the following settings exist: [%s,%s]" ,
985
+ httpSslEnabledKey ,
986
+ problemSettingKey1 ,
987
+ problemSettingKey2 ),
988
+ false ,null
989
+ );
990
+
991
+ assertThat (
992
+ NodeDeprecationChecks .checkSslServerEnabled (nodeSettings , null , clusterState , licenseState ),
993
+ equalTo (expectedIssue )
994
+ );
995
+ }
996
+
997
+ public void testCheckSslCertConfiguration () {
998
+ // SSL enabled, but no keystore/key/cert properties
999
+ Settings nodeSettings = Settings .builder ()
1000
+ .put ("xpack.security.transport.ssl.enabled" , "true" )
1001
+ .build ();
1002
+ final XPackLicenseState licenseState = new XPackLicenseState (Settings .EMPTY , () -> 0 );
1003
+ final ClusterState clusterState = ClusterState .EMPTY_STATE ;
1004
+ DeprecationIssue expectedIssue = new DeprecationIssue (DeprecationIssue .Level .CRITICAL ,
1005
+ "if ssl is enabled either keystore must be set, or key path and certificate path must be set" ,
1006
+ "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_security_changes" ,
1007
+ "none of [xpack.security.transport.ssl.keystore.path], [xpack.security.transport.ssl.key], or [xpack.security.transport" +
1008
+ ".ssl.certificate] are set. If [xpack.security.transport.ssl.enabled] is true either [xpack.security.transport.ssl" +
1009
+ ".keystore.path] must be set, or [xpack.security.transport.ssl.key] and [xpack.security.transport.ssl.certificate] " +
1010
+ "must be set" ,
1011
+ false ,null
1012
+ );
1013
+ assertThat (
1014
+ NodeDeprecationChecks .checkSslCertConfiguration (nodeSettings , null , clusterState , licenseState ),
1015
+ equalTo (expectedIssue )
1016
+ );
1017
+
1018
+ // SSL enabled, and keystore path give, expect no issue
1019
+ nodeSettings = Settings .builder ()
1020
+ .put ("xpack.security.transport.ssl.enabled" , "true" )
1021
+ .put ("xpack.security.transport.ssl.keystore.path" , randomAlphaOfLength (10 ))
1022
+ .build ();
1023
+ assertThat (
1024
+ NodeDeprecationChecks .checkSslCertConfiguration (nodeSettings , null , clusterState , licenseState ),
1025
+ equalTo (null )
1026
+ );
1027
+
1028
+ // SSL enabled, and key and certificate path give, expect no issue
1029
+ nodeSettings = Settings .builder ()
1030
+ .put ("xpack.security.transport.ssl.enabled" , "true" )
1031
+ .put ("xpack.security.transport.ssl.key" , randomAlphaOfLength (10 ))
1032
+ .put ("xpack.security.transport.ssl.certificate" , randomAlphaOfLength (10 ))
1033
+ .build ();
1034
+ assertThat (
1035
+ NodeDeprecationChecks .checkSslCertConfiguration (nodeSettings , null , clusterState , licenseState ),
1036
+ equalTo (null )
1037
+ );
1038
+
1039
+ // SSL enabled, specify both keystore and key and certificate path
1040
+ nodeSettings = Settings .builder ()
1041
+ .put ("xpack.security.transport.ssl.enabled" , "true" )
1042
+ .put ("xpack.security.transport.ssl.keystore.path" , randomAlphaOfLength (10 ))
1043
+ .put ("xpack.security.transport.ssl.key" , randomAlphaOfLength (10 ))
1044
+ .put ("xpack.security.transport.ssl.certificate" , randomAlphaOfLength (10 ))
1045
+ .build ();
1046
+ expectedIssue = new DeprecationIssue (DeprecationIssue .Level .CRITICAL ,
1047
+ "if ssl is enabled either keystore must be set, or key path and certificate path must be set" ,
1048
+ "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_security_changes" ,
1049
+ "all of [xpack.security.transport.ssl.keystore.path], [xpack.security.transport.ssl.key], and [xpack.security.transport.ssl" +
1050
+ ".certificate] are set. Either [xpack.security.transport.ssl.keystore.path] must be set, or [xpack.security.transport.ssl" +
1051
+ ".key] and [xpack.security.transport.ssl.certificate] must be set" ,
1052
+ false ,null
1053
+ );
1054
+ assertThat (
1055
+ NodeDeprecationChecks .checkSslCertConfiguration (nodeSettings , null , clusterState , licenseState ),
1056
+ equalTo (expectedIssue )
1057
+ );
1058
+
1059
+ // SSL enabled, specify keystore and key
1060
+ nodeSettings = Settings .builder ()
1061
+ .put ("xpack.security.transport.ssl.enabled" , "true" )
1062
+ .put ("xpack.security.transport.ssl.keystore.path" , randomAlphaOfLength (10 ))
1063
+ .put ("xpack.security.transport.ssl.key" , randomAlphaOfLength (10 ))
1064
+ .build ();
1065
+ expectedIssue = new DeprecationIssue (DeprecationIssue .Level .CRITICAL ,
1066
+ "if ssl is enabled either keystore must be set, or key path and certificate path must be set" ,
1067
+ "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_security_changes" ,
1068
+ "[xpack.security.transport.ssl.keystore.path] and [xpack.security.transport.ssl.key] are set. Either [xpack.security" +
1069
+ ".transport.ssl.keystore.path] must be set, or [xpack.security.transport.ssl.key] and [xpack.security.transport.ssl" +
1070
+ ".certificate] must be set" ,
1071
+ false ,null
1072
+ );
1073
+ assertThat (
1074
+ NodeDeprecationChecks .checkSslCertConfiguration (nodeSettings , null , clusterState , licenseState ),
1075
+ equalTo (expectedIssue )
1076
+ );
1077
+
1078
+ // Sanity check that it also works for http:
1079
+ nodeSettings = Settings .builder ()
1080
+ .put ("xpack.security.http.ssl.enabled" , "true" )
1081
+ .build ();
1082
+ expectedIssue = new DeprecationIssue (DeprecationIssue .Level .CRITICAL ,
1083
+ "if ssl is enabled either keystore must be set, or key path and certificate path must be set" ,
1084
+ "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_security_changes" ,
1085
+ "none of [xpack.security.http.ssl.keystore.path], [xpack.security.http.ssl.key], or [xpack.security.http.ssl.certificate] are" +
1086
+ " set. If [xpack.security.http.ssl.enabled] is true either [xpack.security.http.ssl.keystore.path] must be set, or [xpack" +
1087
+ ".security.http.ssl.key] and [xpack.security.http.ssl.certificate] must be set" ,
1088
+ false ,null
1089
+ );
1090
+ assertThat (
1091
+ NodeDeprecationChecks .checkSslCertConfiguration (nodeSettings , null , clusterState , licenseState ),
1092
+ equalTo (expectedIssue )
1093
+ );
1094
+ }
1095
+
966
1096
@ SuppressForbidden (reason = "sets and unsets es.unsafely_permit_handshake_from_incompatible_builds" )
967
1097
public void testCheckNoPermitHandshakeFromIncompatibleBuilds () {
968
1098
final DeprecationIssue expectedNullIssue =
0 commit comments