Hi Bill,

Good news.

The "+" will add to any existing categories already given to the login, which in your initial case was SystemLow-SystemHigh, so had no effect. If it was initially SystemLow then it would have done the desired thing.

For platforms newer than CentOS6/RHEL6, then you can make the user_t domain MCS constrained with:

[root@laptop ~]# cat mcsconstrainedusers.te
policy_module(mcsconstrainedusers, 1.0.0)

gen_require(`
  type user_t;
')

mcs_constrained(user_t);

Compiling this under Fedora 25 gave a bunch of warnings, but the module installed OK and gave the desired effect. I've not had time to look into the warnings, sorry.

[root@laptop ~]# make -f /usr/share/selinux/devel/Makefile
/usr/share/selinux/devel/include/contrib/container.if:14: Error: duplicate definition of container_runtime_domtrans(). Original definition on 14.
/usr/share/selinux/devel/include/contrib/container.if:40: Error: duplicate definition of container_runtime_run(). Original definition on 40.
<snip>...
/usr/share/selinux/devel/include/contrib/container.if:589: Error: duplicate definition of docker_spc_stream_connect(). Original definition on 589.
/usr/share/selinux/devel/include/contrib/container.if:603: Error: duplicate definition of container_spc_read_state(). Original definition on 603.
Compiling targeted mcsconstrainedusers module
/usr/bin/checkmodule:  loading policy configuration from tmp/mcsconstrainedusers.tmp
/usr/bin/checkmodule:  policy configuration loaded
/usr/bin/checkmodule:  writing binary representation (version 17) to tmp/mcsconstrainedusers.mod
Creating targeted mcsconstrainedusers.pp policy package
rm tmp/mcsconstrainedusers.mod tmp/mcsconstrainedusers.mod.fc

[root@laptop ~]# semodule -i mcsconstrainedusers.pp
[root@laptop ~]#

Cheers

Phil



Inactive hide details for Bill Durant ---30/05/2017 07:01:42---Hello Phil: Setting the categories instead of adding them with tBill Durant ---30/05/2017 07:01:42---Hello Phil: Setting the categories instead of adding them with the "+" worked!

From: Bill Durant <littus@icloud.com>
To: Philip Seeley <pseeley@au1.ibm.com>
Cc: littus@icloud.com, selinux@lists.fedoraproject.org
Date: 30/05/2017 07:01
Subject: Re: Controlling execution of Java JAR files with SELinux RBAC





Hello Phil:

Setting the categories instead of adding them with the "+" worked!

So it sounds like the chcat "+" option is not working as expected on CentOS 6.9.  Do you concur?

Thank you for your help Phil.

The following series of steps show that it now works as expected:

# uname -a

Linux es300h 2.6.32-696.1.1.el6.x86_64 #1 SMP Tue Apr 11 17:13:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release
CentOS release 6.9 (Final)

# semanage user -l

                Labeling   MLS/       MLS/                         
SELinux User    Prefix     MCS Level  MCS Range                      SELinux Roles

git_shell_u     user       s0         s0                             git_shell_r
green_u         user       s0         s0                             green_r
guest_u         user       s0         s0                             guest_r
red_u           user       s0         s0                             red_r
root            user       s0         s0-s0:c0.c1023                 staff_r sysadm_r system_r unconfined_r
staff_u         user       s0         s0-s0:c0.c1023                 staff_r sysadm_r system_r unconfined_r
sysadm_u        user       s0         s0-s0:c0.c1023                 sysadm_r
system_u        user       s0         s0-s0:c0.c1023                 system_r unconfined_r
unconfined_u    user       s0         s0-s0:c0.c1023                 system_r unconfined_r
user_u          user       s0         s0                             user_r
xguest_u        user       s0         s0                             xguest_r

# semanage user -m -r s0-s0:c0.c1023 user_u

# semanage user -l

                Labeling   MLS/       MLS/                         
SELinux User    Prefix     MCS Level  MCS Range                      SELinux Roles

git_shell_u     user       s0         s0                             git_shell_r
green_u         user       s0         s0                             green_r
guest_u         user       s0         s0                             guest_r
red_u           user       s0         s0                             red_r
root            user       s0         s0-s0:c0.c1023                 staff_r sysadm_r system_r unconfined_r
staff_u         user       s0         s0-s0:c0.c1023                 staff_r sysadm_r system_r unconfined_r
sysadm_u        user       s0         s0-s0:c0.c1023                 sysadm_r
system_u        user       s0         s0-s0:c0.c1023                 system_r unconfined_r
unconfined_u    user       s0         s0-s0:c0.c1023                 system_r unconfined_r
user_u          user       s0         s0-s0:c0.c1023                 user_r
xguest_u        user       s0         s0                             xguest_r

# cat /etc/selinux/targeted/setrans.conf
#
# Multi-Category Security translation table for SELinux
#
# Uncomment the following to disable translation libary
# disable=1
#
# Objects can be categorized with 0-1023 categories defined by the admin.
# Objects can be in more than one category at a time.
# Categories are stored in the system as c0-c1023.  Users can use this
# table to translate the categories into a more meaningful output.
# Examples:
# s0:c0=CompanyConfidential
# s0:c1=PatientRecord
# s0:c2=Unclassified
# s0:c3=TopSecret
# s0:c1,c3=CompanyConfidentialRedHat
s0:c0=NetworkAdministrator
s0:c1=Operator
s0=SystemLow
s0-s0:c0.c1023=SystemLow-SystemHigh
s0:c0.c1023=SystemHigh

# service mcstrans restart
Stopping mcstransd:                                        [  OK  ]
Starting mcstransd:                                        [  OK  ]

# chcat -L
s0:c0                          NetworkAdministrator
s0:c1                          Operator
s0                             SystemLow
s0-s0:c0.c1023                 SystemLow-SystemHigh
s0:c0.c1023                    SystemHigh

# useradd foo

# useradd bar

# passwd foo
Changing password for user foo.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

# passwd bar
Changing password for user bar.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

# semanage login -a foo

# semanage login -a bar

# chcat -l -- c0 foo

# chcat -l -- c1 bar

# semanage login -l

Login Name                SELinux User              MLS/MCS Range           

__default__               unconfined_u              SystemLow-SystemHigh    
bar                       user_u                    SystemLow-Operator      
foo                       user_u                    SystemLow-NetworkAdministrator
root                      unconfined_u              SystemLow-SystemHigh    
system_u                  system_u                  SystemLow-SystemHigh    

# chcat -L -l foo bar
foo: NetworkAdministrator
bar: Operator

# chcat -- +NetworkAdministrator /usr/local/soup/bin/foo.jar

# ls -Z /usr/local/soup/bin/foo.jar
-rwxr-xr-x. admin admin system_u:object_r:bin_t:NetworkAdministrator /usr/local/soup/bin/foo.jar

Now as the Linux user, foo, it works as expected:

$ whoami
foo

$ id -Z
user_u:user_r:user_t:SystemLow-NetworkAdministrator

$ java -jar /usr/local/soup/bin/foo.jar

Hello from the foo application

Now as the Linux user, bar, it also works as expected:

$ whoami
bar

$ id -Z
user_u:user_r:user_t:SystemLow-Operator

$ java -jar /usr/local/soup/bin/foo.jar
Error: Unable to access jarfile /usr/local/soup/bin/foo.jar

Regards,

Bill

On 05/28/2017 05:22 PM, Philip Seeley wrote: