{"id":591,"date":"2014-10-15T14:49:25","date_gmt":"2014-10-15T14:49:25","guid":{"rendered":"http:\/\/www.selinuxplus.com\/?p=591"},"modified":"2014-10-15T14:51:21","modified_gmt":"2014-10-15T14:51:21","slug":"linux-%e7%b3%bb%e7%bb%9f%e7%ae%a1%e7%90%86el7-selinux%e7%af%87","status":"publish","type":"post","link":"http:\/\/www.selinuxplus.com\/?p=591","title":{"rendered":"Linux \u7cfb\u7edf\u7ba1\u7406(EL7)-SELinux\u7bc7"},"content":{"rendered":"<h1>1\u00a0\u00a0\u6982\u8ff0<\/h1>\n<h2>1.1\u00a0\u529f\u80fd\u4ecb\u7ecd<\/h2>\n<p>SELinux \u662f 2.6 \u7248\u672c\u7684 Linux \u5185\u6838\u4e2d\u63d0\u4f9b\u7684\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236(MAC\uff09\u7cfb\u7edf\u3002\u5bf9\u4e8e\u76ee\u524d\u53ef\u7528\u7684 Linux\u5b89\u5168\u6a21\u5757\u6765\u8bf4\uff0cSELinux \u662f\u529f\u80fd\u6700\u5168\u9762\uff0c\u800c\u4e14\u6d4b\u8bd5\u6700\u5145\u5206\u7684\uff0c\u5b83\u662f\u5728 20 \u5e74\u7684 MAC \u7814\u7a76\u57fa\u7840\u4e0a\u5efa\u7acb\u7684\u3002SELinux \u5728\u7c7b\u578b\u5f3a\u5236\u670d\u52a1\u5668\u4e2d\u5408\u5e76\u4e86\u591a\u7ea7\u5b89\u5168\u6027\u6216\u4e00\u79cd\u53ef\u9009\u7684\u591a\u7c7b\u7b56\u7565\uff0c\u5e76\u91c7\u7528\u4e86\u57fa\u4e8e\u89d2\u8272\u7684\u8bbf\u95ee\u63a7\u5236\u6982\u5ff5\u3002[1]<\/p>\n<p>\u5927\u90e8\u5206\u4f7f\u7528 SELinux \u7684\u4eba\u4f7f\u7528\u7684\u90fd\u662f SELinux \u5c31\u7eea\u7684\u53d1\u884c\u7248\uff0c\u4f8b\u5982 Fedora\u3001Red Hat Enterprise Linux (RHEL\uff09\u3001Debian\u6216 Centos\u3002\u5b83\u4eec\u90fd\u662f\u5728\u5185\u6838\u4e2d\u542f\u7528 SELinux \u7684\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e00\u4e2a\u53ef\u5b9a\u5236\u7684\u5b89\u5168\u7b56\u7565\uff0c\u8fd8\u63d0\u4f9b\u5f88\u591a\u7528\u6237\u5c42\u7684\u5e93\u548c\u5de5\u5177\uff0c\u5b83\u4eec\u90fd\u53ef\u4ee5\u4f7f\u7528 SELinux \u7684\u529f\u80fd\u3002<\/p>\n<p>SELinux\u662f\u4e00\u79cd\u57fa\u4e8e \u57df-\u7c7b\u578b \u6a21\u578b\uff08domain-type\uff09\u7684\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\uff08MAC\uff09\u5b89\u5168\u7cfb\u7edf\uff0c\u5b83\u7531NSA\u7f16\u5199\u5e76\u8bbe\u8ba1\u6210\u5185\u6838\u6a21\u5757\u5305\u542b\u5230\u5185\u6838\u4e2d\uff0c\u76f8\u5e94\u7684\u67d0\u4e9b\u5b89\u5168\u76f8\u5173\u7684\u5e94\u7528\u4e5f\u88ab\u6253\u4e86SELinux\u7684\u8865\u4e01\uff0c\u6700\u540e\u8fd8\u6709\u4e00\u4e2a\u76f8\u5e94\u7684\u5b89\u5168\u7b56\u7565\u3002<\/p>\n<p>\u4f17\u6240\u5468\u77e5\uff0c\u6807\u51c6\u7684UN\u2168\u5b89\u5168\u6a21\u578b\u662f&#8221;\u4efb\u610f\u7684\u8bbf\u95ee\u63a7\u5236&#8221;DAC\u3002\u5c31\u662f\u8bf4\uff0c\u4efb\u4f55\u7a0b\u5e8f\u5bf9\u5176\u8d44\u6e90\u4eab\u6709\u5b8c\u5168\u7684\u63a7\u5236\u6743\u3002\u5047\u8bbe\u67d0\u4e2a\u7a0b\u5e8f\u6253\u7b97\u628a\u542b\u6709\u6f5c\u5728\u91cd\u8981\u4fe1\u606f\u7684\u6587\u4ef6\u6254\u5230\/tmp\u76ee\u5f55\u4e0b\uff0c\u90a3\u4e48\u5728DAC\u60c5\u51b5\u4e0b\u6ca1\u4eba\u80fd\u963b\u6b62\u4ed6\uff01<\/p>\n<p>\u800cMAC\u60c5\u51b5\u4e0b\u7684\u5b89\u5168\u7b56\u7565\u5b8c\u5168\u63a7\u5236\u7740\u5bf9\u6240\u6709\u8d44\u6e90\u7684\u8bbf\u95ee\u3002\u8fd9\u662fMAC\u548cDAC\u672c\u8d28\u7684\u533a\u522b\u3002<\/p>\n<p>SELinux\u63d0\u4f9b\u4e86\u6bd4\u4f20\u7edf\u7684UN\u2168\u6743\u9650\u66f4\u597d\u7684\u8bbf\u95ee\u63a7\u5236\u3002\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u5b98\u7f51\u5730\u5740\uff1ahttp:\/\/selinuxproject.org\/page\/Main_Page<\/pre>\n<h2>1.2\u00a0\u5de5\u7a0b\u4f9d\u8d56<\/h2>\n<p>\u5de5\u7a0b\u6e90\u4ed3\u5e93\u642d\u5efa<\/p>\n<h1>2\u00a0\u73af\u5883\u642d\u5efa<\/h1>\n<h2>2.1\u73af\u5883\u8981\u6c42<\/h2>\n<pre class=\"lang:default decode:true\">\u57fa\u7840\u7cfb\u7edf EL7\uff0cor selinuxplus Cloud \r\n\u8f6f\u4ef6\u5305 selinux-policy selinux-policy-targeted<\/pre>\n<h2>2.2 \u73af\u5883\u642d\u5efa<\/h2>\n<p>1 \u5b89\u88c5\u8f6f\u4ef6<\/p>\n<pre class=\"lang:default decode:true\">Yum install selinux-policy-devel<\/pre>\n<p>2 \u89e3\u538b\u7b56\u7565\u5305\uff0c\u914d\u7f6e\u6587\u4ef6\u76ee\u5f55<\/p>\n<pre class=\"lang:default decode:true\">selinux-policy\/SOURCES\/serefpolicy-3.12.1\/policy\/modules\/<\/pre>\n<p>3 \u4ee5getty\u4e3a\u4f8b<\/p>\n<pre class=\"lang:default decode:true \" >[root@localhost system]# ls getty.*\r\ngetty.fc\u00a0 getty.if\u00a0 getty.te<\/pre>\n<p>4 \u6839\u636eaudit2allow \u5de5\u5177\u67e5\u627eavc\u7684deny\u4fe1\u606f \uff0c\u5e76\u4fee\u6539\u6587\u4ef6<\/p>\n<pre class=\"lang:default decode:true\">\u00a0#################################################\r\n# selinuxplus add here for  ...\r\n#\r\ngen_require(`\r\ntype chkpwd_exec_t;\r\ntype init_exec_t;\r\ntype unreserved_port_t;\r\ntype admin_home_t;\r\ntype dmidecode_exec_t;\r\ntype memory_device_t;\r\ntype ssh_keygen_exec_t;\r\ntype sshd_key_t;\r\ntype urandom_device_t;\r\ntype getty_etc_t;\r\ntype init_t;\r\ntype init_var_run_t;\r\ntype power_unit_file_t;\r\ntype systemd_passwd_agent_exec_t;\r\ntype systemd_passwd_var_run_t;\r\ntype systemd_systemctl_exec_t;\r\nclass lnk_file read;\r\n')\r\nallow getty_t chkpwd_exec_t:file execute;\r\nallow getty_t init_exec_t:file getattr;\r\nallow getty_t self:capability setuid;\r\nallow getty_t unreserved_port_t:tcp_socket name_connect;\r\nallow getty_t admin_home_t:file { read open };\r\nallow getty_t dmidecode_exec_t:file { read getattr open execute execute_no_trans };\r\nallow getty_t memory_device_t:chr_file { read open };\r\nallow getty_t self:capability sys_rawio;\r\nallow getty_t ssh_keygen_exec_t:file { read execute open execute_no_trans };\r\nallow getty_t sshd_key_t:file { read getattr open };\r\nallow getty_t urandom_device_t:chr_file { read getattr open };\r\nallow getty_t admin_home_t:dir write;\r\nallow getty_t getty_etc_t:dir { write create add_name };\r\nallow getty_t getty_etc_t:file { write create };<\/pre>\n<h2>2.3\u751f\u6210\u4e8c\u8fdb\u5236\u7b56\u7565<\/h2>\n<p>\u4f7f\u7528\u5de5\u5177\u751f\u4ea7\u4e8c\u8fdb\u5236\u7b56\u7565\uff1a<\/p>\n<pre class=\"lang:default decode:true\">make -f \/usr\/share\/selinux\/devel\/Makefile\u00a0 getty.pp<\/pre>\n<h2>2.4 \u5de5\u7a0b\u8c03\u8bd5<\/h2>\n<p>\u4f7f\u7528semodule\u5de5\u5177\u6d4b\u8bd5<\/p>\n<pre class=\"lang:default decode:true\">semodule \u2013I getty.pp<\/pre>\n<p>\u5f00\u542fselinux\u4e3apermission\u72b6\u6001\uff0c\u5e76\u6839\u636eaudit\u7684\u65e5\u5fd7\u8fdb\u884c\u5b9a\u4f4d\u5206\u6790\uff0c\u5982\u6709\u963b\u6b62\u7b56\u7565\u518d\u6b21\u8fdb\u884c\u6dfb\u52a0\u548c\u751f\u6210\u6d4b\u8bd5\u5de5\u4f5c\u3002<\/p>\n<h2>2.5 \u5176\u4ed6\u4e8b\u9879<\/h2>\n<p>1\u3001\u00a0\u00a0\u00a0 avc\u7684\u4fe1\u606f\u8981\u5168\u5c40\u5206\u6790<br \/>\n2\u3001\u00a0\u00a0\u00a0 \u591a\u6b21\u6d4b\u8bd5\u548c\u91cd\u542f\u673a\u5668\u6d4b\u8bd5\uff0c\u5982\u6709socket\u901a\u4fe1\uff0c\u8981\u8fdb\u884c\u901a\u4fe1\u6d4b\u8bd5\u3002<br \/>\n3\u3001\u00a0\u00a0\u00a0 \u4e00\u4e9b\u89c4\u5219\u6ca1\u6709\u88ab\u5ba1\u8ba1\u51fa\u6765\uff0c\u4f46\u4e00\u6837denial\u4e86\u7a0b\u5e8f\u7684\u8fd0\u884c\uff0c\u9700\u8981\u4f7f\u7528semoudle \u2013DB \u5c06\u90a3\u4e9bdontaudit\u7684\u6d4b\u8bd5\u53bb\u9664\u3002-D \u8868\u793a\u6784\u5efa\u5ba1\u8ba1dontaudit\u7684\u89c4\u5219\uff0c-B\u8868\u793a\u91cd\u65b0rebuild\u3002<br \/>\nYou can build the policy configuration with the &#8220;dontaudit&#8221; rules removed by running &#8220;semodule -DB&#8221;. This will expose any hidden denials. To build the policy configuration with the &#8220;dontaudit&#8221; rules re-insterted run &#8220;semodule -B&#8221;<\/p>\n<h2>2.6 \u5176\u4ed6<\/h2>\n<p>\u63cf\u8ff0\u9879\u76ee\u7814\u5236\u8fc7\u7a0b\u4e2d\u5c06\u91c7\u7528\u7684\u5176\u4ed6\u65b9\u9762\u7684\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u00a0\u00a0\u6982\u8ff0 1.1\u00a0\u529f\u80fd\u4ecb\u7ecd SELinux \u662f &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,5],"tags":[127,124,106,179,126],"_links":{"self":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/591"}],"collection":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=591"}],"version-history":[{"count":2,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/591\/revisions"}],"predecessor-version":[{"id":593,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=\/wp\/v2\/posts\/591\/revisions\/593"}],"wp:attachment":[{"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=591"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.selinuxplus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}