[
https://issues.apache.org/jira/browse/HADOOP-20083?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144232#comment-18144232
]
ASF GitHub Bot commented on HADOOP-20083:
-----------------------------------------
smengcl opened a new pull request, #8983:
URL: https://github.com/apache/hadoop/pull/8983
Generated-by: Claude Code (Opus 5.5)
JIRA: https://issues.apache.org/jira/browse/HADOOP-20083
### Description of PR
`MachineList` resolved each hostname entry with `getByName` and kept only
that one address. A host with several addresses (a dual-stack host, or a host
with more than one IPv4 address) matched only from that address. For example,
`localhost` matched `127.0.0.1` but not `::1` by default, and the reverse with
`java.net.preferIPv6Addresses=true`. This affects proxy user hosts, service
level authorization host lists and `FileBasedIPList`.
This patch resolves hostname entries with `getAllByName` and keeps every
address. IP literal and CIDR entries behave as before (`getAllByName` of a
literal returns that one address).
`InetAddressFactory` gets a public `getAllByName`. The base class returns
`InetAddress.getAllByName`. A subclass that overrides only `getByName` keeps
resolving through it (one address per entry, as before), so existing subclasses
and test factories keep working; they can override `getAllByName` to return
more.
### How was this patch tested?
New test `TestMachineList#testHostNameWithSeveralAddresses`: a hostname with
two IPv4 addresses and one IPv6 address matches from each of them, and
unrelated IPv4 and IPv6 addresses are rejected. It fails without the fix.
`TestMachineList`, `TestProxyUsers`, `TestServiceAuthorization`,
`TestFileBasedIPList`, `TestCacheableIPList`,
`TestDefaultImpersonationProvider`, `TestProxyServers`,
`TestWhitelistBasedResolver` and `TestDoAsEffectiveUser` pass locally on JDK 17.
### For code changes:
- [x] Does the title of this PR start with the corresponding JIRA issue id
(e.g. 'HADOOP-17799. Your PR title ...')?
### AI Tooling
- [x] The PR includes the phrase "Contains content generated by Claude Code".
- [x] My use of AI contributions follows the ASF legal policy
https://www.apache.org/legal/generative-tooling.html
Contains content generated by Claude Code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
> MachineList matches a hostname entry against only one of its addresses
> ----------------------------------------------------------------------
>
> Key: HADOOP-20083
> URL: https://issues.apache.org/jira/browse/HADOOP-20083
> Project: Hadoop Common
> Issue Type: Sub-task
> Reporter: Siyao Meng
> Assignee: Siyao Meng
> Priority: Major
>
> {{MachineList}} resolves each hostname entry once, in the constructor, with
> {{InetAddress.getByName}}, and keeps only that one address
> ([MachineList.java:169|https://github.com/apache/hadoop/blob/904cde0c848781e67dde0b0aece8acad2e320204/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/MachineList.java#L169]).
> {{includes}} then looks the caller's address up in that set
> ([MachineList.java:224|https://github.com/apache/hadoop/blob/904cde0c848781e67dde0b0aece8acad2e320204/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/MachineList.java#L224]).
> {{getByName}} returns the first address of the host. With the JDK default
> ({{java.net.preferIPv6Addresses=false}}) that is the IPv4 address of a
> dual-stack host, so the host is not matched when it connects over IPv6. With
> {{preferIPv6Addresses=true}} it is the reverse. A hostname with several IPv4
> addresses has the same problem today.
> This affects every user of {{MachineList}}: {{hadoop.proxyuser.<user>.hosts}}
> ({{DefaultImpersonationProvider}}), the service level authorization host
> lists ({{ServiceAuthorizationManager}}) and {{FileBasedIPList}}. For example,
> on a dual-stack cluster a proxy user whose host is listed by name is rejected
> when it reaches the NameNode over IPv6.
> Reproduced on trunk ({{904cde0c848}}) with {{localhost}}, which resolves to
> both 127.0.0.1 and ::1:
> {noformat}
> InetAddress.getAllByName("localhost") = [localhost/127.0.0.1,
> localhost/0:0:0:0:0:0:0:1]
> new MachineList(["localhost"]).includes(127.0.0.1) = true
> new MachineList(["localhost"]).includes(::1) = false
> {noformat}
> With {{-Djava.net.preferIPv6Addresses=true}} the two results swap.
> *Proposed fix:*
> * Resolve hostname entries with {{getAllByName}} and keep every address.
> * Add {{getAllByName}} to {{InetAddressFactory}} so tests can simulate a host
> with several addresses.
> * Add tests for a dual-stack hostname matched from both address families.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]