How do I make a new SELinux context and add it to a file/directory?

2

I have the following

audit.log
type=AVC msg=audit(1484787464.870:381223): avc:  denied  { execute } for  pid=10683 comm="pipe" name="tmp.pl" dev=xvde ino=30503 scontext=unconfined_u:system_r:postfix_pipe_t:s0 tcontext=unconfined_u:object_r:usr_t:s0 tclass=file
type=SYSCALL msg=audit(1484787464.870:381223): arch=c000003e syscall=59 success=no exit=-13 a0=7f12efd23ca0 a1=7f12efd23c60 a2=7f12efd23de0 a3=7ffd0f0802f0 items=0 ppid=10681 pid=10683 auid=0 uid=497 gid=12 euid=497 suid=497 fsuid=497 egid=12 sgid=12 fsgid=12 tty=(none) ses=4439 comm="pipe" exe="/usr/libexec/postfix/pipe" subj=unconfined_u:system_r:postfix_pipe_t:s0 key=(null)
maillog
Jan 19 00:57:45 ip-99-99-99-99 pipe[10685]: fatal: pipe_command: execvp /usr/local/mail-captcha/tmp.pl: Permission denied
Jan 19 00:57:45 ip-99-99-99-99 postfix/pipe[10681]: B559C2026D: to=<xxxxxx@xxxxxxxx.net>, relay=mailcaptcha, delay=2727, delays=2726/0.5/0/0.57, dsn=4.3.0, status=deferred (temporary failure. Command output: pipe: fatal: pipe_command: execvp /usr/local/mail-captcha/tmp.pl: Permission denied )
master.cf
mailcaptcha unix -       n       n       -       -       pipe 
  flags=FR user=vmail argv=/usr/bin/perl /usr/local/mail-captcha/tmp.pl ${sender} ${recipient}

# ls -Z tmp.pl
-rwxr-xr-x. vmail vmail unconfined_u:object_r:usr_t:s0   tmp.pl

# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
B559C2026D      625 Thu Jan 19 00:12:18  xxxx@xxxxx.com
(temporary failure. Command output: pipe: fatal: pipe_command: execvp /usr/local/mail-captcha/tmp.pl: Permission denied)
                                         xxxxx@xxxxxx.com

# chcon -t postfix_pipe_t tmp.pl
chcon: failed to change context of `tmp.pl' to `unconfined_u:object_r:postfix_pipe_t:s0': Permission denied

# semanage fcontext -a -t mailcaptcha_t '/usr/local/mail-captcha(/.*)?'
/usr/sbin/semanage: Type mailcaptcha_t is invalid, must be a file or device type

It seems everything would work, if not for SELinux. How do I make a new security context for this file and project? I saw this (http://fedoraproject.org/wiki/PackagingDrafts/SELinux#Creating_new_types), but I don't understand each line and it seems like it is doing much more than creating a simple context.

CentOS release 6.8 (Final)

Chloe

Posted 2017-01-19T01:16:11.673

Reputation: 4 502

No answers