[Network | Rocky Linux] Let’s Encrypt를 통한 SSL 인증서 발급
2024. 7. 18. 12:23

내가 배포했던 프로젝트는 이전까지 HTTP를 사용하고 있었다. HTTP에서 전송하는 데이터는 일반 텍스트로 보안에 취약했으나 이번에 SSL 인증서를 발급하며 적용한 HTTPS는 암호화 및 인증이 존재한다. 이것은 TLS(SSL) 때문인데 일반 HTTP 요청을 암호화하고 해당 요청 및 응답에 디지털 서명을 함으로써 보안 기능을 추가했기 때문에 보안에 더욱 더 강력하다.

1. EPEL 저장소 추가

EPEL은 기본 운영체제에서 제공하지 않는 패키지를 다운 받을 수 있도록 도와주는 추가 패키지 저장소라고 한다.(Let’s Encrypt라는 기관이 비영리기관이라 따로 이렇게 설치를 해줘야하는건가?)

[root@localhost ~]# dnf install epel-release -y

2. Certbot 및 Certbot Apache 플러그인 설치

Certbot은 Let’s Encrypt라는 기관에서 사용하는 프로그램이며 Let’s Encrypt는 사용자에게 무료로 SSL 인증서를 발급해주는 비영리 기관이다.

[root@localhost ~]# dnf install certbot python3-certbot-apache -y

3. Certbot을 사용한 SSL 인증서 발급

나는 도메인이 3개이므로 -d 명령어를 통해 3개의 도메인을 지정했다.

--apache 옵션 명령어는 해당 명령어를 통해 SSL이 발급되면 자동으로 Apache 웹 서버 설정 파일(httpd.conf …)을 자동으로 수정하여 SSL/TLS 인증서를 설정해준다.

[root@localhost ~]# certbot --apache -d ljy.r-e.kr -d replay.o-r.kr -d ttoganjip.kro.kr

 

[root@localhost ~]# certbot --apache -d ljy.r-e.kr -d replay.o-r.kr -d ttoganjip.kro.kr
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): ${이메일 }

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. You must agree in
order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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 our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for ljy.r-e.kr and 2 more domains
An unexpected error occurred:
Error creating new order :: too many certificates already issued for "kro.kr". Retry after 2024-07-18T06:00:00Z: see https://letsencrypt.org/docs/rate-limits/
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

보다시피 제일 밑에 에러가 발생했다.

 

이유인 즉슨 too many certificates already issued for "[kro.kr](http://kro.kr)" kro.kr 도메인으로 등록한 SSL 인증서가 너무 많아서 오후 3시 이후에 시도하라고 한다.

 

김빠진다.

 

 

 

~ 1시간 후 ~

 

 

 

생각해보니 kro.kr 도메인만 빼고 다른 건 발급받을 수 있을 것 같아 다시 시도해봤다.

이번엔 -d 옵션 명령어를 뺐다.

[root@localhost ~]# certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: ttoganjip.kro.kr
2: replay.o-r.kr
3: ljy.r-e.kr
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 3
Requesting a certificate for ljy.r-e.kr

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/ljy.r-e.kr/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/ljy.r-e.kr/privkey.pem
This certificate expires on 2024-10-16.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for ljy.r-e.kr to /etc/httpd/conf/httpd-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://ljy.r-e.kr

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

내가 만든 개인 프로젝트 중 요새 작업 중인 블로그는 뒤에 r-e.kr이 붙기 때문에 kro.kr과는 다르게 인증서 발급이 완료됐다는 문구가 떴다.

 

그럼 o-r.kr이 붙은 것도 등록해줘야겠다!

 

[root@localhost ~]# certbot --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: ttoganjip.kro.kr
2: replay.o-r.kr
3: ljy.r-e.kr
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 2
Requesting a certificate for replay.o-r.kr

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/replay.o-r.kr/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/replay.o-r.kr/privkey.pem
This certificate expires on 2024-10-16.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for replay.o-r.kr to /etc/httpd/conf/httpd-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://replay.o-r.kr

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

이로써 문제가 있었던 kro.kr만 빼고 다른 도메인은 SSL 인증서 발급이 완료되었다.

4. 인증서 확인

[root@localhost ~]# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
  Certificate Name: ljy.r-e.kr
    Serial Number: 31d63facc197da3805164597f8f120767c8
    Key Type: ECDSA
    Domains: ljy.r-e.kr
    Expiry Date: 2024-10-16 00:07:12+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/ljy.r-e.kr/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/ljy.r-e.kr/privkey.pem
  Certificate Name: replay.o-r.kr
    Serial Number: 4339877116c9dc7bc9b5a67028a8ca0be54
    Key Type: ECDSA
    Domains: replay.o-r.kr
    Expiry Date: 2024-10-16 00:09:47+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/replay.o-r.kr/fullchain.pem
    Private Key Path: /etc/letsencrypt/live/replay.o-r.kr/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

4. httpd-le-ssl.conf 확인

SSL 인증서 발급 후 /etc/httpd/conf에 들어가보면 이전과 달리 httpd-le-ssl.conf가 생성된 것을 확인할 수 있다.

 

<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName ljy.r-e.kr
  ProxyPreserveHost On
  ProxyPass / http://192.168.56.103:5221/
  ProxyPassReverse / http://192.168.56.103:5221/

SSLCertificateFile /etc/letsencrypt/live/ljy.r-e.kr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ljy.r-e.kr/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:443>
  ServerName replay.o-r.kr
  ProxyPreserveHost On
  ProxyPass / http://192.168.56.103:5222/
  ProxyPassReverse / http://192.168.56.103:5222/

SSLCertificateFile /etc/letsencrypt/live/replay.o-r.kr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/replay.o-r.kr/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

4. Apache(httpd) 재시작

[root@localhost ~]# systemctl restart httpd

이렇게까지만 하고 SSL 인증서를 발급받은 도메인으로 들어가보자.

그럼 아직까지 https의 기본 포트인 443을 안열어줬기 때문에 아래와 같이 뜬다.

 

이제 어떻게 하냐?

포트를 열어주면 된다..

 

 

일단 방화벽부터 열자.

[root@localhost conf]# firewall-cmd --permanent --add-service=https
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3 enp0s8
  sources:
  services: cockpit dhcpv6-client https ssh
  ports: 30000/tcp 80/tcp
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@localhost ~]#

 

공유기 포트도 열어주고..

 

그리고 외부에서 들어온 443 포트를 받아야하니 포트 포워딩 규칙에 추가해주자.

 

이제 확인해보면 아래와 같이 나온다!

 

 

뭐 꾸민 것도 없고 기능도 없긴한데.. 이렇게까지 해놓고 나니까 열심히 작업해서 배포하고 싶다는 생각이 든다. 이제 기능만 잘 만들 줄 알면 서비스도 만들겠네..

 

+ 추가

오후 3시 넘어서 다시 SSL 인증서 발급을 시도했고 3시 넘은지 얼마 안돼서 그런가 정말로 SSL 발급에 성공했다.

 

 

 


참고 레퍼런스

https://sysdocu.tistory.com/1730

https://blog.naver.com/zsknight/100157542215