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

spread(lxd): work around SSH password authentication disabled by livecd-rootfs #184

Merged
merged 6 commits into from
Dec 16, 2024

Conversation

bboozzoo
Copy link
Contributor

In recent images, livecd-rootfs may be disabling SSH password authentication by default, with the intention that cloud-init would enabled that by placing a higher priority file under /etc/sshd/sshd_config.d/. See https://git.launchpad.net/livecd-rootfs/commit/live-build/ubuntu-cpc/hooks.d/chroot/052-ssh_authentication.chroot?id=480d5b26ea97e0bfebac8aedfa1f2bf7286f027a for reference.

Do the same as cloud-init would a drop a higher priority config overriding relevant SSHD settings.

Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

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

This looks good to me.

@bboozzoo
Copy link
Contributor Author

I'll extend the lxd backend spread test to cover more recent images.

@bboozzoo
Copy link
Contributor Author

LXD backend spread tests have been updated with Ubuntu 18.04, 20.04, and 22.04.

@bboozzoo
Copy link
Contributor Author

Looks like a similar fix but done slightly differently was proposed in #179

@bboozzoo bboozzoo changed the title spread: work around SSH password authentication disabled by livecd-rootfs spread(lxd): work around SSH password authentication disabled by livecd-rootfs Mar 13, 2024
@thp-canonical
Copy link
Contributor

Also related, a similar fix for the Google backend: #155

Copy link

@ZeyadYasser ZeyadYasser left a comment

Choose a reason for hiding this comment

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

Thank you for catching this, Maybe let's wait for it to be merged in the google backend #155? and then backport it to all other providers so that it is consistent across all of them.

Copy link
Collaborator

@cmatsuoka cmatsuoka left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Seems reasonable, but a bit obscure. More details below.

spread/lxd.go Outdated
@@ -482,6 +482,8 @@ func (p *lxdProvider) serverJSON(name string) (*lxdServerJSON, error) {
func (p *lxdProvider) tuneSSH(name string) error {
cmds := [][]string{
{"sed", "-i", `s/^\s*#\?\s*\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/`, "/etc/ssh/sshd_config"},
// provide a higher priority drop in with our overrides
{"/bin/bash", "-c", `[ -d /etc/ssh/sshd_config.d ] && echo -e "PermitRootLogin yes\nPasswordAuthentication yes" > /etc/ssh/sshd_config.d/00-spread.conf`},
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is not making clear what is going on. "Higher priority" than what? Why do we need the same operation in two different ways? Also, if there are duplicates, what happens?

Also, as an aside our comments are typically "// Proper English sentences.", and in the case here it should maybe be above the two lines since they both aim at the same outcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tweaked the wording around the snippets.

Copy link
Collaborator

@cmatsuoka cmatsuoka Dec 9, 2024

Choose a reason for hiding this comment

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

Thanks for the update. The comment explains it better, but I think the wording is still a bit confusing. Let me try an alternative, see what you think.

…otfs

In recent images, livecd-rootfs may be disabling SSH password authentication by
default, with the intention that cloud-init would enabled that by placing a
higher priority file under /etc/sshd/sshd_config.d/. See
https://git.launchpad.net/livecd-rootfs/commit/live-build/ubuntu-cpc/hooks.d/chroot/052-ssh_authentication.chroot?id=480d5b26ea97e0bfebac8aedfa1f2bf7286f027a
for reference.

Do the same as cloud-init would a drop a higher priority config overriding
relevant SSHD settings.

Signed-off-by: Maciej Borzecki <[email protected]>
Extend the list of systems.

Signed-off-by: Maciej Borzecki <[email protected]>
@cmatsuoka cmatsuoka added the Reviewed Supposedly ready for tuning or merging label Dec 11, 2024
Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Thanks!

@niemeyer
Copy link
Contributor

Oops, tests are failing.

spread/lxd.go Outdated
// If the sshd configuration is split in snippets in /etc/ssh/sshd_config.d,
// place the configuration in a 00-* file because the first obtained value
// will be used. See sshd_config(5) for details.
{"/bin/bash", "-c", `[ -d /etc/ssh/sshd_config.d ] && echo -e "PermitRootLogin yes\nPasswordAuthentication yes" > /etc/ssh/sshd_config.d/00-spread.conf`},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 'shortened' version is actually wrong, exit code [ -d /etc/ssh/sshd_config.d ] becomes the return status of the whole command. Let me push a fix.

…fixup

Use a proper `if ..; then .. fi` statement to avoid the shortened shell
form returning with an incorrect status when /etc/ssh/sshd_config.d does
not exist.

Signed-off-by: Maciej Borzecki <[email protected]>
@bboozzoo
Copy link
Contributor Author

hmm the test google system ran out of space?

Error: Failed instance creation: Failed creating instance from image: Unpack failed, Failed to run: unsquashfs -f -d /var/snap/lxd/common/lxd/storage-pools/default/containers/spread-4-ubuntu-18-04/rootfs -n /var/snap/lxd/common/lxd/images/c533845b5db1747674ee915cbb20df6eb47c953bb7caf1fec5b35ae9ccf98c18.rootfs: Write on output file failed because No space left on device

@bboozzoo bboozzoo closed this Dec 11, 2024
@bboozzoo bboozzoo reopened this Dec 11, 2024
@bboozzoo
Copy link
Contributor Author

I don't think this is getting anywhere given the flakiness in lxd:

Error: Failed instance creation: write unix @->/var/snap/lxd/common/lxd/unix.socket: i/o timeout
-----

@bboozzoo bboozzoo closed this Dec 11, 2024
@bboozzoo bboozzoo reopened this Dec 11, 2024
@niemeyer
Copy link
Contributor

Thanks!

@niemeyer niemeyer merged commit ec9dc61 into canonical:master Dec 16, 2024
1 of 3 checks passed
slyon added a commit to slyon/netplan that referenced this pull request Dec 16, 2024
daniloegea pushed a commit to canonical/netplan that referenced this pull request Jan 7, 2025
daniloegea pushed a commit to canonical/netplan that referenced this pull request Jan 20, 2025
@bboozzoo bboozzoo deleted the bboozzoo/fix-lxd branch January 27, 2025 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reviewed Supposedly ready for tuning or merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants