실수로 깃헙에 올려선 안될걸 올렸을 때
프론트와 enum느낀 점
참조한 페이지
실수로 깃헙에 비밀번호나 인증키같은걸 올려버릴때가 있다. 그런경우 git rebase를 하면된다는데 아무리해도 안되서 BFG Repo-Cleaner
라는 것을 찾아봤다. JRE Java 8
이상이 깔려있어야한다.
sudo apt install openjdk-11-jre-headless
: 자바 설치 curl -o bfg.jar -L https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar
git clone --mirror <SSH>
: 클론해오기 (백업 추천)passwords.txt
생성 후 아래의 예제중 맘에 드는걸 고르자PASSWORD1 # Replace literal string 'PASSWORD1' with '***REMOVED***' (default)
PASSWORD2==>examplePass # replace with 'examplePass' instead
PASSWORD3==> # replace with the empty string
regex:password=\w+==>password= # Replace, using a regex
regex:\r(\n)==>$1 # Replace Windows newlines with Unix newlines
$ java -jar bfg.jar --replace-text passwords.txt </home/.../프로젝트폴더>
: passwords.txt
의 내용에 따라서 커밋의 문자열을 대체한다.passwords.txt
는 삭제하거나 .git ignore
에 넣자git add .
, git commit -m "Replace sensitive information"
, git push origin main --force
import { Entity, Column } from 'typeorm';
import { BaseEntity } from '../../common/entity';
export enum UserRole {
Admin = 'admin',
User = 'user',
}
@Entity()
export class User extends BaseEntity {
@Column()
name: string;
@Column()
phone: string;
@Column()
email: string;
@Column()
password: string;
@Column({
type: 'enum',
enum: UserRole,
default: UserRole.User,
})
role: UserRole;
}
User의 타입을 admin과 user로 나누었고 그래서 enum을 도입했다.
그런데 프론트에서 admin과 user 둘 중 하나만 보내도록 만들어두었다. 이렇다면 enum은 필요한 것일까?
GPT에게 물어봤다.
추가로 더 물어본 결과 GPT의 의견은 없어도 되지만, 값이 자주 바뀔경우에는 enum을 적용해두는 것이 가독성이 좋고, 관리하기도 편하다고한다.
우리는 두 개 말고는 사용할 계획이 없으나 코드 가독성을 유지하기위해 남기는게 좋을 것 같다.
평소에 보안사고는 바보만 내는것이라고 생각했는데 내가 내버렸다. 물론 프라이빗 레퍼지토리여서 아무도 모를일이었지만 실제로 유출이 됐다고 치고 해봤는데 생각보다 쉽지 않은 일이었다.
그래도 비슷한 일을 겪은 사람들이 많아서인지 내가 사용한 BFG Repo-Cleaner 말고도 git rebase를 활용한 방법도 있었다. 느낀바가 있는데...
1. git add
를 하기 전에는 항상 잘 확인을 해봐야겠다.
2. 애초에 민감한건 파일에 넣지말고 환경변수로 잘 저장하자.
BFG Repo-Cleaner
BFG Repo-Cleaner
Git에 큰 파일 및 인증키을 올렸을 경우 이력 삭제하기 - bfg-repo-cleaner