我正在Github Actions中运行一个工作流,它构建了一个Docker映像,然后在一个容器中运行一些gsutil命令。
我遇到了身份验证问题,gsutil命令需要访问GCP上的存储桶,但我收到了错误:
Run docker run ltr:latest /bin/sh -c "gsutil cat gs://test-bucket/test_file.txt"
ServiceException: 401 Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.
Error: Process completed with exit code 1.
我不能提供一个完全可复制的代码,因为它需要将GCP项目和服务帐户凭据保存在github的secrets中,但这是我能分享的最多的代码:
Github操作工作流定义:
name: test
on: push
jobs:
test-gsutil-command:
runs-on: [self-hosted, ubuntu-latest]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0
- name: Register gcloud as a Docker credential helper
run: gcloud auth configure-docker
- name: build
run: docker build ltr:latest .
- name: Run gcloud command in docker
run: docker run ltr:latest /bin/sh -c "gsutil cat gs://test-bucket/test_file.txt" # this line is giving me the above error
停靠文件
FROM gcr.io/deeplearning-platform-release/tf-gpu.2-8
RUN mkdir -p /ltr
COPY requirements /ltr/requirements
COPY Makefile /ltr
COPY setup.py /ltr
WORKDIR /ltr
RUN python -m pip --no-cache-dir install -r requirements/base.txt
另一件重要的事情是,我确信我正在使用的服务帐户可以访问我要从中读取文件的存储桶-我可以在本地运行gsutil命令。
您能告诉我,除了工作流中的gcloud auth configure-docker
之外,我还需要做什么才能在Docker容器中运行gsutil命令吗?
1条答案
按热度按时间s71maibg1#
Google已经开发了GitHub操作来促进与Google云的集成。请参见GitHub Action for authenticating to Google Cloud。
一个可以考虑的好机制是Workfload Identity Federation。Google|GitHub支持使用此来验证GitHub操作,请参见Enabling keyless auth from GitHub Actions