在只读根文件系统上安装 mozroot-certdata 包

Install mozroot-certdata package on a read only root file system

我有一个已建立的 yocto 构建,我现在正在尝试切换到具有根文件系统(例如 EXTRA_IMAGE_FEATURES += "read-only-rootfs")。

但是我 运行 遇到了元单声道层中的配方问题:mozroot-certdata。我看到罪魁祸首是 pkg_postint 脚本 (http://git.yoctoproject.org/cgit/cgit.cgi/meta-mono/tree/recipes-mono/mozroot-certdata/mozroot-certdata_1.0.0.bb),它需要在第一次启动时修改根文件系统,而构建系统使用只读根文件系统正确地标记为不可能:

ERROR: The following packages could not be configured offline and rootfs is read-only: ['mozroot-certdata']

我的问题是:有没有办法在构建过程中使用 mono 安装和配置这些 mozroot 证书,这样就不需要在 boot/run 时修改根文件系统?

好吧,我在今年夏末简要地看了一眼,因为我也在使用只读的 rootfs。问题是 mozroot.exe 被硬编码写入 /usr/share/.mono/certs 并且不尊重您的 sysroot。你可能会破解 mozroot.exe 以将导入的文件实际写入 sysroot,尽管我的时间限制不允许我尝试这个(而且我也根本没有研究过 mono...) .

我的解决方案是在每次启动时都进行导入。 (它也可以只做一次,但随后就会出现关于更新的问题)。为了实现这一点,我在 mozroot.exe 想要写入证书数据的目录上进行了绑定挂载。

我的解决方案详情

添加包含以下内容的文件volatile-binds.bbappend

VOLATILE_BINDS += "\
    /tmp/mono-certs /usr/share/.mono/certs \n\
"

这将使从 /tmp/mono-certs/usr/share/.mono/certs 的绑定挂载,因此您将能够导入证书。

然后我添加了一个服务文件和一个mozroot-certdata_%.bbappend:

FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"

DEPENDS += "mono-native"

SRC_URI += "file://mozroot-certdata.service \
"

inherit systemd

SYSTEMD_SERVICE_${PN} = "mozroot-certdata.service"

do_install_append() {
    mkdir -p ${D}${datadir}/.mono/certs
    mkdir -p ${D}${systemd_system_unitdir}
    install -m 440 ${WORKDIR}/mozroot-certdata.service ${D}${systemd_system_unitdir}/mozroot-certdata.service
}

FILES_${PN} += "${datadir}"

# Empty the postinstallation script, as we can import the cert offline.
pkg_postinst_${PN} () {
#     mono $D/usr/lib/mono/4.5/mozroots.exe --import --machine --ask remove --file $D/${sysconfdir}/ssl/certdata.txt
}

服务文件mozroot-certdata.service:

[Unit]
Description=Import certficates to Mono
After=tmp-mono-certs.service

[Service]
Type=oneshot
ExecStart=/usr/bin/mono /usr/lib/mono/4.5/mozroots.exe --import --machine --ask-remove --file /etc/ssl/certdata.txt

[Install]
WantedBy=multi-user.target

is there a way to get these mozroot certs installed and configured with mono during the build process

是的,但它要求 mosroots 二进制文件在 rootfs 创建时可执行。请参阅文档中的 Post-Installation Scripts

pkg_postinst 中的 'else' 分支是在那个时候执行的,如果它成功,则不需要延迟的 postinst(并且你不应该得到构建错误)。 mono-native 配方已经存在,因此您应该能够依赖它并修复 pkg_postinst 函数中的 else 分支,以便它找到本机单声道 & mosroots.exe 并写入 $ 下的正确位置D.

正如 Anders 所提到的,如果您关心基于包的升级,仅此是不够的。