elastic / elastic/support-diagnostics

Fix IPv6 address parsing in KibanaGetDetails

Open Beginner friendly
#1,036 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
304
Forks
175
PR merge metrics
No merged PRs in 30d

Description

**Issue:**
When we have kibana running with IPv6 address:

```
sudo ss -ltnp | grep 5601
LISTEN 0 511 *:5601 *:* users:(("node",pid=32026,fd=19))
```

```
sudo grep "server.host" /etc/kibana/kibana.yml
server.host: "::"
```

and we try to collect the kibana diagnostics with `--type local` it fails with:

```
11:18:24.034 [main] ERROR co.elastic.support.diagnostics.commands.CheckPlatformDetails - Error extracting Kibana network addresses from stats output
java.lang.NumberFormatException: For input string: "::5601"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67) ~[?:?]
at java.base/java.lang.Integer.parseInt(Integer.java:662) ~[?:?]
at java.base/java.lang.Integer.parseInt(Integer.java:778) ~[?:?]
at co.elastic.support.diagnostics.commands.KibanaGetDetails.getNodeNetworkAndLogInfo(KibanaGetDetails.java:174) [diagnostics-9.3.1.jar:9.3.1]
at co.elastic.support.diagnostics.commands.KibanaGetDetails.execute(KibanaGetDetails.java:52) [diagnostics-9.3.1.jar:9.3.1]
at co.elastic.support.diagnostics.chain.DiagnosticChainExec.runDiagnostic(DiagnosticChainExec.java:102) [diagnostics-9.3.1.jar:9.3.1]
at co.elastic.support.diagnostics.DiagnosticService.exec(DiagnosticService.java:92) [diagnostics-9.3.1.jar:9.3.1]
at co.elastic.support.diagnostics.DiagnosticApp.main(DiagnosticApp.java:51) [diagnostics-9.3.1.jar:9.3.1]
```

In the [KibanaGetDetails.java](https://github.com/elastic/support-diagnostics/blob/main/src/main/java/co/elastic/support/diagnostics/commands/KibanaGetDetails.java), the original code used `indexOf(":")` to find the port separator in the transport address:

**Problem:**

```
String httpPublishAddr = processInfo.path("kibana").path("transport_address").asText();
diagNode.httpPublishAddr = httpPublishAddr.substring(0, httpPublishAddr.indexOf(":"));
diagNode.httpPort = Integer.parseInt(httpPublishAddr.substring(httpPublishAddr.indexOf(":") + 1));
```
and the problem is, IPv6 addresses contain multiple colons (e.g., [::]:5601). Using `indexOf(":")` finds the first colon inside the IPv6 address itself, not the port separator. This causes the parsing to fail.

**Proposed Solution:**

Replace `indexOf(':')` with `lastIndexOf(':')` to correctly parse IPv6 addresses. Handles both IPv4 (host:port) and IPv6 ([::]:port) formats. Fixes NumberFormatException when Kibana is configured with server.host: '::'

```
String httpPublishAddr = processInfo.path("kibana").path("transport_address").asText();
int lastColonIndex = httpPublishAddr.lastIndexOf(":");
diagNode.httpPublishAddr = httpPublishAddr.substring(0, lastColonIndex);
diagNode.httpPort = Integer.parseInt(httpPublishAddr.substring(lastColonIndex + 1));
```

This works for both:
e.g:
IPv4: 192.168.1.1:5601 - Last : is the port separator
IPv6: [::]:5601 - Last : is the port separator

Contributor guide

Open the contributing guide

Research direction

Open src/main/java/co/elastic/support/diagnostics/commands/KibanaGetDetails.java and inspect getNodeNetworkAndLogInfo, where the transport address is split into host and port. Reproduce collection with --type local using an IPv6 Kibana address, then verify that both IPv4 and IPv6 transport addresses parse without NumberFormatException and retain the correct port.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.