Skip to content

Commit f016b17

Browse files
albertzaharovitsjkakavaselasticmachinedroberts195dnhatn
authored
Deprecate timeout.tcp_read AD/LDAP realm setting (#47305)
* Done * Update docs/reference/settings/security-settings.asciidoc Co-Authored-By: Ioannis Kakavas <[email protected]> * Update docs/reference/settings/security-settings.asciidoc Co-Authored-By: Ioannis Kakavas <[email protected]> * refactored ldap_search explanation * Tim's review! * [ML] Use CSV ingest processor in find_file_structure ingest pipeline (#51492) Changes the find_file_structure response to include a CSV ingest processor in the ingest pipeline it suggests. Previously the Kibana file upload functionality parsed CSV in the browser, but by parsing CSV in the ingest pipeline it makes the Kibana file upload functionality more easily interchangable with Filebeat such that the configurations it creates can more easily be used to import data with the same structure repeatedly in production. * Add test verify replica allocator with sync_id (#51512) We no longer issue new sync_ids in 8.0, but we still need to make sure that the replica allocator prefers copies with matching sync_id. This commit adds tests for that. Relates #50776 * Formatting: keep simple if / else on the same line (#51526) Previous the formatter was breaking simple if/else statements (i.e. without braces) onto separate lines, which could be fragile because the formatter cannot also introduce braces. Instead, keep such expressions on the same line. * Nits Co-authored-by: Ioannis Kakavas <[email protected]> Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: David Roberts <[email protected]> Co-authored-by: Nhat Nguyen <[email protected]> Co-authored-by: Rory Hunter <[email protected]>
1 parent a687b1f commit f016b17

File tree

6 files changed

+109
-15
lines changed

6 files changed

+109
-15
lines changed

docs/reference/settings/security-settings.asciidoc

+23-8
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,19 @@ An `s` at the end indicates seconds, or `ms` indicates milliseconds.
443443
Defaults to `5s` (5 seconds ).
444444

445445
`timeout.tcp_read`::
446-
The TCP read timeout period after establishing an LDAP connection.
447-
An `s` at the end indicates seconds, or `ms` indicates milliseconds.
448-
Defaults to `5s` (5 seconds ).
446+
deprecated[7.7] The TCP read timeout period after establishing an LDAP
447+
connection. This is equivalent to and is deprecated in favor of
448+
`timeout.response` and they cannot be used simultaneously. An `s` at the end
449+
indicates seconds, or `ms` indicates milliseconds.
450+
451+
`timeout.response`::
452+
The time interval to wait for the response from the LDAP server. An `s` at the
453+
end indicates seconds, or `ms` indicates milliseconds. Defaults to the value of
454+
`timeout.ldap_search`.
449455

450456
`timeout.ldap_search`::
451-
The LDAP Server enforced timeout period for an LDAP search.
457+
The timeout period for an LDAP search. The value is specified in the request
458+
and is enforced by the receiving LDAP Server.
452459
An `s` at the end indicates seconds, or `ms` indicates milliseconds.
453460
Defaults to `5s` (5 seconds ).
454461

@@ -691,12 +698,20 @@ An `s` at the end indicates seconds, or `ms` indicates milliseconds.
691698
Defaults to `5s` (5 seconds ).
692699

693700
`timeout.tcp_read`::
694-
The TCP read timeout period after establishing an LDAP connection.
695-
An `s` at the end indicates seconds, or `ms` indicates milliseconds.
696-
Defaults to `5s` (5 seconds ).
701+
deprecated[7.7] The TCP read timeout period after establishing an LDAP
702+
connection. This is equivalent to and is deprecated in favor of
703+
`timeout.response` and they cannot be used simultaneously. An `s` at the end
704+
indicates seconds, or `ms` indicates milliseconds. Defaults to the value of
705+
`timeout.ldap_search`.
706+
707+
`timeout.response`::
708+
The time interval to wait for the response from the AD server. An `s` at the
709+
end indicates seconds, or `ms` indicates milliseconds. Defaults to the value of
710+
`timeout.ldap_search`.
697711

698712
`timeout.ldap_search`::
699-
The LDAP Server enforced timeout period for an LDAP search.
713+
The timeout period for an LDAP search. The value is specified in the request
714+
and is enforced by the receiving LDAP Server.
700715
An `s` at the end indicates seconds, or `ms` indicates milliseconds.
701716
Defaults to `5s` (5 seconds ).
702717

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/ldap/support/SessionFactorySettings.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ public final class SessionFactorySettings {
2525
public static final Function<String, Setting.AffixSetting<TimeValue>> TIMEOUT_TCP_CONNECTION_SETTING = RealmSettings.affixSetting(
2626
"timeout.tcp_connect", key -> Setting.timeSetting(key, TIMEOUT_DEFAULT, Setting.Property.NodeScope));
2727

28-
public static final Function<String, Setting.AffixSetting<TimeValue>> TIMEOUT_TCP_READ_SETTING = RealmSettings.affixSetting(
29-
"timeout.tcp_read", key -> Setting.timeSetting(key, TIMEOUT_DEFAULT, Setting.Property.NodeScope));
30-
3128
public static final Function<String, Setting.AffixSetting<TimeValue>> TIMEOUT_LDAP_SETTING = RealmSettings.affixSetting(
3229
"timeout.ldap_search", key -> Setting.timeSetting(key, TIMEOUT_DEFAULT, Setting.Property.NodeScope));
3330

31+
public static final Function<String, Setting.AffixSetting<TimeValue>> TIMEOUT_TCP_READ_SETTING = RealmSettings.affixSetting(
32+
"timeout.tcp_read", key -> Setting.timeSetting(key, TimeValue.MINUS_ONE, Setting.Property.NodeScope,
33+
Setting.Property.Deprecated));
34+
35+
public static final Function<String, Setting.AffixSetting<TimeValue>> TIMEOUT_RESPONSE_SETTING = RealmSettings.affixSetting(
36+
"timeout.response", key -> Setting.timeSetting(key, TimeValue.MINUS_ONE, Setting.Property.NodeScope));
37+
3438
public static final Function<String, Setting.AffixSetting<Boolean>> HOSTNAME_VERIFICATION_SETTING = RealmSettings.affixSetting(
3539
"hostname_verification", key -> Setting.boolSetting(key, true, Setting.Property.NodeScope, Setting.Property.Filtered));
3640

@@ -49,6 +53,7 @@ public static Set<Setting.AffixSetting<?>> getSettings(String realmType) {
4953
settings.add(URLS_SETTING.apply(realmType));
5054
settings.add(TIMEOUT_TCP_CONNECTION_SETTING.apply(realmType));
5155
settings.add(TIMEOUT_TCP_READ_SETTING.apply(realmType));
56+
settings.add(TIMEOUT_RESPONSE_SETTING.apply(realmType));
5257
settings.add(TIMEOUT_LDAP_SETTING.apply(realmType));
5358
settings.add(HOSTNAME_VERIFICATION_SETTING.apply(realmType));
5459
settings.add(FOLLOW_REFERRALS_SETTING.apply(realmType));

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactory.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,22 @@ protected static LDAPConnectionOptions connectionOptions(RealmConfig config,
121121
LDAPConnectionOptions options = new LDAPConnectionOptions();
122122
options.setConnectTimeoutMillis(Math.toIntExact(config.getSetting(SessionFactorySettings.TIMEOUT_TCP_CONNECTION_SETTING).millis()));
123123
options.setFollowReferrals(config.getSetting(SessionFactorySettings.FOLLOW_REFERRALS_SETTING));
124-
options.setResponseTimeoutMillis(config.getSetting(SessionFactorySettings.TIMEOUT_TCP_READ_SETTING).millis());
124+
final long responseTimeoutMillis;
125+
if (config.hasSetting(SessionFactorySettings.TIMEOUT_RESPONSE_SETTING)) {
126+
if (config.hasSetting(SessionFactorySettings.TIMEOUT_TCP_READ_SETTING)) {
127+
throw new IllegalArgumentException("[" + RealmSettings.getFullSettingKey(config,
128+
SessionFactorySettings.TIMEOUT_TCP_READ_SETTING) + "] and [" + RealmSettings.getFullSettingKey(config,
129+
SessionFactorySettings.TIMEOUT_RESPONSE_SETTING) + "] may not be used at the same time");
130+
}
131+
responseTimeoutMillis = config.getSetting(SessionFactorySettings.TIMEOUT_RESPONSE_SETTING).millis();
132+
} else {
133+
if (config.hasSetting(SessionFactorySettings.TIMEOUT_TCP_READ_SETTING)) {
134+
responseTimeoutMillis = config.getSetting(SessionFactorySettings.TIMEOUT_TCP_READ_SETTING).millis();
135+
} else {
136+
responseTimeoutMillis = config.getSetting(SessionFactorySettings.TIMEOUT_LDAP_SETTING).millis();
137+
}
138+
}
139+
options.setResponseTimeoutMillis(responseTimeoutMillis);
125140
options.setAllowConcurrentSocketFactoryUse(true);
126141

127142
final boolean verificationModeExists = config.hasSetting(SSLConfigurationSettings.VERIFICATION_MODE_SETTING_REALM);

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmSettingsTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private Settings.Builder commonLdapSettings(String type, boolean configureSSL) {
184184
.put("unmapped_groups_as_roles", randomBoolean())
185185
.put("files.role_mapping", "x-pack/" + randomAlphaOfLength(8) + ".yml")
186186
.put("timeout.tcp_connect", randomPositiveTimeValue())
187-
.put("timeout.tcp_read", randomPositiveTimeValue())
187+
.put("timeout.response", randomPositiveTimeValue())
188188
.put("timeout.ldap_search", randomPositiveTimeValue());
189189
if (configureSSL) {
190190
configureSsl("ssl.", builder, randomBoolean(), randomBoolean());

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapSessionFactoryTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void testBindWithReadTimeout() throws Exception {
8787
Settings settings = Settings.builder()
8888
.put(globalSettings)
8989
.put(buildLdapSettings(ldapUrl, userTemplates, groupSearchBase, LdapSearchScope.SUB_TREE))
90-
.put(RealmSettings.getFullSettingKey(REALM_IDENTIFIER, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "1ms")
90+
.put(RealmSettings.getFullSettingKey(REALM_IDENTIFIER, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "1ms")
9191
.put("path.home", createTempDir())
9292
.build();
9393

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/support/SessionFactoryTests.java

+60-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.action.ActionListener;
1212
import org.elasticsearch.action.support.PlainActionFuture;
1313
import org.elasticsearch.common.settings.SecureString;
14+
import org.elasticsearch.common.settings.Setting;
1415
import org.elasticsearch.common.settings.Settings;
1516
import org.elasticsearch.common.util.concurrent.ThreadContext;
1617
import org.elasticsearch.env.Environment;
@@ -66,13 +67,71 @@ public void testConnectionFactoryReturnsCorrectLDAPConnectionOptionsWithDefaultS
6667
assertThat(options.getSSLSocketVerifier(), is(instanceOf(HostNameSSLSocketVerifier.class)));
6768
}
6869

70+
public void testSessionFactoryWithResponseTimeout() throws Exception {
71+
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("ldap", "response_settings");
72+
final Path pathHome = createTempDir();
73+
{
74+
Settings settings = Settings.builder()
75+
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "10s")
76+
.put(getFullSettingKey(realmId, RealmSettings.ORDER_SETTING), 0)
77+
.put("path.home", pathHome)
78+
.build();
79+
80+
final Environment environment = TestEnvironment.newEnvironment(settings);
81+
RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings));
82+
LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(settings, environment), logger);
83+
assertThat(options.getResponseTimeoutMillis(), is(equalTo(10000L)));
84+
}
85+
{
86+
Settings settings = Settings.builder()
87+
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "7s")
88+
.put(getFullSettingKey(realmId, RealmSettings.ORDER_SETTING), 0)
89+
.put("path.home", pathHome)
90+
.build();
91+
92+
final Environment environment = TestEnvironment.newEnvironment(settings);
93+
RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings));
94+
LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(settings, environment), logger);
95+
assertThat(options.getResponseTimeoutMillis(), is(equalTo(7000L)));
96+
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SessionFactorySettings.TIMEOUT_TCP_READ_SETTING.apply("ldap")
97+
.getConcreteSettingForNamespace("response_settings")});
98+
}
99+
{
100+
Settings settings = Settings.builder()
101+
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "11s")
102+
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "6s")
103+
.put(getFullSettingKey(realmId, RealmSettings.ORDER_SETTING), 0)
104+
.put("path.home", pathHome)
105+
.build();
106+
107+
final Environment environment = TestEnvironment.newEnvironment(settings);
108+
RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings));
109+
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> SessionFactory.connectionOptions(realmConfig
110+
, new SSLService(settings, environment), logger));
111+
assertThat(ex.getMessage(), is("[xpack.security.authc.realms.ldap.response_settings.timeout.tcp_read] and [xpack.security" +
112+
".authc.realms.ldap.response_settings.timeout.response] may not be used at the same time"));
113+
}
114+
{
115+
Settings settings = Settings.builder()
116+
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_LDAP_SETTING), "750ms")
117+
.put(getFullSettingKey(realmId, RealmSettings.ORDER_SETTING), 0)
118+
.put("path.home", pathHome)
119+
.build();
120+
121+
final Environment environment = TestEnvironment.newEnvironment(settings);
122+
RealmConfig realmConfig = new RealmConfig(realmId, settings, environment, new ThreadContext(settings));
123+
LDAPConnectionOptions options = SessionFactory.connectionOptions(realmConfig, new SSLService(settings, environment), logger);
124+
assertThat(options.getResponseTimeoutMillis(), is(equalTo(750L)));
125+
}
126+
}
127+
69128
public void testConnectionFactoryReturnsCorrectLDAPConnectionOptions() throws Exception {
70129
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("ldap", "conn_settings");
71130
final Path pathHome = createTempDir();
72131
Settings settings = Settings.builder()
73132
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_CONNECTION_SETTING), "10ms")
74133
.put(getFullSettingKey(realmId, SessionFactorySettings.HOSTNAME_VERIFICATION_SETTING), "false")
75-
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_TCP_READ_SETTING), "20ms")
134+
.put(getFullSettingKey(realmId, SessionFactorySettings.TIMEOUT_RESPONSE_SETTING), "20ms")
76135
.put(getFullSettingKey(realmId, SessionFactorySettings.FOLLOW_REFERRALS_SETTING), "false")
77136
.put(getFullSettingKey(realmId, RealmSettings.ORDER_SETTING), 0)
78137
.put("path.home", pathHome)

0 commit comments

Comments
 (0)