[TIL] 230831 Spring boot Certbot SSL ์ธ์ฆ ๋ฐ›๊ธฐ

CountryGirlยท2023๋…„ 8์›” 31์ผ
0

TIL

๋ชฉ๋ก ๋ณด๊ธฐ
54/80

์ž„์‹œ๋กœ ์„œ๋ฒ„๋ฅผ ํ•˜๋‚˜ ๋” ๋งŒ๋“ค์—ˆ๋‹ค.
ํ”„๋ก ํŠธ์™€ ๋งž์ถ”๊ธฐ ์œ„ํ•ด์„œ https ๋กœ ๋งŒ๋“ค์–ด์•ผํ–ˆ๋‹ค.

GitHub Actios + AWS CodeDeploy ๋ฅผ ์‚ฌ์šฉํ•ด์„œ CI/CD ๋ฅผ ํ•˜์˜€๋‹ค.

๐Ÿค” 1. snap ์œผ๋กœ certbot ์„ค์น˜

sudo snap install core

sudo snap refresh core

sudo snap install --classic cerbot

sudo ln -s /snap/bin/certbot /ust/bin/certbot

๐Ÿค” 2. ์„ค์น˜ํ•œ certbot ์œผ๋กœ SSL ๋ฐ›๊ธฐ

sudo certbot certonly --standalone

์„ ์ž…๋ ฅํ•˜๊ฒŒ ๋˜๋ฉด,

    1. ์ด๋ฉ”์ผ ์ž…๋ ฅ
    1. ๋„๋ฉ”์ธ ์ž…๋ ฅ

์ด ๋‚˜์˜ค๊ฒŒ ๋œ๋‹ค.

๋‚˜๋Š” 2. ๋„๋ฉ”์ธ ์ž…๋ ฅ์„ ํ–ˆ์„ ๋•Œ, ๊ณ„์† ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค.

์•Œ๊ณ  ๋ณด๋‹ˆ AWS Route53์—์„œ A ๋ ˆ์ฝ”๋“œ๋ฅผ ์„ค์ •ํ•ด์ฃผ์ง€ ์•Š์•„์„œ์˜€๋‹ค.

์•„์ฐจ์ฐจ....

๋ ˆ์ฝ”๋“œ๋ฅผ ์„ค์ •ํ•ด์ฃผ๊ณ  ๋‹ค์‹œ ์‹œ๋„ํ•ด๋ณด์•˜๋‹ค.

ํ•˜์ง€๋งŒ ๋ฐ”๋กœ ๋˜์ง€ ์•Š์•˜๋‹ค.

์•„๋งˆ ๋ ˆ์ฝ”๋“œ๋ฅผ ์žฌ์„ค์ • ํ›„ ํผ์ง€๋Š” ์‹œ๊ฐ„์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋‹ค.
๋ฐ”๋กœ ํ•˜๋ฉด ์•ˆ๋˜๊ณ  ์ข€ ๊ธฐ๋‹ค๋ ค์•ผํ•œ๋‹ค.
2-30๋ถ„ ์ •๋„ ๊ธฐ๋‹ค๋ ธ๋˜ ๊ฒƒ ๊ฐ™๋‹ค.


๐Ÿค” 3. SSL ์ ์šฉ

1. SSL์ธ์ฆ์„œ ํ˜•์‹(PKCS12)๋กœ ๋ณ€ํ™˜

  1. ์„ค์น˜ํ•œ certbot ์œผ๋กœ SSL ์„ ์ž˜ ์„ฑ๊ณตํ–ˆ๋‹ค๋ฉด
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/subbak2.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/subbak2.com/privkey.pem

์ด๋ ‡๊ฒŒ ๋œฌ๋‹ค!

๊ทธ๋Ÿฌ๋ฉด privkey.pem ํŒŒ์ผ์ด ์žˆ๋Š” ๊ณณ์œผ๋กœ ๊ฒฝ๋กœ๋ฅผ ๊ฐ€์•ผํ•œ๋‹ค.

privkey.pem ์ด ์žˆ๋Š” ๊ฒฝ๋กœ์—์„œ ์‹คํ–‰

openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name tomcat -CAfile chain.pem -caname root

๋‚˜๋Š” ๊ณ„์†ํ•ด์„œ

Permission denied

๊ฐ€ ๋– ์„œ sudo๋ฅผ ์จ์„œ ๊ฒฝ๋กœ์— ์ ‘๊ทผํ•˜์˜€๋‹ค.

์ด๋ ‡๊ฒŒ ํ•˜๊ฒŒ ๋˜๋ฉด privkey.pem ํŒŒ์ผ ์žˆ๋Š” ๊ฒฝ๋กœ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

privkey.pem ํŒŒ์ผ ์žˆ๋Š” ๊ฒฝ๋กœ์—์„œ ์œ„์— ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๊ฒŒ ๋˜๋ฉด ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅํ•˜๋ผ๊ณ  ํ•œ๋‹ค.

๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž˜ ๊ธฐ์–ตํ•ด์•ผํ•œ๋‹ค. ๊ทธ๋ž˜์•ผ application.properties ์— ์“ธ ์ˆ˜ ์žˆ๋‹ค !!

2. keystore.p12 ํŒŒ์ผ์„ /src/main/resources ๋กœ ์ด๋™

๋‚˜๋Š” ํŒŒ์ผ์งˆ๋ผ(FileZilla)๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค.

๊ณ„์† ํŒŒ์ผ ์ „์†ก ์‹คํŒจ๊ฐ€ ๋–ณ๋‹ค......

keystore.p12 ์˜ ๊ถŒํ•œ์ด -r-------- ์ด์–ด์„œ ํŒŒ์ผ์„ ์˜ฎ๊ธธ ์ˆ˜ ์—†์—ˆ๋‹ค.

๊ถŒํ•œ์„ rw-r--r-- ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ธฐ ์œ„ํ•ด์„œ ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ผ๋‹ค!!

sudo chmod 644 keystore.p12

rw-r--r-- ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๋ ค๋ฉด 644๋ฅผ ์จ์•ผํ•œ๋‹ค!

๋‹ค์‹œ ํŒŒ์ผ์งˆ๋ผ์—์„œ keystore.p12 ๋ฅผ ์˜ฎ๊ฒผ๋”๋‹ˆ ์„ฑ๊ณตํ–ˆ๋‹ค!!

application.properties ์— SSL ์ •๋ณด ์ถ”๊ฐ€

server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store-type=PKCS12
server.ssl.key-store-password=์œ„์—์„œ ์„ค์ •ํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ

Github ์— push ํ•˜๊ณ  Actions๊ฐ€ ์‹คํ–‰๋˜๋ฉด ์™„์„ฑ!



โœ… REFERENCE

์„ญ์ฝ”๋”ฉ subCoding : SpringBoot ๋ฌด๋ฃŒ SSL ์ธ์ฆ์„œ ์ ์šฉํ•˜๊ธฐ (Certbot)

profile
๐Ÿ’ป๐ŸŒพ์‹œ๊ณจ์†Œ๋…€์˜ ์—‰๋ง์ง•์ฐฝ ๊ฐœ๋ฐœ ์„ฑ์žฅ์ผ์ง€๐ŸŒพ๐Ÿ’ป (2023.05.23 ~)

0๊ฐœ์˜ ๋Œ“๊ธ€