[英]AWS cross account access to CodeCommit repo with roles only (no static credentials)
我在AWS帳戶1111中有一個CodeCommit REPO1。我需要在EC2實例中克隆REPO1,該實例將在AWS帳戶2222中啟動並定期終止。啟動EC2是為了在短時間內(幾分鍾)執行一些批處理作業,然后以自動方式終止。
在不生成靜態證書的情況下,我如何使用角色在2222中啟動EC2實例,從1111克隆REPO1。必須使用bash / CLI使該過程自動化。
幾天來,我一直把頭撞在桌子上,無濟於事。
您需要在帳戶1111中創建一個角色(R1):
然后,您需要確保EC2實例的實例角色具有AssumeRole權限。 這使您可以從EC2實例中假設R1。
現在,在帳戶2222中的EC2實例中,您應該設置一個通過角色訪問REPO1的配置文件。 為此,您可以在〜/ .aws / config文件中添加類似於以下內容的內容:
[profile cross-account-role]
role_arn = arn:aws:iam::<1111>:role/<R1>
credential_source = Ec2InstanceMetadata
external_id = <ExternalId of R1>
output = json
region = <Region where REPO1 is>
然后,您要確認是否正確設置了權限,可以執行以下操作:
aws --profile cross-account-role get-repository --repository-name REPO1
一旦完成,您要配置git客戶端,使其在~/.gitconfig
通過正確的配置文件使用credential-helper, ~/.gitconfig
是運行:
git config --global credential.helper '!aws codecommit --profile cross-account-role credential-helper $@'
git config --global credential.UseHttpPath true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.