[certbot] [SELinux] challenge 디렉토리 권한 문제로 Let's Encrypt 인증서가 갱신되지 않을 때

  보안 강화 리눅스(SELinux)를 켜고 나서 webroot 방식으로 Let's Encrypt SSL/TLS 인증서를 갱신할 때에, 아래처럼 디렉토리 권한 문제로 403 오류가 나서 인증서를 갱신하지 못하는 때가 생길 수 있다.

(certbot 명령어에 --dry-run을 붙이면 인증서를 실제로 갱신하지 않고 시험해 볼 수 있다.)

# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.site-domain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for www.site-domain.com and site-domain.com

Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems:
Domain: site-domain.com
Type: unauthorized
Detail: 12.34.56.78: Invalid response from http://site-domain.com/.well-known/acme-challenge/8NBe9U4tgw37IDrcW3kxZLKKrmgGXb363Y8lDnTFYbM: 403

Domain: www.site-domain.com
Type: unauthorized
Detail: 12.34.56.78: Invalid response from http://www.site-domain.com/.well-known/acme-challenge/X83CGLf235ODpzMXe2H4bBP-wEGwQ-58CiHvjNHpFwA: 403

Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.

Failed to renew certificate www.site-domain.com with error: Some challenges have failed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following simulated renewals failed:
/etc/letsencrypt/live/www.site-domain.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
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.

  'll -Z'로 /var/www/challenge의 보안 문맥(security context)를 확인해 본다.

# ll -Z /var/www/
drwxr-xr-x. root root unconfined_u:object_r:var_t:s0 challenge

  여기에서 /var/www/challenge의 보안 문맥은 var_t으로 나와 있다. /var/www/challenge의 보안 문맥이 httpd에 관한 것이 아니면 Let's Encrypt 인증서를 갱신할 때에 밖에서 인증 정보로 쓰는 파일을 읽을 수 없다.

  chcon으로 /var/www/challenge의 보안 문맥을 httpd_sys_content_t 또는 httpd_sys_rw_content_t로 바꾸어 준다.

# chcon -t httpd_sys_rw_content_t /var/www/challenge/
# chcon -t httpd_sys_content_t /var/www/challenge/

  httpd_sys_rw_content_t가 요즈음에 Let's Encrypt 인증서를 쓰기 시작할 때에 적용되는 기본값인 것 같다. 다른 외부 웹 프로그램이 /var/www/challenge/에 파일을 기록할 일은 없으므로 httpd_sys_content_t로 바꾸어도 결과는 같은 것 같다.

  다시 certbot 명령으로 인증서를 시험 갱신해 본다.

# certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.site-domain.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for www.site-domain.com and site-domain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/www.site-domain.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2023/03/26 12:22 2023/03/26 12:22
글 걸기 주소 : 이 글에는 글을 걸 수 없습니다.

덧글을 달아 주세요