Skip to content

cmdline: add support for loading config from a local device#2230

Open
atd9876 wants to merge 2 commits into
coreos:mainfrom
atd9876:add-metal-config-drive
Open

cmdline: add support for loading config from a local device#2230
atd9876 wants to merge 2 commits into
coreos:mainfrom
atd9876:add-metal-config-drive

Conversation

@atd9876

@atd9876 atd9876 commented May 8, 2026

Copy link
Copy Markdown

Summary

Add support for loading Ignition configuration from a local device
specified via kernel command-line flags ignition.config.device and
ignition.config.path. This enables bare-metal and air-gapped
environments to provide Ignition configs on a labeled disk partition
(e.g., a config drive) without requiring network access.

Acknowledgments

The initial device-based config loading implementation (commit 6c250bc)
was authored by Jan Larwig (@tuunit). This PR builds on that work with
tests, documentation, and robustness improvements.

Changes

  • Device-based config loading: parseCmdline now recognizes
    ignition.config.device and ignition.config.path flags.
    fetchConfig uses both to mount the labeled device read-only and
    read the config file at the specified path.
  • tryMounting function: Waits for the labeled device to appear
    (with a 30-second timeout), mounts it read-only into a temporary
    directory, reads the config, and unmounts on return.
  • Robustness improvements to parseCmdline:
    • Use strings.Fields instead of strings.Split to correctly
      handle tabs, multiple spaces, and trailing newlines.
    • Rename local url variable to parsedURL to avoid shadowing
      the net/url import.
    • Use errors.Is(err, context.DeadlineExceeded) instead of ==
      to correctly match wrapped errors.
  • Tests: Add unit tests covering URL parsing, device+path parsing,
    partial flags, empty flags, invalid URLs, precedence, fileExists,
    and error handling in test helpers.
  • Documentation: Update docs for the new command-line flags.

Fixes #2207

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for loading Ignition configurations from a local device on bare metal platforms via the ignition.config.device and ignition.config.path kernel parameters. The implementation includes documentation updates, a refactored command-line parser, and logic to mount the specified device and read the configuration file. Review feedback identifies a potential logic error where returning configErrors.ErrEmpty might cause a fatal failure instead of a fallback when a device is missing, and a path traversal vulnerability when accessing the configuration file on the mounted device.

Comment thread internal/providers/cmdline/cmdline.go
Comment thread internal/providers/cmdline/cmdline.go Outdated
@atd9876 atd9876 force-pushed the add-metal-config-drive branch from bab4a01 to a13e77b Compare May 8, 2026 12:25

@prestist prestist left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is looking good overall, thank you for working on this! Some small comments.

I think we could use some integration tests, I would add a blackbox test (in tests/positive/) that sets up a labeled disk image with a config file and boots with ignition.config.device=LABEL ignition.config.path=/config.ign, wdyt?

Comment thread internal/providers/cmdline/cmdline.go Outdated
Comment thread internal/providers/cmdline/cmdline.go Outdated
Comment thread internal/providers/cmdline/cmdline.go

@prestist prestist left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just two comments, Im not sure how I feel about them. What are your thoughts?

Comment thread internal/providers/cmdline/cmdline.go
Comment thread internal/providers/cmdline/cmdline.go Outdated
@prestist

prestist commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the updates in 9a073d5 -- I've re-reviewed and the error handling changes look good. Incomplete flags, missing config, and device timeout all correctly return hard errors now instead of falling through silently. The negative blackbox tests are a nice addition too.
I'm fine with the 30s timeout -- laenion's data from SUSE backs that up.

A couple of things I'd like addressed before we merge:
configMinVersion in the tests should be "3.0.0" -- this feature is a provider behavior change, not a spec change. Setting it to 3.4.0 means the tests only run against spec versions >= 3.4.0 when there's no reason for that restriction.
Device label should be validated -- the config file path is properly sanitized with filepath.Clean(filepath.Join("/", ...)) which is great, but the device label from the kernel cmdline is passed straight into filepath.Join(distro.DiskByLabelDir(), opts.DeviceLabel) without the same treatment. Something like rejecting labels containing / or .. would keep it consistent.
A few smaller things (not blocking, but worth considering):

  • If both ignition.config.url and ignition.config.device/ignition.config.path are set, the URL silently wins. Would be good to log a warning so the user knows their device flags are being ignored.
  • Could use a negative test for the "only one of device/path set" error case -- you cover config-not-found and device-not-found but not this one.
  • The distro.go change making KernelCmdlinePath() env-overridable is fine (follows the existing pattern for SystemConfigDir etc.) but ideally should be its own commit since it affects all callers.

Lastly the "Require release note" CI check is failing -- can you add a release note?

@atd9876

atd9876 commented Jun 9, 2026

Copy link
Copy Markdown
Author

I will fix those issues.

Re the

  • negative test for the "only one of device/path set" error case - I felt that the unit tests covered that but I will add one.

@atd9876 atd9876 force-pushed the add-metal-config-drive branch from 9a073d5 to 0861cdd Compare June 10, 2026 08:41
@prestist

Copy link
Copy Markdown
Collaborator

@atd9876 Okay from my perspective this is lgtm, just need to rebase and resolve any commits to get the CI working :)

@atd9876 atd9876 force-pushed the add-metal-config-drive branch from 0861cdd to 06a1302 Compare July 3, 2026 12:20
atd9876 added 2 commits July 7, 2026 09:38
Follow the existing pattern used by SystemConfigDir and other distro
functions, allowing KernelCmdlinePath to be overridden via the
IGNITION_KERNEL_CMDLINE_PATH environment variable. This enables
blackbox tests to inject a fake kernel cmdline.

Signed-off-by: Andrew Dodds <andrew.dodds@sap.com>
Add support for loading Ignition config from a labeled block device via
the ignition.config.device and ignition.config.path kernel command-line
arguments. Both must be specified together.

Error handling:
- Return hard error if only one of device/path is specified
- Return hard error if the device does not appear within 30s timeout
- Return hard error if the config file is not found on the device

Includes unit tests for parseCmdline and blackbox integration tests
covering both positive (successful fetch) and negative (missing device,
missing file, incomplete options) scenarios.

Signed-off-by: Andrew Dodds <andrew.dodds@sap.com>
@atd9876 atd9876 force-pushed the add-metal-config-drive branch from 06a1302 to feb4f08 Compare July 7, 2026 08:38
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.

metal: add config drive support for bare metal provisioning

3 participants