[3/5] rootfs: ship unmodified DISTRO_APT_SOURCES if not requested otherwise

Message ID 20261203153249.1727469-4-felix.moessbauer@siemens.com
State New
Headers show
Series Do not leak DISTRO_APT_PREMIRRORS into the image | expand

Commit Message

Felix Moessbauer Dec. 3, 2026, 3:32 p.m. UTC
Since mmdebstrap became the default bootstrap provider, the apt sources
list used during the build ends up in the final rootfs. It contains the
DISTRO_APT_PREMIRRORS (or snapshot) rewrites, contradicting the user
manual which states that premirrors are only used for the build.

Add the rootfs feature distro-apt-sources that installs the unmodified
list stored by the bootstrap in place of the build-time one and enable
it for images and the SDK. Custom lists from an image SRC_URI still
take precedence as they are installed afterwards in do_rootfs_finalize.

Fixes: 1e33b12acfc9 ("image: Account for differences with mmdebstrap")
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 RECIPE-API-CHANGELOG.md            |  7 +++++++
 meta/classes-recipe/image.bbclass  |  1 +
 meta/classes-recipe/rootfs.bbclass | 15 +++++++++++++++
 meta/classes-recipe/sdk.bbclass    |  2 +-
 4 files changed, 24 insertions(+), 1 deletion(-)

Patch

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index 34698926..3220bf4a 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -1228,3 +1228,10 @@  kept for legal reasons).
 
 Changes in next
 ---------------
+
+### New rootfs feature distro-apt-sources
+
+The `distro-apt-sources` rootfs feature replaces the apt sources list used
+during the build (which includes `DISTRO_APT_PREMIRRORS` or snapshot
+rewrites) with the unmodified one from `DISTRO_APT_SOURCES`. It is enabled
+by default for images and the SDK.
diff --git a/meta/classes-recipe/image.bbclass b/meta/classes-recipe/image.bbclass
index ce19ae1c..4f701efb 100644
--- a/meta/classes-recipe/image.bbclass
+++ b/meta/classes-recipe/image.bbclass
@@ -102,6 +102,7 @@  ROOTFS_FEATURES += "\
     generate-sbom \
     clean-apt-credentials \
     clean-dpkg-config \
+    distro-apt-sources \
     ${IMAGE_ROOTFS_FEATURES} \
     "
 ROOTFS_PACKAGES += "${IMAGE_PREINSTALL} ${@isar_multiarch_packages('IMAGE_INSTALL', d)}"
diff --git a/meta/classes-recipe/rootfs.bbclass b/meta/classes-recipe/rootfs.bbclass
index d0c93abf..820b9df1 100644
--- a/meta/classes-recipe/rootfs.bbclass
+++ b/meta/classes-recipe/rootfs.bbclass
@@ -43,6 +43,7 @@  ROOTFS_BASE_DISTRO ?= "${BASE_DISTRO}"
 # 'clean-apt-credentials' - remove apt auth credentials written by ISAR_APT_CREDS
 # 'clean-dpkg-config' - remove ISAR-specific dpkg configuration files from the rootfs
 # 'exclude-docs' - exclude most documentation files from the rootfs
+# 'distro-apt-sources' - replace the build-time apt sources (incl. premirrors) with the unmodified DISTRO_APT_SOURCES
 
 # convenience variable to enable all features needed for a reproducible rootfs build
 ROOTFS_FEATURES_REPRODUCIBLE = " \
@@ -626,6 +627,20 @@  rootfs_postprocess_clean_dpkg_config() {
     run_privileged find "${ROOTFSDIR}/etc/dpkg/dpkg.cfg.d" -type f -name '*isar*.cfg' -delete
 }
 
+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'distro-apt-sources', 'rootfs_postprocess_distro_apt_sources', '', d)}"
+rootfs_postprocess_distro_apt_sources() {
+    # The bootstrap list carries DISTRO_APT_PREMIRRORS rewrites (or base-apt),
+    # ship the unmodified DISTRO_APT_SOURCES stored by the bootstrap instead.
+    run_privileged_heredoc <<'EOSUDO'
+        set -e
+        if [ -e "${ROOTFSDIR}/etc/apt/sources-list" ]; then
+            rm -f "${ROOTFSDIR}/etc/apt/sources.list.d/0000bootstrap.list"
+            mv "${ROOTFSDIR}/etc/apt/sources-list" \
+               "${ROOTFSDIR}/etc/apt/sources.list.d/0000bootstrap.list"
+        fi
+EOSUDO
+}
+
 ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'exclude-docs', 'rootfs_postprocess_exclude_docs', '', d)}"
 rootfs_postprocess_exclude_docs() {
     run_privileged_heredoc <<'EOSUDO'
diff --git a/meta/classes-recipe/sdk.bbclass b/meta/classes-recipe/sdk.bbclass
index 543df84b..5082c5ce 100644
--- a/meta/classes-recipe/sdk.bbclass
+++ b/meta/classes-recipe/sdk.bbclass
@@ -49,7 +49,7 @@  ROOTFS_ARCH:class-sdk = "${HOST_ARCH}"
 ROOTFS_DISTRO:class-sdk = "${@get_rootfs_distro(d)}"
 ROOTFS_PACKAGES:class-sdk = "sdk-files ${SDK_TOOLCHAIN} ${SDK_PREINSTALL} ${@isar_multiarch_packages('SDK_INSTALL', d)}"
 ROOTFS_VARDEPS:class-sdk = "SDK_INSTALL SDK_INCLUDE_ISAR_APT"
-ROOTFS_FEATURES:append:class-sdk = " clean-apt-lists clean-apt-credentials generate-manifest export-dpkg-status generate-sbom"
+ROOTFS_FEATURES:append:class-sdk = " clean-apt-lists clean-apt-credentials distro-apt-sources generate-manifest export-dpkg-status generate-sbom"
 ROOTFS_MANIFEST_DEPLOY_DIR:class-sdk = "${DEPLOY_DIR_SDKCHROOT}"
 ROOTFS_DPKGSTATUS_DEPLOY_DIR:class-sdk = "${DEPLOY_DIR_SDKCHROOT}"