GAEã®SSL証ææ¸æ´æ°ãLetâs Encryptã§å®å ¨èªååãã
è¿½è¨ 2017/7/4ãgithubã«ãï½
github.com
å é±ã¯ä¼ç¤¾ã®ç¤¾é·è³ç ä¿®ã§ãµã³ãã©ã³ã·ã¹ã³ãã·ãªã³ã³ãã¬ã¼ã«è¡ã£ã¦ãã¦æ¸ããããã¨ã¯å±±ã»ã©ãããã©ãå¿ãã¦ãã¾ããããªä½æ¥ã¡ã¢ã
ç ä¿®ä¸ã«è¨¼ææ¸ã®æéãåãã¦ãã¾ãããªã¢ã¼ãã§æ´æ°ããã®ãé常ã«ã¹ãã¬ã¹ã ã£ãã®ã§ãSSL証ææ¸ãèªååãããã
以åãèãããã©ãGAEã®è¨¼ææ¸ã¯ã¾ã gcloudã³ãã³ãããã¯å¤æ´ã§ããªãã£ãã®ã§è«¦ããã
調ã¹ãªããã¦ã¿ãã¨ã2017/6/14ã®gcloudã®ã¢ãããã¼ãã§ãã³ãã³ãã©ã¤ã³ããGAEç¨ã®SSL証ææ¸ãã¢ããã§ããããã«ãªã£ã¦ãå®ç¾ã§ããããã«ãªã£ãã®ã§æ©éã¤ãã£ã¦ã¿ãã
ã¨ããããã³ãã³ãä¸çºã§
TOKENã®ä½æ
DNSã®å¤æ´
AppEngineã®è¨¼ææ¸ãã¢ãããã¼ã
ã¾ã§åããã
ãã¨cronã§åãã¦ã念ã®ããæå¹æéã®ç£è¦ãä»ããã°å®ç§ï¼
ç£è¦ã¯ãããã©ã«ãã§ã¯æéã¾ã§30æ¥ä»¥ä¸ãã£ããæ´æ°ãããªãã®ã§ãæéã30æ¥ãåã£ãã¿ã¤ãã³ã°ã§ã¢ã©ã¼ãåºãã°ä½ããã®åå ã§æ¢ã¾ã£ã¦ããã®ã確èªã§ããã¯ãã
証ææ¸ã«ã¯Let's Encrypt
letsencrypt.org
ããåãã¯ãããªãã¿ã®âDNSèªè¨¼ãã§ããdehydratedã使ãã
GitHub - lukas2511/dehydrated: letsencrypt/acme client implemented as a shell-script – just add water
åæã¨ãã¦ä½¿ããã¡ã¤ã³ã¯Cloud DNSã«å ¥ãã¦ããå¿ è¦ããããã¾ããå®è¡ã¦ã¼ã¶ã¼ã¯Google Cloud SDKãã¤ã³ã¹ãã¼ã«ãã¦ãææ°ã®gcloudã³ãã³ãã使ããããã«ãã¦ãããGAE使ã£ã¦ãç°å¢ã¨åãã§ããã°å¤§ä¸å¤«ã ã¨ã¯æããã©ã
å ã«ãªããã¡ã¤ã³ï¼bizocean.jpï¼ã¯ãAWS Route53ã§ç®¡çãã¦ãããã©ãä»å使ããµããã¡ã¤ã³ï¼s.bizocean.jpï¼ã®NSã¬ã³ã¼ãã ãCloud DNSã®ãã®ã«åãã¦ããã°ãåé¡ãªãåããã
ãªãªã¸ãã«ã®hook.shããã¼ã¹ã«ä½ããã¨ããããå¤æ´ãå¿ è¦ãããªã®ã¯é ã«ã¾ã¨ããã
gae_hook.sh
#!/usr/bin/env bash DNS_PROJECT="oceanus-dev" GAE_PROJECT="oceanus-gae" CERT_ID=`gcloud beta app --project $GAE_PROJECT ssl-certificates list | awk 'NR==2 {print $1}'` CERT_NAME="letsencrypt-auto`date "+%Y%m%d"`" TARGET_DOMAIN="s.bizocean.jp" ZONE_NAME="s-bizocean-jp" ACME_TTL=60 SLEEP_SECOND=60 function deploy_challenge { local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" if [ $DOMAIN = $TARGET_DOMAIN ];then echo "Set TXT record of _acme-challenge.$DOMAIN to $TOKEN_VALUE" echo "dns update start" gcloud dns --project=$DNS_PROJECT record-sets transaction start -z=${ZONE_NAME} gcloud dns --project=$DNS_PROJECT record-sets transaction remove \ `gcloud --project=$DNS_PROJECT dns record-sets list -z=${ZONE_NAME} --name="_acme-challenge.${DOMAIN}." | awk 'NR==2 {print $4}'` \ -z=${ZONE_NAME} --name="_acme-challenge.${DOMAIN}." --type=TXT --ttl=${ACME_TTL} gcloud dns --project=$DNS_PROJECT record-sets transaction add $TOKEN_VALUE -z=${ZONE_NAME} --name="_acme-challenge.${DOMAIN}." --type=TXT --ttl=${ACME_TTL} gcloud dns --project=$DNS_PROJECT record-sets transaction execute -z=${ZONE_NAME} echo "dns update end sleep ${SLEEP_SECOND}" sleep $SLEEP_SECOND else echo "Don't match $TARGET_DOMAIN and $DOMAIN" echo "Set TXT record of _acme-challenge.$DOMAIN to $TOKEN_VALUE manually" read fi } function clean_challenge { local DOMAIN="${1}" TOKEN_FILENAME="${2}" TOKEN_VALUE="${3}" } function deploy_cert { local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" TIMESTAMP="${6}" if [ $DOMAIN = $TARGET_DOMAIN ];then echo "update ssl cert start" gcloud beta app --project ${GAE_PROJECT} ssl-certificates update $CERT_ID \ --display-name=$CERT_NAME \ --certificate=$FULLCHAINFILE \ --private-key=$KEYFILE else echo "Don't match $TARGET_DOMAIN and $DOMAIN" fi } function unchanged_cert { local DOMAIN="${1}" KEYFILE="${2}" CERTFILE="${3}" FULLCHAINFILE="${4}" CHAINFILE="${5}" } HANDLER=$1; shift; $HANDLER $@
å ¨ä½çã«ã²ãããgcloudã³ãã³ãã並ã¹ãã ãã§æ±ãã
æ´æ°å¾ã®sleepã¯10ç§ç¨åº¦ã ã¨å®å®ããªãã£ãã®ã§ãé·ãã«60ç§ã¨ãããTTLã¨åããã¦ãã£ã¨çãã§ãããããããªãããããã¯ã¹ãã¼ã¿ã¹ã確èªãã¦ãããããã
ãã¡ã¤ã³ãã§ãã¯ä»¥å¤ãä¾å¤å¦çããã£ã¦ãªãããããã¯æ»æ´»ç£è¦ã®æ¹ã«ä»»ããã¤ããã
次ã«å¿
è¦ãªè¨å®ã
éµã®é·ãã¯ããã©ã4096ãGAEã¯2048以ä¸ãã対å¿ãã¦ããªãã®ã§ã¢ããæã«æãããã
å®è¡ãããã£ã¬ã¯ããªã«configã¨ãããã®ã¾ã¾ã®ååã®ãã¡ã¤ã«ãä½æãã¦å¤æ´ããã
config
KEYSIZE="2048"
å®è¡ã³ãã³ãã-xã追å ããã°æ®ãæéã«ãããããå¼·å¶å®æã«ã¢ãããã¼ãããã
./dehydrated -c -d s.bizocean.jp --challenge dns-01 -k ./gae_hook.sh
ãããªæãã§å®è¡ãããã°ãï½ã
éä¸ã§ãããã¨ãã©ã³ã¶ã¯ã·ã§ã³ãæ®ã£ã¡ããã®ã§å®è¡åã«abortããæ¹ããããããããªãã
# INFO: Using main config file /home/yu_yamazaki/letsencrypt/dehydrated/config Processing s.bizocean.jp + Checking domain name(s) of existing cert... unchanged. + Checking expire date of existing cert... + Valid till Oct 2 00:26:00 2017 GMT (Longer than 30 days). Ignoring because renew was forced! + Signing domains... + Generating private key... + Generating signing request... + Requesting challenge for s.bizocean.jp... Set TXT record of _acme-challenge.s.bizocean.jp to RsMwB34gCgdfmks-2LGpsH0MVpBZVYkdveANiAcTXlk dns update start ERROR: (gcloud.dns.record-sets.transaction.start) transaction already exists at [transaction.yaml] Record removal appended to transaction at [transaction.yaml]. Record addition appended to transaction at [transaction.yaml]. Executed transaction [transaction.yaml] for managed-zone [s-bizocean-jp]. Created [https://www.googleapis.com/dns/v1/projects/oceanus-dev/managedZones/s-bizocean-jp/changes/21]. ID START_TIME STATUS 21 2017-07-04T01:44:46.816Z pending dns update end sleep 60 + Responding to challenge for s.bizocean.jp... + Challenge is valid! + Requesting certificate... + Checking certificate... + Done! + Creating fullchain.pem... + Done!
æéå ã ã£ããä½ãããã«çµäºãã
% ./dehydrated -c -d s.bizocean.jp --challenge dns-01 -k ./gae_hook.sh # INFO: Using main config file /home/BIZOCEAN/yu_yamazaki/letsencrypt/dehydrated/config Processing s.bizocean.jp + Checking domain name(s) of existing cert... unchanged. + Checking expire date of existing cert... + Valid till Oct 2 00:46:00 2017 GMT (Longer than 30 days). Skipping renew!
ä»åº¦ã¯HTTPSãã¼ããã©ã³ãµã¼ã®æ¹ãèªååããã
ããã°ã©ãã³ã° Google App Engine
- ä½è : Dan Sanderson,çå·ç«å¸
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2011/01/24
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 5人 ã¯ãªãã¯: 414å
- ãã®ååãå«ãããã° (27件) ãè¦ã
- ä½è : åç©ç¤¼æ,ç¦ç°æ½
- åºç社/ã¡ã¼ã«ã¼: ã¤ã³ãã¬ã¹R&D
- çºå£²æ¥: 2016/03/25
- ã¡ãã£ã¢: Kindleç
- ãã®ååãå«ãããã°ãè¦ã