refpolicy patch: samba enhancements
I apologize if I'm not doing this right, I'm kinda new at this...
I have made some changes to the SELinux policy for our intranet servers that I thought might be useful to a broader audience. Included below is a patch to the latest refpolicy. This has been tested on the Gentoo systems we have here; I don't have easy access to other SELinux systems at the moment. It does the following:
* Updates samba_stream_connect_winbind to match the observed behavior of winbind
* Gives winbind access to delete its own sockets
* Gives nmbd access to fully manage (i.e. rename) log files
* Adds a tunable that lets samba create home directories via pam_mkhomedir
modules/services/samba.if +9 -9
@@ -484,17 +484,19 @@ ## </param> # interface(`samba_stream_connect_winbind',` - ifdef(`distro_redhat',` - gen_require(` - type samba_var_t, winbind_t, winbind_var_run_t; - ') + gen_require(` + type samba_var_t, winbind_t, winbind_var_run_t; + ') - files_search_pids($1) - allow $1 samba_var_t:dir search_dir_perms; - stream_connect_pattern($1,winbind_var_run_t,winbind_var_run_t,winbind_t) - ',` + files_search_pids($1) + allow $1 samba_var_t:dir search_dir_perms; + stream_connect_pattern($1,winbind_var_run_t,winbind_var_run_t,winbind_t) + + ifdef(`distro_redhat',`', ` gen_require(` - type winbind_t, winbind_tmp_t; + type winbind_tmp_t; ') # the default for the socket is (poorly named):
modules/services/samba.te +15 -1
@@ -59,6 +59,13 @@ ## </desc> gen_tunable(samba_share_nfs,false) +## <desc> +## <p> +## Allow samba to create new home directories (e.g. via PAM) +## </p> +## </desc> +gen_tunable(samba_create_home_dirs,false) + type nmbd_t; type nmbd_exec_t; init_daemon_domain(nmbd_t,nmbd_exec_t)
@@ -379,6 +386,14 @@ unprivuser_home_dir_filetrans_home_content(nmbd_t, { file dir }) ') +tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t) + + allow smbd_t self:capability chown; +') ######################################## # # nmbd Local policy
@@ -404,7 +419,7 @@ read_files_pattern(nmbd_t,samba_etc_t,samba_etc_t) manage_dirs_pattern(nmbd_t,samba_log_t,samba_log_t) -append_files_pattern(nmbd_t,samba_log_t,samba_log_t) +manage_files_pattern(nmbd_t,samba_log_t,samba_log_t) allow nmbd_t samba_log_t:file unlink; read_files_pattern(nmbd_t,samba_log_t,samba_log_t)
@@ -675,6 +690,7 @@ manage_dirs_pattern(winbind_t,winbind_tmp_t,winbind_tmp_t) manage_files_pattern(winbind_t,winbind_tmp_t,winbind_tmp_t) +manage_sock_files_pattern(winbind_t,winbind_tmp_t,winbind_tmp_t) files_tmp_filetrans(winbind_t, winbind_tmp_t, { file dir }) manage_files_pattern(winbind_t,winbind_var_run_t,winbind_var_run_t)
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 8 lines · Mike Edenfield
I apologize if I'm not doing this right, I'm kinda new at this...
I have made some changes to the SELinux policy for our intranet servers that I thought might be useful to a broader audience. Included below is a patch to the latest refpolicy. This has been tested on the Gentoo systems we have here; I don't have easy access to other SELinux systems at the moment. It does the following:
Quoted 8 lines
* Updates
samba_stream_connect_winbindto match the observed behavior of winbind* Gives winbind access to delete its own sockets
* Gives nmbd access to fully manage (i.e. rename) log files
* Adds a tunable that lets samba create home directories via
pam_mkhomedir
A few notes:
Quoted 15 lines
Index: policy/modules/services/samba.if
===================================================================modules/services/samba.if +3
-4@@ -484,17 +484,19 @@ ## </param> # interface(`samba_stream_connect_winbind',` - ifdef(`distro_redhat',` - gen_require(` - type samba_var_t, winbind_t, winbind_var_run_t; - ') + gen_require(` + type samba_var_t, winbind_t, winbind_var_run_t; + ')
modules/services/samba.if line 495
Quoted 10 lines
modules/services/samba.if +5
-4- files_search_pids($1) - allow $1 samba_var_t:dir search_dir_perms; - stream_connect_pattern($1,winbind_var_run_t,winbind_var_run_t,winbind_t) - ',` + files_search_pids($1) + allow $1 samba_var_t:dir search_dir_perms; + stream_connect_pattern($1,winbind_var_run_t,winbind_var_run_t,winbind_t) + + ifdef(`distro_redhat',`', `
This can be ifndef(distro_redhat',
modules/services/samba.if line 498
Quoted 3 lines
modules/services/samba.if +3
-0+tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t)
I think we want this to be unprivuser_create_home_dirs(), which would need to be added.
Quoted 7 lines
modules/services/samba.if +3
-0+ + allow smbd_t self:capability chown; +')
modules/services/samba.if line 425
Quoted 8 lines
modules/services/samba.if +1
-1@@ -404,7 +419,7 @@ read_files_pattern(nmbd_t,samba_etc_t,samba_etc_t) manage_dirs_pattern(nmbd_t,samba_log_t,samba_log_t) -append_files_pattern(nmbd_t,samba_log_t,samba_log_t) +manage_files_pattern(nmbd_t,samba_log_t,samba_log_t) allow nmbd_t samba_log_t:file unlink; read_files_pattern(nmbd_t,samba_log_t,samba_log_t)
If the goal is just to add a rename permission onto nmbd, then that permission should be added explicitly. Manage will allow it to delete the log, which we don't want, if we don't have to.
Signature · 9 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 8 lines · Christopher J. PeBenito
modules/services/samba.te line 391
Quoted 3 lines · Mike Edenfield
modules/services/samba.te +3
-0+tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t)I think we want this to be
unprivuser_create_home_dirs(), which would need to be added.
That was my first instinct but I didn't see one already present, so I just copied what I found for oddjob_mkhomedir.
I'll define a new interface for this -- I assume that's probably a separate patch? And I should convert the sysadm role and oddjob type to use the interface?
Quoted 8 lines
Quoted 8 lines
modules/services/samba.te +1
-1@@ -404,7 +419,7 @@ read_files_pattern(nmbd_t,samba_etc_t,samba_etc_t) manage_dirs_pattern(nmbd_t,samba_log_t,samba_log_t) -append_files_pattern(nmbd_t,samba_log_t,samba_log_t) +manage_files_pattern(nmbd_t,samba_log_t,samba_log_t) allow nmbd_t samba_log_t:file unlink;
Quoted 5 lines
modules/services/samba.te line 425
Quoted 1 line
modules/services/samba.te +0
-0read_files_pattern(nmbd_t,samba_log_t,samba_log_t)If the goal is just to add a rename permission onto nmbd, then that permission should be added explicitly. Manage will allow it to delete the log, which we don't want, if we don't have to.
Actually, I missed a line when I was reapplying my patches to do svn diffs; the nmbd_t type already has unlink permissions for the type, just not rename, so it seemed that manage_files was the correct thing -- it should let me get rid of the next line as well.
New patch coming in a bit.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 7 lines · Mike Edenfield
Quoted 6 lines · Christopher J. PeBenito
Quoted 3 lines · Mike Edenfield
modules/services/samba.te +3
-0+tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t)
Quoted 8 lines
Quoted 2 lines
I think we want this to be
unprivuser_create_home_dirs(), which would need to be added.That was my first instinct but I didn't see one already present, so I just copied what I found for
oddjob_mkhomedir.I'll define a new interface for this -- I assume that's probably a separate patch?
No, its fine to include it in this one.
Quoted 2 lines
And I should convert the sysadm role and oddjob type to
use the interface?
Sysadm is fine as is, since it already has broad powers for managing users. I'm not sure about the oddjob usage; you'd have to check the programs features to see if it does other things in addition to just creating the dirs.
Signature · 9 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 14 lines · Christopher J. PeBenito
Quoted 10 lines · Mike Edenfield
Quoted 6 lines · Christopher J. PeBenito
modules/services/samba.te line 391
Quoted 3 lines · Mike Edenfield
modules/services/samba.te +3
-0+tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t)I think we want this to be
unprivuser_create_home_dirs(), which would need to be added.That was my first instinct but I didn't see one already present, so I just copied what I found for
oddjob_mkhomedir.I'll define a new interface for this -- I assume that's probably a separate patch?
No, its fine to include it in this one.
Quoted 8 lines
Quoted 2 lines
And I should convert the sysadm role and oddjob type to
use the interface?Sysadm is fine as is, since it already has broad powers for managing users. I'm not sure about the oddjob usage; you'd have to check the programs features to see if it does other things in addition to just creating the dirs.
The reason I mentioned it is because both sysadm and oddjob use the same two interfaces I put in the samba patch. In fact, I don't see anywhere in the ref policy that manage_home_dirs is ever used without the filetrans interface right before it. This leads me to suggest that I just add a call to home_filetrans_home_dir inside manage_home_dirs, since it seems to be almost a prerequisite anyway.
I just checked oddjob -- it calls a series of related interfaces, which sysadm and the samba policy already also called, so perhaps all of these can be put into a "create_home_directories" interface and simplify the policy in three places:
unprivuser_home_filetrans_home_dir(oddjob_mkhomedir_t) unprivuser_manage_home_content_dirs(oddjob_mkhomedir_t) unprivuser_manage_home_content_files(oddjob_mkhomedir_t) unprivuser_manage_home_dirs(oddjob_mkhomedir_t) unprivuser_home_dir_filetrans_home_content(oddjob_mkhomedir_t,notdevfile_class_set)
--Mike
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 16 lines · Christopher J. PeBenito
Quoted 5 lines · Mike Edenfield
Quoted 4 lines · Christopher J. PeBenito
Quoted 3 lines · Mike Edenfield
modules/services/samba.te +3
-0+tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t)Quoted 7 lines
Quoted 2 lines
I think we want this to be
unprivuser_create_home_dirs(), which would need to be added.That was my first instinct but I didn't see one already present, so I just copied what I found for
oddjob_mkhomedir.I'll define a new interface for this -- I assume that's probably a separate patch?
No, its fine to include it in this one.
Quoted 8 lines
Quoted 2 lines
And I should convert the sysadm role and oddjob type to
use the interface?Sysadm is fine as is, since it already has broad powers for managing users. I'm not sure about the oddjob usage; you'd have to check the programs features to see if it does other things in addition to just creating the dirs.
Oddjob creates the directory and copies /etc/skel
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 105 lines · Mike Edenfield
I apologize if I'm not doing this right, I'm kinda new at this...
I have made some changes to the SELinux policy for our intranet servers that I thought might be useful to a broader audience. Included below is a patch to the latest refpolicy. This has been tested on the Gentoo systems we have here; I don't have easy access to other SELinux systems at the moment. It does the following:
* Updates
samba_stream_connect_winbindto match the observed behavior of winbind* Gives winbind access to delete its own sockets
* Gives nmbd access to fully manage (i.e. rename) log files
* Adds a tunable that lets samba create home directories via
pam_mkhomedirIndex: policy/modules/services/samba.if
===================================================================modules/services/samba.if (working copy) renamed from modules/services/samba.if (revision 2758) +9
-9@@ -484,17 +484,19 @@ ## </param> # interface(`samba_stream_connect_winbind',` - ifdef(`distro_redhat',` - gen_require(` - type samba_var_t, winbind_t, winbind_var_run_t; - ') + gen_require(` + type samba_var_t, winbind_t, winbind_var_run_t; + ') - files_search_pids($1) - allow $1 samba_var_t:dir search_dir_perms; - stream_connect_pattern($1,winbind_var_run_t,winbind_var_run_t,winbind_t) - ',` + files_search_pids($1) + allow $1 samba_var_t:dir search_dir_perms; + stream_connect_pattern($1,winbind_var_run_t,winbind_var_run_t,winbind_t) + + ifdef(`distro_redhat',`', ` gen_require(` - type winbind_t, winbind_tmp_t; + type winbind_tmp_t; ') # the default for the socket is (poorly named):Index: policy/modules/services/samba.te
===================================================================modules/services/samba.te (working copy) renamed from modules/services/samba.te (revision 2758) +15
-1@@ -59,6 +59,13 @@ ## </desc> gen_tunable(samba_share_nfs,false) +## <desc> +## <p> +## Allow samba to create new home directories (e.g. via PAM) +## </p> +## </desc> +gen_tunable(samba_create_home_dirs,false) + type nmbd_t; type nmbd_exec_t; init_daemon_domain(nmbd_t,nmbd_exec_t)@@ -379,6 +386,14 @@ unprivuser_home_dir_filetrans_home_content(nmbd_t, { file dir }) ') +tunable_policy(`samba_create_home_dirs',` + unprivuser_home_filetrans_home_dir(smbd_t) + unprivuser_manage_home_dirs(smbd_t) + + allow smbd_t self:capability chown; +') ######################################## # # nmbd Local policy@@ -404,7 +419,7 @@ read_files_pattern(nmbd_t,samba_etc_t,samba_etc_t) manage_dirs_pattern(nmbd_t,samba_log_t,samba_log_t) -append_files_pattern(nmbd_t,samba_log_t,samba_log_t) +manage_files_pattern(nmbd_t,samba_log_t,samba_log_t) allow nmbd_t samba_log_t:file unlink; read_files_pattern(nmbd_t,samba_log_t,samba_log_t)@@ -675,6 +690,7 @@ manage_dirs_pattern(winbind_t,winbind_tmp_t,winbind_tmp_t) manage_files_pattern(winbind_t,winbind_tmp_t,winbind_tmp_t) +manage_sock_files_pattern(winbind_t,winbind_tmp_t,winbind_tmp_t) files_tmp_filetrans(winbind_t, winbind_tmp_t, { file dir }) manage_files_pattern(winbind_t,winbind_var_run_t,winbind_var_run_t)Signature · 5 lines
-- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Could you do this with pam_oddjob_mkhomedir without having to add the privs. I think this is a better solution.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iEYEARECAAYFAkiA1fwACgkQrlYvE4MpobNGsACfUVTxg3r9Z5BWOcDvyFhhbdyt QKMAoJHXtwqhlM2dAIsizZ2bhvjnKtrz
=E5Av
-----END PGP SIGNATURE-----
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 8 lines · Daniel J Walsh
Quoted 7 lines · Mike Edenfield
I apologize if I'm not doing this right, I'm kinda new at this...
I have made some changes to the SELinux policy for our intranet servers that I thought might be useful to a broader audience. Included below is a patch to the latest refpolicy. This has been tested on the Gentoo systems we have here; I don't have easy access to other SELinux systems at the moment. It does the following:
[...]
Quoted 4 lines
Quoted 1 line
* Adds a tunable that lets samba create home directories via
pam_mkhomedirCould you do this with
pam_oddjob_mkhomedirwithout having to add the privs. I think this is a better solution.
What if you don't have oddjob? It doesn't hurt to have the perms in a tunable. It could be put in a ifndef distro_redhat, if samba in fedora/rh requires pam_oddjob_mkhomedir.
Signature · 9 lines
Chris PeBenito Tresys Technology, LLC (410) 290-1411 x150 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 10 lines · Christopher J. PeBenito
Quoted 8 lines · Daniel J Walsh
Quoted 7 lines · Mike Edenfield
I apologize if I'm not doing this right, I'm kinda new at this...
I have made some changes to the SELinux policy for our intranet servers that I thought might be useful to a broader audience. Included below is a patch to the latest refpolicy. This has been tested on the Gentoo systems we have here; I don't have easy access to other SELinux systems at the moment. It does the following:
[...]
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
* Adds a tunable that lets samba create home directories via
pam_mkhomedirCould you do this with
pam_oddjob_mkhomedirwithout having to add the privs. I think this is a better solution.What if you don't have oddjob? It doesn't hurt to have the perms in a tunable. It could be put in a ifndef
distro_redhat, if samba in fedora/rh requirespam_oddjob_mkhomedir.
If this is the preferable way for RH users to set up samba, would this be an appropriate solution?
tunable_policy(samba_create_home_dirs',
ifdef(distro_redhat',
refpolicywarn(`Use of samba_create_home_dirs is discouraged.
Please use pam_oddjob_mkhomedir instead.')
', `
unprivuser_create_home_dirs(smbd_t)
allow smbd_t self:capability chown;
')')
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 10 lines · Christopher J. PeBenito
Quoted 8 lines · Daniel J Walsh
Quoted 7 lines · Mike Edenfield
I apologize if I'm not doing this right, I'm kinda new at this...
I have made some changes to the SELinux policy for our intranet servers that I thought might be useful to a broader audience. Included below is a patch to the latest refpolicy. This has been tested on the Gentoo systems we have here; I don't have easy access to other SELinux systems at the moment. It does the following:
[...]
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
* Adds a tunable that lets samba create home directories via
pam_mkhomedirCould you do this with
pam_oddjob_mkhomedirwithout having to add the privs. I think this is a better solution.What if you don't have oddjob? It doesn't hurt to have the perms in a tunable. It could be put in a ifndef
distro_redhat, if samba in fedora/rh requirespam_oddjob_mkhomedir.
I have more of a problem with pam_mkhomedir from login programs since samba can currently read/write homedirs with a boolean. It is not as big a deal. oddjob just breaks things out the way SELinux likes it. Pam modure requests a service create a homedir. Service execs a job to create the homedir. Each process gets a different context.
gentoo should look into it.
But I am fine with adding the patch. pam_mkhomedir does not work well currently with ssh, locallogin, gdm on Fedora platform.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 2 lines · Daniel J Walsh
Could you do this with
pam_oddjob_mkhomedirwithout having to add the privs. I think this is a better solution.
Is this a Redhat-specific thing? I'm running Gentoo, and while I have a "pam_mkhomedir" module, I don't have anything called oddjob anywhere.
I'm using the pam_mkhomedir module, but it's running under the nmbd context, so that's where I had to put the rules. There isn't a way to get the PAM module to use a different context than the process it's loaded into, is there?
--Mike
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.