# Set grants on dataset level in BigQuery

**URL:** <https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073>\
**Category:** Help\
**Tags:** grants\
**Created:** [October 14, 2022, 2:12pm UTC](https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073 "2022-10-14T14:12:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chricko](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@chricko](https://discourse.getdbt.com/u/chricko)\
**Post date:** [October 14, 2022, 2:12pm UTC](https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073/1 "2022-10-14T14:12:51Z")

</div>

Hi, i am trying to set specific viewer-access in BigQuery on a dataset through dbt and dbt\_project.yml file.

```auto
a_folder_in_models:
  +dataset: some_dataset
  +grants:
     roles/bigquery.dataViewer: ['group:group@company.com']

```

But when i execute dbt run it will set it on table/view level. At my company we wan’t to set these type of view-access to different ad-groups on dataset level. We wan’t to control these through the file dbt\_project.yml and not inside every model.

Is there a solution to this? Maybe a macro that will solve it? Or am i just doing it wrong in our dbt\_project.yml.

---

<div class="post-metadata">

**Author:** ![minhajpasha](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/minhajpasha/32/1159_2.png) [@minhajpasha](https://discourse.getdbt.com/u/minhajpasha)\
**Post date:** [October 14, 2022, 10:38pm UTC](https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073/2 "2022-10-14T22:38:10Z")

</div>

Hello, If you are creating datasets via terraform, then tf would be best place for this use case . If you are looking via dbt please use post hooks (defined in dbt\_project.yml) or define macro with list of grant SQL statements and call macro on-run-start or on-run-end based on your use case.

I have done the extensive analysis around grants for bq. You can go thru in below link

> [@Grant & revoke in Big query](https://discourse.getdbt.com/t/grant-revoke-in-big-query/5057):
>
> Hello @joellabes dbt core:1.2 dwh: Bigquery Model type: Incremental The access is not getting revoked via DBT.Below are the steps which i have followed and could see issue in the dbt. case one: I have applied the grants as below so that user someone can access the table. {%if target.name ==‘dev’%} {{ config(grants = {‘roles/bigquery.dataViewer’: [‘user:someone@yourcompany.com’]}) }} {%endif%} result user ([someone@yourcompany.com](mailto:someone@yourcompany.com)) is able to access the table. I can see grant statement …

---

<div class="post-metadata">

**Author:** ![chricko](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@chricko](https://discourse.getdbt.com/u/chricko)\
**Post date:** [October 17, 2022, 6:43am UTC](https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073/3 "2022-10-17T06:43:58Z")

</div>

No we are creating the datasets via dbt. Looking into creating a macro for setting the grant on dataset level instead.

---

<div class="post-metadata">

**Author:** ![MatsE](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/matse/32/4489_2.png) [@MatsE](https://discourse.getdbt.com/u/MatsE)\
**Post date:** [October 4, 2024, 10:21am UTC](https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073/4 "2024-10-04T10:21:15Z")

</div>

were you able to find any solution to this @chricko ? I have a very similar type of use-case I would like to pursue.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [October 4, 2024, 10:41am UTC](https://discourse.getdbt.com/t/set-grants-on-dataset-level-in-bigquery/5073/5 "2024-10-04T10:41:21Z")

</div>

dbt doesn’t have a first-class concept of datasets so there is nowhere to hang dataset-level config like grants.

We handled this by removing dbt’s ability to manage datasets (taking away its `bigquery.datasets.create` permission) and creating datasets with Terraform instead

Note: `@Mike Stanley` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1728038475519279?thread_ts=1728037297.027319&cid=CBSQTAPLG). It might not have transferred perfectly.
