목차
API호출 시 필요한 개인정보를 레포에 올려버림 -> info.plist에 내용 옮기고 -> gitignore로 info.plist 등록 -> 캐시도 제거 -> 하지만 HomeViewModel.swift 파일에 있던 개인정보는 그대로 커밋에 남아있음 -> BFG 이용하여 커밋에서 HomeViewModel 파일 제거
1. .gitignore를 통해 민감한 정보 제외하여 커밋하기
위의 사진처럼 민감한 정보가 퍼블릭 레포에 그대로 올라가있었다. 해당 ID와 Secret키는 Spotify를 구독해야만 얻을 수 있기 때문에, 악용될 가능성이 있어서 Info.plist에 정보를 넣어준 후 Info.plist파일을 .gitignore에 등록해줄 것이다.
Bundle name의 +버튼을 눌러 Key값을 추가하고, Value에는 Key값에 해당하는 정보를 넣어준다.
private var clientID: String {
get {
// 1
guard let filePath = Bundle.main.path(forResource: "Info", ofType: "plist") else {
fatalError("Couldn't find file 'Info.plist'.")
}
// 2
let plist = NSDictionary(contentsOfFile: filePath)
guard let value = plist?.object(forKey: "ClientID") as? String else {
fatalError("Couldn't find key 'ClientID' in 'Info.plist'.")
}
return value
}
}
private var clientSecret: String {
get {
// 1
guard let filePath = Bundle.main.path(forResource: "Info", ofType: "plist") else {
fatalError("Couldn't find file 'Info.plist'.")
}
// 2
let plist = NSDictionary(contentsOfFile: filePath)
guard let value = plist?.object(forKey: "ClientSecret") as? String else {
fatalError("Couldn't find key 'ClientSecret' in 'Info.plist'.")
}
return value
}
}
그리고 해당하는 정보에 접근하기 위해 정보가 쓰이는 파일 내에 작성해주면 plist에서 값을 불러와 사용할 수있다.
그리고 .gitignore에 Info.plist를 넣어주면 타인은 개인정보에 접근할 수 없게된다.
https://parkjye.tistory.com/28
[Git] .gitignore 파일 생성 방법
#.gitignore 프로젝트를 개발할 때 필요한 파일 이외의 파일들이 생성된다. .gitignore은 이러한 파일들을 git 관리 대상에서 제외하기 위해(commit에 포함하지 않도록) 규칙들을 저장한 파일이다. 예를
parkjye.tistory.com
위의 링크를 참고하여 만들 수 있다.
위에서 만든 .gitignore파일에
나같은 경우 YoutubeMusicAppClone폴더의 Info.plist를 등록해준다.
등록했음에도 종종 작동하지 않는 경우 git의 캐시가 원인이라고 한다. -> git에 있는 캐시파일을 지우고 다시 add해주면 된다.
git rm -r --cached .
git add .
git commit -m "removed cached"
여기까지하면 민감한 정보가 앞으로 커밋할 때 올라가지 않는다. 하지만 Info.plist는 ignore해주었지만, 기존 파일에 있던 정보는 커밋에 그대로 남아있다.
이럴 경우 두 가지 방법이 있다고 한다. Git 공식 문서에 보면 git filter-repo tool 또는 BFG Repo-Cleaner가 있다.
장단점이 있지만 전자에 비해 후자가 빠르고 간단하다고 한다.
2. BFG Repo-Cleaner를 사용하여 커밋에 남은 민감한 정보 지우기
https://rtyley.github.io/bfg-repo-cleaner/
BFG Repo-Cleaner by rtyley
$ bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git an alternative to git-filter-branch The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history: Removing Crazy Big Files Re
rtyley.github.io
여기에서 BFG Repo-Cleaner를 다운받아준다.
git clone --mirror git://example.com/some-big-repo.git
java -jar bfg.jar --delete-files id_{dsa,rsa} my-repo.git
cd some-big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push
터미널을 켜서 위의 순서대로 진행한다.
git clone --mirror https://github.com/yahoth/YoutubeMusicClone.git
java -jar "/Users/taehyoung/Downloads/bfg-1.14.0.jar" --delete-files HomeViewModel.swift YoutubeMusicClone.git
cd YoutubeMusicClone.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push
나의 경우는 이렇다. 두번째 코드에서 jar 뒤의 경로는 다운로드 받은 파일의 위치이다.
만약 두번째 명령어를 썻을 때 아래처럼 나온다면,
The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java.
brew install openjdk@11
sudo ln -sfn $(brew --prefix)/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
Homebrew가 있다는 가정하에, 두 명령을 넣어주고 진행한다.
다시 돌아가서, java로 시작하는 두번째 명령어가 잘 수행되면 이런 식의 응답이 아래쪽에 나온다.
그리고 레포를 확인해보면 기존 커밋들에서 해당 파일이 지워진 것을 확인할 수 있다.
출처:
https://growingarchive.tistory.com/244
[Git] .gitignore 사용법 및 작동하지 않는 경우 (+ .gitignore 템플릿 사이트)
1. .gitignore란? - 민감한 정보가 들어있는 파일이나 형상관리할 필요가 없는 파일들은 git에서 더이상 추적(track)하지 않도록 .gitignore 파일에 추가해 따로 빼준다. - .gitignore 파일은 프로젝트 디렉토
growingarchive.tistory.com
https://rtyley.github.io/bfg-repo-cleaner/
BFG Repo-Cleaner by rtyley
$ bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git an alternative to git-filter-branch The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history: Removing Crazy Big Files Re
rtyley.github.io
Mac The operation couldn’t be completed. Unable to locate a Java Runtime that supports jarsigner
My purpose is to use jarsigner to sign apk. I get the following prompt: % jarsigner The operation couldn’t be completed. Unable to locate a Java Runtime that supports jarsigner. Please visit h...
stackoverflow.com
https://yiunsr.tistory.com/773
git 히스토리 삭제 방법
git 를 이용하게되면 민감한 데이터(패스워드나 SSH Key)를 commit 하기도 한다. 이 git 가 공개된 git 일 경우 보안상에 문제를 일으키기도 한다. 패스워드는 아니지만 API Key 같은 경우도 문제가 될 수
yiunsr.tistory.com
[Swift] Plist를 활용해서 API key(민감정보) 가리기 (plist, 연산 프로퍼티, .gitignore)
GitGuardian에게 혼났을 때
velog.io
'개발 공부' 카테고리의 다른 글
앱스토어 리젝 대응(크래시 로그 분석방법) (0) | 2024.08.12 |
---|---|
애플 개발자 등록하기(feat: apple developer program 등록을 완료할 수 없습니다) (0) | 2024.03.15 |
ChatGPT 4.0을 무료로 사용가능한 AI 툴 [뤼튼: wrtn] (0) | 2023.07.06 |
API호출 후 데이터 가공해서 서버에 저장하기(2) (SwiftUI) (0) | 2023.04.03 |
API호출 후 데이터 가공해서 서버에 저장하기(1) (SwiftUI) (0) | 2023.03.31 |