์ ๋ฒ ํฌ์คํ ์์ ์์๋ก Public Repository๋ฅผ ์ฌ์ฉํ์ง๋ง, ์ค์ํ ํ์ผ์ด ๋ค์ด์๋ ๋ ํฌ์งํ ๋ฆฌ๋ ๋น์ฐํ private์ผ๋ก ์ค์ ๋์ด ์์ ๊ฒ์ด๋ค.
๊ทธ๋ผ ์ด๋ฒ ํฌ์คํ ์์ , Config Server์์ private repository๋ก๋ถํฐ ์ค์ ํ์ผ์ ๊ฐ์ ธ์ฌ ์ ์๋๋ก ์ธํ ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๋๋ก ํ๊ฒ ๋ค.
1. ๋น๋์นญ ํค ์์ฑ
๋งฅ์์๋ ssh ๋น๋์นญ ํค๋ฅผ ๋ง๋ค ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค.
$ ssh-keygen -m PEM -t rsa -b 4096 -C {๊นํ๋ธ ๊ณ์ }
์ ์ฅํ ์์น์ ๋น๋ฐ๋ฒํธ(passphrase)๋ฅผ ์ค์ ํ๊ณ ๋ง๋ค์ด์ฃผ์.
2. Deploy Key ๋ฑ๋ก
๋ง๋ค์ด ์ฃผ๋ฉด, .pub ์ Public key๋ฅผ ๋ณผ ์ ์๋๋ฐ
์ด๋ฅผ ๊ฐ์ ธ์ค๋ ค๋ Private repository์ Deploy Key๋ก ๋ฑ๋กํด์ฃผ์.
์์ฑํ ํค๋ฅผ cat ๋ช ๋ น์ด๋ก ๋ณด๊ณ , ํค๋ก ๋ฑ๋กํด์ฃผ์.
$ cat ~/.ssh/id_rsa.pub
3. yml ์ค์
config server์ ๋ค์๊ณผ ๊ฐ์ด yml ์ค์ ์ ํด์ฃผ์.
spring:
cloud:
config:
server:
git:
uri: {๊นํ๋ธ ์ฃผ์}
ignore-local-ssh-settings: true
passphrase: {passphrase}
private-key: |
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,660C2ED7C6F0A4A92AC04CCA7E052C79
~์๋ต~
-----END RSA PRIVATE KEY-----
- uri๋ ๊นํ๋ธ ๋ ํฌ์์ ๊ฐ์ ธ์ฌ ์ ์๋ค.
- passphrase์ ํค๋ฅผ ์์ฑํ ๋ ๋ฃ์๋ ๊ฐ์ ๋ฃ์ด์ฃผ์.
- private-key๋
$ cat ~/.ssh/id_rsa
์์ ๋์จ private key๋ฅผ ๋ฃ์.
์ด์ ์ ์์ ์ผ๋ก ๊ฐ์ ธ์ค๋์ง ํ์ธํด๋ณด์.
์ ๊ฐ์ ธ์ค๋ ๊ฒ ๊ฐ๋ค.
์ธ์ฆ์ ์คํจํ๋ฉด, no authorize ์ด๋ผ๊ณ ๋์ค๋ ๊ฒ ๊ฐ๋ค.
4. private key ์ํธํ(๋ฏธ๊ฒฐ)
๊ทธ๋ฐ๋ฐ, ์ฌ๊ธฐ์ ๋ฌธ์ ๊ฐ ์๋ค.
Config Server ์ ๋ค์ด๊ฐ๋ ๋น๋์นญ ํค ๊ฐ์ ๊นํ๋ธ์ ๊ทธ๋๋ก ์ฌ๋ผ๊ฐ๊ฒ ๋๋ค.
์ด ๋น๋์นญ ํค ๊ฐ์ด ์๋ค๋ฉด ๋๊ตฌ๋ ์ง ๋ด private repository์ ์ ๊ทผํ ์ ์๋ ๊ฒ์ด๋ค.
๋ฐ๋ผ์, yml์ ์๋ ์ด private ํค ๊ฐ์ ์ํธํ ํด์ผํ๋ค.
์ด ๋ฐฉ๋ฒ์ ๊ดํ ์๋ฃ๋ ๋ง์ด ์์ด์ ์ฐพ์ง ๋ชปํ๋ค ๐ฅน
๊ทธ๋๋ง ์ฐพ์ ๋ฐฉ๋ฒ์ Spring Cloud์์ ์ ๊ณตํ๋ ๋์นญ ํค ์ํธํ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋๊ฒ ๋ง์ง ์์๊น..?
1. ํค ์คํ ์ด ์์ฑ
$ keytool -genkeypair -alias privateKey -keyalg RSA -dname "CN=Web Server, OU=Unit, O=Organization, L=Seoul, C=KR" -keypass "password" -keystore privateKey.jks -storepass "password"
2. ์ธ์ฆ์ ์ถ์ถ
$ keytool -export -alias privateKey -keystore privateKey.jks -rfc -file trustServer.cer
3. public key ์์ฑ
$ keytool -import -alias trustServer -file trustServer.cer -keystore publicKey.jks
์ด๋ ๊ฒ ํ๋ฉด, privateKey.jks, publicKey.jks, trust.cer ์ธ ํ์ผ์ด ์๊ธด๋ค.
์ด์ , Spring Cloud Config์ ํค๋ฅผ ์ค์ ํด ๋๊ณ ,
encrypt:
key-store: # ๋น๋์นญ ํค ์ฌ์ฉ
location: file:///Users/kimdonghyun/.ssh/jks/privateKey.jks #private key์ ์์น
password: password
alias: privateKey
private key ๊ฐ์ encrypt ํ์ฌ
cipher ํํ๋ก ๋ฃ๋ ๋ฐฉ๋ฒ๋ ์๊ฒ ์ง๋ง.. private key๋ฅผ ์ํด์ ํ๋ฒ ๋ ๋์นญ ํค๋ฅผ ๋ง๋ค๊ณ ๋ณตํธํ ..?
๋ญ๊ฐ ๋นํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ๋ค. ๊ณผ์ฐ ํ์ ์์ ์ด๋ป๊ฒ ํ๋๊ฑธ๊น ..
๋ง์ฝ ๋ด๊ฐ ์ค์ ๊ฐ๋ฐํ๋ ์ํฉ์ด๋ผ๋ฉด, ๋ก์ปฌ์์๋ private key๊ฐ์ด ๋ค์ด์๋ yml์ ์ฌ๋ฆฌ์ง ์๊ณ ,
์ค์ ๋ฐฐํฌ ํ๊ฒฝ์์๋ Github Action + Secret ์ ํตํด์ Private key๋ฅผ ์ฃผ์ ํ ๊ฒ ๊ฐ๋ค.
'BackEnd > Spring Cloud' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ Spring Cloud ] Microservice๋ค ๊ฐ์ ํต์ ๊ตฌ์ถํ๊ธฐ (2) - Kafka (0) | 2024.02.18 |
---|---|
[ Spring Cloud ] Microservice๋ค ๊ฐ์ ํต์ ๊ตฌ์ถํ๊ธฐ (1) - WebClient (0) | 2024.02.14 |
[Spring Cloud] Spring Cloud Bus (0) | 2024.02.05 |
[Spring Cloud] Actuator๋ฅผ ์ด์ฉํ Config Server ๊ธฐ๋ (0) | 2024.01.29 |
[Spring Cloud] API Gateway, Filter (1) | 2024.01.08 |