๐ฏ๏ธ ๋ฌธ์
๊ธฐ์กด ์ค๊ณ์์ https
์ค๊ณ ๋จ๊ณ์์๋ https์ ๋์ ์ ๊ณ ๋ คํ์ง ์์์ต๋๋ค.
๊ทธ ์ด์ ๋ security์ ๋ํ ์๋ จ๋๊ฐ ๋ฎ๊ณ ๊ธฐ๋ฅ ๊ฐ๋ฐ์ ์ข๋ ์ง์คํ๊ธฐ ๋๋ฌธ์ https ์ค์ ์ ํ์ง ์์๋ ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋ฅ์ด ์ํ๋ ๊ฒ์ด๋ผ ์๊ฐํ๊ธฐ ๋๋ฌธ์ ๋๋ค.
https๋ก์ ์ ํ ์ด์ ?
https๋ก ์ ํํ๊ธฐ๋ก ํ ์ด์ ๋ 2๊ฐ์ง์ ๋๋ค. ๋ณด์ ์ด์์ Mixed content ์ด์ ์ ๋๋ค.
1. ๋ณด์ ์ด์
ํ์ฌ ๊ฐ๋ฐ ๋จ๊ณ์์๋ ์ธ๋ถ์ ํ์ด์ง๋ฅผ ๊ฐ๋ฐฉํ์ง ์๊ธฐ ๋๋ฌธ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ง ์์ ์ ์์ง๋ง, ๋์ค์ ์๊ฐํ๋ฉด https์ ๋์ ์ ํ์๋ก ํด์ผํ๋ค๋ ๋ฉํ ๋์ ์กฐ์ธ์ด ์์ด์ ๋์ ์ ๊ณ ๋ คํ์ต๋๋ค.
2. ํ๋ก ํธ์ Mixed content ์ด์
ํ๋ก ํธ์๋ ์๋ฒ์์ https๋ก ๋ฐฐํฌํ๊ธฐ ๋๋ฌธ์ http๋ก ๋ฐฐํฌ๋ ๋ฐฑ์๋ api ํธ์ถ ์ Mixed content ์๋ฌ๊ฐ ๋ฐ์ํ๊ณ , ํด๊ฒฐํ๊ธฐ ์ํด์๋ https๋ก ๋ฐฑ์๋ ์๋ฒ๋ฅผ ๋ฐฐํฌํ๋ ๋ฐฉ๋ฒ์ด ์์์ต๋๋ค. Mixed content๋?
์ด๋ฐ ์ด์ ๋ค๋ก https๋ฅผ ์ ์ฉํ๊ธฐ๋ก ํ์ต๋๋ค.
๐ฅ ํด๊ฒฐ ๋ฐฉ๋ฒ
1. ์ธ์ฆ๋์ง ์์ SSL ์ธ์ฆ์ ๋ฐ๊ธ
์ฒซ๋ฒ์งธ๋ก, ํ๋ก๊ทธ๋๋จธ์ค ๋ฐ๋ธ์ฝ์ค ๊ฐ์ ์ค java์ ๊ธฐ๋ณธ ๋ช ๋ น์ด์ธ keytool์ ์ด์ฉํด ์ธ์ฆ๋์ง ์์ ssl ์ธ์ฆ์๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์ ๋๋ฐ, ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๊ธฐ๋ก ํ์ต๋๋ค.
keytool -genkey -alias prgrms_keystore -keyalg RSA -storetype PKCS12 -keystore prgrms_keystore.p12 # keystore ์์ฑ
keytool -export -alias prgrms_keystore -keystore prgrms_keystore.p12 -rfc -file prgrms.cer # keystore์์ ์ธ์ฆ์ ์ถ์ถ
keytool -import -alias prgrms_truststore -file prgrms.cer -keystore prgrms_truststore.p12 # trust-store ์์ฑ
ํด๋น ๋ฐฉ๋ฒ์ ์ ๋ขฐํ ์ ์๋ ์ธ์ฆ๊ธฐ๊ด์์ ๋ฐ๊ธ๋ฐ์๊ฒ์ด ์๋ ์ฌ์ค ์ธ์ฆ์์ด๊ธฐ ๋๋ฌธ์ ์๋์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค.
2. ์ธ์ฆ๋ SSL ์ธ์ฆ์ ๋ฐ๊ธ
๊ธฐ์กด์ ๋ฐฉ๋ฒ์ผ๋ก๋ ๋ณด์ ๋ฌธ์ ๊ฐ ์์ ํ ํด๊ฒฐ์ด ๋์ง ์์๊ธฐ ๋๋ฌธ์ ์ธ์ฆ๋ SSL ์ธ์ฆ์๋ฅผ ๋ฐ๊ธ๋ฐ์์ผ ํ์ต๋๋ค. Let’s Encrypt๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ๊ธ๋ฐ์์ต๋๋ค.
2-1. ๋๋ฉ์ธ ์ฃผ์ ๋ฐ๊ธ
ssl ์ธ์ฆ์ ๋ฐ๊ธ์๋ ์ ํ ์กฐ๊ฑด์ด ํ์ํฉ๋๋ค. ๋ฐ๋ก ์๋ฒ์ ์ฐ๊ฒฐํ๊ธฐ ์ํ ๋๋ฉ์ธ ์ฃผ์์ ๋๋ค.
๋ณดํต ๋๋ฉ์ธ ๋ฐ๊ธ์ ์ ๋ฃ์ด์ง๋ง, ๋ช๋ช์ ๋ฌด๋ฃ ๋๋ฉ์ธ ๋ฐ๊ธ ์ฌ์ดํธ๋ฅผ ํตํด ์ผ์ ๊ธฐ๊ฐ๋์ ๋ฌด๋ฃ๋ก ์ฌ์ฉํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ฌด๋ฃ ๋๋ฉ์ธ์ ๋ฐ๊ธ๋ฐ์์ต๋๋ค.
ํด๋น ํํ์ด์ง์ ํ์๊ฐ์ ํ ์ํ๋ ๋๋ฉ์ธ์ ์ ๋ ฅํด ์ฃผ์๋ฅผ ํ ๋น๋ฐ์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ , ์๋ ๊ทธ๋ฆผ์ฒ๋ผ IP์ฐ๊ฒฐ๋์ ์๋ฒ์ ip์ฃผ์๋ฅผ ์ ๋ ฅํด ์๋ฒ์ ์ฐ๊ฒฐํฉ๋๋ค.
์ ๋ ฅ์ด ์๋ฃ๋๋ฉด, IP ์ฃผ์ ๋์ ๋๋ฉ์ธ ์ฃผ์ ์ ๋ ฅ์ผ๋ก ํด๋น IP์ ์ ์ํ ์ ์๊ฒ ๋ฉ๋๋ค.
2-2. Let's Encrypt ์ธ์ฆ์ ๋ฐ๊ธ
Let's Encrypt ์ธ์ฆ์ ๋ฐ๊ธ์๋ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ด ์์ง๋ง, ์ฌ๊ธฐ์๋ Certbot์ ์ด์ฉํ์ต๋๋ค.
[Certbot
Tagline
certbot.eff.org](https://certbot.eff.org/)
# ubuntu์์ certbot ์ค์น
apt install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt update
apt upgrade
apt install certbot python3-certbot-apache
์ธ์ฆ์ ๋ฐ๊ธ์ ์ํด์๋ 3๊ฐ์ง์ ๊ณผ์ ์ ๊ฑฐ์นฉ๋๋ค.
- Certbot ์ธ์ฆ์ ์์ฒญ
- ์์ฒญํ ๋๋ฉ์ธ ์์ ์ฃผ ํ์ธ
- ์ธ์ฆ์ ๋ฐ๊ธ
๊ทธ๋ฆฌ๊ณ , ๋๋ฉ์ธ ์์ ์ฃผ ํ์ธ์ ์ํ ๋ฐฉ๋ฒ์๋ 3๊ฐ์ง๊ฐ ์์ต๋๋ค.
- standalone - ๊ฐ์ ์น์๋ฒ๋ฅผ ๊ฐ๋ํ์ฌ ๋๋ฉ์ธ์์ ์ฃผ ํ์ธ
- webroot - ์์ ์ ์น์๋ฒ๊ฐ ์ ๊ณตํ๋ ํน์ ํ์ผ๋ก ๋๋ฉ์ธ์์ ์ฃผ ํ์ธ
- dns - dns ๋ ์ฝ๋์ ํน์ ๊ฐ์ ์์ฑํ์ฌ ๋๋ฉ์ธ์์ ์ฃผ ํ์ธ
์ฌ๊ธฐ์๋ ์๋ฒ๋ฅผ ์ข ๋ฃํด๋ ์๋ฌด๋ฐ ๋ฌธ์ ๊ฐ ์์๊ธฐ ๋๋ฌธ์ 1๋ฒ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ต๋๋ค. ์๋ฒ๋ฅผ ์ค๋จํ ์ ์์ ๊ฒฝ์ฐ 2๋ฒ ๋ฐฉ๋ฒ์ ์ฌ์ฉํฉ๋๋ค.
๋จผ์ , ์ธ์ฆ์ ๋ฐ๊ธ์ 80๋ฒ ํฌํธ๊ฐ ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์ aws์์ ์ธ๋ฐ์ด๋ ํฌํธ๊ฐ ์ด๋ ค์๋์ง ํ์ธํ ํ ์งํํฉ๋๋ค.
# ssl ์ธ์ฆ์ ๋ฐ๊ธ
sudo certbot certonly --standalone
[sudo] password for dev: <root password>
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
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.2-November-15-2017.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 **# ์ด๋ฉ์ผ ์ ๋ณด ์์ ๋์**
Please enter in your domain name(s) (comma and/or space separated)
(Enter 'c' to cancel): **# ์ธ์ฆ์๋ฅผ ๋ฐ๊ธํ ๋๋ฉ์ธ ์
๋ ฅ**
Requesting a certificate for everevent.kro.kr
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/vompressor.com/fullchain.pem **# ๋ฐ๊ธ๋ ์ธ์ฆ์ ๊ฒฝ๋ก**
Your key file has been saved at:
/etc/letsencrypt/live/vompressor.com/privkey.pem **# ๋ฐ๊ธ๋ ์ธ์ฆ์ ๊ฒฝ๋ก**
Your certificate will expire on 2021-05-16. 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
์ด ์ค ๊ธฐ์ตํ ๋ถ๋ถ์ ๋๋ฉ์ธ ์ ๋ ฅ๊ณผ ์ธ์ฆ์ ๊ฒฝ๋ก์ ๋๋ค.
์์ ๋๋ฉ์ธ ๋ฐ๊ธ ์ฌ์ดํธ์์ ๋ฐ๊ธ๋ฐ๊ณ , ํด๋น aws ์๋ฒ์ ์ฐ๊ฒฐํ ๋๋ฉ์ธ ์ฃผ์๋ฅผ ์ ํํ ์ ๋ ฅํด์ผ ํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ , ํด๋น ์ธ์ฆ์ ๊ฒฝ๋ก์ ๊ด๋ จ ํ์ผ๋ค์ด ์์ฑ๋ฉ๋๋ค.
2-3. ์ธ์ฆ์๋ฅผ Spring Boot ํ๋ก์ ํธ์ ์ฐ๊ฒฐํ๊ธฐ
์ฒ์ ์ธ์ฆ์๋ฅผ ๋ฐ๊ธ๋ฐ์ผ๋ฉด /etc/letsencrypt/live
๊ฒฝ๋ก์ ์ธ์ฆ์ ๊ด๋ จ ํ์ผ๋ค์ด ์ ์ฅ๋ฉ๋๋ค.
ํด๋ ์ ๊ทผ์ root ๊ณ์ ๋ง ๊ฐ๋ฅํ๊ธฐ ๋๋ฌธ์ sudo -s
๋ก ์ ํ ํ ์ ๊ทผํฉ๋๋ค.
ํด๋์๋ ๋ค์๊ณผ ๊ฐ์ด ๋ฐ๊ธํ ๋๋ฉ์ธ ์ฃผ์๋ช ์ผ๋ก ๋์ด์๋ ํด๋๊ฐ ์์ฑ๋์ด ์์ต๋๋ค.
ํ์ฌ๋ ์ด๋ฏธ ๋ฐ๊ธํ ๋ค๋ฅธ ์ธ์ฆ์๋ค์ด ํฌํจ๋์ด์์ง๋ง, ์ด๊ธฐ์ ์ ๊ทผํ ์ ๋ฏผํธ์์ 4๊ฐ์ ํ์ผ + README๋ง ์กด์ฌํฉ๋๋ค.
ํด๋น ํค๋ค์ ์ฉ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- privkey.pem : ๊ฐ์ธํค
- fullchain.pem : ๋ด ๊ธฐ๋ณธ ๊ณต๊ฐํค + ๊ธฐํ ์ ๋ณด๋ฅผ ํฌํจํ ๊ณต๊ฐ ํค
- cert.pem : ๊ธฐ๋ณธ ๊ณต๊ฐํค
- chain.pem : ๊ธฐํ ์ ๋ณด๋ฅผ ํฌํจํ ๊ณต๊ฐํค
์ด์ ํ๋ก์ ํธ์ ์ ์ฉํ key๋ฅผ ์์ฑํ ๊ฒ์ ๋๋ค.
openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out [์์ฑํ p12 ํ์ผ๋ช
.p12] -name [๋ณ์นญ] -CAfile chain.pem -caname root
keytool -importkeystore -deststorepass [์ธ์ฆ์ password] -destkeypass [์ธ์ฆ์ password] -destkeystore [์์ฑ๋ jks ํ์ผ๋ช
.jks] -srckeystore [์์ฑํ p12ํ์ผ] -srcstoretype PKCS12 -srcstorepass [PKCS12์์ ์ฌ์ฉํ ์ํธ] -alias [์์์ ์ฌ์ฉํ ๋ณ์นญ]
keytool -import -trustcacerts -alias root -file chain.pem -keystore [์์ฑํ jks ํ์ผ]
๋ง์ง๋ง import๊น์ง ํ๊ฒ๋๋ฉด ์ธ์ฆ์ ๊ด๋ จ๋ ์์ ์ ๋ชจ๋ ์ข ๋ฃ๋ฉ๋๋ค.
์ด์ Spring boot ํ๋ก์ ํธ๋ก ๋์์ application.yml ํ์ผ์ ์์ฑํฉ๋๋ค.
์์์ ์์ฑํ jks ํ์ผ์ resources ํด๋์ ์ฎ๊ธด ํ ์๋์ ๊ฐ์ด ์์ฑํฉ๋๋ค.
server:
port: 443
ssl:
enabled: true
key-store: classpath:everevent.jks
key-store-password: # ์ธ์ฆ์ password
key-password: # ์ธ์ฆ์ password
์ด๋ ๊ฒ ๋๋ฉด ๋ชจ๋ ์ค์ ์ด ๋๋ฉ๋๋ค.
์ฃผ์ํ ์ ์ ์ด๋ ๊ฒ https๋ก ์ค์ ํ api์ ์ ๊ทผ ์ ๋๋ฉ์ธ ๋ช ์ผ๋ก ์ ๊ทผํด์ผ ssl ์ธ์ฆ์ ํ์ธ์ด ๊ฐ๋ฅํฉ๋๋ค. ๊ธฐ์กด์ IP์ฃผ์๋ก ์ ๊ทผํ ๊ฒฝ์ฐ ์ด์ ๊ณผ ๊ฐ์ ๊ฒฝ๊ณ ๋ฌธ๊ตฌ๊ฐ ๊ณ์ ๋ฐ์ํฉ๋๋ค.
ex) https://everevent.kro.kr/test
๐ ํด๊ฒฐํด์ผํ ์ฌํญ
https ์ ์ฉ์ ์ฑ๊ณตํ์ง๋ง ํด๋น ๋ฐฉ๋ฒ์๋ ๋ช๊ฐ์ง์ ๋ฌธ์ ๊ฐ ์กด์ฌํฉ๋๋ค.
- ๋๋ฉ์ธ ์ฃผ์์ ์ ํจ๊ธฐ๊ฐ
- SSL ์ธ์ฆ์์ ์ ํจ๊ธฐ๊ฐ
- jks ํ์ผ์ด resource ํด๋ ๋ด๋ถ์ ์์ด public์ผ๋ก ๋ ธ์ถ๋จ
1๋ฒ์ ๊ฒฝ์ฐ๋ ๋ค๋ฅธ ๋ฌด๋ฃ ๋๋ฉ์ธ ๋ฐ๊ธ ์ฌ์ดํธ, ๋๋ ์ ๋ฃ๋ก ๋ฐ๊ธ๋ฐ์ ํด๊ฒฐ ๊ฐ๋ฅํฉ๋๋ค. (๋ฉํ ๋์ด ๊ณต์ ํด์ฃผ์ ๋งํฌ ์ฐธ๊ณ : https://cloud-oky.tistory.com/348)
2๋ฒ์ ๊ฒฝ์ฐ๋ ์๋์ผ๋ก SSL์ ๊ฐฑ์ ํ๋ ์ค์ ์ ์ถํ์ ์ค์ ํ ๊ฒฝ์ฐ ํด๊ฒฐ ๊ฐ๋ฅํฉ๋๋ค.
3๋ฒ์ ์ฌ๋ฌ๊ฐ์ง ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์กด์ฌํ๋๋ฐ, ์๋ธ๋ชจ๋๋ก jks ํ์ผ์ ์์น๋ฅผ ์ฎ๊ธฐ๋ ๋ฐฉ๋ฒ๊ณผ ์๋ฒ์ nginx๋ฅผ ๋์ nginx์ ssl ์ธ์ฆ์๋ฅผ ๋ฐ๊ธํ๋ ๋ฐฉ๋ฒ ์ ๋๋ค. ์ด๋ถ๋ถ์ ์ถํ์ ๋ฆฌํฉํ ๋ง์ ํตํด ๋ฐฉํฅ์ ๊ฒฐ์ ํด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
๐ ์ฐธ๊ณ ๋ฌธ์
Mixed content : https://c17an.netlify.app/blog/front-end/Mixed-Content-์ด์-ํด๊ฒฐํ๊ธฐ/article/
certbot ubuntu ์ค์น : https://www.manualfactory.net/13639
ssl ์ธ์ฆ์ ๋ฐ๊ธ : https://www.vompressor.com/tls1/
ํ๋ก์ ํธ์ sslํค ์ ์ฉํ๊ธฐ : https://elfinlas.github.io/2018/03/19/spring-boot-tls-certbot/
'Spring > Spring Security' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ExceptionTranslationFilter (0) | 2021.11.15 |
---|---|
AnonymousAuthenticationFilter (0) | 2021.11.15 |