[
https://issues.apache.org/jira/browse/HADOOP-19961?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18126654#comment-18126654
]
ASF GitHub Bot commented on HADOOP-19961:
-----------------------------------------
smengcl commented on code in PR #8819:
URL: https://github.com/apache/hadoop/pull/8819#discussion_r4256748116
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/key/kms/KMSClientProvider.java:
##########
@@ -302,22 +312,51 @@ public KeyProvider createProvider(URI providerUri,
Configuration conf)
hostsPart = t[0];
}
KMSClientProvider[] providers =
- createProviders(conf, origUrl, port, hostsPart);
+ createProviders(conf, origUrl.getProtocol(), origUrl.getPath(),
port, hostsPart);
return new LoadBalancingKMSClientProvider(providerUri, providers,
conf);
}
return null;
}
- private KMSClientProvider[] createProviders(Configuration conf,
- URL origUrl, int port, String hostsPart) throws IOException {
+ /**
+ * Handles an authority that has a bracketed IPv6 literal, which the colon
split above cannot
+ * parse and, for more than one host, neither {@link Path} nor {@link URL}
can hold.
+ */
+ private KMSClientProvider[] createBracketedProviders(Configuration conf,
URI providerUri,
+ String kmsAuthority) throws IOException {
+ String[] parts = kmsAuthority.split("@", 2);
+ if (parts.length != 2) {
+ throw new IOException("No valid authority in kms uri [" + providerUri
+ "]");
+ }
+ int port = -1;
+ String hostsPart = parts[1];
+ // A colon after the last closing bracket delimits the port, others
belong to a literal
+ int portIdx = hostsPart.lastIndexOf(':');
+ if (portIdx > hostsPart.lastIndexOf(']')) {
+ try {
+ port = Integer.parseInt(hostsPart.substring(portIdx + 1));
+ } catch (NumberFormatException e) {
+ throw new IOException("Could not parse port in kms uri [" +
providerUri + "]");
+ }
+ hostsPart = hostsPart.substring(0, portIdx);
+ }
+ return createProviders(conf, parts[0], providerUri.getPath(), port,
hostsPart);
+ }
+
+ private KMSClientProvider[] createProviders(Configuration conf, String
protocol, String path,
+ int port, String hostsPart) throws IOException {
String[] hosts = hostsPart.split(";");
KMSClientProvider[] providers = new KMSClientProvider[hosts.length];
for (int i = 0; i < hosts.length; i++) {
+ // URI would add the brackets itself, which leaves the end of the
address ambiguous
+ if (hosts[i].contains(":") && !hosts[i].startsWith("[")) {
+ throw new IOException("Could not parse host [" + hosts[i]
+ + "] in kms uri. An IPv6 literal must be enclosed in brackets.");
+ }
try {
providers[i] =
new KMSClientProvider(
- new URI("kms", origUrl.getProtocol(), hosts[i], port,
- origUrl.getPath(), null, null), conf);
+ new URI("kms", protocol, hosts[i], port, path, null, null),
conf);
} catch (URISyntaxException e) {
Review Comment:
Tightened in 1bd2a8395dd: a host with a colon must now start with `[` and
end with `]`, so a port attached to a single host is rejected with a targeted
`IOException`, and a test case covers it. The brackets are still passed to
`URI` as is, since the constructor would add them back.
_🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
> Support IPv6 authorities in KMS client provider URIs
> ----------------------------------------------------
>
> Key: HADOOP-19961
> URL: https://issues.apache.org/jira/browse/HADOOP-19961
> Project: Hadoop Common
> Issue Type: Sub-task
> Reporter: Siyao Meng
> Assignee: Siyao Meng
> Priority: Major
> Labels: pull-request-available
>
> KMSClientProvider splits authorities on a colon. This parsing fails for IPv6
> literals. Support bracketed single-host authorities and percent-encoded
> multi-host failover authorities. Use one shared port. Reject ambiguous
> unbracketed IPv6 literals. Preserve DNS and IPv4 behavior.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]