【发布时间】:2020-06-18 15:19:01
【问题描述】:
我希望允许用户模拟服务帐户来对长时间运行的进程进行操作。 但是,所有代码示例都说明了一个服务帐户模拟另一个服务帐户。
用户可以直接模拟服务帐号吗?如果有,怎么做?
我正在关注this example code。
初始化无权访问列表存储桶的源凭据:
from google.oauth2 import service_acccount
target_scopes = [
'https://www.googleapis.com/auth/devstorage.read_only']
source_credentials = (
service_account.Credentials.from_service_account_file(
'/path/to/svc_account.json',
scopes=target_scopes))
现在使用源凭据获取凭据以模拟另一个服务帐户:
from google.auth import impersonated_credentials
target_credentials = impersonated_credentials.Credentials(
source_credentials=source_credentials,
target_principal='impersonated-account@_project_.iam.gserviceaccount.com',
target_scopes = target_scopes,
lifetime=500)
【问题讨论】:
-
你的问题一分。你提到了一个长期运行的过程。用户或服务帐户访问令牌的最长时间为 3,600 秒(一小时)。您需要令牌用于哪种类型的流程?两种帐户类型具有相同的到期限制。
-
进程长期运行,但由另一个谷歌产品处理,服务帐户只负责启动、停止或修改该进程。
标签: google-cloud-platform impersonation service-accounts google-iam google-cloud-iam