# Row Level Security with Explores & SQL "Injected" Dimensions

**URL:** <https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689>\
**Category:** Looker\
**Tags:** lookml, exploring-data, filter\
**Created:** [September 17, 2020, 11:04pm UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689 "2020-09-17T23:04:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [September 17, 2020, 11:04pm UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689/1 "2020-09-17T23:04:00Z")

</div>

We currently use user attributes to filter out other clients information in our Looker dashboards. Originally, this was designed by using a derived table that took the user attributes and only gave client access to what was passed in those fields. This seemed rather unnecessary to build something new each time for our users.

I figured there had to be a better way to do this and was roughly able to accomplish the same thing by moving that logic to an explore and a `sql_always_where` statement that used those user attribute fields. This works great when applying this logic to filters, but I ran into an issue when I wanted to apply that logic to a different explore to filter results on the first load of the dashboard that it’s included in.

Eventually, I settled upon using the explore (which I named the permitted\_client explore) and adding some dimensions to the new table. These dimensions have a `sql` block that has a rough template like so: `{% if _user_attributes["attribute"] != '%' %} ${client} IN ({{ _user_attributes["attribute"]}}) %}` where attribute is a string resembling something like `"'client1','client2','client3'"` or if not filled then `'%'`.

This feels a little counterintuitive as it seems like I’m just injecting some SQL to get around having a layer of abstraction.

Is there no way that I could just extend an explore in a different explore to have it automatically apply this logic? Something like that would be ideal and reusable for me as I’ll need to apply this logic to every new explore I make in my model

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [September 18, 2020, 4:30pm UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689/2 "2020-09-18T16:30:00Z")

</div>

kirkg5:

> permitted\_client

Hi @kirkg5 and Welcome.

You may want to look into the `access_filter `[documentation here](https://docs.looker.com/reference/explore-params/access_filter), looks like it’s what you need.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [September 18, 2020, 5:08pm UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689/3 "2020-09-18T17:08:44Z")

</div>

Wow that looks like someone copied almost exactly what I wrote and built it out. Thanks!

Is there some type of specific format or configuration that allows for multiple clients to be added to one of these access filters?

It seems rather vague past the fact that you can just use `%` for everything.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [September 18, 2020, 6:05pm UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689/4 "2020-09-18T18:05:45Z")

</div>

It’s using the same format as [Looker Filter Expressions](https://docs.looker.com/reference/filter-expressions)

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [September 21, 2020, 6:33pm UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689/5 "2020-09-21T18:33:25Z")

</div>

In case anyone else tries to work with this, make sure when setting a new user attribute that you make it an advanced string filter and not just a “string”. Otherwise the filter expressions won’t work.

---

<div class="post-metadata">

**Author:** ![anonymous8](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anonymous8](https://discuss.google.dev/u/anonymous8)\
**Post date:** [October 17, 2022, 9:49am UTC](https://discuss.google.dev/t/row-level-security-with-explores-sql-injected-dimensions/115689/6 "2022-10-17T09:49:16Z")

</div>

How to implement row level security by passing liquid variables
