Skip to content

Commit 0a93df1

Browse files
authored
Bind host all instead of just _site_ when needed (#83145)
For security on by default we changed the interface where elasticsearch binds by default to be: - _site_ for the HTTP layer so that we have better chances that kibana can communicate to elasticsearch by default as they might not be running on the same host - _site_ for the transport layer when we could determine that there are other existing nodes of this cluster on different nodes. This commit changes the behavior so that we bind to 0.0.0.0 in these cases for the following reasons: - We don't expect hosts nowdays to have publicly routable IP addresses attached to any of their interfaces, and expect that the have a site local address behind some proxy/router. In that respect, binding to 0.0.0.0 doesn't expose elasticsearch to a greater network segment than binding to the site local address would - It is significantly easier to document, explain and argue about with users in the comments and our documentation.
1 parent 280fd2f commit 0a93df1

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

docs/changelog/83145.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 83145
2+
summary: Bind host all instead of just _site_ when needed
3+
area: Security
4+
type: enhancement
5+
issues: []

qa/os/src/test/java/org/elasticsearch/packaging/test/PackagingTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ public void verifySecurityAutoConfigured(Installation es) throws Exception {
671671
assertThat(settings.get("xpack.security.enabled"), equalTo("true"));
672672

673673
if (es.distribution.isDocker() == false) {
674-
assertThat(settings.get("http.host"), equalTo("[_local_, _site_]"));
674+
assertThat(settings.get("http.host"), equalTo("0.0.0.0"));
675675
}
676676
}
677677

x-pack/docs/en/security/enroll-nodes.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[role="exclude"]
22

33
When {es} starts for the first time, the security auto-configuration process
4-
binds the HTTP layer to both `_site_` and `_local_`, but only binds the
5-
transport layer to `_local_`. This intended behavior ensures that you can start
4+
binds the HTTP layer to `0.0.0.0`, but only binds the transport layer to
5+
localhost. This intended behavior ensures that you can start
66
a single-node cluster with security enabled by default without any additional
77
configuration.
88

@@ -14,10 +14,10 @@ could expire, which is why enrollment tokens aren't generated automatically.
1414
Additionally, only nodes on the same host can join the cluster without
1515
additional configuration. If you want nodes from another host to join your
1616
cluster, you need to set `transport.host` to a
17-
{ref}/modules-network.html#network-interface-values[supported value] other than
18-
`_local_` (such as `_site_`), or an IP address that's bound to an interface
19-
where other hosts can reach it. Refer to
20-
{ref}/modules-network.html#transport-settings[transport settings] for more
17+
{ref}/modules-network.html#network-interface-values[supported value]
18+
(such as uncommenting the suggested value of `0.0.0.0`), or an IP address
19+
that's bound to an interface where other hosts can reach it. Refer to
20+
{ref}/modules-network.html#transport-settings[transport settings] for more
2121
information.
2222

2323
To enroll new nodes in your cluster, create an enrollment token with the

x-pack/plugin/security/cli/src/main/java/org/elasticsearch/xpack/security/cli/AutoConfigureNode.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -782,13 +782,11 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
782782
|| localFinalEnv.settings().hasValue(NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.getKey())
783783
|| localFinalEnv.settings().hasValue(NetworkService.GLOBAL_NETWORK_PUBLISH_HOST_SETTING.getKey()))) {
784784
bw.newLine();
785-
bw.write("# Allow HTTP API connections from localhost and local networks");
785+
bw.write("# Allow HTTP API connections from anywhere");
786786
bw.newLine();
787787
bw.write("# Connections are encrypted and require user authentication");
788788
bw.newLine();
789-
bw.write(
790-
HttpTransportSettings.SETTING_HTTP_HOST.getKey() + ": " + hostSettingValue(NetworkUtils.getAllAddresses())
791-
);
789+
bw.write(HttpTransportSettings.SETTING_HTTP_HOST.getKey() + ": 0.0.0.0");
792790
bw.newLine();
793791
}
794792
if (false == (localFinalEnv.settings().hasValue(TransportSettings.HOST.getKey())
@@ -798,15 +796,15 @@ protected void execute(Terminal terminal, OptionSet options, Environment env) th
798796
|| localFinalEnv.settings().hasValue(NetworkService.GLOBAL_NETWORK_BIND_HOST_SETTING.getKey())
799797
|| localFinalEnv.settings().hasValue(NetworkService.GLOBAL_NETWORK_PUBLISH_HOST_SETTING.getKey()))) {
800798
bw.newLine();
801-
bw.write("# Allow other nodes to join the cluster from localhost and local networks");
799+
bw.write("# Allow other nodes to join the cluster from anywhere");
802800
bw.newLine();
803801
bw.write("# Connections are encrypted and mutually authenticated");
804802
bw.newLine();
805803
if (false == inEnrollmentMode
806804
|| false == anyRemoteHostNodeAddress(transportAddresses, NetworkUtils.getAllAddresses())) {
807805
bw.write("#");
808806
}
809-
bw.write(TransportSettings.HOST.getKey() + ": " + hostSettingValue(NetworkUtils.getAllAddresses()));
807+
bw.write(TransportSettings.HOST.getKey() + ": 0.0.0.0");
810808
bw.newLine();
811809
}
812810
bw.newLine();
@@ -880,14 +878,6 @@ protected static boolean anyRemoteHostNodeAddress(List<String> allNodesTransport
880878
return false;
881879
}
882880

883-
protected String hostSettingValue(InetAddress[] allAddresses) {
884-
if (Arrays.stream(allAddresses).anyMatch(InetAddress::isSiteLocalAddress)) {
885-
return "[_local_, _site_]";
886-
} else {
887-
return "[_local_]";
888-
}
889-
}
890-
891881
private Environment possiblyReconfigureNode(Environment env, Terminal terminal) throws UserException {
892882
// We remove the existing auto-configuration stanza from elasticsearch.yml, the elastisearch.keystore and
893883
// the directory with the auto-configured TLS key material, and then proceed as if elasticsearch is started

0 commit comments

Comments
 (0)