diff --git a/CHANGELOG.md b/CHANGELOG.md index 4611fd5db5..7ec92a8087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ #### Bugs * Fix #6747: Preventing websocket error logs when the client is closed +* Fix #6781: Allowing ipv6 entries to work in NO_PROXY #### Improvements diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java index 0d27ffdc8a..8237153a25 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java @@ -73,8 +73,8 @@ public void before(BasicBuilder builder, HttpRequest request, RequestTags tags) private static final String HEADER_INTERCEPTOR = "HEADER"; private static final String KUBERNETES_BACKWARDS_COMPATIBILITY_INTERCEPTOR_DISABLE = "kubernetes.backwardsCompatibilityInterceptor.disable"; private static final String BACKWARDS_COMPATIBILITY_DISABLE_DEFAULT = "true"; - private static final Pattern IPV4_PATTERN = Pattern.compile( - "(http://|https://)?(?(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])(\\/([1-2]\\d|3[0-2]|\\d))?)(\\D+|$)"); + private static final Pattern IP_PATTERN = Pattern.compile( + "(http(s?)://)?(?((\\d{1,3}(.\\d{1,3}){3})|([a-f\\d]{1,4}(\\:[a-f\\d]{0,4}){2,7}))(/\\d+)?)", Pattern.CASE_INSENSITIVE); private static final Pattern INVALID_HOST_PATTERN = Pattern.compile("[^\\da-zA-Z.\\-/:]+"); private HttpClientUtils() { @@ -296,8 +296,8 @@ static boolean isHostMatchedByNoProxy(String host, String[] noProxies) throws Ma } private static Optional extractIpAddressOrSubnet(String ipAddressOrSubnet) { - final Matcher ipMatcher = IPV4_PATTERN.matcher(ipAddressOrSubnet); - if (ipMatcher.find()) { + final Matcher ipMatcher = IP_PATTERN.matcher(ipAddressOrSubnet); + if (ipMatcher.matches()) { return Optional.of(ipMatcher.group("ipAddressOrSubnet")); } return Optional.empty(); diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java index 208c8c3926..a2b5120f43 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java @@ -189,6 +189,7 @@ Stream masterHostnameDoesMatchNoProxyInput() { arguments("192.168.1.110", new String[] { "192.168.1.0/24" }), arguments("192.168.1.110", new String[] { "http://192.168.1.0/24" }), arguments("192.168.1.110", new String[] { "192.0.0.0/8" }), + arguments("2620:52:0:9c:0:0:0:1", new String[] { "2620:52:0:9c::/64" }), arguments("192.168.1.110", new String[] { "http://192.0.0.0/8" })); } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/IpAddressMatcherTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/IpAddressMatcherTest.java index fa3e08c36c..59708d2dc2 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/IpAddressMatcherTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/IpAddressMatcherTest.java @@ -40,6 +40,8 @@ static Stream matchesTrueInput() { arguments("192.168.10.110", "192.168.10.110"), arguments("192.168.1.0/8", "192.168.10.110"), arguments("192.168.1.0/24", "192.168.1.100"), + arguments("10.96.0.1", "0:0:0:0:0:ffff:0a60:0001"), + arguments("2620:52:0:9c::/64", "2620:52:0:9c:0:0:0:1"), arguments("0.0.0.0/0", "123.4.5.6"), arguments("0.0.0.0/0", "192.168.0.159"), arguments("192.168.0.159/0", "123.4.5.6"), @@ -59,7 +61,6 @@ static Stream matchesFalseInput() { arguments("192.168.1.0/24", "193.168.1.10"), arguments("192.168.1.0/24", "192.168.2.10"), arguments("192.168.1.0/8", "193.168.1.10"), - arguments("192.168.1.128/25", "192.168.1.104"), - arguments("kubernetes.default.svc", "kubernetes.default.svc")); + arguments("192.168.1.128/25", "192.168.1.104")); } }