DevOps

[Letsencrypt] 인증서 갱신 에러

  • 계기
    • letsencrypt 인증서는 3개월 단위로 만료되기 때문에 재발급을 필요로한다.
    • 따라서 letsencrypt를 사용하고 있는 프로젝트의 인증서를 정기적으로 재발급해주기 위해 crontab과 certbot을 이용하려 한다.

인증서 갱신을 하려고 하는데, 다음과 같은 문구가 뜨면서 인증서 갱신이 실패한다.

Attempting to renew cert (cert-test.p-e.kr) from /etc/letsencrypt/renewal/cert-test.p-e.kr.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/cert-test.p-e.kr/fullchain.pem (failure)

cert-test.p-e.kr 도메인은 테스트용으로써 ubuntu 18.04 LTS에 직접 certbot을 설치해서 다음 명령어로 인증서를 발급 받았다.

아래 접은글은 번외로 ubuntu 18.04 LTS에 직접 certbot을 설치해 인증서를 발급받는 과정이다.

더보기

Ubuntu 18.04 LTS에 Certbot 설치하기

sudo add-apt-repository ppa:certbot/certbot sudo apt update sudo apt install python-certbot-nginx -y

Certbot으로 인증서 발급받기

// DNS TXT 발급 —manual 옵션을 이용한 이유는 도메인 사이트에 DNS TXT를 등록하기 위함이었다. sudo certbot certonly -d 도메인 --manual --preferred-challenges dns // DNS TXT 없이 도메인명으로 발급받기 sudo certbot --nginx -d 도메인


아무튼 인증서를 발급받고 제대로 등록되었는지 확인까지 마쳤다.

nslookup -q=TXT _acme-challenge.cert-test.p-e.kr


이후 sudo certbot renew --cert-name cert-test.p-e.kr --dry-run 명령어를 통해
인증서 갱신을 가짜로 실행해보려고 했더니 위에서 언급했던 예외가 발생했다.

Attempting to renew cert (cert-test.p-e.kr) from /etc/letsencrypt/renewal/cert-test.p-e.kr.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/cert-test.p-e.kr/fullchain.pem (failure)
Certificates that are created using --manual (and without an authentication hook) cannot be automatically renewed. 
This is because it involves you performing the the authorization steps by hand, which is not something that Certbot can automatically repeat at renewal time. 
Usually you will want to use an authenticator other than the manual one (such as --apache, --nginx, --webroot, --standalone), so that Certbot can perform automatic renewal. 
If you want to perform the manual authorization process again, then you will need to repeat the original command you used. 
For example: certbot certonly --manual -d domain.dev

If you would like further help with getting renewal working, please create a thread on https://community.letsencrypt.org .

—manual 명령어를 써서 인증서를 만들게 되면 자동으로 renew가 불가능하다는 것이다.

본인이 어떤 명령어를 사용해서 인증서를 만들었는지 확인하기 위해서는 /var/log/letsencrypt 경로에서 최초의 로그를 확인해보면 된다.



결론적으로 문제는 다음과 같다.

Most people use --manual because they need a wildcard certificate. 
If you don't need a wildcard certificate, you should most likely use a different authenticator, like --apache, --nginx, --webroot, or --standalone, depending on your needs. 
The other authenticators are much easier to use and support automated renewal out of the box (except for --standalone on systems where there's also an existing web server listening on port 80).
If you do need a wildcard certificate, the trouble is that you need to update your DNS records by posting new _acme-challege TXT records every time the certificate is renewed. 
Certbot isn't capable of doing this itself unless you give it some kind of code and credentials that will allow it to make changes to your DNS records; 
there's no general-purpose way of doing this that would work in every environment.


하지만 서브도메인 등록을 위해 wildcard를 사용할 경우에는 DNS TXT를 발급받을 수 밖에 없다는 점이 한계인 듯…… 즉 서브도메인을 위해 wildcard를 사용했고, DNS TXT를 직접 입력했다면 crontab 과 certbot을 이용한 자동 갱신은 물건너갔다는 점.

  • 해결 방안
    • wildcard를 사용하지 않고 서브도메인, 도메인 별 각각 인증서를 발급받는다.
    • 이때 ,DNS TXT를 발급받지 않는 옵션을 이용해 발급한다. (뭐 sudo certbot --nginx -d [도메인] 요런식?)
    • crontab과 certbot을 이용해 자동 갱신을 수행한다.
    • 자동 갱신은 이 글을 참고하면 좋다.

참고자료