diff options
author | Ming Liu <liu.ming50@gmail.com> | 2021-02-20 13:18:19 +0100 |
---|---|---|
committer | Armin Kuster <akuster808@gmail.com> | 2021-02-23 20:34:51 -0800 |
commit | 76d1e3ecad77ecd38c1c99171d5f2497d1258644 (patch) | |
tree | 136c77e18e80dd3af42403e7a69008a22ff8c805 | |
parent | 52bfc654e8a48a1fcfd89ba8750021c21718f6f5 (diff) | |
download | meta-security-76d1e3ecad77ecd38c1c99171d5f2497d1258644.tar.gz |
meta: refactor IMA/EVM sign rootfs
The current logic in ima-evm-rootfs.bbclass does not guarantee
ima_evm_sign_rootfs is the last function in IMAGE_PREPROCESS_COMMAND
by appending to it, for instance, if there are other "_append" being
used as it's the case in openembedded-core/meta/classes/image.bbclass:
| IMAGE_PREPROCESS_COMMAND_append = " ${@ 'systemd_preset_all;' \
| if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) \
| and not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True,
| False, d) else ''} reproducible_final_image_task; "
and ima-evm-rootfs should be in IMAGE_CLASSES instead of in INHERIT
since that would impact all recipes but not only image recipes.
To fix the above issues, we introduce a ima_evm_sign_handler setting
IMA/EVM rootfs signing requirements/dependencies in event
bb.event.RecipePreFinalise, it checks 'ima' distro feature to decide if
IMA/EVM rootfs signing logic should be applied or not.
Also add ima-evm-keys to IMAGE_INSTALL.
Signed-off-by: Ming Liu <liu.ming50@gmail.com>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
-rw-r--r-- | meta-integrity/classes/ima-evm-rootfs.bbclass | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/meta-integrity/classes/ima-evm-rootfs.bbclass b/meta-integrity/classes/ima-evm-rootfs.bbclass index d6ade3b..4359af0 100644 --- a/meta-integrity/classes/ima-evm-rootfs.bbclass +++ b/meta-integrity/classes/ima-evm-rootfs.bbclass | |||
@@ -37,15 +37,6 @@ ima_evm_sign_rootfs () { | |||
37 | # reasons (including a change of the signing keys) without also | 37 | # reasons (including a change of the signing keys) without also |
38 | # re-running do_rootfs. | 38 | # re-running do_rootfs. |
39 | 39 | ||
40 | # Copy file(s) which must be on the device. Note that | ||
41 | # evmctl uses x509_evm.der also for "ima_verify", which is probably | ||
42 | # a bug (should default to x509_ima.der). Does not matter for us | ||
43 | # because we use the same key for both. | ||
44 | install -d ./${sysconfdir}/keys | ||
45 | rm -f ./${sysconfdir}/keys/x509_evm.der | ||
46 | install "${IMA_EVM_X509}" ./${sysconfdir}/keys/x509_evm.der | ||
47 | ln -sf x509_evm.der ./${sysconfdir}/keys/x509_ima.der | ||
48 | |||
49 | # Fix /etc/fstab: it must include the "i_version" mount option for | 40 | # Fix /etc/fstab: it must include the "i_version" mount option for |
50 | # those file systems where writing files is allowed, otherwise | 41 | # those file systems where writing files is allowed, otherwise |
51 | # these changes will not get detected at runtime. | 42 | # these changes will not get detected at runtime. |
@@ -80,13 +71,16 @@ ima_evm_sign_rootfs () { | |||
80 | } | 71 | } |
81 | 72 | ||
82 | # Signing must run as late as possible in the do_rootfs task. | 73 | # Signing must run as late as possible in the do_rootfs task. |
83 | # IMAGE_PREPROCESS_COMMAND runs after ROOTFS_POSTPROCESS_COMMAND, so | 74 | # To guarantee that, we append it to IMAGE_PREPROCESS_COMMAND in |
84 | # append (not prepend!) to IMAGE_PREPROCESS_COMMAND, and do it with | 75 | # RecipePreFinalise event handler, this ensures it's the last |
85 | # _append instead of += because _append gets evaluated later. In | 76 | # function in IMAGE_PREPROCESS_COMMAND. |
86 | # particular, we must run after prelink_image in | 77 | python ima_evm_sign_handler () { |
87 | # IMAGE_PREPROCESS_COMMAND, because prelinking changes executables. | 78 | if not e.data or 'ima' not in e.data.getVar('DISTRO_FEATURES').split(): |
88 | 79 | return | |
89 | IMAGE_PREPROCESS_COMMAND_append = " ima_evm_sign_rootfs ; " | ||
90 | 80 | ||
91 | # evmctl must have been installed first. | 81 | e.data.appendVar('IMAGE_PREPROCESS_COMMAND', ' ima_evm_sign_rootfs; ') |
92 | do_rootfs[depends] += "ima-evm-utils-native:do_populate_sysroot" | 82 | e.data.appendVar('IMAGE_INSTALL', ' ima-evm-keys') |
83 | e.data.appendVarFlag('do_rootfs', 'depends', ' ima-evm-utils-native:do_populate_sysroot') | ||
84 | } | ||
85 | addhandler ima_evm_sign_handler | ||
86 | ima_evm_sign_handler[eventmask] = "bb.event.RecipePreFinalise" | ||