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

Problem with Busybox sh #2

Closed
malvinas2 opened this issue Dec 12, 2018 · 17 comments
Closed

Problem with Busybox sh #2

malvinas2 opened this issue Dec 12, 2018 · 17 comments

Comments

@malvinas2
Copy link

Using Ubuntu Server 16.04 LTS I got stucked at point 4: Every time I enter the command line "busybox sh..." I get the error "sh: bad number", is there something wrong with the regex-expression inside the script ?

root@ubuntu:~# busybox sh /lib/cryptsetup/scripts/wget_or_ask "mypassword:http://www.my-domain.at/encrypted_keyfile" > unencrypted_keyfile
sh: bad number
Getting passphrase remotely failed for . Enter passphrase: **

Adding parameter -x to sh results in:

root@ubuntu:~# busybox sh -x /lib/cryptsetup/scripts/wget_or_ask "mypassword:http://www.my-domain.at/encrypted_keyfile" > unencrypted_keyfile
+ use_keyring=1
+ use_https=1
+ [ -z ]
+ CRYPTTAB_KEY=mypassword:http://www.my-domain.at/encrypted_keyfile
+ sedRegex=^\(.\+\):\(https:\/\/.\+\)$
+ echo mypassword:http://www.my-domain.at/encrypted_keyfile
+ sed -n -e s/^\(.\+\):\(https:\/\/.\+\)$/\1/p
+ openssl_passphrase=
+ echo mypassword:http://www.my-domain.at/encrypted_keyfile+ sed -n -e s/^\(.\+\):\(https:\/\/.\+\)$/\2/p

+ url=
+ keyctl_id=crypttab:mypassword:http://www.my-domain.at/encrypted_keyfile
+ [ -gt 0 ]
sh: bad number
+ [ ! -x /bin/keyctl ]
+ [ -z ]
+ use_https=0
+ use_plymouth=0
+ [ -x /bin/plymouth ]
+ plymouth --ping
+ keyctl_try_fetch
+ [ 1 -eq 0 ]
+ keyctl search @u user crypttab:mypassword:http://www.my-domain.at/encrypted_keyfile
+ kSerial=keyctl_search: Required key not available
+ exitCode=1
+ [ 1 -eq 0 ]
+ [ 1 -ne 1 ]
+ https_try_fetch
+ [ 0 -eq 0 ]
+ return 0
+ askpass Getting passphrase remotely failed for . Enter passphrase:
+ [ ! -z ]
+ [ 0 -eq 1 ]
+ /lib/cryptsetup/askpass Getting passphrase remotely failed for . Enter passphrase: Getting passphrase remotely failed for . Enter passphrase: **

root@ubuntu:~#

@stupidpupil
Copy link
Owner

I think that the 'bad number' message is a distraction here, actually - it's because the $CRYPTTAB_TRIED envvar isn't set at all and the script ends up trying to compare an empty string as a number. (I should probably guard against this!)

Are you using an http address or an https address? The regex won't let you use the former, but it's easy enough to change if you really want to.

@malvinas2
Copy link
Author

Thank you very much for your fast response.
Within wget_or_ask I changed use_https=1 to use_https=0 and deleted the 's' of https in line 12 (sedRegex=...). Busybox sh runs correctly now, I added the key to cryptluks, updated /etc/crypttab and the initramfs and the encrypted_keyfile is available on the webserver , but after a reboot of the system I am asked for the password.
How do I find the mistake?

@malvinas2
Copy link
Author

I must correct myself: First I removed the 's' of https in the wget_or_ask script and ran it and updated the system, and after that I edited wget_or_ask a second time, changing use_https=1 to use_https=0.
If I make the two changes at once, the keyfile is not found on the webserver.
Nevertheless, it is not working....
I uploaded an excerpt of syslog to https://pastebin.com/r799dEN7 , which says something of "ignoring" password-file-path and wget_or_ask (?).
My /etc/crypttab: https://pastebin.com/UavzSw4p

@stupidpupil
Copy link
Owner

stupidpupil commented Dec 13, 2018

Apologies for this being such a pain!

You'll have to leave use_https=1 (that enables it trying the webserver at all, so long as it can parse the 'keyfile' input etc.) - make sure this is fixed first.

Try adding the 'initramfs' option to the end of your crypttab entry:
luks,keyscript=wget_or_ask,initramfs
and rebuilding your initramfs.

systemd doesn't understand how to use keyscripts (for sort of good reasons) - Debian and Ubuntu can use them, but only in the initramfs. I'm assuming this isn't your root partition - so you have to force it manually. (This is buried in the crypttab man page, but perhaps I should document this more clearly - it's not at all obvious.)

@malvinas2
Copy link
Author

I have added initramfs to the crypttab entry, but during the start I get the message that remotely fetching didn't work and I am asked to enter the passphrase, but neither the password used in https-keyscript nor the normal password (key slot 0) works.

Dec 13 22:07:19 ubuntu systemd-cryptsetup[820]: Password file path 'mypassword:http://www.mydomain.at/encrypted_keyfile' is not absolute. Ignoring.
Dec 13 22:07:19 ubuntu systemd-cryptsetup[820]: Encountered unknown /etc/crypttab option 'keyscript=wget_or_ask', ignoring.
Dec 13 22:07:19 ubuntu systemd-cryptsetup[820]: Encountered unknown /etc/crypttab option 'initramfs', ignoring.

The system boots from a SSD, which is not encrypted. Just the internal harddiscs are encrypted.

@stupidpupil
Copy link
Owner

I think that the systemd warnings can be ignored if you're now getting the "remote fetching didn't work" messages.

It's very odd that the normal password isn't working.

Does the following work (once you're booted)?

/lib/cryptsetup/scripts/wget_or_ask "https://example.org/encrypted_keyfile" > temp
sudo cryptsetup luksOpen --test-passphrase /dev/md2 -d temp

@malvinas2
Copy link
Author

negative:

root@ubuntu:~# /lib/cryptsetup/scripts/wget_or_ask "http://www.mydomain.at/encrypted_keyfile" > temp
/lib/cryptsetup/scripts/wget_or_ask: 24: [: Illegal number:
Getting passphrase remotely failed for . Enter passphrase:

@stupidpupil
Copy link
Owner

Apologies - missed out the passphrase. Should have been:

/lib/cryptsetup/scripts/wget_or_ask "passphrase:https://example.org/encrypted_keyfile" > temp
sudo cryptsetup luksOpen --test-passphrase /dev/md2 -d temp

@malvinas2
Copy link
Author

Oh yes, the passphrase.... I still receive the complain about 'illegal number', but it works, also the 2nd instruction works, adding a test-passphrase.

@malvinas2
Copy link
Author

malvinas2 commented Dec 14, 2018

Some time ago Ubuntu changed the name of the network interface from eth0 to enp2s0. Modifying the corresponding entry in /etc/initramfs-tools/scripts/init-premount/networking.sh, removing the appendix initramfs from keyfile=wget_or_ask in /etc/crypttab and updating initramfs leads -nearly- to the desired result.
Before: https://imgur.com/nhLBajX
After: https://imgur.com/yqsNA0G

I say nearly, because during the boot sequence I get asked a second time to enter manually the passphrase. If you took a look at the video uploaded at https://youtu.be/VwIlscDUPko you will see the effect of https-keyscript between position 05 s till 14 s and at 17 s I get asked for the passphrase. What's that?
I added nofail in crypttab, so the entry options is now luks,keyscript=wget_or_ask,nofail, booting now without asking.

BTW: Is there any fast method to deactivate https-keyscript ? Or do I have to delete the corresponding files located within the subfolders of initramfs (hooks and init-premount) and update initramfs everytime I want to deactivate it?

P.S.: I don't know why, but YouTube rotated the video by 90°......

@malvinas2
Copy link
Author

Well, syslog still says:
Dec 14 21:38:21 ubuntu systemd[1]: Starting Cryptography Setup for md2-crypt...
Dec 14 21:38:21 ubuntu systemd-cryptsetup[753]: Password file path 'mypassword:http://www.mydomain.at/encrypted_keyfile' is not absolute. Ignoring.
Dec 14 21:38:21 ubuntu systemd-cryptsetup[753]: Encountered unknown /etc/crypttab option 'keyscript=wget_or_ask', ignoring.
So, the network interface is found now, but /keyscript=.... still causes problems.

@stupidpupil
Copy link
Owner

Useful point about the network interface name. I've wondered whether I should include the networking setup script at all, since people might have more complicated network configuration requirements anyway - you'd then have to configure networking using kernel parameters.

Disabling it pretty much is a matter of uninstalling it, yes.

You'll get systemd complaining whatever - you can ignore these messages in themselves (which I should document). I still think you need the initramfs option in crypttab so that the Debian/Ubuntu script tries to handle decryption (before systemd tries).

@malvinas2
Copy link
Author

malvinas2 commented Dec 15, 2018

Adding the initramfs option in crypttab I get the result shown in https://imgur.com/x9ZVRvA. No file is fetched remotely and no matter what passphrase I enter, it is not recognized (at least nothing is decrypted).
(without initramfs the network interface is detected, but the message "Fetching remote keyfile for md2-crypt" does not appear, as shown in the previous video e.g.)
syslog now says:
Dec 15 12:28:55 ubuntu systemd[1]: Starting Cryptography Setup for md2-crypt...
Dec 15 12:28:55 ubuntu systemd-cryptsetup[893]: Password file path 'mypassword:http://www.mydomain.at/encrypted_keyfile' is not absolute. Ignoring.
Dec 15 12:28:55 ubuntu systemd-cryptsetup[893]: Encountered unknown /etc/crypttab option 'initramfs', ignoring.
Dec 15 12:28:55 ubuntu systemd-cryptsetup[893]: Encountered unknown /etc/crypttab option 'keyscript=wget_or_ask', ignoring.

@stupidpupil
Copy link
Owner

stupidpupil commented Dec 15, 2018

I'm going to setup a virtual Ubuntu 16.04 machine and see if I can get this working (with an http, not https, URL and with a non-root encrypted drive as well) before I take up any more of your time with guesses.

@stupidpupil
Copy link
Owner

stupidpupil commented Dec 15, 2018

I got a 16.04 install to the the same point you are by:

  1. fixing the network interface name (I've opened another issue for this at init-premount/networking.sh is fragile at best #4 )
  2. editing the regex to allow http:// urls
  3. Using the initramfs option so that the cryptdisks_start script would be used (before systemd-cryptsetup tries to handle it and fails)

At this point cryptdisks_start worked fine once the system is fully booted - remote keyfile is fetched and the partition is decrypted - but booting did not.

Booting resulted in the same error message you had - cryptsetup: unknown fstype, bad password or options?".

Running mkfs.ext4 on the decrypted block device fixed this for me, and it now fetches the remote keyfile and unlocks successfully on boot. (I guess that the initramfs cryptsetup scripts are more paranoid than the systemd equivalent, possibly because they were built with systems other than LUKS in mind?)

Have you created a filesystem on the decrypted block device?

I emphasise 'for me' because I believe there might be other issues that can produce the same error. One is this Ubuntu bug and the other, perhaps, is that if you're using a MD RAID array then that introduces another complication of ensuring that device is available in time for cryptsetup.

(If the second of these does crop up, it is solvable - because one of my machines has an encrypted root partition on top of an MD array, and unlocks using this keyscript.)

@malvinas2
Copy link
Author

malvinas2 commented Dec 16, 2018

No, in fact the raid array hasn't got a filesystem, because I just recently bought the two harddiscs and used them as a kind of 'trial balloon' before encrypting the whole system.
The entire setup will consist of 6 hd's, a set of two of them shall form an mdadm-array, resulting in 3 raids. Each raid is going to be encyrpted and be assigned to a physical volume. Finally the three volumes are combined to one logical volume by lvm.
Well, I am going to encrypt the system in any case. I will report back to you as soon as possible.

@malvinas2
Copy link
Author

Yes, with a filesystem it works like a charm!
Thank you very much for this amazing piece of software!

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda                          8:0 0 7,3T 0 disk
└─sda1                       8:1 0 7,3T 0 part
   └─md0                     9:0 0 7,3T 0 raid1
     └─md0-crypt           252:0 0 7,3T 0 crypt
        └─vgraid-lvraid    252:3 0 20,9T 0 lvm /media/disc
sdb                          8:16 0 7,3T 0 disk
└─sdb1                       8:17 0 7,3T 0 part
   └─md0                     9:0 0 7,3T 0 raid1
     └─md0-crypt           252:0 0 7,3T 0 crypt
        └─vgraid-lvraid    252:3 0 20,9T 0 lvm /media/disc
sdc                          8:32 0 4,6T 0 disk
└─sdc1                       8:33 0 4,6T 0 part
   └─md1                     9:1 0 4,6T 0 raid1
     └─md1-crypt           252:1 0 4,6T 0 crypt
        └─vgraid-lvraid    252:3 0 20,9T 0 lvm /media/disc
sdd                          8:48 0 4,6T 0 disk
└─sdd1                       8:49 0 4,6T 0 part
   └─md1                     9:1 0 4,6T 0 raid1
     └─md1-crypt           252:1 0 4,6T 0 crypt
        └─vgraid-lvraid    252:3 0 20,9T 0 lvm /media/disc
sde                          8:64 0 9,1T 0 disk
└─sde1                       8:65 0 9,1T 0 part
   └─md2                     9:2 0 9,1T 0 raid1
     └─md2-crypt           252:2 0 9,1T 0 crypt
        └─vgraid-lvraid    252:3 0 20,9T 0 lvm /media/disc
sdf                          8:80 0 9,1T 0 disk
└─sdf1                       8:81 0 9,1T 0 part
   └─md2                     9:2 0 9,1T 0 raid1
     └─md2-crypt           252:2 0 9,1T 0 crypt
        └─vgraid-lvraid    252:3 0 20,9T 0 lvm /media/disc
nvme0n1                    259:0 0 238,5G 0 disk
├─nvme0n1p1                259:1 0 512M 0 part /boot/efi
├─nvme0n1p2                259:2 0 230,1G 0 part /
└─nvme0n1p3                259:3 0 7,9G 0 part [SWAP]

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

No branches or pull requests

2 participants