IP 주소 제한 하에서도 certbot의 무료 SSL 인증서를 발급받는 방법
8028 단어 letsencryptcertbotroute53
개요
특정 IP 주소 만 연결 허용하는 환경에서 certbot을 사용하는 경우
certbot 서버로부터의 HTTP 요청이 차단되기 때문에
정상적인 certbot 인증이 실패하고 인증서를 발급하거나 업데이트할 수 없음
이 경우 DNS TXT 레코드에 토큰을 포함시키는 방식으로
certbot 인증을 통과할 수 있다
덧붙여서 공식 가이드 에도 기재되어 있는 내용
참고 사이트
필요한 것
이하의 조건을 만족하는 경우, IP 주소 제한하에서도 certbot에서 증명서 발행을 받을 수 있다
또한 이번에는 DNS는 route53을 이용한다.
증명서의 자동 갱신을 실행하는 방법은 aws cli를 사용해 route53의 자동 갱신을 하는 예로 기재한다.
최초 인증서 발급
certbot 설치
sudo yum install certbot python-certbot-apache
DNS 모드에서 cert를 실행하여 최초 인증서 발급
sudo certbot certonly --preferred-challenges dns-01 --authenticator manual --domain yourdomain.co.jp
위 명령을 발행하면 다음과 같이 들립니다.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for yourdomain.co.jp
-------------------------------------------------------------------------------
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
-------------------------------------------------------------------------------
(Y)es/(N)o: Y ←Yを入力
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.yourdomain.co.jp with the following value:
fpfSXH2O9HRJ...................... ←このトークンをコピーしておく
Once this is deployed,
-------------------------------------------------------------------------------
Press Enter to Continue
토큰이 표시되면 복사하고 콘솔은 Enter를 누르지 않고 이대로 둡니다.
다음으로 route53에 다음과 같은 TXT 레코드 추가

route53이 아닌 bind의 경우
dns에 bind를 사용하는 경우 다음과 같은 TXT 레코드 추가
_acme-challenge.yourdomain.co.jp. 300 IN TXT "fpfSXH2O9HRJ......................"
보충
bind9.3.1 이후에서는 밑줄을 포함하면 디폴트로 에러(bad owner name)가 된다
이 경우 다음과 같이 check-names
를 ignore로 설정해야합니다.
zone "yourdomain.co.jp" {
type master;
file "yourdomain.co.jp.zone";
check-names ignore;
};
보충 보충
원래 _acme-challenge
의 밑줄은 OK인가? 라는 것에 대해
RFC952 과 RFC1033 를 보면
sudo yum install certbot python-certbot-apache
sudo certbot certonly --preferred-challenges dns-01 --authenticator manual --domain yourdomain.co.jp
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for yourdomain.co.jp
-------------------------------------------------------------------------------
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
-------------------------------------------------------------------------------
(Y)es/(N)o: Y ←Yを入力
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.yourdomain.co.jp with the following value:
fpfSXH2O9HRJ...................... ←このトークンをコピーしておく
Once this is deployed,
-------------------------------------------------------------------------------
Press Enter to Continue
_acme-challenge.yourdomain.co.jp. 300 IN TXT "fpfSXH2O9HRJ......................"
zone "yourdomain.co.jp" {
type master;
file "yourdomain.co.jp.zone";
check-names ignore;
};
_acme-challenge.yourdmain.co.jp
라는 하위 도메인은 문제없는 것 같습니다.뱀발
이름 .com으로 도메인을 검색하는 경우 도메인 NAVI에서 위의 _acme ...를 입력하면
밑줄 점검 오류
이름 .com으로 도메인을 취득하고있는 경우는 별도로 route53 또는 DNS를 사용하여 등록하지 않으면 안되는 것 같습니다.
dig
명령으로 TXT 레코드를 볼 수 있으면 OKdig -t txt _acme-challenge.yourdomain.co.jp
; <<>> DiG 9.8.3-P1 <<>> _acme-challenge.yourdomain.co.jp any @8.8.8.8
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51300
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;_acme-challenge.yourdomain.co.jp. IN TXT
;; ANSWER SECTION:
_acme-challenge.yourdomain.co.jp. 9 IN TXT "fpfSXH2O9HRJ......................"
;; Query time: 346 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Jul 20 13:15:53 2017
;; MSG SIZE rcvd: 107
콘솔로 돌아가서 Enter를 누르면 인증이 시작되고,
잘하면 다음과 같이 표시됩니다.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/yourdomain.co.jp/fullchain.pem. Your
cert will expire on 2017-xx-xx. To obtain a new or tweaked version
of this certificate in the future, simply run certbot again. To
non-interactively renew *all* of your certificates, run "certbot
renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
이것으로
/etc/letsencrypt/live/yourdomain.co.jp/
부하에 증명서의 열쇠가 배치되기 때문에웹 서버에 설정하는 등에서 이용할 수 있다
인증서 자동 업데이트 설정
root 사용자로 실행 권장
pip 설치
curl https://bootstrap.pypa.io/get-pip.py | python
자동 업데이트를 위한 모듈 설치
pip install certbot-external-auth boto
wget https://gist.githubusercontent.com/rmarchei/98489c05f0898abe612eec916508f2bf/raw/a7f51af111c98544c0cee8739ebd0b88c39b3afa/route53.py
chmod +x route53.py
mv route53.py /usr/local/bin/
aws 액세스용 역할 만들기
AWS 콘솔에서 IAM 역할을 생성하고 액세스 키를 가져옵니다.
이때 IAM 정책에 AmazonRoute53DomainsFullAccess
를 붙인다.
awscli 설정
pip install awscli
aws configure
AWS Access Key ID [None]: xxxxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxx
Default region name [None]: us-west-2
Default output format [None]: json
인증서 업데이트 시도
지금까지의 설정이 되어 있으면 다음의 커멘드로 증명서 갱신을 할 수 있다.
--renew-by-default
option을 붙여 실행하면 증명서의 기한 관계없이 갱신한다.
이번에 갱신할 수 있을까를 시험하기 위해, 굳이 세트 하고 있다
certbot certonly \
--domain yourdomain.co.jp \
--email [email protected] \
--agree-tos \
--preferred-challenges dns \
--renew-by-default \
--text \
--configurator certbot-external-auth:out \
--certbot-external-auth:out-public-ip-logging-ok \
--certbot-external-auth:out-handler /usr/local/bin/route53.py
에러가 나오지 않으면 /etc/letsencrypt/live/yourdomain.co.jp/
부하의 키 파일이 갱신되고 있을 것.
cron에 등록
인증서 업데이트 셸 만들기
vi certbot-update.sh
--renew-by-default
대신에 --keep-until-expiring
를 붙이면
현재 인증서가 만료될 때까지 업데이트하지 않습니다.
#!/bin/bash
certbot certonly \
--domain yourdomain.co.jp \
--email [email protected] \
--agree-tos \
--preferred-challenges dns \
--keep-until-expiring \
--expand \
--text \
--configurator certbot-external-auth:out \
--certbot-external-auth:out-public-ip-logging-ok \
--certbot-external-auth:out-handler /usr/local/bin/route53.py 2> /dev/null
chmod 755 certbot-update.sh
그 후에는 작성한 쉘을 cron에 등록해 두면 OK
# every am 3:00
0 3 * * * /root/certbot-update.sh
Reference
이 문제에 관하여(IP 주소 제한 하에서도 certbot의 무료 SSL 인증서를 발급받는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/AkihiroTakamura/items/06ced4e780dc217bc1aa
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
curl https://bootstrap.pypa.io/get-pip.py | python
pip install certbot-external-auth boto
wget https://gist.githubusercontent.com/rmarchei/98489c05f0898abe612eec916508f2bf/raw/a7f51af111c98544c0cee8739ebd0b88c39b3afa/route53.py
chmod +x route53.py
mv route53.py /usr/local/bin/
pip install awscli
aws configure
AWS Access Key ID [None]: xxxxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxx
Default region name [None]: us-west-2
Default output format [None]: json
certbot certonly \
--domain yourdomain.co.jp \
--email [email protected] \
--agree-tos \
--preferred-challenges dns \
--renew-by-default \
--text \
--configurator certbot-external-auth:out \
--certbot-external-auth:out-public-ip-logging-ok \
--certbot-external-auth:out-handler /usr/local/bin/route53.py
vi certbot-update.sh
#!/bin/bash
certbot certonly \
--domain yourdomain.co.jp \
--email [email protected] \
--agree-tos \
--preferred-challenges dns \
--keep-until-expiring \
--expand \
--text \
--configurator certbot-external-auth:out \
--certbot-external-auth:out-public-ip-logging-ok \
--certbot-external-auth:out-handler /usr/local/bin/route53.py 2> /dev/null
chmod 755 certbot-update.sh
# every am 3:00
0 3 * * * /root/certbot-update.sh
Reference
이 문제에 관하여(IP 주소 제한 하에서도 certbot의 무료 SSL 인증서를 발급받는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/AkihiroTakamura/items/06ced4e780dc217bc1aa텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)