Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
3ae2151
save logs
krnowak Sep 11, 2025
07f426b
overlay coreos/config, profiles: Drop PKG_INSTALL_MASK
krnowak Aug 21, 2025
69421f5
overlay profiles: Switch to hardened/selinux/systemd profiles
krnowak Apr 23, 2025
3428ec3
sec-policy/selinux-apache: Add from Gentoo
krnowak Sep 18, 2025
5ac9f0b
sec-policy/selinux-apm: Add from Gentoo
krnowak Sep 18, 2025
4417ab7
sec-policy/selinux-bind: Add from Gentoo
krnowak Sep 18, 2025
77902d5
sec-policy/selinux-brctl: Add from Gentoo
krnowak Sep 18, 2025
aef7287
sec-policy/selinux-cdrecord: Add from Gentoo
krnowak Sep 18, 2025
f8ec5b0
sec-policy/selinux-chronyd: Add from Gentoo
krnowak Sep 18, 2025
cacc78d
sec-policy/selinux-dirmngr: Add from Gentoo
krnowak Sep 18, 2025
6c72429
sec-policy/selinux-dnsmasq: Add from Gentoo
krnowak Sep 18, 2025
082f732
sec-policy/selinux-docker: Add from Gentoo
krnowak Sep 18, 2025
41eee72
sec-policy/selinux-dracut: Add from Gentoo
krnowak Sep 18, 2025
7072535
sec-policy/selinux-git: Add from Gentoo
krnowak Sep 18, 2025
7b96d64
sec-policy/selinux-gpg: Add from Gentoo
krnowak Sep 18, 2025
e7c3676
sec-policy/selinux-kdump: Add from Gentoo
krnowak Sep 18, 2025
4a09e5c
sec-policy/selinux-kerberos: Add from Gentoo
krnowak Sep 18, 2025
3109581
sec-policy/selinux-ldap: Add from Gentoo
krnowak Sep 18, 2025
b59c9a4
sec-policy/selinux-loadkeys: Add from Gentoo
krnowak Sep 18, 2025
d580b3a
sec-policy/selinux-logrotate: Add from Gentoo
krnowak Sep 18, 2025
7961d21
sec-policy/selinux-makewhatis: Add from Gentoo
krnowak Sep 18, 2025
b2a6d98
sec-policy/selinux-mandb: Add from Gentoo
krnowak Sep 18, 2025
2a5c666
sec-policy/selinux-ntp: Add from Gentoo
krnowak Sep 18, 2025
b25cc52
sec-policy/selinux-pcscd: Add from Gentoo
krnowak Sep 18, 2025
541d1aa
sec-policy/selinux-podman: Add from Gentoo
krnowak Sep 18, 2025
d176528
sec-policy/selinux-qemu: Add from Gentoo
krnowak Sep 18, 2025
c3ce0e8
sec-policy/selinux-quota: Add from Gentoo
krnowak Sep 18, 2025
4579de2
sec-policy/selinux-rpc: Add from Gentoo
krnowak Sep 18, 2025
0a15889
sec-policy/selinux-rpcbind: Add from Gentoo
krnowak Sep 18, 2025
f6e18fd
sec-policy/selinux-samba: Add from Gentoo
krnowak Sep 18, 2025
f44471a
sec-policy/selinux-sasl: Add from Gentoo
krnowak Sep 18, 2025
07058ff
sec-policy/selinux-smartmon: Add from Gentoo
krnowak Sep 18, 2025
1358d73
sec-policy/selinux-sudo: Add from Gentoo
krnowak Sep 18, 2025
129a48c
sec-policy/selinux-tcsd: Add from Gentoo
krnowak Sep 18, 2025
c120cd4
sec-policy/selinux-virt: Add from Gentoo
krnowak Sep 18, 2025
683f771
sec-policy/selinux-wireguard: Add from Gentoo
krnowak Sep 18, 2025
2f4e0f1
sec-policy/selinux-xfs: Add from Gentoo
krnowak Sep 18, 2025
0d5e084
sec-policy/selinux-zfs: Add from Gentoo
krnowak Sep 18, 2025
1f67a86
overlay coreos/user-patches: Add symlinks for newly added policy pack…
krnowak Apr 23, 2025
6aef3c4
.github: Add newly added policy packages to automation
krnowak Apr 23, 2025
841aaba
overlay profiles: Clean up selinux enabling
krnowak Apr 23, 2025
f499241
overlay profiles: Mask python and perl USE flags for generic images
krnowak Apr 24, 2025
05aca36
overlay profiles: Drop enabling caps and audit USE flags for specific…
krnowak Apr 24, 2025
4e12742
overlay profiles: Disable caps for smartmontools
krnowak Apr 24, 2025
61b21e2
overlay profiles: Allow python for sys-libs/libselinux
krnowak Apr 24, 2025
b058025
overlay coreos/config: Add Flatcar modifications for sys-libs/libsema…
krnowak Apr 25, 2025
3c28074
overlay sys-libs/libsemanage: Move to portage-stable
krnowak Apr 25, 2025
9551558
sys-libs/libsemanage: Sync with Gentoo
krnowak Jul 1, 2025
c1050c4
.github: Add sys-libs/libsemanage to automation
krnowak Apr 25, 2025
96aaf82
overlay sys-apps/policycoreutils: Move to portage-stable
krnowak Apr 29, 2025
e4c0423
sys-apps/policycoreutils: Sync with Gentoo
krnowak Jul 1, 2025
29a1542
.github: Add sys-apps/policycoreutils to automation
krnowak Apr 29, 2025
d2c5816
overlay coreos/config: Add python stuff to install mask for prod images
krnowak May 8, 2025
951d94f
overlay coreos/user-patches: Drop a patch for sys-libs/libsemanage
krnowak May 8, 2025
786c3c4
app-admin/setools: Add from Gentoo
krnowak May 8, 2025
043bf46
.github: Add app-admin/setools to automation
krnowak May 8, 2025
d53488a
overlay profiles: Do not pull app-admin/setools into prod images
krnowak May 8, 2025
5a43ad4
sys-apps/selinux-python: Add from Gentoo
krnowak Jul 1, 2025
744b161
.github: Add sys-apps/selinux-python to automation
krnowak May 8, 2025
1e12157
dev-python/networkx: Add from Gentoo
krnowak Jul 1, 2025
8da50f7
.github: Add dev-python/networkx to automation
krnowak May 8, 2025
43cbef9
overlay coreos/config: Add further modifications to sys-process/audit
krnowak May 8, 2025
27c291e
overlay profiles: Allow python for sys-process/audit
krnowak May 8, 2025
66c1a47
overlay coreos/config: Add further Flatcar modifications for sys-apps…
krnowak May 8, 2025
31f3f7b
overlay profiles: Force static-libs on sys-libs/libsepol to fix boots…
krnowak May 9, 2025
283dfdc
build_toolchain: Do not leak variables
krnowak May 15, 2025
4d81a04
build_toolchains: Break dep loop and handle more dependencies
krnowak May 13, 2025
e3db071
overlay profiles: Move python from package.mask to package.provided f…
krnowak May 19, 2025
61f4bb3
build_library: Building selinux policy
krnowak Sep 4, 2025
957ba2c
build_library: Fix pkg_use_enabled
krnowak Sep 4, 2025
1270586
build_library: Relabel the whole filesystem
krnowak Sep 5, 2025
e94f60c
build_sysext: Allow specifying forbidden packages in sysexts
krnowak Sep 5, 2025
7a7a168
build_library: Forbid SELinux policy packages in sysexts
krnowak Sep 5, 2025
bdd008f
overlay coreos-base/coreos: Add more selinux policy packages
krnowak Sep 5, 2025
fbd5785
HACK: sys-libs/glibc: Enable selinux even when cross-compiling
krnowak Sep 5, 2025
6e734c6
overlay coreos/user-patches: Add a patch for crossdev
krnowak Sep 15, 2025
c3d8994
overlay coreos/user-patches: Drop systemd patches related to SELinux …
krnowak Nov 13, 2025
afe4d4d
overlay profiles: Drop sec-policy/selinux-ntp from package.provided
krnowak Nov 13, 2025
3a79639
overlay coreos/config: Add pam_selinux to systemd PAM configs
krnowak Nov 13, 2025
da2de98
build_sysexts: Relabel sysexts too
krnowak Sep 25, 2025
e3a52dc
build_sysext: Factor out install root to a variable
krnowak Sep 26, 2025
4b14051
overlay coreos/user-patches: Update patch for selinux policies
krnowak Sep 30, 2025
33e4c65
build_library: Move and fix pkg_use_enabled into
krnowak Nov 13, 2025
40e3b86
build_sysext: Fix a crash when there were no forbidden packages
krnowak Nov 13, 2025
1e5adbd
build_sysext: Add --selinux flag and use it to build policies
krnowak Nov 13, 2025
f4be446
build_library: Pass --selinux flag to build_sysext
krnowak Nov 13, 2025
fc437ba
DEBUG
krnowak Nov 13, 2025
a663ba3
build_library/extra_sysexts.sh: Sort entries
krnowak Oct 8, 2025
5e4ceca
build_library/extra_sysexts.sh: Add selinux sysext
krnowak Oct 8, 2025
b41b6b5
overlay coreos/user-patches: Update refpolicy patch
krnowak Oct 8, 2025
1944604
overlay profiles: Build only the mcs SELinux policy
krnowak Oct 8, 2025
dcb418f
overlay profiles: Move python packages as provided to the prod profile
krnowak Nov 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 @@ -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 @@ -339,6 +340,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 @@ -571,13 +573,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 @@ -620,10 +657,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 @@ -701,6 +740,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 @@ -685,8 +686,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 @@ -720,12 +726,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