certbot과 route53 plugin으로 Let’s encrypt 인증서 갱신

sungyong·2020년 5월 12일
1

인프라관리

목록 보기
1/3

Phabricator를 운영중인 서버의 호스트는 AWS route53 을 name server로 사용하고 있다. 그래서 인증서 발급할 때 DNS 인증하는 방식으로 하여 DNS 값이 _acme 값을 넣어 인증받았다.
도커로 왠만한 것들은 다 올리면서, 호스트 자체는 도커를 띄우는 용도로만 제한했다. 그래서 certbot 도 호스트에 설치하는 게 아닌, docker로 가져와 실행했다.
docker pull certbot/certbot
으로 가져와, 아래처럼 docker run으로 실행했다.
docker run -it --rm --name certbot \
-v '/etc/letsencrypt:/etc/letsencrypt' \
-v '/var/lib/letsencrypt:/var/lib/letsencrypt' \
certbot/certbot certonly -d 'phabricator.helele.com' --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
막상 인증서 만료일인 3개월이 되었고, 갱신하려고 보니 하는 방법을 다 까먹었다. 구글링으로 다시 certbot 사용법부터 다시 익혀 시도했다.
➜ phabricator git:() ✗ docker run -it --rm --name certbot \

-v '/etc/letsencrypt:/etc/letsencrypt' \
-v '/var/lib/letsencrypt:/var/lib/letsencrypt' \
certbot/certbot renew --quiet --no-self-upgrade
Attempting to renew cert (phabricator.helele.com) from /etc/letsencrypt/renewal/phabricator.helele.com.conf produced an unexpected error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.'). Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/phabricator.helele.com/fullchain.pem (failure)
1 renew failure(s), 0 parse failure(s)
역시나 한방에 성공하는 법이 없다. 웹서버로 인증받은 것이 아니라 DNS로 인증받은 것으로 갱신도 DNS를 통해서 인증받아야 한다. console 들어가서 route53 값 수정하기는 영 귀찮았다.
다행히 route53 plugin이 있었다.
docker 자체도 route53 plugin이 포함된 certbot으로 받아 실행했다.
➜ phabricator git:() ✗docker pull certbot/dns-route53
docker.io/certbot/dns-route53:latest
➜ phabricator git:() ✗ docker run -it --rm --name certbot \
-v '/etc/letsencrypt:/etc/letsencrypt' \
-v '/var/lib/letsencrypt:/var/lib/letsencrypt' \
certbot/dns-route53 renew --dns-route53
Saving debug log to /var/log/letsencrypt/letsencrypt.log


Processing /etc/letsencrypt/renewal/phabricator.helele.com.conf


Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator dns-route53, Installer None
Renewing an existing certificate
Performing the following challenges:
dns-01 challenge for phabricator.helele.com
Cleaning up challenges
Attempting to renew cert (phabricator.helele.com) from /etc/letsencrypt/renewal/phabricator.helele.com.conf produced an unexpected error: Unable to locate credentials
To use certbot-dns-route53, configure credentials as described at https://boto3.readthedocs.io/en/latest/guide/configuration.html#best-practices-for-configuring-credentials and add the necessary permissions for Route53 access.. Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/phabricator.helele.com/fullchain.pem (failure)


All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/phabricator.helele.com/fullchain.pem (failure)


1 renew failure(s), 0 parse failure(s)
이 것 역시 한 번에 성공하면 재미가 없다.
실패 원인은 aws credential 지정을 안했기 때문. credential 지정하고 다시 한다.
➜ phabricator git:() ✗ export AWS_ACCESS_KEY_ID=AK...
➜ phabricator git:() ✗ export AWS_SECRET_ACCESS_KEY=vX...

➜ phabricator git:() ✗ docker run -it --rm --name certbot \
-v '/etc/letsencrypt:/etc/letsencrypt' \
-v '/var/lib/letsencrypt:/var/lib/letsencrypt' --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY \
certbot/dns-route53 renew --dns-route53
Saving debug log to /var/log/letsencrypt/letsencrypt.log


Processing /etc/letsencrypt/renewal/phabricator.helele.com.conf


Cert is due for renewal, auto-renewing...
Found credentials in environment variables.
Plugins selected: Authenticator dns-route53, Installer None
Renewing an existing certificate
Performing the following challenges:
dns-01 challenge for phabricator.helele.com
Waiting for verification...
Cleaning up challenges


new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/phabricator.helele.com/fullchain.pem



Congratulations, all renewals succeeded. The following certs have been renewed:
/etc/letsencrypt/live/phabricator.helele.com/fullchain.pem (success)


이렇게 해서 인증서 갱신 했다.
3개월 후 또 갱신할 때는 crontab에 등록시키는 것으로 바꿔야겠다.

profile
개발자입니다

0개의 댓글