Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
34a01c3
save logs
krnowak Sep 11, 2025
6d187f9
overlay coreos/config, profiles: Drop PKG_INSTALL_MASK
krnowak Aug 21, 2025
f22f96d
overlay profiles: Switch to hardened/selinux/systemd profiles
krnowak Apr 23, 2025
62fa16c
sec-policy/selinux-apache: Add from Gentoo
krnowak Sep 18, 2025
4a2618b
sec-policy/selinux-apm: Add from Gentoo
krnowak Sep 18, 2025
9d4ab72
sec-policy/selinux-bind: Add from Gentoo
krnowak Sep 18, 2025
d400f01
sec-policy/selinux-brctl: Add from Gentoo
krnowak Sep 18, 2025
12aedfd
sec-policy/selinux-cdrecord: Add from Gentoo
krnowak Sep 18, 2025
96f51ea
sec-policy/selinux-chronyd: Add from Gentoo
krnowak Sep 18, 2025
dfc34e5
sec-policy/selinux-dirmngr: Add from Gentoo
krnowak Sep 18, 2025
d81da1d
sec-policy/selinux-dnsmasq: Add from Gentoo
krnowak Sep 18, 2025
008b554
sec-policy/selinux-docker: Add from Gentoo
krnowak Sep 18, 2025
6335bc1
sec-policy/selinux-dracut: Add from Gentoo
krnowak Sep 18, 2025
9a33698
sec-policy/selinux-git: Add from Gentoo
krnowak Sep 18, 2025
a315c46
sec-policy/selinux-gpg: Add from Gentoo
krnowak Sep 18, 2025
3809512
sec-policy/selinux-kdump: Add from Gentoo
krnowak Sep 18, 2025
d7134d4
sec-policy/selinux-kerberos: Add from Gentoo
krnowak Sep 18, 2025
b158ccf
sec-policy/selinux-ldap: Add from Gentoo
krnowak Sep 18, 2025
7907e0a
sec-policy/selinux-loadkeys: Add from Gentoo
krnowak Sep 18, 2025
857482e
sec-policy/selinux-logrotate: Add from Gentoo
krnowak Sep 18, 2025
a54fed7
sec-policy/selinux-makewhatis: Add from Gentoo
krnowak Sep 18, 2025
cccc507
sec-policy/selinux-mandb: Add from Gentoo
krnowak Sep 18, 2025
23927ed
sec-policy/selinux-ntp: Add from Gentoo
krnowak Sep 18, 2025
83c964c
sec-policy/selinux-pcscd: Add from Gentoo
krnowak Sep 18, 2025
c8cadc8
sec-policy/selinux-podman: Add from Gentoo
krnowak Sep 18, 2025
52a83b0
sec-policy/selinux-qemu: Add from Gentoo
krnowak Sep 18, 2025
de22150
sec-policy/selinux-quota: Add from Gentoo
krnowak Sep 18, 2025
5e06852
sec-policy/selinux-rpc: Add from Gentoo
krnowak Sep 18, 2025
2c79875
sec-policy/selinux-rpcbind: Add from Gentoo
krnowak Sep 18, 2025
b1fef5a
sec-policy/selinux-samba: Add from Gentoo
krnowak Sep 18, 2025
cd6a98d
sec-policy/selinux-sasl: Add from Gentoo
krnowak Sep 18, 2025
b501162
sec-policy/selinux-smartmon: Add from Gentoo
krnowak Sep 18, 2025
7b54d63
sec-policy/selinux-sudo: Add from Gentoo
krnowak Sep 18, 2025
b438f5d
sec-policy/selinux-tcsd: Add from Gentoo
krnowak Sep 18, 2025
db1c58b
sec-policy/selinux-virt: Add from Gentoo
krnowak Sep 18, 2025
995dde6
sec-policy/selinux-wireguard: Add from Gentoo
krnowak Sep 18, 2025
a6604af
sec-policy/selinux-xfs: Add from Gentoo
krnowak Sep 18, 2025
3d7c66b
sec-policy/selinux-zfs: Add from Gentoo
krnowak Sep 18, 2025
f159c56
overlay coreos/user-patches: Add symlinks for newly added policy pack…
krnowak Apr 23, 2025
3728fbc
.github: Add newly added policy packages to automation
krnowak Apr 23, 2025
d2a2725
overlay profiles: Clean up selinux enabling
krnowak Apr 23, 2025
8c5dcbc
overlay profiles: Mask python and perl USE flags for generic images
krnowak Apr 24, 2025
acc8eea
overlay profiles: Drop enabling caps and audit USE flags for specific…
krnowak Apr 24, 2025
b1d7469
overlay profiles: Disable caps for smartmontools
krnowak Apr 24, 2025
b5767e7
overlay profiles: Allow python for sys-libs/libselinux
krnowak Apr 24, 2025
dca79ab
overlay coreos/config: Add Flatcar modifications for sys-libs/libsema…
krnowak Apr 25, 2025
36b64a7
overlay sys-libs/libsemanage: Move to portage-stable
krnowak Apr 25, 2025
06753b9
sys-libs/libsemanage: Sync with Gentoo
krnowak Jul 1, 2025
def84c0
.github: Add sys-libs/libsemanage to automation
krnowak Apr 25, 2025
1e023ea
overlay sys-apps/policycoreutils: Move to portage-stable
krnowak Apr 29, 2025
d7440f4
sys-apps/policycoreutils: Sync with Gentoo
krnowak Jul 1, 2025
aea1941
.github: Add sys-apps/policycoreutils to automation
krnowak Apr 29, 2025
353a582
overlay coreos/config: Add python stuff to install mask for prod images
krnowak May 8, 2025
5fa47b0
overlay coreos/user-patches: Drop a patch for sys-libs/libsemanage
krnowak May 8, 2025
e79379a
app-admin/setools: Add from Gentoo
krnowak May 8, 2025
a67e6a6
.github: Add app-admin/setools to automation
krnowak May 8, 2025
41dde22
overlay profiles: Do not pull app-admin/setools into prod images
krnowak May 8, 2025
7a271b5
sys-apps/selinux-python: Add from Gentoo
krnowak Jul 1, 2025
769ba5f
.github: Add sys-apps/selinux-python to automation
krnowak May 8, 2025
21a0437
dev-python/networkx: Add from Gentoo
krnowak Jul 1, 2025
2dff979
.github: Add dev-python/networkx to automation
krnowak May 8, 2025
8bb5f7b
overlay coreos/config: Add further modifications to sys-process/audit
krnowak May 8, 2025
9a777b5
overlay profiles: Allow python for sys-process/audit
krnowak May 8, 2025
0b26115
overlay coreos/config: Add further Flatcar modifications for sys-apps…
krnowak May 8, 2025
9c310c8
overlay profiles: Force static-libs on sys-libs/libsepol to fix boots…
krnowak May 9, 2025
a71f3bd
build_toolchain: Do not leak variables
krnowak May 15, 2025
c4edbb1
build_toolchains: Break dep loop and handle more dependencies
krnowak May 13, 2025
9ff39fb
overlay profiles: Move python from package.mask to package.provided f…
krnowak May 19, 2025
ed49d87
build_library: Building selinux policy
krnowak Sep 4, 2025
091eb0d
build_library: Fix pkg_use_enabled
krnowak Sep 4, 2025
e82327a
build_library: Relabel the whole filesystem
krnowak Sep 5, 2025
8303f99
build_sysext: Allow specifying forbidden packages in sysexts
krnowak Sep 5, 2025
8cf915e
build_library: Forbid SELinux policy packages in sysexts
krnowak Sep 5, 2025
7ae093e
overlay coreos-base/coreos: Add more selinux policy packages
krnowak Sep 5, 2025
2ed7d1a
HACK: sys-libs/glibc: Enable selinux even when cross-compiling
krnowak Sep 5, 2025
f965d62
overlay coreos/user-patches: Add a patch for crossdev
krnowak Sep 15, 2025
eeb4351
overlay sys-apps/systemd: Drop selinux-related modifications
krnowak Sep 18, 2025
c5cd156
overlay sys-apps/baselayout: Pull in selinux-related pam changes
krnowak Sep 18, 2025
0955186
build_sysexts: Relabel sysexts too
krnowak Sep 25, 2025
6db87c2
build_sysext: Factor out install root to a variable
krnowak Sep 26, 2025
f0d5e04
overlay coreos/user-patches: Update patch for selinux policies
krnowak Sep 30, 2025
ba63e26
selinux stuff
krnowak Sep 30, 2025
d40a3bb
fix
krnowak Oct 2, 2025
28bea0e
overlay sys-apps/systemd: Drop selinux disabling patch again
krnowak Oct 8, 2025
56f881e
build_library/extra_sysexts.sh: Sort entries
krnowak Oct 8, 2025
1dc4cc9
build_library/extra_sysexts.sh: Add selinux sysext
krnowak Oct 8, 2025
eeb01ce
overlay coreos/user-patches: Update refpolicy patch
krnowak Oct 8, 2025
7cf6346
overlay profiles: Build only the mcs SELinux policy
krnowak Oct 8, 2025
24d8f9a
fix
krnowak Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -73,6 +73,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 @@ -335,6 +336,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 @@ -569,13 +571,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 @@ -617,10 +654,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 @@ -697,6 +736,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
8 changes: 7 additions & 1 deletion bootstrap_sdk_container
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ source sdk_lib/sdk_container_common.sh

seed_version=""
target_version=""
logdir=''

declare -a cleanup

Expand All @@ -30,6 +31,7 @@ usage() {
echo " -x <cleanup-script> - For each resource generated during build (container etc.)"
echo " add a cleanup line to <script> which, when run, will free"
echo " the resource. Useful for CI."
echo " -l <directory> - Gather build logs here."
echo " -h - Print this help."
echo
}
Expand All @@ -38,6 +40,7 @@ usage() {
while [ 0 -lt $# ] ; do
case "$1" in
-h) usage; exit 0;;
-l) logdir=${2}; shift 2;;
-x) cleanup=("-x" "$2"); shift; shift;;
*) if [ -z "$seed_version" ] ; then
seed_version="$1"
Expand Down Expand Up @@ -72,8 +75,11 @@ if $official; then
fi

# bootstrap_sdk needs FLATCAR_SDK_VERSION set to the seed version
failed=''
./run_sdk_container "${cleanup[@]}" -V "$seed_version" -v "$target_version" \
sudo -E ./bootstrap_sdk
sudo -E ./bootstrap_sdk || failed=x

# Update versionfile to the actual SDK version
create_versionfile "${target_version}"

if [[ -n ${failed} ]]; then exit 1; fi
11 changes: 0 additions & 11 deletions build_library/board_options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ ARCH=$(get_board_arch ${BOARD})
# What cross-build are we targeting?
. "${BOARD_ROOT}/etc/portage/make.conf" || die

# check if any of the given use flags are enabled for a pkg
pkg_use_enabled() {
local pkg="$1"
shift
# for every flag argument, turn it into `-e ^+flag` for grep
local grep_args="${@/#/-e ^+}"

equery-"${BOARD}" -q uses "${pkg}" | grep -q ${grep_args}
return $?
}

# Usage: pkg_version [installed|binary|ebuild] some-pkg/name
# Prints: some-pkg/name-1.2.3
# Note: returns 0 even if the package was not found.
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
}
30 changes: 22 additions & 8 deletions build_library/build_image_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fi
BUILD_DIR="${FLAGS_output_root}/${BOARD}/${IMAGE_SUBDIR}"
OUTSIDE_OUTPUT_DIR="../build/images/${BOARD}/${IMAGE_SUBDIR}"

source "${BUILD_LIBRARY_DIR}/pkg_util.sh" || exit 1
source "${BUILD_LIBRARY_DIR}/reports_util.sh" || exit 1
source "${BUILD_LIBRARY_DIR}/sbsign_util.sh" || exit 1

Expand Down Expand Up @@ -683,8 +684,13 @@ EOF
fi

# Build the selinux policy
if pkg_use_enabled coreos-base/coreos selinux; then
sudo chroot "${root_fs_dir}" bash -c "cd /usr/share/selinux/mcs && semodule -s mcs -i *.pp"
if is_selinux_enabled "${BOARD}"; then
info "Building selinux mcs policy"
sudo chroot "${root_fs_dir}" bash -s <<'EOF'
cd /usr/share/selinux/mcs
set -x
semodule -s mcs -i *.pp
EOF
fi

# Run tmpfiles once to make sure that /etc has everything in place before
Expand Down Expand Up @@ -718,12 +724,20 @@ EOF
# SELinux: Label the root filesystem for using 'file_contexts'.
# The labeling has to be done before moving /etc to /usr/share/flatcar/etc to prevent wrong labels for these files and as
# the relabeling on boot would cause upcopies in the overlay.
if pkg_use_enabled coreos-base/coreos selinux; then
# TODO: Breaks the system:
# sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"
# sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"/usr
# For now we only try it with /etc
sudo setfiles -Dv -r "${root_fs_dir}" "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}"/etc
if is_selinux_enabled "${BOARD}"; then
# -D - set or update any directory SHA1 digests
# -E - treat conflicting specifications as errors
# -F - force reset of context to match file_context
# -r path - set root path
# -v - show changes in file labels
# -T 0 - use as many threads as there are cores
info "Relabeling the filesystem at ${root_fs_dir@Q}"
local path
# We do not run relabeling on /boot, it's FAT anyway, so no
# support for xattrs there.
for path in / /usr /oem; do
sudo setfiles -D -E -F -r "${root_fs_dir}" -v -T 0 "${root_fs_dir}"/etc/selinux/mcs/contexts/files/file_contexts "${root_fs_dir}${path}"
done
fi

# Backup the /etc contents to /usr/share/flatcar/etc to serve as
Expand Down
Loading