HackTricks와 HackTricks Cloud github 저장소에 PR을 제출하여 자신의 해킹 기법을 공유하세요.
OIDC - Github Actions 남용
GCP
Github 레포지토리에서 GCP 서비스 계정에게 Github Actions에 대한 액세스 권한을 부여하려면 다음 단계가 필요합니다:
원하는 권한을 가진 서비스 계정을 생성하세요:
projectId=FIXMEgcloudconfigsetproject $projectId# Create the Service Accountgcloudiamservice-accountscreate"github-demo-sa"saId="github-demo-sa@${projectId}.iam.gserviceaccount.com"# Enable the IAM Credentials APIgcloudservicesenableiamcredentials.googleapis.com# Give permissions to SAgcloudprojectsadd-iam-policy-binding $projectId \--member="serviceAccount:$saId" \--role="roles/iam.securityReviewer"
새로운 워크로드 신원 풀을 생성하세요:
# Create a Workload Identity PoolpoolName=wi-poolgcloudiamworkload-identity-poolscreate $poolName \--location global \--display-name $poolNamepoolId=$(gcloudiamworkload-identity-poolsdescribe $poolName \--location global \--format='get(name)')
새로운 워크로드 식별 풀 OIDC 제공자를 생성합니다. 이 경우에는 github actions (조직/저장소 이름으로 신뢰)를 신뢰합니다:
위의 예시에서는 my-pool이라는 워크로드 식별 풀에 github-actions라는 OIDC 제공자를 생성합니다. google.subject과 google.audience를 assertion.sub와 assertion.aud에 매핑하고, assertion.aud가 github.com인 경우에만 사용 가능하도록 설정합니다. 허용된 발급자 접두사는 https://token.actions.githubusercontent.com입니다.
attributeMappingScope=repository # could be sub (GitHub repository and branch) or repository_owner (GitHub organization)
gcloudiamworkload-identity-poolsproviderscreate-oidc $poolName \--location global \--workload-identity-pool $poolName \--display-name $poolName \--attribute-mapping "google.subject=assertion.${attributeMappingScope},attribute.actor=assertion.actor,attribute.aud=assertion.aud,attribute.repository=assertion.repository" \
--issuer-uri "https://token.actions.githubusercontent.com"providerId=$(gcloudiamworkload-identity-poolsprovidersdescribe $poolName \--location global \--workload-identity-pool $poolName \--format='get(name)')
마지막으로, 공급자의 주체(principal)가 서비스 주체(service principal)를 사용할 수 있도록 허용합니다: