Habréäžã®SELinuxã«ã€ããŠã¯ãã§ã«æžããŠããŸããããã®ã·ã¹ãã ã«é¢ãã詳现ãªããã¥ã¢ã«ã¯ããã»ã©å€ãå ¬éãããŠããŸããã æ¬æ¥ãã·ã¹ãã ã«é¢ããæ å ±ããæè»ãªããªã·ãŒèšå®ãŸã§ãSELinuxã«é¢ãã詳现ãªããã¥ã¢ã«ãå ¬éããŸãã
æçš¿ãç解ãã«ãããã·ãŒããã«ããªãããã«ãããã¥ã¢ã«ã2ã€ã®éšåã«åããããšã«ããŸããã æåã¯ãã·ã¹ãã èªäœãšãã®æ©èœã®äžéšã«ã€ããŠèª¬æããŸãã 2ã€ç®ã¯ãããªã·ãŒã®èšå®ã«é¢ãããã®ã§ãã ããã§æåã®éšåãå ¬éããå°ãåŸã«2çªç®ã®éšåãå ¬éããŸãã
1.ã¯ããã«
SELinuxïŒSELinuxïŒã¯ã«ãŒãã«ã¬ãã«ã®ã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ã§ãã ãã®ã·ã¹ãã ã¯ãCentOSã®4çªç®ã®ããŒãžã§ã³ã§åããŠç»å ŽããããŒãžã§ã³5ããã³6ã§ã¯ãå®è£ ãå€§å¹ ã«è£å®ããã³æ¹åãããŸããã ãããã®æ¹åã«ãããSELinuxã¯å€ãã®ç·æ¥ã¿ã¹ã¯ãå¹æçã«è§£æ±ºã§ãããŠãããŒãµã«ã·ã¹ãã ã«ãªããŸããã å€å žçãªUnixã®æš©å©ã·ã¹ãã ãæåã«é©çšããããã®æåã®ãã§ãã¯ã«æåããå Žåã«ã®ã¿å¶åŸ¡ãSELinuxã«è»¢éãããããšãèŠããŠãã䟡å€ããããŸãã
1.1ããã€ãã®é¢é£ã¿ã¹ã¯ã
SELinuxã®å®éçãªäŸ¡å€ãç解ããããã«ãæšæºã®ã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ãäžååãªå Žåã®ããã€ãã®äŸãèŠãŠã¿ãŸãããã SELinuxãç¡å¹ã«ãªã£ãŠããå ŽåãDACïŒéžæçã¢ã¯ã»ã¹å¶åŸ¡ïŒãŸãã¯ACLïŒã¢ã¯ã»ã¹å¶åŸ¡ãªã¹ãïŒãå«ãåŸæ¥ã®ä»»æã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ã®ã¿ã«ã¢ã¯ã»ã¹ã§ããŸãã ã€ãŸãããŠãŒã¶ãŒããã³ãŠãŒã¶ãŒã°ã«ãŒãã®ã¬ãã«ã§æžã蟌ã¿ãèªã¿åããå®è¡ã®æš©éãæäœããããšã«ã€ããŠè©±ããŠããããããã¯å Žåã«ãã£ãŠã¯å®å šã«äžååãªå Žåãããã äŸïŒ
-管çè ã¯ãŠãŒã¶ãŒã®ã¢ã¯ã·ã§ã³ãå®å šã«å¶åŸ¡ã§ããŸããã ããšãã°ããŠãŒã¶ãŒã¯ä»ã®ãã¹ãŠã®ãŠãŒã¶ãŒã«ãSSHããŒãªã©ã®ç¬èªã®æ©å¯ãã¡ã€ã«ãèªã¿åãæš©å©ãäžããããšãã§ããŸãã
-ããã»ã¹ã¯ã»ãã¥ãªãã£èšå®ãå€æŽã§ããŸãã ããšãã°ããŠãŒã¶ãŒã®ã¡ãŒã«ãå«ããã¡ã€ã«ã¯ç¹å®ã®1人ã®ãŠãŒã¶ãŒã®ã¿ãèªã¿åãå¯èœã«ããå¿ èŠããããŸãããã¡ãŒã«ã¯ã©ã€ã¢ã³ãã¯ã¢ã¯ã»ã¹æš©ãéåžžã«é©åã«å€æŽã§ããããããããã®ãã¡ã€ã«ã¯èª°ã§ãèªã¿åãå¯èœã§ãã
-ããã»ã¹ã¯ãããããèµ·åãããŠãŒã¶ãŒã®æš©éãç¶æ¿ããŸãã ããšãã°ãããã€ã®æšéŠ¬ã«ææããããŒãžã§ã³ã®Firefoxã¯ããŠãŒã¶ãŒã®SSHããŒãèªã¿åãããšãã§ããŸãããçç±ã¯ãããŸããã
å®éãéžæçã¢ã¯ã»ã¹å¶åŸ¡ïŒDACïŒã®åŸæ¥ã®ã¢ãã«ã§ã¯ããŠãŒã¶ãŒãšã¹ãŒããŒãŠãŒã¶ãŒã®2ã€ã®ã¢ã¯ã»ã¹ã¬ãã«ã®ã¿ãé©åã«å®è£ ãããŠããŸãã åãŠãŒã¶ãŒã«å¿ èŠãªæå°éã®ç¹æš©ãèšå®ã§ããç°¡åãªæ¹æ³ã¯ãããŸããã
ãã¡ãããå€å žçãªã»ãã¥ãªãã£ã¢ãã«ã®æ çµã¿å ã§ãããã®åé¡ãåé¿ããæ¹æ³ã¯ãããããããŸãããã©ããæ®éçã§ã¯ãããŸããã
1.1.1 SELinuxã§äœ¿çšãããåºæ¬çšèªïŒ
ãã¡ã€ã³ -ããã»ã¹ãå®è¡ã§ããã¢ã¯ã·ã§ã³ã®ãªã¹ãã éåžžããã¡ã€ã³ã¯ãããã»ã¹ãæ©èœã§ããæå°ã®ã¢ã¯ã·ã§ã³ã»ãããšããŠå®çŸ©ãããŸãã ãããã£ãŠãããã»ã¹ã®ä¿¡çšã倱ãããå Žåãæ»æè ã¯å€§ããªæ害ãäžããããšã¯ã§ããŸããã
ããŒã« -é©çšã§ãããã¡ã€ã³ã®ãªã¹ãã ãã¡ã€ã³ãããŒã«ã®ãã¡ã€ã³ãªã¹ãã«ãªãå Žåããã®ãã¡ã€ã³ããã®ã¢ã¯ã·ã§ã³ã¯é©çšã§ããŸããã
ã¿ã€ã -ãªããžã§ã¯ãã«é¢é£ããŠæå¹ãªã¢ã¯ã·ã§ã³ã®ã»ããã ãã®ã¿ã€ãã¯ããã€ãããã£ã¬ã¯ããªãããã³ãã¡ã€ã«ã«é©çšã§ãããã¡ã€ã³ã¯ããã»ã¹ã«é©çšã§ãããšããç¹ã§ããã¡ã€ã³ãšã¯ç°ãªããŸãã
ã»ãã¥ãªãã£ã³ã³ããã¹ã -ãã¹ãŠã®SELinuxå±æ§-ããŒã«ãã¿ã€ããããã³ãã¡ã€ã³ã
1.2åŸæ¥ã®ã»ãã¥ãªãã£ã¢ãã«ã®åé¡ã解決ããã
SELinuxã¯ãåãµãŒãã¹ããŠãŒã¶ãŒãããã³ããã°ã©ã ã«æäœéå¿ èŠãªç¹æš©ã®ã¢ãã«ãããå³å¯ã«å®ããŸãã ã·ã¹ãã ã®åèŠçŽ ãæ©èœããããã«äžå¯æ¬ ãªæš©éã®ã¿ãæã€å Žåãããã©ã«ãèšå®ã¯ãçŠæ¢ã¢ãŒããã§ãã ãŠãŒã¶ãŒãããã°ã©ã ããŸãã¯ãµãŒãã¹ããã¡ã€ã«ãå€æŽããããšããŠããããŸãã¯æããã«è§£æ±ºããå¿ èŠã®ãªããªãœãŒã¹ã«ã¢ã¯ã»ã¹ããããšããŠããå Žåãåã«ã¢ã¯ã»ã¹ãæåŠããããã®ãããªè©Šã¿ããã°ã«èšé²ãããŸãã
SELinuxã¯ã«ãŒãã«ã¬ãã«ã§å®è£ ããããããã¢ããªã±ãŒã·ã§ã³ã¢ããªã±ãŒã·ã§ã³ã¯ããã®åŒ·å¶ã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ã®ããŒãžã§ã³ããã®åäœã®æ©èœãªã©ã«ã€ããŠãŸã£ããäœãç¥ããªãå¯èœæ§ããããŸãã é©åãªæ§æã®å ŽåãSELinuxã¯ãµãŒãããŒãã£ã®ããã°ã©ã ãšãµãŒãã¹ã®æ©èœã«åœ±é¿ãäžããŸããã ãã ããã¢ããªã±ãŒã·ã§ã³ããã®ã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ã®ãšã©ãŒã¡ãã»ãŒãžãååã§ããå Žåã¯ãåãã¢ããªã±ãŒã·ã§ã³ã䜿çšããããšã®å©äŸ¿æ§ãå€§å¹ ã«åäžããŸãã å®éãä¿è·ããããªãœãŒã¹ãŸãã¯ãã¡ã€ã«ã«ã¢ã¯ã»ã¹ããããšãããšãSELinuxã¯ãã¢ã¯ã»ã¹æåŠããã¡ããªãŒããã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ã«ãšã©ãŒãéä¿¡ããŸãã ãã ããSELinuxããåä¿¡ããã·ã¹ãã ã³ãŒã«ã®ãªã¿ãŒã³ã³ãŒãã䜿çšããã¢ããªã±ãŒã·ã§ã³ã¯ãããã§ãã
SELinuxã䜿çšããŠãã·ã¹ãã å šäœã®ã»ãã¥ãªãã£ã匷åããæ¹æ³ã確èªããäŸã次ã«ç€ºããŸãã
-sshããŒãèªã¿åãããšãã§ããããã°ã©ã ã®ãªã¹ããäœæããã³æ§æããŸãã
-ã¡ãŒã«ã¯ã©ã€ã¢ã³ããä»ããããŒã¿ãžã®äžæ£ã¢ã¯ã»ã¹ã®é²æ¢ã
-ãŠãŒã¶ãŒã®ããŒã ãã©ã«ããŒã§æ©èœããããã«å¿ èŠãªãã¡ã€ã«ãšãã©ã«ããŒã®ã¿ãèªã¿åããããã«ãã©ãŠã¶ãŒãæ§æããŸãã
2. SELinuxã®åäœã¢ãŒã
SELinuxã«ã¯3ã€ã®äž»èŠãªåäœã¢ãŒãããããããã©ã«ãã§ã¯åŒ·å¶ã¢ãŒããèšå®ãããŠããŸãã ããã¯ããªãå³ããã¢ãŒãã§ãããå¿ èŠã«å¿ããŠããšã³ããŠãŒã¶ãŒã«ãšã£ãŠãã䟿å©ãªã¢ãŒãã«å€æŽã§ããŸãã
Enforcing ïŒããã©ã«ãã¢ãŒãã ãã®ã¢ãŒããéžæãããšãçŸåšã®ã»ãã¥ãªãã£ããªã·ãŒã«äœããã®åœ¢ã§éåãããã¹ãŠã®ã¢ã¯ã·ã§ã³ããããã¯ãããéåããè©Šã¿ããã°ã«èšé²ãããŸãã
Permissive ïŒãã®ã¢ãŒãã䜿çšãããšãçŸåšã®ã»ãã¥ãªãã£ããªã·ãŒã«éåãããã¹ãŠã®ã¢ã¯ã·ã§ã³ã«é¢ããæ å ±ããã°ã«èšé²ãããŸãããã¢ã¯ã·ã§ã³èªäœã¯ãããã¯ãããŸããã
ç¡å¹ ïŒåŒ·å¶ã¢ã¯ã»ã¹å¶åŸ¡ãå®å šã«ç¡å¹ã«ããŸãã
[管ç]ã¡ãã¥ãŒïŒsystem-config-selinuxïŒã§å©çšã§ããç¹å¥ãªGUIããŒã«ã䜿çšããŠãçŸåšã®ã¢ãŒããšä»ã®SELinuxèšå®ã衚瀺ïŒããã³å¿ èŠã«å¿ããŠå€æŽïŒã§ããŸãã ã³ã³ãœãŒã«ã§ã®äœæ¥ã«æ £ããŠããå Žåã¯ãsestatusã³ãã³ãã§çŸåšã®ã¹ããŒã¿ã¹ã確èªã§ããŸãã
# sestatus SELinux status: enabled SELinuxfs mount: /selinux Current mode: enforcing Mode from config file: enforcing Policy version: 21 Policy from config file: targeted
getenforceã³ãã³ãã䜿çšããŠãSELinuxã¹ããŒã¿ã¹ã確èªããããšãã§ããŸãã
setenforceã³ãã³ãã䜿çšãããšã匷å¶ã¢ãŒããšèš±å®¹ã¢ãŒãããã°ããåãæ¿ããããšãã§ããå€æŽã¯åèµ·åããã«æå¹ã«ãªããŸãã ãã ããSELinuxãæå¹ãŸãã¯ç¡å¹ã«ããå Žåããã¡ã€ã«ã·ã¹ãã ã«ã»ãã¥ãªãã£ã©ãã«ãåã€ã³ã¹ããŒã«ããå¿ èŠããããããåèµ·åãå¿ èŠã§ãã
åã·ã¹ãã ããŒãã§é©çšãããããã©ã«ãã¢ãŒããéžæããã«ã¯ããã¡ã€ã«/ etc / selinux / configã®è¡ãSELINUX =ãã®å€ãèšå®ãããenforcingãããpermissiveãããdisabledãã®ããããã®ã¢ãŒããèšå®ããŸãã ããšãã°ããSELINUX = permissiveãã§ãã
3. SELinuxããªã·ãŒ
åè¿°ããããã«ãSELinuxã¯ããã©ã«ãã§åŒ·å¶ã¢ãŒãã§åäœããŸããèš±å¯ãããŠããã¢ã¯ã·ã§ã³ä»¥å€ã®ã¢ã¯ã·ã§ã³ãèªåçã«ãããã¯ãããåããã°ã©ã ããŠãŒã¶ãŒããŸãã¯ãµãŒãã¹ãæ©èœããããã«å¿ èŠãªæš©éã®ã¿ãæã¡ããã以äžã¯ãããŸããã ããã¯ããªãå³ããããªã·ãŒã§ããããã©ã¹ïŒæé«ã¬ãã«ã®æ å ±ã»ãã¥ãªãã£ïŒãšãã€ãã¹ïŒãã€ãã¹ïŒã®äž¡æ¹ããããŸãããã®ã¢ãŒãã§ã·ã¹ãã ãæ§æãããšãã·ã¹ãã 管çè ã«ãšã£ãŠäººä»¶è²»ãé«ããªããŸããå°ãªããšãéèŠãªæ¹æ³ã§ã ãã®ã¢ãããŒãã¯ãšã³ã¿ãŒãã©ã€ãºã»ã¯ã¿ãŒã§ã¯åãå ¥ããããŸããããšã³ããŠãŒã¶ãŒã³ã³ãã¥ãŒã¿ãŒã§ã¯åãå ¥ããããŸããã å€ãã®ç®¡çè ã¯ãã¯ãŒã¯ã¹ããŒã·ã§ã³ã§SELinuxããªãã«ããŠããã®ãããªåé¡ãçºçããªãããã«ããŸãã
ãããåé¿ããããã«ãããšãã°httpdãnamedãdhcpdãmysqldãªã©ã®äž»èŠãªã¢ããªã±ãŒã·ã§ã³ããã³ãµãŒãã¹ã«ã€ããŠãæ»æè ãéèŠãªããŒã¿ã«ã¢ã¯ã»ã¹ã§ããªãããã«äºåèšå®ãããã¿ãŒã²ããããªã·ãŒãå®çŸ©ãããŠããŸãã ããªã·ãŒãå®çŸ©ãããŠããªãåãã¢ããªã±ãŒã·ã§ã³ãunconfined_tãã¡ã€ã³ã§å®è¡ãããSELinuxã«ãã£ãŠä¿è·ãããŸããã ãããã£ãŠãæ£ããéžæãããã¿ãŒã²ããããªã·ãŒã¯ããŠãŒã¶ãŒã«äžå¿ èŠãªåé¡ãåŒãèµ·ããããšãªãã蚱容å¯èœãªã¬ãã«ã®ã»ãã¥ãªãã£ãå®çŸã§ããŸãã
4. SELinuxã®ã¢ã¯ã»ã¹å¶åŸ¡
SELinuxã¯ã次ã®ã¢ã¯ã»ã¹å¶åŸ¡ã¢ãã«ãæäŸããŸãã
Type EnforcementïŒTEïŒïŒã¿ãŒã²ããããªã·ãŒã§äœ¿çšããããã©ã€ããªã¢ã¯ã»ã¹å¶åŸ¡ã¡ã«ããºã ã æäžäœã¬ãã«ã§è©³çŽ°ã«æš©éã管çã§ããŸãã ã·ã¹ãã 管çè ã«ãšã£ãŠæãæè»æ§ããããŸãããæãæéããããã¡ã«ããºã ã§ãã
圹å²ããŒã¹ã®ã¢ã¯ã»ã¹å¶åŸ¡ïŒRBACïŒïŒãã®ã¢ãã«ã§ã¯ãã¢ã¯ã»ã¹æš©ã¯åœ¹å²ãšããŠå®è£ ãããŸãã 圹å²ã¯ãã·ã¹ãã ã®ä»ã®éšåã«å¯ŸããŠã·ã¹ãã ã®1ã€ä»¥äžã®èŠçŽ ã«ãã£ãŠç¹å®ã®ã¢ã¯ã·ã§ã³ãå®è¡ããèš±å¯ãšåŒã°ããŸãã æ¬è³ªçã«ãRBACã¯TEãããã«çºå±ããããã®ã§ãã
ãã«ãã¬ãã«ã»ãã¥ãªãã£ïŒMLSïŒïŒãã¹ãŠã®ã·ã¹ãã ãªããžã§ã¯ãã«ç¹å®ã®ã¢ã¯ã»ã¹ã¬ãã«ãå²ãåœãŠããããã«ãã¬ãã«ã»ãã¥ãªãã£ã¢ãã«ã ã¢ã¯ã»ã¹ã®èš±å¯ãŸãã¯æåŠã¯ããããã®ã¬ãã«ã®æ¯çã«ãã£ãŠã®ã¿æ±ºå®ãããŸãã
SELinuxå ã®ãã¹ãŠã®ããã»ã¹ãšãã¡ã€ã«ã«ã¯ã»ãã¥ãªãã£ã³ã³ããã¹ãããããŸãã
/var/www/html/index.htmlã«ããApache WebãµãŒããŒã®éå§ããŒãžã詳现ã«èŠãŠãå®éã®ã³ã³ããã¹ããèŠãŠã¿ãŸãããã
$ ls -Z /var/www/html/index.html -rw-r--r-- username username system_u:object_r:httpd_sys_content_t /var/www/html/index.html
æšæºã®ãã¡ã€ã«èš±å¯ã«å ããŠãSELinuxã»ãã¥ãªãã£ã³ã³ããã¹ãsystem_uïŒobject_rïŒhttpd_sys_content_tã確èªã§ããŸãã
ã³ã³ããã¹ãã¯ãuserïŒroleïŒtypeïŒmlsã«åºã¥ããŠããŸãããuserïŒroleïŒtypeãã£ãŒã«ãã¯è¡šç€ºãããŸãããmlsãã£ãŒã«ãã¯é衚瀺ã§ãã ã¿ãŒã²ããããªã·ãŒããã®å Žåã¯httpd_sys_content_tã確èªã§ããŸãã
次ã«ããhttpdãããã»ã¹ïŒApache WebãµãŒããŒïŒã®SELinuxã»ãã¥ãªãã£ã³ã³ããã¹ããæ€èšããŸãã
$ ps axZ | grep httpd system_u:system_r:httpd_t 3234 ? Ss 0:00 /usr/sbin/httpd
ã芧ã®ãšããããã®ããã»ã¹ã¯httpd_tãã¡ã€ã³ã§å®è¡ãããŠããŸãã
ããã§ã¯ãããŒã ãã£ã¬ã¯ããªã®ãã¡ã€ã«ã»ãã¥ãªãã£ã³ã³ããã¹ããèŠãŠã¿ãŸãããã
$ ls -Z /home/username/myfile.txt -rw-r--r-- username username user_u:object_r:user_home_t /home/username/myfile.txt
ãã¡ã€ã«ã®ã¿ã€ãã¯user_home_tã§ããããšãããããŸãããã®ã¿ã€ãã¯ããã©ã«ãã§ããŒã ãã£ã¬ã¯ããªå ã®ãã¹ãŠã®ãã¡ã€ã«ã«å²ãåœãŠãããŸãã
ã¢ã¯ã»ã¹ã¯åãã¿ã€ãã®èŠçŽ éã§ã®ã¿èš±å¯ããããããApache WebãµãŒããŒã¯httpd_sys_content_tã¿ã€ãã®/var/www/html/index.htmlãã¡ã€ã«ãåé¡ãªãèªã¿åãããšãã§ããŸãã åæã«ãApacheã¯httpd_tãã¡ã€ã³ã§å®è¡ãããŠãããuseridïŒusernameãã£ãŒã«ããå ¥åãããŠããªããããhome / username / myfile.txtãã¡ã€ã«ã«ã¢ã¯ã»ã¹ã§ããŸãããããã®ãã¡ã€ã«ã¯ã¿ãŒã²ãããå®çŸ©ãããŠããªãããã»ã¹ã§èªã¿åãå¯èœã§ãæ¿æ²»ã ãããã£ãŠãApache WebãµãŒããŒããããã³ã°ãããå Žåãæ»æè ã¯ãã¡ã€ã«ã«ã¢ã¯ã»ã¹ããããhttpd_tãã¡ã€ã³ã«ãªãããã»ã¹ãéå§ãããããããšã¯ã§ããŸããã
5. SELinuxã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°
é ããæ©ãããSELinuxãäœããžã®ã¢ã¯ã»ã¹ãæåŠããç¶æ³ã«çŽé¢ãããšãç¶æ³ãçºçããŸãã ã¢ã¯ã»ã¹ãæåŠãããäž»ãªçç±ã¯ããã€ããããŸãã
-誀ã£ãŠããŒã¯ããããã¡ã€ã«ã
-ããã»ã¹ãééã£ãã³ã³ããã¹ãã§å®è¡ãããŠããŸã
-æ¿æ²»ã®ééãã ãã®ããã»ã¹ã§ã¯ãããªã·ãŒã®äœææã«èæ ®ãããªãã£ããã¡ã€ã«ãžã®ã¢ã¯ã»ã¹ãå¿ èŠã§ãã
-äŸµå ¥ã®è©Šã¿ã
ã¢ã¯ã»ã¹æåŠã®æåã®3ã€ã®çç±ã¯éåžžã«ç°¡åã«è§£æ±ºãããŸãããäŸµå ¥ã®è©Šè¡äžã«ã¢ã©ãŒã ã鳎ãããŠãŒã¶ãŒã«éç¥ãéä¿¡ãããŸãã
åé¡ã«å¯ŸåŠããã«ã¯ãSELinuxãã°ãåç §ããŠãã ããã ããã©ã«ãã§ã¯ãç£æ»ããã»ã¹ã«ãã£ãŠ/var/log/audit/audit.logãã¡ã€ã«ã«æžã蟌ãŸããŸãã ãã®ããã»ã¹ãéå§ãããªãå ŽåãSELinuxã¯/ var / log / messagesãã¡ã€ã«ã«ãã°ã€ã³ããŸãããã®å Žåããã¹ãŠã®ã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ã¡ãã»ãŒãžã¯AVCããŒã§ããŒã¯ãããŸããããã«ãããããšãã°å¿ èŠãªè¡ããã°ãããã£ã«ã¿ãªã³ã°ã§ããŸãã grepã³ãã³ãã䜿çšããŸãã
ææ°ã®ãã£ã¹ããªãã¥ãŒã·ã§ã³ïŒCentOS 5以éïŒã«ã¯ãSELinuxãã°ã䟿å©ã§äœ¿ããããæ¹æ³ã§è¡šç€ºã§ããã°ã©ãã£ã«ã«ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãåãããŠãŒãã£ãªãã£ãå«ãŸããŠããŸãã sealert -bãšå ¥åããŠãã³ã³ãœãŒã«ããåŒã³åºãããšãã§ããŸãã ãã®ãŠãŒãã£ãªãã£ã¯setroubleshootããã±ãŒãžã®äžéšã§ãã XãµãŒããŒãå®è¡ãããŠããªãå Žåã次ã®ã³ãã³ãã䜿çšããŠãããããããããããããã¬ããŒããçæã§ããŸãã
sealert -a /var/log/audit/audit.log > /path/to/mylogfile.txt
5.1ãã¡ã€ã«ã»ãã¥ãªãã£ã³ã³ããã¹ãã©ãã«ã®å€æŽã
chconã³ãã³ãã䜿çšãããšãchownããã³chmodã³ãã³ãã䜿çšããŠæšæºã®ã¢ã¯ã»ã¹å¶åŸ¡ã·ã¹ãã ã®äžéšãšããŠãã¡ã€ã«ã®ææè ãŸãã¯ãã¡ã€ã«ãžã®ã¢ã¯ã»ã¹æš©ãå€æŽã§ããã®ãšåãæ¹æ³ã§ããã¡ã€ã«ãŸãã¯ãã£ã¬ã¯ããªã®SELinuxã³ã³ããã¹ããå€æŽã§ããŸãã
ããã€ãã®äŸãèŠãŠã¿ãŸãããã
Apache WebãµãŒããŒãã·ã¹ãã ã«ã€ã³ã¹ããŒã«ãããŠããããµã€ããä¿åãããŠãããã©ã«ããŒïŒããã©ã«ãã§ã¯/ var / www / html /ïŒããããšãã°/ html /ã§å€æŽãããã®ãã£ã¬ã¯ããªã«index.htmlãã¡ã€ã«ãäœæããå¿ èŠããããšããŸãã
# mkdir /html # touch /html/index.html # ls -Z /html/index.html -rw-r--r-- root root user_u:object_r:default_t /html/index.html # ls -Z | grep html drwxr-xr-x root root user_u:object_r:default_t html
äžèšã§ã¯ãã»ãã¥ãªãã£ã³ã³ããã¹ãã®äžéšãšããŠ/ htmlãã£ã¬ã¯ããªãš/html/index.htmlãã¡ã€ã«ã®äž¡æ¹ãdefault_tåã§ããããšãããããŸãã ããã¯ãApacheãèµ·åããŠãã®ãã£ã¬ã¯ããªãŸãã¯ãã¡ã€ã«ã®æäœãéå§ããããšãããšãSELinuxãã¢ã¯ã»ã¹ãæåŠããããšãæå³ããŸãã Apacheãšããåããããã¡ã€ã«ã®æ£ããã»ãã¥ãªãã£ã³ã³ããã¹ãã¯httpd_sys_content_tã§ãããããããã¯å®å šã«æ£ããã§ãããã
ã³ã³ããã¹ããå€æŽãããã¹ãŠãæ£ããè¡ããããã©ããã確èªããŸãã
# chcon -v --type=httpd_sys_content_t /html context of /html changed to user_u:object_r:httpd_sys_content_t # chcon -v --type=httpd_sys_content_t /html/index.html context of /html/index.html changed to user_u:object_r:httpd_sys_content_t # ls -Z /html/index.html -rw-r--r-- root root user_u:object_r:httpd_sys_content_t /html/index.html # ls -Z | grep html drwxr-xr-x root root user_u:object_r:httpd_sys_content_t html
åãã¡ã€ã«ãšåãã£ã¬ã¯ããªãæåã§åŠçããå¿ èŠã¯ãããŸãããåã«ãªãã·ã§ã³ã䜿çšããŠã-Rãã£ã¬ã¯ããªãååž°çã«èµ°æ»ã§ããŸãã
# chcon -Rv --type=httpd_sys_content_t /html
ã»ãã¥ãªãã£ã³ã³ããã¹ããžã®ãã®ãããªå€æŽã¯ãåèµ·åéã§ä¿æãããŸããããã¡ã€ã«ã·ã¹ãã ã©ãã«ãå€æŽãããšãå€æŽã¯æ¶ããŸãã ã¡ã³ããã³ã¹ãšéçšã®ããã»ã¹ã§ã¯ãããã¯çããããšã§ã¯ãããŸããã ãã®ç¶æ³ã§ã®æ£ãããœãªã¥ãŒã·ã§ã³ã¯ãïŒãã¡ãããã¹ãåŸïŒè¿œå ã®ã«ãŒã«ãäœæããããŒã«ã«ã«ãŒã«ãšçµã¿åãããããšã§ãã ãããã£ãŠãåºæ¬ã«ãŒã«ãããåªå 床ãé«ããªããŸãã
ãã¡ã€ã«ã·ã¹ãã ã®ã©ãã«ãå€æŽããåŸã§ãSELinuxãæ£åžžã«åäœããããã«ãGUIã€ã³ã¿ãŒãã§ã€ã¹ã§SELinuxã管çããããŒã«ãšã³ã³ãœãŒã«ãŠãŒãã£ãªãã£semanageã®äž¡æ¹ã䜿çšã§ããŸãã
semanage fcontext -a -t httpd_sys_content_t "/html(/.*)?"
äžèšã®äŸã§ã¯ãhttpd_sys_content_tã³ã³ããã¹ãã/ htmlãã£ã¬ã¯ããªå ã®ãã¹ãŠã®ãã¡ã€ã«ã«å²ãåœãŠãŸããã
5.2 SELinuxã»ãã¥ãªãã£ã³ã³ããã¹ãã®åŸ©å ã
restoreconã³ãã³ãã䜿çšãããšãã»ãã¥ãªãã£ã³ã³ããã¹ããããã©ã«ãã§å²ãåœãŠããããã®ã«å€æŽã§ããŸãã
ç¹°ãè¿ããŸãããäŸãšããŠApache WebãµãŒããŒã䜿çšããŸãã ãŠãŒã¶ãŒãèªåã®ããŒã ãã£ã¬ã¯ããªã«ããindex.htmlãã¡ã€ã«ã®ã³ããŒãç·šéããïŒmvã³ãã³ãã䜿çšããŠïŒãµã€ããæ ŒçŽãããŠãããã£ã¬ã¯ããªïŒ/ var / www / htmlïŒã«ç§»åãããšããŸãã
ã³ããŒïŒcpã³ãã³ãïŒããå Žåããã¡ã€ã«ã»ãã¥ãªãã£ã³ã³ããã¹ãã¯å®å ãã£ã¬ã¯ããªã³ã³ããã¹ããšäžèŽãã移åäžã¯ã»ãã¥ãªãã£ã³ã³ããã¹ãããœãŒã¹ã³ã³ããã¹ããšäžèŽããããšã«æ³šæããŠãã ããã ãã¡ãããchconã³ãã³ãã䜿çšããŠã»ãã¥ãªãã£ã³ã³ããã¹ããå€æŽã§ããŸããã移åãããã¡ã€ã«ã¯/ var / www / htmlãã£ã¬ã¯ããªã«ããããããã®ãã£ã¬ã¯ããªå ã®ãã¹ãŠã®ãã¡ã€ã«ã®ã³ã³ããã¹ãèšå®ãåçŽã«åŸ©å ã§ããŸãã
index.htmlãã¡ã€ã«ã®ã³ã³ããã¹ãã®ã¿ã埩å ããã«ã¯ã次ã®ã³ãã³ãã䜿çšã§ããŸãã
# restorecon -v /var/www/html/index.html
ãã£ã¬ã¯ããªå šäœãååž°çã«ãã©ããŒã¹ããããã«å«ãŸãããã¹ãŠã®ãã¡ã€ã«ã®ã³ã³ããã¹ããå€æŽããå Žåã¯ã次ã®ã³ãã³ãã䜿çšããŸãã
# restorecon -Rv /var/www/html
5.3ãã¡ã€ã«ã·ã¹ãã å šäœã®ã©ãã«ã®å€æŽã
ãã¡ã€ã«ã·ã¹ãã å šäœã«ã»ãã¥ãªãã£ã©ãã«ãåã€ã³ã¹ããŒã«ããå¿ èŠãããå ŽåããããŸãã ã»ãšãã©ã®å Žåããã®æäœã¯ãã·ã¹ãã ããã°ãããªãã«ãªã£ãåŸãSELinuxãåã³ãªã³ã«ãªã£ããšãã«å®è¡ãããŸãã ããã¯ãããªã·ãŒç®¡çã®ã¿ã€ããå³æ Œã«å€æŽããå Žåã«ãå¿ èŠã§ãïŒãã®å Žåããã¹ãŠã®ããã»ã¹ã¯ç¬èªã®ç¹å¥ãªãã¡ã€ã³ã§åäœããunconfined_tãã¡ã€ã³ã§ã¯èª°ãåäœã§ããŸããïŒã
次åã®åèµ·åæã«ãã¡ã€ã«ã·ã¹ãã ãèªåçã«åé åžããã«ã¯ã次ã®ã³ãã³ããå ¥åããŸãã
# touch /.autorelabel # reboot
å Žåã«ãã£ãŠã¯ãèªååããŒãã£ã·ã§ã³åå²ãæ©èœããªãããšããããŸãïŒã»ãšãã©ã®å ŽåãSELinuxã·ã¹ãã ããªãã«ãããã£ã¹ããªãã¥ãŒã·ã§ã³ãæŽæ°ãããå ŽåïŒã ãã®å Žåã次ã®ã³ãã³ãã䜿çšããŸãã
# genhomedircon # touch /.autorelabel # reboot
5.4ããŒããžã®ã¢ã¯ã»ã¹ã®æäŸã
å€ãã®å ŽåãApacheã®ãããªãµãŒãã¹ãéæšæºããŒãã§ãªãã¹ã³ããçä¿¡æ¥ç¶ãåãå ¥ããããšãã§ããããã«ãããã§ãã åºæ¬çãªSELinuxããªã·ãŒã䜿çšãããšããµãŒãã¹ã«ãã£ãããšæ¥ç¶ãããŠããäºåå®çŸ©ãããããŒãã«ã®ã¿ã¢ã¯ã»ã¹ã§ããŸãã ApacheãããŒã81ã§ãªãã¹ã³ããããã«ããããšããŸãã ãã®å Žåãsemanageã³ãã³ãã䜿çšããŠã«ãŒã«ãè¿œå ããå¿ èŠããããŸãã
# semanage port -a -t http_port_t -p tcp 81
SELinuxãã¢ã¯ã»ã¹ãæäŸããããŒãã®å®å šãªãªã¹ãã¯ã次ã®ããã«è¡šç€ºã§ããŸãã
# semanage port -l
ããã¥ã¢ã«ã®ç¬¬2éšã§ã¯ãã·ã¹ãã ããªã·ãŒãæè»ã«æ§æããæ©èœã瀺ããŸãã