cirros-dev / cirros

120 stars 33 forks source link

Fixed the readlink in init script #110

Closed stesrn closed 1 month ago

stesrn commented 11 months ago

Init script 'S50-dropbear' updated 'dropbear_key_dir' variable to read the target location of the symlink using 'readlink'. But the result was not the target of the link. Now fixed it with removing the switch '-f' for 'readlink'

Because of this issue, host keys are not generated and as a result unable to SSH in to cirros VMs

This is what seen with cirros 0.5.2 $ readlink -f /etc/dropbear /etc/dropbear $ readlink /etc/dropbear /var/run/dropbear

osfrickler commented 11 months ago

Can you add more detail about how to reproduce the issue? Also note that 0.5.2 has been superceded by 0.5.3 or even the 0.6.x train, do you also see the issue there?

smoser commented 11 months ago

I'm confused. I just looked at 0.5.2 and /etc/dropbear is a regular directory, not a symlink at all.

$ sudo mount-image-callback disk1.img --read-only --cd -- stat etc/dropbear
  File: etc/dropbear
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 2b01h/11009d    Inode: 802         Links: 2
Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-11-17 09:28:21.000000000 -0500
Modify: 2023-11-17 09:28:01.000000000 -0500
Change: 2023-11-17 09:28:01.000000000 -0500
 Birth: -
$ sudo mount-image-callback disk1.img --read-only --cd -- ls -ld etc/dropbear
drwx------ 2 root root 4096 Nov 17 09:28 etc/dropbear
$ sudo mount-image-callback disk1.img --read-only --cd -- cat etc/cirros/version
0.5.2
$ sudo mount-image-callback disk1.img --read-only --cd -- chroot .
chroot: failed to run command ‘/bin/bash’: No such file or directory
$ sudo mount-image-callback disk1.img --read-only --cd -- chroot /bin/sh
chroot: cannot change root directory to '/bin/sh': Not a directory
$ sudo mount-image-callback disk1.img --read-only --cd -- chroot . /bin/sh
/ # readlink /etc/dropbear
/ # readlink -f /etc/dropbear
/etc/dropbear
smoser commented 11 months ago

I'm confused. I just looked at 0.5.2 and /etc/dropbear is a regular directory, not a symlink at all.

Also, it seems that 'readlink' without -f on a non-link returns empty output, with -f it will give the actual path. see below.

$ sudo mount-image-callback disk1.img --read-only --cd -- cat etc/cirros/version
0.5.2

$ sudo mount-image-callback disk1.img --read-only --cd -- stat etc/dropbear
  File: etc/dropbear
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 2b01h/11009d    Inode: 802         Links: 2
Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2023-11-17 09:28:21.000000000 -0500
Modify: 2023-11-17 09:28:01.000000000 -0500
Change: 2023-11-17 09:28:01.000000000 -0500
 Birth: -

$ sudo mount-image-callback disk1.img --read-only --cd -- ls -ld etc/dropbear
drwx------ 2 root root 4096 Nov 17 09:28 etc/dropbear

$ sudo mount-image-callback disk1.img --read-only --cd -- chroot /bin/sh
chroot: cannot change root directory to '/bin/sh': Not a directory
$ sudo mount-image-callback disk1.img --read-only --cd -- chroot . /bin/sh
/ # readlink /etc/dropbear
/ # readlink -f /etc/dropbear
/etc/dropbear
stesrn commented 11 months ago

I am seeing the same issue with cirros-0.5.3, but haven't tested it with 0.6.z

@smoser I used the same cirros 0.5.2 and created VM out of it.


$ sudo mount-image-callback --read-only cirros-0.5.2-x86_64-disk.img -C -m /home/sas/test-cirros/tmp -- cat /home/sas/test-cirros/tmp/etc/cirros/version
0.5.2

$ sudo mount-image-callback --read-only cirros-0.5.2-x86_64-disk.img -C -m /home/sas/test-cirros/tmp -- ls /home/sas/test-cirros/tmp/etc/dropbear -l
lrwxrwxrwx. 1 root root 17 Nov 20 12:47 /home/sas/test-cirros/tmp/etc/dropbear -> /var/run/dropbear

$ sudo mount-image-callback --read-only cirros-0.5.2-x86_64-disk.img -C -m /home/sas/test-cirros/tmp -- ls /home/sas/test-cirros/tmp/var/run/dropbear
ls: cannot access '/home/sas/test-cirros/tmp/var/run/dropbear': No such file or directory`

$ sudo mount-image-callback --read-only cirros-0.5.2-x86_64-disk.img -C -m /home/sas/test-cirros/tmp -- readlink /home/sas/test-cirros/tmp/etc/dropbear
/var/run/dropbear

Here the problem is that /etc/dropbear links to /var/run/dropbear. But this directory /var/run/dropbear is not available.

smoser commented 11 months ago

I am seeing the same issue with cirros-0.5.3, but haven't tested it with 0.6.z

@smoser I used the same cirros 0.5.2 and created VM out of it.

You are right... i dont know what I was doing. I'll look at this further.

stesrn commented 9 months ago

@smoser Hi. This issue is not yet addressed. What is the plan to fix this issue with cirros ?

osfrickler commented 1 month ago

For the next release this will be fixed by https://github.com/cirros-dev/cirros/issues/118, I don't think we will support older releases.