ããã«ã¡ã¯ãæè¡é¨ã®ç¦æ£® (@sora_h) ã§ãã
æè¿ã¯ç°å¢å¤æ°ã« API ãã¼ã¯ã³ã credential ã¨ãã£ãèªè¨¼æ
å ±ãå
¥ããäºãå¢ãã¦ãã¦ãã¾ãã
ãã¨ãã°ãAWS ãå©ç¨ãããã¼ã«ã§ã¯ AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
ã¨ãã£ãç°å¢å¤æ°ã«ã ãããã®å ´åã§å¯¾å¿ãã¦ãã¾ãã
ãã®ããã~/.bashrc
ã ~/.zshrc
ãªã©ã·ã§ã«ã®è¨å®ã« export ãæ¸ãã¦ãã常ã«ä½¿ããç¶æ
ã«ãã¦ããæ¹ãå¤ãã¨æãã¾ããã
ããã£ã¦å®ã¯å±éºã§ã¯ãªãã§ãããã?
ä¾ãã°ãä¸è¨ã®ãããªãªã¹ã¯ãèãããã¾ã:
- æå³ããæ
å ±ãå©ç¨ããã¦æå³ããªãå¯ä½ç¨ãçºçãã¦ãã¾ãå±éºæ§
- æ¬çªã«å¤æ´ãä¸ããã¤ããã¯ãªãã£ãããã©äºæ ãèµ·ããã¦ãã¾ãç
- æªæã®ããã¹ã¯ãªãããå®è¡ããéã«ç°å¢å¤æ°ãéä¿¡ãªã©ããã¦ãã¾ãå±éºæ§
äºæ
ãæ¼æ´©ãé²ãããã«ããçè
ã¯ããªããã»ããããå¿
è¦ã¯ãã¾ããªãã¨èãã¦ãã¾ãã
åããå人çã« aws-exec() { env AWS_ACCESS_KEY_ID=... $* }
ã®ãããªã·ã§ã«é¢æ°ãå©ç¨ãã¦ããã®ã§ããã
ãã®æ¹æ³ããã£ã¨åºããã»ããè¯ãã®ã§ã¯?ãã¨ç¤¾å
ã§æè¦ãè²°ã£ãããæ±ç¨çãªãã¼ã«ã«ãã¦ã¿ã¾ããã
大ããªç¹é·ã¯ãå¹³æã§ã¯ãªã OS X ã®ãã¼ãã§ã¼ã³ã«å¤ãä¿åããããã«ããç¹ã§ãã ããã«ãã plain text ã§æ®ããªãä¸ããã¹ãã¬ã¼ãºã®ç¢ºèªã¨ãã£ãã¢ã¯ã»ã¹ã³ã³ããã¼ã«ã調æ´ã§ããããã«ãªãã¾ããã (è¨å®æ¬¡ç¬¬ã§ãã) èªã¿åºããçºçããã¿ã¤ãã³ã°ã§ããã³ãããããäºãã§ããæå³ããªãèªã¿åºããé²ããã¨ãã§ãã¾ãã
ã¾ãããã®ãã¼ã«ãå©ç¨ãã¦æ°è»½ã«ããã¤ãã®ç°å¢å¤æ°ã®çµåã (ã¢ã«ã¦ã³ããè¨å®é¡) ãç°¡åã«åãæ¿ããªããéçºããäºãã§ããããã«ãªãã¾ããã åããµã¼ãã¹ã®ãã¼ã¯ã³ãè¤æ°åãæ¿ãããã¨ãã£ãéã«ã便å©ã ã¨æãã¾ãã
注æ
- OS X ã® keychain ãå©ç¨ãããããOS X ã®ã¿ã®ãµãã¼ãã§ã
ã¤ã³ã¹ãã¼ã«
homebrew
$ brew install https://raw.githubusercontent.com/sorah/envchain/master/brew/envchain.rb
make
$ git clone https://github.com/sorah/envchain.git $ cd envchain $ make $ make install (ãããã¯æåã§) $ cp ./envchain ~/bin/
使ãæ¹
ç°å¢å¤æ°ãã»ãããã
envchain --set <namespace> <variable name> <variable name>...
ã®ããã«å¼ã³åºãäºã§ç°å¢å¤æ°ã keychain ã«ç»é²ã§ãã¾ãã
envchain ã§ã¯è¤æ°ã®ç°å¢å¤æ°ãã»ããã¨ãã¦ç»é²ãã¦åãæ¿ãã¦å©ç¨ããäºãã§ãã¾ãã
$ envchain --set foo SECRET_TOKEN USERNAME foo.SECRET_TOKEN: foobar foo.USERNAME: alice $ envchain --set bar SECRET_TOKEN bar.SECRET_TOKEN: hogehoge
ã»ããããç°å¢å¤æ°ãå©ç¨ãã
envchain <namespace> <cmd> <arg>...
ã®ããã«å¼ã³åºãäºã§ namespace ããç»é²ãã¦ããç°å¢å¤æ°ãèªã¿è¾¼ãã§ã³ãã³ããå®è¡ããäºãã§ãã¾ãã
$ printenv SECRET_TOKEN || echo 'not found' not found $ envchain foo printenv SECRET_TOKEN foobar $ envchain foo printenv USERNAME alice $ envchain bar printenv SECRET_TOKEN foobar
ãã®ä»
envchain --set --noecho
ã envchain --set --require-passphrase
ã¨ãã£ããªãã·ã§ã³ãåå¨ãã¾ãã詳細㯠envchain
ã³ãã³ã (å¼æ°ç¡ã) ã®ãã«ããåç
§ãã¦ãã ããã
ã»ãã¥ãªãã£ã«ã¤ãã¦
ç°å¢å¤æ°ã«æ©å¯æ å ±ãå ¥ããä¸ã§ã®ã»ãã¥ãªãã£ã«é¢ãã¦ãçè ã®è¦è§£ããå人ã®ããã°ã«æ¸ããã®ã§ãã¡ããåç §ãã ãã: http://diary.sorah.jp/2014/06/05/securing-environment-variables
ä»çµã¿
OS X ã® Security framework ã«å«ã¾ãã Keychain Service ãå©ç¨ãã¦ãã¾ãã (ãªãã¡ã¬ã³ã¹)
namespace ã®åã« "envchain-" ãã¤ãããã® (ä¾: envchain-foo, envchain-bar) ã KeychainItem ã®ãµã¼ãã¹åãç°å¢å¤æ°åãã¢ã«ã¦ã³ãåã¨ãã¦ããã©ã«ãã® keychain ã«ç»é²ããããã«ãã¦ãã¾ãã
OS X ã®ãã¼ãã§ã¼ã³ã¢ã¯ã»ã¹ (/Applications/Utilities/Keychain Access.app) ããã¢ã¤ãã ãæ¢ãäºã§ç»é²ããã¦ããæ§åãè¦ãäºãã§ãã¾ãã