简体   繁体   English

GCP 403 调用方没有 create_transfer_config 的权限

[英]GCP 403 The caller does not have permission for create_transfer_config

I am working on GCP and trying to schedule queries in BigQuery by creating transfer configs through programming and required permissions are assigned to the new service account (bigquery.transfers.get, bigquery.transfers.update) and trying to create transfer config using below code.我正在使用 GCP 并尝试通过编程创建传输配置来安排 BigQuery 中的查询,并将所需的权限分配给新服务帐户(bigquery.transfers.get、bigquery.transfers.update)并尝试使用以下代码创建传输配置. I am able get the information about other already created schedule queries and able to update them.我能够获取有关其他已创建的计划查询的信息并能够更新它们。 But I am unable to create them.但我无法创建它们。 Getting 403 caller does not have permission.获取 403 呼叫者没有权限。

from google.cloud import bigquery_datatransfer

transfer_client = bigquery_datatransfer.DataTransferServiceClient()

project_id = "My_Project_Id"
dataset_id = "My_dataset_id"
service_account_name = "<serviceAccount>"
query_string = "update dataservices.temp_bq_schedule set current_time=current_timestamp() where some_integer=17"

parent = transfer_client.common_project_path(project_id)

transfer_config = bigquery_datatransfer.TransferConfig(
    destination_dataset_id=dataset_id,
    display_name="Test_Schedule_QUERY",
    data_source_id="scheduled_query",
    params={
        "query": query_string,
        "write_disposition": "",
        "partitioning_field": "",
    },
    schedule="every 24 hours",
)
transfer_config = transfer_client.create_transfer_config(
    bigquery_datatransfer.CreateTransferConfigRequest(
        parent=parent,
        transfer_config=transfer_config,
        service_account_name=service_account_name,
    )
)

print("Created scheduled query '{}'".format(transfer_config.name))

This is the error while executing the code这是执行代码时的错误

Traceback (most recent call last):
  File "/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 66, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/env/lib/python3.7/site-packages/grpc/_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/env/lib/python3.7/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.PERMISSION_DENIED
        details = "The caller does not have permission"
        debug_error_string = "{"created":"@1637593645.956604992","description":"Error received from peer ipv4:<some ip address with port>","file":"src/core/lib/surface/call.cc","file_line":1063,"grpc_message":"The caller does not have permission","grpc_status":7}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "merge_query.py", line 36, in <module>
    service_account_name=service_account_name,
  File "/env/lib/python3.7/site-packages/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/client.py", line 646, in create_transfer_config
    response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)
  File "/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 154, in __call__
    return wrapped_func(*args, **kwargs)
  File "/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 68, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.PermissionDenied: 403 The caller does not have permission

FYI, I also tried omitting the service_account but still the same issue.仅供参考,我也尝试省略 service_account 但仍然是同样的问题。

And code snippet can be found here https://github.com/googleapis/python-bigquery-datatransfer/blob/main/samples/snippets/scheduled_query.py代码片段可以在这里找到https://github.com/googleapis/python-bigquery-datatransfer/blob/main/samples/snippets/scheduled_query.py

This error is about permissions.此错误与权限有关。 You need these permissions below.您需要以下这些权限。

To schedule a query, you need the following Identity and Access Management (IAM) permissions:要安排查询,您需要以下身份和访问管理 (IAM) 权限:

  • bigquery.transfers.update or both bigquery.jobs.create and bigquery.transfers.get to create the transfer bigquery.transfers.update 或 bigquery.jobs.create 和 bigquery.transfers.get 来创建传输
  • bigquery.jobs.create to run the scheduled query bigquery.jobs.create 运行预定查询
  • bigquery.datasets.update on the target dataset目标数据集上的 bigquery.datasets.update

To modify a scheduled query, you must be the creator of the schedule and have the following permissions:要修改计划查询,您必须是计划的创建者并具有以下权限:

  • bigquery.jobs.create bigquery.jobs.create
  • bigquery.transfers.update bigquery.transfers.update

You can see more details about permissions .您可以查看有关权限的更多详细信息。

You can see this example code.您可以查看此示例代码。

from google.cloud import bigquery_datatransfer
 
transfer_client = bigquery_datatransfer.DataTransferServiceClient()
 
# The project where the query job runs is the same as the project
# containing the destination dataset.
project_id = "your-project-id"
dataset_id = "your_dataset_id"
 
# This service account will be used to execute the scheduled queries. Omit
# this request parameter to run the query as the user with the credentials
# associated with this client.
service_account_name = "abcdef-test-sa@abcdef-test.iam.gserviceaccount.com"
 
# Use standard SQL syntax for the query.
query_string = """
SELECT
  CURRENT_TIMESTAMP() as current_time,
  @run_time as intended_run_time,
  @run_date as intended_run_date,
  17 as some_integer
"""
 
parent = transfer_client.common_project_path(project_id)
 
transfer_config = bigquery_datatransfer.TransferConfig(
    destination_dataset_id=dataset_id,
    display_name="Your Scheduled Query Name",
    data_source_id="scheduled_query",
    params={
        "query": query_string,
        "destination_table_name_template": "your_table_{run_date}",
        "write_disposition": "WRITE_TRUNCATE",
        "partitioning_field": "",
    },
    schedule="every 24 hours",
)
 
transfer_config = transfer_client.create_transfer_config(
    bigquery_datatransfer.CreateTransferConfigRequest(
        parent=parent,
        transfer_config=transfer_config,
        service_account_name=service_account_name,
    )
)
 
print("Created scheduled query '{}'".format(transfer_config.name))

You can see more details about the code .您可以查看有关代码的更多详细信息

You can see more information about working with transfers .您可以查看有关使用传输的更多信息

You also need to make sure that the service account should come from the same project as where the scheduled query runs .您还需要确保服务帐户应该来自运行计划查询的同一项目 Otherwise it won't work.否则它不会工作。 I found that out the hard way.我很难发现这一点。

And of course make sure that you as a user and the service account have all permissions that are needed , which are described here:当然,请确保您作为用户和服务帐户拥有所需的所有权限,如下所述:
https://cloud.google.com/bigquery/docs/scheduling-queries#required_permissions https://cloud.google.com/bigquery/docs/scheduling-queries#required_permissions

See also: How to show and change user in Scheduled Queries另请参阅: 如何在计划查询中显示和更改用户

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GCP SQL 代理无法生成访问令牌; IAM 返回 403 Forbidden:调用者没有权限 - GCP SQL proxy Unable to generate access token; IAM returned 403 Forbidden: The caller does not have permission 403 调用者没有 Firebase 管理 API addFirebase 的权限 - 403 The caller does not have permission for Firebase Management API addFirebase BigQuery - 计划查询错误“PermissionDenied: 403 The caller does not have permission” - BigQuery - Scheduled Query Error "PermissionDenied: 403 The caller does not have permission" 使用服务帐户错误设置计划查询 PermissionDenied: 403 The caller does not have permission in data_transfer_service - Setting up a scheduled query with a service account error PermissionDenied: 403 The caller does not have permission in data_transfer_service Firebase 初始化函数返回 403 调用者没有权限 - Firebase init functions returns 403 caller does not have permission Bitrise Firebase 应用程序分发错误:上传版本失败。 HTTP 错误:403,调用者没有权限 - Bitrise Firebase App Distribution Error: failed to upload release. HTTP Error: 403, The caller does not have permission 来电者没有 DOCUMENT AI 的权限 - Caller does not have permission for DOCUMENT AI Firebase Admin Storage:调用者没有权限 - Firebase Admin Storage: The caller does not have permission 调用者没有权限。 行动 API - The caller does not have permission. Actions API GCP - 用户...无权访问项目实例 - GCP - User ... does not have permission to access projects instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM