限制Google服务帐户的权限?

时间:2015-10-19 22:03:16

标签: google-api google-bigquery

我正在浏览Google的OAuth 2.0 for Server to Server Applications指南,并尝试使用服务帐户的凭据来调用Google API。

所以我有一个data对象,其中包含从JSON密钥文件解析的凭据。

def get_bigquery_service():
    # ... Read and parse JSON Key file
    scope = ["https://www.googleapis.com/auth/bigquery"]
    credentials = SignedJwtAssertionCredentials(
        data['client_email'],
        data['private_key'],
        scope=scope)
    http = httplib2.Http()
    http = credentials.authorize(http)
    return build("bigquery", "v2", http=http)

然后我将可以访问BigQuery API,因为我在scope声明了它。

我担心的是,我无法看到任何允许我实际约束服务帐户以便能够在Google Developer Console中使用BigQuery API的选项。让我们说如果凭证文件被意外泄露给其他人,他们基本上可以对我的任何服务做任何事情,只需在scope中声明他们想要访问的内容。

我们有什么办法可以限制服务帐户的权限吗?

1 个答案:

答案 0 :(得分:1)

所以你有项目-A并且想要创建一个只能使用BigQuery并分析项目A中的数据的服务帐户?

创建project-B,并仅为其启用BigQuery API。为project-B创建一个服务帐户。然后在project-A中给project-B访问以分析其数据。