小编mag*_*ers的帖子

谷歌神器regitsry NPM + github操作

google-github-actions/auth@v0我正在尝试通过 github 使用和在 GAR(Google Artifact Registry)上发布 npm 包google-artifactregistry-auth

对于从 github 到 google 的身份验证,我使用联合工作负载身份执行以下操作:

export PROJECT_ID="my-project-id"

gcloud iam service-accounts create "gh-deploy-service-account" --project "${PROJECT_ID}"

gcloud iam workload-identity-pools create "github-pool" --project="${PROJECT_ID}" --location="global" --display-name="Github pool"

gcloud iam workload-identity-pools describe github-pool" --project="${PROJECT_ID}" --location="global" --format="value(name)"

export WORKLOAD_IDENTITY_POOL_ID=projects/my-custom-id-number/locations/global/workloadIdentityPools/github-pool

gcloud iam workload-identity-pools providers create-oidc "github-provider" \
  --project="${PROJECT_ID}" \
  --location="global" \
  --workload-identity-pool="github-pool" \
  --display-name="Github provider" \
  --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \
  --issuer-uri="https://token.actions.githubusercontent.com"

export REPO="@example/my-package"

gcloud iam service-accounts add-iam-policy-binding "gh-deploy-service-account@${PROJECT_ID}.iam.gserviceaccount.com" \
  --project="${PROJECT_ID}" \
  --role="roles/iam.workloadIdentityUser" \
  --member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/${REPO}"
Run Code Online (Sandbox Code Playgroud)

然后我在谷歌上创建了我的工件存储库:

gcloud artifacts repositories create …
Run Code Online (Sandbox Code Playgroud)

github gcloud github-actions google-artifact-registry workload-identity

4
推荐指数
1
解决办法
1879
查看次数