Skip to content

Commit

Permalink
Merge pull request #189 from alexmurray/support-apparmor-unconfined-mode
Browse files Browse the repository at this point in the history
snapcraft/{hooks,commands}: handle new AppArmor unconfined profile mode
  • Loading branch information
tomponline authored Nov 17, 2023
2 parents 6bae0b3 + 1be7337 commit 0fc5dbb
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 16 deletions.
5 changes: 4 additions & 1 deletion snapcraft/commands/buginfo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -u

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Check that we're root
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/daemon.activate
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current 2>/dev/null)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
if ! aa-exec --help >/dev/null 2>&1; then
echo "The LXD snap was unable to run aa-exec, this usually indicates a LXD sideload." >&2
echo "When sideloading, make sure to manually connect all interfaces." >&2
exit 0
fi

exec aa-exec -p unconfined -- "$0" "$@" || true
fi
fi

# shellcheck disable=SC2155
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/daemon.reload
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

echo reload > "${SNAP_COMMON}/state"
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/daemon.start
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

echo "=> Preparing the system (${SNAP_REVISION})"
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/daemon.stop
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

export LXD_DIR="${SNAP_COMMON}/lxd/"
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/lxc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(while read -r l; do echo "$l"; done < /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(while read -r l; do echo "$l"; done < /proc/self/attr/current)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec /usr/bin/aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Check if native and snap installed
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/lxc-to-lxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Check that we're root
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/lxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Check if native and snap installed
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/lxd-benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Check if native and snap installed
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/lxd-check-kernel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

exec lxc-checkconfig
5 changes: 4 additions & 1 deletion snapcraft/commands/lxd-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# shellcheck disable=SC2155
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/commands/lxd-user
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Set the environment
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/hooks/configure
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Utility functions
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/hooks/connect-plug-ceph-conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Utility functions
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/hooks/disconnect-plug-ceph-conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Utility functions
Expand Down
5 changes: 4 additions & 1 deletion snapcraft/hooks/remove
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -eu

# Re-exec outside of apparmor confinement
if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
if [ -d /sys/kernel/security/apparmor ]; then
label="$(cat /proc/self/attr/current 2>/dev/null)"
if [ "$label" != "unconfined" ] && [ -n "${label##*(unconfined)}" ]; then
exec aa-exec -p unconfined -- "$0" "$@"
fi
fi

# Unmount potential LXD paths.
Expand Down

0 comments on commit 0fc5dbb

Please sign in to comment.