此内容没有您所选择的语言版本。
8.3.8. Allowing Access: audit2allow
Do not use the example in this section in production. It is used only to demonstrate the use of the
audit2allow utility.
From the audit2allow(1) manual page: "
audit2allow – generate SELinux policy allow rules from logs of denied operations"[16]. After analyzing denials as per Section 8.3.7, “sealert Messages”, and if no label changes or Booleans allowed access, use audit2allow to create a local policy module. After access is denied by SELinux, running the audit2allow command presents Type Enforcement rules that allow the previously denied access.
The following example demonstrates using
audit2allow to create a policy module:
- A denial and the associated system call are logged to
/var/log/audit/audit.log:type=AVC msg=audit(1226270358.848:238): avc: denied { write } for pid=13349 comm="certwatch" name="cache" dev=dm-0 ino=218171 scontext=system_u:system_r:certwatch_t:s0 tcontext=system_u:object_r:var_t:s0 tclass=dir type=SYSCALL msg=audit(1226270358.848:238): arch=40000003 syscall=39 success=no exit=-13 a0=39a2bf a1=3ff a2=3a0354 a3=94703c8 items=0 ppid=13344 pid=13349 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="certwatch" exe="/usr/bin/certwatch" subj=system_u:system_r:certwatch_t:s0 key=(null)type=AVC msg=audit(1226270358.848:238): avc: denied { write } for pid=13349 comm="certwatch" name="cache" dev=dm-0 ino=218171 scontext=system_u:system_r:certwatch_t:s0 tcontext=system_u:object_r:var_t:s0 tclass=dir type=SYSCALL msg=audit(1226270358.848:238): arch=40000003 syscall=39 success=no exit=-13 a0=39a2bf a1=3ff a2=3a0354 a3=94703c8 items=0 ppid=13344 pid=13349 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="certwatch" exe="/usr/bin/certwatch" subj=system_u:system_r:certwatch_t:s0 key=(null)Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, certwatch (comm="certwatch") was denied write access ({ write }) to a directory labeled with thevar_ttype (tcontext=system_u:object_r:var_t:s0). Analyze the denial as per Section 8.3.7, “sealert Messages”. If no label changes or Booleans allowed access, useaudit2allowto create a local policy module. - With a denial logged, such as the
certwatchdenial in step 1, run theaudit2allow -w -acommand to produce a human-readable description of why access was denied. The-aoption causes all audit logs to be read. The-woption produces the human-readable description. Theaudit2allowutility accesses/var/log/audit/audit.log, and as such, must be run as the Linux root user:Copy to Clipboard Copied! Toggle word wrap Toggle overflow As shown, access was denied due to a missing Type Enforcement rule. - Run the
audit2allow -acommand to view the Type Enforcement rule that allows the denied access:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Important
Missing Type Enforcement rules are usually caused by bugs in SELinux policy, and should be reported in Red Hat Bugzilla. For Red Hat Enterprise Linux, create bugs against theRed Hat Enterprise Linuxproduct, and select theselinux-policycomponent. Include the output of theaudit2allow -w -aandaudit2allow -acommands in such bug reports. - To use the rule displayed by
audit2allow -a, run theaudit2allow -a -M mycertwatchcommand as the Linux root user to create custom module. The-Moption creates a Type Enforcement file (.te) with the name specified with-M, in your current working directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Also,audit2allowcompiles the Type Enforcement rule into a policy package (.pp). To install the module, run thesemodule -i mycertwatch.ppcommand as the Linux root user.Important
Modules created withaudit2allowmay allow more access than required. It is recommended that policy created withaudit2allowbe posted to an SELinux list, such as fedora-selinux-list, for review. If you believe their is a bug in policy, create a bug in Red Hat Bugzilla.
If you have multiple denials from multiple processes, but only want to create a custom policy for a single process, use the
grep command to narrow down the input for audit2allow. The following example demonstrates using grep to only send denials related to certwatch through audit2allow:
grep certwatch /var/log/audit/audit.log | audit2allow -M mycertwatch2 semodule -i mycertwatch2.pp
~]# grep certwatch /var/log/audit/audit.log | audit2allow -M mycertwatch2
******************** IMPORTANT ***********************
To make this policy package active, execute:
~]# semodule -i mycertwatch2.pp
Refer to Dan Walsh's "Using audit2allow to build policy modules. Revisited." blog entry for further information about using
audit2allow to build policy modules.
[16]
From the audit2allow(1) manual page, which is available when the policycoreutils-sandbox package in Red Hat Enterprise Linux 6 is installed.