git-secret 암호화
이번 프로젝트에서 여러 API를 사용하면서 NAVER SENS API KEY, SLACK API KEY, 11ST OPEN API KEY 등 Secret Key들이 application.yml에 정의되어있는데 해당 파일이 gitHub과 같은 공유소스에 올라가버리면 Slack 같은 경우 탈취당했다고 보고 해당 API KEY를 무력화시켜 사용할 수 없도록 만들어버리고 나머지 API들도 타인의 악용가능성이 있기 때문에 해당 application.yml 파일을 노출하지 않아야했습니다. 또한 gitHub의 webhook을 통해 jenkins로 commit된 내역을 보내고 jenkins에서 빌드해 CI/CD환경을 구축하고 있는데 jenkins가 빌드할때는 application.yml파일이 존재해야 빌드가 가능했습니다. jenkins 내부에 application.yml을 가지고 있는 방법도 사용할 수 있지만 application.yml의 내용이 바뀌어야할때마다 매번 개발자가 jenkins를 들어가서 수정해줘야하는 번거로움이 있어 애초에 gitHub에 올릴 때 application.yml을 암호화해서 올리고 jenkins에서 빌드할 때 복호화하는 방식을 사용하였습니다.
1. WINDOWS10 UBUNTU
git-secret은 linux환경에서 사용이 가능하므로 WINDOWS 환경에서 사용하려면 UBUNTU를 Microsoft Store에서 별도로 다운받아 사용해야합니다.
(1). 개발자 설정 > 개발자 기능 사용 > 개발자 모드 클릭
(2). 제어판 > 프로그램 > 프로그램 및 기능 > Windows 기능 켜기/끄기 > Linux용 Windows 하위 시스템 체크 및 확인
제어판 > 프로그램 > 프로그램 및 기능 > Windows 기능 켜기/끄기 > Hyper-V 체크 및 확인
(3). Microsoft Store에서 UBUNTU 설치
혹시나 WSL 로 Ubuntu 실행 시, 0x800701bc 에러가 발생할 수 있는데, WSL2 Linux Kernel Update 를 설치해주면 해결됩니다. 다운로드 링크: https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi
참고 : Windows 10에서 Ubuntu 사용하기 :: Hello, A Whole New World (tistory.com)
[WSL] WSL2 Ubuntu 구동 시, 0x800701bc 에러 (tistory.com)
2. gpg, git-secret 설치 및 파일 암호화
ubuntu 접속 후
apt install gpg 로 gpg 설치
gpg --full-generate-key 명령어로 암호화에 쓸 key 발급
gpg (GnuPG) 2.2.4; Copyright (C) 2017 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (3072) 4096
Requested keysize is 4096 bits
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: PSC
Email address: email@email.com
Comment: PSC
You selected this USER-ID:
"PSC (PSC) <email@email.com>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
이 때 Comment까지 입력 후 비밀번호를 입력하라고 하는데 8자리 이상의 비밀번호를 입력합니다. ( 해당 비밀번호는 추후 Jenkins에서 복호화할 때 사용할 예정이니 기억해둡니다. )
apt install git-secret 으로 git-secret 설치 후
cd /mnt/c 으로 C드라이브로 이동 후 자신의 프로젝트 폴더로 이동
git-secret init 명령어로 git-secret 환경 초기화
git-secret tell 'email@email.com' 명령어로 사용자 추가
git-secret add 'filename' 명령어로 암호화시킬 파일 등록 ( add한 파일은 .gitignore 파일에 자동으로 추가됨 )
git-secret hide 명령어로 파일 암호화 후 .secret 파일 생성
이상입니다.
다음 게시글에서는 Jenkins로 복호화하는 방법에 대해 알아보겠습니다.
지금까지 읽어주셔서 감사합니다.