bug: ensure only secondary addresses are used when assigning aliases#65
Merged
Conversation
keithaws
reviewed
Aug 2, 2022
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
keithaws
approved these changes
Aug 2, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: #63
Description of changes:
The
local-ipv4sIMDS 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 usingtail -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 withsort. Prior to this change, we were performing thesortoperation before thetail -n +2operation, 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
sortoperation after thetail -n +2operation. 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.