<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5024703430482213163</id><updated>2011-09-12T16:20:15.647-07:00</updated><category term='Policy'/><category term='Pam'/><category term='Newrole'/><category term='FAQ'/><category term='Youtube'/><category term='SU'/><category term='TE'/><category term='mystaff'/><category term='Sepermit'/><category term='MLS'/><category term='Conclusion'/><category term='Booleans'/><category term='Confined'/><category term='Users'/><category term='Run_init'/><category term='Mode'/><category term='SELinux'/><category term='Experience'/><category term='Customized'/><category term='Lockdown'/><category term='Interface'/><category term='Roles'/><category term='Source'/><category term='Domains'/><category term='dontaudit'/><category term='RBAC'/><category term='File context'/><category term='MCS'/><category term='AVC'/><category term='Permissive'/><category term='ACE'/><category term='Unconfined'/><category term='Sudo'/><category term='USER_AVC'/><title type='text'>SELinux Mandatory Access Control</title><subtitle type='html'>Dominick Grift blogs about topics related to Security-Enhanced Linux Mandatory Access Control.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>36</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-4238326997061638222</id><published>2011-08-23T11:10:00.000-07:00</published><updated>2011-08-23T11:17:12.742-07:00</updated><title type='text'>Git daemon and SELinux with RHEL6</title><content type='html'>RHEL6 does not ship with a manual page for configuring Git daemon SELinux policy, and so decided to publish a demonstration on youtube:&lt;br /&gt;&lt;br /&gt;Part 1. Git system daemon, shared repositories.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=vgm89P5nbBQ&lt;br /&gt;&lt;br /&gt;Part 2. Git session daemon, personal repositories.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=XHEPj80217o&lt;br /&gt;&lt;br /&gt;By the way you can look at the manual page (source) here:&lt;br /&gt;&lt;br /&gt;http://git.fedorahosted.org/git/?p=selinux-policy.git;a=blob;f=man/man8/git_selinux.8;h=e9c43b190c394f8ea7e68d9dd29f45c831340bf5;hb=ccadbe7d6ae709cdfd3b06d496477e069a2f13ee&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-4238326997061638222?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/4238326997061638222/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2011/08/git-daemon-and-selinux-with-rhel6.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4238326997061638222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4238326997061638222'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2011/08/git-daemon-and-selinux-with-rhel6.html' title='Git daemon and SELinux with RHEL6'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-3872935420517166958</id><published>2011-02-08T14:22:00.001-08:00</published><updated>2011-02-08T14:22:41.900-08:00</updated><title type='text'>selinux q&amp;a</title><content type='html'>23:15 &lt; someone&gt; What's the difference between httpd_sys_rw_content_t and &lt;br /&gt;                  httpd_sys_content_rw_t?&lt;br /&gt;23:19 &lt; dgrift&gt; none&lt;br /&gt;23:19 &lt; dgrift&gt; their aliased&lt;br /&gt;23:19 &lt; dgrift&gt; theyre&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-3872935420517166958?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/3872935420517166958/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2011/02/selinux-q.html#comment-form' title='2 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3872935420517166958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3872935420517166958'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2011/02/selinux-q.html' title='selinux q&amp;a'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-8991280132991920661</id><published>2011-02-06T14:44:00.000-08:00</published><updated>2011-02-06T14:53:32.788-08:00</updated><title type='text'>frequently asked questions: selinux booleans in detail.</title><content type='html'>Q: &lt;span style="font-style:italic;"&gt;"btw, anyone know if each of the selinux booleans are documented in detail somewhere?"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A: two levels of detail here:&lt;br /&gt;&lt;br /&gt;   1. &lt;span style="font-weight:bold;"&gt;semanage boolean -l | grep httpd_enable_homedirs&lt;/span&gt;&lt;br /&gt;   A written description (usually not very detailed) for the "httpd_enable_homedirs" boolean.&lt;br /&gt;&lt;br /&gt;   2. &lt;span style="font-weight:bold;"&gt;sesearch --allow -SC -T | grep httpd_enable_homedirs&lt;/span&gt;&lt;br /&gt;   All the "allow" type statement rules and type transition rules related to the "httpd_enable_homedirs" boolean. Very detailed but hard to interpret.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-8991280132991920661?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/8991280132991920661/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2011/02/frequently-asked-questions-selinux.html#comment-form' title='1 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/8991280132991920661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/8991280132991920661'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2011/02/frequently-asked-questions-selinux.html' title='frequently asked questions: selinux booleans in detail.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5546042921201310113</id><published>2011-02-06T13:41:00.000-08:00</published><updated>2011-02-06T13:49:16.553-08:00</updated><title type='text'>common issues -- part 1</title><content type='html'>22:13 &lt; _Tassadar&gt; hi&lt;br /&gt;22:14 &lt; _Tassadar&gt; http://fedoraproject.org/wiki/SELinux/samba  &lt;-  i'm reading this document, on how to &lt;br /&gt;                   configure selinux to allow samba to share a certain directory&lt;br /&gt;22:14 &lt; _Tassadar&gt; now i'd like to share /data/files so i issued chcon -t samba_share_t /data/files&lt;br /&gt;22:14 &lt; _Tassadar&gt; it worked, according to ls -Z&lt;br /&gt;22:14 &lt; _Tassadar&gt; but access is still denied&lt;br /&gt;22:15 &lt; _Tassadar&gt; should i recursively set that label to every file in the share as well?&lt;br /&gt;22:16 &lt; SwifT&gt; _Tassadar: (without reading the file) check your AVC denials on what is actually denied, but I &lt;br /&gt;               would say "yes, you'll probably want to recursively set the type"&lt;br /&gt;22:17 &lt; _Tassadar&gt; SwifT: what is the best way to check my AVC denials?&lt;br /&gt;22:17 &lt; _Tassadar&gt; it's a server, i don't have any gui tools&lt;br /&gt;22:20 &lt; dgrift&gt; _Tassadar: try Fedora manage confined services&lt;br /&gt;22:20 &lt; _Tassadar&gt; hm no new entries appear in /var/log/audit/audit.log&lt;br /&gt;22:20 &lt; SwifT&gt; _Tassadar: depends on your system log configuration; try tail -f /var/log/messages or &lt;br /&gt;               /var/log/audit.log&lt;br /&gt;22:20 &lt; _Tassadar&gt; some stuff from cron appears every five mins, but nothing from smb&lt;br /&gt;22:20 &lt; dgrift&gt; _Tassadar this is a common issue&lt;br /&gt;22:20 &lt; dgrift&gt; its this:&lt;br /&gt;22:21 &lt; dgrift&gt; youve created a new mountpoint called /data&lt;br /&gt;22:21 &lt; dgrift&gt; selinux doesnt know that location&lt;br /&gt;22:21 &lt; dgrift&gt; and so it labels it with a type: default_t&lt;br /&gt;22:21 &lt; dgrift&gt; this is a type for locations unknown to selinux&lt;br /&gt;22:21 &lt; dgrift&gt; and selinux silently denies access to type default_t&lt;br /&gt;22:22 &lt; dgrift&gt; because it should not happen&lt;br /&gt;22:22 &lt; dgrift&gt; all locations should be labelled properly&lt;br /&gt;22:22 &lt; _Tassadar&gt; ah&lt;br /&gt;22:22 &lt; _Tassadar&gt; i see&lt;br /&gt;22:22 &lt; dgrift&gt; so how to fix it?:&lt;br /&gt;22:22 &lt; _Tassadar&gt; with restorecon probably&lt;br /&gt;22:22 &lt; dgrift&gt; well you should start by labelling /data&lt;br /&gt;22:22 &lt; dgrift&gt; what type to label it, that depends on your requirements for /data&lt;br /&gt;22:23 &lt; _Tassadar&gt; well it's all user data&lt;br /&gt;22:23 &lt; dgrift&gt; var_t should probably do&lt;br /&gt;22:23 &lt; dgrift&gt; i see&lt;br /&gt;22:23 &lt; _Tassadar&gt; no binaries, no devices&lt;br /&gt;22:23 &lt; _Tassadar&gt; lots of mp3's :)&lt;br /&gt;22:23 &lt; dgrift&gt; whats in /data?&lt;br /&gt;22:23 &lt; dgrift&gt; only dirs?&lt;br /&gt;22:23 &lt; _Tassadar&gt; yes&lt;br /&gt;22:23 &lt; _Tassadar&gt; /data/home/user1 /data/home/user2&lt;br /&gt;22:24 &lt; _Tassadar&gt; /data/home/public_area&lt;br /&gt;22:24 &lt; _Tassadar&gt; /data/public_area i mean&lt;br /&gt;22:24 &lt; dgrift&gt; whats your distro?&lt;br /&gt;22:24 &lt; _Tassadar&gt; Fedora 14&lt;br /&gt;22:24 &lt; dgrift&gt; ok heres my suggestion&lt;br /&gt;22:24 &lt; dgrift&gt; what is /data/home/user1 labelled?&lt;br /&gt;22:24 &lt; _Tassadar&gt; nothing yet&lt;br /&gt;22:25 &lt; dgrift&gt; but thats a user home dir?&lt;br /&gt;22:25 &lt; _Tassadar&gt; drwx------. joe    users unconfined_u:object_r:samba_share_t:s0 joe&lt;br /&gt;22:25 &lt; _Tassadar&gt; well&lt;br /&gt;22:25 &lt; _Tassadar&gt; i labelled it samba_share_t&lt;br /&gt;22:25 &lt; dgrift&gt; ok&lt;br /&gt;22:25 &lt; _Tassadar&gt; that's what the docs told me to do :)&lt;br /&gt;22:26 &lt; dgrift&gt; what do you want?&lt;br /&gt;22:26 &lt; _Tassadar&gt; well it doesn't work yet&lt;br /&gt;22:26 &lt; dgrift&gt; what do you want with those dirs?&lt;br /&gt;22:26 &lt; _Tassadar&gt; i would like the user to be able to mount his directory from a windows workstation&lt;br /&gt;22:26 &lt; dgrift&gt; what is your requirement&lt;br /&gt;22:26 &lt; dgrift&gt; i see&lt;br /&gt;22:26 &lt; _Tassadar&gt; users are allowed read/write access to their own directories&lt;br /&gt;22:26 &lt; dgrift&gt; and not use it locally?&lt;br /&gt;22:26 &lt; _Tassadar&gt; and also in the public_area&lt;br /&gt;22:26 &lt; _Tassadar&gt; no&lt;br /&gt;22:26 &lt; dgrift&gt; ok&lt;br /&gt;22:26 &lt; _Tassadar&gt; no shell access&lt;br /&gt;22:27 &lt; _Tassadar&gt; no local processes are to be started from /data&lt;br /&gt;22:27 &lt; dgrift&gt; so label /data root_t and the other dirs in there samba_share_t&lt;br /&gt;22:27 &lt; _Tassadar&gt; recursively?&lt;br /&gt;22:27 &lt; dgrift&gt; semanage -a -t root_t -f -d /data&lt;br /&gt;22:28 &lt; dgrift&gt; semanage -a -t samba_share_t "/data/home(/.*)?"&lt;br /&gt;22:28 &lt; dgrift&gt; restorecon -R -v /data&lt;br /&gt;22:28 &lt; dgrift&gt; that will label the data dir root_t&lt;br /&gt;22:28 &lt; _Tassadar&gt; nice&lt;br /&gt;22:28 &lt; _Tassadar&gt; what does root_t mean?&lt;br /&gt;22:28 &lt; dgrift&gt; and /data/home and all below it samba_share_t&lt;br /&gt;22:29 &lt; dgrift&gt; it means it the type for filesystem roots&lt;br /&gt;22:29 &lt; dgrift&gt; basically its accessable by all&lt;br /&gt;22:29 &lt; _Tassadar&gt; oh okay, that makes sense in this case&lt;br /&gt;22:29 &lt; dgrift&gt; see if it work&lt;br /&gt;22:29 &lt; _Tassadar&gt; what would the -a option do?&lt;br /&gt;22:29 &lt; _Tassadar&gt; my system doesn't know -a&lt;br /&gt;22:29 &lt; _Tassadar&gt; oh&lt;br /&gt;22:29 &lt; _Tassadar&gt; it does&lt;br /&gt;22:29 &lt; dgrift&gt; oops&lt;br /&gt;22:30 &lt; _Tassadar&gt; something else is wrong&lt;br /&gt;22:30 &lt; dgrift&gt; non i made a booboo&lt;br /&gt;22:30 &lt; _Tassadar&gt; okay&lt;br /&gt;22:30 &lt; dgrift&gt; semanage fcontext -a -t root_t -f -d /data&lt;br /&gt;22:30 &lt; dgrift&gt; semanage fcontext -a -t samba_share_t "/data/home(/.*)?"&lt;br /&gt;22:30 &lt; dgrift&gt; restorecon -R -v /data&lt;br /&gt;22:31 &lt; _Tassadar&gt; lol okay that could take a while&lt;br /&gt;22:31 &lt; _Tassadar&gt; i'll run it without -v&lt;br /&gt;22:31 &lt; dgrift&gt; hopefully it works for you&lt;br /&gt;22:31 &lt; dgrift&gt; yes ok&lt;br /&gt;22:31 &lt; _Tassadar&gt; it's a 11TB mount ;)&lt;br /&gt;22:31 &lt; dgrift&gt; ouch....&lt;br /&gt;22:31 &lt; dgrift&gt; all data on it?&lt;br /&gt;22:31 &lt; _Tassadar&gt; yeah, no worries though, i'm not in a hurry&lt;br /&gt;22:32 &lt; _Tassadar&gt; it's 60% used ;)&lt;br /&gt;22:32 &lt; dgrift&gt; geez&lt;br /&gt;22:32 &lt; dgrift&gt; i hope we get this right first time...&lt;br /&gt;22:32 &lt; dgrift&gt; might want to test first&lt;br /&gt;22:32 &lt; dgrift&gt; with a small dir&lt;br /&gt;22:32 &lt; _Tassadar&gt; heh&lt;br /&gt;22:32 &lt; _Tassadar&gt; i suppose so&lt;br /&gt;22:32 &lt; _Tassadar&gt; ....&lt;br /&gt;22:33 &lt; dgrift&gt; chcon -R -t samba_share_t /data/home/smalluserdir&lt;br /&gt;22:33 &lt; dgrift&gt; chcon -t root_t /data&lt;br /&gt;22:34 &lt; _Tassadar&gt; okay i'll try that&lt;br /&gt;22:34 &lt; dgrift&gt; errr&lt;br /&gt;22:34 &lt; dgrift&gt; its like this:&lt;br /&gt;22:34 &lt; dgrift&gt; chcon -t root_t /data&lt;br /&gt;22:34 &lt; dgrift&gt; chcon -t /data/home&lt;br /&gt;22:34 &lt; dgrift&gt; err&lt;br /&gt;22:34 &lt; _Tassadar&gt; ?&lt;br /&gt;22:34 &lt; _Tassadar&gt; lol&lt;br /&gt;22:34 &lt; dgrift&gt; chcon -t samba_share_t /data/home&lt;br /&gt;22:34 &lt; dgrift&gt; chcon -R -t samba_share_t /data/home/smalluserdir&lt;br /&gt;22:35 &lt; dgrift&gt; so three lines&lt;br /&gt;22:35 &lt; _Tassadar&gt; yeah i understand, but restorecon is already running so /data and /data/home are already done &lt;br /&gt;                   ;)&lt;br /&gt;22:35 &lt; dgrift&gt; because theres 3 dirs&lt;br /&gt;22:35 &lt; _Tassadar&gt; i just tried with a small userdir and it works great !&lt;br /&gt;22:35 &lt; dgrift&gt; ok&lt;br /&gt;22:35 &lt; _Tassadar&gt; but, how do i keep everything neat&lt;br /&gt;22:35 &lt; _Tassadar&gt; does restorecond do that?&lt;br /&gt;22:35 &lt; _Tassadar&gt; i mean every time someone adds a file&lt;br /&gt;22:36 &lt; _Tassadar&gt; it should get the right label immediately&lt;br /&gt;22:36 &lt; dgrift&gt; it inherites the type of the parent dir&lt;br /&gt;22:36 &lt; dgrift&gt; so should be fine&lt;br /&gt;22:36 &lt; _Tassadar&gt; ah i see&lt;br /&gt;22:36 &lt; _Tassadar&gt; so what does restorecond do then?&lt;br /&gt;22:36 &lt; dgrift&gt; try it&lt;br /&gt;22:36 &lt; dgrift&gt; well it watches directories for mislabelled files&lt;br /&gt;22:36 &lt; dgrift&gt; but in your case its not applicable&lt;br /&gt;22:37 &lt; dgrift&gt; because theres only one type&lt;br /&gt;22:37 &lt; _Tassadar&gt; -rw-rw----. joe    users unconfined_u:object_r:samba_share_t:s0 zzzzz.txt&lt;br /&gt;22:37 &lt; _Tassadar&gt; yeah that works&lt;br /&gt;22:37 &lt; dgrift&gt; samba_share_t&lt;br /&gt;22:37 &lt; _Tassadar&gt; ah mislabelled, so not unlabelled&lt;br /&gt;22:37 &lt; _Tassadar&gt; i understand&lt;br /&gt;22:37 &lt; _Tassadar&gt; real    5m32.340s&lt;br /&gt;22:37 &lt; dgrift&gt; well and unlabelled aswell&lt;br /&gt;22:37 &lt; _Tassadar&gt; done :)&lt;br /&gt;22:37 &lt; dgrift&gt; fast system&lt;br /&gt;22:37 &lt; _Tassadar&gt; yeah :)&lt;br /&gt;22:38 &lt; dgrift&gt; i should blog about this issue&lt;br /&gt;22:38 &lt; dgrift&gt; its very common&lt;br /&gt;22:38 &lt; _Tassadar&gt; definately&lt;br /&gt;22:39 &lt; dgrift&gt; and people wonder why its not logging denials&lt;br /&gt;22:39 &lt; _Tassadar&gt; yeah and the fact that audit.log doesn't show anything makes it hard to track for newbies like &lt;br /&gt;                   me&lt;br /&gt;22:39 &lt; _Tassadar&gt; exactly :)&lt;br /&gt;22:39 &lt; dgrift&gt; can i use this chat log?&lt;br /&gt;22:39 &lt; dgrift&gt; to publish?&lt;br /&gt;22:39 &lt; _Tassadar&gt; errrr :)&lt;br /&gt;22:39 &lt; _Tassadar&gt; i suppose&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5546042921201310113?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5546042921201310113/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2011/02/common-issues-part-1.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5546042921201310113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5546042921201310113'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2011/02/common-issues-part-1.html' title='common issues -- part 1'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-3822209684765812282</id><published>2011-01-24T06:35:00.000-08:00</published><updated>2011-01-24T06:52:17.094-08:00</updated><title type='text'>Yet another step by step introduction to policy development.</title><content type='html'>Due to several requests for guides to writing SELinux policy i have decided to create another screen cast detailing how to create a policy for a user application, and some of the things that may help one get familiar with policy writing.&lt;br /&gt;&lt;br /&gt;As per usual by now, it is just a amateur production for amateurs. These recordings are pretty boring and long. I do advise that you view the whole thing in the proper order. Because things may not be explained well all the time, but most of it should become more clear in the course of the series.&lt;br /&gt;&lt;br /&gt;Sometimes i make mistakes that i later notice. By the end of the series everything is pretty much sorted out (except atleast one pretty minor issue that i consider as an exercise to the watcher to troubleshoot and solve).&lt;br /&gt;&lt;br /&gt;Also note that i encountered a conflict with restorecond -u (run in a gnome-session) with regard to labelling a file in the user home directory. I worked around that issue, but it will work fine when one logs out and back in, when it occurs.&lt;br /&gt;&lt;br /&gt;part 1. Setting up an optimal environment for policy writing and in the mean time i explain my view on policy writing and every aspect of it.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=s4EyoW_7riQ&lt;br /&gt;&lt;br /&gt;part 2. Do it yourself: create a simple script and write raw policy for it. Introduction to type transition, allow, dontaudit and other type statements. A start at translating raw policy that SELinux understands into policy that is maintainable and readable by humans and that is scalable in a modular environment.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=G5gUt1-ttGg&lt;br /&gt;&lt;br /&gt;part 3. Proceed with translation of raw policy to m4 macro language powered policy. Merge our loadable policy module into upstream tresys reference policy.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=nbFnchVAgYs&lt;br /&gt;&lt;br /&gt;part 4. troubleshoot remaining issues and fix them.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=rUGBgzTr92A&lt;br /&gt;&lt;br /&gt;If you have specific question with regard to the series above feel free to ask for clarification.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-3822209684765812282?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/3822209684765812282/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2011/01/yet-another-step-by-step-introduction.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3822209684765812282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3822209684765812282'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2011/01/yet-another-step-by-step-introduction.html' title='Yet another step by step introduction to policy development.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-8543066306813862089</id><published>2010-12-16T03:08:00.000-08:00</published><updated>2010-12-16T03:32:32.340-08:00</updated><title type='text'>Note to self: all the stuff a pulseaudio client needs.</title><content type='html'>basically i figured out about three scenarios so far:&lt;br /&gt;&lt;br /&gt;1: The basics.&lt;br /&gt;Pulseaudio is running normally, and the pulseaudio client needs to make some sound i guess&lt;br /&gt;&lt;br /&gt;# manage a pulse-shm file in /dev/shm&lt;br /&gt;manage_files_pattern($1, $2_tmpfs_t, $2_tmpfs_t)&lt;br /&gt;fs_tmpfs_filetrans($1_t, $2_tmpfs_t, file)&lt;br /&gt;fs_getattr_tmpfs($1_t)&lt;br /&gt;&lt;br /&gt;# allow the user of the app to manage and relabel that file as well&lt;br /&gt;allow $3 $2_tmpfs_t:file { relabel_file_perms manage_file_perms };&lt;br /&gt;&lt;br /&gt;# 1. This add an attribute to the pulse client process so that i can allow each pulse client progress to signull any other pulse client process&lt;br /&gt;# 2, This also adds an attribute to the pulse client tmpfs file so that i can allow each pulse client to read write and delete any others pulse client tmpfs file.&lt;br /&gt;gnome_pulseaudio_client($1, $2)&lt;br /&gt;# read write pulseaudio files in ~/pulse (a directory that is actually owned by gnome settings daemon)&lt;br /&gt;gnome_rw_gsettingsd_pulseaudio_files($1)&lt;br /&gt;# read gnome settings daemon home content for example some symlink in ~/.pulse to a pulseaudio sock file&lt;br /&gt;gnome_read_gsettingsd_home_content($1)&lt;br /&gt;# connect to pulseaudio with a unix stream socket&lt;br /&gt;gnome_stream_connect_gsettingsd_pulseaudio($1, $2)&lt;br /&gt;# search /tmp/pulse-*&lt;br /&gt;gnome_search_gsettingsd_tmp_dirs($1)&lt;br /&gt;# set attributes of ~/.pulse directory&lt;br /&gt;gnome_setattr_gsettingsd_home_dirs($1)&lt;br /&gt;&lt;br /&gt;# manage /.cache sound-event-cache files.&lt;br /&gt;xdg_manage_generic_user_cache_files($1)&lt;br /&gt;&lt;br /&gt;2: The not so basics.&lt;br /&gt;These pulse client seem to be required to be able to (re) start the main pulseaudio process as well in some particular cases)&lt;br /&gt;&lt;br /&gt;# domain transition to the gnome settingsd daemon pulseaudio domain when pulseaudio is executed.&lt;br /&gt;gnome_spec_domtrans_gsettingsd_pulseaudio($1, $2)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3: When pulseaudio is not running.&lt;br /&gt;When you kill pulseaudio and run a pulseaudio client app. It, i guess, expects some pulse audio network functionality because pulse is not running on the local system.&lt;br /&gt;&lt;br /&gt;# the pulse client is trying to find pulseaudio on the network i guess...&lt;br /&gt;allow $1 self:netlink_route_socket r_netlink_socket_perms;&lt;br /&gt;allow $1 self:tcp_socket create_socket_perms;&lt;br /&gt;allow $1 self:unix_dgram_socket sendto;&lt;br /&gt;&lt;br /&gt;corenet_all_recvfrom_netlabel($1_t)&lt;br /&gt;corenet_all_recvfrom_unlabeled($1_t)&lt;br /&gt;corenet_tcp_bind_generic_node($1_t)&lt;br /&gt;corenet_tcp_sendrecv_generic_if($1_t)&lt;br /&gt;corenet_tcp_sendrecv_generic_node($1_t)&lt;br /&gt;corenet_tcp_connect_pulseaudio_port($1_t)&lt;br /&gt;corenet_tcp_sendrecv_pulseaudio_port($1_t)&lt;br /&gt;corenet_sendrecv_pulseaudio_client_packets($1_t)&lt;br /&gt;&lt;br /&gt;# if that isnt enough, the pulseaudio client wants to be a dbus system bus client. Dont ask me why but&lt;br /&gt;its probably looking for pulseaudio run as a dbus system domain or init daemon.&lt;br /&gt;dbus_system_bus_client($1)&lt;br /&gt;&lt;br /&gt;..Heck it may even need more like maybe sysnet_read_config, i have not been able to confirm this yet.&lt;br /&gt;&lt;br /&gt;The amount of access(policy) a simple gui application needs to be able to spit out a sound with pulseaudio is simply amazing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-8543066306813862089?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/8543066306813862089/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/12/note-to-self-all-stuff-pulseaudio.html#comment-form' title='1 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/8543066306813862089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/8543066306813862089'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/12/note-to-self-all-stuff-pulseaudio.html' title='Note to self: all the stuff a pulseaudio client needs.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-7581680594149205621</id><published>2010-11-29T11:22:00.001-08:00</published><updated>2010-11-30T10:08:08.286-08:00</updated><title type='text'>My Fedora 14 policy for the adventurous.</title><content type='html'>My Fedora 14 policy for the adventurous.&lt;br /&gt;&lt;br /&gt;I have been working on a policy for Fedora 14. Three different policies actually. One for a minimal fedora installation (--nobase), one for a minimal fedora installation with libvirt and a policy for a minimal gnome desktop system.&lt;br /&gt;&lt;br /&gt;The minimal policy for Fedora 14 gnome desktops is the interesting one. It aims to confine the gnome desktop on workstations. That means it supports almost none system services, excepts the base essentials. It does not have policy for any mail servers, it does have policy for ssh and even httpd. Http policy because gnome-user-share relies on it (dav)&lt;br /&gt;&lt;br /&gt;What it lacks in system services it makes up for in application domains. That is to say it supports some gnome apps, and the user apps that do not have policy should be able to make to work by toggling the gnome_$1_targeted boolean where $1 is your user role prefix. Caution though that this hasnt been tested yet because my sole priority lies with a confined gnome, and this is enough work as is.&lt;br /&gt;&lt;br /&gt;There are atleast some things to do if one decides to give it a spin.&lt;br /&gt;&lt;br /&gt;One should add the following directories to /etc/skel:&lt;br /&gt;.config&lt;br /&gt;.config/enchant&lt;br /&gt;.config/gtk-2.0&lt;br /&gt;.cache&lt;br /&gt;.local&lt;br /&gt;.local/share&lt;br /&gt;.gnome2&lt;br /&gt;.gnome2/accels&lt;br /&gt;&lt;br /&gt;One should also modify /usr/share/dracut/modules.d/98selinux/selinux-loadpolicy.sh&lt;br /&gt;&lt;br /&gt;comment out:&lt;br /&gt;&lt;br /&gt;mount --bind /dev "$NEWROOT/dev"&lt;br /&gt;chroot "$NEWROOT" /sbin/restorecon -R /dev&lt;br /&gt;&lt;br /&gt;..and then use dracut to build a new initramfs for your current kernel.&lt;br /&gt;&lt;br /&gt;Also fix /root:&lt;br /&gt;&lt;br /&gt;semanage fcontext -a -e /home/joe /root&lt;br /&gt;restorecon -R -v /root&lt;br /&gt;&lt;br /&gt;Typically you would:&lt;br /&gt;&lt;br /&gt;setenforce 0&lt;br /&gt;rpm -ev selinux-policy selinux-policy-targeted&lt;br /&gt;rpm -Uvh selinux-policy-2.20100524-1.fc14.noarch.rpm selinux-policy-bare_gui-2.20100524-1.fc14.noarch.rpm&lt;br /&gt;edit /etc/selinux/config and set selinux back to enforcing and point to bare_gui instead of targeted&lt;br /&gt;relabel the file system&lt;br /&gt;best to add a new user (make it staff_u as its user_u by default (sorry no unconfined_u in this policy by default)&lt;br /&gt;make sure to add the user to sudo:&lt;br /&gt;echo "joe ALL=(ALL) ROLE=sysadm_r TYPE=sysadm_t ALL" &gt; /etc/sudoers.d/joe&lt;br /&gt;chmod 0440 /etc/sudoers.d/joe&lt;br /&gt;reboot&lt;br /&gt;&lt;br /&gt;This policy confines all domains. also kernel_t and rpm_t. installation of packages and updting of packages should probably be done in permissive mode for now because the rpm domain needs some more loving. (common packages will work but dont try to install a kernel in enforcing mode or some service that gets restarted in the post-install script.&lt;br /&gt;&lt;br /&gt;As said, this only works with gnome if it works at all (dont worry i am using it on my desktops) but only try this if youre a bit familar with selinux, are feeling adventurous and if you dont panic quickly.&lt;br /&gt;&lt;br /&gt;By default the minimal gnome environment is confined. Gnome apps by default arent allowed to interact with users and often arent allowed to run generic applications. For example the printer applet currently is not confined (i dont like printing its a waste of paper and ink), thus gnome will not be able to run the printer applet until a policy for it is implemented.&lt;br /&gt;&lt;br /&gt;The idea is that gnome can easily be allowed to interact with these generic apps and be allowed to communicate with users by toggling the gnome_$1_targeted boolean. However this is still untested.&lt;br /&gt;&lt;br /&gt;Youll notice that youll have to unlock youre gnome keyring on each login. I am not sure why but gnome keyring daemon or whatever runs it (probably dbus, maybe xdm?) tries to manipulate selinux into running in the user domain which i forcefully prevent so that it can be made to run confined.&lt;br /&gt;&lt;br /&gt;If something is confined then youll be able to run it in a confined environment with gnome_$1_targeted boolean set to off, Else you wont be able to run it untill some policy for it gets implemented.&lt;br /&gt;&lt;br /&gt;The apps you are able to run may not be confined perfectly yet for all use cases (its a lot of work). &lt;br /&gt;&lt;br /&gt;Stuff that works for me:&lt;br /&gt;&lt;br /&gt;a lot of default gnome apps/applets/session services&lt;br /&gt;&lt;br /&gt;totem&lt;br /&gt;rhythmbox&lt;br /&gt;evince&lt;br /&gt;compiz&lt;br /&gt;gedit&lt;br /&gt;terminator&lt;br /&gt;screen&lt;br /&gt;mutt&lt;br /&gt;irssi&lt;br /&gt;firefox&lt;br /&gt;thunderbird&lt;br /&gt;eclipse&lt;br /&gt;vinagre&lt;br /&gt;empathy/telepathy&lt;br /&gt;gpg&lt;br /&gt;metacity&lt;br /&gt;nautilus&lt;br /&gt;gnome schedule&lt;br /&gt;seahorse&lt;br /&gt;&lt;br /&gt;Stuff that is not supported (atleast):&lt;br /&gt;&lt;br /&gt;hal&lt;br /&gt;mlocate&lt;br /&gt;&lt;br /&gt;So one should be able to do some of the basics.&lt;br /&gt;&lt;br /&gt;Why confining the desktop? Not so much to protect generic user content. I use to think this is important but as my policy evolved i discovered that the important thing here is the integrity of gnome and user apps.&lt;br /&gt;&lt;br /&gt;For example: protect access to your keyring, gpg data, ssh data, firefox data etc.&lt;br /&gt;&lt;br /&gt;Not protecting access to your generic ~/.porn directory&lt;br /&gt;&lt;br /&gt;So how would you get started?&lt;br /&gt;&lt;br /&gt;We you can get a tar ball of a recent snapshot here:&lt;br /&gt;&lt;br /&gt;http://217.19.30.59/~dgrift/stuff/&lt;br /&gt;&lt;br /&gt;Just put the tarball in your ~/rpmbuild/SOURCES directory. Extract the support/selinux-policy.spec from the tarball and put that into ~/rpmbuild/SPECS/&lt;br /&gt;then just rpmbuild -ba ~/rpmbuild/SPECS/selinux-policy.spec&lt;br /&gt;it will spit out 3 packages by default (bare_gui and its docs package) which you can install. You do not require the docs rpm but installing it doesnt hurt either.&lt;br /&gt;&lt;br /&gt;If you want to try the bare or bare_virt model you can do so by editing the selinux-policy.spec and set the %define for that model to 1. it will build an rpm for that aswell.&lt;br /&gt;&lt;br /&gt;Remember, expect plenty boogs i would love to receive some feedback or even help in improving the policy. It is a lot of work but the concept is very powerful. By confining the layer between the user and the system (the desktop) we achieve a lot more flexibility. We can then define what each user domain can and cannot do by simply implementing a boolean. &lt;br /&gt;&lt;br /&gt;The idea about the bare and bare_virt models is that its strict, the unconfined module is install but not used. Another important property of bare and bare_virt is small footprint. It only installs the bare minimum modules which keeps the policy small. if one decides to run a service that is not currently supported in bare or bare_virt then one can use loadable module to implement it. The policy is focussed on advanced administrators that value small foot print and want total control over have gets installed and what not.&lt;br /&gt;&lt;br /&gt;Questions comments? domg472 at gmail dot com&lt;br /&gt;&lt;br /&gt;Some background information:&lt;br /&gt;&lt;br /&gt;the policy is based off of recent refpolicy. refpolicy aims the be a base for basically any kind of model. Unfortunately i had to edit refpolicy atleast to remove unconfined_domains ( i think refpolicy probably shouldnt have unconfined domains as its easier to add and unconfined domain than to remove one) also i had to remove and/or redo most of refpolicies user application policies. I think it may be better for refpolicy to ignore user application policies or atleast prefix them all. domains like ssh_t arent helpful in a confined user space, as a confined user space relies heavily on user role prefixes.&lt;br /&gt;&lt;br /&gt;Why not base it on fedora policy?&lt;br /&gt;&lt;br /&gt;All of the above discussed issues apply, plus. Fedora tends to avoid issues by adding modules to base. This causes problems. My policy only has modules in the kernel layer in base all other modules can be disabled in theory. Fedora focusses on usability. little things like easily allowing access to all user content makes it hard to confine the user space.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-7581680594149205621?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/7581680594149205621/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/11/my-fedora-14-policy-for-adventurous.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/7581680594149205621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/7581680594149205621'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/11/my-fedora-14-policy-for-adventurous.html' title='My Fedora 14 policy for the adventurous.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-312764774487795940</id><published>2010-08-07T11:05:00.000-07:00</published><updated>2010-08-07T11:11:04.107-07:00</updated><title type='text'>user home directory contexts</title><content type='html'>Some where in this commit: 0bf4290c235b514c39ed9c8d3f3f2fbb95f60cfa ( in one of the file context specifications there ) is something that makes and breaks whatever creates the per user home directory contexts.&lt;br /&gt;&lt;br /&gt;Without it, semodule (what use to be genhomedircon?) only creates contexts for the "__default__" login.&lt;br /&gt;&lt;br /&gt;It took me almost a day to narrow it down to this. I would like to know which file context specification exactly is causing it and why&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-312764774487795940?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/312764774487795940/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/08/user-home-directory-contexts.html#comment-form' title='7 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/312764774487795940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/312764774487795940'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/08/user-home-directory-contexts.html' title='user home directory contexts'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-1242656380149810436</id><published>2010-08-05T14:22:00.001-07:00</published><updated>2010-08-05T15:15:16.538-07:00</updated><title type='text'>The advantages and disadvantages of domain prefixes.</title><content type='html'>I am trying to merge restricted xwindows users and common users. The idea is to make them both use the same policy and be able to lock down what we know as user_t to a restricted user that we know as xguest by toggling booleans. That will make it easier to adept user environments to meet your requirement. You do not have to write custom policy. Simply enable/disable the functionality that you need with booleans and go.&lt;br /&gt;&lt;br /&gt;To achieve this i use the good old per_role_templates. We used to use them for role based separation, But once user based separation was introduced there seemed to be not much use to these templates any more. However the domain prefixes used in the per role templates can play an important role in enabling and disabling functionality for different users using the same policy. We can use the domain prefix to define tunable policy.&lt;br /&gt;&lt;br /&gt;user joe is allowed to access the network via his web browser. User jane can only access the network with her favourite game. Both use the same policy but have different booleans toggled.&lt;br /&gt;&lt;br /&gt;But consider this: joe is allowed to use the browser. The browser can use stuff like java, flash, a video player, email client etc. Its not joe directly run those its the browser running it for joe. So how is it achieved that when it is allowed that joe can use the web browser, that joe can also watch a video clip via his web browser. Or that joe is not allowed to watch video via his browser but some other user is permitted that.&lt;br /&gt;&lt;br /&gt;This, i believe can be achieved by called per_role_templates in per_role_templates.&lt;br /&gt;&lt;br /&gt;I tried this before in more than one ways and always stumbled on duplicate declarations or out of scope issues. Today i tried a different approach. To avoid duplicate declarations i decided to try and split the per_role_templates into templates for policy and for declarations. The declaration per role templates should only be called by user domains. Whilst the policy per role templates can additionally be called by other policy per role templates. This way booleans, types and attributes are declared once but can be used more than once. For example user X can connect to a streaming port if he runs totem, but he can also connect to a streaming port if he runs totem via his browser. The same can be done for things like java, gpg, flash, web browsers, you name it&lt;br /&gt;&lt;br /&gt;Another thing i have to deal with is xserver duplicated declarations, and so i also split those declarations for the policy and added the declaration interface to the per role declaration template for the various applications and the policy to the per role policy template.&lt;br /&gt;&lt;br /&gt;This stuff becomes important if you truly want to confine the user space. Take for example nautilus. If you click on a video file in nautilus. How does the SELinux know who did it and thus who's policy to apply? All it knows is that nautilus ran the video file and nautilus is not a user its an application. There are may more such examples. Domain prefixes can help here.&lt;br /&gt;&lt;br /&gt;There are also issues with calling per role templates from per role templates. Consider this. You can click on a web url in an E-mail message and you can also use the E-mail client from the web browser. So you called the E-mail per role template from the browser per role template, and you call the browser per role template from the E-mail per role template. This will get you into a loop that never ends. You can wait until you way less than a ounce and policy will still not finish compiling. So that is a issue to consider.&lt;br /&gt;&lt;br /&gt;Just to show you what a per role declaration template for a GUI app would look like:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;########################################&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Role access for mozilla declarations.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;param name="role_prefix"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Prefix to be used&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;## &lt;param name="role"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Role allowed access&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;#&lt;br /&gt;interface(`mozilla_declarations_role',`&lt;br /&gt; gen_require(`&lt;br /&gt;  attribute mozilla_domain;&lt;br /&gt;  type mozilla_exec_t;&lt;br /&gt; ')&lt;br /&gt;&lt;br /&gt; ## &lt;desc&gt;&lt;br /&gt; ## &lt;p&gt;&lt;br /&gt; ## Allow Mozilla to execute anonymous memory (execmem))&lt;br /&gt; ## files.&lt;br /&gt; ## &lt;/p&gt;&lt;br /&gt; ## &lt;/desc&gt;&lt;br /&gt; gen_tunable(mozilla_$1_execmem, false)&lt;br /&gt;&lt;br /&gt; ## &lt;desc&gt;&lt;br /&gt; ## &lt;p&gt;&lt;br /&gt; ## Allow Mozilla to read all user home.&lt;br /&gt; ## files.&lt;br /&gt; ## &lt;/p&gt;&lt;br /&gt; ## &lt;/desc&gt;&lt;br /&gt; gen_tunable(mozilla_$1_read_content, false)&lt;br /&gt;&lt;br /&gt; ## &lt;desc&gt;&lt;br /&gt; ## &lt;p&gt;&lt;br /&gt; ## Network access for mozilla.&lt;br /&gt; ## files.&lt;br /&gt; ## &lt;/p&gt;&lt;br /&gt; ## &lt;/desc&gt;&lt;br /&gt; gen_tunable(mozilla_$1_network_connect, false)&lt;br /&gt;&lt;br /&gt; type $1_mozilla_t, mozilla_domain;&lt;br /&gt; application_domain($1_mozilla_t, mozilla_exec_t)&lt;br /&gt; ubac_constrained($1_mozilla_t)&lt;br /&gt;&lt;br /&gt; role $2 types $1_mozilla_t;&lt;br /&gt;&lt;br /&gt; xserver_object_types_template($1_mozilla)&lt;br /&gt;')&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I am aware that this is a pretty dirty hack, and i am not even sure if this indeed works out the way it appears, but i am just glad and hopeful that it does.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-1242656380149810436?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/1242656380149810436/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/08/advantages-and-disadvantages-of-domain_05.html#comment-form' title='2 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1242656380149810436'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1242656380149810436'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/08/advantages-and-disadvantages-of-domain_05.html' title='The advantages and disadvantages of domain prefixes.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-4625905243698561383</id><published>2010-07-25T08:51:00.000-07:00</published><updated>2010-07-25T08:52:29.820-07:00</updated><title type='text'>About dbus_connect_session_bus and dbus_session_domain. (and other interfaces that include the dbus_session_type attribute)</title><content type='html'>These interfaces currently use the session_bus_type attribute in Fedora.&lt;br /&gt;The problem is that all restricted xwindows and the unconfined users have this attribute assigned to their dbus domain.&lt;br /&gt;&lt;br /&gt;Take for example telepathy, which is a framework that is started by dbus session domains. If you use the dbus_session_domain() interface to start telepathy processes, then this means all restricted xwindows and the unconfined users automatically transition to the telepathy domains when they run telepathy programs from their dbus domains.&lt;br /&gt;&lt;br /&gt;Same goes for the dbus_connect_session_bus() interface in terms of which process that acquire service to which dbus session domains.&lt;br /&gt;&lt;br /&gt;In my branch i went ahead to try and fix this. Instead of using the session_bus_type attribute i use $1_dbusd_t type instead. This way i can define which dbus session can start a program that needs to be started by session dbus domains.&lt;br /&gt;&lt;br /&gt;The problem is that the compiler does not like and permit this. You will run into duplicate declaration issues of the dbus session type ($1_dbusd_t).&lt;br /&gt;&lt;br /&gt;There is a way out of this but it is an ugly work around: Call the interfaces described above in the same optional policy block as where the dbus_role_role is called from.&lt;br /&gt;&lt;br /&gt;By the way: i do not see how dbus can be considered optional.&lt;br /&gt;&lt;br /&gt;The end result is that domains started by dbus session domains can not be optional and should be compiled into the base module.&lt;br /&gt;&lt;br /&gt;Which programs am i talking about? For starters Gnome. Stuff like Gnome configuration daemon, settings daemon, keyring daemon, VFS daemon etc. Then Telepathy, Empathy, Gnome DVB daemon, Vino and who knows what else.&lt;br /&gt;&lt;br /&gt;Also: The dbus_session_bus_client is, in my view, too coarse. It also uses the session_bus_type attribute, allowing the caller to send DBUS messages to all dbus session domains and allowing the caller to stream socket connect to all dbus session domains.&lt;br /&gt;&lt;br /&gt;This is what i am currently using for the two interfaces described above (i left other interfaces affected by dbus_session_type in the current state for now)&lt;br /&gt;&lt;br /&gt;########################################&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Connect to the specified session BUS&lt;br /&gt;## for service (acquire_svc).&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;param name="role_prefix"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Prefix to be used.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;## &lt;param name="domain"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Domain allowed access.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;#&lt;br /&gt;interface(`dbus_connect_session_bus_to',`&lt;br /&gt; gen_require(`&lt;br /&gt;  type $1_dbusd_t;&lt;br /&gt;  class dbus acquire_svc;&lt;br /&gt; ')&lt;br /&gt;&lt;br /&gt; allow $2 $1_dbusd_t:dbus acquire_svc;&lt;br /&gt;')&lt;br /&gt;&lt;br /&gt;########################################&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Allow a application domain to be started&lt;br /&gt;## by the session dbus.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;param name="role_prefix"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Domain allowed to transition.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;## &lt;param name="target_domain"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Type to be used as a domain.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;## &lt;param name="entry_point"&gt;&lt;br /&gt;## &lt;summary&gt;&lt;br /&gt;## Type of the program to be used as an&lt;br /&gt;## entry point to this domain.&lt;br /&gt;## &lt;/summary&gt;&lt;br /&gt;## &lt;/param&gt;&lt;br /&gt;#&lt;br /&gt;interface(`dbus_session_domain',`&lt;br /&gt; gen_require(`&lt;br /&gt;  type $1_dbusd_t;&lt;br /&gt; ')&lt;br /&gt;&lt;br /&gt; domtrans_pattern($1_dbusd_t, $3, $2)&lt;br /&gt;&lt;br /&gt; dbus_session_bus_client($2)&lt;br /&gt; dbus_connect_session_bus($2)&lt;br /&gt;')&lt;br /&gt;&lt;br /&gt;Moral of this article: I would be nice if we came up with a proper solution for the issues i described.&lt;br /&gt;&lt;br /&gt;My branch is "hacked" in a way that it works for a large part but it means that my branch diverged even further from upstream than it already did...&lt;br /&gt;&lt;br /&gt;As always: Changes i have made can be reviewed in my Git repository.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-4625905243698561383?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/4625905243698561383/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/about-dbusconnectsessionbus-and.html#comment-form' title='4 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4625905243698561383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4625905243698561383'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/about-dbusconnectsessionbus-and.html' title='About dbus_connect_session_bus and dbus_session_domain. (and other interfaces that include the dbus_session_type attribute)'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5127295639706995179</id><published>2010-07-17T00:37:00.000-07:00</published><updated>2010-07-17T01:28:50.898-07:00</updated><title type='text'>My thoughts on the user domain.</title><content type='html'>- Unconfined_t users are unrestricted except: exec{mod,heap,stack,mem}. They stay in the unconfined domain wherever possible. Sometimes they transition to other unconfined domains. This is only done for the type transition functionality. (to make sure objects get created with the right types)&lt;br /&gt;&lt;br /&gt;- Common users are restricted in the sense that they transition to restricted domains where possible. Besides that, common users should be limited in their functionality as little as possible. They should be able to do anything a normal Linux user can do except run setuid applications. Common users can be divided into the following:&lt;br /&gt;&lt;br /&gt;user_u: plain common user. should "feel" unrestricted, but domain transitions wherever possible. Also can not run setuid applications.&lt;br /&gt;&lt;br /&gt;staff_u: main difference with user_u is that staff users CAN run setuid applications.&lt;br /&gt;&lt;br /&gt;sysadmin_u: should be able to do most everything a normal root can by domain transitioning wherever possible.&lt;br /&gt;&lt;br /&gt;- Restricted users/restricted Xwindows users, domain transition where ever possible but can only do what they should be able to do. Thus by default the restricted user templates should have limited functionality. Ofcourse these user can not run setuid applications either. Examples of restricted users are.&lt;br /&gt;&lt;br /&gt;guest_u: least privilege restricted login users with only access via ssh, no network access. no setuid.&lt;br /&gt;xguest_u: least privilege restricted login users with only access via xdm. no network access. no setuid.&lt;br /&gt;&lt;br /&gt;These restricted users are almost never tailor made for a specific need. (although xguest is currently modified to be allowed more then it should by default in my view)&lt;br /&gt;&lt;br /&gt;Basically one would modify restricted users and restricted xwindows users to allow then exactly what they need plus/minus some policy that is tunable on the fly.&lt;br /&gt;&lt;br /&gt;- Base users: Are even more limited than restricted users. They also cannot manage any user content. They are a base for task specific roles. privileged or unprivileged. Same as with restricted users these base users need to be tailored because by default all you can do is sudo to them (if you have access to setuid)&lt;br /&gt;Examples of base user usage is: webadm, dbadm&lt;br /&gt;&lt;br /&gt;What got me to blog about this? As staff user i was able to run traceroute in the staff_t domain. I was under the assumption that i should have domain transitioned and that user_ping boolean would have denied access.&lt;br /&gt;&lt;br /&gt;Looking closer in the netutils policy i found conflicting rules. There were conditional transition interfaces available (using user_ping condifition) and there was main tunable policy where ping and traceroute are not able to use terminals if user_ping is set to false. This got me curious. Should this apply to common users? The answer in my view is: no.&lt;br /&gt;&lt;br /&gt;Common users should always be able to run traceroute and ping but they should domain transition to the respective domains to do so.&lt;br /&gt;&lt;br /&gt;That leaves us with the conditional interfaces. They can be used with restricted users. If you want to design a restricted user with permission to ping or traceroute on the fly, then you can use these booleans. They are not implemented into the restricted user templates by default because this is not core functionality. plus you may want to use this boolean for one class of restricted users but not for another class.&lt;br /&gt;&lt;br /&gt;I ended up, removing the tunable_policy from the netutils type enforcement source policy file.&lt;br /&gt;&lt;br /&gt;The conclusion i take away from this and other experiences is that there is some confusion about how the various user domains should behave. Over time , the user domain templates have become inconsistent (at least in Fedora.&lt;br /&gt;&lt;br /&gt;Some other examples are that base users can run all applications and can run usr_t files.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5127295639706995179?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5127295639706995179/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/my-thoughts-on-user-domain.html#comment-form' title='3 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5127295639706995179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5127295639706995179'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/my-thoughts-on-user-domain.html' title='My thoughts on the user domain.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-8132497055051247673</id><published>2010-07-13T10:42:00.000-07:00</published><updated>2010-07-13T10:44:06.494-07:00</updated><title type='text'>Rethinking interaction with user content.</title><content type='html'>In the user space there is often a lot of policy to write that defines how users can interact with user content. We usually use the role templates for this. If an confined app create user home, tmp and tmpfs content. We have to allow the user running the app to manage and relabel this content as well.&lt;br /&gt;&lt;br /&gt;In Fedora a start was made to simplify this a bit. Users that have access to the userdom_manage_home_role template are able to manage and relabel any content that is declared userdom_user_home_content. This way we do not have to explicitly define that a user can manage/ relabel some confined apps user home content. Less policy to write. Fedora has this idea only implemented for user_home_content and not for user_tmp or tmpfs_content.&lt;br /&gt;&lt;br /&gt;The userdom_manage_user_home_role is an old template that dates back to the time when we used roles to separate access to content. Also Fedora combines policy to manage/ relabel and do a bunch of other stuff in this single template. This is not really tidy.&lt;br /&gt;&lt;br /&gt;Ive been wanting the idea that Fedora implemented for user home content, for user_tmp and tmpfs content as well. It might save me from writing more policy then strictly required. Hopefully also for pulseaudio which requires processes to manage files on tmpfs. Each application that uses pulseaudio needs to be able to read and delete every other apps pulseaudio tmpfs file, and then send a null signal that the application that owned the tmpfs file it deleted or read. A LOT of policy, which i am hoping to simplify.&lt;br /&gt;&lt;br /&gt;There are some things to consider as well. We have different classes of users. We have unconfined users, which obviously should be able to manage all user content. We also have confined common users. These users are restricted but should behave as normal Linux users as much as possible. Thus should also be able to manage and relabel all user content.&lt;br /&gt;&lt;br /&gt;Then there are the restricted users. These users have least privileges required. There are two kinds of those. restricted users and restricted xwindows users. An example of an restricted user domain is guest_t, and an example of an restricted xwindows user is xguest_t.&lt;br /&gt;&lt;br /&gt;restricted xwindows users need to be able to manage and relabel user content like pulseaudio tmp, tmpfs and user content. And content like Gnome content, Gconf, Window manager, home bin,cert,video, audio etc.&lt;br /&gt;&lt;br /&gt;normal restricted users like guest only need to be able to manage generic user content.&lt;br /&gt;&lt;br /&gt;Xguest_t also needs some special permission besides the basic restricted xwindows permissions, namely managing and relabelling mozilla_user_content and nsplugin_user_content. and since mozilla_t can transition to for example totem_t, these users should also be able to manage totem user content for example.&lt;br /&gt;&lt;br /&gt;So i started by declaring three attributes: user_home_type, user_tmp_type and user_tmpfs_type. These attributes get assigned to all user content. So if an user app manages a file in home, then the type of that content is assigned the user_home_type attribute. If it manages a file on tmpfs it gets assigned the user_tmpfs_type attribute and if it manages a file in tmp the type of that content gets assigned the user_tmp_type attributes. This is done in the userdom_user (home,tmp,tmpfs) content templates which should be used if a type for that purpose is declared.&lt;br /&gt;&lt;br /&gt;I have replaced the userdom_manage (home.tmp,tmpfs) role templates by templates that differentiate between generic user content and all user content. If have also separated the manage, relabel and file transition permissions.&lt;br /&gt;&lt;br /&gt;The way i plan to use this is as follows: The userdom_login_user_template is shared by all login users (except unconfined users in fedora) So that means both common and restricted users. Therefore, if i add the userdom_manage_all_home_content template call there then that would mean that restricted users can manage all user content. Not what i want. Instead i will add permission to manage relabel and file transition to generic user content to this template. For common users i additionally plan to add permissions to manage and relabel all user content. Unconfined users also get access to manage and relabel all content in the unconfined user module obviously.&lt;br /&gt;&lt;br /&gt;Next thing i plan to do is to extend the restricted_xwindows template to permit managing and relabelling of content that is required for GUI interfaces like gnome content etc.&lt;br /&gt;&lt;br /&gt;Permissions specific to xguest like managing mozilla user content (xguest is permitted to un firefox in the mozilla_t domain) etcetera will be added to the xguest module.&lt;br /&gt;&lt;br /&gt;With this i hope to achieve that i can simplify user content and at the same time keep privileges as tight as possible.&lt;br /&gt;&lt;br /&gt;If you want to see what i have implemented of above thus farm have a look in my Git repository. Use Git log/show to find and review the related commits.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-8132497055051247673?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/8132497055051247673/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/rethinking-interaction-with-user.html#comment-form' title='1 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/8132497055051247673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/8132497055051247673'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/rethinking-interaction-with-user.html' title='Rethinking interaction with user content.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5545377608897108118</id><published>2010-07-12T02:06:00.000-07:00</published><updated>2010-07-12T02:23:29.387-07:00</updated><title type='text'>Targeted configured semi-strict with UBAC for Fedora/Redhat distros.</title><content type='html'>I am maintaining an SELinux policy that is based off of Fedoras' SELinux policy and it aims to merge changes refpolicy as much as possible. It use to have only rather minor differences compared to refpolicy and Fedora but lately it has been diverging pretty much. The source policy is available in my personal shared Git repository and depending on my time it is updated pretty often. I aim to merge any Fedora and refpolicy updates as much as possible as soon as possible. In theory it is latest Fedora policy with refpolicy changes and my own changes. In practice its Fedora plus/minus some bugs/features that i introduced.&lt;br /&gt;&lt;br /&gt;The main property of my policy is that, besides the usual, it aims to confine the user space by default.&lt;br /&gt;As opposed to Fedora, my policy has user based access control enabled. This feature aims to isolate selinux users. In practice it has some rough edges and gothas but it is worth it. So one of the issues is that one has to make sure that the selinux identity field in the security context tuple of user home directories is labeled properly. This is a problem when you add new users. So if a new user is added one should chcon -R -u newuser_u /home/newuser. The second issue is system administration. In my policy, root is mapped to sysadm_u selinux identity, but usually logins as root are not encouraged, and so one logs in as staff_u and then role transitions to either sysadm_r or unconfined_r. This means that you will be root in a sufficient domain but with a ubac constraints. Fortunately unconfined_t has access to the system_r role and can use runcon to run commands using the system_u selinux identity. This is required for many sysadm commands. Example: runcon -u system_u useradd joe.&lt;br /&gt;&lt;br /&gt;My policy installs with root mapped to the selinux identity of root but the root selinux identity does not have default contexts for unconfined. Meaning root cannot login as unconfined_t. Root logs in, in the sysadm_t domain. That should be sufficient. On installation the unconfined module is disabled. It can optionally manually be enabled after installation. updating policy will not try to disable it again if you did. The unconfined_u selinux user mapping was removed by default. You can manually add it if required but my policy does not encourage unconfined logins. This is also why unconfined_login boolean is set to false by default.&lt;br /&gt;&lt;br /&gt;Users that need to have access to privileged domains and dacs root should be mapped to staff_u. These users should use sudo to change to root and to role transition:&lt;br /&gt;&lt;br /&gt;echo "joe ALL=(ALL) TYPE=unconfined_t ROLE=unconfined_r ALL" &gt;&gt; /etc/sudoers&lt;br /&gt;&lt;br /&gt;My policy adds some confinement for some user apps. Most notably currently:&lt;br /&gt;firefox, nsplugin, totem, telepathy, mutt, thunderbird, elinks, irssi, metacity, gnome dvb, seahorse-daemon, vino_server and others.&lt;br /&gt;&lt;br /&gt;So it is targeted policy that is configured in a semi strict fashion. unconfined logins by default are prohibited but the unconfined role/domain can be used as an replacement for sysadm_r/sysadm_t to use with sudo. Also the policy has selinux user isolation, so the various selinux users cannot interfere with eachother.&lt;br /&gt;&lt;br /&gt;To make an rpm of my policy is pretty straight forward on fedora.&lt;br /&gt;You can clone my refpolicy repository:&lt;br /&gt;&lt;br /&gt;git clone git://217.19.30.59/refpolicy.git&lt;br /&gt;&lt;br /&gt;or update it after you cloned it:&lt;br /&gt;&lt;br /&gt;cd refpolicy; git pull&lt;br /&gt;&lt;br /&gt;(Mind you that my IP address is dynamic. It does not change often but it can change. Just "/whois" me on irc.freenode.org to get my current IP address and use that.&lt;br /&gt;&lt;br /&gt;To determine my main policy version either look at the tags or see "Version ; .." in the spec file in "redhat/selinux-policy.spec"&lt;br /&gt;&lt;br /&gt;Replace the version number with the version number in the following commands:&lt;br /&gt;&lt;br /&gt;git archive --format=tar --prefix=refpolicy-3.8.6/ refpolicy | gzip &gt; ~/rpmbuild/SOURCES/refpolicy-3.8.6.tar.gz&lt;br /&gt;&lt;br /&gt;git diff refpolicy master &gt; ~/rpmbuild/SOURCES/refpolicy-3.8.6.patch&lt;br /&gt;&lt;br /&gt;Make sure the path exists (install rpmdevtools) run rpmdev-setuptree.&lt;br /&gt;&lt;br /&gt;Next copy the redhat/selinux-policy.spec from the Git repository:&lt;br /&gt;&lt;br /&gt;cp redhat/selinux-policy.spec ~/rpmbuild/SPECS/&lt;br /&gt;&lt;br /&gt;And build the packages:&lt;br /&gt;&lt;br /&gt;cd ~/rpmbuild/SOURCES/; rpmbuild -ba ../SPECS/selinux-policy.spec&lt;br /&gt;&lt;br /&gt;If you're installing my policy for the first time. e.g. if your current installed policy is stock redhat/fedora policy, then it is encouraged to start clean.&lt;br /&gt;&lt;br /&gt;This means you will lose any modifications that you may have made:&lt;br /&gt;&lt;br /&gt;setenforce 0&lt;br /&gt;yum erase selinux-policy selinux-policy-targeted&lt;br /&gt;mv /etc/selinux /etc/selinux.backup&lt;br /&gt;yum install selinux*.rpm (the build rpms)&lt;br /&gt;touch /.autorelabel &amp;&amp; reboot&lt;br /&gt;&lt;br /&gt;on reboot login as root, you should be in sysadm_t domain and you should be able to add/ fix your login user mapping to staff_u. Once youre login user is mapped to staff_u be sure to fix your login users home and tmp directories context:&lt;br /&gt;semanage login -a -s staff_u -r s0-s0:c0.c1023 joe&lt;br /&gt;chcon -R -u staff_u /home/joe&lt;br /&gt;chcon -R -u staff_u /tmp/joe&lt;br /&gt;chcon -R -u staff_u /var/tmp/joe&lt;br /&gt;&lt;br /&gt;That should be sufficient.&lt;br /&gt;&lt;br /&gt;If pulseadio does not start, then remove ~/.esd_auth ~/.pulse /tmp/.esd* and relogin or restart pulse.&lt;br /&gt;Also you may when you first log in get AVC denials for stuff like metacity trying to access ~/.config (staff_wm_t -&gt; user_home_t), and maybe others as well, ignore it. This is because that directory and others at that point are not restored yet. restorecond -u runs in a gnome-session and should have restored your home directory contexts in the mean time.&lt;br /&gt;&lt;br /&gt;Be prepared to stumble on bugs, issues etcetera. Feel free to contact me if you have questions or comments. Patches welcome.&lt;br /&gt;&lt;br /&gt;I am using this policy myself on two desktop systems (fedora13/Gnome) and several headless servers.&lt;br /&gt;&lt;br /&gt;Warning: Only consider trying this if you are familiar to, and not intimidated by SELinux.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5545377608897108118?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5545377608897108118/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/targeted-configured-semi-strict-with.html#comment-form' title='1 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5545377608897108118'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5545377608897108118'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/07/targeted-configured-semi-strict-with.html' title='Targeted configured semi-strict with UBAC for Fedora/Redhat distros.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-4928461313376429315</id><published>2010-02-14T13:29:00.000-08:00</published><updated>2010-02-14T13:59:33.297-08:00</updated><title type='text'>About apache_content_template</title><content type='html'>In refpolicy there are about eight modules that have calls to apache_content_template in their private policy. These template calls are located in optional policy blocks. This is so that these modules do not depend on the apache module being present. &lt;br /&gt;&lt;br /&gt;The problem is that seven out of these eight modules have file context specifications containing a executable type, that is declared in the apache content template, in their file context file. As far as i know file context specifications are never optional.&lt;br /&gt;&lt;br /&gt;So even though calls to apache content template are optional, they really aren't because the file context specifications that accompany them are not optional.&lt;br /&gt;&lt;br /&gt;This means that eight modules depend on the apache module being installed. Try to de-install the apache module (semodule -r apache) and you will be presented with some very unclear errors. Most people will not know what to do.&lt;br /&gt;&lt;br /&gt;So how can we fix that?&lt;br /&gt;&lt;br /&gt;Well here is an example. We use the apache_cgi_domain() instead:&lt;br /&gt;&lt;br /&gt;########################################&lt;br /&gt;#&lt;br /&gt;# BackupPC admin private declarations.&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;type backuppc_admin_t, backuppc_domains;&lt;br /&gt;type backuppc_admin_exec_t;&lt;br /&gt;domain_type(backuppc_admin_t)&lt;br /&gt;domain_entry_file(backuppc_admin_t, backuppc_admin_exec_t)&lt;br /&gt;role system_r types backuppc_admin_t;&lt;br /&gt;&lt;br /&gt;########################################&lt;br /&gt;#&lt;br /&gt;# BackupPC admin private policy.&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;optional_policy(`&lt;br /&gt; apache_cgi_domain(backuppc_admin_t, backuppc_admin_exec_t)&lt;br /&gt;')&lt;br /&gt;&lt;br /&gt;/usr/share/BackupPC/sbin/BackupPC_Admin     -- gen_context(system_u:object_r:backuppc_admin_exec_t, s0)&lt;br /&gt;&lt;br /&gt;This way we can make the call to apache_cgi_domain() *really* optional. It is a bit more work initially but in my view this is maintainable unlike apache_content_template.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-4928461313376429315?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/4928461313376429315/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/02/about-apachecontenttemplate.html#comment-form' title='17 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4928461313376429315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4928461313376429315'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/02/about-apachecontenttemplate.html' title='About apache_content_template'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-6107822133917796557</id><published>2010-01-14T01:41:00.000-08:00</published><updated>2010-01-14T11:27:29.764-08:00</updated><title type='text'>Test Git daemon policy.</title><content type='html'>Clone my latest selinux-modules git repository:&lt;br /&gt;&lt;br /&gt;git clone git://84.245.6.206/selinux-modules.git&lt;br /&gt;cd selinux-modules &amp;&amp; make -f /usr/share/selinux/devel/Makefile gitd.pp&lt;br /&gt;semodule -d git; semodule -i gitd.pp&lt;br /&gt;cp gitd.if /usr/share/selinux/devel/include/services/gitd.if&lt;br /&gt;&lt;br /&gt;To test the Git session server you should build a custom module calling the gitd_session_role template for your role:&lt;br /&gt;&lt;br /&gt;echo "policy_module(mygittest, 1.0.0)" &gt; mygittest.te;&lt;br /&gt;echo "optional_policy(\`" &gt;&gt; mygittest.te;&lt;br /&gt;echo "gen_require(\`" &gt;&gt; mygittest.te;&lt;br /&gt;echo "# Assuming you want to test as unconfined_t" &gt;&gt; mygittest.te;&lt;br /&gt;echo "type unconfined_t;" &gt;&gt; mygittest.te;&lt;br /&gt;echo "role unconfined_r;" &gt;&gt; mygittest.te;&lt;br /&gt;echo "')" &gt;&gt; mygittest.te;&lt;br /&gt;echo "gitd_session_role(unconfined_r, unconfined_t)" &gt;&gt; mygittest.te;&lt;br /&gt;echo "')" &gt;&gt; mygittest.te;&lt;br /&gt;&lt;br /&gt;make -f /usr/share/selinux/devel/Makefile mygittest.pp&lt;br /&gt;semodule -i mygittest.pp&lt;br /&gt;&lt;br /&gt;Make sure that port tcp:9418 open and that tcp-wrappers is configured to accept connectivity on this port.&lt;br /&gt;&lt;br /&gt;install git-daemon and its dependencies: yum install git-daemon.&lt;br /&gt;&lt;br /&gt;You must edit /etc/xinetd.d/git. set "disable" to "no", "server" to "/usr/libexec/git-core/git-daemon", and remove the "daemon" argument from "server_args". Keep an eye on /var/log/messages in case it behaves strange.&lt;br /&gt;&lt;br /&gt;Restore the following contexts:&lt;br /&gt;&lt;br /&gt;restorecon -R -v /var/lib/git&lt;br /&gt;restorecon -v /usr/libexec/git-core/git-daemon&lt;br /&gt;restorecon -v ~/.gitconfig&lt;br /&gt;restorecon -v ~/public_git&lt;br /&gt;&lt;br /&gt;Start xinetd: service xinetd start.&lt;br /&gt;&lt;br /&gt;Set up a default git shell user for generic shared repositories:&lt;br /&gt;&lt;br /&gt;groupadd git&lt;br /&gt;useradd -Z git_shell_u -M -s /usr/bin/git-shell joe&lt;br /&gt;usermod -a -G git joe&lt;br /&gt;passwd joe&lt;br /&gt;&lt;br /&gt;Set up a bare "test" shared repostory:&lt;br /&gt;&lt;br /&gt;mkdir /var/lib/git/test.git&lt;br /&gt;cd /var/lib/git/test.git &amp;&amp; git --bare init&lt;br /&gt;chown -R root:git /var/lib/git/test.git&lt;br /&gt;chmod -R g+w /var/lib/git/test.git&lt;br /&gt;chmod -R g+s /var/lib/git/test.git&lt;br /&gt;chmod -R +t /var/lib/git/test.git&lt;br /&gt;&lt;br /&gt;From your "normal" user account clone the bare repository:&lt;br /&gt;&lt;br /&gt;git clone git://localhost/test.git&lt;br /&gt;cd test&lt;br /&gt;&lt;br /&gt;Make changes to it:&lt;br /&gt;&lt;br /&gt;echo "test" &gt; test;&lt;br /&gt;git init&lt;br /&gt;git add .&lt;br /&gt;git commit -a -s -m "My initial commit."&lt;br /&gt;&lt;br /&gt;As user "joe" push to the shared repository:&lt;br /&gt;&lt;br /&gt;git push --all git+ssh://joe@localhost/var/lib/git/test.git&lt;br /&gt;git pull&lt;br /&gt;git status&lt;br /&gt;git show&lt;br /&gt;&lt;br /&gt;Testing Git session:&lt;br /&gt;&lt;br /&gt;Stop xinetd and in your "normal" (we are done with "joe" for now) user home directory make sure ~/public_git exists.&lt;br /&gt;restorecon -R -v /public_git&lt;br /&gt;Previously we called a "gitd_session_role" template for users operating in the unconfined_t domain. This means when your id -Z returns: unconfined_u:unconfined_r:unconfined_t:s0, git with the daemon option will run in a Git session SELinux environment for you.&lt;br /&gt;&lt;br /&gt;Create a new personal repository in ~/public_git:&lt;br /&gt;&lt;br /&gt;mkdir ~/public_git/hello&lt;br /&gt;cd ~/public_git/hello&lt;br /&gt;git init&lt;br /&gt;echo "hello" &gt; hello&lt;br /&gt;git add .&lt;br /&gt;git commit -a -s -m "My initial commit."&lt;br /&gt;&lt;br /&gt;Serve your personal repository with the following command:&lt;br /&gt;&lt;br /&gt;git daemon --export-all --user-path=public_git&lt;br /&gt;&lt;br /&gt;In another terminal clone the repository:&lt;br /&gt;&lt;br /&gt;git clone git://localhost/~yourloginnamehere/hello&lt;br /&gt;&lt;br /&gt;Make a commit to it:&lt;br /&gt;&lt;br /&gt;cd hello&lt;br /&gt;echo "bye" &gt;&gt; hello&lt;br /&gt;git commit -a -s -m "Add good bye"&lt;br /&gt;&lt;br /&gt;Push the change to your personal repository:&lt;br /&gt;&lt;br /&gt;git push --all ssh://yourloginnamehere@localhost/~/public_git/hello&lt;br /&gt;&lt;br /&gt;Hosting personal repositories with Git system daemon.&lt;br /&gt;&lt;br /&gt;Stop your Git session daemon (ctrl-c) and start xinetd.&lt;br /&gt;&lt;br /&gt;Set the boolean to allow the Git system daemon to search user home directories for personal Git repositories to serve:&lt;br /&gt;&lt;br /&gt;setsebool gitd_system_enable_homedirs on&lt;br /&gt;&lt;br /&gt;Now clone the personal repository again:&lt;br /&gt;&lt;br /&gt;git clone git://localhost/~yourloginnamehere/hello&lt;br /&gt;cd hello&lt;br /&gt;echo "hi" &gt;&gt; hello&lt;br /&gt;git commit -a -s -m "Added Hi."&lt;br /&gt;&lt;br /&gt;And push to the personal repository:&lt;br /&gt;&lt;br /&gt;git push --all ssh://yourloginnamehere@localhost/~/public_git/hello&lt;br /&gt;&lt;br /&gt;Create a customized Git Shell user that has access to a restricted shared repository (besides having access to any generic system repositories) Also create a restricted repository and allow our created Git shell user access to this new restricted repository.&lt;br /&gt;&lt;br /&gt;echo "policy_module(secret_git_shell, 1.0.0)" &gt; secret_git_shell.te;&lt;br /&gt;echo "gitd_role_template(secret_git_shell)" &gt;&gt; secret_git_shell.te;&lt;br /&gt;echo "gitd_content_template(secret)" &gt;&gt; secret_git_shell.te;&lt;br /&gt;echo "gitd_content_delegation(secret_git_shell_t, gitd_secret_content_t)" &gt;&gt; secret_git_shell.te;&lt;br /&gt;echo "gen_user(secret_git_shell_u, user, secret_git_shell_r, s0, s0)" &gt;&gt; secret_git_shell.te;&lt;br /&gt;&lt;br /&gt;echo "/var/lib/git/secret\.git(/.*)? gen_context(system_u:object_r:gitd_secret_content_t, s0)" &gt; secret_git_shell.fc;&lt;br /&gt;&lt;br /&gt;make -f /usr/share/selinux/devel/Makefile secret_git_shell.pp&lt;br /&gt;semodule -i secret_git_shell.pp&lt;br /&gt;&lt;br /&gt;Create a secret Git shell user:&lt;br /&gt;&lt;br /&gt;useradd -Z secret_git_shell_u -M -s /usr/bin/git-shell jane&lt;br /&gt;usermod -a -G git jane&lt;br /&gt;passwd jane&lt;br /&gt;&lt;br /&gt;Create a bare secret shared repository:&lt;br /&gt;&lt;br /&gt;mkdir /var/lib/git/secret.git&lt;br /&gt;cd /var/lib/git/secret.git &amp;&amp; git --bare init&lt;br /&gt;chown -R root:git /var/lib/git/secret.git&lt;br /&gt;chmod -R g+w /var/lib/git/secret.git&lt;br /&gt;chmod -R g+s /var/lib/git/secret.git&lt;br /&gt;chmod -R +t /var/lib/git/secret.git&lt;br /&gt;&lt;br /&gt;Restore the context of the secret repository:&lt;br /&gt;&lt;br /&gt;restorecon -R -v /var/lib/git/secret.git&lt;br /&gt;&lt;br /&gt;Everyone can read it but only jane can push to it. As a "normal" user clone the secret repository.&lt;br /&gt;&lt;br /&gt;git clone git://localhost/secret.git&lt;br /&gt;cd secret&lt;br /&gt;echo "secret" &gt; secret&lt;br /&gt;git init&lt;br /&gt;git add .&lt;br /&gt;git commit -a -s -m "My first commit."&lt;br /&gt;&lt;br /&gt;Push it as user "jane"&lt;br /&gt;&lt;br /&gt;git push --all git+ssh://jane@localhost/var/lib/git/secret.git&lt;br /&gt;git pull&lt;br /&gt;git status&lt;br /&gt;git show&lt;br /&gt;&lt;br /&gt;Make another commit:&lt;br /&gt;&lt;br /&gt;echo "Joe here" &gt;&gt; secret&lt;br /&gt;git commit -a -s -m "add Joe here"&lt;br /&gt;&lt;br /&gt;Now try to push it as user "joe" (joe can push generic shared repositories but joe is not allowed to push to the secret repository)&lt;br /&gt;&lt;br /&gt;git push --all git+ssh://joe@localhost/var/lib/git/secret.git&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-6107822133917796557?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/6107822133917796557/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2010/01/test-git-daemon-policy.html#comment-form' title='7 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/6107822133917796557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/6107822133917796557'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2010/01/test-git-daemon-policy.html' title='Test Git daemon policy.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-1254384423721238855</id><published>2009-10-21T01:45:00.000-07:00</published><updated>2009-10-21T03:03:07.916-07:00</updated><title type='text'>Git daemon, SELinux and Fedora 12 Beta.</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial;"&gt;Recently i decided to redo my Git daemon domain and reinstall a Git daemon server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This article will explain the issues i had to consider.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELinux can be used to confined the Git daemon and Git Shell. I have not used SELinux in a optimal way here but i decided to implement a mix of MAC, DAC and Git ACL.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;As for SELinux i have installed the following module:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gitd.te:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;"&gt;[code]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;policy_module(gitd, 1.0.0)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git daemon global private declarations.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;attribute gitd_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;attribute gitd_content_type;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gitd_exec_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# FIXME&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gitd_port_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_port(gitd_port_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git daemon system private declarations.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## Allow Git-shell to modify and execute public files&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## used for public file transfer services. Directories/Files must&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## be labeled public_content_rw_t.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# gen_tunable(gitd_allow_anon_write, false)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## Allow Git daemon system to search home directories.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gen_tunable(gitd_system_enable_homedirs, false)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## Allow Git daemon system to access cifs file systems.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gen_tunable(gitd_system_use_cifs, false)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## Allow Git daemon system to access nfs file systems.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gen_tunable(gitd_system_use_nfs, false)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gitd_system_t, gitd_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;inetd_service_domain(gitd_system_t, gitd_exec_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;role system_r types gitd_system_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gitd_shared_t, gitd_content_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files_type(gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# permissive gitd_system_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git shell private declarations.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    attribute unpriv_userdomain, userdomain;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    class context contains;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;attribute gits_file_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;attribute gits_usertype;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gits_t, userdomain, gits_usertype, unpriv_userdomain;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;domain_type(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;role gits_r types gits_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow system_r gits_r;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corecmd_shell_entry_type(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corecmd_bin_entry_type(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;domain_interactive_fd(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;domain_user_exemption_target(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# permissive gits_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git daemon session session private declarations.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## Allow Git daemon session to bind&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## tcp sockets to all unreserved ports.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gen_tunable(gitd_session_bind_all_unreserved_ports, false)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gitd_session_t, gitd_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;application_domain(gitd_session_t, gitd_exec_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;ubac_constrained(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type gitd_personal_t, gitd_content_type;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;userdom_user_home_content(gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# permissive gitd_session_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git daemon global private policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gitd_type self:fifo_file rw_fifo_file_perms;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gitd_type self:netlink_route_socket { create_socket_perms nlmsg_read };&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gitd_type self:tcp_socket create_socket_perms;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gitd_type self:udp_socket create_socket_perms;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gitd_type self:unix_dgram_socket create_socket_perms;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# FIXME&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gitd_type gitd_port_t:tcp_socket name_bind;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_all_recvfrom_netlabel(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_all_recvfrom_unlabeled(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_tcp_sendrecv_all_if(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_tcp_sendrecv_all_nodes(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_tcp_sendrecv_all_ports(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corenet_tcp_bind_all_nodes(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corecmd_exec_bin(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files_read_etc_files(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files_read_usr_files(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;fs_search_auto_mountpoints(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;kernel_read_system_state(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;logging_send_syslog_msg(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;miscfiles_read_localization(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;sysnet_read_config(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;optional_policy(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    nis_use_ypbind(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;optional_policy(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    nscd_read_pid(gitd_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git daemon system repository private policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;list_dirs_pattern(gitd_system_t, gitd_content_type, gitd_content_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;read_files_pattern(gitd_system_t, gitd_content_type, gitd_content_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files_search_var(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# This will not work since git-shell needs to execute gitd content thus public content files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# There is currently no clean way to execute public content files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# miscfiles_read_public_files(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_enable_homedirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    userdom_search_user_home_dirs(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_enable_homedirs &amp;amp;&amp;amp; use_nfs_home_dirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_list_nfs(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_read_nfs_files(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_enable_homedirs &amp;amp;&amp;amp; use_samba_home_dirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_list_cifs(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_read_cifs_files(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_use_cifs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_list_cifs(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_read_cifs_files(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_use_nfs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_list_nfs(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_read_nfs_files(gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git shell private policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gits_t self:context contains;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow gits_t self:fifo_file rw_fifo_file_perms;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;corecmd_exec_bin(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;kernel_read_system_state(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files_read_etc_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files_search_home(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gitd_execute_shared_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gitd_manage_shared_content(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;miscfiles_read_localization(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# miscfiles_read_public_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;ssh_rw_stream_sockets(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# FIXME&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# This will not work since git-shell needs to execute gitd content thus public content files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# There is currently no clean way to execute public content files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# tunable_policy(`gitd_allow_anon_write', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # miscfiles_exec_public_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # miscfiles_manage_public_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_enable_homedirs &amp;amp;&amp;amp; use_nfs_home_dirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_exec_nfs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_nfs_dirs(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_nfs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_enable_homedirs &amp;amp;&amp;amp; use_samba_home_dirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_exec_cifs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_cifs_dirs(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_cifs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_use_cifs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_exec_cifs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_cifs_dirs(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_cifs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_system_use_nfs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_exec_nfs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_nfs_dirs(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_manage_nfs_files(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;optional_policy(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    nscd_read_pid(gits_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Git daemon session repository private policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;list_dirs_pattern(gitd_session_t, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;read_files_pattern(gitd_session_t, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;userdom_search_user_home_dirs(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;userdom_use_user_terminals(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`gitd_session_bind_all_unreserved_ports', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    corenet_tcp_bind_all_unreserved_ports(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`use_nfs_home_dirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_list_nfs(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_read_nfs_files(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;tunable_policy(`use_samba_home_dirs', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_list_cifs(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    fs_read_cifs_files(gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[/code]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gitd.if&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[code]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;Git daemon is a really simple server for Git repositories.&lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        A really simple TCP git daemon that normally listens on&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        port DEFAULT_GIT_PORT aka 9418. It waits for a&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        connection asking for a service, and will serve that&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        service if it is enabled.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        It verifies that the directory has the magic file&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        git-daemon-export-ok, and it will refuse to export any&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        git directory that has not explicitly been marked for&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        export this way (unless the --export-all parameter is&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        specified). If you pass some directory paths as&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        git-daemon arguments, you can further restrict the&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        offers to a whitelist comprising of those.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        By default, only upload-pack service is enabled, which&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        serves git-fetch-pack and git-ls-remote clients, which&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        are invoked from git-fetch, git-pull, and git-clone.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        This is ideally suited for read-only updates, i.e.,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        pulling from git repositories.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##        An upload-archive also exists to serve git-archive.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#######################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Role access for Git daemon session.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="role"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Role allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    User domain for the role.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_session_role', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_session_t, gitd_exec_t, gitd_personal_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    #&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # Git daemon session shared declarations.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    #&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ## &lt;desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ## &lt;p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ## Allow transitions to the Git daemon&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ## session domain.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ## &lt;/p&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ## &lt;/desc&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_tunable(gitd_session_transition, false)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    role $1 types gitd_session_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    #&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # Git daemon session shared policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    #&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    tunable_policy(`gitd_session_transition', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        domtrans_pattern($2, gitd_exec_t, gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        can_exec($2, gitd_exec_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    allow $2 gitd_session_t:process { ptrace signal_perms };&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ps_process_pattern($2, gitd_session_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    exec_files_pattern($2, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_dirs_pattern($2, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_files_pattern($2, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    relabel_dirs_pattern($2, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    relabel_files_pattern($2, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to execute&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon shared files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_execute_shared_files', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_shared_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    exec_files_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_var($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to manage&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon shared content.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_manage_shared_content', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_shared_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_dirs_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_files_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_var($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to manage&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon personal content.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_manage_personal_content', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_personal_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_dirs_pattern($1, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_files_pattern($1, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_home($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to read&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon personal content.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_read_personal_content', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_personal_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    list_dirs_pattern($1, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    read_files_pattern($1, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_home($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to read&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon shared content.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_read_shared_content', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_shared_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    list_dirs_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    read_files_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_var($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to relabel&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon shared content.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_relabel_shared_content', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_shared_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    relabel_dirs_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    relabel_files_pattern($1, gitd_shared_t, gitd_shared_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_var($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Allow the specified domain to relabel&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon personal content.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_relabel_personal_content', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_personal_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    relabel_dirs_pattern($1, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    relabel_files_pattern($1, gitd_personal_t, gitd_personal_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    files_search_home($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;########################################&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    All of the rules required to administrate an&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Git daemon system environment&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="userdomain_prefix"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Prefix of the domain. Example, user would be&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    the prefix for the user_t domain.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="domain"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    Domain allowed access.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;param name="role"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    The role to be allowed to manage the Git daemon domain.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;##    &lt;/summary&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;/param&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;## &lt;rolecap/&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interface(`gitd_system_admin', `&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gen_require(`&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type gitd_system_t, gitd_exec_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    ')&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    allow $1 gitd_system_t:process { getattr ptrace signal_perms };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    kernel_search_proc($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    allow $1 git_system_t:dir list_dir_perms;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    read_files_pattern($1, gitd_system_t, gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    read_lnk_files_pattern($1, gitd_system_t, gitd_system_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    manage_files_pattern($1, gitd_exec_t, gitd_exec_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # This will not work since git-shell needs to execute gitd content thus public content files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # There is currently no clean way to execute public content files.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    # miscfiles_manage_public_files($1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gitd_manage_shared_content($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    gitd_relabel_shared_content($1)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;    seutil_domtrans_setfiles($1)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;')&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[/code]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;gitd.fc&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[code]HOME_DIR/public_git(/.*)?                    gen_context(system_u:object_r:gitd_personal_t, s0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;HOME_DIR/\.gitconfig                --        gen_context(system_u:object_r:gitd_personal_t, s0)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;/srv/git(/.*)?                            gen_context(system_u:object_r:gitd_shared_t, s0)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;/usr/libexec/git-core/git-daemon        --        gen_context(system_u:object_r:gitd_exec_t, s0)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# Conflict with Fedora cgit fc spec.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# /var/lib/git(/.*)?                        gen_context(system_u:object_r:gitd_shared_t, s0)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[/code]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;I manually labelled tcp:9418 gitd_port_t&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[code]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;semanage port -a -t gitd_port_t -p tcp 9418&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[/code]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I also manually added a SELinux user mapping:&lt;br /&gt;&lt;br /&gt;semanage user -a -L s0 -r s0 -R "gits_r" -P gits_u&lt;br /&gt;&lt;br /&gt;echo "system_r:sshd_t:s0              gits_r:gits_t:s0" &gt; /etc/selinux/targeted/contexts/users/gits_u&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;I edited /etc/xinetd.d/git:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[code]&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre class="bz_comment_text" id="comment_text_0"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial;"&gt;# default: off&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# description: The git dæmon allows git repositories to be exported using \&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#       the git:// protocol.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;service git&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        disable         = no&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        socket_type     = stream&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        type            = UNLISTED&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        port            = 9418&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        wait            = no&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        user            = nobody&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#        server          = /usr/bin/git&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;#        server_args     = daemon --base-path=/srv/git --export-all&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;--user-path=public_git --syslog --inetd --verbose&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        server          = /usr/libexec/git-core/git-daemon&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        server_args     = --base-path=/srv/git --export-all&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;--user-path=public_git --syslog --inetd --verbose&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        log_on_failure  += USERID&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;# xinetd doesn't do this by default. &lt;/span&gt;&lt;span style="font-family: arial;" class="bz_closed"&gt;&lt;a href="https://bugzilla.redhat.com/show_bug.cgi?id=195265" title="CLOSED ERRATA - xinetd doesn't listen on IPv6 by default."&gt;bug #195265&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;        flags           = IPv6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;[/code]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Basically the selinux policy has 3 parts. one part is for the gitd system inetd server. the second part is for running gitd as a unprivileged user, and the third part is policy for the system wide git-shell environment.&lt;br /&gt;So we secure the system wide gitd process, gitd process that users run and the git-shell process that is used to push pull to shared repositories.&lt;br /&gt;&lt;br /&gt;When you compile git-daemon, configured it like above and install the selinux module, restore the contexts of the paths in gitd.fc. then start xinetd: youll notice that inetd_t is not allowed to bind to gitd_port_t.&lt;br /&gt;You can simply use audit2allow with the -M option to allow inetd_t to bind to gitd_port on behalf of gitd_system_t&lt;br /&gt;&lt;br /&gt;I use DAC to give usergroups access to the particular repositories and i use git ACL to restrict access to branches, tags etc.&lt;br /&gt;&lt;br /&gt;I used this great web site do implement this:&lt;br /&gt;&lt;br /&gt;http://www.kernel.org/pub/software/scm/git/docs/everyday.html&lt;br /&gt;&lt;br /&gt;I wrote two simple scripts:&lt;br /&gt;&lt;br /&gt;1. to add new users&lt;br /&gt;2. to add new repostiries&lt;br /&gt;&lt;br /&gt;create_repository:&lt;br /&gt;&lt;br /&gt;crepo.sh:&lt;br /&gt;[code]&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;# crepo.sh &lt;repository&gt;&lt;br /&gt;&lt;br /&gt;groupadd $1 || exit 1;&lt;br /&gt;usermod -a -G $1 badabing || exit 1;&lt;br /&gt;&lt;br /&gt;mkdir /srv/git/$1.git || exit 1;&lt;br /&gt;chmod -R +t /srv/git/$1.git || exit 1;&lt;br /&gt;cd /srv/git/$1.git &amp;amp;&amp;amp; git --bare init || exit 1;&lt;br /&gt;&lt;br /&gt;cp /home/dgrift/create_repository/update /srv/git/$1.git/hooks/ || exit 1;&lt;br /&gt;cp /home/dgrift/create_repository/allowed-users /srv/git/$1.git/info/ || exit 1;&lt;br /&gt;&lt;br /&gt;chown -R nobody:$1 /srv/git/$1.git || exit 1;&lt;br /&gt;&lt;br /&gt;chmod -R g+s /srv/git/$1.git/branches || exit 1;&lt;br /&gt;chmod -R g+s /srv/git/$1.git/hooks || exit 1;&lt;br /&gt;chmod -R g+s /srv/git/$1.git/info || exit 1;&lt;br /&gt;chmod -R g+s /srv/git/$1.git/objects || exit 1;&lt;br /&gt;chmod -R g+s /srv/git/$1.git/refs || exit 1;&lt;br /&gt;chmod -R g+w /srv/git/$1.git || exit 1;&lt;br /&gt;&lt;br /&gt;exit 0;&lt;br /&gt;&lt;br /&gt;#EOF&lt;br /&gt;[/code]&lt;br /&gt;&lt;br /&gt;This script installs the git ACL files update and allowed-users:&lt;br /&gt;&lt;br /&gt;update:&lt;br /&gt;[code]&lt;br /&gt;http://www.kernel.org/pub/software/scm/git/docs/howto/update-hook-example.txt&lt;br /&gt;[/code]&lt;br /&gt;&lt;br /&gt;allowed-users:&lt;br /&gt;[code]&lt;br /&gt;refs/heads/master       badabing&lt;br /&gt;+refs/heads/pu          badabing&lt;br /&gt;refs/heads/bw/.*        badabing&lt;br /&gt;refs/heads/tmp/.*       .*&lt;br /&gt;refs/tags/v[0-9].*      badabing&lt;br /&gt;[/code]&lt;br /&gt;&lt;br /&gt;I also created a script to do part of what is required to add new users (i havent tested this script yet:&lt;br /&gt;&lt;br /&gt;[code]&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;# agits.sh &lt;username&gt; &lt;repository&gt;&lt;br /&gt;&lt;br /&gt;useradd -Z gits_u -s /usr/bin/git-shell $1 || exit 1;&lt;br /&gt;usermod -a -G sshusers,$2 $1 || exit 1;&lt;br /&gt;&lt;br /&gt;echo "Do not forget to set a password!"&lt;br /&gt;echo "Manually add entries for $1 in /etc/security/namespace.conf!"&lt;br /&gt;echo "You may need to edit /srv/git/$2.git/info/allowed-users!"&lt;br /&gt;&lt;br /&gt;# TODO: usrquota&lt;br /&gt;&lt;br /&gt;exit 0;&lt;br /&gt;[/code]&lt;br /&gt;&lt;br /&gt;By the way xinetd and selinux dont play nice so you may need to edit the xinetd init script:&lt;br /&gt;&lt;br /&gt;[code]&lt;br /&gt;https://bugzilla.redhat.com/show_bug.cgi?id=529681&lt;br /&gt;[/code]&lt;br /&gt;&lt;br /&gt;So that is basically it.&lt;br /&gt;The SELinux policy for the git system service should work by default. Additionally there are some booleans to to toggle for example to allow the git system service to also host personal repositories in ~/public_git, allow git to use any unreserved port for mass git repostory hosting. enable disable transition to git_session_t which is the user daemon.&lt;br /&gt;For this to work you must also enable git policy for users by creating a module:&lt;br /&gt;&lt;br /&gt;for example if you want unconfined users to transition to git domain if they run git daemon &lt;...&gt;&lt;br /&gt;&lt;br /&gt;myunconfined.te:&lt;br /&gt;[code]&lt;br /&gt;policy_module(myunconfined, 0.0.1)&lt;br /&gt;optional_policy(`&lt;br /&gt;gen_require(`&lt;br /&gt; type unconfined_t;&lt;br /&gt;')&lt;br /&gt;&lt;br /&gt;git_session_role(unconfined_r, unconfined_t)&lt;br /&gt;[/code]&lt;br /&gt;&lt;br /&gt;build and install that:&lt;br /&gt;&lt;br /&gt;make -f /usr/share/selinux/devel/Makefile&lt;br /&gt;sudo semodule -i myunconfined.pp&lt;br /&gt;&lt;br /&gt;That should work and make unconfined_t users transition to git_session_t when they run git daemon &lt;...&gt;&lt;br /&gt;&lt;br /&gt;For me this setup works, but i have not thoroughly tested the git_session_t domain yet.&lt;br /&gt;&lt;br /&gt;Would be nice to get some feedback so that i can improve this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The git selinux policy is malformed above use the command below to pull the current gitd policy from my git repository&lt;br /&gt;&lt;br /&gt;git clone git://&lt;/span&gt;&lt;/span&gt;&lt;span style="display: inline;" id="ip"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial;"&gt;82.197.205.60/selinux-modules.git&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-1254384423721238855?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/1254384423721238855/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/10/git-daemon-selinux-and-fedora-12-beta.html#comment-form' title='2 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1254384423721238855'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1254384423721238855'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/10/git-daemon-selinux-and-fedora-12-beta.html' title='Git daemon, SELinux and Fedora 12 Beta.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-1511886773288714711</id><published>2009-10-06T15:14:00.000-07:00</published><updated>2009-10-06T15:25:39.845-07:00</updated><title type='text'>My view on domains, domain types, roles, domain transitions and more.</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family: arial;"&gt;A domain is an environment in which a process operates. That environment is defined by the access vectors where a particular process is the sources.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Sometimes people refer to types of processes as domains. This is technically incorrect. Types of processes are domain types.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A domain is a general term for process environments. Processes can have different natures or properties. For example a user process environment can be called a domain and a process of a program can also be called a domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In SELinux world we like to "label" everything. So instead of calling a user process environment a domain we call it a user domain. The type of a user process is called a user domain type although technically its a domain type since user processes are processes.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Besides user domains, there are more different domains. These domains are defined by who transitioned to them. For example, init daemons are started by init scripts. The init script process sandbox is called init script domain and process environments that init script domains transition to are called init daemon domains.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Examples of init daemon domains are the environment of the httpd_t init daemon domain type, or postgresql. The main property is that these processes are started by init scripts.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Process environments of programs that user process environments transition to are called application domains, and the type of such a process is called a application domain type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It depends on what transitions to what, that defines what domain it is. A cgi webapp that operates in its own environment is called a apache daemon domain if the httpd_t init daemon domain transitions to the process environment of a cgi webapp.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are many more such domains and they are defined by what domain transitioned to them.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Domain transitions occur upon entrypoints. An entrypoint is a defined path to usually a  executable file. Types of executable files are called executable file types. They are important in entrypoints to domains.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;apache init script has a executable file type called for example httpd_initrc_exec_t.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When the init_t domain type executes the file with executable file type httpd_initrc_exec_t,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;the process of that executable file type will get the initrc_t domain type and the process will operate in the init script domain (init script process environment).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The entrypoint is:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;init_t -&gt; httpd_initrc_exec_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This entrypoint leads to the initrc_t process environment. (init script domain)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now this starts all over again when the process that has domain type initrc_t runs the apache executable.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Assuming in this example that /usr/sbin/httpd is apaches executable file and that it has a executable file type of httpd_exec_t.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The entrypoint is:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;initrc_t -&gt; httpd_exec_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The init script domain type runs the apache executable file type. There is a rule that says:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;when initrc_t executes httpd_exec_t, then transition to the httpd_t process environment type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;initrc_t -&gt; httpd_exec_t -&gt; httpd_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;initrc_t is a (init script) domain type. policy where initrc_t is the source type is called a init script domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;httpd_exec_t is a executable file type.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;initrc_t -&gt; httpd_exec_t is the entrypoint to the httpd_t domain (type)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;httpd_t -&gt; is a (init daemon) domain type. policy where httpd_t is the source type is called a init daemon domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are api available that make transitioning to these types of domains easier.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For example you can simply call the init_daemon_domain() interface if your process is started by a init script. proper calling of this single interface will take care of some of the declarations that are required. it will also set up a domain transition pattern.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type myinitdaemondomaintype_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type myinitdaemondomaintypeexecutablefiletype_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;init_daemon_domain(myinitdaemondomaintype_t, myinitdaemondomaintypeexecutablefiletype_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This will instruct SELinux to let processes that run in the initrc_t init script domain that execute files with executable file type myinitdaemondomaintypeexecutablefiletype_t, domain transition to the myinitdaemondomaintype_t process enviroment and give that process the init daemon domain type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;initrc_t -&gt; myinitdaemondomaintypeexecutablefiletype_t -&gt; myinitdaemondomaintype_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This ofcourse requires that file files in question are labelled accordingly.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;application domains are handled a bit differently. This is mainly because of RBAC.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Role based access control is a mechanism that allows a single user to operate in various environments (user domains)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This means that you must also define which role is allowed to use the target domain type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;user_t: user domain type&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;userapp_exec_t: (application) executable file type of the application to transition to.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;userapp_t: application domain type&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;entrypoint:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;user_t -&gt; userapp_exec_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Target of the entry point:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;userapp_tRole of the user that this domain transition pattern is defined for:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;user_r&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type user_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;type userapp_exec_t;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;application_domain(user_t, userapp_exec_t)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;role user_r types userapp_t;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;domain_transition_pattern(user_t, userapp_exec_t, userapp_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Again same idea but its just a bit more complicated than the init daemon domain because users&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(and applications started by users) can have different roles.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Applications started by init (system) can only have one role(system_r), So that makes the init daemon domains less complicated.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Explained:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When a user process that operates in the user_t user process environment runs a file with executable file type myapp_exec_t, then the process of that executable file type will run in the myapp_t application process environment (application domain).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Since users can have different roles we also define that particular role to have access to the application domain type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;We also manually define a domain transition pattern (user_t -&gt; myapp_exec_t -&gt; myapp_t)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Keep in mind that domains transitioned to by users also have to deal with roles, unlike domain transitioned to by system processes. processes where the role field in the context is system_r.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Your policy source has many example of the different domains. If you want to write policy for a init daemon than look up an example of a init daemon domain in the source policy, and see if that can get you started. Idem ditto for application domains, apache daemon domains, xinet service domains, dbus service domains and etcetera.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;User domains are different. They arent started by other processes. instead a real person logs into the system and by running a tty or pts a new domain is initiated. These transtions are defined both in the user domain policy and selinux mappings, many of which can be defined with the semanage command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;for example:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;(real human) -&gt; tty_device_t -&gt; user_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;I wont go into much detail here but i want to touch on the different user domains to consider. Users can have different roles. Roles are mappings to domains. and as explained domain are environments in which processes operate, defined by the policy in which a domain type is a source.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are two different classes of user domain to consider. user domains that need a login environment, and user domains that do not need a login enviroment. i refer to them as primary and secondary user domains.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;An example of a primary login user domain is staff_t. A user can login to a system in the staff_t user domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;An example of a secundary user domain is webadm_t.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A primary user domain can be allowed to domain transition via roles (RBAC) to this secondary user domain. Thus may not be required to login and have a home directory and etcetera. Secondary user domains are often used for environments that have super user privileges. Like for example the webadm_t environment allows a user process to manage the webserver environment.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Have a look at the different defined user domain in the source policy. look at both staff domain and webadm domain and keep in mind that the first is a primary domain and the latter a secondary domain. By mapping the webadm_r and staff_r roles to a selinux user and mapping  this selinux user to a linux login you can make selinux allow users that operate in the staff_t user domain to use Role based access control to domain transition to the secondary webadm_t user domain via sudo or su in conjunction with newrole.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-1511886773288714711?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/1511886773288714711/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/10/my-view-on-domains-domain-types-roles.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1511886773288714711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1511886773288714711'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/10/my-view-on-domains-domain-types-roles.html' title='My view on domains, domain types, roles, domain transitions and more.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-9182037528389825455</id><published>2009-09-17T05:46:00.000-07:00</published><updated>2009-09-17T05:47:46.587-07:00</updated><title type='text'>AVC Denials: Example</title><content type='html'>&lt;span style="font-family: arial;font-size:130%;" &gt;SELinux logs policy violations to /var/log/audit/audit.log if audit is installed and enabled. If audit is&lt;br /&gt;not installed or enabled, than SELinux sends policy violation notices to dmesg or /var/log/messages.&lt;br /&gt;&lt;br /&gt;The policy violations that SELinux logs are called AVC denials. AVC is an abbreviation for Access Vector&lt;br /&gt;Cache. Which is the SELinux cache with Access Vectors. Access vectors are the rules that govern access.&lt;br /&gt;&lt;br /&gt;Reading AVC denials properly helps troubleshoot issues. In this article i will talk about, and highlight&lt;br /&gt;some of the information you can retrieve from AVC denials. I will also touch on some of the tools that&lt;br /&gt;assist in listing, parsing and translating SELinux Access Vector Cache denials.&lt;br /&gt;&lt;br /&gt;Example of a AVC denial:&lt;br /&gt;&lt;br /&gt;avc:  denied  { getattr } for  pid=7604 comm="firefox" path="/usr/lib64/firefox-3.5.3/firefox" dev=dm-2 ino=1311607&lt;br /&gt;scontext=dgrift_u:dgrift_r:gwibber_t:s0-s0:c0.c1023 tcontext=system_u:object_r:mozilla_exec_t:s0 tclass=file&lt;br /&gt;&lt;br /&gt;The line above provides much information about what has been denied:&lt;br /&gt;&lt;br /&gt;1. What process was denied access.&lt;br /&gt;2. What domain type did the source process operate in when it was denied access.&lt;br /&gt;3. What object or subject was the source process denied access to.&lt;br /&gt;4. What was the object/subject type of the target.&lt;br /&gt;5. What permission was denied.&lt;br /&gt;6. What is the class of the target.&lt;br /&gt;7. What was the process identity of the source.&lt;br /&gt;8. What was the inode number of the target object.&lt;br /&gt;9. What happened.&lt;br /&gt;&lt;br /&gt;Security is about managing interaction. Interaction has a source and a target. Interaction involves atleast&lt;br /&gt;a subject as a source (an interacting party) and a subject or object as a target. The target of the&lt;br /&gt;interaction. Subjects are interacting entities, and object non-interacting entities. Subjects can interact&lt;br /&gt;with object, but subjects can also interact with other subjects.&lt;br /&gt;&lt;br /&gt;The target class in a AVC denial tells us what the class (origin) of the target in an interaction is.&lt;br /&gt;A source of a interaction is always a subject (interacting entity). Object can not interact and thus can&lt;br /&gt;never be a source of an interaction.&lt;br /&gt;&lt;br /&gt;Lets try and connect the dots and see if we can make sense of the example AVC denial above. We will try to&lt;br /&gt;answer each of our 9 questions in the check list:&lt;br /&gt;&lt;br /&gt;1. What process was denied access.&lt;br /&gt;&lt;br /&gt;comm="firefox" shows use the name of the command that was run. The firefox program was denied access.&lt;br /&gt;&lt;br /&gt;2. What domain type did the source&lt;br /&gt;process operate in when it was denied access.&lt;br /&gt;&lt;br /&gt;scontext=dgrift_u:dgrift_r:gwibber_t:s0-s0:c0.c1023 shows that the source firefox was operating with the&lt;br /&gt;gwibber_t domain type. The type is the third field in the security context tuple.&lt;br /&gt;&lt;br /&gt;3. What object or subject was the source process denied access to.&lt;br /&gt;&lt;br /&gt;path="/usr/lib64/firefox-3.5.3/firefox" Shows what the target of the source in this interaction was.&lt;br /&gt;&lt;br /&gt;4. What was the object/subject type of the target.&lt;br /&gt;&lt;br /&gt;tcontext=system_u:object_r:mozilla_exec_t:s0 shows the type of the target.&lt;br /&gt;&lt;br /&gt;5. What permission was denied.&lt;br /&gt;&lt;br /&gt;{ getattr } Shows the syscall (permission) that was denied.&lt;br /&gt;&lt;br /&gt;6. What is the class of the target.&lt;br /&gt;&lt;br /&gt;tclass=file shows that the class of the target in our interaction was file.&lt;br /&gt;&lt;br /&gt;7. What was the process identity of the source.&lt;br /&gt;&lt;br /&gt;pid=7604 shows that the process id of the source of our interaction was 7604&lt;br /&gt;&lt;br /&gt;8. What was the inode number of the target object.&lt;br /&gt;&lt;br /&gt;ino=131160 shows that the inode number of the target object in our interaction was 131160.&lt;br /&gt;&lt;br /&gt;9. What happened.&lt;br /&gt;&lt;br /&gt;denied shows that the particular Access Vector was denied.&lt;br /&gt;&lt;br /&gt;We have all the detail that we need to established *what* happend.&lt;br /&gt;&lt;br /&gt;1. The command /usr/bin/firefox was executed but some interacting entity.&lt;br /&gt;2. This command was executed with the gwibber_t domain type.&lt;br /&gt;3. The target of the source /usr/bin/firefox was /usr/lib64/firefox-3.5.3/firefox&lt;br /&gt;4. The type of the target was mozilla_exec_t&lt;br /&gt;5. The source /usr/bin/firefox that operated with the gwibber_t domain type was denied the "getattr"&lt;br /&gt;syscall on the target /usr/lib64/firefox-3.5.3/firefox that had type mozilla_exec_t.&lt;br /&gt;6. The class of the target /usr/lib64/firefox-3.5.3/firefox is a file (the target is a file object)&lt;br /&gt;7. The process of /usr/bin/firefox had the process id of 7604 when this Access vector occured.&lt;br /&gt;8. The inode number of the target file object is 131160&lt;br /&gt;9. Access was denied.&lt;br /&gt;&lt;br /&gt;These are the SELinux facts:&lt;br /&gt;&lt;br /&gt;the /usr/bin/firefox command was denied to get the attributes of the /usr/lib64/firefox-3.5.3/firefox file&lt;br /&gt;source domain type gwibber_t was denied get attribute of a file object with type mozilla_exec_t&lt;br /&gt;&lt;br /&gt;What this means is that there was no rule to allow this access, thus access was denied.&lt;br /&gt;&lt;br /&gt;From here on out things get less obvious:&lt;br /&gt;&lt;br /&gt;We know some facts but this has raised other questions:&lt;br /&gt;&lt;br /&gt;1. Are the types of the source and target correct?&lt;br /&gt;2. We know what was denied but we dont know why.&lt;br /&gt;3. Should we allow this access?&lt;br /&gt;4. Does it signal intrusion?&lt;br /&gt;5. If we allow it access what would be the best way to do it.&lt;br /&gt;6. What are the problems if we do it the other way?&lt;br /&gt;&lt;br /&gt;The reason that these questions are harder to answer is because it depends on the policy that is created by&lt;br /&gt;the policy author. But if you see an AVC denial we can usually narrow the cause down to:&lt;br /&gt;&lt;br /&gt;a. The source and/or the target is mislabelled (wrong type)&lt;br /&gt;b. It is a bug in policy.&lt;br /&gt;c. Intrusion was detected and prevented.&lt;br /&gt;&lt;br /&gt;So let's try to answer all these questions:&lt;br /&gt;&lt;br /&gt;1. Are the types of the source and target correct?&lt;br /&gt;&lt;br /&gt;This is the first thing we must verify. If the types are incorrect than we must correct them first to be able to learn the real reason&lt;br /&gt;about what happend. Objects sometimes get mislabelled. For example if created the object whilst you had SELinux disabled and forgot to&lt;br /&gt;restore the context. Another reason might be that you have moved the file from another location as opposed to copying it, and forgot&lt;br /&gt;the restore the context.&lt;br /&gt;&lt;br /&gt;How do we determine whether the types are correct? Well the answer is that we have to dig into some of the properties of the policy.&lt;br /&gt;We have to put ourselves into the shoes of the policy author.&lt;br /&gt;&lt;br /&gt;To verify whether the type of the source (gwibber_t) is correct we have to ask ourselves which policy module owns this type?&lt;br /&gt;This is a hard question to answer. Really the only way to figure this out is to grep for the gwibber_t type in the source of the&lt;br /&gt;policy. In this case there is a policy module installed called gwibber.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;grep -r "type gwibber_t" Modules/&lt;br /&gt;&lt;br /&gt;We are looking for the declaration of the gwibber_t type. Types are usually declared in files with .te suffixes (type enforcement&lt;br /&gt;source policy files)&lt;br /&gt;&lt;br /&gt;So we could narrow our grep a bit:&lt;br /&gt;&lt;br /&gt;grep -r "type gwibber_t" Modules/ | grep "\.te"&lt;br /&gt;&lt;br /&gt;Modules/gwibber.te:type gwibber_t;&lt;br /&gt;Modules/gwibber.te:type gwibber_tmpfs_t;&lt;br /&gt;&lt;br /&gt;The type is declared in the gwibber.te source policy type enforcement file. We can now grep this file for the policy_module&lt;br /&gt;declaration to figure out what the name of the module is:&lt;br /&gt;&lt;br /&gt;grep policy_module Modules/gwibber.te&lt;br /&gt;policy_module(gwibber, 0.0.1)&lt;br /&gt;&lt;br /&gt;The policy module name is gwibber and the version number is 0.0.1, Now we can determine whether this module is installed:&lt;br /&gt;&lt;br /&gt;sudo /usr/sbin/semodule -l | grep gwibber&lt;br /&gt;gwibber 0.0.1&lt;br /&gt;&lt;br /&gt;The module is installed, we know that the type gwibber_t is owned by the gwibber module.&lt;br /&gt;&lt;br /&gt;Now we should figure out what the type of the firefox command is. the firefox command is located in /usr/bin/firefox.&lt;br /&gt;We can use ls -alZ /usr/sbin/firefox to determine the type of this command:&lt;br /&gt;&lt;br /&gt;-rwxr-xr-x. root root system_u:object_r:bin_t:s0       /usr/bin/firefox&lt;br /&gt;&lt;br /&gt;The type of the firefox command is bin_t. This type has a special property that is specific to the policy model. You could look up the&lt;br /&gt;properties of this type the same way that we are currently looking up the properties of type gwibber_t.&lt;br /&gt;&lt;br /&gt;But to not overly complicate things i will explain the main property of the bin_t type.&lt;br /&gt;&lt;br /&gt;The bin_t type is a generic type for executable files in bin and sbin directories. These commands get run with the domain type of the&lt;br /&gt;subject that executed the command. So if a process that was operating with the gwibber_t domain type executed a command with the bin_t&lt;br /&gt;type, than that command would run with the gwibber_t domain type.&lt;br /&gt;&lt;br /&gt;With this in we have to figure out whether processes with the gwibber_t domain type are allowed to execute files with the bin_t type:&lt;br /&gt;&lt;br /&gt;sudo sesearch --allow -s gwibber_t -t bin_t -c file -p execute&lt;br /&gt;Found 1 semantic av rules:&lt;br /&gt;   allow gwibber_t bin_t : file { ioctl read getattr lock execute execute_no_trans open } ;&lt;br /&gt;&lt;br /&gt;The sesearch command queries the policy store and looks if there is a rule which allows the source gwibber_t domain type to execute&lt;br /&gt;target objects of the files class with type bin_t.&lt;br /&gt;&lt;br /&gt;A line is returned confirming that this is allowed. This tells us that the source in our interaction is likely correclty labelled.&lt;br /&gt;This is what happened. Some process that run with the gwibber_t domain type ran /usr/bin/firefox which has the bin_t type causing the&lt;br /&gt;firefox command to run with the gwibber_t domain type.&lt;br /&gt;&lt;br /&gt;Now we need to determine whether the type of our target is correct. In our interaction that fortunatly is pretty easy.&lt;br /&gt;We know the path of our target: /usr/lib64/firefox-3.5.3/firefox&lt;br /&gt;We can run the matchpathcon command to see what type is defined for this location and if that defined type corresponds to the target&lt;br /&gt;type in our avc denial: mozilla_exec_t.&lt;br /&gt;&lt;br /&gt;sudo /sbin/matchpathcon /usr/lib64/firefox-3.5.3/firefox&lt;br /&gt;/usr/lib64/firefox-3.5.3/firefox        system_u:object_r:mozilla_exec_t:s0&lt;br /&gt;&lt;br /&gt;This confirms that the labelling in the interaction is correct for both source and target.&lt;br /&gt;&lt;br /&gt;Sometimes however, the full path of the target is not shown in a avc denial. In that case you can use the inode number to find the&lt;br /&gt;full path:&lt;br /&gt;&lt;br /&gt;find / -inum 131160&lt;br /&gt;/usr/lib64/firefox-3.5.3/firefox&lt;br /&gt;&lt;br /&gt;2. We know what was denied but we dont know why.&lt;br /&gt;&lt;br /&gt;This is another hard question to solve. We are no psychics. We cannot read the mind of the policy author.&lt;br /&gt;We can try:&lt;br /&gt;&lt;br /&gt;Should gwibber be able to run firefox? It should be able to run the default browser yes but in this case (the case where i am the&lt;br /&gt;policy author of the gwibber policy module) it was decided to not allow this funcionality. It is obvious that the gwibber_t domain&lt;br /&gt;type was not allowed the access/see (get attributes) the mozilla executable file with type mozilla_exec_t. So either that was done on&lt;br /&gt;purpose or it is a bug in the policy.&lt;br /&gt;&lt;br /&gt;3. Should we allow this access?&lt;br /&gt;3. Should we allow this access?&lt;br /&gt;4. Does it signal intrusion?&lt;br /&gt;5. If we allow it access what would be the best way to do it.&lt;br /&gt;6. What are the problems if we do it the other way?&lt;br /&gt;&lt;br /&gt;Another tough question. if we allow gwibber_t to get attributes of files with type mozilla_exec_t it will probably want more after&lt;br /&gt;that. Chances are that gwibber wants to execute the file (run firefox), since gwibber is designed to open pages in the default&lt;br /&gt;browser.&lt;br /&gt;&lt;br /&gt;If we want gwibber to be able to open the browser, do we want to allow gwibber_t to run the browser with the gwibber_t type or should&lt;br /&gt;we lets gwibber_t domain transition to the mozilla_t domain type? Well my personal opinion is to domain transition where ever possible&lt;br /&gt;but it depends on the situation. In this case a domain transition from gwibber_t to mozilla_t via mozilla_exec_t would likely be the&lt;br /&gt;best decision. However this requires that policy is written manually to make it do what we want it to do.&lt;br /&gt;&lt;br /&gt;But what if we just want to allow this single access vector? We could use the audit2allow tool to translate the avc denial into policy&lt;br /&gt;language and to create a module. Than we could load the created policy module into the policy store with the semodule command.&lt;br /&gt;&lt;br /&gt;echo "avc:  denied  { getattr } for  pid=7604 comm="firefox" path="/usr/lib64/firefox-3.5.3/firefox" dev=dm-2 ino=1311607&lt;br /&gt;scontext=dgrift_u:dgrift_r:gwibber_t:s0-s0:c0.c1023 tcontext=system_u:object_r:mozilla_exec_t:s0 tclass=file" | audit2allow -M&lt;br /&gt;mygwibber; sudo semodule -i mygwibber.pp&lt;br /&gt;&lt;br /&gt;Or we could do it ourselves:&lt;br /&gt;echo "policy_module(mygwibber, 0.0.1)" &gt; mygwibber.te;&lt;br /&gt;echo "require { type gwibber_t, mozilla_exec_t; }" &gt;&gt; mygwibber.te;&lt;br /&gt;echo "allow gwibber.te mozilla_exec_t:file getattr;" &gt;&gt; mygwibber.te;&lt;br /&gt;make -f /usr/share/selinux/devel/Makefile mygwibber.pp&lt;br /&gt;sudo semodule -i mygwibber.pp&lt;br /&gt;&lt;br /&gt;So:&lt;br /&gt;&lt;br /&gt;a. The source and/or the target is mislabelled (wrong type)&lt;br /&gt;&lt;br /&gt;The types were correct.&lt;br /&gt;&lt;br /&gt;b. It is a bug in policy.&lt;br /&gt;&lt;br /&gt;It is a bug in policy because we determined that it is usually behaviour for gwibber to try to run the default browser to display&lt;br /&gt;pages. Either we should allow it gwibber to run the browser (be it with the gwibber_t domain type or by domain transition with the&lt;br /&gt;mozilla_t domain type) or we should make sure that no AVC denials are displayed when gwibber_t tries to access the mozilla executable&lt;br /&gt;file with type mozilla_exec_t.&lt;br /&gt;&lt;br /&gt;The rule that i am going to implement is this:&lt;br /&gt;&lt;br /&gt;dontaudit gwibber_t mozilla_exec_t:file getattr;&lt;br /&gt;&lt;br /&gt;Which says if domain type gwibber_t tries to get attributes of files with type mozilla_exec_t than "dontaudit" which means do not&lt;br /&gt;print an avc denials (e.g. silently deny this)&lt;br /&gt;&lt;br /&gt;That is just my personal preference. Its not something fixed. It is my security decision, whether good or bad.&lt;br /&gt;&lt;br /&gt;c. Intrusion was detected and prevented.&lt;br /&gt;&lt;br /&gt;No not really an intrusion since gwibber is designed to open pages in the default web browser which is firefox. So it is expected&lt;br /&gt;behaviour. However i dont want to allow it. But i dont want to log the AVC denial when it happens either because its not important.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-9182037528389825455?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/9182037528389825455/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/09/avc-denials-example.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/9182037528389825455'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/9182037528389825455'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/09/avc-denials-example.html' title='AVC Denials: Example'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5249869767884565499</id><published>2009-09-16T14:39:00.000-07:00</published><updated>2009-09-16T14:41:49.445-07:00</updated><title type='text'>A perspective on SELinux</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family: arial;"&gt;Many people think SELinux is complicated. SELinux is actually beautifully simple if you keep in mind that it &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allows you to manage security very granular in computer systems which are very complex.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In this article i will try to explain the basics of SELinux. The things you need to know to find your &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;way around the SELinux environment.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELinux can roughly be categorized in a few separate parts (ordered by importance):&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;1. The SELinux framework.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;* 2. The tools to manage SELinux.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;* 3. The policy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In this article i will talk about The SELinux framework and the Type enforcement security model.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Knowledge of the SELinux framework is fundamental. If you are familiar with this it will enable you to &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;find your way around the rest.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Knowledge of the different SELinux security models is also important in this part i will talk about how &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;the Type enforcement security model fits into the SELinux Framework.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;To learn about SELinux you have to know a bit about security and about computer systems.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;What is security? Security is managing parties in an interaction. So for example if you want to secure a &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;human sitting on a chair. You have to manage the human and the chair. The human interacts. this is &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;called a subject, the chair does not interact and this is called an object. You could create policy that allows &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;the human to sit on the chair but not stand on it. Standing on it may cause it to break.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;How do computer systems work? Computer systems are similar. processes are like humans. We call them &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;agents. A process therefore is a subject just like the human in my chair example. Processes interact. A &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;file in a computer system does not interact. The subject interacts with it. A file is a object. In a &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;computer system there are many classes of objects just like there are many kind of classes of object in &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;real life. My example was a chair but it could have been a bed or a bike etc. In a computer system a &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;object could be a file or a network port. Generally keep in mind that subjects interact and object get &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;interacted with.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So simplified:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Real life: human, chair, sit&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Computer system: process, file, read&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Humans can be categorized in many classes, the most obvious is man and woman but there are many types of &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;different humans. Processes in a computer system can also be categorized in many classes, for example a &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;process of a user or a process of a program. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Chairs can also be categorized in many classes. Theres rocket chairs and theres oother chairs as well, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;but they are all chairs and objects. Objects in computer systems can also be categorized. There are &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;files and directories etcetera.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you want to manage all these subjects and objects than you will want to categorize them. So that you &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;can create policy for each.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Subjects interact, objects dont. Lets look at some policy for the examples i gave.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;real life:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow man chair:rocket_chair sit;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;computer system:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow user file:dir read;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So in the real life example we allow a subject: human of the type: man to sit on a chair that is of the &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;class rocket_chair.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In the computer system example we allow a subject: process of the type user to read a file that is of &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;the class dir.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Our rule start with allow to signal that we want to allow the rule that follows, than follow our source &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;of the interaction. Which is always a subject since subject interact and object do not. Next is the &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;target. targets can be either subject or objects. subjects can interact with other subjects. for example &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;a man talking with a woman. Next is the class of the target. in our man/woman interaction the class &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;would of the target human would be woman. The last part defines the permission. What interaction is &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allowed? in our man/chair example the man is allowed to site on a rocket_chair in our computer system &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;example the user process is allowed to read a dir. In our recent man talks to woman example we allow a &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;man to talk to a woman.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So back to SELinux. How does SELinux relates to all this. SELinux is for a large part in the kernel. It &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;is a framework. That means that SELinux provides us with some attributes so that we can create policy to &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;define what may and what may not. The attributes that SELinux provides are classes and permissions. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELinux knows the classes of the parties involved in interaction in a computer system. It knows &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;subjects and the different classes of objects. SELinux also knows how subject interact with the &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;different object. In the real life example: SELinux knows theres a human interacting with a chair. It &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;knows the chair is a rocket chair and it know in what ways humans interact with chairs (sit for example)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So the framework provides us with the attributes to create rules. What it cannot do is make further &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;destictions between different subjects and objects. And to be able to manage everything we must make &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;distinctions as much as possible. This is what policy authors do. They make categorize sources and &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;targets in an interaction. for example. SELinux knows a human wants to site in a chair. It even knows it &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;is a rocket chair. But what if we want to make a destinction between a yellow rocket chair and a red &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;rocket chair? We want to be able to allow the human to site in the red rocket chair but not the yellow &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;one. SELinux framework does not know the color, we do. This is where types come in.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Policy authors assign types to subjects and objects.  so in the real life example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow human chair:rocket_chair sit;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow human_man_type red_chair_type:rocket_chair sit;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In the computer system:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow process file:dir read;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow user_process_type home_file_type:dir read;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Types allow us to further categorize the parties in an interaction.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If sufficient for now to know that the SELinux framework provides us with the classes and permission &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;attributes and that it allows us the further categorize the source and target in an interaction, be it &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;subjects or objects.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Type enforcement is a model where policy is enforcement for interaction between the types of the parties &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;involved. The types can be defined by the policy author and the best types depend on the environment. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In a computer environment you might want to make a destinction between a log file and a library file, a &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;program or a user. In a real life environment you might want to make a destinction between man or woman, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;red rocket chair or yellow rocket chair. It depends on what colors rocket chairs exist in you &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;environment. Types enable us to define the properties of our environment.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;By default all interaction is forbidden. if we want to allow something we have define what is allowed. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If there are many types and classes of parties in interaction in an environment you might be able to &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;imagine to amount of rules required to manage all this. For now it is sufficient to know that there are &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;also ways to group or tag different types.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If you want a human to be able to sit on all colored rocket chairs you could for example tag the &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;red_chair_type and the yellow_chair_type to be colored_chair_types and use the tag to make one single &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;rule for both colored chairs.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;allow human_man_type colored_chair_types:rocket_chair sit;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;So that is a very important thing to understand about SELinux and security in general. The enforcement &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;of types is the most important security model of SELinux.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Besides the "allow source target:target_class permission;" rules, there is another thing to understand &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;and that is called a type transition. You can make one type transition to another type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For now it is suffice to know that subject and object types can be triggered to change. Subject types &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;can change via rules that define what should happen if a process executes a file and object &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;types can transition via rule that define what should happen if a file is created under a certain &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;parents type.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Type transitions help you futher categorize parties which will let you define rule for types in certain scenarios.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This is the basics about SELinux. Types are configured by policy authors. The have special meanings and those meanings can vary per &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;policy. So the only thing that really always applies are classes and permissions they stay the same. Types are defined by humans and &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;to learn what a certail type is allowed you would have to reference the policy to determine that.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;And that is want you we are often confronted with, types. rules that govern how one type can interact with another. What we dont know &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;is what a certain type of a subject is supposed to be allowed to do to a certain type of a object.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;These things can be figured out by referencing the policy and asking yourself the question what is the meaning of the type? what are &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;its properties? This is what makes SELinux environments complex because policy is based on a policy authors vision on a system. And &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;that vision may differ per policy model and environment. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELinux itself is not complicated but if you want to manage a complex system you will have to create many different types and thats &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;where SELinux gets complex. If you have a simple system to manage than SELinux will also be simpeler. If you have a simple security &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;goal on a complex system you may also be able to implement a simpler policy that is targeted towards just reaching your simple &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;security goal.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Eventually its all just subjects, objects, classes and permissions when it comes to the SELinux framework and the type enforcement &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;security model. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The more granular the policy to govern how subject can interact with objects gets,the complexer selinux gets. But this is the strenght &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;of SELinux: it allows you to define very granular what is allowed and what not in a system.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Blame the policy author and the policy for the complexity of managing your Security-Enhanced Linux ( i bet the policy author will &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;blame Linux ;) )&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;A quick note about the tools:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;What are the tools for:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;labeling objects&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;parsing access vector denials&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;translating access vector denials to policy&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;finding suggestions to solutions for access vector denials&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;finding what type a object should have&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;changing types of objects&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;restoring types of objects&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;searching rules in the policy database&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;mapping linux logins to subject types&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5249869767884565499?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5249869767884565499/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/09/perspective-on-selinux.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5249869767884565499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5249869767884565499'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/09/perspective-on-selinux.html' title='A perspective on SELinux'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-6304393634263861890</id><published>2009-09-10T03:53:00.000-07:00</published><updated>2009-09-10T04:43:12.400-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Experience'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>Some SELinux experiences that i want to share with you:</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;Disclaimer: I am just thinking out loud here, and i am sure that in some cases i do not fully understand the complexity or the underlying ideas of, and behind the issues that i am about to describe. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;1. (not fedora specific)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;User space processes own files on tmpfs for pulseaudio. These user space processes want to read (and unlink) each others pulseaudio files on tmpfs. To facilitate this, it requires much policy and also by allowing a user space process to read another user space processes pulseaudio tmpfs files , you also give it access to the user space process non pulseaudio tmpfs files. which might not be desired.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;maybe somehow we can implement a attribute for user space processes pulseaudio files on tmpfs. and/or create a generic interface for this interaction. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;3. (fedora specific)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;xserver policy has been modified and xserver_user_x_domain_template and xserver_x_domain_template have been added. These templates could be used instead of xserver_user_client and xserver_common_app.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;By calling these templates other xserver related policy in the domain that call it can for a large part also be removed. The interfaces mentioned above include most of the required xserver policy for user and application processes to function.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;There are some notable exceptions:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;xserver_rw_xdm_home_files&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Also it appears that the interfaces mentioned above were designed with mls policy in mind. To be able to enable xserver object manager in a way that could benefit targeted policy i think a solution could be found so that xserver policy can be easily extended to provide a basic multi purpose useable policy for targeted as well ( maybe create interfaces for the various scenarios ) so that interfaces (or maybe tunable policy) can be called to make xserver object manager work in a basic form and/or specific form in targeted policy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;So that the admin can easily extend xserver policy for his custom needs without having to write local policy himself or having to implement his own custom interfaces, at least as much as possible.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;An example of stuff that currently has no policy implemented but in many cases is required is for example the functionality to change mouse button (for left handed people) and the use of acceleration (3d)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Also we should keep in mind that there is a allow_write_xshm boolean that probably should be used where ever required instead of allowing access to this by adding fixed policy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;My point is that i think xserver object manager could at least to some extend be usable in a targeted policy, and that it could be extendible. Currently in fedora there is no easy way to make openoffice work nice with XACE. I cannot extend its policy due to 'not within scope issues' (user domain prefixes). The java SELinux implementation suffers similar issues.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;3. (not fedora specific)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This also brings me to staff and user domains. These domains do not have access to some devices (cannot rw to dri, cannot rw to wifi, webcam etc) maybe we should implement some booleans for this with a $1. e.g. userdom_$1_use_dri etc. or maybe create users domains that add this functionality. I think this is a requirement to makes confined domains acceptable for day-to-day GUI use. Also the allow_execmem boolean is a bit too coarse. Lets face it we are not close to a working none execmem/execstack environment yet. For example nautilus requires it, totem, etc. many of these apps run in the user domain. Setting allow_execmem would in my view be overkill to just allow a single user domain execmem permission. allow_$1_execmem, where $1 is a specific user domain would in my view be a reasonable temporary solution. In either case i do not think we should just ignore the issue.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The "easy" access to execmem and devices like dri are in my view important to help make confined user domains usable for the general public in a GUI environment.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-6304393634263861890?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/6304393634263861890/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/09/some-selinux-experiences-that-i-want-to.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/6304393634263861890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/6304393634263861890'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/09/some-selinux-experiences-that-i-want-to.html' title='Some SELinux experiences that i want to share with you:'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-736237654885643051</id><published>2009-07-12T09:22:00.001-07:00</published><updated>2009-07-12T09:27:15.662-07:00</updated><title type='text'>Policy development: optional policy</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;If you have looked into source policy you might have noticed optional policy blocks of policy in the type enforcement source policy files. Optional policy is used to make policy modular.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If you call a interface in your policy module that is hosted by another policy module then your module is dependent on that other module. If you decide to de-install the policy module that hosts the interface that you called in your policy module than your policy will no longer be able to build. This is because you're calling shared policy that no longer exists.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;To avoid these dependencies, optional policy block are used.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Let's look at some examples:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/apps/mozilla.te&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;On line 244 to line 246 there is an optional policy block defined with policy that is borrowed from the gnome policy module.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;This can determined since the interface is prefixed by the name (gnome) of the policy module that hosts the interface that is called by mozilla.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The interface facilitates permissions that allows firefox to connect to a unix stream socket that is owned by gnome gconf.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The interface is defined here:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/apps/gnome.if&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;(line 38 to line 55)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Let's use the semodule command to list both mozilla and gnome modules:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;&lt;br /&gt;# semodule -l | grep gnome&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;gnome   2.0.0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;gnomeclock      1.0.0&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;# semodule -l | grep mozilla&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;mozilla 2.0.1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;We should be able to de-install both modules without getting into dependency troubles. If i decide to de-install the gnome module then the gnome_stream_connect_gconf interface becomes unavailable since it is defined in the gnome policy module that i just de-installed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If we would have called gnome_stream_connect_gconf(mozilla_t) without using the optional policy block than we would run into trouble if we tried to de-install the gnome module. The compiler would complain about missing dependencies.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;You should note that not all policy comes as a stand alone module. Some policies are not optional and they go into a single policy module called base.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;As a rule keep in mind that if you can list a module with the semodule command then it can be de-installed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If you borrow shared policy from another (optional) policy module then remember to place it into the optional policy block. For example all policy borrowed from gnome module can be placed into a optional policy block for gnome policy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/apps/mozilla.te&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;(line 225 to line 227)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;These are two interfaces that are hosted by the apache policy module. Both interfaces can go into a single optional policy block since both interfaces are dependent on the same apache module.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-736237654885643051?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/736237654885643051/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/07/policy-development-optional-policy.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/736237654885643051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/736237654885643051'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/07/policy-development-optional-policy.html' title='Policy development: optional policy'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-3291146074247039959</id><published>2009-07-12T03:50:00.000-07:00</published><updated>2009-07-12T10:34:35.808-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='USER_AVC'/><category scheme='http://www.blogger.com/atom/ns#' term='FAQ'/><category scheme='http://www.blogger.com/atom/ns#' term='ACE'/><category scheme='http://www.blogger.com/atom/ns#' term='dontaudit'/><category scheme='http://www.blogger.com/atom/ns#' term='AVC'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>FAQ: SELinux denies access but AVC denials can not be found.</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;It happens. There are a few reasons for this:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;1. Silenced &lt;span style="font-style: italic;"&gt;AVC&lt;/span&gt; denials&lt;span style="font-style: italic;"&gt; (access vector cache).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In policy one can define to silently deny access vectors. This means access is denied and attempts are not logged. Such a rule &lt;span style="font-style: italic;"&gt; (access vector)&lt;/span&gt; would look like this for example (fictional):&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;dontaudit user_t var_t:dir { read open };&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;When a user that operates in the user_t user domain tries to read a var_t directory object type, access is denied. The attempt that was denied would not be logged.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In general the use of "dontaudit" rules should be kept to a minimum. The issue of being denied access and not finding an audit trail for this reason should not happen often at all.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;There are exceptions, like restricted user domains. These processes are restricted/limited for reason and those restrictions/limits might give violation attempts when a user operating in such a domain tries to do something that is not allowed. In this case the &lt;span style="font-style: italic;"&gt;AVC&lt;/span&gt; denials are anticipated and silenced to avoid flooding of the logs with meaning less entries.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;There is a way to expose these silenced &lt;span style="font-style: italic;"&gt;AVC&lt;/span&gt; denials, but be aware that this may fill up your logs quicker than expected.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The &lt;span style="font-style: italic;"&gt;semodule&lt;/span&gt; command used with the &lt;span style="font-style: italic;"&gt;-DB&lt;/span&gt; options unloads "dontaudit" rules on-the-fly. All attempts to violate policy are now logged.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The &lt;span style="font-style: italic;"&gt;semodule&lt;/span&gt; command used with the &lt;span style="font-style: italic;"&gt;-B&lt;/span&gt; option builds the policy with the "dontaudit" rules included. Silenced &lt;span style="font-style: italic;"&gt;AVC&lt;/span&gt; denials are back in policy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;2. User space object managers.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;User space object managers are SELinux extensions on application layers. Applications that implement a SELinux &lt;span style="font-style: italic;"&gt;Access Control Extension&lt;/span&gt; provides classes and permissions to be used for SELinux Policy. The application itself enforces policy that is defined using the &lt;span style="font-style: italic;"&gt;classes&lt;/span&gt;  and permissions it has provided.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;There are only few applications that are also user space object managers. DBus implements this and this feature is enabled by default. If some access is denied and you've unloaded the "dontaudit" rules using the &lt;span style="font-style: italic;"&gt;semodule &lt;/span&gt;command with &lt;span style="font-style: italic;"&gt;-DB&lt;/span&gt; option, but you still cannot find any audit trail, then chances are the DBUS access control extension is responsible.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In some cases, which might be due to a bug, DBUS sends its user_avc denials to &lt;span style="font-style: italic;"&gt;/var/log/messages&lt;/span&gt; instead of the expected &lt;span style="font-style: italic;"&gt;/var/log/audit/audit.log&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;So it is recommended to also see &lt;span style="font-style: italic;"&gt;/var/log/messages&lt;/span&gt; or &lt;span style="font-style: italic;"&gt;dmesg&lt;/span&gt; if you suspect SELinux denied access but you cannot find any audit trail.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;SELinux denials are called &lt;span style="font-style: italic;"&gt;AVC&lt;/span&gt; denials and can also be listed using the &lt;span style="font-style: italic;"&gt;ausearch&lt;/span&gt; command with &lt;span style="font-style: italic;"&gt;-m&lt;/span&gt; option and &lt;span style="font-style: italic;"&gt;avc&lt;/span&gt; parameter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;User space object manager denials are called &lt;span style="font-style: italic;"&gt;USER_AVC&lt;/span&gt; denials and can also be listed using the ausearch command with the -m option and user_avc parameter. Note that this only works for denials logged to &lt;span style="font-style: italic;"&gt;/var/log/audit/audit.log&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If you suspect SELinux denied some access but you can not find the audit trail then consider building the policy without the "dontaudit" rules using semodule -DB. If you still cannot find any audit trail than maybe a user space object manager denied access. Look for &lt;span style="font-style: italic;"&gt;USER_AVC&lt;/span&gt; denials in &lt;span style="font-style: italic;"&gt;audit.log&lt;/span&gt; or look in &lt;span style="font-style: italic;"&gt;/var/log/messages&lt;/span&gt;, or &lt;span style="font-style: italic;"&gt;dmesg&lt;/span&gt;. The log file for the application itself may also have them.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;I think the goal is to have everything log to audit.log for simplicity but at the moment this is not the case.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;Tip:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;You can use the &lt;span style="font-style: italic;"&gt;sesearch&lt;/span&gt; command to list "dontaudit" rules that are currently built-in policy. For example to list "dontaudit" rules where the &lt;span style="font-style: italic;"&gt;httpd_t&lt;/span&gt; is the source domain:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;sesearch --dontaudit -s httpd_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Have a look at "man sesearch" &lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-3291146074247039959?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/3291146074247039959/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/07/faq-selinux-denies-access-but-avc.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3291146074247039959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3291146074247039959'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/07/faq-selinux-denies-access-but-avc.html' title='FAQ: SELinux denies access but AVC denials can not be found.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-882454318220942286</id><published>2009-06-29T06:40:00.000-07:00</published><updated>2009-06-29T07:15:25.839-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MCS'/><category scheme='http://www.blogger.com/atom/ns#' term='MLS'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>Multi Category Security</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;Multi Category Security or MCS is a discretionary implementation of the mandatory Multi Level Security or MLS Model. SELinux Policy MLS is a SELinux Policy model that is used in Department of Defense type environments. In a MLS environment processes are forced to operate on specified Security Levels. The s0 Security Level or SystemLow level is the lower end of the Security Level Range in a MLS environment. The s15 Security Level or SystemHigh level is the upper end of the Security Range in a MLS environment. Between the low and upper end there are fourteen levels to be used.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In MLS there is a rule that says: "no read up and no write down". This means that processes that are forced to operate on for example Security Level s14 can not read processes or files that operate on the s15 Security Level. Processes that are forced to operate on the s5 Security Level can not write to files or interact with processes on the s4 Security Level. The MLS model is used to enforce confidentiality.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;MCS basically tries to use the MLS attributes: Security Levels and Security Compartments, in its own model in a way that may be useful in common environments. SELinux Policy Targeted can be build with the MCS functionality. Red Hat distributions have this MCS functionality enabled by default in its Targeted SELinux Policy model. Gentoo Hardened, as far as i know, does not have MCS functionality builtin by default.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;MCS pretty much works like the DAC Extended attributes. Users are assigned categories and can apply these categories to content that they own to their discretion. You can easily recognise a MCS enabled system by looking at security contexts. A system that has SELinux Policy Targeted implemented without MCS enabled only has three fields in its Security Context tuples: user_u:role_r:type_t. Systems that have MCS implemented have one or more extra fields in their Security Context tuple: user_u:role_r:type_t:s0:c0. In MCS policy there is only one Security Level. This SystemLow level is s0. MCS does have 1024 categories that can be assigned to processes and files. Categories are the last field in the Security Context tuple. In a MCS environment s0:c0.c1023 is SystemHigh or the upper end of the MCS range. This means that if you are assigned the SystemHigh MCS range that you can access all categories. By default everything in a MCS environment has access to SystemLow or s0.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Example:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Create a new SELinux User that is based of off the user_u SELinux User. Call this SELinux User for example "mcsuser_u" and assign the full MCS range to this SELinux User:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semanage user -a -L s0 -r s0-s0:c0.c1023 -R user_u -P user mcsuser_u&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo cp /etc/selinux/targeted/contexts/users/user_u /etc/selinux/targeted/contexts/users/mcsuser_u&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;( to list the differences between SELinux User user_u and mcsuser_u simply:&lt;span style="font-weight: bold;"&gt; sudo semanage user -l | grep user_u&lt;/span&gt; )&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now create three Linux Users and map them to the mcsuser_u SELinux user. Give John access to the s0-s0:c122 MCS range. Give Jane access to the s0-s0:c123 MCS range, and give johnjane access to the s0-s0:c122,c123 MCS range.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo useradd john&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo useradd jane&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo useradd johnjane&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semanage login -a -s mcsuser_u -r s0-s0:c122 john&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semanage login -a -s mcsuser_u -r s0-s0:c123 jane&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semanage login -a -s mcsuser_u -r s0-s0:c122,c123 johnjane&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Login as john, touch file with name test and list its attributes:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# touch test; ls -Z test;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;mcsuser_u:object_r:user_home_t:s0 test&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The file was created on the s0 SystemLow level which is accessible by everything. Now add the c122 category to the file with the chcat command, and list the SELinux attributes of file test:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# chcat -- +s0:c122 test&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# ls -Z test&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;mcsuser_u:object_r:user_home_t:s0:c122&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If you try to add for example category s0:c123 to the file you will be denied access to do so because your assigned MCS range does not include the s0:c123 category.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Try the same procedure for Jane but instead use the s0:c123 category.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Linux User johnjane has access to both s0:c122 and s0:c123 MCS categories. In a shared location where DAC permissions are sufficient johnjane would be able to access both files with s0:c122 as well as s0:c123 categories.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Johnjane can also assign both s0:c122 and s0:c123 to a single file, but then neither John nor Jane woould be able to access it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If all these MCS category digits make you dizzy then you can install mcstrans. Mcstrans is a daemon that translates the MCS category numbers into strings of letters which are easier to work with. The mcstrans daemon has some problems though.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# sudo yum install mcstrans&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# chkconfig mcstrans on&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# service mcstrans start&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now one can add translations for the MCS category digits with the semanage command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Translate s0:c122 to JohnsFriends, s0:c123 to JanesFriends, and s0:c122,c123 to JohnJanesFriends:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# sudo semanage translation -a -T JohnsFriends s0:c122&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# sudo semanage translation -a -T JanesFriends s0:c123&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# sudo semanage translation -a -T JohnsJanesFriend s0:c122,c123&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;( use &lt;span style="font-weight: bold;"&gt;sudo semanage translation -l&lt;/span&gt; to list current translation mappings )&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Note: After this the mcstrans may have died. If required restart the mcstrans daemon.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# sudo service mcstrans restart&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Users can use the chcat command to list which categories they have assigned:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# chcat -L john&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;john: JohnsFriends&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;User can also use the id command with the -Z option to view their security context. The context displays to categories.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;# id -Z&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;mcsuser_u:user_r:user_t:SystemLow-JohnsFriends&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;MCS is a neat extra functionality that can be enabled on systems that have SELinux Targeted Policy implemented.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The functionality of MCS is similar to that of Extended Attributes.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;man: chcat, man semanage, man id&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-882454318220942286?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/882454318220942286/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/multi-category-security.html#comment-form' title='1 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/882454318220942286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/882454318220942286'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/multi-category-security.html' title='Multi Category Security'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-7728704829005249141</id><published>2009-06-28T06:11:00.000-07:00</published><updated>2009-06-28T07:08:31.787-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><category scheme='http://www.blogger.com/atom/ns#' term='mystaff'/><title type='text'>Mystaff SELinux User Domain</title><content type='html'>&lt;span style=";font-family:arial;font-size:130%;"  &gt;The staff module provided by Refpolicy is pretty cool but i needed a user domain with less privileges that would be able to transition to privileged admin domains.&lt;br /&gt;&lt;br /&gt;One of my requirements was that this User Domain should only be accessible via OpenSSH and that it should be identical to the guest_t User Domain or have even less privileges. The guest_t User Domain was designed to not User Domain transition ever.&lt;br /&gt;&lt;br /&gt;Another requirement for my mystaff User Domain was that this user should not be able to change passwords. I did this because the provided staff_t User Domain by Tresys can change passwords. If i sudo to root in the staff_t User Domain than in theory i would be able to change the root password. This is something i wanted to prevent for mystaff user.&lt;br /&gt;&lt;br /&gt;Generally i wanted mystaff to have as little privileges as possible. It would be a very restricted login environment only accessible with OpenSSH that would be able to transition to specified admin User domains like for example webadm_t.&lt;br /&gt;&lt;br /&gt;I started by reverse engineering the staff_t User Domain:&lt;br /&gt;&lt;br /&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/roles/staff.te&lt;br /&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/roles/staff.if&lt;br /&gt;&lt;br /&gt;The staff.te file is mostly one call to a interface that is defined in the userdom modules interface file:&lt;br /&gt;&lt;br /&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/system/userdomain.if ( line 927 to line 1020)&lt;br /&gt;&lt;br /&gt;So far so good, but this interface has calls to to included several other interfaces that are defined in the same interface files:&lt;br /&gt;&lt;br /&gt;userdom_restricted_user_template($1)&lt;br /&gt;userdom_common_user_template($1)&lt;br /&gt;&lt;br /&gt;These interfaces have calls to yet other interfaces defined in userdom.if file and so forth and so forth.&lt;br /&gt;&lt;br /&gt;userdom_login_user_template($1)&lt;br /&gt;userdom_basic_networking_template($1)&lt;br /&gt;&lt;br /&gt;Which call:&lt;br /&gt;&lt;br /&gt;userdom_base_user_template($1)&lt;br /&gt;userdom_manage_home_role($1_r, $1_t)&lt;br /&gt;userdom_manage_tmp_role($1_r, $1_t)&lt;br /&gt;userdom_manage_tmpfs_role($1_r, $1_t)&lt;br /&gt;userdom_exec_user_tmp_files($1_t)&lt;br /&gt;userdom_exec_user_home_content_files($1_t)&lt;br /&gt;userdom_change_password_template($1)&lt;br /&gt;&lt;br /&gt;My goal was to expand all these userdomain interfaces so that i could remove parts of policy in there that i did not need.&lt;br /&gt;&lt;br /&gt;Since i did not want mystaff to be able to change passwords i could for example remove the userdom_change_password_template altogether.&lt;br /&gt;&lt;br /&gt;I also wanted mystaff to easily be customizable for different admin domain transitions and i started making different admin domains based of off webadm User domain. Basically i edited the name and declarations and replace the apache_admin interface calls by admin interface calls for other services. I also remove some policy specific to webadm.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/services/aide.if (line 46 to line 71)&lt;br /&gt;&lt;br /&gt;The interface to call for administration of the aide domain.&lt;br /&gt;&lt;br /&gt;Long story short. Below you will find the links to the mystaff user domain that is based of off the staff domain provided by upstream. In mystaff module i have expanded all userdom interface calls and i have removed policy that i did not require.&lt;br /&gt;&lt;br /&gt;Basically the mystaff_u SELinux user is even more restricted then guest_u but unlike guest_u, mystaff_u can use sudo to user domain transition to admin domains. By default i have it call the webadm_role_change interface which allows mystaff_r access to the already by default installed webadm_r role. I also used the gen_user() macro to generate a mystaff_u SELinux User. However this SELinux user does not yet have the webadm_r role mapped. One could simply use semanage user -m &lt;...&gt; mystaff_u to add the webadm_r or edit the gen_user() macro to recflect mystaff_u SELinux Users access to the webadm_r role.&lt;br /&gt;&lt;br /&gt;You will also notice plenty commented role_change template calls for other services. One can simple uncomment any of these calls to allow mystaff_r access to the role these provides. This requires that you install the corresponding admin User domains which can be found in the same modules directory.&lt;br /&gt;It is then also required to map any of these roles to the mystaff_u SELinux User.&lt;br /&gt;&lt;br /&gt;http:///82.197.205.60/~dgrift/stuff/modules/mystaff.te&lt;br /&gt;http:///82.197.205.60/~dgrift/stuff/modules/mystaff.if&lt;br /&gt;http:///82.197.205.60/~dgrift/stuff/modules/mystaff.fc&lt;br /&gt;&lt;br /&gt;Other source policy modules:&lt;br /&gt;http:///82.197.205.60/~dgrift/stuff/modules/&lt;br /&gt;&lt;br /&gt;By the way: the mystaff module can be easily modified to reflect a myguest modified guest User Domain. Just comment:&lt;br /&gt;&lt;/span&gt;&lt;pre  style="font-family:arial;"&gt;&lt;span style="font-size:130%;"&gt;optional_policy(`&lt;br /&gt;sudo_role_template(mystaff, mystaff_r, mystaff_t)&lt;br /&gt;')&lt;br /&gt;&lt;br /&gt;# Available privileged roles&lt;br /&gt;# Test&lt;br /&gt;optional_policy(`&lt;br /&gt;webadm_role_change(mystaff_r)&lt;br /&gt;')&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;span style=";font-family:arial;font-size:130%;"  &gt;In that case one may also want to rename the mystaff to something more appropriate. One can simply modify this policy to add or remove privileges.&lt;br /&gt;&lt;br /&gt;Oh, by the way, do not forget to add default contexts for mystaff_u. You can base you mystaff_u default context file of off the staff_u file in /etc/selinux/targeted/contexts/users/. All you have to do is replace staff by mystaff in this file. (see my previous article on creating custom user domains)&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-7728704829005249141?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/7728704829005249141/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/mystaff-selinux-user-domain.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/7728704829005249141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/7728704829005249141'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/mystaff-selinux-user-domain.html' title='Mystaff SELinux User Domain'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-7674116864881536255</id><published>2009-06-28T04:44:00.000-07:00</published><updated>2009-06-28T05:02:34.361-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TE'/><category scheme='http://www.blogger.com/atom/ns#' term='File context'/><category scheme='http://www.blogger.com/atom/ns#' term='Interface'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>Policy module source</title><content type='html'>&lt;span style="font-family: arial;font-size:130%;" &gt;In this article i will try to explain a bit more about the policy module source files.&lt;br /&gt;&lt;br /&gt;A policy module source has three files. The first file is a Type Enforcement file. These files have the .te extension. The second file is a interface file. These files have a .if extension. The third file is called a file context file. This file has a .fc extension.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;Type enforcement source policy file.&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;This file has policy and declarations that a personal or local to the policy module. Policy that is used by the (personal) types that are declared in this module.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;Interface source policy file.&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;This file has policy and declarations that are shared with other types.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;File context source policy file.&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;This file has personal file contexts for the personal types that are (usually) declared in the Type Enforcement file.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;Some background information:&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;Example of a AVC denial:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;avc:  denied  { read write } for  pid=1864 comm="tor" path="/dev/console" dev=tmpfs ino=496 scontext=system_u:system_r:tor_t:s0 tcontext=system_u:object_r:console_device_t:s0 tclass=chr_file&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;Example of the AVC denial when processed by audit2allow:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;allow tor_t console_device_t:chr_file { read write };&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;Example of the AVC denial processed by audit2allow -R:&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;term_use_console(tor_t)&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;The AVC denial has a lot of information about details of a denied rule in the Access Vector Cache. The basic audit2allow command translates this AVC denial into human readable policy language. The &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;audit2allow -R&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; command goes looking for any available shared policy that may be available for us to use.&lt;br /&gt;&lt;br /&gt;In this example the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; domain wants to read and write to &lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;/dev/console&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; which is a character device file that has type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;. Tor interacts with terminal.&lt;br /&gt;&lt;br /&gt;To make policy manageable and to keep the footprint of policy as small as possible the concept of shared policy is used. There is no need for duplicate policy. There should be a single point where a certain access is defined. This point is defined in the interface file of the target.&lt;br /&gt;&lt;br /&gt;In this example &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;term_use_console&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; is shared policy that is hosted by the module that declared(owns) type&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt; console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;. Interfaces (shared policy) are usually prefixed by the name of the module that own the type of the target.&lt;br /&gt;&lt;br /&gt;The &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; domain tries to read and write to &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; which is a type that is declared in the terminal.te source policy file. The &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;terminal.if&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; interface file hosts policy to interact with this type properly: &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;term_use_console&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;. term is the abbreviation for terminal which is the name of the module that hosts the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; file.&lt;br /&gt;&lt;br /&gt;The type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; is declared here -- it is a declaration the is personal to the terminal policy module (&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;terminal.te&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;):&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/kernel/terminal.te&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; (line 21)&lt;br /&gt;&lt;br /&gt;The interface &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;term_use_console&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; is defined here -- it is policy that is shared (hosted) by the terminal policy module (&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;terminal.if&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;):&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/kernel/terminal.if&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; (line 219 to line 237)&lt;br /&gt;&lt;br /&gt;The terminal module own the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t &lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;type and shares all policy other types need to be able to interact with this type. If something changes in the way that interaction is done with this type then the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;terminal.if&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; is a central point to modify policy for this. Other types simple call this shared policy and changes automatically get synchronized.&lt;br /&gt;&lt;br /&gt;Shared policy usually have a commented header which explains the purpose of the interface and the parameters it expects when it is called.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;For term_use_console the description is:&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;Read from and write to the console&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;And the parameter it expects is:&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;Domain allowed access.&lt;br /&gt;&lt;br /&gt;If the tor_t domain wants to read and write to the terminal a device file with type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t &lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;then it can simple call the shared policy that is hosted in the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;terminal.if &lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;file, which is the file that shares policy and declaration with regard to types and domains that are personal to the terminal policy module.&lt;br /&gt;&lt;br /&gt;Look at interfaces like BASH functions. You can source a external file that has BASH functions and then call any functions that are provided by the sources functions file.&lt;br /&gt;&lt;br /&gt;The purpose of the commented headers is that it is easy to reference and call the interfaces. The source policy can be converted to html if you run "&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;make html&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;" in the source root.&lt;br /&gt;&lt;br /&gt;An example of this is hosted here:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;http://oss.tresys.com/docs/refpolicy/api/&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;The specific term_use_console interface is specified here:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;http://oss.tresys.com/docs/refpolicy/api/kernel_terminal.html&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;Below the commented header for the term_use_console interface the actual shared policy can be found. This policy often has calls to shared policy for types that are external to the module. In this case the term_use_console as a interface call to &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;dev_list_all_dev_nodes($1)&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; Which is shared policy that is hosted by the devices module (interfaces defined in device.if).&lt;br /&gt;&lt;br /&gt;The &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;$1&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; is a variable of the parameter is expects. Look up the interface name here: &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;http://oss.tresys.com/docs/refpolicy/api/kernel_devices.html &lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;and see what parameter is expects: Domain allowed to list device nodes.&lt;br /&gt;&lt;br /&gt;If a domain type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; wants to list device nodes then simple call &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;dev_list_all_dev_nodes(tor_t)&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;$1, $2, $3&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; etc are variables that replace parameter 1, parameter 2, parameter 3 etc.&lt;br /&gt;&lt;br /&gt;Another rule in the term_use_console interface in terminal.if is:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;allow $1 console_device_t:chr_file rw_chr_file_perms;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;If term_use_console(tor_t) is defined than the rule is translated:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;allow tor_t console_device_t:chr_file rw_chr_file_perms;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;Which basically allows the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; domain type read and write access to character files with type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;The last thing to mention about the term_use_console interface and interfaces in general is the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;gen_require()&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; blocks that can be seen.&lt;br /&gt;&lt;br /&gt;Since type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; is declared in &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;terminal.te&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; and since &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;term_use_console&lt;/span&gt;&lt;span style="font-family: arial;"&gt; is called by &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; domain in the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor.te&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; source policy file, the&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt; tor_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; files has to borrow the&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt; console_device_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; type which is external to the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;tor.te&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; file.&lt;br /&gt;&lt;br /&gt;The &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;gen_require() and require{}&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; block basically source types that are declared in other modules. After the types are sourced they can be used in personal policy.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;another example:&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;If you encounter a AVC denial than consider that the target type (tcontext type) usually hosts policy to facilitate the access that the source type (scontext type) in the AVC denial needs. Run the AVC denial through audit2allow to hav it translated to raw policy language. Run the AVC denial through audit2allow -R to have it look for any shared policy that facilitates the access that is required.&lt;br /&gt;&lt;br /&gt;Of course you can also do this yourself:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;avc:  denied  { read } for  pid=1842 comm="smartd" name="config" dev=dm-1 ino=39859 scontext=system_u:system_r:fsdaemon_t:s0 tcontext=system_u:object_r:selinux_config_t:s0 tclass=file&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;The smartd executable that runs in the &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;fsdaemon_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; domain wants to read a file with name config and with type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;selinux_config_t.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;allow fsdaemon_t selinux_config_t:file read;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;The module that has declared &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;selinux_config_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; should also provide shared policy that facilitates the access &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;fsdaemon_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; domain needs.&lt;br /&gt;&lt;br /&gt;I would expect that type &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;selinux_config_t&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; would be declared in selinux.te since types and interfaces are often prefixed by the name of the module that owns it. In this case it is not so straight forward. A little peruse of the policy shows that this type is declared in the selinuxutil.te file.&lt;br /&gt;&lt;br /&gt;So shared policy related to this type should be in the selinuxutil.if file. On line 595 in the selinuxutil.if interface file here:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/system/selinuxutil.if&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;This interface called &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;seutil_read_config&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt; can be called by &lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;fsdaemon_t &lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;if we wish to give that domain this permissions.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;seutil_read_config(fsdaemon_t)&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;However policy decisions are usually not that simple to make. A better idea may be to use this interface on line 575:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;font-size:130%;" &gt;&lt;br /&gt;seutil_dontaudit_read_config(fsdaemon_t)&lt;/span&gt;&lt;span style="font-family: arial;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;File context files define file contexts of types that are declared in the policy module. Have a look at some of the many examples Type Enforcement, Interface and File contexts files available in Tresys Reference policy.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-7674116864881536255?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/7674116864881536255/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/policy-module-source.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/7674116864881536255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/7674116864881536255'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/policy-module-source.html' title='Policy module source'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-3497712552769060159</id><published>2009-06-27T08:36:00.000-07:00</published><updated>2009-06-27T09:20:12.261-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Youtube'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux screencasts</title><content type='html'>Here are some screen cast where i demonstrate some of the things that were discussed in the SELinux Lockdown series.&lt;br /&gt;&lt;br /&gt;1. Create custom SELinux users.&lt;br /&gt;&lt;br /&gt;Here i create a new SELinux User called new_u and map the staff_r, system_r and unconfined roles to this user. This SELinux User also has also has access to all available MCS categories.&lt;br /&gt;&lt;br /&gt;Linux user joe is mapped to the new_u SELinux user. Default contexts for new_u SELinux were copied from those of staff_u since new_u is based of off staff_u with minor modifications (access to unconfined_r instead of sysadm_r)&lt;br /&gt;&lt;br /&gt;Sudo is also set up to allow joe root access and to automatically Domain Transition to unconfined_t User Domain.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=NmkQqNq0DJE&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/NmkQqNq0DJE&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/NmkQqNq0DJE&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;2. Quick demonstration of PAM SEPermit.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=-0qge9vtPjg&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/-0qge9vtPjg&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/-0qge9vtPjg&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;3. Quick demonstration of unconfined_login boolean.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=Ky3jm5n4f8M&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/Ky3jm5n4f8M&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/Ky3jm5n4f8M&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;4. How to extend staff_t User Domain to allow listing of /var (part1)&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=0gaxh0lZ4MU&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/0gaxh0lZ4MU&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/0gaxh0lZ4MU&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;4.1 How to extend staff_t User Domain to allow listing of /var (part2)&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=Rnrca8khz1w&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/Rnrca8khz1w&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/Rnrca8khz1w&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;5. Create a new unprivileged (secondary) User Domain.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=bDFTiZOteiA&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/bDFTiZOteiA&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/bDFTiZOteiA&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;6. The newrole command is useful for unprivileged User Domain transitions.&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=9N0WsncDrfY&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/9N0WsncDrfY&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/9N0WsncDrfY&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;7. Demonstration of how to create a Application Domain to achieve listing of /var for staff_t (part1)&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=c06sjcC9CNs&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/c06sjcC9CNs&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/c06sjcC9CNs&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;7.1 Demonstration of how to create a Application Domain to achieve listing of /var for staff_t (part2)&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=U2GDBor1BsQ&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/U2GDBor1BsQ&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/U2GDBor1BsQ&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;7.2 Demonstration of how to create a Application Domain to achieve listing of /var for staff_t (part3)&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=riXisTFPEzo&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/riXisTFPEzo&amp;hl=en&amp;fs=1"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/riXisTFPEzo&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;Looks like the last episode turned out a bit too long for YouTube. Heres a trimmed down version:&lt;br /&gt;&lt;br /&gt;http://www.youtube.com/watch?v=9UJUxqf3NkY&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/9UJUxqf3NkY&amp;hl=en&amp;fs=1&amp;"&gt;&lt;/param&gt;&lt;param name="allowFullScreen" value="true"&gt;&lt;/param&gt;&lt;param name="allowscriptaccess" value="always"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/9UJUxqf3NkY&amp;hl=en&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;br /&gt;Excuse my bad english and funny dialect :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-3497712552769060159?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/3497712552769060159/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-screencasts.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3497712552769060159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3497712552769060159'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-screencasts.html' title='SELinux screencasts'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-1877283547196315196</id><published>2009-06-27T03:25:00.000-07:00</published><updated>2009-06-27T04:06:39.901-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Conclusion'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Ten: Conclusion</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;A lot was discussed in the previous nine articles. This is the last article in this series. In this article i will in short repeat the steps to maximize the security that SELinux provides. Details about any of these steps can be found in the previous articles.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;1. SELinux User.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Map Linux Users by default to a confined SELinux User. Think least privilege. Use for example &lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;guest_u&lt;/span&gt;&lt;span style="font-family:arial;"&gt;: &lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semanage login -m -s guest_u -r s0-s0 __default__&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;If you wish to override the default SELinux User for a new Linux User then you can do so with the &lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;useradd&lt;/span&gt;&lt;span style="font-family:arial;"&gt; and &lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;-Z&lt;/span&gt;&lt;span style="font-family:arial;"&gt; option.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Do not map Linux users to the&lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;" &gt; unconfined_u&lt;/span&gt;&lt;span style="font-family:arial;"&gt; SELinux user. An exception to this rule can be the root user. Root users should not be allowed to login except via TTY in emergencies.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;2. PAM SEPermit.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Add entries for all your confined SELinux Users to&lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt; /etc/security/sepermit.conf&lt;/span&gt;&lt;span style="font-family:arial;"&gt; to block logins when SELinux is in permissive mode. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;You can decide to create a unique SELinux User for yourself that is exempted from SEPermit. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;3. Permissive mode Vs. Permissive Domains.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Always prefer the use of Permissive Domains over Permissive Mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;4. Do not modify your default SELinux Users. If you need a custom SELinux User and or SELinux user Domain then create a new one. You can base them of off existing ones.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;5. Use Role based Access control to confine root and user privileges.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;6. Do not modify existing Roles/ User Domains.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt; If you need a custom role then base it of off an existing role and map the new role to a new SELinux user. You can however map existing roles to new SELinux users.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;7. Use sudo. Not SU and newrole.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;8. Remove the unconfined domain(s).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Be sure to &lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semodule -r unconfined&lt;/span&gt;&lt;span style="font-family:arial;"&gt; to disable system services that have no policy defined. use &lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semodule -r unconfineduser&lt;/span&gt;&lt;span style="font-family:arial;"&gt; to completely disable unconfined user environments &lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;(not recommended)&lt;/span&gt;&lt;span style="font-family:arial;"&gt; If you do decide to remove unconfineduser, then make sure to configure your SELinux User mappings to reflect this. Use sysadm instead of unconfined&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;I prefer unconfined User Domain over sysadm User Domain for a secondary all purpose privileged user domain because:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;a. unconfined_login boolean can be set to disable unconfined user logins.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;b. ssh_sysadm_login, and xdm_sysadm_login booleans do not work.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;c. sysadm is a drunken unconfined.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;d. root logins are disabled.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;e. i only use unconfined user domain as a secundary privileged user domain that can only be accessed via sudo&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;e.1. except for the root Linux User which can only login via TTY in emergencies.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;9. Remove as much policy as possible by either disabling or enabling booleans.&lt;br /&gt;&lt;br /&gt;set unconfined_login to off&lt;br /&gt;set xserver_object_manager to on&lt;br /&gt;set *_exec_content to off&lt;br /&gt;consider the secure_mode_booleans&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-1877283547196315196?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/1877283547196315196/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-10-conclusion.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1877283547196315196'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1877283547196315196'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-10-conclusion.html' title='SELinux Lockdown Part Ten: Conclusion'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-4082107556968325338</id><published>2009-06-27T03:13:00.000-07:00</published><updated>2009-06-27T03:22:42.211-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Booleans'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Nine: Booleans</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family: arial;"&gt;Booleans are blocks of policy that can be added or removed on the fly by toggling a boolean. The old NSA Example policy was based on a least privilege model. This means that as little as possible was allowed to successfully achieve a task. Almost each rule that gets added to SELinux policy adds new privileges. To maximize security that SELinux provide the mount of active rules should be kept to a minimum.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In Fedora 11 There is some policy enabled with booleans that your environment may not need. It is recommended that this policy is removed and that it is only added when it is needed.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Some booleans add policy when enabled, others add policy when disabled. A simple description of a booleans functionality can be displayed with the command: &lt;span style="font-weight: bold;"&gt;sudo semanage boolean -l&lt;/span&gt;. These descriptions are usually enough to understand its functionality but the descriptions are short. If you run a AVC denial through the &lt;span style="font-style: italic;"&gt;audit2why&lt;/span&gt; command than &lt;span style="font-style: italic;"&gt;audit2why &lt;/span&gt;will display which boolean to set in order to solve the issue if the problem can be solved by toggling a boolean.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Sometimes it is best to look to the contents of booleans to understand what they allow. Booleans are defined in Source Policy. You would have to have access to the Source Policy and you would have to know how to find the blocks of policy that are the content of the boolean.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are three older tools that help you list, set and toggle SELinux booleans: &lt;span style="font-style: italic;"&gt;getsebool, setsebool and togglesebool&lt;/span&gt;. In Fedora 11 the functionality that these tools provides has been built into the semanage command: &lt;span style="font-weight: bold;"&gt;semanage boolean&lt;/span&gt;. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The names of booleans should point to the Source Policy Module where the boolean is defined. Unfortunately it often is not that easy to find the location of the boolean definition in Source Policy. In a prefect scenario that name of the boolean has the name of the module where it is defined prepended. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Example: How to find the meaning and content of gpg_agent_env_file boolean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;# semanage boolean -l | grep gpg&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;gpg_agent_env_file             -&gt; off   Allow usage of the gpg-agent --write-env-file option. This also allows gpg-agent to manage user files.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;As the name of the boolean suggest, the boolean is defined somewhere in the gpg module:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/apps/gpg.te&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;On line 196 to line 203 the actually content of the boolean is defined.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This boolean allows programs that run in the &lt;span style="font-style: italic;"&gt;gpg_agent_t&lt;/span&gt; SELinux Domain to write files in the user home space with the generic &lt;span style="font-style: italic;"&gt;user_home_t&lt;/span&gt; type when the boolean is set to on.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;I think there is actually a but in the block of policy as the &lt;span style="font-style: italic;"&gt;gpg_agent_t&lt;/span&gt; may only type transition to &lt;span style="font-style: italic;"&gt;user_home_t&lt;/span&gt; files and not to directories.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The boolean declaration can be found on line 9 to line 15. The declaration has a short description of the functionality of the boolean.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The reason why i showed you how to find a description and the actual content of a boolean is because i cannot discuss each and every boolean in this article. If it is decided to lock-down booleans one can look up whether it actually adds or removes policy when toggled on and what it actually does. Then the boolean can just be switched on and off to see if you need to policy it provides. If required that AVC denials can be fed to audit2why to see if there is a boolean available to allow the functionality.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There are a few booleans that i would like to highlight in this article:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The unconfined_login boolean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;unconfined_login               -&gt; off   Allow a user to login as an unconfined domain&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This boolean was discussed the Part Eight of this series. If set to on then users can login to the system in the &lt;span style="font-style: italic;"&gt;unconfined_t&lt;/span&gt; User Domain.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Security can be improved much by setting this to off. The content of this boolean can be found in the unconfineduser.te file in Source Policy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The ssh_sysadm_login and xdm_sysadm_login booleans:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;ssh_sysadm_login               -&gt; off   Allow ssh logins as sysadm_r:sysadm_t&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;xdm_sysadm_login               -&gt; off   Allow xdm logins as sysadm&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This boolean is similar to unconfined_login for the &lt;span style="font-style: italic;"&gt;sysadm_t&lt;/span&gt; User Domain. This boolean currently does NOT work. Therefore it is not recommended to map any SELinux Users to the &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role. Users with access to this role can log into the system directly in this privileged domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The  *_allow_exec_content_t booleans:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;allow_sysadm_exec_content      -&gt; off   allow_sysadm_exec_content&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;allow_xguest_exec_content      -&gt; off   allow_xguest_exec_content&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;allow_user_exec_content        -&gt; off   allow_user_exec_content&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;allow_staff_exec_content       -&gt; off   allow_staff_exec_content&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;allow_guest_exec_content       -&gt; off   allow_guest_exec_content&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The description of this boolean is not very helpfull as you can see. When this boolean is set to on then users that operate in any of the mentioned User Domains can execute user content in their user space. This means files with type &lt;span style="font-style: italic;"&gt;user_home_t&lt;/span&gt;, &lt;span style="font-style: italic;"&gt;user_tmp_t&lt;/span&gt; or when nfs or samba home directories are enabled types &lt;span style="font-style: italic;"&gt;nfs_t&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;cifs_t&lt;/span&gt; respectively. This boolean is Fedora specific and its contents can be found in the userdomain.if Source Policy file.   &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The secure_module boolean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;secure_mode                    -&gt; off   Enabling secure mode disallows programs, such as newrole, from transitioning to administrative user domains.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The secure_mode boolean can be enabled to disallow User Domain transitions to privileged User Domains. The content of this boolean can be found in the selinuxutil.te Source policy file: &lt;span style="font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/system/selinuxutil.te&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The policy for this boolean starts on line 289 and ends on line 295. This boolean currently only works for the newrole command. It does NOT work for the sudo command. Therefore it is encouraged to not depend on this boolean.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The secure_mode_insmod boolean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;secure_mode_insmod             -&gt; off   Disable transitions to insmod.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When this boolean is set to on then confined users will not be able to transition to the insmod Domain. Restricted user domain will not be able to insert Linux Kernel modules. This boolean is defined in the modutils.te Source Policy file: &lt;span style="font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/system/modutils.te&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The policy starts on line 120 and end on line 122. The declaration for this boolean can be found on line 4 to line 6.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The secure_mode_policyload boolean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;secure_mode_policyload         -&gt; off   boolean to determine whether the system permits loading policy, setting enforcing mode, and changing boolean values.  Set this to true and you have to reboot to set it back&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The description of this boolean is quite good. When enabled there is no policy to permit the loading of policy, setting the enforcing mode and changing of booleans. This policy can be found in the selinux.te Source Policy file:  &lt;span style="font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/kernel/selinux.te&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The content of this boolean starts on line 44 and ends on line 52.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;The xserver_object_manager boolean:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;xserver_object_manager         -&gt; off    Support X userspace object manager&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This boolean is quite powerful. By enabling this boolean the X Server access control extensions become enable. XACE allows the operator to define how processes can interact with X Server. The default policy still has rough edges. XACE is implemented for the SELinux Multi Level Security Policy Model which enforces confidentiality. By default it is disabled with SELinux Policy Targeted. If you feel brave, enable it and experience the power of Xace.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;After you set this boolean to true you are required to restart the X server.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The content of this boolean can be found in the xserver.te Source Policy file: &lt;span style="font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/services/xserver.te&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The content of this boolean starts on line 749 and ends on line 766.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;It is not always easy to find where booleans are defined unfortunately. There is room for improvement with the naming of booleans.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;To achieve greater security minimize the amount of policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Sometimes policy is added by turning a boolean on and sometimes policy is added by turning a boolean off.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Content of booleans can be reviewed in Source Policy.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Refer: man getsebool, man setsebool, man togglesebool, man audit2why, man semanage&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-4082107556968325338?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/4082107556968325338/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-nine-booleans.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4082107556968325338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4082107556968325338'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-nine-booleans.html' title='SELinux Lockdown Part Nine: Booleans'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5464960710823214887</id><published>2009-06-26T05:33:00.000-07:00</published><updated>2009-06-26T05:42:46.236-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Domains'/><category scheme='http://www.blogger.com/atom/ns#' term='Unconfined'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='Users'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Eight: Unconfined</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family: arial;"&gt;The unconfined space is for processes that require almost unrestricted access. Almost because writable memory execution is not permitted. The following permissions are restricted for processes that operate in the unconfined space unless specified otherwise: &lt;span style="font-style: italic;"&gt;Execmem Execstack Execheap Execmod&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Processes that in a default Fedora 11 installation operate in this Unconfined Domain are the Linux Kernel, RPM, init scripts, and unconfined users.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Unconfined processes usually run programs unconfined too unless other otherwise specified. It is expected that unconfined processes are unrestricted and that children inherit this unconfined environment. Exceptions to this rule as said should be specified by creating policy that transitions the Unconfined Domain to a restricted space when a unconfined process runs a program.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Security can be greatly improved by removing the unconfined space. This will cause all processes to be restricted by SELinux. In Fedora 11 the unconfined space was split into two parts. The first part is the unconfined space for programs, and the second part is the unconfined space for users. This second part was renamed to the unconfineduser domain. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The result of this split is that now either or both environments can be removed. If the unconfined domain which is the domain for unconfined programs is removed then the init scripts will be restricted. This means that system services that do not have SELinux policy defined will run in the restricted init script environment and will not run unrestricted. This is a great way to ensure that no unrestricted system services are implemented on the system. The kernel and RPM processes stay unconfined because these processes need many permissions in order to operate successfully.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The unconfineduser domain can be removed to ensure that all users operate in a restricted environment. If it is decided to remove the unconfineduser domain than you must reconfigure your SELinux mappings to reflect this change.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;There should be no reason to not remove the unconfined domain if the operator feels comfortable with SELinux. The operator can implement SELinux policy for any system process that does not have policy defined already.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The unconfineduser domain is usually handy to keep, as the operator can mannually configure which Linux users are mapped to this User Domain. SELinux can be configured to not allow unconfined logins via OpenSSH or Grapical User Interface. This means that users that have access to the unconfineduser domain can only login using this environment on the TTY or access the unconfined user space via the&lt;span style="font-style: italic;"&gt; sudo&lt;/span&gt; command or &lt;span style="font-style: italic;"&gt;SU&lt;/span&gt; with &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Using the unconfined user domain as a secondary domain only improves security if unconfined logins are not enabled.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Example: Remove the unconfined domain, disallow unconfined user logins, map &lt;span style="font-style: italic;"&gt;unconfined_r&lt;/span&gt; role to existing &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux User, Remove the &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role for the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux User. Add Linux user John and map the Linux user to the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux user. Add an entry for John to &lt;span style="font-weight: bold;"&gt;/etc/sudoers&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo setsebool -P unconfined_login off&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo semanage user -m -L s0 -r s0-s0:c0.c1023 -R "staff_r system_r unconfined_r" -P user staff_u&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo semodule -r unconfined&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo useradd -Z staff_u john&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo visudo (john ALL=(ALL) TYPE=unconfined_t ROLE=unconfined_r ALL)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;John logs into the system as the restricted Linux user &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt;. When John wants to acquire &lt;span style="font-style: italic;"&gt;root&lt;/span&gt; privileges he simply runs the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command. John can open a &lt;span style="font-style: italic;"&gt;root&lt;/span&gt; shell in the unconfined space by running the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command with the &lt;span style="font-style: italic;"&gt;-s&lt;/span&gt; option.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This configuration should not change your ways of doing things too much since root logins are not encouraged and since the &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; restricted user domain has all permissions that a unprivileged user requires. It is also possible to create a custom User Domain that is tailor made to your personal requirements and map its role to a custom SELinux Users together with the &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;unconfined_r&lt;/span&gt; role. That way you can keep the staff_u SELinux User in its original state and can you modify your User Domain and SELinux user to your requirements.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Consider removing the Unconfined Domain and or the Unconfineduser Domain to improve security.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Refer: man semanage, man semodule, man visudo, man setsebool&lt;/span&gt;&lt;span style="font-style: italic; font-family: arial;"&gt;, man sudo&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5464960710823214887?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5464960710823214887/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-eight-unconfined.html#comment-form' title='2 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5464960710823214887'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5464960710823214887'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-eight-unconfined.html' title='SELinux Lockdown Part Eight: Unconfined'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-1446593877919010087</id><published>2009-06-25T04:58:00.000-07:00</published><updated>2009-06-25T05:10:23.328-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Newrole'/><category scheme='http://www.blogger.com/atom/ns#' term='Sudo'/><category scheme='http://www.blogger.com/atom/ns#' term='Domains'/><category scheme='http://www.blogger.com/atom/ns#' term='SU'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='Users'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><category scheme='http://www.blogger.com/atom/ns#' term='Run_init'/><title type='text'>SELinux Lockdown Part Seven: SU, Newrole, Sudo and Run_init.</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family: arial;"&gt;Before Fedora 9 was released users with access to roles would execute the &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command to Domain Transition. This command can be installed as &lt;span style="font-style: italic;"&gt;policycoreutils-newrole&lt;/span&gt;. The user would for example run: &lt;span style="font-weight: bold;"&gt;newrole -r &lt;newrole_r&gt;&lt;/span&gt;, and get prompted to enter his user password. The &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command would than verify whether the users has all access that is required to make the requested domain transition and allow or deny it.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If the user Transitioned to a privileged User Domain and wanted to perform a privileged task, he would then execute the &lt;span style="font-style: italic;"&gt;SU&lt;/span&gt; command to meet that Discretionary Access Control requirements. The&lt;span style="font-style: italic;"&gt; SU &lt;/span&gt;command prompts for the &lt;span style="font-style: italic;"&gt;root&lt;/span&gt; password.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In a strict environment to become a privileged user, one would run two programs and enter two seperate passwords. A privileged user would require access to roots password to perform any privileged task this way.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For a user such as this to run a system service the is another command to execute. The &lt;span style="font-style: italic;"&gt;Run_init&lt;/span&gt; command performs a Domain transition to the Init Script which in turn starts a system service in its proper Domain. This program also prompts for a password.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;That is a lot of passwords and commands just to restart &lt;span style="font-style: italic;"&gt;Apache&lt;/span&gt; for example.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In Fedora 9 the sudo command was modified to support Domain Transitions. The use of the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command is recommended over the &lt;span style="font-style: italic;"&gt;SU&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;Newrole&lt;/span&gt; command.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Two main advantages of the &lt;span style="font-style: italic;"&gt;Sudo&lt;/span&gt; command are that this command allows you to change Linux uid and SElinux Domain Transition in one turn and that you do not need the root password to do so as long as you are added to the &lt;span style="font-weight: bold;"&gt;/etc/sudoers&lt;/span&gt; configuration file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The destination Domain can be specified as a parameter of the &lt;span style="font-style: italic;"&gt;-t&lt;/span&gt; option, and the destination role can be specified as a parameter of the &lt;span style="font-style: italic;"&gt;-r&lt;/span&gt; option. Sudo can also be configured to Transition to a specified role and domain by default in its &lt;span style="font-style: italic;"&gt;/etc/sudoers&lt;/span&gt; file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For example: Linux user joe logs into the system as SELinux user &lt;span style="font-style: italic;"&gt;joe_u&lt;/span&gt;. SELinux User &lt;span style="font-style: italic;"&gt;joe_u&lt;/span&gt; has access to the &lt;span style="font-style: italic;"&gt;joe_r&lt;/span&gt; role as well as the &lt;span style="font-style: italic;"&gt;webadm_r&lt;/span&gt; role and the &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role. The &lt;span style="font-style: italic;"&gt;joe_r&lt;/span&gt; role maps to the &lt;span style="font-style: italic;"&gt;joe_t&lt;/span&gt; User Domain which has all the permissions required for a restricted login user. The &lt;span style="font-style: italic;"&gt;joe_t&lt;/span&gt; User Domain has access to the &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role as well as the &lt;span style="font-style: italic;"&gt;webadm_r&lt;/span&gt; role in policy. An entry for joe in &lt;span style="font-weight: bold;"&gt;/etc/sudoers&lt;/span&gt; is as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;joe ALL=(ALL) TYPE=webadm_t ROLE=webadm_r ALL&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This entry allows Sudo to transition user joe to &lt;span style="font-style: italic;"&gt;webadm_r&lt;/span&gt; role and &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; role automatically when joe run the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Joe logs in and finds himself in the &lt;span style="font-style: italic;"&gt;joe_t&lt;/span&gt; User Domain. Then when Joe wants to start the Apache service he simple runs: &lt;span style="font-weight: bold;"&gt;sudo service httpd start.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;&lt;span style="font-style: italic;"&gt;Sudo&lt;/span&gt; changes Joes Linux UID to 0 and transitions Joes' Domain and Role automatically to the specified Role and Domain &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;webadm_r&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Joe also has access to the &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role that is required to transition to the Init script domain which starts httpd in its proper Domain. The &lt;span style="font-style: italic;"&gt;Run_init&lt;/span&gt; command is no longer required.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;If Joe has access to several roles then Joe can override the default role and domain specified in the &lt;span style="font-style: italic;"&gt;Sudo&lt;/span&gt; configuration file by specifying the &lt;span style="font-style: italic;"&gt;-t&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;-r&lt;/span&gt; options with the destination role and domain parameters. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Prefer the &lt;span style="font-style: italic;"&gt;Sudo command &lt;/span&gt;over the &lt;span style="font-style: italic;"&gt;SU&lt;/span&gt; with &lt;span style="font-style: italic;"&gt;Newrole&lt;/span&gt; commands.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Prefer access to the &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role over the &lt;span style="font-style: italic;"&gt;Run_init&lt;/span&gt; command.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Refer: man su, man sudo, man newrole, man run_init&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-1446593877919010087?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/1446593877919010087/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-seven-su-newrole.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1446593877919010087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1446593877919010087'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-seven-su-newrole.html' title='SELinux Lockdown Part Seven: SU, Newrole, Sudo and Run_init.'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-1863496220938165572</id><published>2009-06-24T03:27:00.000-07:00</published><updated>2009-06-24T03:38:32.170-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Roles'/><category scheme='http://www.blogger.com/atom/ns#' term='Domains'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='Users'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Six: Customized SELinux Roles</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family: arial;"&gt;In part four of this series i have demonstrated how to create and implement a customized SELinux User Domain. Creating Roles is done in very much the same way. As mentioned in my previous article about RBAC: Roles are mappings to User Domains. Some User Domains can be used by users to log into the system because those User Domains have permissions to access the user home directory for example. I refer those these User Domains as primary User Domains. Other User Domains are designed to be secondary. Users can Domain Transition using the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; or &lt;span style="font-style: italic;"&gt;su&lt;/span&gt; with &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command to these secondary User Domains. Secondary User Domains can not be used by a user to log into the system.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;In this Chapter i am going to demonstrate how such a secondary User Domain is create and implemented. The goal is to create a Privileged SELinux Role that provides the permissions required to manage a Bind DNS service. This role will be based of off the &lt;span style="font-style: italic;"&gt;webadm_t &lt;/span&gt;User Domain that was discussed previously. I will also revisit some material from part four: Customized SELinux User Domains because the user primary User Domain must be modified to be able to access our new &lt;span style="font-style: italic;"&gt;bindadm_r&lt;/span&gt; role.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;As mentioned i will start with creating a new secondary User Domain called &lt;span style="font-style: italic;"&gt;bindadm&lt;/span&gt; that is based of off the pre-defined &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; SELinux User Domain. The two SELinux Source Policy files i am going base my new User Domain of are: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/roles/webadm.te&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/roles/webadm.if&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;SELinux Source Policy files that have a&lt;span style="font-style: italic;"&gt; ".te"&lt;/span&gt; extension are called Type Enforcement files. Files with a &lt;span style="font-style: italic;"&gt;".if"&lt;/span&gt; extension are called Interface files. Type Enforcement files have Declarations and Policy that are personal or local to the Domain. Interface files have Declarations and Policy that are shared by the Domain with other Domains that may want to interact with our Domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;mkdir ~/bindadm; cd ~/bindadm;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "policy_module(bindadm, 0.0.1)" &gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "role bindadm_r;" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "userdom_base_user_template(bindadm)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "allow bindadm_t self:capability { dac_override dac_read_search kill sys_ptrace sys_nice };" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "files_dontaudit_search_all_dirs(bindadm_t)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "files_manage_generic_locks(bindadm_t) &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "files_list_var(bindadm_t)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "selinux_get_enforce_mode(bindadm_t)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "seutil_domtrans_setfiles(bindadm_t)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "logging_send_syslog_msg(bindadm_t)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "userdom_dontaudit_search_user_home_dirs(bindadm_t)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This is the basic contents for a generic privileged secondary User Domain. I left out policy that is specific to managing the Apache service.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now i will add policy that is specific to managing the Bind service. I am able to borrow this policy from the bind Source Policy. As i mentioned shared policy is located in Interface files. This means that if i want to include shared policy related to Bind i should be able to find this in the &lt;span style="font-style: italic;"&gt;bind.te&lt;/span&gt; file if the policy is available:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/services/bind.if&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Starting on line 252 in bind.if and ending on line 305 is policy shared by the Bind module to administrate the bind service. I just have to call this Interface in our &lt;span style="font-style: italic;"&gt;bindadm&lt;/span&gt; Type Enforcement file to include this Policy:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "bind_admin(bindadm_t, bindadm_r)" &gt;&gt; bindadm.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;This concludes my &lt;span style="font-style: italic;"&gt;bindadm&lt;/span&gt; Type Enforcement file. Next my &lt;span style="font-style: italic;"&gt;bindadm&lt;/span&gt; Source Policy should share policy that might be required by other Domains to be able to interact with our &lt;span style="font-style: italic;"&gt;bindadm_t&lt;/span&gt; Domain. I will base this policy of off the &lt;span style="font-weight: bold;"&gt;webadm.if&lt;/span&gt; file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "## &lt;summary&gt;Bind administrator role&lt;/summary&gt;" &gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "########################################" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "## &lt;summary&gt;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "##    Change to the bind administrator role." &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "## &lt;/summary&gt;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo '## &lt;param name="role"&gt;' &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "##    &lt;summary&gt;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "##    Role allowed access." &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "##    &lt;/summary&gt;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "## &lt;/param&gt;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "## &lt;rolecap/&gt;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "#" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "interface(\`bindadm_role_change',\`" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "    gen_require(\`" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "        role bindadm_r;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "    ')" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "    allow \$1 bindadm_r;" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "')" &gt;&gt; bindadm.if;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;The Bind Administrator Shared policy above will later be called by our user primary Customized SELinux User Domain. I am now finished with my &lt;span style="font-style: italic;"&gt;bindadm_t&lt;/span&gt; User Domain.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;My next step is to create a Customized SELinux User Domain for our Bind guy and allow that User Domain to transition to the &lt;span style="font-style: italic;"&gt;bindadm_r&lt;/span&gt; role by calling the &lt;span style="font-weight: bold;"&gt;bindadm_role_change&lt;/span&gt; interface. This Customized SELinux User Domain will be based of off the &lt;span style="font-style: italic;"&gt;staff_t &lt;/span&gt;User Domain:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/roles/staff.te&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "policy_module(bindguy, 0.0.1)" &gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "role bindguy_r;" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "userdom_unpriv_user_template(bindguy)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "sudo_role_template(bindguy, bindguy_r, bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "ssh_role_template(bindguy, bindguy_r, bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "kernel_read_ring_buffer(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "kernel_getattr_core_if(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "kernel_getattr_message_if(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "kernel_read_software_raid_state(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "auth_domtrans_pam_console(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "libs_manage_shared_libs(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "seutil_run_newrole(bindguy_t, bindguy_r)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "netutils_run_ping(bindguy_t, bindguy_r)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "domain_read_all_domains_state(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "domain_getattr_all_domains(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "domain_obj_id_change_exemption(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "files_read_kernel_modules(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "kernel_read_fs_sysctls(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "modutils_read_module_config(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "modutils_read_module_deps(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "miscfiles_read_hwdata(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "term_use_unallocated_ttys(bindguy_t)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now i will call the &lt;span style="font-weight: bold;"&gt;bindadm_role_change&lt;/span&gt; interface that i have defined in the &lt;span style="font-style: italic;"&gt;bindadm.if &lt;/span&gt;Interface file to allow the &lt;span style="font-style: italic;"&gt;bindguy_t&lt;/span&gt; User Domain to transition to the &lt;span style="font-style: italic;"&gt;bindadm_t&lt;/span&gt; SELinux restricted environment:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "bindadm_role_change(bindguy_r)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;I can also automatically create a SELinux User Mapping called &lt;span style="font-style: italic;"&gt;bindguy_u&lt;/span&gt; which is mapped to the &lt;span style="font-style: italic;"&gt;bindguy_r, bindadm_r&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role. The &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role is included so that &lt;span style="font-style: italic;"&gt;bindadm_t&lt;/span&gt; can stop, start and restart the bind system service.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "gen_user(bindguy_u, user, bindguy_r system_r bindadm_r, s0, s0 - mls_systemhigh, mcs_allcats)" &gt;&gt; bindguy.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;To let the login programs know that bindguy is a valid login user i will add default contexts for this user based of off &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; default contexts:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;cp /etc/selinux/targeted/contexts/users/staff_u /etc/selinux/targeted/contexts/users/bindguy_u&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sed -i 's/staff/bindguy/g' /etc/selinux/targeted/contexts/users/bindguy_u&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Both the bindguy and bindadm policy can now be build and installed:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;make -f /usr/share/selinux/devel/Makefile&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo semodule -i bindguy.pp bindadm.pp&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Now i can add a new Linux user with the&lt;span style="font-style: italic;"&gt; useradd&lt;/span&gt; command and &lt;span style="font-style: italic;"&gt;-Z&lt;/span&gt; option and &lt;span style="font-style: italic;"&gt;bindguy_u&lt;/span&gt; parameter:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo useradd -Z bindguy_u bindguy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;For bindguy to be able to use sudo to automatically transition to Linux user root and SELinux Domain &lt;span style="font-style: italic;"&gt;bindadm_t&lt;/span&gt; i will add to &lt;span style="font-style: italic;"&gt;/etc/sudoers&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;echo "bindguy ALL=(ALL) ROLE=bindadm_r TYPE=bindadm_t ALL" &gt;&gt; /etc/sudoers;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;When bindguy logs into the system he will find himself in the &lt;span style="font-style: italic;"&gt;bindguy_t &lt;/span&gt;User Domain which is based of off the &lt;span style="font-style: italic;"&gt;staff_t &lt;/span&gt;User Domain. The &lt;span style="font-style: italic;"&gt;bindguy_t&lt;/span&gt; User Domain can domain transition to the &lt;span style="font-style: italic;"&gt;bindadm_t &lt;/span&gt;User Domain which is a Domain to be used with root access, that can manage the Bind service.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Bindguy would be able to restart the bind service for example by executing:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-weight: bold;"&gt;sudo service named restart&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;Bindguy will also be able to edit the various Bind content and configuration files. Bindguy will not be able to change the root password for example.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;Note: If you found any errors in this exercise or if you have any question or comments, please contact me. Thanks!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family: arial; font-style: italic;"&gt;refer: man bind, man semodule, man sudo, man useradd&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-1863496220938165572?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/1863496220938165572/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-six-customized.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1863496220938165572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/1863496220938165572'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-six-customized.html' title='SELinux Lockdown Part Six: Customized SELinux Roles'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-9036890604139371730</id><published>2009-06-23T02:54:00.000-07:00</published><updated>2009-06-23T04:37:55.313-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='RBAC'/><category scheme='http://www.blogger.com/atom/ns#' term='Domains'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='Users'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Five: SELinux RBAC</title><content type='html'>&lt;span style=";font-family:arial;font-size:130%;"  &gt;It was explained in part one of this series that SELinux users are mapped to SELinux User Domains and Multi Category Security Components. These mappings can be configured by running the semanage command with the user option, and the SELinux User mappings can also automatically be configured by calling the &lt;span style="font-style: italic;"&gt;gen_user()&lt;/span&gt; interface in the Type Enforcement Source Module file for your User Domain.&lt;br /&gt;&lt;br /&gt;SELinux RBAC is used to be able to assign several SELinux restricted environments to a single SELinux user.&lt;br /&gt;&lt;br /&gt;SELinux User Roles are User Domains. When i refer to roles i often mean a SELinux Users' secondary User Domain. Often roles that were designed to be secondary User Domains differ from primary User Domains. This is because Linux Users do not actually use the roles that were designed to be secondary User Domains to log into the system.&lt;br /&gt;&lt;br /&gt;Instead Linux users Domain Transition to their secondary role by using the&lt;span style="font-style: italic;"&gt; sudo&lt;/span&gt; command or a combination of the &lt;span style="font-style: italic;"&gt;su &lt;/span&gt;and &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command.&lt;br /&gt;&lt;br /&gt;Keep in mind that some roles were designed to be primary User Domains and other roles only support secondary User Domain functionality. Primary User Domains let a user log into the system and secondary User Domains can only be used with the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;su&lt;/span&gt; with &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Sysadm Role - An example of a role that is designed to be a primary User Domain:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;sysadm_u&lt;/span&gt; SELinux User is mapped to the &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role. This mapping can be listed by running: &lt;span style="font-weight: bold;"&gt;sudo semanage user -l | grep sysadm_u&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Linux Users that are mapped to the &lt;span style="font-style: italic;"&gt;sysadm_u&lt;/span&gt; SELinux User operate in the &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role by default. In this case &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; is a primary User Domain.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux User is also mapped to the &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role. The primary User Domain for the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux user is &lt;span style="font-style: italic;"&gt;staff_r&lt;/span&gt; role. The default contexts configured in &lt;span style="font-weight: bold;"&gt;/etc/selinux/targeted/contexts/users/staff_u&lt;/span&gt; define what User Domains users should be logged in with by default, and what User Domains users can log in with by for example specifying a User Domain to log in with.&lt;br /&gt;&lt;br /&gt;By default a &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux User logs into the system in the &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; User Domain. The&lt;span style="font-style: italic;"&gt; sysadm_r&lt;/span&gt; role which was designed to  be a primary User Domain can optionally be used to log in by using for example: &lt;span style="font-weight: bold;"&gt;ssh joe/sysadm_r@localhost.localdomain.tld&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role can also be used to Domain Transition by running the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; and &lt;span style="font-style: italic;"&gt;su&lt;/span&gt; with &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command the way secondary User Domains as accessed.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;sysadm_t&lt;/span&gt; User Domain is the default environment of operation for the &lt;span style="font-style: italic;"&gt;sysadm_u&lt;/span&gt; SELinux User and is designed to be the secondary environment of operation for the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux User, but even the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux User can force the &lt;span style="font-weight: bold;"&gt;pam_selinux&lt;/span&gt;  Pluggable Authentication Module to use &lt;span style="font-style: italic;"&gt;sysadm_t&lt;/span&gt; as its primary User Domain.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Webadm Role - An example of a role that is designed to be a secondary domain:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Unlike the &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role, the &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; User Domain cannot be used to log in to the system directly. Instead it must be accessed from another User Domain with the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; or &lt;span style="font-style: italic;"&gt;su&lt;/span&gt; with &lt;span style="font-style: italic;"&gt;newrole&lt;/span&gt; command. The&lt;span style="font-style: italic;"&gt; webadm_t&lt;/span&gt; User Domain does not have the permissions required to run a full user environment.&lt;br /&gt;&lt;br /&gt;To use the&lt;span style="font-style: italic;"&gt; webadm_r&lt;/span&gt; role, it should be mapped to for example the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux user: &lt;span style="font-weight: bold;"&gt;sudo semanage user -m -L s0 -r s0-s0:c0-c1023 -R "staff_r system_r webadm_r" -P user staff_u&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Please note that you are not encouraged to modify existing SELinux Users. It is preferred that the default SELinux Users are left in their original state. Instead add new customized SELinux Users:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage user -a -L s0 -r s0-s0:c0-c1023 -R "staff_r system_r webadm_r" -P user webadm_u&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;cp /etc/selinux/targeted/contexts/users/staff_u /etc/selinux/targeted/contexts/users/webadm_u&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;webadm_r&lt;/span&gt; role can only be used as a secondary User Domain for two reason in this example. The first reason is the the&lt;span style="font-style: italic;"&gt; webadm_t&lt;/span&gt; User Domain does not have enough permissions to support a full login environment. The second reason this that the we have based our&lt;span style="font-style: italic;"&gt; webadm_u&lt;/span&gt; default context file in &lt;span style="font-weight: bold;"&gt;/etc/selinux/targeted/contexts/users&lt;/span&gt; of off the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; default contexts file. In this file the &lt;span style="font-style: italic;"&gt;webadm_t &lt;/span&gt;User Domain is not a valid context to use for system logins.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Using Roles to confine Root:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Role Based Access Control can be used to create different User Domains with different permissions and assign those roles to SELinux Users. Although RBAC can be used for both unprivileged and privileged users, it is common to use it to restrict the privileged root user.&lt;br /&gt;&lt;br /&gt;The &lt;span style="font-style: italic;"&gt;webadm_u&lt;/span&gt; SELinux user i create above for example can be used to restrict a Linux User with root access to only be able to manage the Apache environment. The &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; User Domain is unprivileged. This means that if i run in the &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; User Domain as &lt;span style="font-style: italic;"&gt;root&lt;/span&gt;, then i will not be able to use the root powers. The &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; User Domain is a limited privileged User Domain. If i operate in the &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; User Domain as&lt;span style="font-style: italic;"&gt; root&lt;/span&gt; then i can access &lt;span style="font-style: italic;"&gt;root&lt;/span&gt; resources that are permitted by the &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; restricted environment.&lt;br /&gt;&lt;br /&gt;For example, i, &lt;span style="font-style: italic;"&gt;dgrift &lt;/span&gt;am mapped to the &lt;span style="font-style: italic;"&gt;webadm_u &lt;/span&gt;SELinux User. I am also allowed all &lt;span style="font-style: italic;"&gt;root&lt;/span&gt; permissions in the sudoers configuration file in &lt;span style="font-weight: bold;"&gt;/etc/sudoers&lt;/span&gt;. When i log into the system by default i will find myself in the &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; User Domain. If i run the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command as &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; then i will for example not be able to restart the Apache service.&lt;br /&gt;&lt;br /&gt;If i use the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command to Domain Transition to &lt;span style="font-style: italic;"&gt;webadm_t&lt;/span&gt; before restarting the service i will be able to succeed:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo -r webadm_r -t webadm_t service httpd restart&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If i try to use the &lt;span style="font-style: italic;"&gt;sudo&lt;/span&gt; command to change&lt;span style="font-style: italic;"&gt; root&lt;/span&gt; password i will fail because neither &lt;span style="font-style: italic;"&gt;staff_t&lt;/span&gt; nor &lt;span style="font-style: italic;"&gt;webam_t&lt;/span&gt; User Domains have access to this privilege.&lt;br /&gt;&lt;br /&gt;This is a powerful feature. It means that it is not possible to delegate limited specified root privileges without having to share roots password.&lt;br /&gt;&lt;br /&gt;Next i will explain some of the pre-defined roles available:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The guest_r role:&lt;/span&gt;&lt;br /&gt;This is a primary User Domain only. See part one in this series for a explanation of the &lt;span style="font-style: italic;"&gt;guest_u&lt;/span&gt; SELinux user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The xguest_r role:&lt;/span&gt;&lt;br /&gt;This is a primary User Domain only. See part one in this series for a explanation of the &lt;span style="font-style: italic;"&gt;xguest_u&lt;/span&gt; SELinux user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The user_r role:&lt;/span&gt;&lt;br /&gt;This is a primary User Domain only. See part one in this series for a explanation of the &lt;span style="font-style: italic;"&gt;user_u&lt;/span&gt; SELinux user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The staff_r role:&lt;/span&gt;&lt;br /&gt;This is a primary User Domain only. See part one in this series for a explanation of the &lt;span style="font-style: italic;"&gt;staff_u&lt;/span&gt; SELinux user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The sysadm_r role:&lt;/span&gt;&lt;br /&gt;This User Domain can be used as both primary as well as secondary User Domain. The &lt;span style="font-style: italic;"&gt;sysadm_u&lt;/span&gt; SELinux Users uses &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; as its default role and the &lt;span style="font-style: italic;"&gt;staff_u &lt;/span&gt;SELinux user uses &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; as its optional role. The &lt;span style="font-style: italic;"&gt;sysadm_r&lt;/span&gt; role has permissions sufficient for user logins. See part one in this series for a explanation of the &lt;span style="font-style: italic;"&gt;sysadm_u&lt;/span&gt; user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The system_r role:&lt;/span&gt;&lt;br /&gt;This role is used by the system as a primary role. Users can use the &lt;span style="font-style: italic;"&gt;system_r&lt;/span&gt; role as a secondary role to restart system services in their proper context.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The unconfined_r role:&lt;/span&gt;&lt;br /&gt;This User Domain can be used both as primary as well as secondary User Domain. See part one in this series for a explanation of the &lt;span style="font-style: italic;"&gt;unconfined_u&lt;/span&gt; user.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The webadm_r role:&lt;/span&gt;&lt;br /&gt;This User Domain can be used as secondary User Domain only. This role has does not have access to user home directories and many other privileges required by login users. This User Domain has the permission required to manage the Apache environment.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The logadm_r role:&lt;/span&gt;&lt;br /&gt;This User Domain can be used as secondary User Domain only. This role has does not have access to user home directories and many other privileges required by login users. This User Domain has the permission required to manage the logging environment.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-style: italic;"&gt;Refer: man newrole, man su, man sudo, man semanage&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-9036890604139371730?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/9036890604139371730/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-five-selinux-rbac.html#comment-form' title='1 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/9036890604139371730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/9036890604139371730'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-five-selinux-rbac.html' title='SELinux Lockdown Part Five: SELinux RBAC'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5442692431883468321</id><published>2009-06-22T02:51:00.000-07:00</published><updated>2009-06-22T03:20:38.949-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Policy'/><category scheme='http://www.blogger.com/atom/ns#' term='Source'/><category scheme='http://www.blogger.com/atom/ns#' term='Domains'/><category scheme='http://www.blogger.com/atom/ns#' term='Customized'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='Users'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Four: Customized SELinux User Domains</title><content type='html'>&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;In the first chapter of this series i discussed SELinux users and explained some of the properties of the pre-defined SELinux Users. These profiles should cover most common usage scenarios. In the event that non of the pre-defined SELinux Users really fit a Linux users' profile one can decide to introduce a new restricted environment tailor made to the requirements that are determined.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The easiest way to do this is to base a new custom SELinux User Domain of off a existing one rather then create a new restricted environment from scratch. In this article i will show you how the create a Custom SELinux User Domain that is based of off the &lt;span style="font-style: italic;"&gt;user_t&lt;/span&gt; restricted user environment. I will also show you ways to map this User Domain to a custom SELinux User so that Linux users can be mapped to this environment as described in the chapter called SELinux Users.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The case is the following: I have to add a restricted user to this system with requirements that are almost identical to the SELinux user user_u. The exeption is the this user also must be able to list the &lt;span style="font-style: italic;"&gt;/var&lt;/span&gt; mountpoint. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;To accomplish this, a new SELinux restricted user environment based of off the &lt;span style="font-style: italic;"&gt;user_t&lt;/span&gt; User Domain should be created and installed with a SELinux Policy Module. We can extend this Policy Module to allow the listing of &lt;span style="font-style: italic;"&gt;/var&lt;/span&gt;, and we can create a map for the new User Domain to a new SELinux user.&lt;/span&gt;&lt;span style="font-family:arial;"&gt; We can also use the semanage command to manually map our new User Domain to a new SELinux User instead of adding this map to the Policy Module itself.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;To complete this task i will need access to the SELinux Source Policy for referencing purposes. In this example i will use SELinux Source Policy that is publicly available and browsable at &lt;span style="font-style: italic; font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/&lt;/span&gt;. Although that in this example using upstream Tresys Reference Policy will suffice, it should be noted that in most cases one should refer to distribution specific SELinux Source Policy instead.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;First let's have a look that the &lt;span style="font-style: italic;"&gt;user_t&lt;/span&gt; User Domain SELinux Source Policy Module in the Tresys Source Policy here:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;" &gt;&lt;span style="font-weight: bold;"&gt;http://oss.tresys.com/projects/refpolicy/browser/trunk/policy/modules/roles/unprivuser.te&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Our new User Domain called &lt;span style="font-style: italic;"&gt;myuser_t&lt;/span&gt; will be based of off this &lt;span style="font-style: italic;"&gt;user_t &lt;/span&gt;Policy Module. There will be some minor modifications to target the Fedora Distro specific policy instead:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;mkdir ~/myuser; cd ~/myuser;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;echo "policy_module(myuser, 0.0.1)" &gt; myuser.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;echo "role myuser_r;" &gt;&gt; myuser.te;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;echo "userdom_unpriv_user_template(myuser)" &gt;&gt; myuser.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The policy above will create a new SELinux restricted User Domain that is almost identical to that of the &lt;span style="font-style: italic;"&gt;user_t&lt;/span&gt; user environment that is mapped to the &lt;span style="font-style: italic;"&gt;user_u&lt;/span&gt; SELinux User in a default installation.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now i am going to add the policy that allows this environment access to list the &lt;span style="font-style: italic;"&gt;/var&lt;/span&gt; mountpoint:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;echo "files_list_var(myuser_t)" &gt;&gt; myuser.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Next i will programmatically map our &lt;span style="font-style: italic;"&gt;myuser_t&lt;/span&gt; SELinux User Domain to a new SELinux user called &lt;span style="font-style: italic;"&gt;myuser_u&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;echo "gen_user(myuser_u, user, myuser_r, s0, s0)" &gt;&gt; myuser.te;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Note that the above policy is similar to running the following semanage command manually:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semanage user -a -L s0 -r s0-s0 -R myuser_r -P user myuser_u&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Policy for the customized User Domain is now ready. A binary SELinux Policy Module should now be build from the Source Policy:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;make -f /usr/share/selinux/devel/Makefile &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Alternatively the following commands can be used to build a binary Policy Module:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;checkmodule -M -m -o myuser.mod myuser.te&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;semodule_package -o myuser.pp -m myuser.mod&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Install the new binary Policy Module that has been created:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sudo semodule -i myuser.pp&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Finally we should define default SELinux Security Contexts for our new SELinux user in order to let the login programs know which User Domain to use:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;cp /etc/selinux/targeted/contexts/users/user_u /etc/selinux/targeted/contexts/users/myuser_u&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;" &gt;sed -i 's/user/myuser/g' /etc/selinux/targeted/contexts/users/myuser_u&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Now we can simply add a new Linux User and map this user to our fresh myuser_u SELinux User with the useradd command and -Z option or with the semanage command with the -m option.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Instead of modifying default SELinux Users and SELinux User Domains create new ones.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;&lt;span style="font-family:arial;"&gt;refer: man semodule, man semanage, man checkmodule, man semodule_package&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5442692431883468321?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5442692431883468321/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-four-customized.html#comment-form' title='2 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5442692431883468321'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5442692431883468321'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-four-customized.html' title='SELinux Lockdown Part Four: Customized SELinux User Domains'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-4291318716174246578</id><published>2009-06-21T03:10:00.000-07:00</published><updated>2009-06-22T01:47:25.331-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Permissive'/><category scheme='http://www.blogger.com/atom/ns#' term='Domains'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><category scheme='http://www.blogger.com/atom/ns#' term='Mode'/><title type='text'>SELinux Lockdown Part Three: Permissive Mode Vs. Permissive Domains</title><content type='html'>&lt;span style=";font-family:arial;font-size:130%;"  &gt;The SELinux Permissive Mode is a state where SELinux permits violation of SELinux policy system wide. In this system wide permissive state policy violations are merely logged. Permissive Mode can be used to troubleshoot and test SELinux related issues. The complication with a system wide permissive state is that is is wise to operate it in a safe environment and out of production. In some rare scenarios one could consider minimizing the risks that come with Permissive Mode by using the SEPermit Pluggable Authentication Module, but often this measure is not suffice because that only disables Linux user logins. System services remain vulnerable to policy violations.&lt;br /&gt;&lt;br /&gt;Recently SELinux Permissive Domains were introduced to mitigate these issues. With Permissive Domains one can run a single SELinux Security Domain in a permissive state. By using Permissive Domains you can keep your system in production and for example disable public access to the Permissive Domain using IPTables, TCP Wrappers, PAM or using other methods.&lt;br /&gt;&lt;br /&gt;The semanage command can be used to add and delete SELinux Permissive Domains. You do need to know in which Security Domain a process runs in order to make this Security Domain a Permissive Domain. The ps command used with the -Z option can help you find this information.&lt;br /&gt;&lt;br /&gt;Example of how to make the Security Domain called &lt;span style="font-style: italic;"&gt;httpd_t&lt;/span&gt; for Apache a Permissive Domain:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage permissive -a httpd_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example of how to make the Security Domain called &lt;span style="font-style: italic;"&gt;httpd_t&lt;/span&gt; for Apache be enforced again by SELinux:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage permissive -d httpd_t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example of how to use the semanage command to list SELinux Permissive Domains:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage permissive -l&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=";font-family:arial;font-size:130%;"  &gt;Conclusion:&lt;br /&gt;&lt;br /&gt;Prefer SELinux Permissive Domains over Permissive Mode.&lt;br /&gt;Add, list and delete Permissive domains with the semanage command.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;font-family:arial;font-size:85%;"  &gt;Refer: man semanage, man tcpd, man pam_sepermit, man iptables&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-4291318716174246578?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/4291318716174246578/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-three-permissive.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4291318716174246578'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/4291318716174246578'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-three-permissive.html' title='SELinux Lockdown Part Three: Permissive Mode Vs. Permissive Domains'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-5122676697306919478</id><published>2009-06-20T04:13:00.000-07:00</published><updated>2009-06-20T07:04:50.817-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sepermit'/><category scheme='http://www.blogger.com/atom/ns#' term='Permissive'/><category scheme='http://www.blogger.com/atom/ns#' term='Pam'/><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part Two: PAM SEPermit</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;In a previous article i discussed the advantage of mapping Linux users to confined SELinux users. There may be times when you are required to troubleshoot issues on the system or solve issues that require you to operate in SELinux Permissive Mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The SELinux Permissive Mode is a state in which SELinux restrictions are not enforced. SELinux does however audit SELinux policy violations that would have normally be prevented. Look at Permissive Mode as a Intrusion Detection System where Enforcing Mode could be considered a Intrusion Prevention System.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In most cases one will want to move the system out of production whilst operating in Permissive Mode. In some cases this may not be so easy.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;There are ways to minimize the risks involved with Permissive Mode. A feature that was recently introduced called SELinux Permissive Domains is a preferred method to accomplish this. Permissive Domains will be discussed in a later chapter.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;The Pluggable Authentication Module called SEPermit can also help minimizing exposure of Permissive Mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;PAM SEPermit can disable Linux user logins when the system operates in Permissive Mode. Consider operating a system where your local Linux users are restricted by SELinux. Permissive Mode effectively lifts those restrictions. Linux users may take advantage of this by accessing resources they would otherwise be restricted to use.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In Fedora 11 PAM SEPermit is enabled by default in the various appropriate files in&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;font-size:130%;"  &gt; /etc/pam.d/&lt;/span&gt; like for example &lt;span style="font-style: italic;font-family:arial;font-size:130%;"  &gt;/etc/pam.d/sshd&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;. One can simply configure SEPermit to disable Linux user logins in Permissive mode by adding Linux users and or SELinux users to the SEPermit configuration file located in &lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;font-size:130%;"  &gt;/etc/security/sepermit.conf&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Appending &lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;font-size:130%;"  &gt;%user_u&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt; to your &lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;font-size:130%;"  &gt;sepermit.conf&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt; file in&lt;/span&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-family:arial;font-size:130%;"  &gt; /etc/security&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="font-family:arial;"&gt; for example, disable login for SELinux user user_u when the system is in Permissive Mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;Be aware that SELinux Permissive Mode however also lifts SELinux restrictions for processes other then Linux users like for example system services.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;In most cases you are still encouraged to move your system out of the Demilitarized Zone when troubleshooting issues in Permissive Mode. PAM SEPermit can however be helpful in some cases.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-size:130%;" &gt;Try it out!&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;Conclusion:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Prefer SELinux Permissive Domains over SELinux Permissive Mode.&lt;br /&gt;If Permissive Mode in a live environment is required on a system with SELinux restricted Linux users then you are encourage to disable Linux user logins with the SEPermit Pluggable Authentication Module.&lt;br /&gt;Be aware that this only affects Linux Users and that system services will not be protected by SELinux in Permissive Mode.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic;"&gt;refer: man pam_sepermit, man setenforce, man getenforce&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-5122676697306919478?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/5122676697306919478/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-two-pam-sepermit.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5122676697306919478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/5122676697306919478'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-two-pam-sepermit.html' title='SELinux Lockdown Part Two: PAM SEPermit'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5024703430482213163.post-3973753788921092589</id><published>2009-06-19T03:54:00.000-07:00</published><updated>2009-06-21T03:41:31.240-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lockdown'/><category scheme='http://www.blogger.com/atom/ns#' term='Confined'/><category scheme='http://www.blogger.com/atom/ns#' term='Users'/><category scheme='http://www.blogger.com/atom/ns#' term='SELinux'/><title type='text'>SELinux Lockdown Part One: SELinux Users</title><content type='html'>&lt;span style="font-family:arial;"&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;span style="font-size:85%;"&gt;This article is the first in a series about tightening SELinux configuration for Fedora 11.&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;In Fedora 11, Linux users by default are mapped to the unconfined_u SELinux user. The unconfined_u SELinux user is mapped to the unconfined_r, system_r roles and to all available Multi Category Security compartments.&lt;br /&gt;&lt;br /&gt;Both unconfined_r and system_r are roles that map to SELinux security domains. SELinux security domains are defined security environments for processes on the Linux system.&lt;br /&gt;&lt;br /&gt;The unconfined security domain, unconfined_t, is a environment reserved for processes that are to a large extend exempted from SELinux restrictions. The system_r role maps to security domains for system processes.&lt;br /&gt;&lt;br /&gt;The unconfined_u SELinux user has access to the system_r role to be able to run system processes in their security domains. SELinux user unconfined_u operates in the unconfined_t security domain via the unconfined_r role that it is mapped to.&lt;br /&gt;&lt;br /&gt;The semanage command can be used to add, modify and delete Linux user to SELinux user mappings, as well as other settings related to SELinux management. Alternatively the system-config-selinux graphical user interface to semanage can be used to modify these settings.&lt;br /&gt;&lt;br /&gt;To use the semanage command to list to which SELinux user, Linux users get mapped by default type: &lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;span style="font-weight: bold;"&gt;sudo semanage login -l | grep default&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;__default__               unconfined_u                   SystemLow-SystemHigh&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;In the example above Linux users are mapped to the unconfined_u SELinux user by default.&lt;br /&gt;&lt;br /&gt;To modify this configuration to map Linux users by default to a confined SELinux user called user_u simply type:&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt; &lt;span style="font-weight: bold;"&gt;sudo semanage login -m -s user_u "__default__"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;This will map new Linux users to the restricted user_u SELinux user by default.&lt;br /&gt;&lt;br /&gt;You can override this mapping when you run the useradd command to add Linux users with the -Z option. This option specifies to which SELinux user the Linux user should be mapped. For example type:&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt; &lt;span style="font-weight: bold;"&gt;sudo useradd -Z guest_u joe&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The usermod command with -Z option can also be used to modify a Linux user to SELinux user mapping.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;This will add a Linux user called joe and will map joe to the guest_u SELinux user instead of mapping joe to the defined default SELinux user.&lt;br /&gt;&lt;br /&gt;There are some SELinux user profiles predefined. These profiles can be listed with the semanage command. type:&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt; &lt;span style="font-weight: bold;"&gt;sudo semanage user -l&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;Next i will discuss some of the properties of these predefined SELinux users.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The guest_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;This profile is used for users that need to be tightly controlled. The guest_u SELinux user can only log in using OpenSSH. Guest users have no access to network resources, setuid, setgid programs.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The xguest_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;This profile is identical to that of guest_u. The exception is that Xguest users can only log in to Xwindows and cannot log in using OpenSSH. Another exception of Xguest users is that this partical user can access HTTP port using a SELinux restricted instance of Mozilla Firefox.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The user_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;The user_u SELinux user resembles a ordinary unprivileged SELinux confined user. This user can log in using Xwindows and OpenSSH, has access to network resources, but cannot use setuid and setgid programs.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The staff_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;This SELinux user is identical to user_u except that staff_u can access setuid and getgid programs. The staff_u SELinux user can also stat all process on the system amongst other minor extra privileges compared to user_u.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The sysadm_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;This user is designed for SELinux restricted root login, which is not recommended. This SELinux user is used in a Multi Level Security Environment where there is no unconfined_u.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The unconfined_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;The unconfined_u SELinux user is the environment where all Linux users are mapped to be default in Fedora Targeted policy. This user is to a large extend exempted from SELinux confinement. The exception is Memory Execution Protections.&lt;br /&gt;&lt;br /&gt;Real Linux users, not root, should not be mapped to the unconfined_u SELinux user group if you want to improve security on your system. In many scenarios having unconfined users on a system creates a gaping hole in security.&lt;br /&gt;&lt;br /&gt;Root logins should be prohibited always. Root should only be able to log in using the terminal in case of an emergency. In Fedora, the Linux user root is mapped to unconfined_u. This means that root logins are almost not protected by SELinux.&lt;br /&gt;&lt;br /&gt;The improve the security of root logins one could map the root Linux user to the sysadm_u SELinux user. Although this does not provide much security over unconfined_u, and root will be able to bypass SELinux security.&lt;br /&gt;&lt;br /&gt;Bottom line is that root logins should not be permitted except on the terminals in case of emergency.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;The system_u SELinux user:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;This SELinux user profile is reserved for the system. Linux users should not be mapped to the System_u SELinux user.&lt;br /&gt;&lt;br /&gt;I explained how one can define a default SELinux user for new Linux users by default, and i explained how one can override this with the useradd command and -Z option.&lt;br /&gt;&lt;br /&gt;The available predefined SELinux users were explained. What is left is to show how SELinux user mappings to Linux users can be altered.&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;br /&gt;&lt;br /&gt;To list all Linux user to SELinux user mappings:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage login -l&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To manually map a Linux user to a SELinux user:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage login -a (...)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To modify a Linux user to SELinux user mapping:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage -m (...)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To delete a Linux user to SELinux uper mapping:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;sudo semanage -d (...)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Conclusion:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:130%;"&gt;Configure SELinux to map Linux users to confined SELinux users by default to improve security.&lt;br /&gt;Disallow root logins using OpenSSH and Xwindows altogether. Allow root to only login using the terminal in case of emergency. Either leave the root Linux user mapping to the unconfined_u SELinux user or map root to sysadm_u. (for example if you decide to de-install the unconfineduser SELinux module)&lt;br /&gt;Map your Linux users to the appropriate confined SELinux user by using the profile that best fits.&lt;br /&gt;Use the useradd command with -Z option to add Linux users, overriding the default Linux user to SELinux user mapping by the SELinux user that you pass as its argument.&lt;br /&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;&lt;br /&gt;Refer: man semanage, man useradd, man usermod&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:130%;" &gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-style: italic;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5024703430482213163-3973753788921092589?l=selinux-mac.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://selinux-mac.blogspot.com/feeds/3973753788921092589/comments/default' title='Reacties plaatsen'/><link rel='replies' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-one-confined.html#comment-form' title='0 reacties'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3973753788921092589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5024703430482213163/posts/default/3973753788921092589'/><link rel='alternate' type='text/html' href='http://selinux-mac.blogspot.com/2009/06/selinux-lockdown-part-one-confined.html' title='SELinux Lockdown Part One: SELinux Users'/><author><name>Dominick "domg472" Grift</name><uri>http://www.blogger.com/profile/11819170833190325982</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
