Skip to content

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

Open
atd9876 wants to merge 4 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 4 commits into
coreos:mainfrom
atd9876:add-metal-config-drive

Conversation

@atd9876
Copy link
Copy Markdown

@atd9876 atd9876 commented May 8, 2026

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

Copy link
Copy Markdown

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

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
- Use strings.Fields instead of strings.Split for proper whitespace handling
- Use errors.Is for wrapped error comparison (context.DeadlineExceeded)
- Rename local url variable to parsedURL to avoid shadowing net/url import
- Check f.Close() error in test helper
- Check url.Parse error in test assertion

Signed-off-by: Andrew Dodds <[email protected]>
@atd9876 atd9876 force-pushed the add-metal-config-drive branch from bab4a01 to a13e77b Compare May 8, 2026 12:25
Copy link
Copy Markdown
Collaborator

@prestist prestist left a comment

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
- Return hard error on device timeout instead of silently continuing
- Wrap os.Remove in logging closure for temp mount point cleanup
- Add blackbox integration test for cmdline device/path config fetch

Signed-off-by: Andrew Dodds <[email protected]>
Copy link
Copy Markdown
Collaborator

@prestist prestist left a comment

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?

}

return util.ParseConfig(f.Logger, data)
return types.Config{}, report.Report{}, platform.ErrNoProvider
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.

Hmm, this feels like it could lead to misconfiguration, if a user sets the wrong file location, we would get an error, but then that would essentially lead to a log, and the continuation of the provisioning no?

return types.Config{}, report.Report{}, err
}
if data == nil {
logger.Info("config file %q not found on device. Continuing without config...", opts.UserDataPath)
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.

Im not sure we would want to continue if we cannot find the user specified config.

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

4 participants