CodeCommit 의 저장소에 접근하는 방법은 3가지가 있다.
- HTTPS : 가장 간편. IAM 사용자라면 https git 자격 증명을 발급 받아 접근 가능
- SSH : IAM 사용자로서 SSH 키 페어 발급 및 사용 (로컬에 host, config 파일 설정)
- HTTPS (GRC): 나머지 루트 계정, 페더레이션 액세스, 임시 보안 인증 정보 사용으로 접근 가능
GRC(git-remote-codecommit) 방식은, git-remote-codecommit 이라는 툴을 사용하여 저장소에 접근하는 방법인데, 다른 AWS 계정의 IAM 사용자에게 저장소를 공유하기 위해 사용해 보겠다.
1. 정책/역할 생성
다른 AWS 계정에게 부여할 정책을 생성한다.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:BatchGet*",
"codecommit:Create*",
"codecommit:DeleteBranch",
"codecommit:Get*",
"codecommit:List*",
"codecommit:Describe*",
"codecommit:Put*",
"codecommit:Post*",
"codecommit:Merge*",
"codecommit:Test*",
"codecommit:Update*",
"codecommit:GitPull",
"codecommit:GitPush"
],
"Resource": [
"arn:aws:codecommit:us-east-2:111122223333:MySharedDemoRepo"
]
},
{
"Effect": "Allow",
"Action": "codecommit:ListRepositories",
"Resource": "*"
}
]
}
역할(FirstRepositoryRole)을 생성하여 위 정책을 연결하고 역할 ARN 을 복사하여, 다른 AWS 계정의 IAM 사용자에게 공유한다.
arn:aws:iam::111122223333:role/FirstRepositoryRole
필요하다면 위 정책 대신 powerful 한 정책을 부여해도 된다. (예, AWSCodeCommitPowerUser)
2. 접근할 다른 AWS 사용자(또는 그룹)에 정책 추가
저장소에 접근할 다른 AWS 계정의 IAM 사용자 또는 그룹에 정책 추가.
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::111122223333:role/FirstRepositoryRole"
}
}
3. 프로필 설정
다른 AWS 계정의 IAM 사용자는 git-remote-codecommit 을 사용하여 CodeCommit 저장소에 접근할 수 있도록 로컬 컴퓨터에 프로필을 구성해야 한다.
$ aws configure --profile my_profile
AWS Access Key ID [None]: Your-IAM-User-Access-Key
AWS Secret Access Key ID [None]: Your-IAM-User-Secret-Access-Key
Default region name ID [None]: us-east-2
Default output format [None]: json
일반적으로 설정하는 위 방식으로 IAM 사용자 인증 정보를 등록하면 사용자 디렉토리의 .aws/credential .aws/config 파일이 생성되는데 config 파일에 FirstRepositoryRole 저장소 접근 전용으로 사용할 프로필(repo1) 을 하나 생성해서 arn 정보와 연결 프로필(source_profile) 을 삽입한다.
[profile repo1]
region = us-east-2
role_arn = arn:aws:iam::111122223333:role/FirstRepositoryRole
source_profile = my_profile
4. git-remote-codecommit 설치
pip 가 설치되어 있지 않다면, 설치.
$ curl -O https://bootstrap.pypa.io/get-pip.py
$ python3 get-pip.py --user
$ pip install git-remote-codecommit
만약 맥에서 아래와 같이 externally-managed-environment 에러가 발생했다면, 이미 Python 이 homebrew 를 통해 설치되어 시스템 전체에 영향을 미칠 수 있기 때문이다.
% python3 get-pip.py --user
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.
If you wish to install a Python library that isn't in Homebrew,
use a virtual environment:
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz
If you wish to install a Python application that isn't in Homebrew,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. You can install pipx with
brew install pipx
You may restore the old behavior of pip by passing
the '--break-system-packages' flag to pip, or by adding
'break-system-packages = true' to your pip.conf file. The latter
will permanently disable this error.
If you disable this error, we STRONGLY recommend that you additionally
pass the '--user' flag to pip, or set 'user = true' in your pip.conf
file. Failure to do this can result in a broken Homebrew installation.
Read more about this behavior here: <https://peps.python.org/pep-0668/>
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
이 경우, 가상환경으로 세팅하는 것이 안정적이다.
$ python3 -m venv grc
$ source grc/bin/activate
$ python3 -m pip install git-remote-codecommit
5. git clone
HTTPS(GRC) 주소를 복사한 후 저장소 이름 앞에 프로필@ 추가하여 소스 복제
예) codecommit::ap-northeast-2://MySharedDemoRepo
$ git clone codecommit::ap-northeast-2://repo1@MySharedDemoRepo
'IT기술 > AWS' 카테고리의 다른 글
S3 오래된 객체 삭제 (0) | 2025.04.15 |
---|---|
AWS Reserved Instance (RI) (0) | 2025.03.21 |
CloudWatch Container Insights (1) | 2025.03.20 |
Failed deploy model due to AccessDenied (0) | 2025.03.20 |
AWS WAF setting (0) | 2025.03.17 |