Skip to content
Notifications
Clear all

Showcase: My open-source toolkit for auditing Claw agent permissions before you deploy.

2 Posts
2 Users
0 Reactions
2 Views
(@data_diver_dan)
Estimable Member
Joined: 3 months ago
Posts: 126
Topic starter   [#11556]

The migration from our legacy, manually-managed ETL system to a dbt-centric analytics platform was predicated on a single, non-negotiable principle: trust in the data. However, during our parallel run, we discovered a critical vector for data quality degradation that wasn't in our transformation logic, but in the deployment permissions of our data agents. Specifically, our new "claw" agents—responsible for idempotent data extraction and loading—were being granted blanket schema permissions, leading to scenarios where a misconfigured model could drop production tables.

This incident prompted a months-long side quest into permission auditing. I've since assembled a toolkit of open-source SQL queries and a lightweight dashboard to visualize agent permissions across the entire warehouse *before* deployment. The core philosophy is to treat permissions as a first-class data artifact, subject to the same review as model code.

The forcing function was a near-miss where a development agent, promoted to production, retained `CREATE TABLE` permissions in our core reporting schema. The sequencing decision was to audit in this order:
* **Catalog-Level Roles:** What warehouse-level roles is the agent principal assigned?
* **Schema-Level Privileges:** A detailed breakdown of `USAGE`, `CREATE`, and `OWNERSHIP` on all schemas.
* **Table-Level Privileges:** Specifically hunting for `INSERT`, `UPDATE`, `DELETE`, and `TRUNCATE` grants that could lead to data mutation.
* **Future Grants:** The most insidious, as these apply to objects not yet created.

Here is the foundational query for Snowflake that we run in our CI/CD pipeline (a similar approach works for BigQuery or Redshift with their respective `INFORMATION_SCHEMA` views).

```sql
-- Audit Script for Agent Permissions (Snowflake)
WITH agent_roles AS (
SELECT
grantee_name AS role_name
FROM snowflake.account_usage.grants_to_roles
WHERE granted_to = 'USER'
AND grantee_name LIKE '%CLAW_AGENT%'
AND deleted_on IS NULL
)
SELECT
ar.role_name,
p.privilege,
p.table_catalog,
p.table_schema,
p.name AS object_name,
p.granted_on
FROM snowflake.account_usage.grants_to_roles p
JOIN agent_roles ar ON p.grantee_name = ar.role_name
WHERE p.deleted_on IS NULL
AND p.granted_on IN ('ROLE', 'DATABASE', 'SCHEMA', 'TABLE', 'VIEW')
ORDER BY 1, 4, 5, 3;
```

We materialize this output into a `permission_snapshots` table. The accompanying Looker dashboard (which could be built in any BI tool) provides a diff view between environments. This is where things slipped for us initially: we didn't account for inherited role hierarchies. Our second iteration added a recursive CTE to explode all inherited roles for a given agent user.

The key takeaways from our rebuild story are:
* Permission drift is a silent data quality risk. It must be version-controlled, either via Terraform or as a checked-in manifest.
* Auditing must be recursive and cover future grants.
* Visualizing the diff between staging and production permissions is as crucial as reviewing a Pull Request.

The toolkit has prevented three potential production incidents in the last quarter. I'm happy to share the full dbt package and LookML code for anyone undertaking a similar stack modernization.

- dan


Garbage in, garbage out.


   
Quote
(@infra_architect_42)
Reputable Member
Joined: 1 month ago
Posts: 127
 

What you've described with blanket schema permissions is a classic failure of the principle of least privilege, and I'm not surprised it surfaced during a parallel run. That's precisely when these implicit trust assumptions break.

Your approach of treating permissions as a data artifact is correct, but I'd push it further. The SQL queries are a great start for static analysis, but the real challenge is the dynamic, context-sensitive nature of modern data platforms. For instance, a role might have no direct `CREATE TABLE` privilege, yet inherit it via a nested role structure or a future grant. Your audit needs to recursively unravel role hierarchies, not just inspect direct grants.

Also, consider the pipeline runtime. An agent might execute a stored procedure owned by a different role, operating with the owner's rights. Your pre-deployment snapshot might miss these lateral privilege escalations. Integrating this audit into your CI/CD, perhaps as a Terraform plan check or a Kubernetes Admission Controller for your agent manifests, closes the feedback loop faster than a standalone dashboard.


Boring is beautiful


   
ReplyQuote