24.2. Writing custom IMA policy
If the built-in IMA policies that you enable with kernel command line parameters, such as ima_policy=tcb or ima_policy=critical_data, or the sample policies in /usr/share/ima/policies/ do not meet your requirements, you can create custom IMA policy rules. When systemd loads a policy from /etc/ima/ima-policy, it replaces the built-in IMA policy.
After you define your IMA policy, generate good reference values if the policy includes IMA-appraisal rules before you deploy it. If your policy does not include IMA-appraisal rules, you can verify the policy by running echo /PATH-TO-YOUR-DRAFT-IMA-POLICY > /sys/kernel/security/integrity/ima/policy. This approach helps prevent system boot failures.
Procedure
Review the rule format and an example policy.
An IMA policy rule uses the format
action [condition …]to specify an action that is triggered under certain conditions. For example, the sample policy in/usr/share/ima/policies/01-appraise-executable-and-lib-signaturesincludes the following rules:# Skip some unsupported filesystems # For a list of these filesystems, see # https://www.kernel.org/doc/Documentation/ABI/testing/ima_policy # PROC_SUPER_MAGIC dont_appraise fsmagic=0x9fa0 … appraise func=BPRM_CHECK appraise_type=imasigThe first rule,
dont_appraise fsmagic=0x9fa0, instructs IMA to skip appraising files in thePROC_SUPER_MAGICfilesystem. The last rule,appraise func=BPRM_CHECK appraise_type=imasig, enforces signature verification when a file is executed.