# Access Control

Set who can query what in Contextflo. It supports access control across all data sources, at the granularity each underlying data source supports.

Source: https://contextflo.com/docs/access-control

Contextflo enforces access by detecting which tables every query reads and applying your policies to each one. You decide which teams can read which tables; Contextflo checks every query against those rules before any results come back. Nothing is visible until a rule allows it.

## How It Works

1. **Someone asks a question**: an AI agent writes SQL, or a dashboard or artifact runs its query.
2. **We detect every table the query reads**, including tables joined, tables in subqueries and, on BigQuery, tables read inside your functions.
3. **We apply your policies** to each table, for the person asking.
4. **If every table is allowed, results come back. If any table is denied, the query is stopped** and the person is told which tables they're missing and to contact an admin.

Every query is checked, every time, so a rule change applies to the next query.

## Setting Up Policies

### Access Groups

- Organize access by department: Sales, Finance, Support, each its own group.
- People belong to one or more groups.
- Each group holds a list of rules (`ALLOW` or `DENY`).

### Rules

- A rule is an action (`ALLOW` or `DENY`) plus a name pattern, eg: `PROD.CRM.*`, `ANALYTICS.*`, `FINANCE.PRODUCTS.TRANSACTIONS`.
- Patterns match fully qualified table names (case-insensitive). A table can be a warehouse table or view, an uploaded CSV, or a Google Sheet tab.
- `DENY` wins when several rules match the same table.
- A person's access is the combination of all their groups. No matching `ALLOW` means denied.

> A group with only `DENY` rules grants nothing on its own. Someone whose only group is `DENY FINANCE.*` is denied every table, because there's no `ALLOW` to match.

### A Typical Setup

1. **One group per department**, each allowing only the datasets that department needs.
2. **Invite people straight into their department group.**
3. **Use Check access** to see, for any person, which tables they can read and which group decided it.

### Rolling Out

Enforcement can be switched off while you set up groups. Queries then run as normal, and the activity log shows which ones would have been denied, so you can fix your rules before anyone is blocked.

## What Your Team Will See

- **Agents only see what they can query.** Table lists and table context hide anything the person can't access.
- **Dashboards and artifacts run as the viewer.** Two people opening the same dashboard each see only what their own groups allow; a chart built on a table someone can't access won't load for them.
- **A blocked query says why.** The person sees which tables they're missing and is pointed to an admin.
- **If access can't be checked, the query doesn't run.** The person is asked to try again, and our team is alerted.

## What Gets Blocked, and What Doesn't

Policies are about tables and views.

### Blocked

- **Any table or view no group allows.**
- **Tables read inside a function** (BigQuery UDFs and table functions). Calling a function that reads a denied table is blocked, the same as querying that table directly.
- **Changes of any kind.** Inserts, updates, deletes, creating or dropping objects, and multi-statement scripts are refused for everyone, admins included. Contextflo only reads.
- **BigQuery `EXTERNAL_QUERY`**, which reaches into other databases outside your policies.
- **Warehouse metadata** (`INFORMATION_SCHEMA`), for everyone except admins.
- **Uploaded files** read any way other than by their table name. Listing every table or reading files directly is refused.

### Not Blocked

- **What's behind a view you allowed.** Access to a view covers the tables it reads, which is how you limit rows and columns (see below).
- **Functions themselves.** There are no rules on functions. A function that only computes (parses text, does math) runs for anyone who can read the tables in the query. Anything a function does outside the warehouse, such as a BigQuery remote function, is your own code and runs under your warehouse's permissions.
- **Dashboards shared outside your workspace** (shared links). People see that dashboard's data, not data from their own groups.

> Contextflo can never read more than your warehouse lets it. The permissions of the connection you set up are the outer limit; your policies narrow it down from there.

## When New Tables Are Connected

- **Newly connected tables stay hidden until a rule covers them.** A rule on one table covers only that table.
- **Schema and namespace rules are broad.** `PROD.CRM.*` covers every table in that schema, including ones connected later. Use them where a team should get everything in a schema, and table rules where it shouldn't.

## Offboarding

- **Removing someone from the workspace** removes their membership and every access group they were in.
- **Removing someone from a group** takes effect on their next query.
- **The record stays.** Their questions, the SQL that ran, and who asked remain in the activity log.

## Rows and Columns

Policies work per table. To limit rows or hide columns, create a view in your warehouse with the right filter and columns, and give the group the view instead of the base table. Examples for Snowflake, BigQuery and Postgres are in [access control for Claude on your warehouse](https://contextflo.com/blog/ai-data-access-control).

## Operating Tips

- Name groups for business intent (`finance-readonly`, `marketing-plus`).
- Prefer `ALLOW` lists per group over `DENY` carve-outs from a broad grant. Use `DENY` sparingly and as specific as possible (TABLE > SCHEMA > NAMESPACE).
- Review memberships periodically with Check access.

Need help modeling rules? Reach out to the Contextflo team, we're happy to review your setup.
