freebsd-src/release/tools/oci.conf
Colin Percival 0b1c5628c7 release: Rework vm_extra_pre_umount
The vm_extra_pre_umount function in vmimage.subr served two purposes:
It removed /etc/resolv.conf and /qemu (if cross-building), and it
provided a function for cloudware to override in order to make cloud
specific changes to the filesystem before constructing a disk image.

This resulted in a number of bugs:
1. When cross-building, the emulator binary was left as /qemu in the
Azure, GCE, Openstack and Vagrant images.
2. The build host's resolv.conf was left as /etc/resolv.conf in the
basic-ci and basic-cloudinit images.
3. When building GCE images, a Google-specific resolv.conf file was
constructed, and then deleted before the disk image was created.

Move the bits needed for running code inside a VM staging directory
from vm_install_base into a new vm_emulation_setup routine, and move
the corresponding cleanup bits from vm_extra_pre_umount to a new
vm_emulation_cleanup routine.

Remove the /qemu and /etc/resolv.conf cleanups from the cloudware
configuration files (where they exist) since we will now be running
vm_emulation_cleanup to remove those even when vm_extra_pre_umount
has been overridden.

Override vm_emulation_cleanup in gce.conf since in that one case (and
*only* that one case) we don't want to clean up resolv.conf (since it
was constructed for the VM image rather than copied from the host).

releng/14.1 candidate.

MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
2024-05-06 13:40:47 -07:00

95 lines
2.1 KiB
Bash

#!/bin/sh
# Set to a list of packages to install.
export VM_EXTRA_PACKAGES="
comms/py-pyserial
converters/base64
devel/oci-cli
devel/py-babel
devel/py-iso8601
devel/py-pbr
devel/py-six
ftp/curl
lang/python
lang/python3
net/cloud-init
net/py-eventlet
net/py-netaddr
net/py-netifaces
net/py-oauth
net/rsync
panicmail
security/ca_root_nss
security/sudo
sysutils/firstboot-freebsd-update
sysutils/firstboot-pkgs
sysutils/panicmail
textproc/jq
"
# Should be enough for base image, image can be resized in needed
export VMSIZE=6g
# Set to a list of third-party software to enable in rc.conf(5).
export VM_RC_LIST="
cloudinit
firstboot_pkgs
firstboot_freebsd_update
growfs
ntpd
ntpd_sync_on_start
sshd
zfs"
vm_extra_pre_umount() {
cat <<-'EOF' >> ${DESTDIR}/etc/rc.conf
dumpdev=AUTO
sendmail_enable=NONE
EOF
cat <<-'EOF' >> ${DESTDIR}/boot/loader.conf
autoboot_delay="5"
beastie_disable="YES"
boot_serial="YES"
loader_logo="none"
cryptodev_load="YES"
opensolaris_load="YES"
xz_load="YES"
zfs_load="YES"
EOF
cat <<-'EOF' >> ${DESTDIR}/etc/ssh/sshd_config
# S11 Configure the SSH service to prevent password-based login
PermitRootLogin prohibit-password
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitEmptyPasswords no
UseDNS no
EOF
# S14 Root user login must be disabled on serial-over-ssh console
pw -R ${DESTDIR} usermod root -w no
# OCI requirements override the default FreeBSD cloud-init settings
cat <<-'EOF' >> ${DESTDIR}/usr/local/etc/cloud/cloud.cfg.d/98_oci.cfg
disable_root: true
system_info:
distro: freebsd
default_user:
name: freebsd
lock_passwd: True
gecos: "OCI Default User"
groups: [wheel]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/sh
network:
renderers: ['freebsd']
EOF
# Use Oracle Cloud Infrastructure NTP server
sed -i '' -E -e 's/^pool.*iburst/server 169.254.169.254 iburst/' \
${DESTDIR}/etc/ntp.conf
touch ${DESTDIR}/firstboot
return 0
}