GiithubActions에서 IAMRole을 사용하여 CodeCommiit에 미러링

개요


다음은 Action을 사용하여 Giithub에서 CodeCommiit로 미러링하는 방법에 대해 설명합니다.
검색만 하면 이쪽 동작으로 할 수 있어요.
pixta-dev/repository-mirroring-action
다만, IAM의 SSH 키를 Secrets에 로그인하여 push를 만드는 방법
최근에 지허브AWS 제휴의 말을 들었다.
안전성 측면에서도 가능하다면 IAMRole로 구현하고 싶어서 조사한 뒤 필기를 했습니다

절차.


IAMRole의 프로듀싱.


Giithub 측에서 Assiume Role을 위해 Role을 준비합니다.
참고여기 기사.제작GithubActionsDeployRole, 후속 작업에서 로엘의arn을 사용합니다.

actions 설정


다음yaml을 actions로 설정하면push가 거울로 비칩니다.간단하다
name: Mirror to CodeCommit

on:
  push:

env:
  AWS_REGION: ap-northeast-1
  AWS_ROLE_ARN: arn:aws:iam::xxxxxxxx:role/GithubActionsDeployRole
  AWS_WEB_IDENTITY_TOKEN_FILE: /tmp/awscreds
  ECR_REPOSITORY: yourrepo

jobs:
  deploy:
    name: Mirror
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read

    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Configure AWS
      run: |
        echo AWS_WEB_IDENTITY_TOKEN_FILE=$AWS_WEB_IDENTITY_TOKEN_FILE >> $GITHUB_ENV
        echo AWS_ROLE_ARN=$AWS_ROLE_ARN >> $GITHUB_ENV
        echo AWS_DEFAULT_REGION=$AWS_REGION >> $GITHUB_ENV
        curl --silent -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sigstore" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE

    - name: Configure git
      run: |
        git config --global credential.helper '!aws codecommit credential-helper $@'
        git config --global credential.UseHttpPath true
        
    - name: Mirroring
      run: |
        git remote add mirror https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/$ECR_REPOSITORY
        git push --tags --force --prune mirror "refs/remotes/origin/*:refs/heads/*"

IAMRole의 arn과 창고 이름을 각각 설정
AWS 인증 작성 섹션 참조AWS federation comes to GitHub Actions
AWS 계정을 시크릿에 등록하는 게 좋을 것 같아요.
git의 config 추가 참조AWS 문서, 인증 정보 조수 설정
미러링 명령 참조pixta-dev/repository-mirroring-action 설정
다음 오류가 발생했습니다.checkout 이 인자가 필요합니다with:fetch-depth: 0
remote: Unknown commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
error: remote unpack failed: Unknown commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
To https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/xxxxxx
 ! [remote rejected] origin/main -> main (unpacker error)
error: failed to push some refs to 'https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/xxxxxx'

SSH 키 활용에서 해방되세요!

좋은 웹페이지 즐겨찾기