-
[AWS/CodeCommit] 프로젝트별(AWS계정별) 자격증명 설정하기기타/Git 2023. 10. 13. 13:50
개요
최근 회사에서 다른 팀과 프로젝트 협업을 하게 되어 해당 팀 AWS CodeCommit의 레포지토리를 연결해야할 일이 생겼다.
하지만 나는 이미 우리 팀 AWS CodeCommit을 세팅해놓은 상태였다.
그래도 혹시 모르니!!! git clone을 시도해보았고 역시나 될리가 없었다...ㅎ
에러 발생
403에러가 아닌 not found 일 경우 해당 레포지토리가 없을 수 있지만
레포지토리 주소가 틀리지 않았다면 자격 증명 계정이 다른 경우에도 발생하는 에러이다.
fatal: repository 'https://git-codecommit.' not found
➔ 레포지토리가 없음 / git global로 설정된 자격증명 계정에 해당 레포지토리가 없음
fatal: unable to access ‘https://git-codecommit.’: The requested URL returned error: 403
➔ 자격증명의 region이 다름 / 만료된 자격 증명임
프로젝트별 자격증명 설정 방법 (multiple aws accounts) - MacOS 기준
해당 설정은 아래 글을 참고하였습니다
https://aws.amazon.com/blogs/devops/using-git-with-aws-codecommit-across-multiple-aws-accounts/
Using Git with AWS CodeCommit Across Multiple AWS Accounts | Amazon Web Services
I use AWS CodeCommit to host all of my private Git repositories. My repositories are split across several AWS accounts for different purposes: personal projects, internal projects at work, and customer projects. The CodeCommit documentation shows you how t
aws.amazon.com
1. 개발 프로젝트를 모아두는 폴더 내부에 아래와 같이 폴더 구성
team1 project team2 project
team1 은 aws 계정 단위(나의 경우에는 회사 내부팀 이름)
각 팀 내에 여러개의 project 가 존재할 수도 있다.
이제 aws의 config와 git의 config를 연결해주면 된다.
그 전에 전제 조건이 있다.
AWS CLI 가 설치되어 있어야 한다! 아래 링크에서 설명해주는대로 설치하기!!
https://docs.aws.amazon.com/ko_kr/codecommit/latest/userguide/setting-up-https-unixes.html
(이후 aws --help 명령어로 설치 확인)
2. aws config 에서 profile을 작성한다.
[default] region = ap-northeast-2 [profile team1] region = ap-northeast-2 aws_access_key_id = team1에서 제공받은 ACCESS KEY aws_secret_access_key = team1에서 제공받은 SECRET ACCESS KEY [profile team2] region = ap-northeast-2 aws_access_key_id = team2에서 제공받은 ACCESS KEY aws_secret_access_key = team2에서 제공받은 SECRET ACCESS KEY
각 팀 계정에서 aws의 access key와 secret access key를 요청해서 받아 profile을 설정해준다.
region은 나의 경우 프로젝트가 모두 Seoul이였기 때문에 ap-northeast-2를 적용해주었다.
주의!
secret access key는 access key를 처음 받을 때만 확인할 수 있고, 그 이후로는 확인할 수 없으므로 받아둔 계정 파일(xlsx)을 삭제하지 않거나 따로 메모를 해두기!!!
관리자 계정으로 IAM에서 사용자별 Access Key 발급하는 방법은 아래 포스팅 참고~
https://stirringdev.tistory.com/112
[AWS] IAM으로 사용자별 access key발급하기
개요 AWS CLI 로 다중 credential 을 사용하기 위해서는 access key와 secret access key를 발급 받아서 사용하기 위해 시도했다. 사용자별 Access Key 및 Secret Access Key 발급하는 방법 1. 관리자 계정으로 접속하
stirringdev.tistory.com
3. git config를 작성한다.
중요!!하게 유심히 살피기
.gitconfig 와 .gitconfig-team1 그리고 .gitconfig-team2 파일을 각각 작성해야한다.
우선 내 컴퓨터에 git을 설치했다면 MacOs 기준으로
~(/Users/myName) 경로에 .gitconfig 파일이 있을 것이다.
해당 파일을 열어 아래와 같이 설정을 해둔다.
[user] # 내 이메일과 이름을 적어줌 email = defaultMyEmail name = defaultMyName [credential "https://github.com"] helper = helper = osxkeychain # 각 팀 폴더별로 .gitconfig를 설정 [includeIf "gitdir:~/Desktop/web-project/team1/"] path=~/.gitconfig-team1 [includeIf "gitdir:~/Desktop/web-project/team2/"] path=~/.gitconfig-team2
.gitconfig가 있는 동일한 경로에 .gitconfig-team1과 .gitconfig-team2를 만들어 각각 설정해준다.
// ~/.gitignore-team1 [user] name = myName [credential] # helper를 빈문자열로 1차 설정함으로써 캐싱된 데이터를 날리고 다시씀 # 이걸 해주지 않으면 403에러가 발생함 helper = helper = !aws --profile team1 codecommit credential-helper $@ UseHttpPath = true // ~/.gitignore-team2 [user] name = myName [credential] helper = helper = !aws --profile team2 codecommit credential-helper $@ UseHttpPath = true
결과 확인
team2 경로 또는 team2의 프로젝트 경로 내에서 git config --list 명령어를 사용해 내용을 살펴보면,
includeif에서 team2의 내용만 읽는 것을 확인할 수 있다.
git config는 아래와 같은 순서대로 읽어와서 설정 된다.
~/.gitconfig ➔ ~/.gitconfig-team2 ➔ ~/Desktop/web-project/team2/myProjectName/.git/config
성공~!
'기타 > Git' 카테고리의 다른 글
[GitLab] CI/CD와 Microsoft Teams 알림 연동 (feat.WebHooks) (0) 2024.10.18 [GitLab] GitLab Runner를 이용한 자동 통합 배포 시스템 구축 (4) 2024.10.17 [github] macOS에서 ssh 연결하기 (0) 2023.04.10 [Github] 깃허브 프로필의 Overview 작성하는 방법 (0) 2022.06.01 [GIT] 내 컴퓨터에서 만든 프로젝트를 github에 올리기 (0) 2022.05.29