24.4. Loading an IMA policy signed by your custom IMA key
To maintain your system integrity and meet the security requirements your organization, you can load an IMA policy that is signed with your own custom IMA key. This approach ensures that only trusted, authenticated policies are applied during system startup or runtime.
This procedure applies only to x86_64 and aarch64 systems with UEFI Secure Boot enabled, and to ppc64le systems running PowerVM Secure Boot.
Prerequisites
- You must have root privileges on your system.
-
UEFI Secure Boot is enabled for Red Hat Enterprise Linux or the kernel is booted with the
ima_policy=secure_bootparameter to ensure only signed IMA policy can be loaded. - The custom IMA CA key has been added to the MOK list. For more information, see Enrolling public key on target system by adding the public key to the MOK list.
- The kernel version is 5.14 or later.
- Good reference values have been generated for the IMA policy. For more information, see Generate good reference values for IMA appraisal.
Procedure
Add your custom IMA code signing key to the
.imakeyring:# keyctl padd asymmetric <KEY_SUBJECT> %:.ima < <PATH_TO_YOUR_CUSTOM_IMA_KEY>Prepare your IMA policy and sign it with your custom IMA code signing key:
# evmctl ima_sign <PATH_TO_YOUR_CUSTOM_IMA_POLICY> -k <PATH_TO_YOUR_CUSTOM_IMA_KEY>Load the signed IMA policy:
# echo <PATH_TO_YOUR_CUSTOM_SIGNED_IMA_POLICY> > /sys/kernel/security/ima/policy # echo $? 00indicates that the IMA policy was loaded successfully. If the command returns a nonzero value, the IMA policy was not loaded successfully.
警告Do not skip this step. If you do, your system might fail to boot and you need to recover your system.
If the IMA policy fails to load, repeat the steps 2 and 3 to fix the issue.
Copy the signed IMA policy to
/etc/ima/ima-policyto enable systemd load it automatically on boot:# cp --preserve=xattr <PATH_TO_YOUR_CUSTOM_IMA_POLICY> /etc/ima/ima-policyAutomatically add your custom IMA code signing key to
.imakeyring on boot by using thedracutintegrity module:# cp <PATH_TO_YOUR_CUSTOM_IMA_KEY> /etc/keys/ima/ # cp --preserve=xattr /usr/share/ima/dracut-98-integrity.conf /etc/dracut.conf.d/98-integrity.conf # dracut -fAdditionally for
s390xsystems:# zipl
Verification
Verify that the IMA policy is loaded successfully:
# cat /sys/kernel/security/ima/policyThe output should include the rules from your custom IMA policy.