Skip to content

system-reinstall-bootc: SSH key handling via cloud-init detection#2163

Draft
hone wants to merge 1 commit intobootc-dev:mainfrom
hone:ssh-key-cloud-init
Draft

system-reinstall-bootc: SSH key handling via cloud-init detection#2163
hone wants to merge 1 commit intobootc-dev:mainfrom
hone:ssh-key-cloud-init

Conversation

@hone
Copy link
Copy Markdown
Contributor

@hone hone commented Apr 23, 2026

If cloud-init is detected in the target image:

  1. Check the host for existing root SSH keys at /root/.ssh/authorized_keys.
  2. If host keys exist, automatically configure inheritance via /target/root/.ssh/authorized_keys.
  3. If no host keys exist, proceed without manual interaction, trusting cloud-init in the new system to handle key provisioning.

If cloud-init is not detected, maintain the existinginteractive behavior to prevent user lock-out.

Ref: #1300

If cloud-init is detected in the target image:
1. Check the host for existing root SSH keys at /root/.ssh/authorized_keys.
2. If host keys exist, automatically configure inheritance via
   /target/root/.ssh/authorized_keys.
3. If no host keys exist, proceed without manual interaction, trusting
   cloud-init in the new system to handle key provisioning.

If cloud-init is not detected, maintain the existinginteractive behavior
to prevent user lock-out.

Ref: bootc-dev#1300

Signed-off-by: Terence Lee <hone02@gmail.com>
@hone hone marked this pull request as draft April 23, 2026 23:26
@github-actions github-actions Bot added the area/system-reinstall-bootc Issues related to system-reinstall-botoc label Apr 23, 2026
@bootc-bot bootc-bot Bot requested a review from ckyrouac April 23, 2026 23:26
Copy link
Copy Markdown
Contributor

@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 automatic SSH key inheritance when cloud-init is detected in the target image, allowing the system to reuse host keys instead of prompting the user. It adds a new check for cloud-init within the container and updates the command generation logic to handle optional SSH keys. Feedback suggests moving the cloud-init check before the spinner is cleared to improve the user experience during the container run. Additionally, it is recommended to expand the key inheritance logic to include keys from other users on the host, ensuring consistency with existing behavior and preventing potential lockouts.

Comment on lines 73 to +79
let has_clean = podman::bootc_has_clean(&opts.image)?;
spinner.finish_and_clear();

let ssh_key_file = tempfile::NamedTempFile::new()?;
let ssh_key_file_path = ssh_key_file
.path()
.to_str()
.ok_or_else(|| anyhow::anyhow!("unable to create authorized_key temp file"))?;
let mut _ssh_key_tempfile = None;
let mut ssh_key_file_path = None;

if podman::image_has_cloud_init(&opts.image)? {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The podman::image_has_cloud_init check involves running a container, which can take a few seconds. It should be performed while the spinner is active to provide better feedback to the user and avoid a perceived hang in the UI.

Suggested change
let has_clean = podman::bootc_has_clean(&opts.image)?;
spinner.finish_and_clear();
let ssh_key_file = tempfile::NamedTempFile::new()?;
let ssh_key_file_path = ssh_key_file
.path()
.to_str()
.ok_or_else(|| anyhow::anyhow!("unable to create authorized_key temp file"))?;
let mut _ssh_key_tempfile = None;
let mut ssh_key_file_path = None;
if podman::image_has_cloud_init(&opts.image)? {
let has_clean = podman::bootc_has_clean(&opts.image)?;
let has_cloud_init = podman::image_has_cloud_init(&opts.image)?;
spinner.finish_and_clear();
let mut _ssh_key_tempfile = None;
let mut ssh_key_file_path = None;
if has_cloud_init {

Comment on lines +80 to +81
let host_root_keys = std::path::Path::new("/root/.ssh/authorized_keys");
if host_root_keys.exists() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The automatic inheritance logic only checks for keys in /root/.ssh/authorized_keys. This is a departure from the existing interactive behavior in get_ssh_keys, which scans all users on the host system. If a user is running this tool via sudo but has their keys in their own home directory (e.g., /home/user/.ssh/authorized_keys), they will not be inherited automatically, potentially leading to a lockout if the image relies on these keys and cloud-init has no other datasource. Consider using the existing multi-user key detection logic or at least checking the current user's keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/system-reinstall-bootc Issues related to system-reinstall-botoc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant