RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2144514 - SELinux is preventing /usr/bin/bash from execute access on the file kitinerary-extractor.
Summary: SELinux is preventing /usr/bin/bash from execute access on the file kitinerar...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: selinux-policy
Version: 8.7
Hardware: All
OS: Linux
low
high
Target Milestone: rc
: ---
Assignee: Zdenek Pytela
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks: 2155540
TreeView+ depends on / blocked
 
Reported: 2022-11-21 14:29 UTC by Brian J. Murrell
Modified: 2023-02-01 07:24 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2155540 (view as bug list)
Environment:
Last Closed: 2023-02-01 07:24:25 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-140032 0 None None None 2022-11-21 14:42:57 UTC

Description Brian J. Murrell 2022-11-21 14:29:39 UTC
SELinux is preventing /usr/bin/bash from execute access on the file kitinerary-extractor.

*****  Plugin catchall_boolean (89.3 confidence) suggests   ******************

If you want to unify HTTPD handling of all content files.
Then you must tell SELinux about this by enabling the 'httpd_unified' boolean.
You can read 'httpd_selinux' man page for more details.
Do
setsebool -P httpd_unified 1

*****  Plugin catchall (11.6 confidence) suggests   **************************

If you believe that bash should be allowed execute access on the kitinerary-extractor file by default.                                                                             
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# ausearch -c 'sh' --raw | audit2allow -M my-sh
# semodule -X 300 -i my-sh.pp


Additional Information:
Source Context                system_u:system_r:httpd_t:s0
Target Context                system_u:object_r:httpd_sys_rw_content_t:s0
Target Objects                kitinerary-extractor [ file ]
Source                        sh
Source Path                   /usr/bin/bash
Port                          <Unknown>
Host                          server.interlinx.bc.ca
Source RPM Packages           bash-4.4.20-4.el8_6.x86_64
Target RPM Packages
SELinux Policy RPM            selinux-policy-targeted-3.14.3-108.el8.noarch
Local Policy RPM              selinux-policy-targeted-3.14.3-108.el8.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     server.interlinx.bc.ca
Platform                      Linux server.interlinx.bc.ca
                              4.18.0-372.32.1.el8_6.x86_64 #1 SMP Tue Oct 25
                              05:53:57 EDT 2022 x86_64 x86_64
Alert Count                   2
First Seen                    2022-11-21 07:21:34 EST
Last Seen                     2022-11-21 07:21:34 EST
Local ID                      1f75424b-3f34-4224-8beb-42ce08c4f6e1

Raw Audit Messages
type=AVC msg=audit(1669033294.816:11840): avc:  denied  { execute } for  pid=640400 comm="sh" name="kitinerary-extractor" dev="dm-7" ino=3409397 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:httpd_sys_rw_content_t:s0 tclass=file permissive=0


type=SYSCALL msg=audit(1669033294.816:11840): arch=x86_64 syscall=access success=no exit=EACCES a0=556b86fdb880 a1=1 a2=7ffcedc6a2b0 a3=0 items=0 ppid=447045 pid=640400 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm=sh exe=/usr/bin/bash subj=system_u:system_r:httpd_t:s0 key=(null)              

Hash: sh,httpd_t,httpd_sys_rw_content_t,file,execute

While one suggestion is to use the httpd_unified boolean and refers one to the httpd_selinux about it, that manpage doesn't even mention the boolean, so I cannot enable it with any confidence about what it's doing?  But one also has to wonder if it's too big of a hammer.

For context, this AVC seems to have happened in relation to NextCloud.

# debugfs /dev/dm-7                                                                                                                                                 
debugfs 1.45.6 (20-Mar-2020)
ncheck 3409397
debugfs:  ncheck 3409397
Inode   Pathname
3409397 /lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin/bin/kitinerary-extractor

Comment 1 Zdenek Pytela 2022-12-21 08:51:54 UTC
Brian,

What is the reason having the file labeled as httpd_sys_rw_content_t? Type of the file on the default location is

rhel88# matchpathcon /usr/libexec/kf5/kitinerary-extractor
/usr/libexec/kf5/kitinerary-extractor   system_u:object_r:bin_t:s0

and httpd is allowed to execute it:

rhel88# sesearch -A -s httpd_t -t bin_t -c file -p execute
allow httpd_t base_ro_file_type:file { execute execute_no_trans getattr ioctl lock map open read };
allow httpd_t bin_t:file { execute execute_no_trans getattr ioctl lock map open read };


Other than that, you are right, the boolean seems to be quite powerful and not quite well documented:

rhel88# semanage boolean -l | grep -e ^SELinux -e httpd_unified
SELinux boolean                State  Default Description
httpd_unified                  (off  ,  off)  Unify HTTPD handling of all content files.

It also needs to be troubleshooted why the man page does not mention all httpd booleans.

Comment 2 Brian J. Murrell 2022-12-21 12:15:47 UTC
(In reply to Zdenek Pytela from comment #1)
> Brian,

Hi Zdenek,
 
> What is the reason having the file labeled as httpd_sys_rw_content_t?

I have no reason in particular for that.  Isn't that just the default label for that location?

> Type
> of the file on the default location is
> 
> rhel88# matchpathcon /usr/libexec/kf5/kitinerary-extractor
> /usr/libexec/kf5/kitinerary-extractor   system_u:object_r:bin_t:s0

Which seems quite reasonable.

But do note that the path of this particular kitinerary-extractor is /var/lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin/bin/ as it's bundled (as much as I hate bundling) with nextcloud.

I am aware that kf5-kitinerary-0:22.04.1-1.el8.x86_64 exists in EL8 but I really don't know enough about nextcloud apps to know how/if I can use the above RPM and remove it from the Nextcloud app.  That's probably not even possible.

Perhaps SELinux needs some policy to handle binaries bundled with nextcloud [apps]?  I currently have the following 'bin' directories in /var/lib/nextcloud:

/var/lib/nextcloud/apps/mail/vendor/cerdic/css-tidy/bin
/var/lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin/bin
/var/lib/nextcloud/apps/mail/vendor/amphp/process/bin

Comment 3 Zdenek Pytela 2022-12-21 12:44:44 UTC
Looks like this is the default:

rhel88# matchpathcon /var/lib/nextcloud
/var/lib/nextcloud      system_u:object_r:httpd_sys_rw_content_t:s0

Unfortunately I am not aware of the package tree content, but I'd expect an equivalency rule, e. g.

rhel88# semanage fcontext -a -e /usr/bin /var/lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin
rhel88# restorecon -Rv /var/lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin

is set to assign proper context to files in the directory provided they should be executed from httpd as if they were on the regular path. It needs to be assessed case by case.

Having said that, I don't think there is anything which could be addressed in selinux-policy, but rather in the app or as a local policy at the target system.

Comment 4 Brian J. Murrell 2022-12-21 12:52:36 UTC
(In reply to Zdenek Pytela from comment #3)
> 
> Unfortunately I am not aware of the package tree content,

I provided a few examples in my previous message.  It seems pattern/predictable.

> but I'd expect an
> equivalency rule, e. g.
> 
> rhel88# semanage fcontext -a -e /usr/bin
> /var/lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin

Can this be applied as a wildcard with '*/*' or somesuch in place of the 'christophwurst/kitinerary-bin' since all 3 examples found match that pattern?

> Having said that, I don't think there is anything which could be addressed
> in selinux-policy, but rather in the app

I'm afraid I don't know anything about how to distribute selinux policy updates with app RPMs.  :-(

> or as a local policy at the target
> system.

Yeah, of course.  But then every sysadmin has to [know [how to]] do this.  :-( also.

Comment 5 Zdenek Pytela 2022-12-21 13:42:40 UTC
(In reply to Brian J. Murrell from comment #4)
> (In reply to Zdenek Pytela from comment #3)
> > 
> > Unfortunately I am not aware of the package tree content,
> 
> I provided a few examples in my previous message.  It seems
> pattern/predictable.
> 
> > but I'd expect an
> > equivalency rule, e. g.
> > 
> > rhel88# semanage fcontext -a -e /usr/bin
> > /var/lib/nextcloud/apps/mail/vendor/christophwurst/kitinerary-bin
> 
> Can this be applied as a wildcard with '*/*' or somesuch in place of the
> 'christophwurst/kitinerary-bin' since all 3 examples found match that
> pattern?

I also provided just an example.
Regular expressions (not wildcards) can be used in the semanage-fcontext command file specification.
The actual content of the setting needs to be assessed by someone understanding the content and usage, perhaps making an equivalency of the content root (or all content root patterns) to filesystem root.
Software collections may serve as a good example of equivalency rules when the software is installed into /opt.

> > Having said that, I don't think there is anything which could be addressed
> > in selinux-policy, but rather in the app
> 
> I'm afraid I don't know anything about how to distribute selinux policy
> updates with app RPMs.  :-(
> 
> > or as a local policy at the target
> > system.
> 
> Yeah, of course.  But then every sysadmin has to [know [how to]] do this. 
> :-( also.

I think the package vendor should be contacted.

Comment 6 Brian J. Murrell 2022-12-21 13:46:42 UTC
(In reply to Zdenek Pytela from comment #5)
> I also provided just an example.
> Regular expressions (not wildcards) can be used in the semanage-fcontext
> command file specification.

Ahhh.  That's useful to know.  Thanks!

> I think the package vendor should be contacted.

Meaning the nextcloud developers or the person rolling it into an RPM?  If the latter, that is me, based on work done by others.

Comment 7 Zdenek Pytela 2022-12-21 14:12:37 UTC
(In reply to Brian J. Murrell from comment #6)
> (In reply to Zdenek Pytela from comment #5)
> > I also provided just an example.
> > Regular expressions (not wildcards) can be used in the semanage-fcontext
> > command file specification.
> 
> Ahhh.  That's useful to know.  Thanks!
> 
> > I think the package vendor should be contacted.
> 
> Meaning the nextcloud developers or the person rolling it into an RPM?  If
> the latter, that is me, based on work done by others.

In that case it should not be difficult to include a particular semanage-fcontext command for each subpackage, see

semanage fcontext -a -e / "/var/lib/nextcloud/apps/mail/vendor/c/cc"
mkdir -p /var/lib/nextcloud/apps/mail/vendor/c/cc/usr/bin
touch /var/lib/nextcloud/apps/mail/vendor/c/cc/usr/bin/ls
restorecon -Rv  /var/lib/nextcloud/apps/mail/vendor
Relabeled /var/lib/nextcloud/apps/mail/vendor/c/cc from unconfined_u:object_r:httpd_sys_rw_content_t:s0 to unconfined_u:object_r:root_t:s0
Relabeled /var/lib/nextcloud/apps/mail/vendor/c/cc/usr from unconfined_u:object_r:httpd_sys_rw_content_t:s0 to unconfined_u:object_r:usr_t:s0
Relabeled /var/lib/nextcloud/apps/mail/vendor/c/cc/usr/bin from unconfined_u:object_r:httpd_sys_rw_content_t:s0 to unconfined_u:object_r:bin_t:s0
Relabeled /var/lib/nextcloud/apps/mail/vendor/c/cc/usr/bin/ls from unconfined_u:object_r:httpd_sys_rw_content_t:s0 to unconfined_u:object_r:bin_t:s0

but the actual usage needs to be adjusted based on the subpackage content.

Comment 8 Zdenek Pytela 2023-02-01 07:24:25 UTC
As no new information appeared during the past weeks, we are going to close this bug. If you need to pursue this matter further, feel free to reopen this bug and attach the needed information.


Note You need to log in before you can comment on or make changes to this bug.