Chefã§ã®MySQLãã¹ã¯ã¼ãã®æ±ã
opscodeã®ãªãã¸ããªã«ããMySQLã®cookbookã§ã¯ãrootã¦ã¼ã¶ãã¬ããªã±ã¼ã·ã§ã³ç¨ã®ã¦ã¼ã¶ã®ãã¹ã¯ã¼ããã©ã³ãã ã«çæãã¦è¨å®ãã¦ããã
opscode ã® recipe ã®ç¹å¾´
ãã®ã©ã³ãã ã¨ããç¹ãã«ãã¼ããã¹ãããã¾ãä»çµã¿ãçµã¿è¾¼ã¾ãã¦ããã
ãã¹ã¯ã¼ããè¨å®ããã¨ããã¯
node.set_unless['mysql']['server_root_password'] = secure_password
ã¨ãã£ãå½¢ã§ãattributeã«è¨å®ããã¦ããªãå ´åã¯ã©ã³ãã ã«çæããã¨ããäºããã¦ã2度ç®ä»¥éãåããã¹ã¯ã¼ãã¨ãªãããã«ãªã£ã¦ããã
2åç®ä»¥éãåããã¹ã¯ã¼ããä¿è¨¼ããããã«ãããã²ã¨ã¤ã®æã
unless Chef::Config[:solo] ruby_block "save node data" do block do node.save end action :create end end
ããã® node.save ã¨ãããã¤ã
æ®éã§ããã°ãrecipe(run_list)ã®å®è¡ããã¹ã¦å®äºããã¾ã§ã¯attributeããµã¼ãã«ä¿åãããªããã ãã©ããã®ã¡ã½ããã使ããã¨ã§ãå³æã«ä¿åããããããã§ãä¸ãä¸rootã®ãã¹ã¯ã¼ããè¨å®ããããã¨ã®ã©ããã§ã³ã±ã¦ããåããã¹ã¯ã¼ãã§è¨å®ãç¶ãããã¨ãã§ãã(ä¸ã®ã³ã¼ãã«ããããã«chef-soloã®ã¨ãã¯å®è¡ãããªããã©)ãã¾ããmasterã¯éä¸ã§ã³ã±ããã©ãã¹ã¬ã¼ãã¯ããã§è¨å®ããã(ã§ããã)ã§ããããã¹ã¯ã¼ãã使ã£ã¦ã»ããã¢ããã ãã¯ç¶ãããã¨ãã§ããã
ããã¯ããèããããä»çµã¿ã§ãããã
Encrypted Data Bag
ãã ãã©ã³ãã ã§ããã°æ¨æ¸¬ããã¥ããã¦ãããããããªããã©ã好ããªãã¹ã¯ã¼ããè¨å®ãããããã¢ããªããã®ã¢ã¯ã»ã¹ãèããã¨ãã¹ã¦ã®ãµã¼ãã§ã¢ããªç¨ã¦ã¼ã¶ã¯å ±éã«ãã¦ããããã¨ãã£ãè¦æããããã¾ããæä¾ããã¦ããrecipeã®ã¾ã¾ã ã£ããattributeã«ãã®ã¾ã¾è¨å®ãã¦ãã¾ãã¨ãå¹³æã®ãã¹ã¯ã¼ããattributeã®ä¸è¦§ãã確èªã§ãã¦ãã¾ãã
ãããªæã«ä¾¿å©ãªã®ããEncrypted Data Bagã¨ããå¹³æã§ä¿åããããªããã¼ã¿ãChefã«ä¿æãã¦ããããã®æ©æ§ãEncrypted Data Bag ã使ãããã«å¿
è¦ãªã®ã¯encrepted_data_bag_secretã¨å¼ã°ããå
±ééµã ãã
â»ãã£ã¦ããã¨ã¯Opscodeã®ãµã¤ãã«æ¸ããã¦ãããã¨ã¨å
¨ãåãã§ãã
å ±ééµã®ä½æ
# openssl rand -base64 512 | tr -d '\r\n' > /etc/chef/encrypted_data_bag_secret
ãããEncrypted Data Bagså©ç¨ããåã¯ã©ã¤ã¢ã³ãã¨å ±æãããå ±ææ¹æ³ã¯ååã»ããã¢ããã§ããã°ãknifeã³ãã³ãã®bootstrapã§æå®ãã¦ãããã°è¯ãããã®æ¹æ³ã¯å¾ã»ã©ã
knifeã³ãã³ãã§æå·åããããã¼ã¿ãdata bagsã«ä¿å
passwordã¨ããdata bagã«mysqlã¨ããé ç®ãä½æãã¾ããããã§æå®ããmysqlã¨ããã®ã¯ãdata bagã®IDã¨ãªããããã¯æå·åããã¾ããã
# knife data bag create --secret-file /etc/chef/encrypted_data_bag_secret passwords mysql [editorãéãã®ã§ä»¥ä¸ã®ããã«å ¥åãã¦ä¿å] { "id": "mysql", "user": "root", "pass": "your_password" }
â»EDITORç°å¢å¤æ°ãè¨å®ãã¦ããªãã¨Errorã«ãªãã¾ãã
ä½æããdata bagã確èªãã¦ã¿ã¾ãããã
# knife data bag show passwords mysql { "id": "mysql", "pass": "trywgFA6R70NO28PNhMpGhEvKBZuxouemnbnAUQsUyo=\n", "user": "e/p+8WJYVHY9fHcEgAAReg==\n" }
userã¨passãæå·åããã¦ä¿åããã¦ãã¾ãã
ã§ã¯ã復å·åãã¦è¡¨ç¤ºãã¦ã¿ã¾ãã
# knife data bag show --secret-file /etc/chef/encrypted_data_bag_secret passwords mysql { "id": "mysql", "user": "root", "pass": "your_password" }
å ç¨å ¥åãããã®ã表示ããã¾ããã
Recipeãã Encrypted Data Bagã®ãã¼ã¿ãå¼ã³åºã
å®éã« recipe ããdata bagã®å¤ãå¼ã¶ã«ã¯ã以ä¸ã®ãããªæãã«ãã¦ããã¾ãã
å ±ééµãç´æ¥æå®ããå ´å
mysql_data = Chef::EncryptedDataBagItem.load("passwords", "mysql", secret) user = mysql_data["user"] password =mysql_data["pass"]
å ±ééµãã¡ã¤ã«ãããã©ã«ãã® /etc/chef/encrypted_data_bag_secret ã«é ç½®ããã¦ããå ´åã¯secretãæå®ããªãã¦ãOK
mysql_data = Chef::EncryptedDataBagItem.load("passwords", "mysql") user = mysql_data["user"] password =mysql_data["pass"]
ããã§ãã¦ã¼ã¶åããã¹ã¯ã¼ãã node['mysql']['user'] ã¨ãã£ã¦ãã¾ãã¨ããã£ããæå·åãã¦ä¿åããã¦ããã¦ã¼ã¶åã¨ãã¹ã¯ã¼ããå¹³æã§attributeã«ç»é²ããã¦ãã¾ãã¾ãã®ã§ããããã»ããããã¨æãã¾ããdata bagã«ä¿åããã¦ããã®ã§ã次å以éã«å¤ããã¨ããäºãç¡ãã§ãããã
recipeå ã§å®ç¾©ãããã¼ã«ã«å¤æ°ã®ã¾ã¾ã ã¨ãã³ãã¬ã¼ãã«æ¸¡ããªãã®ã§ãtemplateãªã½ã¼ã¹ã®ä¸ã§ä»¥ä¸ã®ããã«å®ç¾©ããã°ãã³ãã¬ã¼ãå ã§å¼ã³åºããã
template "hoge" do source "hoge.erb" ... variables( :user => user, :pass => pass ) end
ããã§ãã§ããattributeã«å¹³æã®ãã¹ã¯ã¼ããç»é²ããããã¨ãªããèªåã®å¥½ã¿ã®ãã¹ã¯ã¼ããè¨å®åºæ¥ã¾ããã
bootstrap 㧠encrypted_data_bag_secret ã渡ã
ååã»ããã¢ããã®ãµã¼ãã®å ´åã«ã¯ãvalidation.pemãchef_server_urlãæ°è¦ã¯ã©ã¤ã¢ã³ãã«è¨å®ããããã« bootstrap ã®ä»çµã¿ãå©ç¨ããããã®ä¸ã§ãencrypted data bagã®å ±ééµãã»ããã¢ãããããµã¼ãã«é ç½®ãããã¨ãã§ããã
以ä¸ã®ããã«bootstrapãã¡ã¤ã«ã«æ¸ãã
( cat <<'EOP' <%= encrypted_data_bag_secret %> EOP ) > /etc/chef/encrypted_data_bag_secret
encrypted_data_bag_secret ãªã©ãbootstrap ã§ä½¿ç¨ãããå¤ãªã©ã¯ãknifeãå®è¡ãããã¼ãã®knife.rbã«è¨å®ããã¦ãããã®ãå©ç¨ãããããã®ãããencrypted_data_bag_secretãã¡ã¤ã«ã®å ´æãknife.rbã«æå®ãã¦ããå¿ è¦ãããã
encrypted_data_bag_secret "/etc/chef/encrypted_data_bag_secret"
ããã§ãknifeã³ãã³ãããbootstrapãã¡ã¤ã«ããã¦åæå®è¡ãããã°ãrecipeãå®è¡ããã¯ã©ã¤ã¢ã³ãã§ãåé¡ãªãdata bagã復å·åã§ããã
(追è¨:2012-02-12 16:25) recipeå ã®ãã¼ã«ã«å¤æ°ããã³ãã¬ã¼ãã§ä½¿ãããã®è¨è¿°ã追è¨ã