본문 바로가기
IT이야기/리눅스

let’s encrypt wildcard SSL 증명서 발급하기

by somick 2020. 7. 31.

Let’s Encrypt with Wildcard!

지금 이 블로그의 SSL 증명서는 Let’s Encrypt를 이용하여 발행한 것이다. 이전 중국제 무료 SSL 증명서를 이용했었지만 갱신하려고 보니 소리소문 없이 서비스를 중지한 경험이 있어 3개월마다 갱신해야 한다는 불편함이 있지만 Let’s Encrypt로부터 SSL 증명서를 발급 받았다.

이전에는 도메인 별로 SSL 증명서를 따로 발급 받아야 했지만 2018년 3월 부터 wildcard증명서도 이용가능해 졌기 때문에 증명서를 교체하기로 했다. 아래에 그 발급과정을 기재한다.

certbot 설치

처음에 Let’s Encrypt사이트에서 설치관련 문서를 찾아보았지만 없었고 certbot을 이용하여 증명서를 발급 받는 것이기 때문에 certbot 사이트의 설치 문서를 참고하였다.

certbot 사이트에 접속하면 먼저 사용중인 웹서버와 OS를 지정하자. 그에 맞추어 적절한 문서를 표시해 준다. 여기에서는 apache + ubuntu 16.04를 지정하였다. 먼저 certbot을 설치하는 과정이 필요한데 github로부터 repository를 직접 clone하는 방법도 있지만 앞으로의 관리를 생각하여 apt-get으로 설치하였다.

먼저 software-properties-common 패키지가 필요한데 시스템에 설치되어 있는지 확인하자.  아래와 같이 버전이 표시되면 시스템에 설치되어 있는 상태이다.

$ dpkg -l | grep -i software-properties-common
ii  software-properties-common                  0.96.20.7

만약 아무것도 표시되지 않는다면 아래와 같이 패키지를 설치한다.

$ sudo apt-get update
$ sudo apt-get install software-properties-common

설치가 끝났으면 repository를 추가하고 certbot을 설치하자.

$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-apache

도메인과 인증

cert bot의 설치가 끝났다. certbot을 실행하기 이전에 미리 생각해 두어야 할 점이 있다.

인증서를 발급할 도메인

wildcard 증명서는 naked 도메인의 1차 서브도메인을 지원한다. 즉 gitlab.soday.net이나 wp.soday.net, smtp.soday.net 과 같은 형식처럼 *.soday.net에 대해서는 하나의 SSL 증명서로 해결 가능하다. 그렇지만 soday.net 도 같이 발급하려면 옵션으로 도메인을 추가해 주어야 한다. 특별한 이유가 없다면 naked 도메인도 하나의 인증서에 같이 발급하는걸 추천한다.

도메인의 인증

SSL 증명서를 발급하려는 도메인이 정확히 자기 소유인지 확인할 필요가 있다. 인증 방식으로는 메일이나 웹서버에 특정 파일을 작성하거나 도메인에 특정 레코드를 추가하는 방법 등 여러가지가 있다. 메일인증 방식은 3개월 마다 메일을 확인하여 클릭해 주어야 한다는 불편이 있고, 파일 작성 방식은 현재 backend 쪽에서 haproxy와 다른 패키지를 이용하고 있기 때문에 힘들 듯 하다.

 

이전에는 매번 서버셋팅을 바꾸어 파일 인증 방식으로 증명서를 갱신 했지만 위험성도 있고 수정사항이 발생 했을 경우 고려사항이 많아지니 이번에는 도메인 인증방식으로 증명서를 발급 하기로 했다.

증명서의 발급

증명서 발급 명령어를 실행하기 이전에 자기 도메인의 관리 사이트에 접속하여 서브도메인을 추가할 준비를 해놓자. 엔터키를 누르는 순간 인증을 시도하니 엔터키 누르기 이전에 인증용 서브 도메인을 추가하는게 좋다. 준비가 되었으면 아래 명령어로 증명서를 발급 하도록 하자!

$ sudo certbot certonly --manual \
-d *.soday.net \
-d soday.net \
-m <mailaddr>@gmail.com \
--agree-tos \
--manual-public-ip-logging-ok \
--preferred-challenges dns-01 \
--server https://acme-v02.api.letsencrypt.org/directory
 

-d 옵션으로 증명서를 발급할 도메인을 지정하도록 한다. -m 다음에는 자기 메일 주소를 지정한다.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
 
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: n
 
Attempting to parse the version 0.23.0 renewal configuration file
found at /etc/letsencrypt/renewal/www.soday.net.conf with version
0.22.2 of Certbot. This might not work.
Attempting to parse the version 0.24.0 renewal configuration file
found at /etc/letsencrypt/renewal/gitlab.soday.net.conf with version
0.22.2 of Certbot. This might not work.
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for soday.net
dns-01 challenge for soday.net
 
 
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
-_auth-subdomain_-.soday.net with the following value:
 
--== authority domain txt record value1 ==--
 
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
 
-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
-_auth-subdomain_-.soday.net with the following value:
 
--== authority domain txt record value2 ==--
 
Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue ⇒ 여기서 엔터를 누르면 바로 인증이 시작되니 먼저 인증용 도메인을 등록
 
Waiting for verification...
Cleaning up challenges
 
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/soday.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/soday.net/privkey.pem
   Your cert will expire on 2018-09-17. 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
 

시작하기 전에 메일주소를 제공할 것이냐 물어보는데 특별히 필요할 것 같진 않아 no를 입력했다. yes를 입력하면 여러가지 정보가 메일로 날아올 터이니 필요한 경우에는 yes를 지정한다.

 

이전에 이용했던 구버전 certbot 파일을 갱신했다는 메시지와 함께 추가할 서브 도메인과 TXT 레코드 값이 표시된다.  도메인 관리 사이트에서 서브 도메인에 TXT 레코드로 지정된 문자열을 추가한다. 엔터키를 누르면 또 하나의 레코드가 표시되는데 -d 옵션으로 2개의 도메인을 지정했기 때문이다. 만약 3개를 지정했다면 당연히 레코드도 3개가 표시되고 3개 모두 등록할 필요가 있다. 마지막 레코드가 표시된 후 엔터키를 누르면 바로 인증이 시작되기 때문에 그 전에 레코드가 잘 등록되었는지 확인하자.

$ dig -_auth-subdomain_-.soday.net TXT +noall +ans

실제로 반영되기 까지는 시간이 필요하니 정기적으로 확인하여 등록한 레코드가 모두 표시되는 것을 확인한 후에 엔터키를 눌러 인증단계로 진행하자. 특별한 문제가 없다면 증명서가 발급되고 증명서가 저장되어 있는 디렉토리가 표시된다. fullchain.pem 파일이 CA중간 증명서이고 privkey.pem 파일이 암호키 파일, cert.pem 파일이 SSL 증명서 파일이다.

발급된 파일들을 haproxy에 적용시키자 특별한 문제 없이 암호화 된 페이지가 표시되었다.

증명서도 *.soday.net으로 정확하게 표시된다.

$ curl -v https://soday.net
* Rebuilt URL to: https://soday.net/
* Hostname was NOT found in DNS cache
*   Trying 39.111.246.236...
* Connected to soday.net (39.111.246.236) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*        subject: CN=*.soday.net
*        start date: 2018-06-19 12:17:14 GMT
*        expire date: 2018-09-17 12:17:14 GMT
*        subjectAltName: soday.net matched
*        issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*        SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: soday.net
> Accept: */*

 

curl 명령어로 확인해 보니 soday.net에 대해서도 matched 와 verify ok가 표시되니 문제는 없는 듯 하다.

증명서의 자동 갱신

Let’s Encrypt에서 발급된 증명서는 모두 90일이 기한이다. 90일이 되기 전에 아래 명령어를 실행하여 증명서를 갱신하자.

$ sudo certbot renew --dry-run

매번 실행 하는 것도 귀찮으니 cron 에 등록하여 정기적으로 실행되도록 설정해 놓으면 더욱 편하겠다.

댓글