如何解决允许未经身份验证的参数不起作用
我正在使用以下 .yaml 文件通过 GitHub 和 Google Cloud Build 创建 CICD 管道:
# Cloud Function specifications
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args:
- functions
- deploy
- hello_world
- --source=./src
- --trigger-http
- --memory=1024MB
- --max-instances=5
- --runtime=python39
- --region=europe-west6
- --entry-point=predict
- --allow-unauthenticated
一切正常,功能部署正确;但是,每当我尝试调用它时,都会抛出以下错误:
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
似乎 --allow-unauthenticated 参数工作不正常。 如何公开 API 并提供公共访问权限?
注意:
如果我运行 gcloud functions describe --project=XXXXXX --region=europe-west6 hello_world
我明白了:
availableMemoryMb: 1024
buildId: 1234
entryPoint: predict
environmentVariables:
ABC: '"discount"'
httpsTrigger:
securityLevel: SECURE_OPTIONAL
url: https://europe-west6-XXX.cloudfunctions.net/hello_world
ingressSettings: ALLOW_ALL
labels:
deployment-tool: cli-gcloud
maxInstances: 5
name: projects/XXX/locations/europe-west6/functions/hello_world
runtime: python39
serviceAccountEmail: XXX@appspot.gserviceaccount.com
sourceUploadUrl: https://storage.googleapis.com/gcf-upload-europe-west6XXX
status: ACTIVE
timeout: 60s
updateTime: '2021-06-10T17:09:55.950Z'
versionId: '2'
解决方法
使用 --allow-unauthenticated
标志修改 IAM 权限。
为确保未经授权的开发人员无法修改功能权限,正在部署该功能的用户或服务必须具有
cloudfunctions.functions.setIamPolicy
权限(如 here 所述)。
上述权限包含在 Owner 和 Cloud Functions Admin 角色中。因此,一旦将 Function Admin 角色授予 Cloud Build 服务帐户,一切都会正常运行。
,请修改云构建服务帐号权限并添加功能管理员角色,应该可以了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。