Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 373673 - portage fails to emerge with /usr portage on nfs with selinux
Summary: portage fails to emerge with /usr portage on nfs with selinux
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Interface (emerge) (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: SE Linux Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-01 06:31 UTC by Matthew Thode ( prometheanfire )
Modified: 2011-07-12 00:43 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2011-07-01 06:31:31 UTC
emerge fails if running from nfs while selinux is enforcing

Reproducible: Always

Steps to Reproduce:
mount /usr/portage with nfs
set selinux to enforcing
emerge something (pango was my test)
Actual Results:  
>>> Emerging (1 of 1) x11-libs/pango-1.28.4
Traceback (most recent call last):
  File "/usr/lib64/portage/pym/_emerge/EbuildFetcher.py", line 113, in _spawn
    allow_missing_digests=False):
  File "/usr/lib64/portage/pym/portage/package/ebuild/fetch.py", line 582, in fetch
    vfs_stat = os.statvfs(mysettings["DISTDIR"])
OSError: [Errno 13] Permission denied: '/usr/portage/distfiles'

Expected Results:  
emerge finds the files

I have tried mounting with the context=system_u:object_r:portage_ebuild_t and rootcontext=system_u:object_r:portage_ebuild_t as per https://www.centos.org/docs/5/html/Deployment_Guide-en-US/sec-sel-admincontrol.html#rhlcommon-section-0097  but it still mounts as system_u:object_r:nfs_t
Comment 1 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2011-07-01 06:32:24 UTC
I have tried with this line both commented and uncommented.

FEATURES="buildpkg webrsync-gpg usersandbox collision-protect userpriv userfetch fixlafiles news parallel-fetch unmerge-orphans unknown-features-warn usersync strict fixpackages fail-clean"
Comment 2 SpanKY gentoo-dev 2011-07-03 16:36:25 UTC
if the OS is giving you "permission denied", there's really nothing portage can do about it
Comment 3 Sven Vermeulen 2011-07-03 18:24:57 UTC
this is a selinux policy issue, not portage. I asked to create a bugreport so that we can follow this up on the selinux policy development (part of gentoo hardened).

Please reopen and reassign to selinux? can't do that myself currently yet
Comment 4 Sven Vermeulen 2011-07-04 17:48:41 UTC
Preliminary tests show that we can go two ways here.

Either we make a small adjustment to allow mounting with the context= option. In this case, the command to mount the NFS file system could be:

~# mount -t nfs -o context=system_u:object_r:portage_ebuild_t nfs_host:/nfs/portage /usr/portage

The only additional "privilege" required here is
  allow mount_t portage_ebuild_t:filesystem relabelfrom;

However, this does require that each specific location portage provides (/usr/portage as portage_ebuild_t and /usr/portage/distfiles/*src as portage_srcrepo_t) gets separate mount points as they require separate labels.

What I will do is add a SELinux boolean "gentoo_portage_allow_nfs" which allows the appropriate domains to manage nfs_t files. You can then still see if you want to allow this (broad) privilege, or rather use a more detailed mount-mechanism as described earlier.
Comment 5 Matthew Thode ( prometheanfire ) archtester Gentoo Infrastructure gentoo-dev Security 2011-07-05 04:28:13 UTC
(In reply to comment #4)
> Preliminary tests show that we can go two ways here.
> 
> Either we make a small adjustment to allow mounting with the context= option.
> In this case, the command to mount the NFS file system could be:
> 
> ~# mount -t nfs -o context=system_u:object_r:portage_ebuild_t
> nfs_host:/nfs/portage /usr/portage
> 
> The only additional "privilege" required here is
>   allow mount_t portage_ebuild_t:filesystem relabelfrom;
> 
> However, this does require that each specific location portage provides
> (/usr/portage as portage_ebuild_t and /usr/portage/distfiles/*src as
> portage_srcrepo_t) gets separate mount points as they require separate labels.
> 
> What I will do is add a SELinux boolean "gentoo_portage_allow_nfs" which allows
> the appropriate domains to manage nfs_t files. You can then still see if you
> want to allow this (broad) privilege, or rather use a more detailed
> mount-mechanism as described earlier.

I personally prefer the mount based approach, as that seems more 'secure'.
Comment 6 Sven Vermeulen 2011-07-05 16:11:26 UTC
True, but might be more challenging to manage. I'll take a look at why I need to allow _relabelfrom_ portage_ebuild_t rather than _relabelto_ portage_ebuild_t for the mount option to work...
Comment 7 Sven Vermeulen 2011-07-07 18:53:40 UTC
The necessary fixes for this should now be available in the hardened-dev overlay
Comment 8 Sven Vermeulen 2011-07-11 20:31:44 UTC
Is in portage tree (sec-policy/selinux-base-policy-2.20101213-r18)
Comment 9 Anthony Basile gentoo-dev 2011-07-12 00:43:20 UTC
And there was much rejoicing!