Apple Sandbox(Seatbelt)ãã»ã»ã»å¼·ãããã¦ãããã ï¼
ãã®è¨äºã¯ã«ã¼ãã«/VM Advent Calendar 2011ã®è¨äºã§ãï¼
åæ¸ã
ã©ããï¼ãµã³ãããã¯ã¹èããªid:yuzuharaã§ãï¼
ä»å¹´ã¯ã¿ããªå¤§å¥½ãMacã«æ¨æºæè¼ããã¦ããApple Sandboxã®è©±ããã¦ã¿ããã¨æãã¾ã
ãµã³ãããã¯ã¹ã£ã¦ããã¨ï¼ã³ã³ããã¹ãã«ãã£ã¦ããããæå³ãå¤ããã¾ãï¼
ããã®è¨äºã§ãããµã³ãããã¯ã¹ã¯ï¼”OSã¬ãã«ã®å®è¡æã¢ããªã±ã¼ã·ã§ã³ã®éé¢ãè¡ãæ©æ§”ã®ãã¨ãããã¾ãï¼éé¢ã¨ããã®ã¯ï¼ããã°ã©ã ãå®è¡ããã¨OSã管çãããªã½ã¼ã¹ã®ãã¹ã¦ãå©ç¨ä¸å¯è½ãªç¶æ ã§èµ·åããã¨ããæãã§ãï¼ãã®ç¶æ ããï¼ã»ãã¥ãªãã£ããªã·ã¼ã«ããæä½éã®ãªã½ã¼ã¹ã®å©ç¨ã許å¯ãã¦ããã®ããµã³ãããã¯ã¹ã®åºæ¬çãªå©ç¨æ¹æ³ã¨ãªãã¾ãï¼
ãããªæãï¼
ããµã³ãããã¯ã¹ã¯ï¼ãµã³ãããã¯ã¹ä¸ã§å®è¡ããã¢ããªã±ã¼ã·ã§ã³ãï¼ãããããã»ãã¥ãªãã£ããªã·ã¼ã«æ¸ããããªã½ã¼ã¹ã«ããã¢ã¯ã»ã¹åºæ¥ãªããã¾ãï¼ã¢ããªã±ã¼ã·ã§ã³ã«èå¼±æ§ãããï¼ãã®æ¨©éãä¹ã£åãããã¨ãã§ãï¼ãããããè¨è¿°ããã»ãã¥ãªãã£ããªã·ã¼ã®ç¯å²ã«ããå¤æ´ããäºãåºæ¥ã¾ããï¼
ã»ã»ã»ã¾ãï¼ãã®ã»ãã¥ãªãã£ããªã·ã¼ãæ¸ãã®ãé£ãããã§ããã©ãï¼
ãOSã¬ãã«ã®ã¢ããªã±ã¼ã·ã§ã³ã®éé¢ã¨ããã°ï¼ Daniel Walshãããä½ã£ãSELinux SandboxãFedora14ããå©ç¨å¯è½ã«ãªã£ã¦ãã¾ãï¼ãã®ä¸èº«ã¯ï¼sandboxç¨ã®type ã¨ï¼labelã®ç®¡çï¼ç¶æ³ã«ãã£ã¦labelãå¤æ´ï¼ãè¡ããã¼ã«ã§ãï¼ãã¼ã¹ã«ãªã£ã¦ããå¼·å¶ã¢ã¯ã»ã¹å¶å¾¡ã¯ï¼çããããã¤ããã¤ãçã£å ã«Disabledã«ãã¦ãã¾ãSELinuxã§ãï¼
ãã¾ãã©ããçããï¼SELinux Sandboxããªãã£ã¡ãããã§ããããã©ã»ã»ã»
Apple Sandboxã¨ã¯
ãMac OSX 10.6(Snow Leopard)ããæè¼ããã¦ããï¼ã¢ããªã±ã¼ã·ã§ã³ç¨ãµã³ãããã¯ã¹ã§ãï¼"Seatbelt”ã¨ããååã§éçºãé²ãããã¦ããï¼ãã¡ãã®ååãç¥ã£ã¦ãã人ãå¤ããã¨æãã¾ãï¼
ããã®ãã¼ã¹ã«ãªã£ã¦ããã®ã¯ï¼Trusted BSD Projectã§éçºãããMAC Frameworkã§ãï¼Trusted BSDã¯ã¢ã¡ãªã«å½é²ç·çã®ã»ãã¥ãªãã£ã«é¢ããã³ã³ãã¥ã¼ã¿ã¼å°å ¥åºæºï¼Common Criteriaï¼ã«BSDãé©å¿ããããã®ã»ãã¥ãªãã£æ©è½ç¾¤ã§ããï¼
Apple Sandboxã®ç°¡åãªä½¿ãæ¹
ãã¨ãããã使ã£ã¦ã¿ã¾ãããï¼
ãçããã®Macï¼Lionï¼ã«ã¯ï¼æ¢ã«ãã®Apple Sandboxã¯çµã¿è¾¼ã¾ãã¦ãã¾ãï¼ã¤ãã§ã«ããã¨iOSããã¤ã¹ã«ãï¼ãµã³ãããã¯ã¹ã使ã£ã¦ã¢ããªã±ã¼ã·ã§ã³ãlaunchããã«ã¯ï¼/usr/bin/sandbox-execã¨ããã³ãã³ããå©ç¨ãã¾ãï¼
ãsandbox-execã§ã¯ï¼ã»ãã¥ãªãã£ããªã·ã¼ã®ãã¨ãprofileã¨èªãã§ãã¾ãï¼ããã©ã«ãã§ç¨æããã¦ããprofileãæå®ããã¨ãã¯ï¼"-n"ã§æå®ãã¾ãï¼èªåèªèº«ã§profileãç¨æããå ´åã¯ï¼ãã¡ã¤ã«ã«è¨è¿°ãï¼.sbã¨ããæ¡å¼µåã§ä¿åãã¦ããã¨ããããã§ãï¼ãã¡ã¤ã«ãæå®ããã¨ãã¯-f hoge.sbï¼
%sandbox-exec -n no-internet curl http://www.gentoo.org/
curl: (7) Failed to connect to 89.16.167.134: Operation not permitted
ã¨ã¾ãï¼ã¤ã³ã¿ã¼ãããã«ç¹ããã«ã¨ã©ã¼ã¨ãªãã¾ãï¼
ãªãã·ã§ã³ã«ã¤ãã¦ã¯ï¼man sandbox-execãman sandbox_initã§ç¢ºèªã§ãã¾ãï¼
ããã£ã¨ç´¹ä»ï¼
- no-internet
ããTCP/IPãå©ç¨ä¸å¯
- no-networking
ããã½ã±ãããã¼ã¹ã®å ¨ã¦ã®éä¿¡ãå©ç¨ä¸å¯
- no-write
ãã¢ããªã±ã¼ã·ã§ã³ã¯ãããªããã¡ã¤ã«ã«ãæ¸ãè¾¼ã¿ãã§ããªã
- no-write-except-temporary
ãã¢ããªã±ã¼ã·ã§ã³ã¯ä¸é¨ï¼/var/tmpã_CS_DAR-WIN_USER_TEMP_DIRã«è¨å®ããããã£ã¬ã¯ããª)ã®ãã£ã¬ã¯ããªä»¥å¤ã«æ¸ãè¾¼ã¿ãã§ããªã
- pure-computation
ãã¢ããªã±ã¼ã·ã§ã³ã¯ä¸åOSã®ãªã½ã¼ã¹ã»ãµã¼ãã¹ãå©ç¨ãããã¨ãã§ããªã
ãããã«ï¼æ¸ãè¾¼ã¿ç¦æ¢ãããã¡ã¤ã«ã使ã£ã¦ï¼gentooã®ããããã¼ã¸ããã¦ã³ãã¼ããã¦ã¿ã¾ããï¼
% sandbox-exec -n no-write curl -o /var/tmp/gentoo http://www.gentoo.org/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Warning: Failed to create the file /var/tmp/gentoo: Operation not permitted
5 47502 5 2598 0 0 2062 0 0:00:23 0:00:01 0:00:22 5575
curl: (23) Failed writing body (0 != 2598)
アアアッï¼æ¸ãè¾¼ããªãã£ã¦æããã¾ããï¼
ä»åº¦ã¯ï¼/var/tmpã«æ¸ãè¾¼ã¿ã許å¯ããããªã·ã¼ãç¨ãã¦ï¼/var/tmp/gentooã¨ãããã¡ã¤ã«ã«æ¸ãè¾¼ã¿ã試ã¿ã¾ãï¼
% sandbox-exec -n no-write-except-temporary curl -o /var/tmp/gentoo http://www.gentoo.org/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 47502 100 47502 0 0 32532 0 0:00:01 0:00:01 --:--:-- 46938
[bachi@lucchini] % head /var/tmp/gentoo
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
ãï¼ä¿åã§ãã¾ãããï¼
ç°¡åãªä½¿ãæ¹ã¯ããã§ãï¼
ãããã¡ã¤ã«ã®æ¸ãæ¹
ãããã¡ã¤ã«ã¯ãããªæ¹ã«æ¸ãã¦ããã¾ãï¼ã©ããSå¼ã£ã½ãã»ã»ã»
(version 1)
(allow default)
(deny file-write* (regex #"/var/tmp/*$") )
ããªã·ã¼è¨è¿°ã®åºæ¬ã¯ï¼ãããããã¹åãã¼ã¹ã¨ãªã£ã¦ã¾ãï¼
ããï¼ã«ã¼ãã«ã¢ã¸ã¥ã¼ã«ã®ä¸ã«æ£è¦è¡¨ç¾ã¨ã³ã¸ã³ãå ¥ã£ã¦ãã¦ï¼ã«ã¼ãã«ã®ä¸ã§ãã®ã¾ã¾è©ä¾¡ãããã¿ããã§ãï¼
ã»ï¼ã»ãã¥ãªãã£çã«å¤§ä¸å¤«ãªãã ãããã»ã»ã»
ï¼TOMOYOãæ£è¦è¡¨ç¾ã«ãã°ããã£ãã¨ããããã¾ããããã»ã»ï¼
ãã®ãããã¡ã¤ã«ã¯ï¼/var/tmp/以ä¸ã«ãã¡ã¤ã«ãä½æã§ããªãããããã«ããªã·ã¼ãæ¸ãã¦ã¿ã¾ããï¼
ãã³ãã¯ï¼ããã©ã«ãã§ç¦æ¢ã¨æ¸ãããã®ã§ããã»ã»ã»ãã®ããã«ã¯ï¼ããã°ã©ã ã®æ£å¸¸ãªåä½ããã¹ã¦è¨è¿°ããªããã°ãªãã¾ããï¼
ãã®ä½æ¥ã¯ã¨ã¦ã大å¤ã»ã»ã»ã»
ã¨ï¼ãã®å¤§å¤ãªä½æ¥ãç°¡åã«ããæ¹æ³ãããããã§ãï¼
sandbox-simplify ã¨ããã³ãã³ãã¯ï¼traceã³ãã³ãã§åã£ãããã»ã¹ã®ãã¬ã¼ã¹ãã°ã使ã£ã¦ï¼ãããã¡ã¤ã«ã®ä¸å°ãä½ã£ã¦ããã¾ãï¼
â»traceã«ã¤ãã¦ã¯æéãç¡ãã£ãã®ã§ä»åº¦å度ã¾ã¨ãã¾ãã»ã»ã»
æ¢åã®ãããã¡ã¤ã«ãè¦ã¦ã¿ãã
Lion ã§ã¯ï¼/System/Library/Sandbox/Profiles ã/usr/share/sandboxã®ä¸ã«ãããã¡ã¤ã«ãããããããã¾ãï¼èå³ããã人ã¯ã®ããã¦ã¿ãã¨è¯ãã¨æãã¾ãï¼
ããã»ã¹ã®åºæ¬çãªæ¯ãèãï¼ã©ã¤ãã©ãªããã°å¨ãï¼ã«ã¤ãã¦ã¯ï¼/System/Library/Sandbox/Profiles/bsd.sbã¨ãããã¡ã¤ã«ãããã¾ãï¼
èªåã§ã«ã¹ã¿ã ãããã¡ã¤ã«ãä½ãã¨ãã¯ï¼ã¾ããã®bsd.sbãimportããã¨ããã¨æããã¾ãï¼
ã©ããªããã°ã©ã ããµã³ãããã¯ã¹åããã¦ããã®ï¼
activity monitorã§ç¢ºèªãããã¨ãåºæ¥ã¾ãï¼ããã©ã«ãã§ã¯è¡¨ç¤ºããã¦ããªãã®ã§ï¼é ç®ãå³ã¯ãªãã¯→表示ï¼ï¼
æåãªã®ã¯Google Chromeã§ããï¼
ãã¨ã¯Appleã®ããã©ã«ãã¤ã³ã¹ãã¼ã«ã¢ããªã¯å²ã¨ãµã³ãããã¯ã¹åããã¦ããããã§ãï¼
ã¾ã¨ã
ãã£ã¨ã§ããï¼Apple Sandboxã«ã¤ãã¦ç´¹ä»ãã¾ããï¼
ä½è£ãããã°ï¼ä»åº¦ã¯kernelå é¨ãèªãã§ã¿ããã¨æãã¾ãï¼
ããã§ã¯ï¼çããè¯ããå¹´ãï¼
åèæç®