使用 gsutil 从 GKE 容器复制文件失败,出现 AccessDeniedException: 403 Insufficient Permission
Using gsutil to copy a file from a GKE container fails with AccessDeniedException: 403 Insufficient Permission
我在 Dockerfile 中安装了 gsutil,如下所示:
FROM postgres
RUN apt-get update -y
RUN apt-get install -y curl python && curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:/root/google-cloud-sdk/bin
然后将其部署为以下 Pod 中的容器:
apiVersion: v1
kind: Pod
metadata:
name: postgresql-backup
spec:
containers:
- name: web
image: xxx/posgresql-backup:latest
ports:
- name: web
containerPort: 80
protocol: TCP
command: ['sh', '-c', 'echo The app is running! && sleep 36000']
请注意,在我的例子中,容器在默认服务帐户下执行:111111111-compute@developer.gserviceaccount.com
我之前创建了一个名为:posgresql-backup
的存储桶
当我在执行容器中打开终端时:kubectl exec -it xxx -- /bin/bash
如果我 运行 gsutil ls gs://posgresql-backup
,它 returns 该存储桶中的文件列表:
gs://posgresql-backup/dump1.sql
然而,当我尝试将文件从容器 cp 到存储桶时 gsutil cp myfile.txt gs://posgresql-backup
:
AccessDeniedException: 403 Insufficient Permission
在存储桶权限中,我将服务帐户添加为 Storage Admin 和 Storage Object Admin,但这并没有什么不同。
我还缺少什么?
问题是 GKE 节点的默认节点池配置将 Cloud Storage API 设置为只读,因此我必须对其进行自定义:
我在 Dockerfile 中安装了 gsutil,如下所示:
FROM postgres
RUN apt-get update -y
RUN apt-get install -y curl python && curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:/root/google-cloud-sdk/bin
然后将其部署为以下 Pod 中的容器:
apiVersion: v1
kind: Pod
metadata:
name: postgresql-backup
spec:
containers:
- name: web
image: xxx/posgresql-backup:latest
ports:
- name: web
containerPort: 80
protocol: TCP
command: ['sh', '-c', 'echo The app is running! && sleep 36000']
请注意,在我的例子中,容器在默认服务帐户下执行:111111111-compute@developer.gserviceaccount.com
我之前创建了一个名为:posgresql-backup
的存储桶当我在执行容器中打开终端时:kubectl exec -it xxx -- /bin/bash
如果我 运行 gsutil ls gs://posgresql-backup
,它 returns 该存储桶中的文件列表:
gs://posgresql-backup/dump1.sql
然而,当我尝试将文件从容器 cp 到存储桶时 gsutil cp myfile.txt gs://posgresql-backup
:
AccessDeniedException: 403 Insufficient Permission
在存储桶权限中,我将服务帐户添加为 Storage Admin 和 Storage Object Admin,但这并没有什么不同。
我还缺少什么?
问题是 GKE 节点的默认节点池配置将 Cloud Storage API 设置为只读,因此我必须对其进行自定义: