Working with Row level Security and Python

I am working with Google Cloud Platform BigQuery and I have created a project in order to apply row level securities to restrict the access to information. I have tried to replicate the work done in BigQuery on Python. I have been able to create, update and delete row level security policies.

I have used this code

path to your json key file

KEY_PATH = “XXX.json”

read the credentials from our file

scopes are not necessary because we defined them in GCP already

CREDS = service_account.Credentials.from_service_account_file(KEY_PATH)

the client object will be used to interact with BQ

client = bigquery.Client(credentials=CREDS, project=CREDS.project_id)

and then for example:

Our SQL Query

Query_1 = “”"
SELECT *
FROM XXX.XXX.Test
“”"

labelling our query job

query_job_1 = client.query(Query_1)

results as a dataframe

Table = query_job_1.result().to_dataframe()
Table

It has worked perfectly.

BUT I have not been able to have the list of row Access Policies. If I look at the documentation Method: rowAccessPolicies.list | BigQuery | Google Cloud. It is explained that we need to use the following HTTPS and use a request GET but when I am running it in my python script I have a 401 ERROR message saying:

{'error': {'code': 401,
  'message': 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See [https://developers.google.com/identity/sign-in/web/devconsole-project.',](https://developers.google.com/identity/sign-in/web/devconsole-project.',)
  'status': 'UNAUTHENTICATED',
  'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo',
    'reason': 'CREDENTIALS_MISSING',
    'domain': 'googleapis.com',
    'metadata': {'service': 'bigquery.googleapis.com',
     'method': 'google.cloud.bigquery.v2.RowAccessPolicyService.ListRowAccessPolicies'}}]}}

Has someone the process to be able to access the list of ROW LEVEL SECURITY POLICIES from Bigquery into a python script. Big thanks !!!

Hello Filipe,

It looks that you’ve posted your issue at the StackOverflow at [1], and this is the appropriate channel (StackOverflow) for technical questions while the Google Groups forum is reserved for general product discussion. Thus I would suggest that you seek assistance from the appropriate support channel, thanks.

[1] https://stackoverflow.com/questions/69896182