Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mis-detecting network configuration in initramfs cmdline #844

Merged
merged 4 commits into from
Mar 29, 2021

Conversation

TheRealFalcon
Copy link
Member

Integration test still needs to be written

Proposed Commit Message

Fix mis-detecting network configuration in initramfs cmdline

klibc initramfs in debian allows the 'iscsi_target_ip=' cmdline
parameter to specify an iscsi device attachment. This can
cause cloud-init to mis-detect the cmdline paramter as a
networking config.

LP: #1919188

Additional Context

https://bugs.launchpad.net/cloud-init/+bug/1919188

Test Steps

Integration test still needs to be written

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

@TheRealFalcon TheRealFalcon force-pushed the fix-cmdline branch 3 times, most recently from aba220c to b31d7a4 Compare March 15, 2021 19:34
@@ -72,7 +73,7 @@ def is_applicable(self) -> bool:
(ii) an open-iscsi interface file is present in the system
"""
if self._files:
if 'ip=' in self._cmdline or 'ip6=' in self._cmdline:
if re.search(r'(^|\s)ip[6]*=', self._cmdline):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think [6]* is slightly incorrect, it would match, e.g., ip666 (the addressing protocol of the beast); 6? will match 0 or 1 "6"s. (Either way, the square brackets are superfluous: a character and a bracket expression containing only that character are equivalent.) This is borderline nit territory, but as regexes are hard enough to read at the best of times, I think it's worth being exact here.

I think we're also missing tests for the ^ choice of the subexpression here: nothing fails if I edit the regex to only have \s there instead of the subexpression. Can you add a test for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just flying past here, but you should really "parse" the kernel cmdline with shlex.split, because that's essentially what the initramfs is doing. This regex would match something like the admittedly extremely contrived opt="bunch of stuff with spaces and ip=foo". Also the fewer regexes in the codebase the better!

@TheRealFalcon
Copy link
Member Author

TheRealFalcon commented Mar 23, 2021

@OddBloke Updated based on review comments.

I attempted writing an integration test for this behavior, but I was unable to create one. It requires

  1. Passing kernel command line arguments
  2. The datasource indicating there is no network config

#1 is doable but hacky. I can't figure out a way to do #2. Can you think of a realistic way to do #2? If not, are you ok having just unit test coverage for this one?

klibc initramfs in debian allows the 'iscsi_target_ip=' cmdline
parameter to specify an iscsi device attachment. This can
cause cloud-init to mis-detect the cmdline paramter as a
networking config.

LP: #1919188
@TheRealFalcon
Copy link
Member Author

Updated (as a separate commit) to do this using shlex instead.

@mwhudson
Copy link
Contributor

Thanks, that makes me much less queasy :-)

I think it would make sense to parse the kernel command line into a dict more generally but that's a much bigger change of course.

Copy link
Collaborator

@OddBloke OddBloke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, thanks! I wonder if we should add a test for quoted content (i.e. cmdline of foo="ip=shouldntbedetected"); I'll let you decide and land this with or without it.

@TheRealFalcon
Copy link
Member Author

@OddBloke
Copy link
Collaborator

Separate from this one? https://github.com/canonical/cloud-init/pull/844/files#diff-402c7850e179c77acffc2f2a35c464a2ba0bdb6517060dbf8a9f6a6a571432b3R4435

That looks good, no idea how I missed it first time through!

@OddBloke OddBloke merged commit 3b7e2e8 into canonical:master Mar 29, 2021
@TheRealFalcon TheRealFalcon deleted the fix-cmdline branch August 19, 2021 20:39
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.

3 participants