Skip to content

bug: ensure only secondary addresses are used when assigning aliases#65

Merged
nmeyerhans merged 1 commit into
amazonlinux:mainfrom
nmeyerhans:github-63
Aug 2, 2022
Merged

bug: ensure only secondary addresses are used when assigning aliases#65
nmeyerhans merged 1 commit into
amazonlinux:mainfrom
nmeyerhans:github-63

Conversation

@nmeyerhans
Copy link
Copy Markdown
Contributor

@nmeyerhans nmeyerhans commented Aug 1, 2022

Issue #, if available: #63

Description of changes:

The local-ipv4s IMDS field lists the primary RFC 1918 address on the first line, with secondary IPv4 addresses on subsequent lines. When assigning alises, we want to only consider secondary IPv4 addresses, so we exclude the primary using tail -n +2. In order to ensure consistent ordering across invocations, even if IMDS returns secondary addresses in unspecified order, the list of secondaries is processed with sort. Prior to this change, we were performing the sort operation before the tail -n +2 operation, meaning that a secondary address that sorted before the primary would be mistakenly interpreted as a primary address, and a secondary address could be mistaken for the primary address.

To fix this, we move the sort operation after the tail -n +2 operation. Technically this could still be broken if IMDS ever stops returning the primary address on the first line of the output, but for now there is no better way to identify the primary address.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@nmeyerhans nmeyerhans requested a review from keithaws August 1, 2022 21:22
@nmeyerhans nmeyerhans linked an issue Aug 1, 2022 that may be closed by this pull request
Comment thread lib/lib.sh Outdated
The `local-ipv4s` IMDS field lists the primary RFC 1918 address on the
first line, with secondary IPv4 addresses on subsequent lines.  When
assigning alises, we want to only consider secondary IPv4 addresses,
so we exclude the primary using `tail -n +2`.  In order to ensure
consistent ordering across invocations, even if IMDS returns secondary
addresses in unspecified order, the list of secondaries is processed
with `sort`.  Prior to this change, we were performing the `sort`
operation before the `tail -n +2` operation, meaning that a secondary
address that sorted before the primary would be mistakenly interpreted
as a primary address, and a secondary address could be mistaken for
the primary address.

See amazonlinux#63
@nmeyerhans nmeyerhans merged commit 507a118 into amazonlinux:main Aug 2, 2022
@nmeyerhans nmeyerhans deleted the github-63 branch August 2, 2022 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secondary IPs missed in aliases depending on sort

2 participants