{"id":117136,"date":"2026-10-22T17:40:42","date_gmt":"2026-10-22T09:40:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117136.html"},"modified":"2026-10-22T17:40:42","modified_gmt":"2026-10-22T09:40:42","slug":"selinux%e4%b8%8eapparmor%e5%85%a5%e9%97%a8%ef%bc%9a%e5%bc%ba%e5%88%b6%e8%ae%bf%e9%97%ae%e6%8e%a7%e5%88%b6%e9%85%8d%e7%bd%ae%e4%b8%8e%e6%8e%92%e9%94%99","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117136.html","title":{"rendered":"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519"},"content":{"rendered":"<p>\u300c\u670d\u52a1\u6539\u4e86\u914d\u7f6e\u5c31\u662f\u8d77\u4e0d\u6765&#xff0c;\u65e5\u5fd7\u4e5f\u6ca1\u62a5\u9519\u300d\u300c\u660e\u660e\u7ed9\u4e86 777 \u6743\u9650\u8fd8\u662f\u62d2\u7edd\u8bbf\u95ee\u300d\u2014\u2014\u5f88\u591a\u4eba\u88ab\u8fd9\u7c7b\u8be1\u5f02\u95ee\u9898\u5751\u8fc7&#xff0c;\u6700\u540e\u53d1\u73b0\u662f SELinux \u6216 AppArmor \u5728\u300c\u591a\u7ba1\u95f2\u4e8b\u300d\u3002\u5b83\u4eec\u662f Linux \u7684**\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236&#xff08;MAC&#xff09;**\u673a\u5236&#xff0c;\u6bd4\u4f20\u7edf\u7684\u6587\u4ef6\u6743\u9650\u66f4\u5e95\u5c42\u3001\u66f4\u4e25\u683c\u3002\u8fd9\u4e00\u7bc7\u8bb2\u6e05 SELinux \u548c AppArmor \u7684\u539f\u7406\u3001\u914d\u7f6e\u548c\u6392\u9519\u65b9\u6cd5&#xff0c;\u8ba9\u4f60\u4e0d\u518d\u628a\u300c\u5173\u6389\u5b83\u300d\u5f53\u6210\u552f\u4e00\u89e3\u6cd5\u3002<\/p>\n<h3>\u4e00\u3001\u4ec0\u4e48\u662f\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236<\/h3>\n<p>\u4f20\u7edf\u7684 Linux \u6743\u9650&#xff08;rwx\u3001owner\/group\/other&#xff09;\u53eb DAC&#xff08;\u81ea\u4e3b\u8bbf\u95ee\u63a7\u5236&#xff09;&#xff1a;\u6587\u4ef6\u5c5e\u4e3b\u53ef\u4ee5\u968f\u610f\u51b3\u5b9a\u8c01\u80fd\u8bbf\u95ee\u3002\u95ee\u9898\u5728\u4e8e\u2014\u2014\u5982\u679c\u67d0\u4e2a\u8fdb\u7a0b\u4ee5 root \u8fd0\u884c&#xff0c;\u5b83\u5c31\u80fd\u8bbf\u95ee\u4efb\u4f55\u6587\u4ef6&#xff0c;\u4e00\u65e6\u88ab\u653b\u7834&#xff0c;\u5371\u5bb3\u5de8\u5927\u3002<\/p>\n<p>MAC&#xff08;\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236&#xff09; \u5728 DAC \u4e4b\u4e0a\u518d\u52a0\u4e00\u5c42&#xff1a;\u7531\u7cfb\u7edf\u7b56\u7565\u7edf\u4e00\u51b3\u5b9a&#xff0c;\u8fdb\u7a0b\u80fd\u8bbf\u95ee\u54ea\u4e9b\u8d44\u6e90&#xff0c;\u8fde root \u4e5f\u8981\u9075\u5b88\u3002\u5b83\u5c31\u662f\u300c\u7eb5\u6df1\u9632\u5fa1\u300d\u91cc\u7684\u7b2c 4 \u5c42&#xff08;\u89c1\u7b2c 79 \u7bc7&#xff09;\u3002<\/p>\n<table>\n<tr>\u7ef4\u5ea6DAC&#xff08;\u4f20\u7edf\u6743\u9650&#xff09;MAC&#xff08;SELinux\/AppArmor&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>\u51b3\u5b9a\u8005<\/td>\n<td>\u6587\u4ef6\u5c5e\u4e3b<\/td>\n<td>\u7cfb\u7edf\u7b56\u7565<\/td>\n<\/tr>\n<tr>\n<td>root \u80fd\u5426\u7ed5\u8fc7<\/td>\n<td>\u80fd<\/td>\n<td>\u4e0d\u80fd<\/td>\n<\/tr>\n<tr>\n<td>\u7c92\u5ea6<\/td>\n<td>\u7528\u6237\/\u7ec4\/\u5176\u4ed6<\/td>\n<td>\u8fdb\u7a0b\/\u8def\u5f84\/\u6807\u7b7e<\/td>\n<\/tr>\n<tr>\n<td>\u76ee\u7684<\/td>\n<td>\u57fa\u672c\u7684\u8bbf\u95ee\u63a7\u5236<\/td>\n<td>\u9650\u5236\u8fdb\u7a0b\u80fd\u529b&#xff0c;\u9632\u63d0\u6743<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4e8c\u3001\u4e24\u5927\u6d41\u6d3e<\/h3>\n<p>MAC \u5b9e\u73b0<br \/>\n \u251c\u2500 SELinux&#xff08;\u7ea2\u5e3d\u7cfb&#xff1a;RHEL\/CentOS\/Rocky\/Fedora&#xff09;\u2014\u2014 \u57fa\u4e8e\u300c\u6807\u7b7e\u300d<br \/>\n \u2514\u2500 AppArmor&#xff08;Debian \u7cfb&#xff1a;Ubuntu\/Debian\/SUSE&#xff09;\u2014\u2014 \u57fa\u4e8e\u300c\u8def\u5f84\u300d<\/p>\n<table>\n<tr>\u7ef4\u5ea6SELinuxAppArmor<\/tr>\n<tbody>\n<tr>\n<td>\u53d1\u884c\u7248<\/td>\n<td>RHEL\/CentOS\/Rocky<\/td>\n<td>Ubuntu\/Debian<\/td>\n<\/tr>\n<tr>\n<td>\u6a21\u578b<\/td>\n<td>\u6807\u7b7e&#xff08;label\/context&#xff09;<\/td>\n<td>\u8def\u5f84&#xff08;path&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u914d\u7f6e<\/td>\n<td>\u590d\u6742&#xff0c;\u7b56\u7565\u8bed\u8a00<\/td>\n<td>\u7b80\u5355&#xff0c;\u53ef\u8bfb\u6587\u672c<\/td>\n<\/tr>\n<tr>\n<td>\u5b66\u4e60\u66f2\u7ebf<\/td>\n<td>\u9661<\/td>\n<td>\u7f13<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5148\u786e\u8ba4\u4f60\u7684\u7cfb\u7edf\u7528\u54ea\u4e2a&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u770b SELinux<\/span><br \/>\ngetenforce<br \/>\n<span class=\"token comment\"># \u770b AppArmor<\/span><br \/>\naa-status<\/p>\n<h3>\u4e09\u3001SELinux \u57fa\u7840<\/h3>\n<h4>\u4e09\u79cd\u6a21\u5f0f<\/h4>\n<p>getenforce<\/p>\n<table>\n<tr>\u6a21\u5f0f\u884c\u4e3a<\/tr>\n<tbody>\n<tr>\n<td>Enforcing<\/td>\n<td>\u5f3a\u5236\u6267\u884c\u7b56\u7565&#xff0c;\u8fdd\u89c4\u88ab\u62d2\u7edd<\/td>\n<\/tr>\n<tr>\n<td>Permissive<\/td>\n<td>\u53ea\u8bb0\u5f55\u4e0d\u963b\u6b62&#xff08;\u6392\u9519\u65f6\u7528&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Disabled<\/td>\n<td>\u5b8c\u5168\u5173\u95ed<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e34\u65f6\u5207\u6362&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> setenforce <span class=\"token number\">0<\/span>     <span class=\"token comment\"># \u6539 Permissive<\/span><br \/>\n<span class=\"token function\">sudo<\/span> setenforce <span class=\"token number\">1<\/span>     <span class=\"token comment\"># \u6539 Enforcing<\/span><\/p>\n<p>\u914d\u7f6e\u6587\u4ef6 \/etc\/selinux\/config&#xff08;\u6c38\u4e45&#xff0c;\u9700\u91cd\u542f&#xff09;&#xff1a;<\/p>\n<p>SELINUX&#061;enforcing<br \/>\nSELINUXTYPE&#061;targeted<\/p>\n<h4>\u26a0\ufe0f \u6392\u9519\u9ec4\u91d1\u6d41\u7a0b<\/h4>\n<p>\u670d\u52a1\u62a5\u300cPermission denied\u300d\u65f6&#xff0c;\u5148\u522b\u6025\u7740\u5173 SELinux&#xff0c;\u6539\u7528 Permissive \u6a21\u5f0f\u6d4b\u8bd5&#xff1a;<\/p>\n<p><span class=\"token comment\"># 1. \u5207\u6362 Permissive<\/span><br \/>\n<span class=\"token function\">sudo<\/span> setenforce <span class=\"token number\">0<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u91cd\u542f\u670d\u52a1&#xff0c;\u5982\u679c\u597d\u4e86 \u2192 \u662f SELinux \u95ee\u9898<\/span><br \/>\n<span class=\"token function\">sudo<\/span> systemctl restart myservice<\/p>\n<p><span class=\"token comment\"># 3. \u5207\u56de Enforcing&#xff0c;\u67e5\u770b\u62d2\u7edd\u65e5\u5fd7\u627e\u771f\u56e0<\/span><br \/>\n<span class=\"token function\">sudo<\/span> setenforce <span class=\"token number\">1<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ausearch <span class=\"token parameter variable\">-m<\/span> avc <span class=\"token parameter variable\">-ts<\/span> recent<\/p>\n<p>\u8bb0\u4f4f&#xff1a;Permissive \u662f\u300c\u6392\u9519\u5de5\u5177\u300d&#xff0c;\u4e0d\u662f\u300c\u89e3\u51b3\u65b9\u6848\u300d\u3002 \u627e\u5230\u771f\u56e0\u540e\u8981\u4e48\u8c03\u4e0a\u4e0b\u6587\u3001\u8981\u4e48\u5f00\u5e03\u5c14\u503c\u3001\u8981\u4e48\u5199\u7b56\u7565&#xff0c;\u800c\u4e0d\u662f\u6c38\u4e45\u7981\u7528\u3002<\/p>\n<h4>\u67e5\u770b\u62d2\u7edd\u65e5\u5fd7<\/h4>\n<p><span class=\"token comment\"># \u770b AVC \u62d2\u7edd\u8bb0\u5f55<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ausearch <span class=\"token parameter variable\">-m<\/span> avc <span class=\"token parameter variable\">-ts<\/span> recent<br \/>\n<span class=\"token function\">sudo<\/span> journalctl <span class=\"token parameter variable\">-t<\/span> audit <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> AVC<\/p>\n<p><span class=\"token comment\"># \u7528 sealert \u5f97\u5230\u4eba\u7c7b\u53ef\u8bfb\u7684\u5efa\u8bae<\/span><br \/>\n<span class=\"token function\">sudo<\/span> dnf <span class=\"token function\">install<\/span> setroubleshoot-server <span class=\"token parameter variable\">-y<\/span><br \/>\n<span class=\"token function\">sudo<\/span> sealert <span class=\"token parameter variable\">-a<\/span> \/var\/log\/audit\/audit.log<\/p>\n<p>AVC denied \u5c31\u662f\u300cSELinux \u62d2\u7edd\u4e86\u67d0\u64cd\u4f5c\u300d&#xff0c;\u65e5\u5fd7\u91cc\u4f1a\u5199\u6e05\u695a\u300c\u54ea\u4e2a\u8fdb\u7a0b\u3001\u5bf9\u54ea\u4e2a\u8d44\u6e90\u3001\u505a\u4e86\u4ec0\u4e48\u64cd\u4f5c\u300d\u4ee5\u53ca\u4fee\u590d\u5efa\u8bae\u3002<\/p>\n<h3>\u56db\u3001SELinux \u4e0a\u4e0b\u6587\u4e0e\u5e03\u5c14\u503c<\/h3>\n<p>SELinux \u7684\u6838\u5fc3\u662f\u6807\u7b7e&#xff08;context&#xff09;\u3002\u6bcf\u4e2a\u8fdb\u7a0b\u548c\u6587\u4ef6\u90fd\u5e26\u4e00\u4e2a\u5b89\u5168\u4e0a\u4e0b\u6587&#xff0c;\u683c\u5f0f&#xff1a;<\/p>\n<p>user:role:type:level<br \/>\nsystem_u:object_r:httpd_sys_content_t:s0<\/p>\n<p>\u6392\u969c\u6700\u5173\u6ce8\u7684\u662f type \u5b57\u6bb5&#xff08;\u7b2c\u4e09\u4e2a&#xff09;\u3002<\/p>\n<h4>\u67e5\u770b\u4e0a\u4e0b\u6587<\/h4>\n<p><span class=\"token comment\"># \u6587\u4ef6\u4e0a\u4e0b\u6587<\/span><br \/>\n<span class=\"token function\">ls<\/span> <span class=\"token parameter variable\">-Z<\/span> \/var\/www\/html\/index.html<br \/>\n<span class=\"token comment\"># system_u:object_r:httpd_sys_content_t:s0 &#8230;<\/span><\/p>\n<p><span class=\"token comment\"># \u8fdb\u7a0b\u4e0a\u4e0b\u6587<\/span><br \/>\n<span class=\"token function\">ps<\/span> <span class=\"token parameter variable\">-eZ<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> nginx<br \/>\n<span class=\"token comment\"># system_u:system_r:httpd_t:s0  nginx<\/span><\/p>\n<p>\u89c4\u5219&#xff1a;\u8fdb\u7a0b\u7684 type&#xff08;\u5982 httpd_t&#xff09;\u5fc5\u987b\u80fd\u8bbf\u95ee\u6587\u4ef6\u7684 type&#xff08;\u5982 httpd_sys_content_t&#xff09;&#xff0c;\u5426\u5219\u88ab\u62d2\u3002<\/p>\n<h4>\u4fee\u6539\u6587\u4ef6\u4e0a\u4e0b\u6587<\/h4>\n<p>\u573a\u666f&#xff1a; \u628a\u7f51\u7ad9\u6587\u4ef6\u653e\u5230 \/web\/ \u800c\u4e0d\u662f\u9ed8\u8ba4\u7684 \/var\/www\/html\/&#xff0c;nginx \u8bbf\u95ee\u88ab\u62d2\u3002<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b\u5e94\u8be5\u7528\u4ec0\u4e48\u4e0a\u4e0b\u6587<\/span><br \/>\nsemanage fcontext <span class=\"token parameter variable\">-l<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> httpd_sys_content<\/p>\n<p><span class=\"token comment\"># \u628a \/web \u76ee\u5f55\u6807\u8bb0\u4e3a web \u5185\u5bb9\u7c7b\u578b<\/span><br \/>\n<span class=\"token function\">sudo<\/span> semanage fcontext <span class=\"token parameter variable\">-a<\/span> <span class=\"token parameter variable\">-t<\/span> httpd_sys_content_t <span class=\"token string\">&#034;\/web(\/.*)?&#034;<\/span><br \/>\n<span class=\"token comment\"># \u5e94\u7528\u89c4\u5219\u5230\u5b9e\u9645\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">sudo<\/span> restorecon <span class=\"token parameter variable\">-Rv<\/span> \/web<\/p>\n<p>\u5173\u952e\u70b9&#xff1a; semanage fcontext \u662f\u6301\u4e45\u89c4\u5219&#xff0c;restorecon \u628a\u89c4\u5219\u5e94\u7528\u5230\u73b0\u6709\u6587\u4ef6\u3002\u53ea\u505a\u524d\u8005\u4e0d\u751f\u6548&#xff0c;\u53ea\u505a\u540e\u8005\u91cd\u542f\u53ef\u80fd\u4e22&#xff0c;\u4e24\u8005\u90fd\u8981\u3002<\/p>\n<h4>\u5e03\u5c14\u503c&#xff08;boolean&#xff09;&#xff1a;\u5f00\u5173\u5f0f\u7b56\u7565<\/h4>\n<p>SELinux \u6709\u4e00\u4e9b\u300c\u5373\u5f00\u5373\u7528\u300d\u7684\u5f00\u5173&#xff0c;\u5bf9\u5e94\u5e38\u89c1\u9700\u6c42&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5217\u51fa\u6240\u6709\u5e03\u5c14\u503c<\/span><br \/>\ngetsebool <span class=\"token parameter variable\">-a<\/span><\/p>\n<p><span class=\"token comment\"># \u67e5\u770b web \u76f8\u5173<\/span><br \/>\ngetsebool <span class=\"token parameter variable\">-a<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> httpd<\/p>\n<p><span class=\"token comment\"># \u5f00\u542f\u300c\u5141\u8bb8 httpd \u8fde\u63a5\u7f51\u7edc\u300d<\/span><br \/>\n<span class=\"token function\">sudo<\/span> setsebool <span class=\"token parameter variable\">-P<\/span> httpd_can_network_connect on<\/p>\n<p>-P \u8868\u793a\u6301\u4e45\u5316&#xff08;\u91cd\u542f\u540e\u4ecd\u751f\u6548&#xff09;\u3002<\/p>\n<p>\u5178\u578b\u573a\u666f&#xff1a;<\/p>\n<table>\n<tr>\u9700\u6c42\u5e03\u5c14\u503c<\/tr>\n<tbody>\n<tr>\n<td>web \u670d\u52a1\u8fde\u6570\u636e\u5e93<\/td>\n<td>httpd_can_network_connect_db on<\/td>\n<\/tr>\n<tr>\n<td>web \u670d\u52a1\u8bbf\u95ee\u5916\u7f51<\/td>\n<td>httpd_can_network_connect on<\/td>\n<\/tr>\n<tr>\n<td>ftp \u8bfb\u5199\u5bb6\u76ee\u5f55<\/td>\n<td>ftp_home_dir on<\/td>\n<\/tr>\n<tr>\n<td>\u5141\u8bb8 http \u5199\u76ee\u5f55<\/td>\n<td>httpd_unified on<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5148\u67e5\u5e03\u5c14\u503c&#xff0c;\u518d\u6539\u4e0a\u4e0b\u6587&#xff0c;\u6700\u540e\u624d\u8003\u8651\u5199\u7b56\u7565\u2014\u2014\u8fd9\u662f SELinux \u6392\u9519\u7684\u4f18\u5148\u7ea7\u3002<\/p>\n<h3>\u4e94\u3001SELinux \u5e38\u89c1\u6392\u9519<\/h3>\n<h4>1. \u670d\u52a1\u8d77\u4e0d\u6765&#xff08;\u7aef\u53e3\u95ee\u9898&#xff09;<\/h4>\n<p>\u573a\u666f&#xff1a; \u7ed9 nginx \u914d\u4e86 8080 \u7aef\u53e3&#xff0c;\u8d77\u4e0d\u6765\u3002<\/p>\n<p>nginx: [emerg] bind() to 0.0.0.0:8080 failed (13: Permission denied)<\/p>\n<p>\u539f\u56e0&#xff1a; SELinux \u53ea\u5141\u8bb8 httpd \u7ed1\u5b9a\u7279\u5b9a\u7aef\u53e3\u3002<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b httpd \u5141\u8bb8\u7684\u7aef\u53e3<\/span><br \/>\nsemanage port <span class=\"token parameter variable\">-l<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> http_port_t<\/p>\n<p><span class=\"token comment\"># \u628a 8080 \u52a0\u5165 httpd \u5141\u8bb8\u7aef\u53e3<\/span><br \/>\n<span class=\"token function\">sudo<\/span> semanage port <span class=\"token parameter variable\">-a<\/span> <span class=\"token parameter variable\">-t<\/span> http_port_t <span class=\"token parameter variable\">-p<\/span> tcp <span class=\"token number\">8080<\/span><\/p>\n<h4>2. \u6587\u4ef6\u8bbf\u95ee\u88ab\u62d2<\/h4>\n<p>\u573a\u666f&#xff1a; \u7f51\u7ad9\u6587\u4ef6\u653e\u81ea\u5b9a\u4e49\u76ee\u5f55&#xff0c;403\u3002<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b AVC \u65e5\u5fd7\u786e\u8ba4<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ausearch <span class=\"token parameter variable\">-m<\/span> avc <span class=\"token parameter variable\">-ts<\/span> recent <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> nginx<\/p>\n<p><span class=\"token comment\"># \u4fee\u6b63\u4e0a\u4e0b\u6587&#xff08;\u89c1\u4e0a\u6587&#xff09;<\/span><br \/>\n<span class=\"token function\">sudo<\/span> semanage fcontext <span class=\"token parameter variable\">-a<\/span> <span class=\"token parameter variable\">-t<\/span> httpd_sys_content_t <span class=\"token string\">&#034;\/web(\/.*)?&#034;<\/span><br \/>\n<span class=\"token function\">sudo<\/span> restorecon <span class=\"token parameter variable\">-Rv<\/span> \/web<\/p>\n<h4>3. \u670d\u52a1\u91cd\u542f\u540e\u4e0a\u4e0b\u6587\u4e22\u5931<\/h4>\n<p>cp\/mv\/tar \u6709\u65f6\u4e0d\u5e26\u4e0a\u4e0b\u6587&#xff0c;\u6216\u6587\u4ef6\u7cfb\u7edf\u4e0d\u4fdd\u7559\u3002\u7528 restorecon \u91cd\u5efa&#xff1a;<\/p>\n<p><span class=\"token function\">sudo<\/span> restorecon <span class=\"token parameter variable\">-Rv<\/span> \/path<\/p>\n<h4>4. \u5b9e\u5728\u8981\u7528\u300c\u6587\u6863\u5316\u300d\u7684\u5173\u95ed<\/h4>\n<p>\u5982\u679c\u786e\u8ba4\u67d0\u7b56\u7565\u4e0d\u9002\u7528\u4e8e\u4e1a\u52a1&#xff0c;\u4e14\u4e0d\u60f3\u5173\u5168\u5c40&#xff0c;\u53ef\u4ee5&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u53ea\u5bf9\u7279\u5b9a\u670d\u52a1\u8bbe\u767d\u540d\u5355&#xff08;\u63a8\u8350&#xff09;<\/span><br \/>\nsemanage permissive <span class=\"token parameter variable\">-a<\/span> httpd_t<\/p>\n<p><span class=\"token comment\"># \u5b8c\u5168\u7981\u7528&#xff08;\u4e0d\u63a8\u8350&#xff0c;\u4ec5\u6d4b\u8bd5&#xff09;<\/span><br \/>\nsetenforce <span class=\"token number\">0<\/span><\/p>\n<p>permissive \u53ea\u8ba9 httpd_t \u57df\u5bbd\u5bb9&#xff0c;\u5176\u4ed6\u4ecd\u53d7\u4fdd\u62a4&#xff0c;\u6bd4\u5168\u5c40\u5173\u95ed\u5b89\u5168\u5f97\u591a\u3002<\/p>\n<h3>\u516d\u3001AppArmor \u57fa\u7840<\/h3>\n<p>Ubuntu\/Debian \u9ed8\u8ba4\u7528 AppArmor&#xff0c;\u5b83\u57fa\u4e8e\u8def\u5f84\u800c\u4e0d\u662f\u6807\u7b7e&#xff0c;profile \u662f\u7eaf\u6587\u672c&#xff0c;\u6613\u61c2\u3002<\/p>\n<h4>\u67e5\u770b\u72b6\u6001<\/h4>\n<p><span class=\"token function\">sudo<\/span> aa-status<\/p>\n<p>apparmor module is loaded.<br \/>\n42 profiles are loaded.<br \/>\n38 profiles are in enforce mode.<br \/>\n   \/usr\/sbin\/nginx<br \/>\n   \/usr\/bin\/man<br \/>\n&#8230;<br \/>\n4 profiles are in complain mode.<\/p>\n<h4>\u4e24\u79cd\u6a21\u5f0f<\/h4>\n<table>\n<tr>\u6a21\u5f0f\u884c\u4e3a<\/tr>\n<tbody>\n<tr>\n<td>enforce<\/td>\n<td>\u5f3a\u5236\u6267\u884c&#xff0c;\u8fdd\u89c4\u62d2\u7edd<\/td>\n<\/tr>\n<tr>\n<td>complain<\/td>\n<td>\u53ea\u8bb0\u5f55\u4e0d\u963b\u6b62&#xff08;\u6392\u9519\u7528&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u5207\u6362\u6a21\u5f0f<\/h4>\n<p><span class=\"token comment\"># \u6539\u67d0 profile \u4e3a complain&#xff08;\u6392\u9519&#xff09;<\/span><br \/>\n<span class=\"token function\">sudo<\/span> aa-complain \/usr\/sbin\/nginx<\/p>\n<p><span class=\"token comment\"># \u6539\u56de enforce<\/span><br \/>\n<span class=\"token function\">sudo<\/span> aa-enforce \/usr\/sbin\/nginx<\/p>\n<p><span class=\"token comment\"># \u7981\u7528\u67d0 profile<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">ln<\/span> <span class=\"token parameter variable\">-s<\/span> \/etc\/apparmor.d\/usr.sbin.nginx \/etc\/apparmor.d\/disable\/<br \/>\n<span class=\"token function\">sudo<\/span> apparmor_parser <span class=\"token parameter variable\">-R<\/span> \/etc\/apparmor.d\/usr.sbin.nginx<\/p>\n<h4>\u6392\u9519<\/h4>\n<p><span class=\"token comment\"># \u67e5\u770b\u62d2\u7edd\u65e5\u5fd7<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">dmesg<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-i<\/span> apparmor<br \/>\n<span class=\"token function\">sudo<\/span> journalctl <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> apparmor<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">dmesg<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> <span class=\"token string\">&#034;apparmor&#061;<span class=\"token entity\" title=\"\\\\&quot;\">\\\\&#034;<\/span>DENIED<span class=\"token entity\" title=\"\\\\&quot;\">\\\\&#034;<\/span>&#034;<\/span><\/p>\n<h4>\u751f\u6210\/\u8c03\u6574 profile<\/h4>\n<p><span class=\"token comment\"># \u8ba9 AppArmor \u5b66\u4e60\u4e00\u4e2a\u7a0b\u5e8f\u7684\u884c\u4e3a<\/span><br \/>\n<span class=\"token function\">sudo<\/span> aa-genprof \/usr\/bin\/myapp<\/p>\n<p><span class=\"token comment\"># \u4ece\u65e5\u5fd7\u81ea\u52a8\u751f\u6210 profile<\/span><br \/>\n<span class=\"token function\">sudo<\/span> aa-logprof<\/p>\n<h3>\u4e03\u3001MAC \u52a0\u56fa\u7684\u6b63\u786e\u5fc3\u6001<\/h3>\n<table>\n<tr>\u505a\u6cd5\u8bc4\u4ef7<\/tr>\n<tbody>\n<tr>\n<td>\u51fa\u95ee\u9898\u5c31 Disabled\/disable<\/td>\n<td>\u274c \u7b49\u4e8e\u62c6\u6389\u4e00\u5c42\u9632\u7ebf<\/td>\n<\/tr>\n<tr>\n<td>\u4fdd\u6301 Enforcing&#xff0c;\u7528 Permissive \u5b9a\u4f4d<\/td>\n<td>\u2705 \u6b63\u786e\u59ff\u52bf<\/td>\n<\/tr>\n<tr>\n<td>\u5148\u8c03\u4e0a\u4e0b\u6587\/\u5e03\u5c14\u503c<\/td>\n<td>\u2705 \u4f18\u5148\u65b9\u6848<\/td>\n<\/tr>\n<tr>\n<td>\u4e3a\u7279\u5b9a\u670d\u52a1\u8bbe permissive<\/td>\n<td>\u2705 \u6298\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>\u5199\u81ea\u5b9a\u4e49\u7b56\u7565<\/td>\n<td>\u2705 \u7ec8\u6781\u65b9\u6848&#xff08;\u590d\u6742&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>SELinux\/AppArmor \u7684\u521d\u8877\u662f\u300c\u5373\u4f7f\u670d\u52a1\u88ab\u653b\u7834&#xff0c;\u4e5f\u9650\u5236\u5b83\u80fd\u9020\u6210\u7684\u7834\u574f\u300d\u3002 \u5173\u6389\u5b83&#xff0c;\u7b49\u4e8e\u653e\u5f03\u4e86\u8fd9\u5c42\u4fdd\u62a4\u3002\u6b63\u786e\u7684\u505a\u6cd5\u662f\u7406\u89e3\u5b83\u4e3a\u4ec0\u4e48\u62d2\u7edd&#xff0c;\u7136\u540e\u7cbe\u51c6\u5730\u653e\u884c\u5fc5\u8981\u64cd\u4f5c\u3002<\/p>\n<h3>\u516b\u3001\u26a0\ufe0f \u5e38\u89c1\u9519\u8bef<\/h3>\n<li>\u9047\u5230\u95ee\u9898\u76f4\u63a5 setenforce 0\u3002\u8fd9\u662f\u628a\u5b89\u5168\u9632\u7ebf\u62c6\u4e86&#xff0c;\u5e94\u8be5\u5148\u5b9a\u4f4d\u518d\u7cbe\u51c6\u653e\u884c\u3002<\/li>\n<li>\u6539\u4e86 semanage fcontext \u5fd8\u4e86 restorecon\u3002\u89c4\u5219\u662f\u89c4\u5219&#xff0c;\u8fd8\u5f97\u5e94\u7528\u5230\u5b9e\u9645\u6587\u4ef6\u3002<\/li>\n<li>getenforce \u663e\u793a Enforcing \u5c31\u614c\u3002Enforcing \u662f\u6b63\u5e38\u72b6\u6001&#xff0c;\u8bf4\u660e\u7b56\u7565\u5728\u4fdd\u62a4\u4f60\u3002<\/li>\n<li>\u590d\u5236\u6587\u4ef6\u540e\u4e0a\u4e0b\u6587\u4e22\u5931\u3002cp\/mv \u53ef\u80fd\u4e0d\u4fdd\u7559\u4e0a\u4e0b\u6587&#xff0c;\u7528 restorecon \u4fee\u590d\u3002<\/li>\n<li>chmod 777 \u4e5f\u89e3\u51b3\u4e0d\u4e86\u3002\u56e0\u4e3a\u74f6\u9888\u5728 MAC \u800c\u975e DAC&#xff0c;\u6743\u9650\u518d\u5bbd\u4e5f\u6ca1\u7528\u3002<\/li>\n<li>\u4e0d\u77e5\u9053\u7cfb\u7edf\u7528\u54ea\u4e2a MAC\u3002\u5148 getenforce \/ aa-status \u786e\u8ba4&#xff0c;\u522b\u5bf9\u7740 AppArmor \u627e SELinux \u7684\u9519\u3002<\/li>\n<li>\u91cd\u88c5\u7cfb\u7edf\u540e\u7b56\u7565\u6ca1\u8fc1\u79fb\u3002\u81ea\u5b9a\u4e49\u7684 SELinux \u4e0a\u4e0b\u6587\u3001AppArmor profile \u9700\u8981\u5907\u4efd\u548c\u8fc1\u79fb\u3002<\/li>\n<li>\u5728\u751f\u4ea7\u4e0a\u76f4\u63a5\u6539\u914d\u7f6e\u9a8c\u8bc1\u3002\u5e94\u5728\u6d4b\u8bd5\u73af\u5883\u9a8c\u8bc1\u7b56\u7565\u6539\u52a8&#xff0c;\u907f\u514d\u5f71\u54cd\u751f\u4ea7\u3002<\/li>\n<h3>\u4e5d\u3001\u539f\u7406\u63a2\u7a76&#xff1a;\u5b89\u5168\u4e0a\u4e0b\u6587\u4e0e\u7b56\u7565\u5339\u914d<\/h3>\n<h4>SELinux \u7684\u6807\u7b7e\u6a21\u578b<\/h4>\n<p>SELinux \u7ed9\u6bcf\u4e2a\u4e3b\u4f53&#xff08;\u8fdb\u7a0b&#xff09;\u548c\u6bcf\u4e2a\u5ba2\u4f53&#xff08;\u6587\u4ef6\u3001\u7aef\u53e3\u3001socket&#xff09;\u90fd\u6253\u4e00\u4e2a\u5b89\u5168\u4e0a\u4e0b\u6587\u3002\u8bbf\u95ee\u65f6&#xff0c;\u5185\u6838\u505a\u4e00\u4ef6\u4e8b&#xff1a;<\/p>\n<p>\u4e3b\u4f53&#xff08;\u8fdb\u7a0b\u4e0a\u4e0b\u6587&#xff09;\u7684\u64cd\u4f5c  \u2192  \u67e5\u7b56\u7565  \u2192  \u5ba2\u4f53&#xff08;\u6587\u4ef6\/\u7aef\u53e3\u4e0a\u4e0b\u6587&#xff09;<\/p>\n<p>\u51b3\u7b56\u4e0d\u770b\u4f60\u300c\u662f\u8c01&#xff08;root \u8fd8\u662f\u666e\u901a\u7528\u6237&#xff09;\u300d&#xff0c;\u800c\u770b\u300c\u8fdb\u7a0b\u5e26\u4ec0\u4e48\u6807\u7b7e\u3001\u6587\u4ef6\u5e26\u4ec0\u4e48\u6807\u7b7e\u3001\u7b56\u7565\u5141\u4e0d\u5141\u8bb8\u8fd9\u5bf9\u6807\u7b7e\u4ea4\u4e92\u300d\u3002<\/p>\n<p>\u4e3e\u4f8b&#xff1a;<\/p>\n<p>nginx \u8fdb\u7a0b    \u4e0a\u4e0b\u6587&#xff1a;system_u:system_r:httpd_t<br \/>\n\u7f51\u7ad9\u6587\u4ef6      \u4e0a\u4e0b\u6587&#xff1a;system_u:object_r:httpd_sys_content_t<br \/>\n\u7b56\u7565&#xff1a;\u5141\u8bb8 httpd_t \u8bfb httpd_sys_content_t      \u2192 \u901a\u8fc7 \u2713<\/p>\n<p>\/etc\/shadow   \u4e0a\u4e0b\u6587&#xff1a;system_u:object_r:shadow_t<br \/>\n\u7b56\u7565&#xff1a;\u4e0d\u5141\u8bb8 httpd_t \u8bfb shadow_t               \u2192 \u62d2\u7edd \u2717<\/p>\n<p>\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48 nginx&#xff08;\u54ea\u6015\u4ee5 root \u8fd0\u884c&#xff09;\u4e5f\u8bfb\u4e0d\u4e86 \/etc\/shadow\u2014\u2014\u4e0d\u662f\u6743\u9650\u95ee\u9898&#xff0c;\u662f SELinux \u7b56\u7565\u5c42\u9762\u6839\u672c\u4e0d\u5141\u8bb8\u3002\u8fd9\u5c31\u662f\u300c\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u300d\u7684\u5a01\u529b&#xff1a;\u8fde root \u90fd\u8981\u670d\u4ece\u7b56\u7565\u3002<\/p>\n<h4>\u4e3a\u4ec0\u4e48\u6309\u300c\u7aef\u53e3\u300d\u4e5f\u8981\u7ba1<\/h4>\n<p>\u4e0d\u5149\u662f\u6587\u4ef6&#xff0c;\u7aef\u53e3\u4e5f\u6709\u6807\u7b7e\u3002http_port_t \u662f\u5141\u8bb8 httpd \u7ed1\u5b9a\u7684\u7aef\u53e3\u96c6\u5408\u3002\u8fd9\u6837\u5373\u4f7f\u653b\u51fb\u8005\u8ba9 nginx \u7ed1\u5b9a\u5230\u522b\u7684\u7aef\u53e3&#xff0c;\u4e5f\u7ed1\u4e0d\u4e0a\u2014\u2014\u9650\u5236\u7684\u4e0d\u662f\u300c\u8c01\u80fd\u7ed1\u300d&#xff0c;\u800c\u662f\u300c\u8fd9\u4e2a\u8fdb\u7a0b\u80fd\u7ed1\u54ea\u4e9b\u300d\u3002<\/p>\n<h4>AppArmor \u7684\u8def\u5f84\u6a21\u578b<\/h4>\n<p>AppArmor \u66f4\u76f4\u89c2&#xff0c;profile \u91cc\u76f4\u63a5\u5199\u8def\u5f84\u89c4\u5219&#xff1a;<\/p>\n<p>\/usr\/sbin\/nginx {<br \/>\n  \/etc\/nginx\/** r,<br \/>\n  \/var\/www\/** r,<br \/>\n  \/var\/log\/nginx\/** w,<br \/>\n  network tcp,<br \/>\n}<\/p>\n<p>\u610f\u601d\u662f\u300cnginx \u53ea\u80fd\u8bfb \/etc\/nginx\u3001\/var\/www&#xff0c;\u5199 \/var\/log\/nginx&#xff0c;\u5141\u8bb8 TCP\u300d\u3002\u57fa\u4e8e\u8def\u5f84\u7684\u597d\u5904\u662f\u53ef\u8bfb\u6027\u597d&#xff0c;\u7f3a\u70b9\u662f\u8def\u5f84\u53d8\u52a8&#xff08;\u5982\u8f6f\u94fe\u63a5\u3001mount&#xff09;\u5bb9\u6613\u7ed5\u8fc7\u3002<\/p>\n<h4>\u4e24\u8005\u5bf9\u6bd4\u7684\u672c\u8d28<\/h4>\n<ul>\n<li>SELinux \u57fa\u4e8e\u6807\u7b7e&#xff1a;\u8d44\u6e90\u5e26\u6807\u7b7e&#xff0c;\u8fdb\u7a0b\u5e26\u6807\u7b7e&#xff0c;\u7b56\u7565\u7ba1\u300c\u6807\u7b7e\u5bf9\u6807\u7b7e\u300d\u3002\u5f3a\u52bf\u4f46\u590d\u6742\u3002<\/li>\n<li>AppArmor \u57fa\u4e8e\u8def\u5f84&#xff1a;\u7b56\u7565\u7ba1\u300c\u8fdb\u7a0b\u5bf9\u8def\u5f84\u300d\u3002\u7b80\u5355\u4f46\u4e0d\u591f\u7ec6\u3002<\/li>\n<\/ul>\n<p>\u65e0\u8bba\u54ea\u79cd&#xff0c;\u6838\u5fc3\u601d\u60f3\u90fd\u662f\u4e00\u6837\u7684&#xff1a;\u7ed9\u8fdb\u7a0b\u5212\u5b9a\u4e00\u4e2a\u300c\u53ea\u80fd\u78b0\u8fd9\u4e9b\u300d\u7684\u7b3c\u5b50&#xff0c;\u5373\u4f7f\u5b83\u88ab\u653b\u7834&#xff0c;\u4e5f\u7ffb\u4e0d\u51fa\u8fd9\u4e2a\u7b3c\u5b50\u3002 \u8fd9\u5c31\u662f\u300c\u6c99\u7bb1&#xff08;sandbox&#xff09;\u300d\u548c\u300c\u6700\u5c0f\u6743\u9650\u300d\u5728\u7f51\u7edc\u8bbf\u95ee\u63a7\u5236\u5c42\u7684\u843d\u5730\u3002<\/p>\n<h4>\u548c\u5bb9\u5668\u5b89\u5168\u7684\u5173\u7cfb<\/h4>\n<p>Docker\/Kubernetes \u7684\u5bb9\u5668\u9694\u79bb&#xff0c;\u4e5f\u4f1a\u7528\u5230 SELinux\/AppArmor&#xff1a;<\/p>\n<p><span class=\"token comment\"># docker \u6307\u5b9a SELinux \u6807\u7b7e<\/span><br \/>\n<span class=\"token function\">docker<\/span> run &#8211;security-opt <span class=\"token assign-left variable\">label<\/span><span class=\"token operator\">&#061;<\/span>type:container_t <span class=\"token punctuation\">..<\/span>.<\/p>\n<p><span class=\"token comment\"># docker \u6307\u5b9a AppArmor profile<\/span><br \/>\n<span class=\"token function\">docker<\/span> run &#8211;security-opt <span class=\"token assign-left variable\">apparmor<\/span><span class=\"token operator\">&#061;<\/span>docker-default <span class=\"token punctuation\">..<\/span>.<\/p>\n<p>K8s \u7684 Pod Security Context \u4e5f\u80fd\u6307\u5b9a seLinuxOptions\u3002\u7406\u89e3 MAC&#xff0c;\u4e5f\u662f\u7406\u89e3\u5bb9\u5668\u5b89\u5168\u7684\u57fa\u7840\u3002<\/p>\n<h3>\u5341\u3001SELinux\/AppArmor \u901f\u67e5\u8868<\/h3>\n<p><span class=\"token comment\"># &#061;&#061;&#061;&#061;&#061; SELinux &#061;&#061;&#061;&#061;&#061;<\/span><br \/>\ngetenforce                          <span class=\"token comment\"># \u770b\u6a21\u5f0f<\/span><br \/>\nsetenforce <span class=\"token number\">0<\/span> \/ <span class=\"token number\">1<\/span>                    <span class=\"token comment\"># \u4e34\u65f6\u5207 Permissive\/Enforcing<\/span><br \/>\n<span class=\"token function\">ls<\/span> <span class=\"token parameter variable\">-Z<\/span> <span class=\"token function\">file<\/span>                          <span class=\"token comment\"># \u770b\u6587\u4ef6\u4e0a\u4e0b\u6587<\/span><br \/>\n<span class=\"token function\">ps<\/span> <span class=\"token parameter variable\">-eZ<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> proc                  <span class=\"token comment\"># \u770b\u8fdb\u7a0b\u4e0a\u4e0b\u6587<\/span><br \/>\nausearch <span class=\"token parameter variable\">-m<\/span> avc <span class=\"token parameter variable\">-ts<\/span> recent          <span class=\"token comment\"># \u770b\u62d2\u7edd\u65e5\u5fd7<\/span><br \/>\nsemanage fcontext <span class=\"token parameter variable\">-a<\/span> <span class=\"token parameter variable\">-t<\/span> TYPE <span class=\"token string\">&#034;\u8def\u5f84&#034;<\/span>  <span class=\"token comment\"># \u52a0\u4e0a\u4e0b\u6587\u89c4\u5219<\/span><br \/>\nrestorecon <span class=\"token parameter variable\">-Rv<\/span> \/path                <span class=\"token comment\"># \u5e94\u7528\u4e0a\u4e0b\u6587<\/span><br \/>\nsemanage port <span class=\"token parameter variable\">-a<\/span> <span class=\"token parameter variable\">-t<\/span> http_port_t <span class=\"token parameter variable\">-p<\/span> tcp <span class=\"token number\">8080<\/span>   <span class=\"token comment\"># \u653e\u5f00\u7aef\u53e3<\/span><br \/>\ngetsebool <span class=\"token parameter variable\">-a<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> xxx             <span class=\"token comment\"># \u770b\u5e03\u5c14\u503c<\/span><br \/>\nsetsebool <span class=\"token parameter variable\">-P<\/span> xxx on                 <span class=\"token comment\"># \u5f00\u5e03\u5c14\u503c<\/span><br \/>\nsemanage permissive <span class=\"token parameter variable\">-a<\/span> domain_t     <span class=\"token comment\"># \u5355\u57df\u5bbd\u5bb9<\/span><\/p>\n<p><span class=\"token comment\"># &#061;&#061;&#061;&#061;&#061; AppArmor &#061;&#061;&#061;&#061;&#061;<\/span><br \/>\naa-status                           <span class=\"token comment\"># \u770b\u72b6\u6001<\/span><br \/>\naa-complain \/path                   <span class=\"token comment\"># \u5207 complain<\/span><br \/>\naa-enforce \/path                    <span class=\"token comment\"># \u5207 enforce<\/span><br \/>\n<span class=\"token function\">dmesg<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> <span class=\"token parameter variable\">-i<\/span> apparmor            <span class=\"token comment\"># \u770b\u65e5\u5fd7<\/span><br \/>\naa-genprof \/usr\/bin\/app             <span class=\"token comment\"># \u751f\u6210 profile<\/span><\/p>\n<p>\u4e00\u53e5\u8bdd\u6536\u5c3e&#xff1a;SELinux \u7528\u300c\u6807\u7b7e\u300d\u3001AppArmor \u7528\u300c\u8def\u5f84\u300d&#xff0c;\u90fd\u662f\u7ed9\u8fdb\u7a0b\u5212\u5b9a\u6d3b\u52a8\u8303\u56f4&#xff0c;\u8fde root \u4e5f\u7ba1\u3002 \u9047\u5230\u300c\u6743\u9650\u7ed9\u4e86\u8fd8\u88ab\u62d2\u300d&#xff0c;\u5148\u60f3\u5b83\u4fe9&#xff1b;\u6392\u9519\u7528 Permissive\/complain \u5b9a\u4f4d&#xff0c;\u518d\u7528 semanage\/\u5e03\u5c14\u503c\u7cbe\u51c6\u653e\u884c\u2014\u2014\u522b\u628a\u5173\u95ed\u5f53\u89e3\u6cd5&#xff0c;\u90a3\u7b49\u4e8e\u81ea\u65ad\u4e00\u5c42\u9632\u7ebf\u3002<\/p>\n<hr \/>\n<p>\u81f3\u6b64&#xff0c;\u7b2c\u516b\u7bc7\u300c\u7f51\u7edc\u914d\u7f6e\u3001\u8fdc\u7a0b\u4e0e\u5b89\u5168\u7bc7\u300d10 \u7bc7\u5168\u90e8\u5b8c\u6210\u3002\u4e0b\u4e00\u7bc7\u8fdb\u5165\u7b2c\u4e5d\u7bc7\u300c\u5b58\u50a8\u3001\u78c1\u76d8\u3001\u5907\u4efd\u4e0e\u6062\u590d\u7bc7\u300d&#xff0c;\u4ece\u78c1\u76d8\u5206\u533a\u5f00\u59cb&#xff0c;\u628a\u5b58\u50a8\u8fd9\u5757\u786c\u9aa8\u5934\u5543\u4e0b\u6765\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u670d\u52a1\u6539\u4e86\u914d\u7f6e\u5c31\u662f\u8d77\u4e0d\u6765&#xff0c;\u65e5\u5fd7\u4e5f\u6ca1\u62a5\u9519\u300d\u300c\u660e\u660e\u7ed9\u4e86 777 \u6743\u9650\u8fd8\u662f\u62d2\u7edd\u8bbf\u95ee\u300d\u2014\u2014\u5f88\u591a\u4eba\u88ab\u8fd9\u7c7b\u8be1\u5f02\u95ee\u9898\u5751\u8fc7&#xff0c;\u6700\u540e\u53d1\u73b0\u662f SELinux \u6216 AppArmor \u5728\u300c\u591a\u7ba1\u95f2\u4e8b\u300d\u3002\u5b83\u4eec\u662f Linux \u7684**\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236&#xff08;MAC&#xff09;**\u673a\u5236&#xff0c;\u6bd4\u4f20\u7edf\u7684\u6587\u4ef6\u6743\u9650\u66f4\u5e95\u5c42\u3001\u66f4\u4e25\u683c\u3002\u8fd9\u4e00\u7bc7\u8bb2\u6e05 SELinux \u548c AppArmor \u7684\u539f\u7406\u3001\u914d\u7f6e\u548c\u6392\u9519\u65b9\u6cd5&#xff0c;\u8ba9\u4f60\u4e0d\u518d\u628a\u300c\u5173\u6389\u5b83\u300d\u5f53\u6210\u552f\u4e00\u89e3\u6cd5\u3002<br \/>\n\u4e00\u3001\u4ec0\u4e48\u662f\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13178,58,43,44],"topic":[],"class_list":["post-117136","post","type-post","status-publish","format-standard","hentry","category-server","tag-1024---","tag-linux","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117136.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u300c\u670d\u52a1\u6539\u4e86\u914d\u7f6e\u5c31\u662f\u8d77\u4e0d\u6765&#xff0c;\u65e5\u5fd7\u4e5f\u6ca1\u62a5\u9519\u300d\u300c\u660e\u660e\u7ed9\u4e86 777 \u6743\u9650\u8fd8\u662f\u62d2\u7edd\u8bbf\u95ee\u300d\u2014\u2014\u5f88\u591a\u4eba\u88ab\u8fd9\u7c7b\u8be1\u5f02\u95ee\u9898\u5751\u8fc7&#xff0c;\u6700\u540e\u53d1\u73b0\u662f SELinux \u6216 AppArmor \u5728\u300c\u591a\u7ba1\u95f2\u4e8b\u300d\u3002\u5b83\u4eec\u662f Linux \u7684**\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236&#xff08;MAC&#xff09;**\u673a\u5236&#xff0c;\u6bd4\u4f20\u7edf\u7684\u6587\u4ef6\u6743\u9650\u66f4\u5e95\u5c42\u3001\u66f4\u4e25\u683c\u3002\u8fd9\u4e00\u7bc7\u8bb2\u6e05 SELinux \u548c AppArmor \u7684\u539f\u7406\u3001\u914d\u7f6e\u548c\u6392\u9519\u65b9\u6cd5&#xff0c;\u8ba9\u4f60\u4e0d\u518d\u628a\u300c\u5173\u6389\u5b83\u300d\u5f53\u6210\u552f\u4e00\u89e3\u6cd5\u3002 \u4e00\u3001\u4ec0\u4e48\u662f\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117136.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-22T09:40:42+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117136.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117136.html\",\"name\":\"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-22T09:40:42+00:00\",\"dateModified\":\"2026-10-22T09:40:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117136.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117136.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117136.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117136.html","og_locale":"zh_CN","og_type":"article","og_title":"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u300c\u670d\u52a1\u6539\u4e86\u914d\u7f6e\u5c31\u662f\u8d77\u4e0d\u6765&#xff0c;\u65e5\u5fd7\u4e5f\u6ca1\u62a5\u9519\u300d\u300c\u660e\u660e\u7ed9\u4e86 777 \u6743\u9650\u8fd8\u662f\u62d2\u7edd\u8bbf\u95ee\u300d\u2014\u2014\u5f88\u591a\u4eba\u88ab\u8fd9\u7c7b\u8be1\u5f02\u95ee\u9898\u5751\u8fc7&#xff0c;\u6700\u540e\u53d1\u73b0\u662f SELinux \u6216 AppArmor \u5728\u300c\u591a\u7ba1\u95f2\u4e8b\u300d\u3002\u5b83\u4eec\u662f Linux \u7684**\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236&#xff08;MAC&#xff09;**\u673a\u5236&#xff0c;\u6bd4\u4f20\u7edf\u7684\u6587\u4ef6\u6743\u9650\u66f4\u5e95\u5c42\u3001\u66f4\u4e25\u683c\u3002\u8fd9\u4e00\u7bc7\u8bb2\u6e05 SELinux \u548c AppArmor \u7684\u539f\u7406\u3001\u914d\u7f6e\u548c\u6392\u9519\u65b9\u6cd5&#xff0c;\u8ba9\u4f60\u4e0d\u518d\u628a\u300c\u5173\u6389\u5b83\u300d\u5f53\u6210\u552f\u4e00\u89e3\u6cd5\u3002 \u4e00\u3001\u4ec0\u4e48\u662f\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236","og_url":"https:\/\/www.wsisp.com\/helps\/117136.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-22T09:40:42+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117136.html","url":"https:\/\/www.wsisp.com\/helps\/117136.html","name":"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-22T09:40:42+00:00","dateModified":"2026-10-22T09:40:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117136.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117136.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117136.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"SELinux\u4e0eAppArmor\u5165\u95e8\uff1a\u5f3a\u5236\u8bbf\u95ee\u63a7\u5236\u914d\u7f6e\u4e0e\u6392\u9519"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117136"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117136\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117136"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}