Cron – How to allow cron to send an email attachment

cronselinuxsendmail

SELinux is preventing cron from attaching a log file in the email with the following error:

notice kernel [ 7148.923034] type=1400 audit(1359466501.857:5): avc:
denied { read } for pid=3182 comm="mailx" name="attachment"
dev="dm-1" ino=4140
scontext=system_u:system_r:system_mail_t:s0-s0:c0.c1023
tcontext=system_u:object_r:var_log_t:s0 tclass=file

A bash script is run by cron every hour to email a log file if it is not empty. The script contains the following line:

echo "" | mailx -s "Critical Message" -a /var/log/attachment test@email.com

I think the problem has to do with the file security context. I read somewhere that setting the context to public content might help, but not sure if it is a good idea or if there is a better approach.

Best Answer

You have three options (well, three that I can think of right now):
1. File a bug and wait for an update to the policy package which does allow this.
2. Change the context of the file you're attempting to attach so that SELinux lets it get attached.
3. Put SElinux in permissive mode, so it will log the fact that it wants to deny this action but it won't actually prevent it from happening.

Each option has drawbacks, some perhaps significant, so the route you take will be highly dependent on your environment.

Related Topic