【问题标题】:Failed to authenticate to Cloud IAP Backend from Cloud Tasks HTTP Request无法从 Cloud Tasks HTTP 请求向 Cloud IAP 后端进行身份验证
【发布时间】:2020-03-17 02:58:06
【问题描述】:

我正在尝试使用 Cloud Tasks HTTP 请求到达受 Cloud IAP 保护的 HTTPS 负载均衡器后面的 Kubernetes 端点。

端点使用任何 Gsuite 公司帐户正常工作,但当 Cloud Task 执行时,这是 Cloud Audit - 数据访问日志(仅显示重要部分)

authenticationInfo: {
}
authorizationInfo: [
  0: {
    permission: "iap.webServiceVersions.accessViaIAP"     
    resource: "projects/<PROJECT_NUMBER>/iap_web/compute/services/<SERVICE_NUMBER>/versions/bs_0"     
    resourceAttributes: {
      service: "iap.googleapis.com"      
      type: "iap.googleapis.com/WebServiceVersion"      
    }
  }
]

status: {
  code: 7    
  message: "PERMISSION_DENIED"    
}

我正在使用计算引擎服务帐户来创建任务,因此我已授予此帐户适当的权限:

当我创建任务时,我将适当的 OIDC 服务帐户电子邮件添加到 http 请求中

'oidc_token': {'service_account_email': <PROJECT_NUMBER>-compute@developer.gserviceaccount.com}}

我还检查了另一个端点上的 Cloud Tasks HTTP 请求,并且存在身份验证承载令牌。

目前我真的不知道如何让它发挥作用。 感谢您的帮助

【问题讨论】:

    标签: google-iap google-cloud-tasks


    【解决方案1】:

    我发现了问题,OIDC 需要特定的受众来使用 Cloud IAP。

    所需的受众是 IAP ClientID,可以在 API & Services > Credentials 中的 OAuth 2.0 客户端 ID 部分下找到,名称以 IAP 开头。

    此处的示例是用于添加可由 Cloud IAP 授予访问权限的任务的 python 代码。

    # This is the important part, the audience filed is very important! 
    oidc_token = {'service_account_email': <PROJECT_NUMBER>-compute@developer.gserviceaccount.com, 'audience': <PROJECT_NUMBER>-<NUMBER_GENERATED_AUTOMATICALLY_BY_IAP>.apps.googleusercontent.com}
    
    http_request = {'http_method': 'POST', 'url': url, 'body': json.dumps(payload).encode(), 'headers': headers, 'oidc_token': oidc_token}
    task['schedule_time'] = timestamp
    created_task = client.create_task(parent, {'http_request': http_request})
    

    【讨论】:

      猜你喜欢
      • 2020-07-22
      • 2022-12-15
      • 2020-08-24
      • 2020-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 2020-10-31
      相关资源
      最近更新 更多