티스토리 뷰

개요

  • Let's Encrypt는 무료로 제공되는 세계적 규모의 TLS 공인 인증서이다. 이를 이용하여 상용 인증서와 동일한 수준의 보안을 무료로 보장 받을 수 있다. 이번 글에서는 CentOS 운영체제에 Let’s Encrypt 인증서를 설치하고 자동 갱신하는 방법을 소개하고자 한다.

Certbot 설치

  • Certbot 클라이언트는 Let’s Encrypt 무료 SSL 공인 인증서를 설치하고 무중단으로 갱신하는 것까지 가능하게 해주는 툴이다. 이 툴을 이용해 아래 설명할 NGINX 환경설정까지 자동 적용할 수 있다. 설치 방법은 아래와 같다.
# EPEL 저장소 설치
$ sudo yum install epel-release

# Amazon EC2일 경우 아래 방법으로 설치
$ sudo amazon-linux-extras install epel

# Certbot 클라이언트 설치
$ cd /opt
$ sudo wget https://dl.eff.org/certbot-auto
$ sudo mv certbot-auto /usr/local/bin/certbot-auto
$ sudo chown root /usr/local/bin/certbot-auto
$ sudo chmod 0755 /usr/local/bin/certbot-auto

# Amazon EC2 인스턴스의 경우, 아래 작업 필요
$ sudo nano /usr/local/bin/certbot-auto
# 변경 전
elif [ -f /etc/redhat-release ]; then
# 변경 후
elif [ -f /etc/redhat-release ] || grep 'cpe:.*:amazon_linux:2' /etc/os-release > /dev/null 2>&1; then

# Certbot 클라이언트 설치 확인
$ sudo /usr/local/bin/certbot-auto --version
certbot 1.5.0

acme-dns-certbot 설치

  • 앞서 설치한 Certbot는 기본적으로 단일 서버의 물리 IP 주소가 맵핑되는 HTTP 인증 방식을 사용한다. 이 방식은 단일 서버에 대해서는 문제가 없지만 로드 밸런서나 복수개 서버에 대한 클러스터군에 대해서는 인증서 관리가 불가능하다는 단점이 있다. acme-dns-certbot은 별도의 전용 도메인과 CNAME을 등록한 후 DNS 인증 방식을 사용하여 인증서 설치 및 갱신을 가능하게 해주는 툴이다. 설치 방법은 아래와 같다.
$ cd /opt
$ sudo wget https://github.com/joohoi/acme-dns-certbot-joohoi/raw/master/acme-dns-auth.py
$ sudo chmod +x acme-dns-auth.py
$ sudo mv acme-dns-auth.py /etc/letsencrypt/
  • 이제 실제로 특정 도메인에 대한 인증서를 설치할 차례이다.
# foo.com, bar.com 2개 도메인에 대한 CNAME 레코드 획득 실행
$ sudo /usr/local/bin/certbot-auto certonly --manual --manual-auth-hook /etc/letsencrypt/acme-dns-auth.py --preferred-challenges dns --debug-challenges -d foo.com -d bar.com

Running manual-auth-hook command: /etc/letsencrypt/acme-dns-auth.py
Output from manual-auth-hook command acme-dns-auth.py:
Please add the following CNAME record to your main DNS zone:
_acme-challenge.foo.com CNAME e753a415-6a13-4303-937e-55708dcd65a5.auth.acme-dns.io.

Press Enter to Continue

# 위 상태에서 대기 후 획득된 도메인과 맵핑되는 CNAME을 도메인 관리 사이트에 등록한다. 등록이 완료되면 Enter를 실행
# 아래와 같이 Congratulations! 메시지가 출력되면 인증서 설치 완료

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/foo.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/foo.com/privkey.pem
   Your cert will expire on 2020-09-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again. To non-interactively renew *all* of your certificates, run
   "certbot-auto 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

인증서 자동 갱신 처리

  • Let’s Encrypt 인증서는 3개월의 유효기간을 가진다. 만료 임박시 인증서 설치 시점에 입력한 이메일 주소로 안내 메일을 발송하지만 매번 수동으로 갱신하려면 여간 귀찮은 것이 아니다. 깜박 잊고 갱신 시기를 놓칠 경우 시스템 장애로 이어질 수 있는 사안이다. 아래와 같이 crontab에 등록하여 인증서 갱신을 자동으로 실행하게 할 수 있다.
# 인증서 자동 갱신 크론잡 등록
$ sudo crontab -e
@monthly /usr/local/bin/certbot-auto renew && /usr/sbin/nginx -s reload

NGINX에 설치된 인증서 적용

  • 위 설치된 인증서를 NGINX 로드밸런서에도 별도의 수작업 없이 작동으로 적용할 수 있다.
# NGINX에 인증서를 설치하고, HTTPS로 접속되도록 자동 설정 실행
# 방화벽에서 80 포트가 개방되어 있어야 정상적으로 인증서가 다운로드
$ sudo /usr/local/bin/certbot-auto --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter Email address (used for urgent renewal ans security notices): *****
Congratulations! You have successfully enabled https://someyourdomain.com

# 기존 443 포트를 사용 중인 모든 프로세스 종료
$ sudo fuser -k 443/tcp
$ sudo rm /etc/httpd/conf.d/ssl.conf
$ sudo service httpd restart
$ sudo service nginx restart

# NGINX 재시작
$ sudo service nginx restart
  • 자동 적용 내용 살펴보면 server 블록에 아래 내용이 추가되는 것을 확인할 수 있다.
server {
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/someyourdomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/someyourdomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

관련 링크

댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함