bricksentry 0.1.31__tar.gz → 0.1.33__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bricksentry-0.1.31 → bricksentry-0.1.33}/CHANGELOG.md +18 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/PKG-INFO +5 -3
- {bricksentry-0.1.31 → bricksentry-0.1.33}/README.md +4 -2
- bricksentry-0.1.33/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/pyproject.toml +1 -1
- {bricksentry-0.1.31 → bricksentry-0.1.33}/server.json +2 -2
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/assess.py +26 -3
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/cli.py +3 -1
- bricksentry-0.1.33/src/bricksentry/governed.py +57 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/history.py +8 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/lineage.py +11 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/preview.py +23 -11
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/databricks_template_schema.json +2 -2
- bricksentry-0.1.33/tests/test_0132.py +158 -0
- bricksentry-0.1.31/deploy/databricks-app/requirements.txt +0 -1
- {bricksentry-0.1.31 → bricksentry-0.1.33}/.gitignore +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/LICENSE +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/SECURITY.md +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/action.yml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/deploy/container/Dockerfile +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_validation.ipynb +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_validation.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/scripts/render_demo_image.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/agent_view.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/backends/databricks_backend.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/cleanup.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/diff.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/job.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/job_demo.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/models.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/netguard.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/policy.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/src/bricksentry/validation.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/conftest.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0110.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0112.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0114.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0120.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0121.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0122.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0123.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0126.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0127.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0128.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0129.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0130.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_0131.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_018.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_019.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_demo.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_diff.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.31 → bricksentry-0.1.33}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.33 (2026-11-23)
|
|
4
|
+
|
|
5
|
+
From a round of 15 previously untested areas on 0.1.32 on a Free Edition workspace. Thirteen were verified for the first time (NOT NULL and generated columns, empty tables, unicode names, INSERT OVERWRITE, duplicate and NULL keys in both directions, OPTIMIZE and RESTORE as the latest commit, bad job arguments, and the `wide-blast-radius` and `pii-table` rules firing on real Unity Catalog lineage and tags). It found one defect:
|
|
6
|
+
|
|
7
|
+
- **Tags and owners are read afresh for every check.** Unity Catalog lineage cached a table's owner and tags (and column tags) for the life of the process. A one-shot job run was unaffected, but in a long-running process, such as the MCP server agents use, a `pii` or `certified` tag added after the first check of a table was never seen, so those rules silently stopped applying to it. Every check (`assess`, `preview_write`, `check-last-change`, `impact`) now starts by forgetting cached governance metadata.
|
|
8
|
+
- A long-running process keeps at most the 500 most recent assessments in memory; older ones are still found in the assessment store when one is configured.
|
|
9
|
+
- README: Unity Catalog shows new tags within about a minute but new lineage can take 10–15 minutes, so a check right after a change may not see it yet.
|
|
10
|
+
|
|
11
|
+
Verified before release on Databricks Free Edition from the release branch: one long-running instance gave `warn` on an untagged table, then `needs_human` ("table is tagged pii") once the tag was added, and likewise `pii-column-changed` for a column tag, with `impact` showing the tag and the downstream column; a key-colliding MERGE still gives BLOCK with a correct Undo, and masked tables still get the clear message.
|
|
12
|
+
|
|
13
|
+
## 0.1.32 (2026-11-22)
|
|
14
|
+
|
|
15
|
+
Fixes from a scale, adversarial and platform-feature round on 0.1.31 on a Free Edition workspace. It found no safety problem: previews took 20–33 s on 1 million rows and 27–29 s on 10 million with exact counts; 8 operations at once on the same tables finished cleanly with unique clones; partitioned, liquid-clustered, identity-column and CHECK-constraint tables previewed correctly; hostile column names, forbidden words in values and 300-clause SQL were handled.
|
|
16
|
+
|
|
17
|
+
- **Columns named like keywords can be previewed.** A write touching a column named `` `drop` `` (or `alter`, `grant`…) was refused as a DROP. Quoted names are now names to the keyword check; the check that the SQL doesn't name the production table still reads inside them. An unclosed `` ` `` or `"` is refused, and `"..."` is read both with and without backslash escapes, as engines differ.
|
|
18
|
+
- **Tables with column masks or row filters get one clear message.** Databricks refuses shallow clones and time travel on them (`COLUMN_MASKS_FEATURE_NOT_SUPPORTED`, `ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED`), so neither `preview_write` nor `check-last-change` can work on them. bricksentry now checks for masks and filters first and says so, with what to do instead, before creating anything; it also recognises the engine's error if the check can't read them. It doesn't copy governed data into the sandbox to work around this, because the sandbox may be readable by more people than the table.
|
|
19
|
+
- README: measured timings on 1 and 10 million rows; sampling on serverless mainly lowers cost, not time; the masked-table limit.
|
|
20
|
+
|
|
3
21
|
## 0.1.31 (2026-11-22)
|
|
4
22
|
|
|
5
23
|
Fixes from two edge-case rounds on 0.1.30 on a Free Edition workspace: production was never changed in any scenario (writes to other tables, hidden statements, views, materialized views, column mapping and deletion vectors, `check-last-change` after OPTIMIZE, VACUUM, ALTER, RESTORE and overwrites, a write landing mid-check, Ctrl-C mid-run), and every rollback suggestion was confirmed by time travel.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.33
|
|
4
4
|
Summary: Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
|
|
5
5
|
Project-URL: Homepage, https://bricksentry.org
|
|
6
6
|
Project-URL: Documentation, https://bricksentry.org/docs
|
|
@@ -203,7 +203,7 @@ bricksentry is listed in the [official MCP Registry](https://registry.modelconte
|
|
|
203
203
|
Designed for agents:
|
|
204
204
|
|
|
205
205
|
- **The verdict never comes from an LLM.** Rules in `policy.yml` decide, so the same change always gets the same answer.
|
|
206
|
-
- **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine. Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
|
|
206
|
+
- **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine, and so are columns named like keywords when quoted (`` `drop` ``). Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
|
|
207
207
|
- **Errors come back as `{"error": ...}`**, so agents can recover instead of crashing.
|
|
208
208
|
- **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window. A full-table checksum guards the sample: if the sample shows no change but the tables differ, the diff re-runs on every row, so a one-row change can't slip through.
|
|
209
209
|
- **Assessments are saved** as JSON (default `~/.bricksentry/assessments`), so `explain_diff` and `safe_to_ship` work from another process or a fresh `Sentry`.
|
|
@@ -495,7 +495,7 @@ Without lineage access bricksentry still diffs, and adds a `lineage-unavailable`
|
|
|
495
495
|
|
|
496
496
|
## What a check costs
|
|
497
497
|
|
|
498
|
-
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size:
|
|
498
|
+
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so warehouse cost grows with table size. Measured on a Free Edition serverless warehouse: a preview took 20–33 s on 1 million rows, 27–29 s on 10 million, 37–61 s on 100 million (47 s even when every row changed), and under 5 minutes on 1 billion (287 s with every row changed), always with exact counts; `check-last-change` took 27 s on 10 million, 49 s on 100 million and 264 s on 1 billion. These were narrow synthetic tables that compress well; wide real tables take longer. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Sampling lowers warehouse cost; it starts saving time on large tables (`sample_pct: 10` was 1.5× faster on 100 million rows and 2.8× faster on 1 billion, and estimated the changed share within 0.01 points). For tables above roughly 500 million rows, we suggest sampling 10%: pass `--sample-pct 10` when you check them (CLI or job task), or set `sample_pct: 10` in `bricksentry.yml` if every table you check is that large. Exact diffs stay the default. Lineage lookups are one query per depth level, bounded by `lookback_days`.
|
|
499
499
|
|
|
500
500
|
## Audit trail
|
|
501
501
|
|
|
@@ -530,7 +530,9 @@ bricksentry is in **public beta** (0.1.x). It has been tested hard but only by i
|
|
|
530
530
|
|
|
531
531
|
## Known limits (v0.1.x)
|
|
532
532
|
|
|
533
|
+
- **Lineage and tags arrive with a delay.** Unity Catalog shows new tags in its system tables within about a minute, but new lineage can take 10–15 minutes (measured on a Free Edition workspace). A check right after a change may not see it yet. bricksentry reads them afresh for every check, so the next check after they appear does.
|
|
533
534
|
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
|
|
535
|
+
- **Tables with column masks or row filters can't be checked.** Databricks refuses shallow clones and time travel on them, so `preview_write` and `check-last-change` stop with a message saying so. bricksentry won't copy governed data into the sandbox to get around it. Check the change on the table that feeds it, or on a dev copy without the mask or filter.
|
|
534
536
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
535
537
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
536
538
|
- **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.28 on a Free Edition workspace with an HR pipeline: pull-request gating with comment updates, the bundle demo job, `check-last-change` and the newer-changes warning in the CLI, report, JSON and Slack, the refused-statement guards, outbound-URL checks, matching of 2,000 NULL keys, exact totals over a million decimal rows, the audit trail, an AI agent attempting six risky changes on the live pipeline, the job task blocking a bad MERGE inside a real Databricks job, and worst-case rounds (50,000 NULL keys, near-max decimals, exotic types, 200-column tables) whose five findings were fixed in 0.1.26, a round of leak, data-shape and race tests whose four findings were fixed in 0.1.27, and a round on MERGE, allowlist bypasses, metadata injection, remote access and governance features whose findings were fixed in 0.1.28. Every run, with its numbers and the bugs it found, is in [VALIDATION.md](VALIDATION.md). The automated tests use DuckDB and a mocked SDK, so please run the [validation notebook](examples/databricks/bricksentry_validation.py) on your workspace and [share a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml), whether it passes or not.
|
|
@@ -155,7 +155,7 @@ bricksentry is listed in the [official MCP Registry](https://registry.modelconte
|
|
|
155
155
|
Designed for agents:
|
|
156
156
|
|
|
157
157
|
- **The verdict never comes from an LLM.** Rules in `policy.yml` decide, so the same change always gets the same answer.
|
|
158
|
-
- **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine. Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
|
|
158
|
+
- **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Comments before the statement are fine, and so are columns named like keywords when quoted (`` `drop` ``). Write the target as its full name (`main.sales.orders`) or `{{target}}`; a table name or `{{target}}` inside a quoted value is left as data. A write wrapped in a CTE (`WITH ... INSERT`) is refused: put the CTE in the statement's `SELECT` instead.
|
|
159
159
|
- **Errors come back as `{"error": ...}`**, so agents can recover instead of crashing.
|
|
160
160
|
- **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window. A full-table checksum guards the sample: if the sample shows no change but the tables differ, the diff re-runs on every row, so a one-row change can't slip through.
|
|
161
161
|
- **Assessments are saved** as JSON (default `~/.bricksentry/assessments`), so `explain_diff` and `safe_to_ship` work from another process or a fresh `Sentry`.
|
|
@@ -447,7 +447,7 @@ Without lineage access bricksentry still diffs, and adds a `lineage-unavailable`
|
|
|
447
447
|
|
|
448
448
|
## What a check costs
|
|
449
449
|
|
|
450
|
-
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size:
|
|
450
|
+
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries (plus three or four cheap metadata queries to pin each table's Delta version): a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so warehouse cost grows with table size. Measured on a Free Edition serverless warehouse: a preview took 20–33 s on 1 million rows, 27–29 s on 10 million, 37–61 s on 100 million (47 s even when every row changed), and under 5 minutes on 1 billion (287 s with every row changed), always with exact counts; `check-last-change` took 27 s on 10 million, 49 s on 100 million and 264 s on 1 billion. These were narrow synthetic tables that compress well; wide real tables take longer. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Sampling lowers warehouse cost; it starts saving time on large tables (`sample_pct: 10` was 1.5× faster on 100 million rows and 2.8× faster on 1 billion, and estimated the changed share within 0.01 points). For tables above roughly 500 million rows, we suggest sampling 10%: pass `--sample-pct 10` when you check them (CLI or job task), or set `sample_pct: 10` in `bricksentry.yml` if every table you check is that large. Exact diffs stay the default. Lineage lookups are one query per depth level, bounded by `lookback_days`.
|
|
451
451
|
|
|
452
452
|
## Audit trail
|
|
453
453
|
|
|
@@ -482,7 +482,9 @@ bricksentry is in **public beta** (0.1.x). It has been tested hard but only by i
|
|
|
482
482
|
|
|
483
483
|
## Known limits (v0.1.x)
|
|
484
484
|
|
|
485
|
+
- **Lineage and tags arrive with a delay.** Unity Catalog shows new tags in its system tables within about a minute, but new lineage can take 10–15 minutes (measured on a Free Edition workspace). A check right after a change may not see it yet. bricksentry reads them afresh for every check, so the next check after they appear does.
|
|
485
486
|
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping; column lineage records source-to-target derivations, so a column used only in a filter or join may not appear.
|
|
487
|
+
- **Tables with column masks or row filters can't be checked.** Databricks refuses shallow clones and time travel on them, so `preview_write` and `check-last-change` stop with a message saying so. bricksentry won't copy governed data into the sandbox to get around it. Check the change on the table that feeds it, or on a dev copy without the mask or filter.
|
|
486
488
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
487
489
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
488
490
|
- **Validated on Databricks** (serverless, November 2026): a 2-million-row table with 0.1.4 (lineage, rollback plans, previews on shallow clones, every verdict level, the sampling guard catching a single changed row), then live runs of every release up to 0.1.28 on a Free Edition workspace with an HR pipeline: pull-request gating with comment updates, the bundle demo job, `check-last-change` and the newer-changes warning in the CLI, report, JSON and Slack, the refused-statement guards, outbound-URL checks, matching of 2,000 NULL keys, exact totals over a million decimal rows, the audit trail, an AI agent attempting six risky changes on the live pipeline, the job task blocking a bad MERGE inside a real Databricks job, and worst-case rounds (50,000 NULL keys, near-max decimals, exotic types, 200-column tables) whose five findings were fixed in 0.1.26, a round of leak, data-shape and race tests whose four findings were fixed in 0.1.27, and a round on MERGE, allowlist bypasses, metadata injection, remote access and governance features whose findings were fixed in 0.1.28. Every run, with its numbers and the bugs it found, is in [VALIDATION.md](VALIDATION.md). The automated tests use DuckDB and a mocked SDK, so please run the [validation notebook](examples/databricks/bricksentry_validation.py) on your workspace and [share a validation report](https://github.com/bricksentry/bricksentry/issues/new?template=validation_report.yml), whether it passes or not.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.33
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.33"
|
|
8
8
|
description = "Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.33",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.33",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -9,6 +9,7 @@ import uuid
|
|
|
9
9
|
from datetime import datetime, timezone
|
|
10
10
|
from typing import Any
|
|
11
11
|
|
|
12
|
+
from bricksentry import governed
|
|
12
13
|
from bricksentry.backends.base import Backend, make_backend
|
|
13
14
|
from bricksentry.config import Config
|
|
14
15
|
from bricksentry.diff import diff_tables
|
|
@@ -60,6 +61,11 @@ class Sentry:
|
|
|
60
61
|
return d
|
|
61
62
|
|
|
62
63
|
def downstream(self, table: str, depth: int | None = None) -> list[ImpactNode]:
|
|
64
|
+
"""Downstream lineage with owners and tags read afresh (see ``LineageProvider.refresh``)."""
|
|
65
|
+
self.lineage.refresh()
|
|
66
|
+
return self._downstream(table, depth)
|
|
67
|
+
|
|
68
|
+
def _downstream(self, table: str, depth: int | None = None) -> list[ImpactNode]:
|
|
63
69
|
return self.lineage.downstream(table, depth or int(self.config.lineage.get("depth", 3)))
|
|
64
70
|
|
|
65
71
|
def rollback_plan(self, table: str) -> str:
|
|
@@ -86,6 +92,9 @@ class Sentry:
|
|
|
86
92
|
"""
|
|
87
93
|
candidates = candidates or {}
|
|
88
94
|
diffs = diffs or {}
|
|
95
|
+
# Governance metadata (tags, owners) is read afresh for every check, never reused from an
|
|
96
|
+
# earlier one: in a long-lived process a tag added since would otherwise be missed.
|
|
97
|
+
self.lineage.refresh()
|
|
89
98
|
results: list[TableAssessment] = []
|
|
90
99
|
notify: set[str] = set()
|
|
91
100
|
for table in tables:
|
|
@@ -101,7 +110,7 @@ class Sentry:
|
|
|
101
110
|
err = str(e)
|
|
102
111
|
lineage_err: str | None = None
|
|
103
112
|
try:
|
|
104
|
-
nodes = self.
|
|
113
|
+
nodes = self._downstream(table)
|
|
105
114
|
except Exception as e: # e.g. no SELECT on system.access.table_lineage
|
|
106
115
|
nodes = []
|
|
107
116
|
lineage_err = _first_line(e)
|
|
@@ -146,7 +155,7 @@ class Sentry:
|
|
|
146
155
|
policy_sha256=self.policy.sha256,
|
|
147
156
|
triggered_by=_actor(),
|
|
148
157
|
)
|
|
149
|
-
self.
|
|
158
|
+
self._remember(a)
|
|
150
159
|
self._save(a)
|
|
151
160
|
return a
|
|
152
161
|
|
|
@@ -193,7 +202,7 @@ class Sentry:
|
|
|
193
202
|
a = Assessment.from_dict(json.loads(f.read_text()))
|
|
194
203
|
except (OSError, ValueError, KeyError, TypeError):
|
|
195
204
|
return None
|
|
196
|
-
self.
|
|
205
|
+
self._remember(a)
|
|
197
206
|
return a
|
|
198
207
|
|
|
199
208
|
def preview_write(
|
|
@@ -210,11 +219,17 @@ class Sentry:
|
|
|
210
219
|
raise ValueError(f"No keys configured for {target}; pass keys=[...] to preview_write")
|
|
211
220
|
clone = sandbox_name(self.config.sandbox_schema, target)
|
|
212
221
|
rewritten = rewrite_for_preview(sql, target, clone, self.backend.quote)
|
|
222
|
+
what = governed.describe(self.backend, target)
|
|
223
|
+
if what:
|
|
224
|
+
raise ValueError(governed.preview_message(target, what))
|
|
213
225
|
schema = ".".join(clone.split(".")[:-1])
|
|
214
226
|
created = bool(schema and self.backend.ensure_schema(schema))
|
|
215
227
|
try:
|
|
216
228
|
self.backend.clone(target, clone)
|
|
217
229
|
except Exception as e:
|
|
230
|
+
what = governed.from_error(e)
|
|
231
|
+
if what:
|
|
232
|
+
raise ValueError(governed.preview_message(target, what)) from None
|
|
218
233
|
raise RuntimeError(
|
|
219
234
|
f"Could not clone {target} to preview the write: {_first_line(e)}. Check the table name "
|
|
220
235
|
f"and that you can create tables in {schema or 'the sandbox schema'}."
|
|
@@ -283,6 +298,14 @@ class Sentry:
|
|
|
283
298
|
return [f"notify: bad config ({e})"]
|
|
284
299
|
return send(assessment, settings, pr=pr, force=force)
|
|
285
300
|
|
|
301
|
+
_MAX_IN_MEMORY = 500 # a long-lived server shouldn't grow forever; older ones reload from the store
|
|
302
|
+
|
|
303
|
+
def _remember(self, a: Assessment) -> None:
|
|
304
|
+
self._assessments.pop(a.id, None)
|
|
305
|
+
self._assessments[a.id] = a
|
|
306
|
+
while len(self._assessments) > self._MAX_IN_MEMORY:
|
|
307
|
+
self._assessments.pop(next(iter(self._assessments)))
|
|
308
|
+
|
|
286
309
|
# --- lookups for agents -------------------------------------------------
|
|
287
310
|
def get_assessment(self, assessment_id: str) -> Assessment | None:
|
|
288
311
|
return self._assessments.get(assessment_id) or self._load(assessment_id)
|
|
@@ -246,7 +246,9 @@ def check_last_change(table, keys, version, since, sample_pct, allow_no_change,
|
|
|
246
246
|
click.echo(str(e), err=True)
|
|
247
247
|
sys.exit(0 if allow_no_change else 2)
|
|
248
248
|
except (NotImplementedError, ValueError, RuntimeError) as e:
|
|
249
|
-
|
|
249
|
+
err = click.ClickException(str(e))
|
|
250
|
+
err.exit_code = 2 # never 1, which means BLOCK
|
|
251
|
+
raise err from e
|
|
250
252
|
md = to_markdown(a)
|
|
251
253
|
if output:
|
|
252
254
|
Path(output).write_text(md)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Tables with Unity Catalog column masks or row filters.
|
|
2
|
+
|
|
3
|
+
Databricks refuses both shallow clones and time travel (``VERSION AS OF``) on these tables
|
|
4
|
+
(``COLUMN_MASKS_FEATURE_NOT_SUPPORTED`` / ``ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED``).
|
|
5
|
+
So bricksentry can't preview a write on them (no clone) or compare two versions of them
|
|
6
|
+
(no time travel), and it says so up front, in one clear message, instead of failing in the
|
|
7
|
+
middle. It never copies governed data into the scratch schema as a workaround: the scratch
|
|
8
|
+
schema may be readable by more people than the table, which is what masks and filters
|
|
9
|
+
exist to prevent. And it never suggests removing the mask or filter.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
_CODES = ("COLUMN_MASKS_FEATURE_NOT_SUPPORTED", "ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def describe(db: Any, table: str) -> str | None:
|
|
20
|
+
""""a column mask (on amount)", "a row filter", both, or None. None also when the
|
|
21
|
+
protections can't be read; the engine's own error is then recognised by ``from_error``."""
|
|
22
|
+
try:
|
|
23
|
+
p = (db.protections([table]) or {}).get(table) or {}
|
|
24
|
+
except Exception:
|
|
25
|
+
return None
|
|
26
|
+
parts = []
|
|
27
|
+
if p.get("masked"):
|
|
28
|
+
cols = ", ".join(sorted(p["masked"]))
|
|
29
|
+
parts.append(f"a column mask (on {cols})")
|
|
30
|
+
if p.get("row_filter"):
|
|
31
|
+
parts.append("a row filter")
|
|
32
|
+
return " and ".join(parts) or None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def from_error(e: BaseException) -> str | None:
|
|
36
|
+
text = str(e)
|
|
37
|
+
if _CODES[0] in text and _CODES[1] in text:
|
|
38
|
+
return "a column mask and a row filter"
|
|
39
|
+
if _CODES[0] in text:
|
|
40
|
+
return "a column mask"
|
|
41
|
+
if _CODES[1] in text:
|
|
42
|
+
return "a row filter"
|
|
43
|
+
return None
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def check_message(table: str, what: str) -> str:
|
|
47
|
+
return (f"{table} has {what}. Databricks doesn't allow reading earlier versions of tables with column "
|
|
48
|
+
"masks or row filters (time travel and clones are refused), so check-last-change can't compare "
|
|
49
|
+
"versions of it. Check changes before they reach it instead: preview or assess the write on the "
|
|
50
|
+
"table that feeds it, or on a dev copy without the mask or filter.")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def preview_message(table: str, what: str) -> str:
|
|
54
|
+
return (f"{table} has {what}. Databricks doesn't allow shallow clones of tables with column masks or row "
|
|
55
|
+
"filters, and bricksentry won't copy governed data into the sandbox, so this write can't be "
|
|
56
|
+
"previewed here. Preview it on a dev copy of the table without the mask or filter, or on the table "
|
|
57
|
+
"that feeds it.")
|
|
@@ -14,6 +14,8 @@ from dataclasses import dataclass, field
|
|
|
14
14
|
from datetime import datetime, timezone
|
|
15
15
|
from typing import TYPE_CHECKING, Any
|
|
16
16
|
|
|
17
|
+
from bricksentry import governed
|
|
18
|
+
|
|
17
19
|
if TYPE_CHECKING: # pragma: no cover
|
|
18
20
|
from bricksentry.assess import Sentry
|
|
19
21
|
from bricksentry.models import Assessment
|
|
@@ -253,6 +255,9 @@ def check_change(
|
|
|
253
255
|
if not _NAME.fullmatch(table):
|
|
254
256
|
raise ValueError(f"table must be schema.table or catalog.schema.table; got {table!r}")
|
|
255
257
|
|
|
258
|
+
what = governed.describe(db, table)
|
|
259
|
+
if what:
|
|
260
|
+
raise ValueError(governed.check_message(table, what))
|
|
256
261
|
history = _read_history(db, table, history_limit)
|
|
257
262
|
change = pick_change(table, history, version=version, since=since)
|
|
258
263
|
keys = keys or sentry.config.spec(table).keys or db.primary_key(table)
|
|
@@ -273,6 +278,9 @@ def check_change(
|
|
|
273
278
|
try:
|
|
274
279
|
db.clone_version(table, target, v)
|
|
275
280
|
except Exception as e:
|
|
281
|
+
what = governed.from_error(e)
|
|
282
|
+
if what:
|
|
283
|
+
raise ValueError(governed.check_message(table, what)) from None
|
|
276
284
|
raise RuntimeError(
|
|
277
285
|
f"Could not read version {v} of {table}: its files may have been removed by VACUUM, "
|
|
278
286
|
f"or you may lack CREATE TABLE on {scratch}. ({str(e).strip()[:300]})") from None
|
|
@@ -45,6 +45,12 @@ class LineageProvider(ABC):
|
|
|
45
45
|
"""Downstream columns fed by ``columns`` of ``table``, with their tags."""
|
|
46
46
|
return []
|
|
47
47
|
|
|
48
|
+
def refresh(self) -> None:
|
|
49
|
+
"""Forget anything cached, so the next check reads owners and tags afresh.
|
|
50
|
+
Called at the start of every check: a long-lived process (the MCP server)
|
|
51
|
+
must see a pii or certified tag added after its first check."""
|
|
52
|
+
return None # nothing cached by default
|
|
53
|
+
|
|
48
54
|
|
|
49
55
|
class StaticLineage(LineageProvider):
|
|
50
56
|
"""Lineage from config::
|
|
@@ -179,6 +185,11 @@ class UnityCatalogLineage(LineageProvider):
|
|
|
179
185
|
self._meta_cache: dict[str, tuple[str | None, dict[str, str]]] = {}
|
|
180
186
|
self._exists: dict[str, bool] = {} # True / False when information_schema answered; absent if unknown
|
|
181
187
|
|
|
188
|
+
def refresh(self) -> None:
|
|
189
|
+
self._col_tag_cache.clear()
|
|
190
|
+
self._meta_cache.clear()
|
|
191
|
+
self._exists.clear()
|
|
192
|
+
|
|
182
193
|
def _excluded(self, name: str) -> bool:
|
|
183
194
|
n = name.lower()
|
|
184
195
|
return any(fnmatch.fnmatch(n, p) for p in self.exclude_patterns)
|
|
@@ -63,7 +63,7 @@ def _strip_quotes(name: str) -> str:
|
|
|
63
63
|
return name.replace("`", "").replace('"', "").lower()
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
|
|
66
|
+
def _scan(sql: str, backslash: bool = True, idents: bool = False) -> list[tuple[str, int, int]]:
|
|
67
67
|
"""Split ``sql`` into ("code" | "string" | "comment", start, end) pieces.
|
|
68
68
|
|
|
69
69
|
'...' is a string literal. `...` and "..." are skipped over as single tokens (so a
|
|
@@ -88,7 +88,7 @@ def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
|
|
|
88
88
|
def skip_quoted(j: int, q: str) -> int:
|
|
89
89
|
j += 1
|
|
90
90
|
while j < n:
|
|
91
|
-
if sql[j] == "\\" and q != "`" and
|
|
91
|
+
if sql[j] == "\\" and q != "`" and backslash:
|
|
92
92
|
j += 2
|
|
93
93
|
continue
|
|
94
94
|
if sql[j] == q:
|
|
@@ -102,7 +102,14 @@ def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
|
|
|
102
102
|
while i < n:
|
|
103
103
|
c = sql[i]
|
|
104
104
|
if c in "`\"":
|
|
105
|
-
|
|
105
|
+
j = skip_quoted(i, c)
|
|
106
|
+
if idents: # report quoted names as their own pieces (for the keyword check)
|
|
107
|
+
if j >= n and not (j - i >= 2 and sql[j - 1] == c):
|
|
108
|
+
raise PreviewGuardError(f"The SQL has a quote ({c}) that is never closed.")
|
|
109
|
+
close("code", start, i)
|
|
110
|
+
close("ident", i, j)
|
|
111
|
+
start = j
|
|
112
|
+
i = j
|
|
106
113
|
elif c == "'":
|
|
107
114
|
close("code", start, i)
|
|
108
115
|
j = skip_quoted(i, "'")
|
|
@@ -128,15 +135,20 @@ def _scan(sql: str, backslash: bool = True) -> list[tuple[str, int, int]]:
|
|
|
128
135
|
return pieces
|
|
129
136
|
|
|
130
137
|
|
|
131
|
-
|
|
132
|
-
"""The SQL with comments blanked and '...' literals emptied, for the guards to inspect."""
|
|
133
|
-
return "".join(sql[a:b] if k == "code" else (" " if k == "comment" else "''")
|
|
134
|
-
for k, a, b in _scan(sql, backslash))
|
|
138
|
+
_BLANK = {"comment": " ", "string": "''", "ident": "`_`"}
|
|
135
139
|
|
|
136
140
|
|
|
137
|
-
def
|
|
138
|
-
"""The SQL
|
|
139
|
-
|
|
141
|
+
def _strip_sql_comments_and_strings(sql: str, backslash: bool = True, idents: bool = False) -> str:
|
|
142
|
+
"""The SQL with comments blanked and '...' literals emptied, for the guards to inspect.
|
|
143
|
+
With ``idents``, quoted names (`drop`, "drop") are blanked too."""
|
|
144
|
+
return "".join(sql[a:b] if k == "code" else _BLANK[k] for k, a, b in _scan(sql, backslash, idents))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _masked(sql: str, idents: bool = False) -> list[str]:
|
|
148
|
+
"""The SQL as each engine family would read it; every guard must pass on all of them.
|
|
149
|
+
``idents`` blanks quoted names: right for keyword and ``;`` checks (a column named
|
|
150
|
+
`drop` is a name, not a statement), wrong for finding the production table's name."""
|
|
151
|
+
return [_strip_sql_comments_and_strings(sql, True, idents), _strip_sql_comments_and_strings(sql, False, idents)]
|
|
140
152
|
|
|
141
153
|
|
|
142
154
|
_LEADING_COMMENTS = re.compile(r"\A(?:\s+|--[^\n]*(?:\n|\Z)|/\*.*?\*/)*", re.S)
|
|
@@ -166,7 +178,7 @@ def statement_head(sql: str) -> str:
|
|
|
166
178
|
def rewrite_for_preview(sql: str, target: str, clone: str, quote) -> str:
|
|
167
179
|
"""Return SQL that writes to ``clone`` instead of ``target``. Raises PreviewGuardError if unsafe."""
|
|
168
180
|
body = sql.strip().rstrip(";").strip()
|
|
169
|
-
for code in _masked(body):
|
|
181
|
+
for code in _masked(body, idents=True):
|
|
170
182
|
if ";" in code:
|
|
171
183
|
raise PreviewGuardError(
|
|
172
184
|
"preview_write accepts exactly one SQL statement. Preview each write separately, in the order they "
|
{bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/databricks_template_schema.json
RENAMED
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
},
|
|
87
87
|
"bricksentry_version": {
|
|
88
88
|
"type": "string",
|
|
89
|
-
"default": "0.1.
|
|
89
|
+
"default": "0.1.33",
|
|
90
90
|
"description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
|
|
91
91
|
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
92
|
-
"pattern_match_failure_message": "Use a version like 0.1.
|
|
92
|
+
"pattern_match_failure_message": "Use a version like 0.1.33.",
|
|
93
93
|
"order": 10
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""0.1.32: findings from the scale, adversarial and platform-feature round on 0.1.31."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from click.testing import CliRunner
|
|
5
|
+
from test_0114 import FakeDelta
|
|
6
|
+
|
|
7
|
+
from bricksentry import governed, job
|
|
8
|
+
from bricksentry.assess import Sentry
|
|
9
|
+
from bricksentry.cli import main
|
|
10
|
+
from bricksentry.config import Config
|
|
11
|
+
from bricksentry.preview import PreviewGuardError, rewrite_for_preview
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def q(p):
|
|
15
|
+
return f"`{p}`"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def rw(sql, target="main.s.t"):
|
|
19
|
+
return rewrite_for_preview(sql, target, "sb.x.t__preview_0123abcd", q)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# --- a column named like a keyword -------------------------------------------------
|
|
23
|
+
def test_quoted_keyword_names_are_names():
|
|
24
|
+
assert rw("UPDATE main.s.t SET `drop` = 1 WHERE id = 2").startswith("UPDATE `sb`")
|
|
25
|
+
assert rw("INSERT INTO main.s.t (`drop`, `alter`, `grant`) VALUES (1, 2, 3)")
|
|
26
|
+
assert rw('UPDATE main.s.t SET "truncate" = 1')
|
|
27
|
+
assert rw("UPDATE main.s.t SET `a;b` = 1")
|
|
28
|
+
assert rw("UPDATE `main`.`s`.`t` SET `drop` = 1")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@pytest.mark.parametrize("sql", [
|
|
32
|
+
"UPDATE main.s.t SET drop = 1", # unquoted: still a keyword
|
|
33
|
+
"UPDATE main.s.t SET `drop` = 1; DROP TABLE main.s.prod",
|
|
34
|
+
'UPDATE main.s.t SET a = "x\\"; DROP TABLE main.s.prod; --"', # DuckDB: no escapes in "..."
|
|
35
|
+
'UPDATE main.s.t SET a = 1 "; DROP TABLE main.s.prod', # never closed
|
|
36
|
+
"UPDATE main.s.t SET a = 1 `; DROP TABLE main.s.prod",
|
|
37
|
+
])
|
|
38
|
+
def test_quoted_names_hide_nothing(sql):
|
|
39
|
+
with pytest.raises(PreviewGuardError):
|
|
40
|
+
rw(sql)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_production_name_in_backticks_is_still_found():
|
|
44
|
+
# The leftover check still reads inside backticks: a second reference to production refused.
|
|
45
|
+
with pytest.raises(PreviewGuardError):
|
|
46
|
+
rewrite_for_preview("INSERT INTO {{target}} SELECT * FROM `main`.`s`.`t`", "main.s.t",
|
|
47
|
+
"sb.x.t__preview_0123abcd", q)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# --- tables with column masks or row filters -----------------------------------------
|
|
51
|
+
class Governed(FakeDelta):
|
|
52
|
+
def __init__(self, prot=None, clone_error=None):
|
|
53
|
+
super().__init__()
|
|
54
|
+
self.prot = prot or {}
|
|
55
|
+
self.clone_error = clone_error
|
|
56
|
+
|
|
57
|
+
def protections(self, tables):
|
|
58
|
+
return {t: self.prot[t] for t in tables if t in self.prot}
|
|
59
|
+
|
|
60
|
+
def clone_version(self, source, target, version):
|
|
61
|
+
if self.clone_error:
|
|
62
|
+
raise RuntimeError(self.clone_error)
|
|
63
|
+
return super().clone_version(source, target, version)
|
|
64
|
+
|
|
65
|
+
def clone(self, source, target):
|
|
66
|
+
if self.clone_error:
|
|
67
|
+
raise RuntimeError(self.clone_error)
|
|
68
|
+
return super().clone(source, target)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def sentry(db):
|
|
72
|
+
return Sentry(Config.from_dict({"assessment_store": False, "sandbox_schema": "scratch",
|
|
73
|
+
"tables": {"sales.orders": {"keys": ["order_id"]}}}), backend=db)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_describe():
|
|
77
|
+
db = Governed({"sales.orders": {"masked": ["ssn", "amount"], "row_filter": True}})
|
|
78
|
+
assert governed.describe(db, "sales.orders") == "a column mask (on amount, ssn) and a row filter"
|
|
79
|
+
assert governed.describe(db, "sales.other") is None
|
|
80
|
+
assert governed.from_error(RuntimeError("[COLUMN_MASKS_FEATURE_NOT_SUPPORTED.TIME_TRAVEL] x")) == "a column mask"
|
|
81
|
+
assert governed.from_error(RuntimeError("[ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED.CLONE]")) == "a row filter"
|
|
82
|
+
assert governed.from_error(RuntimeError("other")) is None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_check_change_refuses_up_front():
|
|
86
|
+
db = Governed({"sales.orders": {"masked": ["amount"], "row_filter": False}})
|
|
87
|
+
with pytest.raises(ValueError, match="sales.orders has a column mask \\(on amount\\).*can't compare versions"):
|
|
88
|
+
sentry(db).check_change("sales.orders")
|
|
89
|
+
assert not [t for t in FakeDelta.list_tables(db, "scratch")] # nothing was cloned
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_check_change_recognises_the_engine_error():
|
|
93
|
+
db = Governed(clone_error="[ROW_LEVEL_SECURITY_FEATURE_NOT_SUPPORTED.TIME_TRAVEL] Time travel is not supported")
|
|
94
|
+
with pytest.raises(ValueError, match="has a row filter.*dev copy without the mask or filter"):
|
|
95
|
+
sentry(db).check_change("sales.orders")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_preview_refuses_up_front_and_never_suggests_unmasking():
|
|
99
|
+
db = Governed({"sales.orders": {"masked": [], "row_filter": True}})
|
|
100
|
+
with pytest.raises(ValueError) as e:
|
|
101
|
+
sentry(db).preview_write("UPDATE {{target}} SET amount = 0 WHERE order_id = 1", "sales.orders")
|
|
102
|
+
msg = str(e.value)
|
|
103
|
+
assert "won't copy governed data" in msg and "drop" not in msg.lower() and "remove" not in msg.lower()
|
|
104
|
+
db = Governed(clone_error="[COLUMN_MASKS_FEATURE_NOT_SUPPORTED.CLONE] Shallow clone not supported")
|
|
105
|
+
with pytest.raises(ValueError, match="has a column mask"):
|
|
106
|
+
sentry(db).preview_write("UPDATE {{target}} SET amount = 0 WHERE order_id = 1", "sales.orders")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_cli_and_job_report_it_cleanly(monkeypatch, tmp_path):
|
|
110
|
+
db = Governed({"sales.orders": {"masked": ["amount"], "row_filter": False}})
|
|
111
|
+
monkeypatch.setattr("bricksentry.assess.make_backend", lambda spec: db)
|
|
112
|
+
cfg = tmp_path / "bricksentry.yml"
|
|
113
|
+
cfg.write_text("sandbox_schema: scratch\nassessment_store: false\nlineage: {type: static}\n")
|
|
114
|
+
r = CliRunner().invoke(main, ["check-last-change", "sales.orders", "-c", str(cfg), "--no-notify"])
|
|
115
|
+
assert r.exit_code == 2 and "has a column mask" in r.output and "Traceback" not in r.output
|
|
116
|
+
lines: list[str] = []
|
|
117
|
+
code = job.run(["--tables", "sales.orders", "--scratch-schema", "scratch"], backend=db, out=lines.append)
|
|
118
|
+
assert code == 2 and "has a column mask" in "\n".join(lines)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# --- governance metadata is read afresh for every check (0.1.33) ----------------------
|
|
122
|
+
def _uc(backend):
|
|
123
|
+
from bricksentry.lineage import UnityCatalogLineage
|
|
124
|
+
|
|
125
|
+
backend.execute("CREATE SCHEMA IF NOT EXISTS sys3")
|
|
126
|
+
backend.execute("CREATE OR REPLACE TABLE sys3.table_lineage AS SELECT * FROM (VALUES "
|
|
127
|
+
"('sales.orders', 'sales.daily', 'JOB', '1', current_date)) "
|
|
128
|
+
"t(source_table_full_name, target_table_full_name, entity_type, entity_id, event_date)")
|
|
129
|
+
backend.execute("CREATE OR REPLACE TABLE sys3.tables AS SELECT * FROM (VALUES "
|
|
130
|
+
"(NULL, 'sales', 'orders', 'data-team'), (NULL, 'sales', 'daily', 'bi')) "
|
|
131
|
+
"t(table_catalog, table_schema, table_name, table_owner)")
|
|
132
|
+
backend.execute("CREATE OR REPLACE TABLE sys3.table_tags AS SELECT * FROM (VALUES "
|
|
133
|
+
"('x', 'x', 'x', 'x', NULL)) t(catalog_name, schema_name, table_name, tag_name, tag_value)")
|
|
134
|
+
return UnityCatalogLineage(backend, lineage_table="sys3.table_lineage", tables_table="sys3.tables",
|
|
135
|
+
tags_table="sys3.table_tags")
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_tag_added_after_first_check_is_seen(sentry):
|
|
139
|
+
b = sentry.backend
|
|
140
|
+
lin = _uc(b)
|
|
141
|
+
s = Sentry(sentry.config, backend=b, lineage=lin)
|
|
142
|
+
first = s.preview_write("UPDATE {{target}} SET status = 'x' WHERE order_id = 1", "sales.orders")
|
|
143
|
+
assert "pii" not in str(first)
|
|
144
|
+
# A long-lived process (the MCP server): the tag is added after the first check.
|
|
145
|
+
b.execute("INSERT INTO sys3.table_tags VALUES (NULL, 'sales', 'orders', 'pii', NULL), "
|
|
146
|
+
"(NULL, 'sales', 'daily', 'certified', NULL)")
|
|
147
|
+
second = s.preview_write("UPDATE {{target}} SET status = 'y' WHERE order_id = 1", "sales.orders")
|
|
148
|
+
t = second["tables"][0]
|
|
149
|
+
assert "pii" in t["tags"], t
|
|
150
|
+
nodes = s.downstream("sales.orders")
|
|
151
|
+
assert any("certified" in n.tags for n in nodes)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_in_memory_assessments_are_capped(sentry, monkeypatch):
|
|
155
|
+
monkeypatch.setattr(type(sentry), "_MAX_IN_MEMORY", 3)
|
|
156
|
+
ids = [sentry.preview_write(f"UPDATE {{{{target}}}} SET status = 's{i}' WHERE order_id = 1",
|
|
157
|
+
"sales.orders")["id"] for i in range(5)]
|
|
158
|
+
assert list(sentry._assessments) == ids[-3:]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.31
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.31 → bricksentry-0.1.33}/examples/databricks/bricksentry_hr_walkthrough.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.31 → bricksentry-0.1.33}/templates/job-check/template/{{.project_name}}/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|