简体   繁体   English

在 Yocto ext4 Image 中设置 Linux 功能

[英]Setting Linux Capabilities in Yocto ext4 Image

I intend to set some capabilities on binaries included in a Yocto image using "setcap".我打算使用“setcap”为 Yocto 映像中包含的二进制文件设置一些功能。 For some reason the solutions mentioned here did not work for me: Linux capabilities with yocto .出于某种原因,这里提到的解决方案对我不起作用: yocto 的 Linux 功能 I have checked that by running "getcap" on my binary within the rootfs creation directory:我通过在 rootfs 创建目录中的二进制文件上运行“getcap”来检查:

getcap ${IMAGE_ROOTFS}/usr/bin/mybinary

does not return anything.不返回任何东西。 Nor do I find the capabilities in the final running sdcard image.我也没有在最终运行的 sdcard 映像中找到这些功能。

Next I tried the approach using IMAGE_PREPROCESS_COMMAND.接下来我尝试使用 IMAGE_PREPROCESS_COMMAND 的方法。 I wrapped up setcap commands in small shell functions such as:我将 setcap 命令封装在小的 shell 函数中,例如:

my_setcap_function() {
    sudo setcap cap_ipc_owner+ep ${IMAGE_ROOTFS}/usr/bin/mybinary
}

and append the function names to IMAGE_PREPROCESS_COMMAND.并将函数名称附加到 IMAGE_PREPROCESS_COMMAND。 This works to the extent that now running getcap on my binary within the {IMAGE_ROOTFS} directory does show the correct caps set.这适用于现在在 {IMAGE_ROOTFS} 目录中对我的二进制文件运行 getcap 确实显示正确的大写设置。 However I still do not get the capabilities in the final running sdcard image.但是,我仍然没有在最终运行的 sdcard 映像中获得这些功能。

Also if I mount the rootfs ext4 (which is used to create the final sdcard image) on a directory using -o loop, I do not see the capabilities on my binary.此外,如果我使用 -o 循环将 rootfs ext4(用于创建最终的 sdcard 映像)挂载到目录上,我将看不到二进制文件的功能。 It seems to me that the capabilitiess somehow get lost when the ext4 is created using mkfs.ext4.在我看来,当使用 mkfs.ext4 创建 ext4 时,功能会以某种方式丢失。

I had to attach sudo to setcap because otherwise it complains saying "unable to set CAP_SETFCAP effective capability: Operation not permitted".我必须将 sudo 附加到 setcap,否则它会抱怨说“无法设置 CAP_SETFCAP 有效能力:不允许操作”。 Although my understanding was that IMAGE_PREPROCESS_COMMAND commands are run using fakeroot so this sudo should not be required.虽然我的理解是 IMAGE_PREPROCESS_COMMAND 命令是使用 fakeroot 运行的,所以不需要这个 sudo。

So, to summarize my question:所以,总结一下我的问题:

  1. How can I get the capabilities on the sdcard image made using ext4 rootfs image?如何获得使用 ext4 rootfs 映像制作的 sdcard 映像的功能?
  2. I want to use a way that does not require using "sudo".我想使用一种不需要使用“sudo”的方式。

I am using Yocto Krogoth and currently cannot upgrade that.我正在使用 Yocto Krogoth,目前无法升级。

Did you really test it on the final image or in the rootfs folder from the yocto build?您是否真的在最终图像或 yocto 构建的 rootfs 文件夹中对其进行了测试?

I run getcap on the files in the rootfs folder, and there where nothing set.我对 rootfs 文件夹中的文件运行 getcap,在那里没有设置。

Because yocto uses pseudo lib to intercept chown, chmod calls, track them in a sqlite db (uses LD_PRELOAD for interception).因为 yocto 使用伪库来拦截 chown、chmod 调用,在 sqlite db 中跟踪它们(使用 LD_PRELOAD 进行拦截)。

So this attributes are not set for the files in the "rootfs" folder, however added at image/rootfs creation.所以这个属性不是为“rootfs”文件夹中的文件设置的,而是在创建 image/rootfs 时添加的。

you can use setcap in recipe, you have to add您可以在配方中使用 setcap,您必须添加

DEPENDS = "libcap-native"

in your recipe.在你的食谱里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM