hartwork / image-bootstrap

:partly_sunny: Creates Linux chroots and bootable virtual machine images; command line tool (Python 3)
https://linuximages.de/
264 stars 39 forks source link

Error: a bytes-like object is required, not 'str' #87

Closed kovetskiy closed 4 years ago

kovetskiy commented 4 years ago

Hi there, image-bootstrap fails everytime when I specify a password using --password or --password-file (I put password in a file) options. It fails every time.

Here is the log:

# LOOP_DEVICE="$(losetup --show -f disk3g)"
# image-bootstrap --password lu4Eph8uir0ooHahxei3 arch $LOOP_DEVICE
     _                          __             __      __
    (_)_ _  ___ ____ ____  ___ / /  ___  ___  / /____ / /________ ____
   / /  ' \/ _ `/ _ `/ -_)/__// _ \/ _ \/ _ \/ __(_-</ __/ __/ _ `/ _ \
  /_/_/_/_/\_,_/\_, /\__/    /_.__/\___/\___/\__/___/\__/_/  \_,_/ .__/
               /___/                      v2.0.3 :: 2020-04-10  /_/

Software libre licensed under AGPL v3 or later.
Brought to you by Sebastian Pipping <sebastian@pipping.org>.
Please report bugs at https://github.com/hartwork/image-bootstrap.  Thank you!

Selected approach "chroot-grub2-drive" for bootloader installation.
Checking for blkid... /usr/sbin/blkid
Checking for blockdev... /usr/sbin/blockdev
Checking for chmod... /usr/sbin/chmod
Checking for chroot... /usr/sbin/chroot
Checking for cp... /usr/sbin/cp
Checking for find... /usr/sbin/find
Checking for gpg... /usr/sbin/gpg
Checking for kpartx... /usr/sbin/kpartx
Checking for mkdir... /usr/sbin/mkdir
Checking for mkfs.ext4... /usr/sbin/mkfs.ext4
Checking for mount... /usr/sbin/mount
Checking for parted... /usr/sbin/parted
Checking for partprobe... /usr/sbin/partprobe
Checking for rm... /usr/sbin/rm
Checking for rmdir... /usr/sbin/rmdir
Checking for sed... /usr/sbin/sed
Checking for tar... /usr/sbin/tar
Checking for tune2fs... /usr/sbin/tune2fs
Checking for umount... /usr/sbin/umount
Checking for wget... /usr/sbin/wget

Checking for known unsupported architecture/machine combination...
Checking if "/dev/loop3" is a block device...
Warning: Using --password PASSWORD is a security risk more often than not; please consider using --password-file FILE, instead.
Unsharing Linux namespaces (mount, UTS/hostname)...
Checking size of "/dev/loop3"...
Partitioning "/dev/loop3"...
Activating partition devices...
Creating file system on "/dev/mapper/loop3p1"...
mke2fs 1.45.5 (07-Jan-2020)
Creating directory "/mnt/tmpybcf94kr"...
Mounting partitions...
Creating directory "/mnt/tmpybcf94kr/etc"...
Writing file "/mnt/tmpybcf94kr/etc/hostname"...
Writing file "/mnt/tmpybcf94kr/etc/resolv.conf" (based on file "/etc/resolv.conf")...
Bootstrapping Arch into "/mnt/tmpybcf94kr"...
Checking access to "/var/cache/directory-bootstrap"...
Checking access to "/mnt/tmpybcf94kr"...
Downloading image listing...
Downloading keyring listing...
Re-using cache file "/var/cache/directory-bootstrap/archlinux-keyring-20200422.tar.gz.sig".
Re-using cache file "/var/cache/directory-bootstrap/archlinux-keyring-20200422.tar.gz".
Initializing temporary GnuPG home at "/tmp/tmpnasd4oes/gpg_home"...
Downloading "https://raw.githubusercontent.com/gpg/gnupg/master/dirmngr/sks-keyservers.netCA.pem"...
--2020-05-21 13:31:48--  https://raw.githubusercontent.com/gpg/gnupg/master/dirmngr/sks-keyservers.netCA.pem
Loaded CA certificate '/etc/ssl/certs/ca-certificates.crt'
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.128.133, 151.101.0.133, 151.101.192.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.128.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1984 (1.9K) [text/plain]
Saving to: ‘/tmp/tmpnasd4oes/gpg_home/sks-keyservers.netCA.pem’

/tmp/tmpnasd4oes/gpg_home/sks-keyserver 100%[=============================================================================>]   1.94K  --.-KB/s    in 0s

2020-05-21 13:31:49 (25.2 MB/s) - ‘/tmp/tmpnasd4oes/gpg_home/sks-keyservers.netCA.pem’ saved [1984/1984]

Importing GPG keys whitelisted to sign archlinux-keyring...
Keys found allowed to sign archlinux-keyring tarball:
  - Bartlomiej Piotrowski <bpiotrowski@archlinux.org> (F3691687D867B81B51CE07D9BBE43771487328A9)
  - Christian Hesse <Christi@n-Hes.se> (BD84DE71F493DF6814B0167254EDC91609BC9183)
  - Evangelos Foutras <evangelos@foutrelis.com> (86CFFCA918CF3AF47147588051E8B148A9999C34)
  - Florian Pritz <bluewind@xinu.at> (CFA6AF15E5C74149FC1D8C086D1655C14CE1C13E)
  - Jelle van der Waa <jelle@archlinux.org> (E499C79F53C96A54E572FEE1C06086337C50773E)
  - Pierre Schmitz <pierre@archlinux.de> (4AA4767BBC9C4B1D18AE28B77F2D434B9741E8AC)
  - Thomas Bächler <thomas@bchlr.de> (A314827C4E4250A204CE6E13284FC34C8E4B1A25)
Importing GPG keys from the internet...
Importing GPG keys from disk...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/86CFFCA918CF3AF47147588051E8B148A9999C34.asc"...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/E499C79F53C96A54E572FEE1C06086337C50773E.asc"...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/4AA4767BBC9C4B1D18AE28B77F2D434B9741E8AC.asc"...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/BD84DE71F493DF6814B0167254EDC91609BC9183.asc"...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/A314827C4E4250A204CE6E13284FC34C8E4B1A25.asc"...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/CFA6AF15E5C74149FC1D8C086D1655C14CE1C13E.asc"...
Importing GPG key from file "/usr/lib/python3.8/site-packages/directory_bootstrap/resources/arch/F3691687D867B81B51CE07D9BBE43771487328A9.asc"...
Verifying integrity of file "/var/cache/directory-bootstrap/archlinux-keyring-20200422.tar.gz"...
gpg: Signature made Wed 22 Apr 2020 02:57:05 PM CEST
gpg:                using RSA key BD84DE71F493DF6814B0167254EDC91609BC9183
gpg: Good signature from "Christian Hesse <Christi@n-Hes.se>" [unknown]
gpg:                 aka "Christian Hesse <mail@eworm.de>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: BD84 DE71 F493 DF68 14B0  1672 54ED C916 09BC 9183
Importing GPG key from file "/tmp/tmpnasd4oes/archlinux-keyring-20200422/archlinux.gpg"...
Re-using cache file "/var/cache/directory-bootstrap/archlinux-bootstrap-2020.05.01-x86_64.tar.gz.sig".
Re-using cache file "/var/cache/directory-bootstrap/archlinux-bootstrap-2020.05.01-x86_64.tar.gz".
Verifying integrity of file "/var/cache/directory-bootstrap/archlinux-bootstrap-2020.05.01-x86_64.tar.gz"...
gpg: Signature made Fri 01 May 2020 07:33:58 AM CEST
gpg:                using RSA key 4AA4767BBC9C4B1D18AE28B77F2D434B9741E8AC
gpg: Good signature from "Pierre Schmitz <pierre@archlinux.de>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 4AA4 767B BC9C 4B1D 18AE  28B7 7F2D 434B 9741 E8AC
Extracting bootstrap image to "/tmp/tmpnasd4oes/pacstrap_root/"...
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.security.capability'
tar: Ignoring unknown extended header keyword 'LIBARCHIVE.xattr.security.capability'
Adjusting mirror list at "/tmp/tmpnasd4oes/pacstrap_root/root.x86_64/etc/pacman.d/mirrorlist"...
Writing file "/tmp/tmpnasd4oes/pacstrap_root/root.x86_64/etc/resolv.conf" (based on file "/etc/resolv.conf")...
Mounting non-disk file systems...
Initializing pacman keyring... (may take 2 to 7 minutes)
gpg: /etc/pacman.d/gnupg/trustdb.gpg: trustdb created
gpg: no ultimately trusted keys found
gpg: starting migration from earlier GnuPG versions
gpg: porting secret keys from '/etc/pacman.d/gnupg/secring.gpg' to gpg-agent
gpg: migration succeeded
gpg: Generating pacman keyring master key...
gpg: key 1442B8A55FE6C200 marked as ultimately trusted
gpg: directory '/etc/pacman.d/gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/etc/pacman.d/gnupg/openpgp-revocs.d/DF170D2D9A76414711D472411442B8A55FE6C200.rev'
gpg: Done
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: inserting ownertrust of 4
gpg: setting ownertrust to 4
gpg: setting ownertrust to 4
gpg: setting ownertrust to 4
gpg: setting ownertrust to 4
gpg: key 1EB2638FF56C0C53: no user ID for key signature packet of class 10
gpg: key 1EB2638FF56C0C53: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: key 786C63F330D7CB92: no user ID for key signature packet of class 10
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   5  trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: depth: 1  valid:   5  signed:  78  trust: 0-, 0q, 0n, 5m, 0f, 0u
gpg: depth: 2  valid:  73  signed:  24  trust: 73-, 0q, 0n, 0m, 0f, 0u
gpg: next trustdb check due at 2020-05-31
Took 12 seconds.
Pacstrapping into "/tmp/tmpnasd4oes/pacstrap_root/root.x86_64/mnt/arch_root/"...
warning: /mnt/arch_root/etc/resolv.conf installed as /mnt/arch_root/etc/resolv.conf.pacnew
Securing root account at "/tmp/tmpnasd4oes/pacstrap_root/root.x86_64/mnt/arch_root/etc/shadow"...
Unmounting non-disk file systems...
Cleaning up "/tmp/tmpnasd4oes"...
Writing file "/mnt/tmpybcf94kr/etc/hostname"...
Writing file "/mnt/tmpybcf94kr/etc/resolv.conf" (based on file "/etc/resolv.conf")...
Writing file "/mnt/tmpybcf94kr/etc/fstab"...
Running pre-chroot scripts...
Mounting non-disk file systems...
Setting root password...
Unmounting non-disk file systems...
Unmounting partitions...
umount: /mnt/tmpybcf94kr: target is busy.
umount: /mnt/tmpybcf94kr: target is busy.
umount: /mnt/tmpybcf94kr: target is busy.
Removing directory "/mnt/tmpybcf94kr"...
Deactivating partition devices...
Error: a bytes-like object is required, not 'str'
If this looks like a bug to you, please file a report at https://github.com/hartwork/image-bootstrap.  Thank you!

image-bootstrap --password lu4Eph8uir0ooHahxei3 arch $LOOP_DEVICE  33.97s user 7.49s system 47% cpu 1:28.18 total

Unfortunately, this python-ish error doesn't have a stacktrace.

hartwork commented 4 years ago

Hi!

Confirmed, probably a regression from the transition from Python 2 to Python 3. Please try --debug when you need a backtrace next time. For this one I get:

[..]
Traceback (most recent call last):
  File "[..]/image-bootstrap/directory_bootstrap/shared/output_control.py", line 40, in run_handle_errors
    main_function(messenger, options)
  File "[..]/image-bootstrap/image_bootstrap/__main__.py", line 97, in _main__level_three
    bootstrap.run()
  File "[..]/image-bootstrap/image_bootstrap/engine.py", line 944, in run
    self._set_root_password_inside_chroot()
  File "[..]/image-bootstrap/image_bootstrap/engine.py", line 444, in _set_root_password_inside_chroot
    p.stdin.write('root:%s' % self._config.root_password)
TypeError: a bytes-like object is required, not 'str'
Error: a bytes-like object is required, not 'str'
[..]

Let me have a closer look.

hartwork commented 4 years ago

I have pushed a fix now, tagged 2.0.4 in Git, and uploaded 2.0.4 to PyPI. Be sure to use 2.0.4 for Arch to not miss out on this security fix.