Score:0

selinux file context precendence, logrotate and httpd

au flag

UPDATE:

figured out the issue, its with my fcontext path expression

I have to use

semanage fcontext -a -t logrotate_tmp_t "/etc/httpd/logs(./*)?"
instead of 
semanage fcontext -a -t logrotate_tmp_t "/etc/httpd/logs/*"

and -t httpd_log_t also works

I think the questions that remain

  1. Where can I find the documentation reference to the expression? and will it be version specific?
  2. is there any man command to show these kind of selinux file context related help content on the server? I checked seinfo and sesearch was not installed on that server, do I simply have to install them?

ORIGINAL: I have a server in AWS running SELinux, been trying to configure httpd log rotation.

sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from conif files: enforcing
Policy version: 24
Policy from config file: targeted

logrotate can't seem to work properly on httpd logs

Manually running logrotate and logrotate -f as root works. I tried it with logrotate -d it does read the logrotate.status and retrieve last date correctly. But when its put to cron.daily/logrotate, the rotation does not happen and I receive mail in /var/mail/root that

/etc/cron.daily/logrotate:

error: unable to open /etc/httpd/logs/access_log-yyyymmdd for compression

or sometimes
error: error opening /etc/httpd/logs/access_log: Permission denied

ls -Z in the path yields below

~cd /etc/httpd
~ls -dZ logs
dxwxr-xr-x. root root unconfined_u:object_r:httpd_log_t:s0 logs
~ls -Z logs
-rw-r--r--. root unconfined_u:object_r:httpd_config_t:s0 access_log

I was having difficulty determining what file contexts to and how to put it to the folder and files

man logrotate does not mention what contexts it needs, and date of manual is 2022

man semanage date of manual is 2010

reading https://linux.die.net/man/8/logrotate_selinux, the only appropriate file context seems to be logrotate_tmp_t, so I tried to add it

semanage fcontext -a -t logrotate_tmp_t /etc/httpd/logs/*
restorecon -v /etc/httpd/logs/*

but restorecon did not produce any output, not even without * or /

checked semanage fcontext -l with grep -n

 685:/etc/httpd(/.*)? all files system_u:object_r:httpd_config_t:s0
2928:/etc/httpd/logs all files system_u:object_r:httpd_log_t:s0
4642:/etc/httpd/logs/* all files system_u:object_r:logrotate_tmp_t:s0    

and I read that lines come later should take precendence, however that does not seems the case, as seen in the ls -Z output above. I also tried to give the logs folder var_log_t context as a workaround (same context as /var/log) but it also does not show in ls -Z.

I even tried semanage fcontext -C -l in the logs folder, and only the entry /etc/httpd/logs/* all files system_u:object_r:logrotate_tmp_t:s0 came up

I am confused whether if this is due to the selinux and logrotate version being too old? would want to know.

  1. If there is a correct way invoke the selinus related manual of logrotate on the machine? man logrotate_ tab does not show any available options
  2. Did I understand the selinux file context precedence correctly?
  3. Is this an old version issue?
  4. does the context type given by fcontext -l matter? choices are "all files, regular file, directory, symbolic link etc"
  5. and if the context type matters, how do I set it in the command? semanage -v showed that its in the Object-specific Opions, -f specifies file type of object, "" is all files, -- is regular file, -d is directory, but wherever I insert it in the semanage fcontext -a -t type files command, it always give me semange: bad option
  6. What is my actual issue
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.