Skip to content

Commit

Permalink
Merge pull request canonical#439 from tomponline/latest-candidate
Browse files Browse the repository at this point in the history
More microovn and lxd user setup fixes (latest-candidate)
  • Loading branch information
tomponline authored Apr 24, 2024
2 parents 96b6427 + 6cba913 commit a60a65d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
20 changes: 10 additions & 10 deletions snapcraft/commands/daemon.activate
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ if echo "${SNAP_MODEL}" | grep -q "^lxd-core"; then
exit 0
fi

# Setup the "lxd" user
if ! getent passwd lxd >/dev/null 2>&1; then
echo "==> Creating \"lxd\" user"
if grep -q "^passwd.*extrausers" /var/lib/snapd/hostfs/etc/nsswitch.conf; then
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false --extrausers lxd || true
else
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false lxd || true
fi
fi

# Setup the "lxd" group
if [ "${daemon_group}" = "lxd" ] && ! getent group lxd >/dev/null 2>&1; then
echo "==> Creating \"lxd\" group"
Expand All @@ -79,6 +69,16 @@ if [ "${daemon_group}" = "lxd" ] && ! getent group lxd >/dev/null 2>&1; then
fi
fi

# Setup the "lxd" user
if ! getent passwd lxd >/dev/null 2>&1; then
echo "==> Creating \"lxd\" user"
if grep -q "^passwd.*extrausers" /var/lib/snapd/hostfs/etc/nsswitch.conf; then
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false --gid lxd --extrausers lxd || true
else
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false --gid lxd lxd || true
fi
fi

# Set socket ownership
if getent group "${daemon_group}" >/dev/null 2>&1; then
if [ -e "${SNAP_COMMON}/lxd/unix.socket" ]; then
Expand Down
47 changes: 28 additions & 19 deletions snapcraft/commands/daemon.start
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,6 @@ for entry in dev proc sys; do
mount -o bind "/${entry}" "/var/lib/snapd/hostfs/${entry}"
done

# Setup the "lxd" user
if ! getent passwd lxd >/dev/null 2>&1; then
echo "==> Creating \"lxd\" user"
if grep -q "^passwd.*extrausers" /var/lib/snapd/hostfs/etc/nsswitch.conf; then
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false --extrausers lxd || true
else
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false lxd || true
fi
fi

# Setup the "lxd" group
if [ "${daemon_group}" = "lxd" ] && ! getent group lxd >/dev/null 2>&1; then
echo "==> Creating \"lxd\" group"
Expand All @@ -294,6 +284,16 @@ if [ "${daemon_group}" = "lxd" ] && ! getent group lxd >/dev/null 2>&1; then
fi
fi

# Setup the "lxd" user
if ! getent passwd lxd >/dev/null 2>&1; then
echo "==> Creating \"lxd\" user"
if grep -q "^passwd.*extrausers" /var/lib/snapd/hostfs/etc/nsswitch.conf; then
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false --gid lxd --extrausers lxd || true
else
nsenter -t 1 -m useradd --system -M -N --home "${SNAP_COMMON}/lxd" --shell /bin/false --gid lxd lxd || true
fi
fi

# Setup for ceph
echo "==> Setting up ceph configuration"
if [ "${ceph_builtin:-"false"}" = "true" ]; then
Expand Down Expand Up @@ -321,27 +321,36 @@ sed \
"${SNAP}/etc/lvm/lvm.conf" > /etc/lvm/lvm.conf

# Setup for OVN
echo "==> Cleaning up OVN configuration"
if [ -L /etc/ovn ]; then
echo "=> Removing /etc/ovn symlink"
rm -f /etc/ovn
elif [ -d /etc/ovn ]; then
echo "=> Removing /etc/ovn directory"
rm -rf /etc/ovn
fi

echo "==> Setting up OVN configuration"
if [ "${ovn_builtin:-"false"}" = "true" ]; then
echo "=> Using builtin OVN"
mkdir -p "${SNAP_COMMON}/ovn"
ln -s "${SNAP_COMMON}/ovn" /etc/ovn
elif [ -d "${SNAP_DATA}/microovn/certificates/pki" ]; then
echo "==> Cleaning up OVN configuration"
if [ -L /etc/ovn ]; then
echo "=> Removing /etc/ovn symlink"
rm -f /etc/ovn
elif [ -d /etc/ovn ]; then
echo "=> Removing /etc/ovn directory"
rm -rf /etc/ovn
fi

echo "=> Detected MicroOVN Content Interface"
mkdir -p /etc/ovn
ln -s "${SNAP_DATA}/microovn/certificates/pki/client-cert.pem" /etc/ovn/cert_host
ln -s "${SNAP_DATA}/microovn/certificates/pki/client-privkey.pem" /etc/ovn/key_host
ln -s "${SNAP_DATA}/microovn/certificates/pki/cacert.pem" /etc/ovn/ovn-central.crt
elif [ -d /var/snap/microovn/ ]; then
echo "==> Cleaning up OVN configuration"
if [ -L /etc/ovn ]; then
echo "=> Removing /etc/ovn symlink"
rm -f /etc/ovn
elif [ -d /etc/ovn ]; then
echo "=> Removing /etc/ovn directory"
rm -rf /etc/ovn
fi

echo "=> Detected MicroOVN"
mkdir -p /etc/ovn
ln -s /var/snap/microovn/common/data/pki/client-cert.pem /etc/ovn/cert_host
Expand Down

0 comments on commit a60a65d

Please sign in to comment.