Skip to content

Increase selinux coverage of the host system #2849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 67 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7687b71
overlay profiles: Switch to hardened/selinux/systemd profiles
krnowak Apr 23, 2025
2b8b30f
sec-policy/selinux-apache: Add from Gentoo
krnowak Apr 24, 2025
4b13121
sec-policy/selinux-apm: Add from Gentoo
krnowak Apr 23, 2025
1736aeb
sec-policy/selinux-bind: Add from Gentoo
krnowak Apr 23, 2025
a1d60e8
sec-policy/selinux-brctl: Add from Gentoo
krnowak Apr 23, 2025
a739758
sec-policy/selinux-cdrecord: Add from Gentoo
krnowak Apr 23, 2025
4714f2c
sec-policy/selinux-chronyd: Add from Gentoo
krnowak Apr 23, 2025
71fd2cb
sec-policy/selinux-dirmngr: Add from Gentoo
krnowak Apr 24, 2025
4d9b6fb
sec-policy/selinux-dnsmasq: Add from Gentoo
krnowak Apr 23, 2025
0cfbd9a
sec-policy/selinux-docker: Add from Gentoo
krnowak Apr 23, 2025
92934ff
sec-policy/selinux-dracut: Add from Gentoo
krnowak Apr 23, 2025
ba3dd9e
sec-policy/selinux-git: Add from Gentoo
krnowak Apr 23, 2025
130d7c5
sec-policy/selinux-gpg: Add from Gentoo
krnowak Apr 23, 2025
a2a3d10
sec-policy/selinux-kdump: Add from Gentoo
krnowak Apr 23, 2025
7998702
sec-policy/selinux-kerberos: Add from Gentoo
krnowak Apr 23, 2025
669fd52
sec-policy/selinux-ldap: Add from Gentoo
krnowak Apr 23, 2025
dd005dd
sec-policy/selinux-loadkeys: Add from Gentoo
krnowak Apr 23, 2025
9f6309c
sec-policy/selinux-logrotate: Add from Gentoo
krnowak Apr 23, 2025
80fbbcb
sec-policy/selinux-makewhatis: Add from Gentoo
krnowak Apr 23, 2025
eda84d9
sec-policy/selinux-mandb: Add from Gentoo
krnowak Apr 23, 2025
7902136
sec-policy/selinux-ntp: Add from Gentoo
krnowak Apr 23, 2025
699e108
sec-policy/selinux-pcscd: Add from Gentoo
krnowak Apr 23, 2025
979e163
sec-policy/selinux-podman: Add from Gentoo
krnowak Apr 23, 2025
d817723
sec-policy/selinux-qemu: Add from Gentoo
krnowak Apr 23, 2025
56122d0
sec-policy/selinux-quota: Add from Gentoo
krnowak Apr 23, 2025
7defefc
sec-policy/selinux-rpc: Add from Gentoo
krnowak Apr 23, 2025
f7a18f0
sec-policy/selinux-rpcbind: Add from Gentoo
krnowak Apr 23, 2025
c7c8162
sec-policy/selinux-samba: Add from Gentoo
krnowak Apr 23, 2025
d2573cc
sec-policy/selinux-sasl: Add from Gentoo
krnowak Apr 23, 2025
94f4ca9
sec-policy/selinux-smartmon: Add from Gentoo
krnowak Apr 23, 2025
2fc0b69
sec-policy/selinux-sudo: Add from Gentoo
krnowak Apr 23, 2025
e93e9cb
sec-policy/selinux-tcsd: Add from Gentoo
krnowak Apr 23, 2025
7bba878
sec-policy/selinux-virt: Add from Gentoo
krnowak Apr 24, 2025
c8beb11
sec-policy/selinux-wireguard: Add from Gentoo
krnowak Apr 23, 2025
beb7080
sec-policy/selinux-xfs: Add from Gentoo
krnowak Apr 23, 2025
5466952
sec-policy/selinux-zfs: Add from Gentoo
krnowak Apr 23, 2025
2bd97f4
overlay coreos/user-patches: Add symlinks for newly added policy pack…
krnowak Apr 23, 2025
6d2f857
.github: Add newly added policy packages to automation
krnowak Apr 23, 2025
1d068d3
overlay profiles: Clean up selinux enabling
krnowak Apr 23, 2025
b3bd533
overlay profiles: Mask python and perl USE flags for generic images
krnowak Apr 24, 2025
d3c0c93
overlay profiles: Drop enabling caps and audit USE flags for specific…
krnowak Apr 24, 2025
f67f2e3
overlay profiles: Disable caps for smartmontools
krnowak Apr 24, 2025
c17c79d
overlay profiles: Allow python for sys-libs/libselinux
krnowak Apr 24, 2025
ca215ff
overlay coreos/config: Add Flatcar modifications for sys-libs/libsema…
krnowak Apr 25, 2025
17ea2bf
overlay sys-libs/libsemanage: Move to portage-stable
krnowak Apr 25, 2025
ec4ac1f
sys-libs/libsemanage: Sync with Gentoo
krnowak Apr 25, 2025
4c21a11
.github: Add sys-libs/libsemanage to automation
krnowak Apr 25, 2025
df0677b
overlay sys-apps/policycoreutils: Move to portage-stable
krnowak Apr 29, 2025
7df32ef
sys-apps/policycoreutils: Sync with Gentoo
krnowak Apr 29, 2025
9c51a70
.github: Add sys-apps/policycoreutils to automation
krnowak Apr 29, 2025
b431a3f
overlay profiles: Add FLATCAR_{TYPE,SUBTYPE} variables
krnowak Apr 30, 2025
b607ec2
overlay: Replace cros_target with new variables
krnowak Apr 30, 2025
37db0d8
overlay coreos/config: Add python stuff to install mask for prod images
krnowak May 8, 2025
8a3cf7e
overlay coreos/user-patches: Drop a patch for sys-libs/libsemanage
krnowak May 8, 2025
efad8a7
app-admin/setools: Add from Gentoo
krnowak May 8, 2025
38931a2
.github: Add app-admin/setools to automation
krnowak May 8, 2025
8f7d61d
overlay profiles: Do not pull app-admin/setools into prod images
krnowak May 8, 2025
2276b61
sys-apps/selinux-python: Add from Gentoo
krnowak May 8, 2025
1abdba6
.github: Add sys-apps/selinux-python to automation
krnowak May 8, 2025
1f37cd9
dev-python/networkx: Add from Gentoo
krnowak May 8, 2025
699f600
.github: Add dev-python/networkx to automation
krnowak May 8, 2025
a929ce9
overlay coreos/config: Add further modifications to sys-process/audit
krnowak May 8, 2025
a292cde
overlay profiles: Allow python for sys-process/audit
krnowak May 8, 2025
09fce97
overlay coreos/config: Add further Flatcar modifications for sys-apps…
krnowak May 8, 2025
fc92672
overlay profiles: Force static-libs on sys-libs/libsepol to fix boots…
krnowak May 9, 2025
99d44ca
build_toolchain: Do not leak variables
krnowak May 15, 2025
4e5c37e
build_toolchains: Break dep loop and handle more dependencies
krnowak May 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
40 changes: 40 additions & 0 deletions .github/workflows/portage-stable-packages-list
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ acct-user/tss
app-admin/eselect
app-admin/logrotate
app-admin/perl-cleaner
app-admin/setools
app-admin/sudo

app-alternatives/awk
Expand Down Expand Up @@ -325,6 +326,7 @@ dev-python/markupsafe
dev-python/mdurl
dev-python/more-itertools
dev-python/msgpack
dev-python/networkx
dev-python/olefile
dev-python/packaging
dev-python/pathspec
Expand Down Expand Up @@ -555,13 +557,48 @@ scripts

sec-keys/openpgp-keys-gentoo-release

sec-policy/selinux-apache
sec-policy/selinux-apm
sec-policy/selinux-base
sec-policy/selinux-base-policy
sec-policy/selinux-bind
sec-policy/selinux-brctl
sec-policy/selinux-cdrecord
sec-policy/selinux-chronyd
sec-policy/selinux-container
sec-policy/selinux-dbus
sec-policy/selinux-dirmngr
sec-policy/selinux-dnsmasq
sec-policy/selinux-docker
sec-policy/selinux-dracut
sec-policy/selinux-git
sec-policy/selinux-gpg
sec-policy/selinux-kdump
sec-policy/selinux-kerberos
sec-policy/selinux-ldap
sec-policy/selinux-loadkeys
sec-policy/selinux-logrotate
sec-policy/selinux-makewhatis
sec-policy/selinux-mandb
sec-policy/selinux-ntp
sec-policy/selinux-pcscd
sec-policy/selinux-podman
sec-policy/selinux-policykit
sec-policy/selinux-qemu
sec-policy/selinux-quota
sec-policy/selinux-rpc
sec-policy/selinux-rpcbind
sec-policy/selinux-samba
sec-policy/selinux-sasl
sec-policy/selinux-smartmon
sec-policy/selinux-sssd
sec-policy/selinux-sudo
sec-policy/selinux-tcsd
sec-policy/selinux-unconfined
sec-policy/selinux-virt
sec-policy/selinux-wireguard
sec-policy/selinux-xfs
sec-policy/selinux-zfs

sys-apps/acl
sys-apps/attr
Expand Down Expand Up @@ -603,10 +640,12 @@ sys-apps/nvme-cli
sys-apps/pciutils
sys-apps/pcsc-lite
sys-apps/pkgcore
sys-apps/policycoreutils
sys-apps/portage
sys-apps/pv
sys-apps/sandbox
sys-apps/sed
sys-apps/selinux-python
sys-apps/semodule-utils
sys-apps/shadow
sys-apps/smartmontools
Expand Down Expand Up @@ -681,6 +720,7 @@ sys-libs/libcap-ng
sys-libs/libnvme
sys-libs/libseccomp
sys-libs/libselinux
sys-libs/libsemanage
sys-libs/libsepol
sys-libs/libunwind
sys-libs/liburing
Expand Down
137 changes: 137 additions & 0 deletions build_library/break_dep_loop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Goo to attempt to resolve dependency loops on individual packages.
# If this becomes insufficient we will need to move to a full multi-stage
# bootstrap process like we do with the SDK via catalyst.
#
# Called like:
#
# break_dep_loop [-v] [PKG_USE_PAIR]…
#
# Pass -v for verbose output.
#
# PKG_USE_PAIR consists of two arguments: a package name (for example:
# sys-fs/lvm2), and a comma-separated list of USE flags to clear (for
# example: udev,systemd).
#
# Env vars:
#
# BDL_ROOT, BDL_PORTAGEQ, BDL_EQUERY, BDL_EMERGE, BDL_INFO
break_dep_loop() {
local bdl_root=${BDL_ROOT:-/}
local bdl_portageq=${BDL_PORTAGEQ:-portageq}
local bdl_equery=${BDL_EQUERY:-equery}
local bdl_emerge=${BDL_EMERGE:-emerge}
local bdl_info=${BDL_INFO:-echo}
local conf_dir="${bdl_root%/}/etc/portage"
local flag_file="${conf_dir}/package.use/break_dep_loop"
local force_flag_file="${conf_dir}/profile/package.use.force/break_dep_loop"

local verbose=
if [[ ${1:-} = '-v' ]]; then
verbose=x
shift
fi

# Be sure to clean up use flag hackery from previous failed runs
sudo rm -f "${flag_file}" "${force_flag_file}"

if [[ ${#} -eq 0 ]]; then
return 0
fi

function bdl_call() {
local output_var_name=${1}; shift
if [[ ${output_var_name} = '-' ]]; then
local throw_away
output_var_name=throw_away
fi
local -n output_ref=${output_var_name}
if [[ -n ${verbose} ]]; then
"${bdl_info}" "${*@Q}"
fi
local -i rv=0
output_ref=$("${@}") || rv=${?}
if [[ -n ${verbose} ]]; then
"${bdl_info}" "output: ${output_ref}"
"${bdl_info}" "exit status: ${rv}"
fi
return ${rv}
}

# Temporarily compile/install packages with flags disabled. If a binary
# package is available use it regardless of its version or use flags.
local pkg use_flags disabled_flags
local -a flags
local -a pkgs args flag_file_entries pkg_summaries
local -A per_pkg_flags=()
while [[ $# -gt 1 ]]; do
pkg=${1}
use_flags=${2}
shift 2

mapfile -t flags <<<"${use_flags//,/$'\n'}"
disabled_flags="${flags[*]/#/-}"

pkgs+=( "${pkg}" )
per_pkg_flags["${pkg}"]=${use_flags}
flag_file_entries+=( "${pkg} ${disabled_flags}" )
args+=( "--buildpkg-exclude=${pkg}" )
pkg_summaries+=( "${pkg}[${disabled_flags}]" )
done
unset pkg use_flags disabled_flags flags

# If packages are already installed we have nothing to do
local pkg any_package_uninstalled=
for pkg in "${pkgs[@]}"; do
if ! bdl_call - "${bdl_portageq}" has_version "${bdl_root}" "${pkg}"; then
any_package_uninstalled=x
break
fi
done
if [[ -z ${any_package_uninstalled} ]]; then
if [[ -n ${verbose} ]]; then
"${bdl_info}" "all packages (${pkgs[*]}) are installed already, skipping"
fi
return 0
fi
unset pkg any_package_uninstalled

# Likewise, nothing to do if the flags aren't actually enabled.
local pkg any_flag_enabled= equery_output flag flags_str
local -a flags grep_args
for pkg in "${pkgs[@]}"; do
bdl_call equery_output "${bdl_equery}" -q uses "${pkg}"
flags_str=${per_pkg_flags["${pkg}"]}
mapfile -t flags <<<"${flags_str//,/$'\n'}"
for flag in "${flags[@]}"; do
grep_args+=( -e "${flag/#/+}" )
done
if bdl_call - grep --quiet --line-regexp --fixed-strings "${grep_args[@]}" <<<"${equery_output}"; then
any_flag_enabled=x
break
fi
done
if [[ -z ${any_flag_enabled} ]]; then
if [[ -n ${verbose} ]]; then
"${bdl_info}" "all packages (${pkgs[*]}) has all the desired USE flags already disabled, skipping"
fi
return 0
fi
unset pkg any_flag_enabled equery_output flag flags_str flags grep_args

"${bdl_info}" "Merging ${pkg_summaries[*]}"
sudo mkdir -p "${flag_file%/*}" "${force_flag_file%/*}"
printf '%s\n' "${flag_file_entries[@]}" | sudo tee "${flag_file}" >/dev/null
cp -a "${flag_file}" "${force_flag_file}"
if [[ -n ${verbose} ]]; then
"${bdl_info}" "contents of ${flag_file@Q}:"
"${bdl_info}" "$(<"${flag_file}")"
"${bdl_info}" "${bdl_emerge}" --rebuild-if-unbuilt=n "${args[@]}" "${pkgs[@]}"
fi
# rebuild-if-unbuilt is disabled to prevent portage from needlessly
# rebuilding zlib for some unknown reason, in turn triggering more rebuilds.
"${bdl_emerge}" \
--rebuild-if-unbuilt=n \
"${args[@]}" "${pkgs[@]}"
sudo rm -f "${flag_file}" "${force_flag_file}"
unset bdl_call
}
77 changes: 71 additions & 6 deletions build_library/catalyst_toolchains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e
source /tmp/chroot-functions.sh
source /tmp/toolchain_util.sh
source /tmp/break_dep_loop.sh

# A note on packages:
# The default PKGDIR is /usr/portage/packages
Expand All @@ -28,13 +29,77 @@ build_target_toolchain() {
local ROOT="/build/${board}"
local SYSROOT="/usr/$(get_board_chost "${board}")"

mkdir -p "${ROOT}/usr"
cp -at "${ROOT}" "${SYSROOT}"/lib*
cp -at "${ROOT}"/usr "${SYSROOT}"/usr/include "${SYSROOT}"/usr/lib*
function btt_emerge() {
# --root is required because run_merge overrides ROOT=
PORTAGE_CONFIGROOT="$ROOT" run_merge --root="$ROOT" --sysroot="$ROOT" "${@}"
}

# --root is required because run_merge overrides ROOT=
PORTAGE_CONFIGROOT="$ROOT" \
run_merge -u --root="$ROOT" --sysroot="$ROOT" "${TOOLCHAIN_PKGS[@]}"
# install baselayout first - with the selinux profile, this is
# pulled into the dependency chain
btt_emerge --oneshot --nodeps sys-apps/baselayout

# copy libraries from sysroot to root - sysroot seems to be
# split-usr, whereas root does not, so take this into account
(
shopt -s nullglob
local d f
local -a files
for d in "${SYSROOT}"/lib* "${SYSROOT}"/usr/lib*; do
if [[ ! -d ${d} ]]; then
continue
fi
files=( "${d}"/* )
if [[ ${#files[@]} -gt 0 ]]; then
f=${d##*/}
cp -at "${ROOT}/usr/${f}" "${files[@]}"
fi
done
)
cp -at "${ROOT}"/usr "${SYSROOT}"/usr/include

local -a args_for_bdl=()
if [[ -n ${clst_VERBOSE} ]]; then
args_for_bdl+=(-v)
fi
function btt_bdl_portageq() {
ROOT=${ROOT} SYSROOT=${ROOT} PORTAGE_CONFIGROOT=${ROOT} portageq "${@}"
}
function btt_bdl_equery() {
ROOT=${ROOT} SYSROOT=${ROOT} PORTAGE_CONFIGROOT=${ROOT} equery "${@}"
}
# Breaking the following loops here:
#
# glibc[nscd] -> libcap[pam] -> sys-libs/pam -> libcrypt -> libxcrypt[system] -> glibc
# glibc[nscd] -> audit[python] -> python -> libcrypt -> libxcrypt[system] -> glibc
# glibc[selinux] -> libselinux[python] -> python -> libcrypt -> libxcrypt[system] -> glibc
# systemd[cryptsetup] -> cryptsetup[udev] -> libudev[systemd] -> systemd
# systemd[cryptsetup] -> cryptsetup -> lvm2[udev] -> libudev[systemd] -> systemd
# systemd[cryptsetup] -> cryptsetup -> lvm2[lvm,systemd] -> systemd
# systemd[cryptsetup] -> cryptsetup -> tmpfiles[systemd] -> systemd
# systemd[curl] -> curl -> nghttp2[systemd] -> systemd
# importd requires curl, so needs to be disabled too
# systemd[tpm] -> tpm2-tss -> tmpfiles[systemd] -> systemd
# util-linux[audit] -> audit[python] -> python -> util-linux
# util-linux[cryptsetup] -> cryptsetup -> util-linux
# util-linux[pam] -> sys-libs/pam[audit] -> sys-process/audit[python] -> python -> util-linux
# su requires pam, so needs to be disabled too
# util-linux[selinux] -> libselinux[python] -> python -> util-linux
# util-linux[systemd] -> systemd -> util-linux
# util-linux[udev] -> libudev[systemd] -> systemd -> util-linux
args_for_bdl+=(
sys-apps/systemd cryptsetup,curl,importd,tpm
sys-apps/util-linux audit,cryptsetup,pam,selinux,su,systemd,udev
sys-libs/glibc nscd,selinux
)
BDL_ROOT=${ROOT} \
BDL_PORTAGEQ=btt_bdl_portageq \
BDL_EQUERY=btt_bdl_equery \
BDL_EMERGE=btt_emerge \
break_dep_loop "${args_for_bdl[@]}"
unset btt_bdl_portageq btt_bdl_equery

btt_emerge --changed-use --update --deep "${TOOLCHAIN_PKGS[@]}"
unset btt_emerge
}

configure_crossdev_overlay / /usr/local/portage/crossdev
Expand Down
Loading