<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iptables and more on Linux &#187; security</title>
	<atom:link href="http://iptables.gen.tr/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://iptables.gen.tr</link>
	<description>networking, tools in Linux and more...</description>
	<lastBuildDate>Wed, 16 Jun 2010 15:37:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SELinux tools</title>
		<link>http://iptables.gen.tr/2010/01/selinux-tools/</link>
		<comments>http://iptables.gen.tr/2010/01/selinux-tools/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 18:34:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[selinux]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=95</guid>
		<description><![CDATA[As SELinux is a bit of complicated compared to the tools that we use currently, I have thought it is good to have some tips here.
1) seinfo: This is the selinux query tool to see statistics about your policy.



[root@rh54-3 ~]# seinfo 
Statistics for policy file: /etc/selinux/targeted/policy/policy.21
Policy Version &#38; Type: v.21 (binary, MLS)
Classes:            61    Permissions:       220
Types:            [...]]]></description>
			<content:encoded><![CDATA[<p>As SELinux is a bit of complicated compared to the tools that we use currently, I have thought it is good to have some tips here.</p>
<p>1) <strong>seinfo:</strong> This is the selinux query tool to see statistics about your policy.</p>
<table style="background-color: #87cefa; width: 505px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 ~]# <strong>seinfo </strong></p>
<p>Statistics for policy file: /etc/selinux/targeted/policy/policy.21<br />
Policy Version &amp; Type: v.21 (binary, MLS)</p>
<p>Classes:            61    Permissions:       220<br />
Types:            1710    Attributes:        161<br />
Users:               3    Roles:               6<br />
Booleans:          242    Cond. Expr.:       222<br />
Sensitivities:       1    Categories:       1024<br />
Allow:          116810    Neverallow:          0<br />
Auditallow:         41    Dontaudit:        6778<br />
Role allow:          5    Role trans:          0<br />
Type_trans:       1886    Type_change:         0<br />
Type_member:         0    Range_trans:       317<br />
Constraints:        47    Validatetrans:       0<br />
Fs_use:             18    Genfscon:           74<br />
Portcon:           323    Netifcon:</td>
</tr>
</tbody>
</table>
<p>2)<strong> sesearch:</strong> This is a very handy tool. When I started using SELinux, I was thinking that processes with a specific type are only allowed to make operations of the same type:) how stupid I am. Then I have seen by experience that policy can defines it and to see what a source can do, we can use sesearch. For example to search for httpd_t type source in order to see in which types it is associated with issue the following;</p>
<table style="background-color: #87cefa; width: 677px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 ~]#<strong> sesearch -s httpd_t -c file &#8211;allow</strong><br />
Found 103 av rules:<br />
allow httpd_t etc_runtime_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_var_lib_t : file { ioctl read write create getattr setattr lock append unlink link rename };<br />
allow httpd_t httpd_var_run_t : file { ioctl read write create getattr setattr lock append unlink link rename };<br />
allow httpd_t httpd_sys_content_t : file { ioctl read getattr lock };<br />
allow httpd_t public_content_rw_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_bugzilla_htaccess_t : file { ioctl read getattr lock };<br />
allow httpd_t mailman_data_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_cvs_htaccess_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_sys_htaccess_t : file { ioctl read getattr lock };<br />
allow httpd_t squirrelmail_spool_t : file { ioctl read write create getattr setattr lock append unlink link rename };<br />
allow httpd_t httpd_prewikka_htaccess_t : file { ioctl read getattr lock };<br />
allow httpd_t locale_t : file { ioctl read getattr lock };<br />
allow httpd_t var_auth_t : file { ioctl read write create getattr setattr lock append unlink link rename };<br />
allow httpd_t etc_t : file { ioctl read getattr lock };<br />
allow httpd_t fonts_t : file { ioctl read getattr lock };<br />
allow httpd_t ld_so_t : file { ioctl read getattr lock execute };<br />
allow httpd_t proc_t : file { ioctl read getattr lock };<br />
allow httpd_t sysfs_t : file { ioctl read getattr lock };<br />
allow httpd_t krb5_keytab_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_config_t : file { ioctl read getattr lock };<br />
allow httpd_t udev_tbl_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_tmp_t : file { ioctl read write create getattr setattr lock append unlink link rename };<br />
allow httpd_t shell_exec_t : file { ioctl read getattr lock execute execute_no_trans };<br />
allow httpd_t cvs_data_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_helper_exec_t : file { read getattr execute };<br />
allow httpd_t ld_so_cache_t : file { ioctl read getattr lock };<br />
allow httpd_t httpd_squirrelmail_t : file { ioctl read write create getattr setattr lock append unlink link rename };<br />
allow httpd_t httpd_php_exec_t : file { read getattr execute };<br />
allow httpd_t httpd_nagios_htaccess_t : file { ioctl read getattr lock };<br />
allow httpd_t net_conf_t : file { ioctl read getattr lock };<br />
&#8230;</p>
<p>&#8230;</td>
</tr>
</tbody>
</table>
<p>3)<strong> Restorecon</strong></p>
<p>This is a very useful utility that allows you to restore types configured statically in the system. The only thing you should do is</p>
<table style="background-color: #87cefa; width: 489px; height: 24px;" border="0">
<tbody>
<tr>
<td><strong>#restorecon -R -v /data</strong></td>
</tr>
</tbody>
</table>
<p>However if your type is in /etc/selinux/targeted/contexts/customizable_types file then you have to add &#8220;<strong>-F</strong>&#8221; flag into the command, if you don&#8217;t nothing happens:)  As I have quoted text from Dan Walsh&#8217;s blog (RH engineer) , restorecon ignores these types and -F must be added.</p>
<ul>
<li><em>customizable_types </em>
<ul>
<li><em>These are a list of file types that restorecon will ignore.  So if you want to relabel your entire system using restorecon, and a file is labeled with a context in this file, the context will not be changed.  This can be overridden with the -F flag.  This allows you to specify special directories on your system as being readable by apache.  So if you chcon -R -t httpd_sys_content_t  /var/myhtml, a relabel will not change this directory tree back to var_t.</em></li>
</ul>
</li>
</ul>
<p>Selinux User Guide: <a href="http://docs.fedoraproject.org/selinux-user-guide/f12/en-US/index.html" target="_blank">http://docs.fedoraproject.org/selinux-user-guide/f12/en-US/index.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/selinux-tools/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Disabling local access for normal users</title>
		<link>http://iptables.gen.tr/2010/01/disabling-local-access-for-normal-users/</link>
		<comments>http://iptables.gen.tr/2010/01/disabling-local-access-for-normal-users/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 13:40:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=93</guid>
		<description><![CDATA[If you want to disable only local login for normal users you can use the file /etc/security/access.conf for this purpose however it doesn&#8217;t work by default even if you configure this file properly. For example, if you want to allow root logins locally but not any other user, edit access.conf file such that;



-:ALL EXCEPT root:ALL



Literally [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to disable only local login for normal users you can use the file /etc/security/access.conf for this purpose however it doesn&#8217;t work by default even if you configure this file properly. For example, if you want to allow root logins locally but not any other user, edit access.conf file such that;</p>
<table style="background-color: #87cefa; width: 350px; height: 24px;" border="0">
<tbody>
<tr>
<td>-:ALL EXCEPT root:ALL</td>
</tr>
</tbody>
</table>
<p>Literally the above line means &#8221; Disable (-) all users&#8217;  (ALL) login access except (EXCEPT) root user (root) and allow root user to login via all terminals.</p>
<p>We haven&#8217;t finished yet as we must introduce this file into pam configuration. The necessary pam module is &#8220;<strong>pam_access</strong>&#8221; my new /etc/pam.d/login file is as follows:</p>
<table style="background-color: #87cefa; width: 629px; height: 248px;" border="0">
<tbody>
<tr>
<td>#%PAM-1.0<br />
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so<br />
auth       include      system-auth<br />
account    required     pam_nologin.so<br />
<span style="color: #ff0000;"><strong>account    required     pam_access.so</strong></span><br />
account    include      system-auth<br />
password   include      system-auth<br />
# pam_selinux.so close should be the first session rule<br />
session    required     pam_selinux.so close<br />
session    include      system-auth<br />
session    required     pam_loginuid.so<br />
session    optional     pam_console.so<br />
# pam_selinux.so open should only be followed by sessions to be executed in the user context<br />
session    required     pam_selinux.so open<br />
session    optional     pam_keyinit.so force revoke</td>
</tr>
</tbody>
</table>
<p>By the default, the red line isn&#8217;t in this file. Once you add it, you will see that access restrictions are applied.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/disabling-local-access-for-normal-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabling su for normal users</title>
		<link>http://iptables.gen.tr/2010/01/disabling-su-for-normal-users/</link>
		<comments>http://iptables.gen.tr/2010/01/disabling-su-for-normal-users/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 13:10:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=88</guid>
		<description><![CDATA[When I install Gentoo, as far as I remember, by default normal users aren&#8217;t allowed to use &#8220;su&#8221; . If you want to let any user to use &#8220;su&#8221; then you have to add them into the &#8220;wheel&#8221; user group. In redhat, you can uncomment one line, and it works like a charm.
Edit the file [...]]]></description>
			<content:encoded><![CDATA[<p>When I install Gentoo, as far as I remember, by default normal users aren&#8217;t allowed to use &#8220;su&#8221; . If you want to let any user to use &#8220;su&#8221; then you have to add them into the &#8220;wheel&#8221; user group. In redhat, you can uncomment one line, and it works like a charm.</p>
<p>Edit the file /etc/pam.d/su :</p>
<table style="background-color: #87cefa; width: 539px; height: 24px;" border="0">
<tbody>
<tr>
<td>#%PAM-1.0<br />
auth            sufficient      pam_rootok.so<br />
# Uncomment the following line to implicitly trust users in the &#8220;wheel&#8221; group.<br />
#auth           sufficient      pam_wheel.so trust use_uid<br />
# Uncomment the following line to require a user to be in the &#8220;wheel&#8221; group.<br />
<span style="color: #ff0000;"><strong>#auth            required        pam_wheel.so use_uid</strong></span><br />
auth            include         system-auth<br />
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet<br />
account         include         system-auth<br />
password        include         system-auth<br />
session         include         system-auth<br />
session         optional        pam_xauth.so</td>
</tr>
</tbody>
</table>
<p>If you uncomment the red line;</p>
<table style="background-color: #87cefa; width: 541px; height: 24px;" border="0">
<tbody>
<tr>
<td>#%PAM-1.0<br />
auth            sufficient      pam_rootok.so<br />
# Uncomment the following line to implicitly trust users in the &#8220;wheel&#8221; group.<br />
#auth           sufficient      pam_wheel.so trust use_uid<br />
# Uncomment the following line to require a user to be in the &#8220;wheel&#8221; group.<br />
<strong>auth            required        pam_wheel.so use_uid</strong><br />
auth            include         system-auth<br />
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet<br />
account         include         system-auth<br />
password        include         system-auth<br />
session         include         system-auth<br />
session         optional        pam_xauth.so</td>
</tr>
</tbody>
</table>
<p>Then users have to be in wheel group in order to gain access to root privileges. Once you add your normal user into wheel user e.g</p>
<table style="background-color: #87cefa; width: 536px; height: 24px;" border="0">
<tbody>
<tr>
<td><strong>usermod -G wheel testuser</strong></td>
</tr>
</tbody>
</table>
<p>this test users can switch into root user.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/disabling-su-for-normal-users/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Displaying certificates with openssl</title>
		<link>http://iptables.gen.tr/2010/01/displaying-certificates-with-openssl/</link>
		<comments>http://iptables.gen.tr/2010/01/displaying-certificates-with-openssl/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 12:14:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=83</guid>
		<description><![CDATA[Sometimes you need to view certificates with a simple utility rather then using a browser or MUA. Here is how you can do it with openssl. For instance you would like to display the certificate of https://192.168.200.1  , lets do it;
DISPLAYING A REMOTE CERTIFICATE



# openssl s_client -connect 192.168.200.1:443
CONNECTED(00000003)
depth=0 /C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain
verify error:num=18:self signed certificate
verify return:1
depth=0 /C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain
verify error:num=9:certificate [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to view certificates with a simple utility rather then using a browser or MUA. Here is how you can do it with openssl. For instance you would like to display the certificate of https://192.168.200.1  , lets do it;</p>
<p><strong>DISPLAYING A REMOTE CERTIFICATE</strong></p>
<table style="background-color: #87cefa; width: 671px; height: 24px;" border="0">
<tbody>
<tr>
<td><strong># openssl s_client -connect 192.168.200.1:443</strong><br />
CONNECTED(00000003)<br />
depth=0 /C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
verify error:num=18:self signed certificate<br />
verify return:1<br />
depth=0 /C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
verify error:num=9:certificate is not yet valid<br />
notBefore=Dec  8 18:44:11 2009 GMT<br />
verify return:1<br />
depth=0 /C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
notBefore=Dec  8 18:44:11 2009 GMT<br />
verify return:1<br />
&#8212;<br />
Certificate chain<br />
0 s:/C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
i:/C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
&#8212;<br />
Server certificate<br />
&#8212;&#8211;BEGIN CERTIFICATE&#8212;&#8211;<br />
MIIEDjCCA3egAwIBAgICRrUwDQYJKoZIhvcNAQEFBQAwgbsxCzAJBgNVBAYTAi0t<br />
MRIwEAYDVQQIEwlTb21lU3RhdGUxETAPBgNVBAcTCFNvbWVDaXR5MRkwFwYDVQQK<br />
ExBTb21lT3JnYW5pemF0aW9uMR8wHQYDVQQLExZTb21lT3JnYW5pemF0aW9uYWxV<br />
bml0MR4wHAYDVQQDExVsb2NhbGhvc3QubG9jYWxkb21haW4xKTAnBgkqhkiG9w0B<br />
CQEWGnJvb3RAbG9jYWxob3N0LmxvY2FsZG9tYWluMB4XDTA5MTIwODE4NDQxMVoX<br />
DTEwMTIwODE4NDQxMVowgbsxCzAJBgNVBAYTAi0tMRIwEAYDVQQIEwlTb21lU3Rh<br />
dGUxETAPBgNVBAcTCFNvbWVDaXR5MRkwFwYDVQQKExBTb21lT3JnYW5pemF0aW9u<br />
MR8wHQYDVQQLExZTb21lT3JnYW5pemF0aW9uYWxVbml0MR4wHAYDVQQDExVsb2Nh<br />
bGhvc3QubG9jYWxkb21haW4xKTAnBgkqhkiG9w0BCQEWGnJvb3RAbG9jYWxob3N0<br />
LmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqP30TzVK+<br />
kO/V8g7PLP4gDDBAJAoQheb/I8Fg4pMiWUKnBE1hqftCOWcd1KTyNWgXPNB+xspE<br />
5G+3Lk5enccuzr/r0YrjJHWYNzKge4tau1sLSqpBWlFGyQmBlP1JBG2vBQMy9nu6<br />
t/RtJMii6yDm9H6xj10h98wXut8D6mOyQwIDAQABo4IBHTCCARkwHQYDVR0OBBYE<br />
FPbm+ZFfjHJF3HtyQDzO31YbNVaNMIHpBgNVHSMEgeEwgd6AFPbm+ZFfjHJF3Hty<br />
QDzO31YbNVaNoYHBpIG+MIG7MQswCQYDVQQGEwItLTESMBAGA1UECBMJU29tZVN0<br />
YXRlMREwDwYDVQQHEwhTb21lQ2l0eTEZMBcGA1UEChMQU29tZU9yZ2FuaXphdGlv<br />
bjEfMB0GA1UECxMWU29tZU9yZ2FuaXphdGlvbmFsVW5pdDEeMBwGA1UEAxMVbG9j<br />
YWxob3N0LmxvY2FsZG9tYWluMSkwJwYJKoZIhvcNAQkBFhpyb290QGxvY2FsaG9z<br />
dC5sb2NhbGRvbWFpboICRrUwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOB<br />
gQBNUijzKybFB2a/vDpetJ9AEyyLFwlqnF2QIY577pYo6WBR/w6XsEo7oN2PHRKB<br />
z77OfW9Wt15tTMqm3gZMHVY7wmnWA0uVbnbnAL90Ht6pdRvqYy7CyejaKJQKPBhI<br />
ZjGKWJlPzgf5gro4nSPwoG+qFnmJYotoFfGP9+5gF1HEmA==<br />
&#8212;&#8211;END CERTIFICATE&#8212;&#8211;<br />
subject=/C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
issuer=/C=&#8211;/ST=SomeState/L=SomeCity/O=SomeOrganization/OU=SomeOrganizationalUnit/CN=localhost.localdomain/emailAddress=root@localhost.localdomain<br />
&#8212;<br />
No client certificate CA names sent<br />
&#8212;<br />
SSL handshake has read 1606 bytes and written 316 bytes<br />
&#8212;<br />
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-SHA<br />
Server public key is 1024 bit<br />
Compression: NONE<br />
Expansion: NONE<br />
SSL-Session:<br />
Protocol  : TLSv1<br />
Cipher    : DHE-RSA-AES256-SHA<br />
Session-ID: 1B7226891FBA809022C13F2ECC68E602895ADBA11F8FCB93630BA7DC643B1781<br />
Session-ID-ctx:<br />
Master-Key: 46F7E40AE4688DFBDCDBAE5B261078323A227C21988F78B568A8F15C660CD2C9C4A8FF517B71A460B1C2CFF8F51FAF7F<br />
Key-Arg   : None<br />
Krb5 Principal: None<br />
Start Time: 1136128014<br />
Timeout   : 300 (sec)<br />
Verify return code: 9 (certificate is not yet valid)<br />
&#8212;</td>
</tr>
</tbody>
</table>
<p><strong>DISPLAYING A LOCAL CERTIFICATE (FILE)</strong></p>
<p>If you issue the following command for the certificate file (server.crt) locally saved, you will see the certificate details</p>
<table style="background-color: #87cefa; width: 276px; height: 24px;" border="0">
<tbody>
<tr>
<td><strong>#openssl x509 -in server.crt -text</strong></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/displaying-certificates-with-openssl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SELinux and SAMBA</title>
		<link>http://iptables.gen.tr/2010/01/selinux-and-samba/</link>
		<comments>http://iptables.gen.tr/2010/01/selinux-and-samba/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 17:18:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[samba]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=72</guid>
		<description><![CDATA[In this article we will configure samba based on a case in which SELinux is enabled again . The case is:
&#8220;Setup samba in such a way that only users mert and yigit will be able to access the folder /samba_share in the server&#8221;
1) First create the folder and set the permissions for these users and [...]]]></description>
			<content:encoded><![CDATA[<p>In this article we will configure samba based on a case in which SELinux is enabled again . The case is:</p>
<p>&#8220;Setup samba in such a way that only users <strong>mert</strong> and <strong>yigit</strong> will be able to access the folder /samba_share in the server&#8221;</p>
<p><strong>1) </strong>First create the folder and set the permissions for these users and adjust selinux settings.</p>
<table style="background-color: #87cefa; width: 495px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 /]# <strong>mkdir /samba_share</strong><br />
[root@rh54-2 /]#<strong> setfacl -m u:mert:rwx /samba_share/</strong><br />
[root@rh54-2 /]# <strong>setfacl -m u:yigit:rwx /samba_share/</strong><br />
[root@rh54-2 /]# <strong>getfacl /samba_share/</strong><br />
getfacl: Removing leading &#8216;/&#8217; from absolute path names<br />
# file: samba_share<br />
# owner: root<br />
# group: root<br />
user::rwx<br />
<strong>user:yigit:rwx</strong><br />
<strong>user:mert:rwx</strong><br />
group::r-x<br />
mask::rwx<br />
other::r-x</td>
</tr>
</tbody>
</table>
<p>From the getfacl output we can see that root,mert and yigit users have full access on this folder.</p>
<p>Now put this new share under the security context type of samba which is : <strong>samba_share_t</strong></p>
<table style="background-color: #87cefa; width: 664px; height: 52px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>chcon -R -t samba_share_t /samba_share/</strong><br />
[root@rh54-2 ~]#<strong> semanage fcontext -a -t samba_share_t &#8220;/samba_share(/.*)?&#8221;</strong></td>
</tr>
</tbody>
</table>
<p>As it can be seen we have also added the folder into the policy so that if relabeling is performed, this folder won&#8217;t be affected.</p>
<p><strong>2) </strong>Setup SAMBA config to allow access for these users</p>
<table style="background-color: #87cefa; width: 492px; height: 24px;" border="0">
<tbody>
<tr>
<td>[sambatest]<br />
comment = share for mert and yigit<br />
path = /samba_share<br />
writable = yes<br />
valid users = yigit mert</td>
</tr>
</tbody>
</table>
<p>and reload samba</p>
<table style="background-color: #87cefa; width: 491px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>/etc/init.d/smb reload</strong><br />
Reloading smb.conf file: [  OK  ]</td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> <em>As we have used &#8220;<strong>valid users</strong>&#8221; option for users, no other users are allowed even to display/login into this share. If we had written<br />
&#8220;<strong>writable = no</strong>&#8221; and &#8220;<strong>write list = yigit mert</strong>&#8221; , then other users would have also gained access into this share.</em></p>
<p><span id="more-72"></span></p>
<p><strong>3) </strong>Add these users into samba user list</p>
<table style="background-color: #87cefa; width: 495px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>smbpasswd -a yigit</strong><br />
New SMB password:<br />
Retype new SMB password:<br />
Added user yigit.<br />
[root@rh54-2 ~]# <strong>smbpasswd -a mert</strong><br />
New SMB password:<br />
Retype new SMB password:<br />
Added user mert.</td>
</tr>
</tbody>
</table>
<p>4) Connect to samba server and send a test file followed by a deletion</p>
<table style="background-color: #87cefa; width: 501px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>touch testfile</strong><br />
[root@rh54-2 ~]#<strong> smbclient //192.168.200.81/sambatest -U yigit </strong><br />
Password:<br />
Domain=[RH54-2] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]<br />
smb: \&gt; <strong>put testfile</strong><br />
putting file testfile as \testfile (0.0 kb/s) (average 0.0 kb/s)<br />
smb: \&gt; <strong>rm testfile</strong><br />
smb: \&gt;</td>
</tr>
</tbody>
</table>
<p>As you can see sending and removing a file works for the user yigit, lets try for mert.</p>
<table style="background-color: #87cefa; width: 557px; height: 108px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 ~]# <strong>smbclient //192.168.200.81/sambatest -U mert</strong><br />
Password:<br />
Domain=[RH54-2] OS=[Unix] Server=[Samba 3.0.33-3.14.el5]<br />
smb: \&gt; <strong>put testfilemert</strong><br />
putting file testfilemert as \testfilemert (0.0 kb/s) (average 0.0 kb/s)<br />
smb: \&gt; <strong>rm testfilemert</strong><br />
smb: \&gt;</td>
</tr>
</tbody>
</table>
<p>Great!! it has worked as well. POSIX access list is a great way when you have run out of tools in permission managament. It is by no means that involving SELinux also complicates things a bit. Fortunately there isn&#8217;t many booleans for SAMBA.</p>
<p>Please let me know if you have any questions in configuration or anything to add.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/selinux-and-samba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SELinux and BIND</title>
		<link>http://iptables.gen.tr/2010/01/selinux-and-bind/</link>
		<comments>http://iptables.gen.tr/2010/01/selinux-and-bind/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 22:38:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[selinux]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=67</guid>
		<description><![CDATA[When SELinux and BIND are together, there is not much to say as there are only two booleans that you can toggle as you can see below;



[root@rh54-2 named]# getsebool -a &#124; grep named
named_disable_trans &#8211;&#62; off
named_write_master_zones &#8211;&#62; off




When your booelans is like above and you want to use your BIND as a slave server, you will [...]]]></description>
			<content:encoded><![CDATA[<p>When SELinux and BIND are together, there is not much to say as there are only two booleans that you can toggle as you can see below;</p>
<table style="background-color: #87cefa; width: 553px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 named]# <strong>getsebool -a | grep named</strong><br />
named_disable_trans &#8211;&gt; off<br />
named_write_master_zones &#8211;&gt; off</td>
</tr>
</tbody>
</table>
<p><span id="more-67"></span></p>
<p>When your booelans is like above and you want to use your BIND as a slave server, you will get a SELinux blocking similar to below.</p>
<table style="background-color: #87cefa; width: 553px; height: 906px;" border="0">
<tbody>
<tr>
<td>[root@rh54-2 named]#<strong> sealert -l d157199a-1b33-41a6-bf77-3811bb492b84 </strong></p>
<p>Summary:</p>
<p>SELinux is preventing the named daemon from writing to the zone directory</p>
<p>Detailed Description:</p>
<p>SELinux has denied the named daemon from writing zone files. Ordinarily, named<br />
is not required to write to these files. Only secondary servers should be<br />
required to write to these directories. If this machine is not a secondary<br />
server, this could signal a intrusion attempt.</p>
<p>Allowing Access:</p>
<p>If you want named to run as a secondary server and accept zone transfers you<br />
need to turn on the named_write_master_zones boolean: &#8220;setsebool -P<br />
named_write_master_zones=1&#8243;</p>
<p>The following command will allow this access:</p>
<p>setsebool -P named_write_master_zones=1</p>
<p>Additional Information:</p>
<p>Source Context                root:system_r:named_t<br />
Target Context                system_u:object_r:named_zone_t<br />
Target Objects                ./named [ dir ]<br />
Source                        named<br />
Source Path                   /usr/sbin/named<br />
Port                          &lt;Unknown&gt;<br />
Host                          rh54-2.iptables.gen.tr<br />
Source RPM Packages           bind-9.3.6-4.P1.el5<br />
Target RPM Packages<br />
Policy RPM                    selinux-policy-2.4.6-255.el5<br />
Selinux Enabled               True<br />
Policy Type                   targeted<br />
MLS Enabled                   True<br />
Enforcing Mode                Enforcing<br />
Plugin Name                   named_write_master_zones<br />
Host Name                     rh54-2.iptables.gen.tr<br />
Platform                      Linux rh54-2.iptables.gen.tr 2.6.18-164.el5 #1 SMP Tue<br />
Aug 18 15:51:54 EDT 2009 i686 i686<br />
Alert Count                   2<br />
First Seen                    Tue Jan  5 06:08:58 2010<br />
Last Seen                     Tue Jan  5 06:08:59 2010<br />
Local ID                      d157199a-1b33-41a6-bf77-3811bb492b84<br />
Line Numbers</p>
<p>Raw Audit Messages</p>
<p>host=rh54-2.iptables.gen.tr type=AVC msg=audit(1262668139.6:51): avc:  denied  { write } for  pid=4299 comm=&#8221;named&#8221; name=&#8221;named&#8221; dev=dm-0 ino=195429 scontext=root:system_r:named_t:s0 tcontext=system_u:object_r:named_zone_t:s0 tclass=dir</p>
<p>host=rh54-2.iptables.gen.tr type=SYSCALL msg=audit(1262668139.6:51): arch=40000003 syscall=5 success=no exit=-13 a0=9448670 a1=c2 a2=1b6 a3=9448674 items=0 ppid=1 pid=4299 auid=0 uid=25 gid=25 euid=25 suid=25 fsuid=25 egid=25 sgid=25 fsgid=25 tty=(none) ses=6 comm=&#8221;named&#8221; exe=&#8221;/usr/sbin/named&#8221; subj=root:system_r:named_t:s0 key=(null)</td>
</tr>
</tbody>
</table>
<p>To get named update the zone files you have to toggle the boolean as below;</p>
<table style="background-color: #87cefa; width: 518px; height: 24px;" border="0">
<tbody>
<tr>
<td>setsebool -P named_write_master_zones=1</td>
</tr>
</tbody>
</table>
<p>Then your zone files will be written properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/selinux-and-bind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SELinux and Apache</title>
		<link>http://iptables.gen.tr/2010/01/selinux-and-network-services/</link>
		<comments>http://iptables.gen.tr/2010/01/selinux-and-network-services/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 19:54:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[selinux]]></category>

		<guid isPermaLink="false">http://iptables.gen.tr/?p=58</guid>
		<description><![CDATA[SELinux (Security Enhanced Linux) is something that some of us may be afraid of because once it is enabled network services start to behave abnormally. However once it is configured properly you can restrict processes and enforce their access to files and directories as you wish. In this article we will speak briefly about integration [...]]]></description>
			<content:encoded><![CDATA[<p>SELinux (Security Enhanced Linux) is something that some of us may be afraid of because once it is enabled network services start to behave abnormally. However once it is configured properly you can restrict processes and enforce their access to files and directories as you wish. In this article we will speak briefly about integration of SELinux with Apache.</p>
<p><span style="text-decoration: underline;"><strong>SELinux modes</strong></span></p>
<p>There three modes of SELinux</p>
<ul>
<li>Enforcing : You can restrict processes in this mode</li>
<li>Permissive : You can see what might happen in the logs if the mode was Enforcing instead of Permissive.</li>
<li>Disabled : Inactive state</li>
</ul>
<p>You can query the runtime mode with &#8220;getenforce&#8221;:</p>
<table style="background-color: #87cefa; width: 242px; height: 38px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 ~]# <strong>getenforce </strong><br />
<strong><span style="color: #ff0000;">Enforcing</span></strong></td>
</tr>
</tbody>
</table>
<p>or you can set the SELinux mode with &#8220;setenforce&#8221;:</p>
<table style="background-color: #87cefa; width: 243px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 ~]# <strong>setenforce 0</strong><br />
[root@rh54-3 ~]# <strong>getenforce </strong><br />
<span style="color: #ff0000;"><strong>Permissive</strong></span></td>
</tr>
</tbody>
</table>
<p><strong>Note: </strong>If you want to set the selinux mode to enforcing, you must reboot the server to relabel the filesystem. To have your changes to be persistent between reboots, set the SELinux mode in <strong>/etc/sysconfig/selinux</strong> file.</p>
<p>Redhat uses targeted policy by default which isn&#8217;t very strict and mainly service focused.</p>
<p><span id="more-58"></span></p>
<p><span style="text-decoration: underline;"><strong>Security Context</strong></span></p>
<p>When you label the file system some extra attributes are involved for each file, lets see them;</p>
<table style="background-color: #87cefa; width: 514px; height: 94px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 ~]# <strong>ls -Z</strong><br />
-rw&#8212;&#8212;-  root root system_u:object_r:user_home_t    anaconda-ks.cfg<br />
drwxr-xr-x  root root <strong>root:object_r:user_home_t</strong> Desktop<br />
-rw-r&#8211;r&#8211;  root root root:object_r:user_home_t        install.log<br />
-rw-r&#8211;r&#8211;  root root root:object_r:user_home_t        install.log.syslog</td>
</tr>
</tbody>
</table>
<p>&#8220;ls -Z&#8221; shows us the security context &#8220;root:object_r:user_home_t&#8221;  of our files.  As you can see security context has three elements which are  user,role and type in which we will be dealing with the type part mainly.</p>
<p>In targeted mode SELinux systems, not all services are SELinux protected. If you want to see whether a service is protected or not you can issue;</p>
<table style="background-color: #87cefa; width: 634px; height: 152px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 ~]# <strong>ps -ef<span style="color: #ff0000;">Z</span> |grep  httpd</strong><br />
system_u:system_r:httpd_t       root      3102     1  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:<strong><span style="color: #ff0000;">httpd_t </span></strong> apache    3127  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3128  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3129  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3130  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3131  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3132  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3133  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd<br />
system_u:system_r:httpd_t       apache    3134  3102  0 11:19 ?        00:00:00 /usr/sbin/httpd</td>
</tr>
</tbody>
</table>
<p>You can see that httpd has a context and type is httpd_t.</p>
<p><span style="text-decoration: underline;"><strong>Apache and SELinux</strong></span></p>
<p>We will go by an example. SELinux mode is enforcing and we want to provide virtualhost services. Lets do it;</p>
<p>We have the following VirtualHost configuration in apache</p>
<table style="background-color: #87cefa; width: 412px; height: 24px;" border="0">
<tbody>
<tr>
<td>NameVirtualHost 192.168.200.79:80<br />
#<br />
&lt;VirtualHost 192.168.200.79:80&gt;<br />
DocumentRoot /var/www/html<br />
ServerName rh54-3.iptables.gen.tr<br />
&lt;/VirtualHost&gt;</td>
</tr>
</tbody>
</table>
<p>Lets look at the security context of DocumentRoot</p>
<table style="background-color: #87cefa; width: 499px; height: 150px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 html]#<strong> ls -Z /var/www/</strong><br />
drwxr-xr-x  root      root system_u:object_r:httpd_sys_script_exec_t cgi-bin<br />
drwxr-xr-x  root      root system_u:object_r:httpd_sys_content_t error<br />
<strong>drwxr-xr-x  root      root system_u:object_r:httpd_sys_content_t html</strong><br />
drwxr-xr-x  root      root system_u:object_r:httpd_sys_content_t icons<br />
drwxr-xr-x  root      root system_u:object_r:httpd_sys_content_t manual<br />
drwxr-xr-x  webalizer root system_u:object_r:httpd_sys_content_t usage</td>
</tr>
</tbody>
</table>
<p>As you can see our type for this directory is httpd_sys_content_t. When you point your browser to http://rh54-3.iptables.gen.tr address you will see what is in that directory (e.g index.html)</p>
<p>What if we want to serve virtualhost in a different directory. What will happen?</p>
<table style="background-color: #87cefa; width: 487px; height: 24px;" border="0">
<tbody>
<tr>
<td>NameVirtualHost 192.168.200.79:80<br />
#<br />
&lt;VirtualHost 192.168.200.79:80&gt;<br />
DocumentRoot <strong>/web/docs</strong><br />
ServerName dummy-host.example.com<br />
&lt;/VirtualHost&gt;</td>
</tr>
</tbody>
</table>
<p>Once you reload the configuration, you will notice that you can&#8217;t display the content of this new directory i.e /web/docs but why?</p>
<p>Lets look at the security context</p>
<table style="background-color: #87cefa; width: 411px; height: 38px;" border="0">
<tbody>
<tr>
<td>root@rh54-3 www]# ls -Z /web<br />
drwxr-xr-x  root root root:object_r:<strong>default_t</strong> docs</td>
</tr>
</tbody>
</table>
<p>From the security context, we see that the type for this &#8220;docs&#8221; folder is default_t and the SELinux policy currently active in the system doesn&#8217;t allow to access httpd process with httpd_t type into &#8220;/web/docs&#8221; folder.  Ok ok, what this means or how we can see that SELinux is preventing access. If your setroubleshoot service is running on the system, you will see SELinux messages in your logs. For example when I try to access this new virtualhost, I have got the following message in my log;</p>
<table style="background-color: #87cefa; width: 666px; height: 52px;" border="0">
<tbody>
<tr>
<td>Jan  5 15:02:18 rh54-3 setroubleshoot: SELinux is preventing access to files with the default label, default_t. For complete SELinux messages. run <strong>sealert -l 188d441e-0307-495b-a6cc-b7915fa408e3</strong></td>
</tr>
</tbody>
</table>
<p>If you run the command log entry suggests, you will have the following output.</p>
<table style="background-color: #87cefa; width: 671px; height: 24px;" border="0">
<tbody>
<tr>
<td>[root@rh54-3 www]#<strong> sealert -l 188d441e-0307-495b-a6cc-b7915fa408e3</strong></p>
<p>Summary:</p>
<p>SELinux is preventing access to files with the default label, default_t.</p>
<p>Detailed Description:</p>
<p>[SELinux is in permissive mode, the operation would have been denied but was<br />
permitted due to permissive mode.]</p>
<p>SELinux permission checks on files labeled default_t are being denied. These<br />
files/directories have the default label on them. This can indicate a labeling<br />
problem, especially if the files being referred to are not top level<br />
directories. Any files/directories under standard system directories, /usr,<br />
/var. /dev, /tmp, &#8230;, should not be labeled with the default label. The default<br />
label is for files/directories which do not have a label on a parent directory.<br />
So if you create a new directory in / you might legitimately get this label.</p>
<p>Allowing Access:</p>
<p>If you want a confined domain to use these files you will probably need to<br />
relabel the file/directory with chcon. In some cases it is just easier to<br />
relabel the system, to relabel execute: &#8220;touch /.autorelabel; reboot&#8221;</p>
<p>Additional Information:</p>
<p>Source Context                <strong>root:system_r:httpd_t</strong><br />
Target Context                <strong>root:object_r:default_t</strong><br />
Target Objects                ./web [ dir ]<br />
Source                        httpd<br />
Source Path                   /usr/sbin/httpd<br />
Port                          &lt;Unknown&gt;<br />
Host                          rh54-3.iptables.gen.tr<br />
Source RPM Packages           httpd-2.2.3-31.el5<br />
Target RPM Packages<br />
Policy RPM                    selinux-policy-2.4.6-255.el5<br />
Selinux Enabled               True<br />
Policy Type                   targeted<br />
MLS Enabled                   True<br />
Enforcing Mode                Permissive<br />
Plugin Name                   default<br />
Host Name                     rh54-3.iptables.gen.tr<br />
Platform                      Linux rh54-3.iptables.gen.tr 2.6.18-164.el5 #1 SMP Tue<br />
Aug 18 15:51:54 EDT 2009 i686 i686<br />
Alert Count                   1<br />
First Seen                    Tue Jan  5 15:02:17 2010<br />
Last Seen                     Tue Jan  5 15:02:17 2010<br />
Local ID                      188d441e-0307-495b-a6cc-b7915fa408e3<br />
Line Numbers</p>
<p>Raw Audit Messages</p>
<p>host=rh54-3.iptables.gen.tr type=AVC msg=audit(1262700137.792:35): avc:  denied  { search } for  pid=3508 comm=&#8221;httpd&#8221; name=&#8221;web&#8221; dev=dm-0 ino=65568 scontext=root:system_r:httpd_t:s0 tcontext=root:object_r:default_t:s0 tclass=dir</p>
<p>host=rh54-3.iptables.gen.tr type=AVC msg=audit(1262700137.792:35): avc:  denied  { getattr } for  pid=3508 comm=&#8221;httpd&#8221; path=&#8221;/web/docs&#8221; dev=dm-0 ino=65569 scontext=root:system_r:httpd_t:s0 tcontext=root:object_r:default_t:s0 tclass=dir</p>
<p>host=rh54-3.iptables.gen.tr type=SYSCALL msg=audit(1262700137.792:35): arch=40000003 syscall=195 success=yes exit=0 a0=917c4b0 a1=bfbb510c a2=631ff4 a3=8000 items=0 ppid=3507 pid=3508 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=2 comm=&#8221;httpd&#8221; exe=&#8221;/usr/sbin/httpd&#8221; subj=root:system_r:httpd_t:s0 key=(null)</td>
</tr>
</tbody>
</table>
<p>It tells us that something is wrong:) as we are trying to access directory that we aren&#8217;t allowed to. To solve this issue, we can change the context of the destination directory.</p>
<table style="background-color: #87cefa; width: 406px; height: 24px;" border="0">
<tbody>
<tr>
<td>chcon -R -t httpd_sys_content_t /web/</td>
</tr>
</tbody>
</table>
<p>or you could have just copied the type from a known object into this one with;</p>
<table style="background-color: #87cefa; width: 408px; height: 24px;" border="0">
<tbody>
<tr>
<td>chcon -R &#8211;reference /var/www/html/ /web/</td>
</tr>
</tbody>
</table>
<p>Once you issue this command, all directories under this directory will be within httpd_sys_content_t which will allow httpd process to access because policy says so:)</p>
<p>However, if the filesystem is relabeled somehow, you will lose this labeling. If you want your change to survive during relabeling of the filesystems, then add this into the policy as follows;</p>
<table style="background-color: #87cefa; width: 444px; height: 24px;" border="0">
<tbody>
<tr>
<td>semanage fcontext -a -t httpd_sys_content_t &#8220;/web(/.*)?&#8221;</td>
</tr>
</tbody>
</table>
<p>However in the end, you didn&#8217;t like SELinux at all but you only want to disable SELinux for httpd. With the following command you can do this;</p>
<table style="background-color: #87cefa; width: 372px; height: 24px;" border="0">
<tbody>
<tr>
<td>setsebool -P httpd_disable_trans 1</td>
</tr>
</tbody>
</table>
<p>I have tried to talk about SELinux briefly. Main focus was apache but I will try to involve ftp,samba and NFS soon.</p>
<p>Please drop your comments if you have anything to add or any correction.</p>
]]></content:encoded>
			<wfw:commentRss>http://iptables.gen.tr/2010/01/selinux-and-network-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
