How retrieve the user and SQL code associated with a BigQuery job?

后端 未结 1 918
陌清茗
陌清茗 2021-01-14 04:38

For security purposes, I\'d like to be able to audit who is running what kinds of queries within a certain project. Is this possible?

Using bq ls -j fro

相关标签:
1条回答
  • 2021-01-14 05:19

    In the CLI, you can run bq ls -j -a to retrieve jobs for all users in a project.

    Then you can run for each job id a bq show -j <job_id> and in order to have more details you will choose to use the json response:

    bq show --format=prettyjson -j job_joQEqPwOiOoBlOhDBEgKxQAlKJQ
    

    this returns the following format which have your query, your user and bytesprocessed etc...

    {
      "configuration": {
        "dryRun": false, 
        "query": {
          "createDisposition": "CREATE_IF_NEEDED", 
          "destinationTable": {
            "datasetId": "", 
            "projectId": "", 
            "tableId": ""
          }, 
          "query": "", 
          "writeDisposition": "WRITE_TRUNCATE"
        }
      }, 
      "etag": "", 
      "id": "", 
      "jobReference": {
        "jobId": "", 
        "projectId": ""
      }, 
      "kind": "bigquery#job", 
      "selfLink": "", 
      "statistics": {
        "creationTime": "1435006022346", 
        "endTime": "1435006144730", 
        "query": {
          "cacheHit": false, 
          "totalBytesProcessed": "105922683030"
        }, 
        "startTime": "1435006023171", 
        "totalBytesProcessed": "105922683030"
      }, 
      "status": {
        "state": "DONE"
      }, 
      "user_email": ""
    }
    

    Using the API you need to pass allUsers property to list jobs from all users https://cloud.google.com/bigquery/docs/reference/v2/jobs/list#allUsers

    0 讨论(0)
提交回复
热议问题