Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1063503 - New cron file label seems to be a problem
Summary: New cron file label seems to be a problem
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: selinux-policy
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Miroslav Grepl
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-02-10 21:20 UTC by Bruno Wolff III
Modified: 2014-11-19 14:42 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-11-19 14:42:19 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Bruno Wolff III 2014-02-10 21:20:33 UTC
Description of problem:
I am running a cron job as a normal user. The file gets labelled unconfined_u:object_r:user_cron_spool_t:s0 by default. However when I leave that label my cronjob doesn't run. (The only entry is "* * * * *	/usr/bin/getmail".
I get the following error logged by cron:
Feb 10 14:48:54 cerberus crond[3055]: (bruno) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 file_context=unconfined_u:object_r:user_cron_spool_t:s0 (/var/spool/cron/bruno)

If I label the cron file unconfined_u:object_r:usr_t then things work. I tried this because on another rawhide machine where I hadn't updated a cron file in a while it was labelled usr_t. So I thought it would be worth testing this on the machine where I was seeing the problem.

(I do have some local policies that allow some extra things to work, mostly involving qmail. But I don't think add on modules can normally make things more restrictive.)

I run the targeted policy (though I also have minimal and mls policies installed).

Version-Release number of selected component (if applicable):
selinux-policy-targeted-3.13.1-22.fc21.noarch

Comment 1 Miroslav Grepl 2014-02-11 12:01:40 UTC
Try to execute

#setsebool cron_userdomain_transition on

Comment 2 Bruno Wolff III 2014-02-11 13:00:47 UTC
I tested that and that seemed to fix things. The puzzling thing is when I tried turning it back off, things kept working. (Though I didn't reboot or restart cronie when I did that.) I had recently upgraded the machine from f20 to rawhide and had an issue where some posttrans scripts might not have been run. It looks like cron_userdomain_transition is new to rawhide so if a default of on was set in a posttran script, that could explain why I ran into the problem.

Comment 3 Bruno Wolff III 2014-02-11 13:23:35 UTC
I checked changing cron_userdomain_transition and restarting crond after each change and when I did that I did need to have it on for things to work.

Comment 4 Miroslav Grepl 2014-02-11 16:43:55 UTC
Dominick,
what was the purpose of this change? I mean this boolean.

Comment 5 Dominick Grift 2014-02-12 08:25:18 UTC
The user_cron_spool_t is an important part of this functionality by changing the label of the "domain entry file" to usr_t you break the functionality.

Basically crond uses the crontab's as an entry point to a the target domain specified by policy.

So were just saying:

if cron_userdomain_transition is off then:

cronjob_t user_cron_spool_t:file entrypoint;

and if it is on then:

myuser_t user_cron_spool_t:file entrypoint;

Crond computes in which domain to run the cronjob by looking up which transitions are available.

user_cron_spool_t is the entrypoint to the specified target domain and so it is an important port of the functionality.

So the bug is in the fact that OP changed the type of the crontab from user_cron_spool_t to usr_t. We need to figure out why he wanted/needed to do that, because it should really stay user_cron_spool_t.

Comment 6 Dominick Grift 2014-02-12 08:39:41 UTC
By the way if its not done already: you might want to default to cron_userdomain_transition to on by default in Targeted policy, and to off by default in MLS policy. (at least that is probably what i would do, its a matter of taste i guess though)

Comment 7 Miroslav Grepl 2014-02-12 08:45:13 UTC
Yes because I have a problem with

Feb 10 14:48:54 cerberus crond[3055]: (bruno) Unauthorized SELinux context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 file_context=unconfined_u:object_r:user_cron_spool_t:s0 (/var/spool/cron/bruno)

How do we go to tell a user turn on the boolean?

Comment 8 Dominick Grift 2014-02-12 09:33:32 UTC
We should not have to tell a user to set the boolean. I do not see what that message implies.

It should be as simple as :

if the cron_userdomain_transition is set to on then run the job in the calling user domain, else run it in cronjob_t.

So i am not sure why its complaining about unauthorized SELinux context. Where does it it get that context from? (maybe default_contexts?)

I guess i could try and install rawhide to see if i can reproduce. I haven't heard of similar issues with other distros using this solution.

Comment 9 Miroslav Grepl 2014-02-12 10:05:07 UTC
Yes it comes from default user contexts. For example

system_r:crond_t:s0		unconfined_r:unconfined_t:s0

so if there is a cronjob then crond_t looks here for this info and sets "unconfined_t". But of course crond_t does SELinux checks and this is a reason why we get it.

Comment 10 Miroslav Grepl 2014-02-12 10:07:15 UTC
Which of course does not work with this rawhide feature.

Comment 11 Dominick Grift 2014-02-12 11:02:00 UTC
I think i figured out the issues

First issue is that the default contexts differ with refpolicy (both for users and default_contexts)

The second is that in Fedora file_unconfined_type cannot "entrypoint" of all file_type (why?) where as in refpolicy it can.

So in fedora we need some modifications

We need to explicitly allow unconfined_cronjob_t user_cron_spool_t:file entrypoint; if cron_userdomain_transition=1

and we need to edit the /etc/selinux/targeted/contexts/users/* to make it first try *.cronjob_t and then $USERDOMAiN

we also need to adjust /etc/selinux/targeted/default_contexts to include unconfined_r:unconfined_cronjob_t (and others)

Ill make a screencast of my manual test for reference purposes

Comment 12 Dominick Grift 2014-02-12 11:15:36 UTC
here is a quick rundown of the issue and proof of concept:

https://www.youtube.com/watch?v=V3VXePNuUv8

Please try it out. if questions let me know

(might still be processing)

Comment 13 Miroslav Grepl 2014-02-12 12:42:51 UTC
(In reply to Dominick Grift from comment #11)
> I think i figured out the issues
> 
> First issue is that the default contexts differ with refpolicy (both for
> users and default_contexts)
> 
> The second is that in Fedora file_unconfined_type cannot "entrypoint" of all
> file_type (why?) where as in refpolicy it can.

Yes, rawhide entrypoint changes.

> 
> So in fedora we need some modifications
> 
> We need to explicitly allow unconfined_cronjob_t user_cron_spool_t:file
> entrypoint; if cron_userdomain_transition=1
> 
> and we need to edit the /etc/selinux/targeted/contexts/users/* to make it
> first try *.cronjob_t and then $USERDOMAiN
> 
> we also need to adjust /etc/selinux/targeted/default_contexts to include
> unconfined_r:unconfined_cronjob_t (and others)

Well I will need to re-check all this new concept and play with it more to see if we can get it working in Fedora(also MLS).

> 
> Ill make a screencast of my manual test for reference purposes

Comment 14 Bruno Wolff III 2014-02-12 13:31:31 UTC
A correction for comment 5. I only switched to usr_t on the machine where I noticed the problem, after the user_cron_spool_t label was causing a problem. usr_t actually seemed to work as a work around. I tried that label because another rawhide machine still had a cron file with a usr_t label, as I apparently hadn't done a full relabel since the change on that machine.

Comment 15 Miroslav Grepl 2014-03-07 09:18:12 UTC
Ok going thru this bug and sure it can be fixed how Dominick wrote.

But basically I am not big fan of this concept. I believe we want to see user cronjobs running in a userdomain for all cases. I don't understand why we would make a difference. Also cronjob_t caused issues on MLS systems. It was a reason why we switched to have a userdomain.

Comment 16 Miroslav Grepl 2014-03-07 15:45:05 UTC
I am going to turn on the boolean by default but keep this bug opened to discuss.


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