bsd-cloudinit icon indicating copy to clipboard operation
bsd-cloudinit copied to clipboard

Problem with python on FreeBSD 12 RC1

Open fredericalix opened this issue 7 years ago • 10 comments

When cloudbaseinit run, python crash with this log stack.

Starting local daemons:2018-11-22 00:02:29.890 673 CRITICAL cloudbaseinit [-] AttributeError: Undefined symbol "ERR_load_crypto_strings" 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit Traceback (most recent call last): 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/run.py", line 3, in 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit shell.main() 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/cloudbaseinit/shell.py", line 29, in main 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit init.InitManager().configure_host() 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/cloudbaseinit/init.py", line 107, in configure_host 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit plugins = plugins_factory.load_plugins() 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/cloudbaseinit/plugins/common/factory.py", line 45, in load_plugins 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit plugins.append(cl.load_class(class_path)()) 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/cloudbaseinit/utils/classloader.py", line 28, in load_class 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit module = import(parts[0], fromlist=parts[1]) 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/cloudbaseinit/plugins/freebsd/setuserpassword.py", line 25, in 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit from cloudbaseinit.utils import crypt 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/root/bsd-cloudinit/cloudbaseinit/utils/crypt.py", line 89, in 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit openssl.ERR_load_crypto_strings.restype = ctypes.c_int 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/usr/local/lib/python2.7/ctypes/init.py", line 379, in getattr 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit func = self.getitem(name) 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit File "/usr/local/lib/python2.7/ctypes/init.py", line 384, in getitem 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit func = self._FuncPtr((name_or_ordinal, self)) 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit AttributeError: Undefined symbol "ERR_load_crypto_strings" 2018-11-22 00:02:29.890 673 TRACE cloudbaseinit

fredericalix avatar Nov 21 '18 23:11 fredericalix

Confirming the same issue also with 12 released two days ago.

livenson avatar Dec 19 '18 19:12 livenson

#!/bin/csh #bsd-cloudinit workaround

#usage #echo /root/bsd-cloudinit >> /etc/rc.local #chmod u+x /root/bsd-cloudinit

set PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin export $PATH

#disk_resize gpart recover vtbd0 gpart resize -i 2 vtbd0 growfs -y vtbd0p2

#set passwordless sudo echo 'freebsd ALL=(ALL) NOPASSWD: ALL' > /usr/local/etc/sudoers.d/10-cloudinit

#set_key fetch http://169.254.169.254/openstack/latest/meta_data.json -q -o - | jq -r '.keys[] |.data' > /home/freebsd/.ssh/authorized_keys

#set_hostname set fqdn=fetch http://169.254.169.254/openstack/latest/meta_data.json -q -o - | jq '.hostname' | sed 's/.novalocal//g' sed -i "" "s/hostname.*/hostname=$fqdn/g" /etc/rc.conf hostname echo $fqdn | tr -d '"'

#set root passwd pw mod user root -w random > /dev/null

#run userdata fetch http://169.254.169.254/latest/user-data -q -o - | sh

#make clean set history = 0 ssh-keygen -A

#do Cheshire Cat sed -i "" "s/.*bsd-cloudinit//g" /etc/rc.local rm -f /root/bsd-cloudinit

h5t4 avatar Dec 31 '18 10:12 h5t4

This is almost certainly due to FreeBSD 12 using OpenSSL 1.1.1. ERR_load_crypto_strings is deprecated:

https://www.openssl.org/docs/man1.1.1/man3/SSL_load_error_strings.html

I'm not clued up enough on OpenSSL to propose a fix though. But I do note the same issue exists in the original cloudbase-init, so maybe it'll get fixed there at some point:

https://github.com/openstack/cloudbase-init/blob/master/cloudbaseinit/utils/crypt.py

tdb avatar Jan 18 '19 22:01 tdb

After install bsd-cloudinit:

  1. Install OpenSSL1.0.2 on /usr/ports/security/openssl port
  2. Edit this file: /root/bsd-cloudinit/cloudbaseinit/utils/crypt.py Replace openssl_lib_path = ctypes.util.find_library("ssl") by openssl_lib_path = "/usr/local/lib/libssl.so" Finish

tuanvu958 avatar Jul 04 '19 08:07 tuanvu958

Maybe this fix for cloudbase-init will help?

https://github.com/cloudbase/cloudbase-init/commit/a2434e40e0938f120b8c26fee084143c7896dc10

tdb avatar Jul 04 '19 09:07 tdb

@tdb I tried it, but could not create the freebsd user and could not expand the hard disk capacity when start instance

tuanvu958 avatar Jul 05 '19 01:07 tuanvu958

@h5t4 Thank you very much this one helped!

I added a few improvements:

#!/bin/csh
#bsd-cloudinit workaround

#usage
#echo /root/bsd-cloudinit >> /etc/rc.local
#chmod u+x /root/bsd-cloudinit

set PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
export $PATH

#disk_resize
gpart recover vtbd0
gpart resize -i 2 vtbd0
growfs -y vtbd0p2

#install needed packages
export ASSUME_ALWAYS_YES=yes
pkg install sudo jq 

#create freebsd user
pw useradd -n freebsd || true

#create home directory and .ssh
mkdir -p /home/freebsd/.ssh/
chown -R freebsd:freebsd /home/freebsd

#set passwordless sudo
echo 'freebsd ALL=(ALL) NOPASSWD: ALL' > /usr/local/etc/sudoers.d/10-cloudinit

#set_key
fetch http://169.254.169.254/openstack/latest/meta_data.json -q -o - | jq -r '.keys[] |.data' > /home/freebsd/.ssh/authorized_keys

#set_hostname
set fqdn=`fetch http://169.254.169.254/openstack/latest/meta_data.json -q -o - | jq '.hostname' | sed 's/.novalocal//g'`
sed -i "" "s/hostname.*/hostname=$fqdn/g" /etc/rc.conf
hostname `echo $fqdn | tr -d '"'`

#set root passwd
pw mod user root -w random > /dev/null

#run userdata
fetch http://169.254.169.254/latest/user-data -q -o - | sh

#make clean
set history = 0
ssh-keygen -A

#do Cheshire Cat
sed -i "" "s/.*bsd-cloudinit//g" /etc/rc.local
rm -f /root/bsd-cloudinit

br-olf avatar May 28 '20 15:05 br-olf

Hi, @br-olf How should I use this script? where should I put it if I want to make a cloud template image for OpenStack?

EhsanSaZ avatar Nov 09 '20 10:11 EhsanSaZ

root@hack:/ # head -n 3 /root/bsd-cloudinit #!/bin/csh #bsd-cloudinit workaround

h5t4 avatar Nov 09 '20 15:11 h5t4

@EhsanSaZ copy the script to the file /root/bsd-cloudinit and look at line 4-6 in the script ;-)

br-olf avatar Nov 13 '20 15:11 br-olf