docker - Authentication, O Auth 2, Google Cloud Platform COS Container Optimized
问题描述
我在 Google Cloud 上使用容器优化的“COS”Linux 创建了一个 GCP 实例。该实例还从 Docker 存储库中提取,并在启动时托管多个容器。机器运转良好,实例处于活动状态。绝对没有错误。
当我尝试使用https://www.googleapis.com/../ 从外部访问它时,问题就出现了。.
我收到以下错误(在任何浏览器中):
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED"
}
}
我与 GCP 合作多年,从未见过此错误。不过我刚开始使用COS。我在想这可能与此有关?有什么提示吗?
解决方案
在 GCE 中,存储 API 的默认访问范围是只读的,并且由于您的实例从 Docker 注册表中提取,因此您使用的服务帐户需要具有以下范围之一:
- 读/写(https://www.googleapis.com/auth/devstorage.read_write)
- 完全控制(https://www.googleapis.com/auth/devstorage.full_control)
您可以在 Cloud Console 中的实例详细信息中或在 Cloud Shell 中使用以下命令检查和编辑实例的 API 范围:
- 列出访问范围:
curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/?recursive=true" -H "Metadata-Flavor: Google"
- 添加范围:
gcloud alpha compute instances [INSTANCE_NAME] --scopes=[SCOPE,...] --service-account=[SERVICE_ACCOUNT]
. 将 [SCOPE] 替换为storage-rw
(读/写)或storage-full
(完全控制)。
推荐阅读
- java - 检测 if 语句中大小写混合的单词
- django - 如何将空间 JOIN 翻译成 Django 查询语言?
- css - 如何在引导反应中添加高度和溢出属性以反应表?
- python - 有评分就不能删帖吗?
- java - 允许 URL 中的语言参数(Spring Boot / Security)
- python - python plotly小提琴图显示负尾
- javascript - React Native Fetch video file by chunk / YouTube Data API chunk(multipart) upload
- hyperledger-fabric - 如何列出链码?
- c# - 当 portId = 0 时,TcpServerChannel 抛出 SocketException
- javascript - 使用javascript检查元素的转换属性