bricksentry 0.1.21__tar.gz → 0.1.23__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.21 → bricksentry-0.1.23}/CHANGELOG.md +19 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/PKG-INFO +25 -8
- {bricksentry-0.1.21 → bricksentry-0.1.23}/README.md +22 -5
- bricksentry-0.1.23/SECURITY.md +31 -0
- bricksentry-0.1.23/deploy/container/Dockerfile +29 -0
- bricksentry-0.1.23/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_check_my_table.ipynb +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_check_my_table.py +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_quickstart.ipynb +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_quickstart.py +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/pyproject.toml +3 -2
- {bricksentry-0.1.21 → bricksentry-0.1.23}/server.json +2 -2
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/assess.py +22 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/backends/base.py +16 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/backends/databricks_backend.py +3 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/backends/duckdb_backend.py +3 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/cli.py +4 -2
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/diff.py +46 -17
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/github.py +2 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/models.py +14 -0
- bricksentry-0.1.23/src/bricksentry/netguard.py +79 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/notify.py +6 -3
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/policy.py +6 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/report.py +8 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/databricks_template_schema.json +2 -2
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_0114.py +3 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_0121.py +1 -1
- bricksentry-0.1.23/tests/test_0122.py +97 -0
- bricksentry-0.1.23/tests/test_0123.py +121 -0
- bricksentry-0.1.21/SECURITY.md +0 -19
- bricksentry-0.1.21/deploy/databricks-app/requirements.txt +0 -1
- {bricksentry-0.1.21 → bricksentry-0.1.23}/.gitignore +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/LICENSE +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/action.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/scripts/render_demo_image.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/history.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/job.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/job_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/conftest.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_0110.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_0112.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_0120.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_018.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_019.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_diff.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.23}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.23 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
From a review of accuracy, auditability and documentation:
|
|
6
|
+
|
|
7
|
+
- **Exact totals.** Sums of decimal and integer columns are added as `DECIMAL(38, x)` instead of `DOUBLE`, so totals on large tables don't drift by cents and big integer columns can't overflow. Floating-point columns are still summed as `DOUBLE`.
|
|
8
|
+
- **Duplicated keys are matched one to one.** When a key appears more than once (including many rows with a NULL key, which match each other), copies are numbered and copy *n* is matched with copy *n*. Before, every copy matched every other copy: 2,000 NULL-key rows on each side joined into 4,000,000 pairs, and a duplicated row counted as a second match instead of an added row. A bad MERGE that duplicates rows now shows them as added, and the diff notes that copies were paired. Tables without duplicate keys run exactly as before.
|
|
9
|
+
- **Audit trail on every assessment:** `created_at` (UTC), `bricksentry_version`, `policy_sha256` (a fingerprint of the rules behind the verdict) and `triggered_by` (`BRICKSENTRY_ACTOR`, or the GitHub actor in GitHub Actions). In the JSON and the pull-request report footer. Older saved assessments still load.
|
|
10
|
+
- README: permissions needed per feature, what a check costs, and the audit trail.
|
|
11
|
+
- Links to the agent docs no longer end in `).` where READMEs and notebooks are shown as plain text (some directories turned them into a broken link). Package description and keywords mention change impact analysis and deployment guardrails.
|
|
12
|
+
|
|
13
|
+
## 0.1.22 (2026-11-15)
|
|
14
|
+
|
|
15
|
+
Security hardening, following a review on the Canopii MCP Trust Index:
|
|
16
|
+
|
|
17
|
+
- **Outbound requests are checked.** Slack/Teams webhooks and the GitHub API must use `https://`, must not resolve to loopback, private, link-local or cloud-metadata addresses, and redirects are never followed. A webhook that fails the check is skipped with a one-line reason; the verdict is unchanged. Set `BRICKSENTRY_ALLOW_PRIVATE_URLS=1` for targets on a private network such as GitHub Enterprise Server.
|
|
18
|
+
- **Container image** for the MCP server: `deploy/container/Dockerfile` (non-root user, config mounted read-only). CI builds it on every push and checks that it lists the MCP tools.
|
|
19
|
+
- `SECURITY.md` explains the network behaviour, why the MCP server listens on `0.0.0.0` only on Databricks Apps, and how releases are published.
|
|
20
|
+
- `bricksentry preview` with no `keys` configured for the table now exits with code 2 (configuration error), as the CLI help and README document; 0.1.21 exited 1. Found in the live test of 0.1.21.
|
|
21
|
+
|
|
3
22
|
## 0.1.21 (2026-11-13)
|
|
4
23
|
|
|
5
24
|
- `bricksentry preview` printed a raw Python traceback when it refused a statement (DROP, TRUNCATE, ALTER, GRANT, several statements). It now prints the refusal and what to do instead, and exits with code 2. A missing `keys` setting is also reported as one clear line. Agents were not affected: the MCP tools already returned the refusal as an error message. Found in a live test on Databricks.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: Change
|
|
3
|
+
Version: 0.1.23
|
|
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
|
|
7
7
|
Project-URL: Source, https://github.com/bricksentry/bricksentry
|
|
@@ -10,7 +10,7 @@ Project-URL: Changelog, https://github.com/bricksentry/bricksentry/blob/main/CHA
|
|
|
10
10
|
Author: Brahma
|
|
11
11
|
License-Expression: Apache-2.0
|
|
12
12
|
License-File: LICENSE
|
|
13
|
-
Keywords: ai-agents,ci,data-diff,data-engineering,data-quality,databricks,delta-lake,impact-analysis,lineage,mcp,unity-catalog
|
|
13
|
+
Keywords: ai-agents,change-impact-analysis,ci,data-diff,data-engineering,data-quality,databricks,delta-lake,deployment-guardrails,impact-analysis,lineage,mcp,rollback,unity-catalog
|
|
14
14
|
Classifier: Development Status :: 3 - Alpha
|
|
15
15
|
Classifier: Intended Audience :: Developers
|
|
16
16
|
Classifier: Operating System :: OS Independent
|
|
@@ -213,7 +213,7 @@ databricks bundle deploy --var warehouse_id=<your-sql-warehouse-id>
|
|
|
213
213
|
databricks bundle run bricksentry_mcp
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
-
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --
|
|
216
|
+
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --port 8000` serves the same endpoint (on 127.0.0.1 unless you pass `--host`). To run it isolated, use the container image in [`deploy/container`](deploy/container/Dockerfile): non-root, config mounted read-only. [SECURITY.md](SECURITY.md) explains what bricksentry may reach over the network. Unity Catalog *MCP Services* are for servers hosted outside Databricks, so a Databricks App is the recommended way to run bricksentry inside it; see the [kit's README](deploy/databricks-app/README.md).
|
|
217
217
|
|
|
218
218
|
## For data engineers: CLI and CI
|
|
219
219
|
|
|
@@ -432,10 +432,27 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
432
432
|
|
|
433
433
|
## Permissions needed on Databricks
|
|
434
434
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
435
|
+
Grant only what the features you use need. Everything is read-only except the scratch schema.
|
|
436
|
+
|
|
437
|
+
| Feature | Needs |
|
|
438
|
+
|---|---|
|
|
439
|
+
| Any check | `CAN USE` on a SQL warehouse |
|
|
440
|
+
| Data diff (`diff`, `assess`, pull-request checks) | `SELECT` on the tables and their candidates |
|
|
441
|
+
| `check-last-change`, the job task | `SELECT` on the table and its Delta history (versions not yet removed by `VACUUM`), and `CREATE TABLE` on `sandbox_schema` for two short-lived shallow clones |
|
|
442
|
+
| `preview_write` (agents) | `CREATE TABLE` on `sandbox_schema`; the write only ever runs on a clone there |
|
|
443
|
+
| Blast radius | `SELECT` on `system.access.table_lineage` |
|
|
444
|
+
| Column-level impact | `SELECT` on `system.access.column_lineage` |
|
|
445
|
+
| Owners and tags | `SELECT` on `system.information_schema` (tables, table tags, column tags) |
|
|
446
|
+
|
|
447
|
+
Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing. A dedicated service principal with exactly these grants is the recommended setup for jobs and the MCP server.
|
|
448
|
+
|
|
449
|
+
## What a check costs
|
|
450
|
+
|
|
451
|
+
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries: 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: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. 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. Lineage lookups are one query per depth level, bounded by `lookback_days`.
|
|
452
|
+
|
|
453
|
+
## Audit trail
|
|
454
|
+
|
|
455
|
+
Every assessment records when it ran (UTC), the bricksentry version, a SHA-256 fingerprint of the policy rules that produced the verdict, and who triggered it (`BRICKSENTRY_ACTOR`, or the GitHub actor in GitHub Actions). They're in the JSON and in the footer of the pull-request report, so a verdict can be traced to the exact rules behind it. Assessments are saved as JSON under `assessment_store`; point it at a shared, access-controlled folder to keep a history.
|
|
439
456
|
|
|
440
457
|
## Known limits (v0.1.x)
|
|
441
458
|
|
|
@@ -166,7 +166,7 @@ databricks bundle deploy --var warehouse_id=<your-sql-warehouse-id>
|
|
|
166
166
|
databricks bundle run bricksentry_mcp
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
-
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --
|
|
169
|
+
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --port 8000` serves the same endpoint (on 127.0.0.1 unless you pass `--host`). To run it isolated, use the container image in [`deploy/container`](deploy/container/Dockerfile): non-root, config mounted read-only. [SECURITY.md](SECURITY.md) explains what bricksentry may reach over the network. Unity Catalog *MCP Services* are for servers hosted outside Databricks, so a Databricks App is the recommended way to run bricksentry inside it; see the [kit's README](deploy/databricks-app/README.md).
|
|
170
170
|
|
|
171
171
|
## For data engineers: CLI and CI
|
|
172
172
|
|
|
@@ -385,10 +385,27 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
385
385
|
|
|
386
386
|
## Permissions needed on Databricks
|
|
387
387
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
388
|
+
Grant only what the features you use need. Everything is read-only except the scratch schema.
|
|
389
|
+
|
|
390
|
+
| Feature | Needs |
|
|
391
|
+
|---|---|
|
|
392
|
+
| Any check | `CAN USE` on a SQL warehouse |
|
|
393
|
+
| Data diff (`diff`, `assess`, pull-request checks) | `SELECT` on the tables and their candidates |
|
|
394
|
+
| `check-last-change`, the job task | `SELECT` on the table and its Delta history (versions not yet removed by `VACUUM`), and `CREATE TABLE` on `sandbox_schema` for two short-lived shallow clones |
|
|
395
|
+
| `preview_write` (agents) | `CREATE TABLE` on `sandbox_schema`; the write only ever runs on a clone there |
|
|
396
|
+
| Blast radius | `SELECT` on `system.access.table_lineage` |
|
|
397
|
+
| Column-level impact | `SELECT` on `system.access.column_lineage` |
|
|
398
|
+
| Owners and tags | `SELECT` on `system.information_schema` (tables, table tags, column tags) |
|
|
399
|
+
|
|
400
|
+
Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing. A dedicated service principal with exactly these grants is the recommended setup for jobs and the MCP server.
|
|
401
|
+
|
|
402
|
+
## What a check costs
|
|
403
|
+
|
|
404
|
+
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries: 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: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. 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. Lineage lookups are one query per depth level, bounded by `lookback_days`.
|
|
405
|
+
|
|
406
|
+
## Audit trail
|
|
407
|
+
|
|
408
|
+
Every assessment records when it ran (UTC), the bricksentry version, a SHA-256 fingerprint of the policy rules that produced the verdict, and who triggered it (`BRICKSENTRY_ACTOR`, or the GitHub actor in GitHub Actions). They're in the JSON and in the footer of the pull-request report, so a verdict can be traced to the exact rules behind it. Assessments are saved as JSON under `assessment_store`; point it at a shared, access-controlled folder to keep a history.
|
|
392
409
|
|
|
393
410
|
## Known limits (v0.1.x)
|
|
394
411
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Security policy
|
|
2
|
+
|
|
3
|
+
bricksentry runs SQL against your data warehouse and can be called by AI agents, so we take reports seriously.
|
|
4
|
+
|
|
5
|
+
## Reporting a vulnerability
|
|
6
|
+
|
|
7
|
+
Please use GitHub's private vulnerability reporting: open the repository's **Security** tab and choose **Report a vulnerability**. Don't open a public issue for security problems.
|
|
8
|
+
|
|
9
|
+
Especially relevant:
|
|
10
|
+
|
|
11
|
+
- Any way for `preview_write` to modify a table other than its sandbox clone
|
|
12
|
+
- SQL injection through table names, keys or config values
|
|
13
|
+
- Ways for an agent to obtain a `pass` verdict that the policy should not allow
|
|
14
|
+
|
|
15
|
+
You'll get an acknowledgement as soon as possible, and a fix or mitigation plan once the report is confirmed.
|
|
16
|
+
|
|
17
|
+
## How bricksentry handles your environment
|
|
18
|
+
|
|
19
|
+
**Network.** bricksentry talks to your SQL warehouse through the Databricks SDK, and makes only two other kinds of outbound HTTP call: Slack/Teams webhooks you configure, and the GitHub API when you ask it to comment on a pull request. Both must use `https://`, must not resolve to loopback, private, link-local or other non-public addresses (so a misconfigured URL can't reach internal services or cloud metadata endpoints), and redirects are never followed. If a legitimate target is on a private network, such as GitHub Enterprise Server or a webhook relay in your VPC, set `BRICKSENTRY_ALLOW_PRIVATE_URLS=1`. Webhook URLs are never written to logs or error messages.
|
|
20
|
+
|
|
21
|
+
**MCP server.** Over HTTP it listens on `127.0.0.1` by default. It listens on `0.0.0.0` only on Databricks Apps (when `DATABRICKS_APP_PORT` is set), because the platform requires it and puts its own authentication in front. `--read-only` removes `preview_write`, so a shared server never writes, not even to a sandbox clone. To isolate it further, run it in a container: see `deploy/container/Dockerfile` (non-root user, config mounted read-only).
|
|
22
|
+
|
|
23
|
+
**Writes.** The only tool that writes, `preview_write`, runs one statement on a disposable shallow clone and refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements. Verdicts come from your policy file, never from an LLM.
|
|
24
|
+
|
|
25
|
+
**Secrets.** Credentials come from the environment, the Databricks SDK's own configuration or a secret scope; bricksentry never stores them.
|
|
26
|
+
|
|
27
|
+
**Releases.** Releases are built and published by GitHub Actions with PyPI trusted publishing (no long-lived upload token), from a tagged commit on `main`. Releases published by the workflow carry PyPI provenance attestations, which you can check on each file's page on PyPI.
|
|
28
|
+
|
|
29
|
+
## Supported versions
|
|
30
|
+
|
|
31
|
+
Only the latest release receives security fixes during the 0.x series.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# bricksentry MCP server in a container, running as a non-root user.
|
|
2
|
+
#
|
|
3
|
+
# Build from the repository root:
|
|
4
|
+
# docker build -f deploy/container/Dockerfile -t bricksentry-mcp .
|
|
5
|
+
#
|
|
6
|
+
# stdio (for Claude, Cursor and other MCP clients), config mounted read-only:
|
|
7
|
+
# docker run -i --rm -v "$PWD/bricksentry.yml:/config/bricksentry.yml:ro" \
|
|
8
|
+
# -e DATABRICKS_HOST -e DATABRICKS_TOKEN bricksentry-mcp
|
|
9
|
+
#
|
|
10
|
+
# HTTP, published on this machine only (inside the container the server must listen on 0.0.0.0):
|
|
11
|
+
# docker run --rm -p 127.0.0.1:8000:8000 -e BRICKSENTRY_HOST=0.0.0.0 \
|
|
12
|
+
# -v "$PWD/bricksentry.yml:/config/bricksentry.yml:ro" -e DATABRICKS_HOST -e DATABRICKS_TOKEN \
|
|
13
|
+
# bricksentry-mcp --config /config/bricksentry.yml --transport streamable-http --read-only
|
|
14
|
+
|
|
15
|
+
FROM python:3.12-slim
|
|
16
|
+
|
|
17
|
+
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PIP_NO_CACHE_DIR=1 PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
18
|
+
|
|
19
|
+
COPY pyproject.toml README.md LICENSE /src/
|
|
20
|
+
COPY src /src/src
|
|
21
|
+
RUN pip install "/src[databricks,mcp]" && rm -rf /src \
|
|
22
|
+
&& useradd --create-home --uid 10001 bricksentry
|
|
23
|
+
|
|
24
|
+
USER bricksentry
|
|
25
|
+
WORKDIR /home/bricksentry
|
|
26
|
+
ENV BRICKSENTRY_STORE=/home/bricksentry/.bricksentry/assessments
|
|
27
|
+
|
|
28
|
+
ENTRYPOINT ["bricksentry", "mcp"]
|
|
29
|
+
CMD ["--config", "/config/bricksentry.yml"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.23
|
{bricksentry-0.1.21 → bricksentry-0.1.23}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
@@ -287,7 +287,7 @@
|
|
|
287
287
|
"source": [
|
|
288
288
|
"## Next steps\n",
|
|
289
289
|
"- **Check every change before it ships:** run the same check in CI on pull requests. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).\n",
|
|
290
|
-
"- **Let AI agents check their own changes:** `uvx bricksentry-mcp
|
|
290
|
+
"- **Let AI agents check their own changes:** `uvx bricksentry-mcp`, docs at <https://bricksentry.org/docs/agents>\n",
|
|
291
291
|
"- **Get alerts:** set a Slack or Teams webhook and run `bricksentry test-alert`. See [bricksentry.org/docs/configuration](https://bricksentry.org/docs/configuration)."
|
|
292
292
|
]
|
|
293
293
|
}
|
|
@@ -229,5 +229,5 @@ print("Share what it found:\nhttps://github.com/bricksentry/bricksentry/issues/n
|
|
|
229
229
|
# MAGIC %md
|
|
230
230
|
# MAGIC ## Next steps
|
|
231
231
|
# MAGIC - **Check every change before it ships:** run the same check in CI on pull requests. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).
|
|
232
|
-
# MAGIC - **Let AI agents check their own changes:** `uvx bricksentry-mcp
|
|
232
|
+
# MAGIC - **Let AI agents check their own changes:** `uvx bricksentry-mcp`, docs at <https://bricksentry.org/docs/agents>
|
|
233
233
|
# MAGIC - **Get alerts:** set a Slack or Teams webhook and run `bricksentry test-alert`. See [bricksentry.org/docs/configuration](https://bricksentry.org/docs/configuration).
|
|
@@ -343,7 +343,7 @@
|
|
|
343
343
|
"source": [
|
|
344
344
|
"## Next steps\n",
|
|
345
345
|
"- **In CI:** `bricksentry init` writes `bricksentry.yml` and `policy.yml`; add `bricksentry assess --from-git origin/main --comment` to your pull-request workflow. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).\n",
|
|
346
|
-
"- **For AI agents:** `bricksentry mcp` exposes these same tools over MCP
|
|
346
|
+
"- **For AI agents:** `bricksentry mcp` exposes these same tools over MCP, docs at <https://bricksentry.org/docs/agents>\n",
|
|
347
347
|
"- **Feedback and bugs:** [github.com/bricksentry/bricksentry/issues](https://github.com/bricksentry/bricksentry/issues)"
|
|
348
348
|
]
|
|
349
349
|
}
|
|
@@ -257,5 +257,5 @@ agent_tools.set_sentry(None)
|
|
|
257
257
|
# MAGIC %md
|
|
258
258
|
# MAGIC ## Next steps
|
|
259
259
|
# MAGIC - **In CI:** `bricksentry init` writes `bricksentry.yml` and `policy.yml`; add `bricksentry assess --from-git origin/main --comment` to your pull-request workflow. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).
|
|
260
|
-
# MAGIC - **For AI agents:** `bricksentry mcp` exposes these same tools over MCP
|
|
260
|
+
# MAGIC - **For AI agents:** `bricksentry mcp` exposes these same tools over MCP, docs at <https://bricksentry.org/docs/agents>
|
|
261
261
|
# MAGIC - **Feedback and bugs:** [github.com/bricksentry/bricksentry/issues](https://github.com/bricksentry/bricksentry/issues)
|
|
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "Change
|
|
7
|
+
version = "0.1.23"
|
|
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"
|
|
11
11
|
license = "Apache-2.0"
|
|
@@ -13,6 +13,7 @@ authors = [{ name = "Brahma" }]
|
|
|
13
13
|
keywords = [
|
|
14
14
|
"databricks", "delta-lake", "unity-catalog", "data-engineering", "data-diff",
|
|
15
15
|
"lineage", "impact-analysis", "ci", "mcp", "ai-agents", "data-quality",
|
|
16
|
+
"change-impact-analysis", "deployment-guardrails", "rollback",
|
|
16
17
|
]
|
|
17
18
|
classifiers = [
|
|
18
19
|
"Development Status :: 3 - Alpha",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.23",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.23",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import os
|
|
6
7
|
import re
|
|
7
8
|
import uuid
|
|
9
|
+
from datetime import datetime, timezone
|
|
8
10
|
from typing import Any
|
|
9
11
|
|
|
10
12
|
from bricksentry.backends.base import Backend, make_backend
|
|
@@ -138,6 +140,10 @@ class Sentry:
|
|
|
138
140
|
tables=results,
|
|
139
141
|
verdict=Verdict.worst([t.verdict for t in results]),
|
|
140
142
|
notify=sorted(notify),
|
|
143
|
+
created_at=datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
144
|
+
bricksentry_version=_version(),
|
|
145
|
+
policy_sha256=self.policy.sha256,
|
|
146
|
+
triggered_by=_actor(),
|
|
141
147
|
)
|
|
142
148
|
self._assessments[a.id] = a
|
|
143
149
|
self._save(a)
|
|
@@ -255,6 +261,22 @@ class Sentry:
|
|
|
255
261
|
return self._diffs.get(table)
|
|
256
262
|
|
|
257
263
|
|
|
264
|
+
def _version() -> str:
|
|
265
|
+
from bricksentry import __version__ # imported late: bricksentry/__init__ imports this module
|
|
266
|
+
|
|
267
|
+
return __version__
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _actor() -> str | None:
|
|
271
|
+
"""Who asked for the check: BRICKSENTRY_ACTOR if set, else the GitHub actor in
|
|
272
|
+
GitHub Actions. Nothing is read from the machine itself."""
|
|
273
|
+
if os.environ.get("BRICKSENTRY_ACTOR"):
|
|
274
|
+
return os.environ["BRICKSENTRY_ACTOR"].strip()[:200]
|
|
275
|
+
if os.environ.get("GITHUB_ACTOR"):
|
|
276
|
+
return "github:" + os.environ["GITHUB_ACTOR"].strip()[:200]
|
|
277
|
+
return None
|
|
278
|
+
|
|
279
|
+
|
|
258
280
|
def _first_line(e: Exception, limit: int = 200) -> str:
|
|
259
281
|
"""A short, single-line error for verdict reasons and alerts."""
|
|
260
282
|
text = (str(e).strip().splitlines() or [type(e).__name__])[0]
|
|
@@ -54,6 +54,22 @@ class Backend(ABC):
|
|
|
54
54
|
backend has no cheap row hash, and the guard is skipped."""
|
|
55
55
|
return None
|
|
56
56
|
|
|
57
|
+
def row_hash(self, columns: list[str]) -> str | None:
|
|
58
|
+
"""SQL for a hash of one row's ``columns``; orders copies of a duplicated key
|
|
59
|
+
so identical copies pair up. ``None`` means unsupported (copies are paired in
|
|
60
|
+
no particular order)."""
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
def exact_sum(self, expr: str, type_name: str) -> str:
|
|
64
|
+
"""SUM that doesn't drift on large tables: decimals and integers are added as
|
|
65
|
+
DECIMAL(38, x), only floating-point columns as DOUBLE."""
|
|
66
|
+
t = type_name.lower()
|
|
67
|
+
if t.startswith(("decimal", "numeric")):
|
|
68
|
+
return f"SUM({expr})"
|
|
69
|
+
if t.startswith(("float", "double", "real")):
|
|
70
|
+
return f"SUM(CAST({expr} AS DOUBLE))"
|
|
71
|
+
return f"SUM(CAST({expr} AS DECIMAL(38, 0)))"
|
|
72
|
+
|
|
57
73
|
@abstractmethod
|
|
58
74
|
def days_ago(self, days: int) -> str:
|
|
59
75
|
"""SQL expression for the date ``days`` days ago."""
|
|
@@ -109,6 +109,9 @@ class DatabricksBackend(Backend):
|
|
|
109
109
|
cols = ", ".join(self.quote(c) for c in columns)
|
|
110
110
|
return f"SUM(CAST(xxhash64({cols}) AS DECIMAL(38, 0)))"
|
|
111
111
|
|
|
112
|
+
def row_hash(self, columns: list[str]) -> str | None:
|
|
113
|
+
return f"xxhash64({', '.join(self.quote(c) for c in columns)})"
|
|
114
|
+
|
|
112
115
|
def sample_predicate(self, keys: list[str], pct: float, alias: str | None = None) -> str:
|
|
113
116
|
pre = f"{alias}." if alias else ""
|
|
114
117
|
cols = ", ".join(f"{pre}{self.quote(k)}" for k in keys)
|
|
@@ -38,6 +38,9 @@ class DuckDBBackend(Backend):
|
|
|
38
38
|
cols = ", ".join(self.quote(c) for c in columns)
|
|
39
39
|
return f"SUM(CAST(hash({cols}) AS HUGEINT))"
|
|
40
40
|
|
|
41
|
+
def row_hash(self, columns: list[str]) -> str | None:
|
|
42
|
+
return f"hash({', '.join(self.quote(c) for c in columns)})"
|
|
43
|
+
|
|
41
44
|
def sample_predicate(self, keys: list[str], pct: float, alias: str | None = None) -> str:
|
|
42
45
|
pre = f"{alias}." if alias else ""
|
|
43
46
|
cols = ", ".join(f"{pre}{self.quote(k)}" for k in keys)
|
|
@@ -170,8 +170,10 @@ def preview(target, sql_text, sql_file, keys, fmt, notify, fail_on, config_path)
|
|
|
170
170
|
# A refused statement is an expected outcome, not a crash: say why and what to do instead.
|
|
171
171
|
click.echo(click.style("Refused: ", fg="red", bold=True) + str(e), err=True)
|
|
172
172
|
raise SystemExit(2) from None
|
|
173
|
-
except ValueError as e: # e.g. no key columns configured
|
|
174
|
-
|
|
173
|
+
except ValueError as e: # e.g. no key columns configured: a configuration error, exit 2
|
|
174
|
+
err = click.ClickException(str(e))
|
|
175
|
+
err.exit_code = 2
|
|
176
|
+
raise err from None
|
|
175
177
|
if notify:
|
|
176
178
|
a = s.get_assessment(out["id"])
|
|
177
179
|
if a is not None:
|
|
@@ -114,14 +114,50 @@ def _diff(
|
|
|
114
114
|
# A marker column says whether a joined row exists on each side. Testing the key
|
|
115
115
|
# for NULL instead would count a NULL-key row as both added and removed.
|
|
116
116
|
present = q("__bs_present")
|
|
117
|
+
occ = q("__bs_occ")
|
|
118
|
+
kc = ", ".join(q(k) for k in keys)
|
|
117
119
|
|
|
118
|
-
def
|
|
119
|
-
|
|
120
|
-
return f"{alias} AS (SELECT *, 1 AS {present} FROM {backend.qualified(tbl)}{where})"
|
|
120
|
+
def sample_where() -> str:
|
|
121
|
+
return f" WHERE {backend.sample_predicate(keys, sample_pct)}" if sample_pct else ""
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
def raw_cte(tbl: str, alias: str) -> str:
|
|
124
|
+
return f"{alias} AS (SELECT *, 1 AS {present} FROM {backend.qualified(tbl)}{sample_where()})"
|
|
125
|
+
|
|
126
|
+
# Duplicate keys first: a key that appears more than once (including many NULL
|
|
127
|
+
# keys, which match each other) would multiply rows in the key join.
|
|
128
|
+
raw_ctes = f"WITH {raw_cte(base, 'b_src')}, {raw_cte(candidate, 'c_src')}"
|
|
129
|
+
|
|
130
|
+
def dupes(tbl_cte: str) -> int:
|
|
131
|
+
sql = (
|
|
132
|
+
f"{raw_ctes} SELECT COUNT(*) AS n FROM "
|
|
133
|
+
f"(SELECT {kc} FROM {tbl_cte} GROUP BY {kc} HAVING COUNT(*) > 1) d"
|
|
134
|
+
)
|
|
135
|
+
return int(backend.scalar(sql) or 0)
|
|
136
|
+
|
|
137
|
+
dup_b, dup_c = dupes("b_src"), dupes("c_src")
|
|
138
|
+
notes: list[str] = []
|
|
139
|
+
pair_copies = bool(dup_b or dup_c)
|
|
140
|
+
if pair_copies:
|
|
141
|
+
# Number the copies of each key and match copy n to copy n, so the join stays
|
|
142
|
+
# one to one: an extra copy counts as added (or removed), not as a second match.
|
|
143
|
+
# Ordering by a row hash pairs identical copies with each other.
|
|
144
|
+
order = backend.row_hash([c for c in b_cols if c in c_cols and c not in schema.type_changed]) or kc
|
|
145
|
+
|
|
146
|
+
def side(tbl: str, alias: str) -> str:
|
|
147
|
+
return (f"{alias} AS (SELECT *, 1 AS {present}, ROW_NUMBER() OVER (PARTITION BY {kc} "
|
|
148
|
+
f"ORDER BY {order}) AS {occ} FROM {backend.qualified(tbl)}{sample_where()})")
|
|
149
|
+
|
|
150
|
+
ctes = f"WITH {side(base, 'b_src')}, {side(candidate, 'c_src')}"
|
|
151
|
+
notes.append(
|
|
152
|
+
"Some keys appear more than once, so copies of the same key were paired one to one "
|
|
153
|
+
"(an extra copy counts as added or removed, not as another match)."
|
|
154
|
+
)
|
|
155
|
+
else:
|
|
156
|
+
ctes = raw_ctes
|
|
123
157
|
# Null-safe key match: a NULL key in production matches a NULL key in the candidate.
|
|
124
158
|
join_on = " AND ".join(f"b.{q(k)} IS NOT DISTINCT FROM c.{q(k)}" for k in keys)
|
|
159
|
+
if pair_copies:
|
|
160
|
+
join_on += f" AND b.{occ} = c.{occ}"
|
|
125
161
|
in_b, in_c = f"b.{present} IS NOT NULL", f"c.{present} IS NOT NULL"
|
|
126
162
|
|
|
127
163
|
def cmp(col: str) -> str:
|
|
@@ -149,27 +185,19 @@ def _diff(
|
|
|
149
185
|
)
|
|
150
186
|
j = backend.query(join_sql)[0]
|
|
151
187
|
|
|
152
|
-
# Row counts, nulls, numeric sums per side.
|
|
188
|
+
# Row counts, nulls, numeric sums per side. Sums are exact for decimals and integers.
|
|
153
189
|
def profile(tbl_cte: str, cols: dict[str, str]) -> dict:
|
|
154
190
|
any_null_key = " OR ".join(f"{q(k)} IS NULL" for k in keys)
|
|
155
191
|
parts = ["COUNT(*) AS n_rows", f"SUM(CASE WHEN {any_null_key} THEN 1 ELSE 0 END) AS null_keys"]
|
|
156
192
|
for i, col in enumerate(common):
|
|
157
193
|
parts.append(f"SUM(CASE WHEN {q(col)} IS NULL THEN 1 ELSE 0 END) AS nul_{i}")
|
|
158
194
|
if backend.is_numeric(cols[col]):
|
|
159
|
-
parts.append(f"
|
|
160
|
-
return backend.query(f"{
|
|
195
|
+
parts.append(f"{backend.exact_sum(q(col), cols[col])} AS sum_{i}")
|
|
196
|
+
return backend.query(f"{raw_ctes} SELECT {', '.join(parts)} FROM {tbl_cte}")[0]
|
|
161
197
|
|
|
162
198
|
pb = profile("b_src", b_cols)
|
|
163
199
|
pc = profile("c_src", c_cols)
|
|
164
200
|
|
|
165
|
-
def dupes(tbl_cte: str) -> int:
|
|
166
|
-
kc = ", ".join(q(k) for k in keys)
|
|
167
|
-
sql = (
|
|
168
|
-
f"{ctes} SELECT COUNT(*) AS n FROM "
|
|
169
|
-
f"(SELECT {kc} FROM {tbl_cte} GROUP BY {kc} HAVING COUNT(*) > 1) d"
|
|
170
|
-
)
|
|
171
|
-
return int(backend.scalar(sql) or 0)
|
|
172
|
-
|
|
173
201
|
col_changes: list[ColumnChange] = []
|
|
174
202
|
for i, col in enumerate(common):
|
|
175
203
|
changed = int(j.get(f"chg_{i}") or 0)
|
|
@@ -225,12 +253,13 @@ def _diff(
|
|
|
225
253
|
unchanged_rows=int(j.get("unchanged_rows") or 0),
|
|
226
254
|
schema=schema,
|
|
227
255
|
columns=col_changes,
|
|
228
|
-
duplicate_keys_base=
|
|
229
|
-
duplicate_keys_candidate=
|
|
256
|
+
duplicate_keys_base=dup_b,
|
|
257
|
+
duplicate_keys_candidate=dup_c,
|
|
230
258
|
null_keys_base=int(pb.get("null_keys") or 0),
|
|
231
259
|
null_keys_candidate=int(pc.get("null_keys") or 0),
|
|
232
260
|
segments=segments,
|
|
233
261
|
sampled_pct=sample_pct,
|
|
262
|
+
notes=notes,
|
|
234
263
|
)
|
|
235
264
|
|
|
236
265
|
|
|
@@ -6,6 +6,7 @@ import json
|
|
|
6
6
|
import os
|
|
7
7
|
import urllib.request
|
|
8
8
|
|
|
9
|
+
from bricksentry import netguard
|
|
9
10
|
from bricksentry.report import MARKER
|
|
10
11
|
|
|
11
12
|
|
|
@@ -17,7 +18,7 @@ def _req(method: str, url: str, token: str, body: dict | None = None):
|
|
|
17
18
|
req.add_header("X-GitHub-Api-Version", "2022-11-28")
|
|
18
19
|
if data:
|
|
19
20
|
req.add_header("Content-Type", "application/json")
|
|
20
|
-
with
|
|
21
|
+
with netguard.urlopen(req, timeout=30) as r:
|
|
21
22
|
return json.loads(r.read() or b"null")
|
|
22
23
|
|
|
23
24
|
|
|
@@ -91,6 +91,7 @@ class TableDiff:
|
|
|
91
91
|
sampled_pct: float | None = None
|
|
92
92
|
sample_note: str | None = None
|
|
93
93
|
error: str | None = None
|
|
94
|
+
notes: list[str] = field(default_factory=list)
|
|
94
95
|
|
|
95
96
|
def _pct(self, n: int) -> float:
|
|
96
97
|
denom = max(self.base_rows, 1)
|
|
@@ -260,6 +261,11 @@ class Assessment:
|
|
|
260
261
|
tables: list[TableAssessment]
|
|
261
262
|
verdict: Verdict
|
|
262
263
|
notify: list[str] = field(default_factory=list)
|
|
264
|
+
# Audit trail: when, with which bricksentry and policy, and who asked.
|
|
265
|
+
created_at: str | None = None # UTC, ISO 8601
|
|
266
|
+
bricksentry_version: str | None = None
|
|
267
|
+
policy_sha256: str | None = None # fingerprint of the policy rules that produced the verdict
|
|
268
|
+
triggered_by: str | None = None # BRICKSENTRY_ACTOR, or the GitHub actor in GitHub Actions
|
|
263
269
|
|
|
264
270
|
@property
|
|
265
271
|
def hits(self) -> list[RuleHit]:
|
|
@@ -272,6 +278,10 @@ class Assessment:
|
|
|
272
278
|
"risk_tier": self.verdict.risk_tier,
|
|
273
279
|
"safe_to_ship": self.verdict in (Verdict.PASS, Verdict.WARN),
|
|
274
280
|
"notify": self.notify,
|
|
281
|
+
"created_at": self.created_at,
|
|
282
|
+
"bricksentry_version": self.bricksentry_version,
|
|
283
|
+
"policy_sha256": self.policy_sha256,
|
|
284
|
+
"triggered_by": self.triggered_by,
|
|
275
285
|
"rule_hits": [h.to_dict() for h in self.hits],
|
|
276
286
|
"tables": [t.to_dict() for t in self.tables],
|
|
277
287
|
}
|
|
@@ -283,4 +293,8 @@ class Assessment:
|
|
|
283
293
|
tables=[TableAssessment.from_dict(t) for t in d.get("tables") or []],
|
|
284
294
|
verdict=Verdict(d["verdict"]),
|
|
285
295
|
notify=list(d.get("notify") or []),
|
|
296
|
+
created_at=d.get("created_at"),
|
|
297
|
+
bricksentry_version=d.get("bricksentry_version"),
|
|
298
|
+
policy_sha256=d.get("policy_sha256"),
|
|
299
|
+
triggered_by=d.get("triggered_by"),
|
|
286
300
|
)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Guard for the few outbound HTTP calls bricksentry makes (Slack/Teams webhooks, GitHub API).
|
|
2
|
+
|
|
3
|
+
The URLs come from your own config or CI environment, but a mistyped or malicious value could
|
|
4
|
+
still point at an internal service. So outbound requests must use https, must not target
|
|
5
|
+
loopback, private, link-local or other non-public addresses, and never follow redirects.
|
|
6
|
+
|
|
7
|
+
Set ``BRICKSENTRY_ALLOW_PRIVATE_URLS=1`` when a legitimate target is on a private network
|
|
8
|
+
(for example GitHub Enterprise Server or a webhook relay inside your VPC).
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import ipaddress
|
|
14
|
+
import os
|
|
15
|
+
import socket
|
|
16
|
+
import urllib.request
|
|
17
|
+
from urllib.parse import urlsplit
|
|
18
|
+
|
|
19
|
+
ALLOW_PRIVATE_ENV = "BRICKSENTRY_ALLOW_PRIVATE_URLS"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class UnsafeURLError(ValueError):
|
|
23
|
+
"""An outbound URL that bricksentry refuses to call."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _private_allowed() -> bool:
|
|
27
|
+
return os.environ.get(ALLOW_PRIVATE_ENV, "").strip().lower() in ("1", "true", "yes")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _is_public(ip: str) -> bool:
|
|
31
|
+
addr = ipaddress.ip_address(ip.split("%", 1)[0])
|
|
32
|
+
if isinstance(addr, ipaddress.IPv6Address) and addr.ipv4_mapped:
|
|
33
|
+
addr = addr.ipv4_mapped
|
|
34
|
+
return not (addr.is_private or addr.is_loopback or addr.is_link_local or addr.is_reserved
|
|
35
|
+
or addr.is_multicast or addr.is_unspecified)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def check_url(url: str, what: str = "URL") -> None:
|
|
39
|
+
"""Raise UnsafeURLError if ``url`` is not https or resolves to a non-public address.
|
|
40
|
+
|
|
41
|
+
A host that can't be resolved right now is let through: the request itself will then fail
|
|
42
|
+
with a normal connection error, and nothing internal can be reached that way.
|
|
43
|
+
"""
|
|
44
|
+
parts = urlsplit(url)
|
|
45
|
+
if parts.scheme != "https":
|
|
46
|
+
raise UnsafeURLError(f"{what} must start with https://")
|
|
47
|
+
host = parts.hostname
|
|
48
|
+
if not host:
|
|
49
|
+
raise UnsafeURLError(f"{what} has no host")
|
|
50
|
+
if _private_allowed():
|
|
51
|
+
return
|
|
52
|
+
if host.lower() in ("localhost", "localhost.localdomain") or host.lower().endswith(".localhost"):
|
|
53
|
+
raise UnsafeURLError(f"{what} points at localhost; set {ALLOW_PRIVATE_ENV}=1 if that is intended")
|
|
54
|
+
try:
|
|
55
|
+
ipaddress.ip_address(host)
|
|
56
|
+
candidates = [host]
|
|
57
|
+
except ValueError:
|
|
58
|
+
try:
|
|
59
|
+
candidates = [info[4][0] for info in socket.getaddrinfo(host, parts.port or 443)]
|
|
60
|
+
except (socket.gaierror, UnicodeError, OSError):
|
|
61
|
+
return
|
|
62
|
+
for ip in candidates:
|
|
63
|
+
if not _is_public(ip):
|
|
64
|
+
raise UnsafeURLError(
|
|
65
|
+
f"{what} resolves to a non-public address; set {ALLOW_PRIVATE_ENV}=1 if that is intended")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
69
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl): # noqa: D102
|
|
70
|
+
return None # a redirect becomes an HTTPError instead of a request to a new host
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
_OPENER = urllib.request.build_opener(_NoRedirect)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def urlopen(req: urllib.request.Request, timeout: float):
|
|
77
|
+
"""``urllib.request.urlopen`` without redirects, after ``check_url``."""
|
|
78
|
+
check_url(req.full_url)
|
|
79
|
+
return _OPENER.open(req, timeout=timeout)
|
|
@@ -39,6 +39,7 @@ import urllib.request
|
|
|
39
39
|
from dataclasses import dataclass, field
|
|
40
40
|
from typing import Any
|
|
41
41
|
|
|
42
|
+
from bricksentry import netguard
|
|
42
43
|
from bricksentry.models import Assessment, RuleHit, TableAssessment, Verdict
|
|
43
44
|
|
|
44
45
|
_EMOJI = {"pass": ":large_green_circle:", "warn": ":large_yellow_circle:",
|
|
@@ -271,7 +272,7 @@ def _post(url: str, payload: dict[str, Any], timeout: int = 15) -> None:
|
|
|
271
272
|
req = urllib.request.Request(url, data=json.dumps(payload).encode(), method="POST")
|
|
272
273
|
req.add_header("Content-Type", "application/json")
|
|
273
274
|
req.add_header("User-Agent", f"bricksentry/{_version()}")
|
|
274
|
-
with
|
|
275
|
+
with netguard.urlopen(req, timeout=timeout) as r:
|
|
275
276
|
r.read()
|
|
276
277
|
|
|
277
278
|
|
|
@@ -339,8 +340,10 @@ def send(a: Assessment, settings: NotifySettings, pr: str | None = None, force:
|
|
|
339
340
|
for name, url, build in channels:
|
|
340
341
|
if not url:
|
|
341
342
|
continue
|
|
342
|
-
|
|
343
|
-
|
|
343
|
+
try:
|
|
344
|
+
netguard.check_url(url, "webhook URL")
|
|
345
|
+
except netguard.UnsafeURLError as e:
|
|
346
|
+
out.append(f"{name}: skipped, {e}")
|
|
344
347
|
continue
|
|
345
348
|
try:
|
|
346
349
|
_deliver(url, build())
|
|
@@ -40,6 +40,8 @@ All conditions inside one ``when`` must hold (AND). Use several rules for OR.
|
|
|
40
40
|
from __future__ import annotations
|
|
41
41
|
|
|
42
42
|
import fnmatch
|
|
43
|
+
import hashlib
|
|
44
|
+
import json
|
|
43
45
|
from typing import Any
|
|
44
46
|
|
|
45
47
|
from bricksentry.measures import is_measure
|
|
@@ -104,6 +106,10 @@ def _tag_label(want: Any) -> str:
|
|
|
104
106
|
class Policy:
|
|
105
107
|
def __init__(self, spec: dict[str, Any] | None = None):
|
|
106
108
|
spec = spec if spec is not None else DEFAULT_POLICY
|
|
109
|
+
# A fingerprint of the rules, recorded on every assessment so a verdict can be
|
|
110
|
+
# traced to the exact policy that produced it.
|
|
111
|
+
canonical = json.dumps(spec, sort_keys=True, default=str, separators=(",", ":"))
|
|
112
|
+
self.sha256 = hashlib.sha256(canonical.encode()).hexdigest()
|
|
107
113
|
self.default = Verdict(spec.get("default", "pass"))
|
|
108
114
|
self.notify_on = Verdict(spec.get("notify_owners_on", "needs_human"))
|
|
109
115
|
self.rules = spec.get("rules") or []
|
|
@@ -38,7 +38,13 @@ def to_markdown(a: Assessment, max_downstream: int = 15) -> str:
|
|
|
38
38
|
lines.append("")
|
|
39
39
|
for t in a.tables:
|
|
40
40
|
lines += _table_section(t, max_downstream)
|
|
41
|
-
|
|
41
|
+
audit = " · ".join(x for x in (
|
|
42
|
+
f"bricksentry {a.bricksentry_version}" if a.bricksentry_version else "bricksentry",
|
|
43
|
+
f"policy `{a.policy_sha256[:12]}`" if a.policy_sha256 else "",
|
|
44
|
+
a.created_at.replace("T", " ").replace("+00:00", " UTC") if a.created_at else "",
|
|
45
|
+
f"triggered by {a.triggered_by}" if a.triggered_by else "",
|
|
46
|
+
) if x)
|
|
47
|
+
lines += ["", f"<sub>Generated by {audit}. Verdicts come from policy rules, not from an LLM.</sub>"]
|
|
42
48
|
return "\n".join(lines)
|
|
43
49
|
|
|
44
50
|
|
|
@@ -53,6 +59,7 @@ def _table_section(t: TableAssessment, max_downstream: int) -> list[str]:
|
|
|
53
59
|
f"{d.changed_rows:,} | {d.unchanged_rows:,} |",
|
|
54
60
|
"",
|
|
55
61
|
]
|
|
62
|
+
out += [f"> {_esc(n)}" for n in d.notes] + ([""] if d.notes else [])
|
|
56
63
|
changed_cols = [c for c in d.columns if c.changed_rows or (c.sum_change_pct and abs(c.sum_change_pct) > 0.01)]
|
|
57
64
|
if changed_cols:
|
|
58
65
|
out += ["<details><summary>Column changes</summary>", "",
|
{bricksentry-0.1.21 → bricksentry-0.1.23}/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.23",
|
|
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.23.",
|
|
93
93
|
"order": 10
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -107,7 +107,9 @@ def test_check_change_end_to_end():
|
|
|
107
107
|
a, change = sentry(db).check_change("sales.orders")
|
|
108
108
|
t = a.tables[0]
|
|
109
109
|
assert change.version == 3 and change.base_version == 2
|
|
110
|
-
|
|
110
|
+
# The 4 duplicated copies count as added (0.1.23); before, each copy was counted
|
|
111
|
+
# as a second match of the same key, which reported 0 added for a table that grew.
|
|
112
|
+
assert t.diff.added_rows == 4 and t.diff.base_rows == 1800 and t.diff.candidate_rows == 1804
|
|
111
113
|
assert t.diff.duplicate_keys_candidate > 0
|
|
112
114
|
assert a.verdict.value == "block" # duplicate keys
|
|
113
115
|
assert t.rollback == 'RESTORE TABLE "sales"."orders" TO VERSION AS OF 2'
|
|
@@ -28,5 +28,5 @@ def test_missing_keys_is_a_clean_error(monkeypatch, tmp_path):
|
|
|
28
28
|
cfg = tmp_path / "bricksentry.yml"
|
|
29
29
|
cfg.write_text("sandbox_schema: scratch\nassessment_store: false\nlineage: {type: static}\n")
|
|
30
30
|
r = CliRunner().invoke(main, ["preview", "other.table", "--sql", "DELETE FROM other.table", "-c", str(cfg)])
|
|
31
|
-
assert r.exit_code ==
|
|
31
|
+
assert r.exit_code == 2 and "No keys configured for other.table" in r.output
|
|
32
32
|
assert isinstance(r.exception, SystemExit)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""0.1.22: outbound URLs (webhooks, GitHub API) must be https, public, and are never redirected."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import http.server
|
|
6
|
+
import socket
|
|
7
|
+
import threading
|
|
8
|
+
import urllib.error
|
|
9
|
+
import urllib.request
|
|
10
|
+
|
|
11
|
+
import pytest
|
|
12
|
+
|
|
13
|
+
from bricksentry import github, netguard, notify
|
|
14
|
+
from bricksentry.models import Verdict
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.mark.parametrize("url", [
|
|
18
|
+
"http://hooks.slack.com/services/x", # not https
|
|
19
|
+
"https://localhost/hook",
|
|
20
|
+
"https://127.0.0.1/hook",
|
|
21
|
+
"https://169.254.169.254/latest/meta-data/", # cloud metadata endpoint
|
|
22
|
+
"https://10.0.0.5/hook",
|
|
23
|
+
"https://192.168.1.10/hook",
|
|
24
|
+
"https://[::1]/hook",
|
|
25
|
+
"https://[::ffff:127.0.0.1]/hook",
|
|
26
|
+
"https://0.0.0.0/hook",
|
|
27
|
+
"https:///nohost",
|
|
28
|
+
])
|
|
29
|
+
def test_unsafe_urls_are_refused(url):
|
|
30
|
+
with pytest.raises(netguard.UnsafeURLError):
|
|
31
|
+
netguard.check_url(url)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_public_addresses_pass():
|
|
35
|
+
netguard.check_url("https://8.8.8.8/x")
|
|
36
|
+
netguard.check_url("https://[2001:4860:4860::8888]/x")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_hostname_resolving_to_private_address_is_refused(monkeypatch):
|
|
40
|
+
monkeypatch.setattr(socket, "getaddrinfo", lambda *a, **k: [(None, None, None, "", ("10.1.2.3", 443))])
|
|
41
|
+
with pytest.raises(netguard.UnsafeURLError, match="non-public"):
|
|
42
|
+
netguard.check_url("https://hooks.internal.example/x")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_unresolvable_host_is_left_to_fail_normally(monkeypatch):
|
|
46
|
+
def boom(*a, **k):
|
|
47
|
+
raise socket.gaierror("no such host")
|
|
48
|
+
monkeypatch.setattr(socket, "getaddrinfo", boom)
|
|
49
|
+
netguard.check_url("https://does-not-exist.example/x")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_private_targets_can_be_allowed(monkeypatch):
|
|
53
|
+
monkeypatch.setenv(netguard.ALLOW_PRIVATE_ENV, "1")
|
|
54
|
+
netguard.check_url("https://10.0.0.5/api/v3")
|
|
55
|
+
with pytest.raises(netguard.UnsafeURLError): # https is still required
|
|
56
|
+
netguard.check_url("http://10.0.0.5/api/v3")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_redirects_are_not_followed():
|
|
60
|
+
class Redirect(http.server.BaseHTTPRequestHandler):
|
|
61
|
+
def do_POST(self):
|
|
62
|
+
self.send_response(302)
|
|
63
|
+
self.send_header("Location", "http://169.254.169.254/")
|
|
64
|
+
self.end_headers()
|
|
65
|
+
|
|
66
|
+
def log_message(self, *a):
|
|
67
|
+
pass
|
|
68
|
+
|
|
69
|
+
srv = http.server.HTTPServer(("127.0.0.1", 0), Redirect)
|
|
70
|
+
threading.Thread(target=srv.serve_forever, daemon=True).start()
|
|
71
|
+
try:
|
|
72
|
+
req = urllib.request.Request(f"http://127.0.0.1:{srv.server_port}/", data=b"{}", method="POST")
|
|
73
|
+
with pytest.raises(urllib.error.HTTPError) as e:
|
|
74
|
+
netguard._OPENER.open(req, timeout=5)
|
|
75
|
+
assert e.value.code == 302
|
|
76
|
+
finally:
|
|
77
|
+
srv.shutdown()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_webhook_to_private_address_is_skipped_not_sent(monkeypatch):
|
|
81
|
+
sent = []
|
|
82
|
+
monkeypatch.setattr(notify, "_post", lambda url, payload, timeout=15: sent.append(url))
|
|
83
|
+
a = notify.sample_assessment(Verdict.BLOCK)
|
|
84
|
+
settings = notify.NotifySettings(slack_webhook="https://169.254.169.254/hook")
|
|
85
|
+
out = notify.send(a, settings, force=True)
|
|
86
|
+
assert sent == []
|
|
87
|
+
assert out == ["slack: skipped, webhook URL resolves to a non-public address; "
|
|
88
|
+
"set BRICKSENTRY_ALLOW_PRIVATE_URLS=1 if that is intended"]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_github_api_must_be_public_https(monkeypatch):
|
|
92
|
+
monkeypatch.setenv("GITHUB_REPOSITORY", "o/r")
|
|
93
|
+
monkeypatch.setenv("GITHUB_TOKEN", "t")
|
|
94
|
+
with pytest.raises(netguard.UnsafeURLError):
|
|
95
|
+
github.upsert_pr_comment("x", pr=1, api="https://127.0.0.1:9/api")
|
|
96
|
+
with pytest.raises(netguard.UnsafeURLError):
|
|
97
|
+
github.upsert_pr_comment("x", pr=1, api="http://api.github.com")
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""0.1.23: exact totals, one-to-one matching of duplicated keys, and an audit trail
|
|
2
|
+
on every assessment."""
|
|
3
|
+
|
|
4
|
+
from bricksentry import Config, Sentry, __version__
|
|
5
|
+
from bricksentry.backends.databricks_backend import DatabricksBackend
|
|
6
|
+
from bricksentry.diff import diff_tables
|
|
7
|
+
from bricksentry.lineage import StaticLineage
|
|
8
|
+
from bricksentry.models import Assessment
|
|
9
|
+
from bricksentry.policy import Policy
|
|
10
|
+
from bricksentry.report import to_markdown
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# --- exact totals ----------------------------------------------------------------
|
|
14
|
+
def test_decimal_totals_are_exact(backend):
|
|
15
|
+
backend.execute("CREATE SCHEMA m")
|
|
16
|
+
backend.execute("CREATE TABLE m.base AS SELECT i AS id, CAST(0.10 AS DECIMAL(18, 2)) AS amount "
|
|
17
|
+
"FROM range(1, 1000001) t(i)")
|
|
18
|
+
backend.execute("CREATE TABLE m.cand AS SELECT * FROM m.base")
|
|
19
|
+
d = diff_tables(backend, "m.base", "m.cand", ["id"])
|
|
20
|
+
amount = d.columns[0]
|
|
21
|
+
# Adding 0.1 a million times as DOUBLE drifts (100000.00000133...); as DECIMAL it doesn't.
|
|
22
|
+
assert amount.base_sum == 100000.0 and amount.candidate_sum == 100000.0
|
|
23
|
+
assert amount.sum_change_pct == 0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_sum_sql_by_type():
|
|
27
|
+
b = DatabricksBackend(warehouse_id="wh", client=object())
|
|
28
|
+
assert b.exact_sum("`a`", "decimal(18,2)") == "SUM(`a`)"
|
|
29
|
+
assert b.exact_sum("`a`", "bigint") == "SUM(CAST(`a` AS DECIMAL(38, 0)))" # no BIGINT overflow
|
|
30
|
+
assert b.exact_sum("`a`", "double") == "SUM(CAST(`a` AS DOUBLE))"
|
|
31
|
+
assert b.row_hash(["a", "b"]) == "xxhash64(`a`, `b`)"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# --- duplicated keys are matched one to one --------------------------------------
|
|
35
|
+
def test_many_null_keys_do_not_multiply(backend):
|
|
36
|
+
backend.execute("CREATE SCHEMA n")
|
|
37
|
+
backend.execute("CREATE TABLE n.base AS SELECT CASE WHEN i <= 2000 THEN NULL ELSE i END AS id, i AS v "
|
|
38
|
+
"FROM range(1, 3001) t(i)")
|
|
39
|
+
backend.execute("CREATE TABLE n.cand AS SELECT * FROM n.base")
|
|
40
|
+
d = diff_tables(backend, "n.base", "n.cand", ["id"])
|
|
41
|
+
# 2,000 NULL keys on each side used to join into 4,000,000 pairs.
|
|
42
|
+
assert (d.added_rows, d.removed_rows, d.changed_rows, d.unchanged_rows) == (0, 0, 0, 3000)
|
|
43
|
+
assert d.null_keys_base == 2000 and d.is_identical
|
|
44
|
+
assert d.notes and "paired one to one" in d.notes[0]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_a_new_copy_of_a_key_counts_as_added(backend):
|
|
48
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders "
|
|
49
|
+
"UNION ALL SELECT order_id, region, amount, status FROM sales.orders WHERE order_id <= 3")
|
|
50
|
+
d = diff_tables(backend, "sales.orders", "sales_ci.orders", ["order_id"])
|
|
51
|
+
assert (d.added_rows, d.removed_rows, d.changed_rows, d.unchanged_rows) == (3, 0, 0, 1000)
|
|
52
|
+
assert d.duplicate_keys_candidate == 3
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_changed_copy_of_a_duplicated_key(backend):
|
|
56
|
+
backend.execute("CREATE SCHEMA k")
|
|
57
|
+
backend.execute("CREATE TABLE k.base AS SELECT * FROM (VALUES (1, 'a'), (1, 'b'), (2, 'c')) t(id, v)")
|
|
58
|
+
backend.execute("CREATE TABLE k.cand AS SELECT * FROM (VALUES (1, 'a'), (1, 'z'), (2, 'c')) t(id, v)")
|
|
59
|
+
d = diff_tables(backend, "k.base", "k.cand", ["id"])
|
|
60
|
+
assert d.base_rows == d.candidate_rows == 3
|
|
61
|
+
assert d.added_rows == d.removed_rows == 0
|
|
62
|
+
assert d.changed_rows == 1 and d.unchanged_rows == 2
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_no_note_without_duplicates(backend):
|
|
66
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
|
|
67
|
+
assert diff_tables(backend, "sales.orders", "sales_ci.orders", ["order_id"]).notes == []
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# --- audit trail ------------------------------------------------------------------
|
|
71
|
+
def _sentry(backend, policy=None):
|
|
72
|
+
cfg = Config.from_dict({"assessment_store": False, "policy": policy,
|
|
73
|
+
"tables": {"sales.orders": {"keys": ["order_id"]}}})
|
|
74
|
+
return Sentry(cfg, backend=backend, lineage=StaticLineage({}))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_assessment_records_when_what_and_who(backend, monkeypatch):
|
|
78
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
|
|
79
|
+
monkeypatch.delenv("GITHUB_ACTOR", raising=False)
|
|
80
|
+
monkeypatch.setenv("BRICKSENTRY_ACTOR", "nightly-orders-job")
|
|
81
|
+
a = _sentry(backend).assess(["sales.orders"], candidates={"sales.orders": "sales_ci.orders"})
|
|
82
|
+
assert a.created_at and a.created_at.endswith("+00:00")
|
|
83
|
+
assert a.bricksentry_version == __version__
|
|
84
|
+
assert a.policy_sha256 == Policy().sha256 and len(a.policy_sha256) == 64
|
|
85
|
+
assert a.triggered_by == "nightly-orders-job"
|
|
86
|
+
|
|
87
|
+
d = a.to_dict()
|
|
88
|
+
assert {"created_at", "bricksentry_version", "policy_sha256", "triggered_by"} <= set(d)
|
|
89
|
+
again = Assessment.from_dict(d)
|
|
90
|
+
assert (again.created_at, again.policy_sha256, again.triggered_by) == (
|
|
91
|
+
a.created_at, a.policy_sha256, "nightly-orders-job")
|
|
92
|
+
|
|
93
|
+
md = to_markdown(a)
|
|
94
|
+
assert f"bricksentry {__version__}" in md and f"policy `{a.policy_sha256[:12]}`" in md
|
|
95
|
+
assert "triggered by nightly-orders-job" in md and " UTC" in md
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_github_actor_and_nobody(backend, monkeypatch):
|
|
99
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
|
|
100
|
+
monkeypatch.delenv("BRICKSENTRY_ACTOR", raising=False)
|
|
101
|
+
monkeypatch.setenv("GITHUB_ACTOR", "octocat")
|
|
102
|
+
a = _sentry(backend).assess(["sales.orders"], candidates={"sales.orders": "sales_ci.orders"})
|
|
103
|
+
assert a.triggered_by == "github:octocat"
|
|
104
|
+
monkeypatch.delenv("GITHUB_ACTOR")
|
|
105
|
+
a = _sentry(backend).assess(["sales.orders"], candidates={"sales.orders": "sales_ci.orders"})
|
|
106
|
+
assert a.triggered_by is None
|
|
107
|
+
assert "triggered by" not in to_markdown(a)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_policy_fingerprint_changes_with_the_rules():
|
|
111
|
+
a = Policy({"rules": [{"name": "x", "when": {"duplicate_keys": True}, "then": "block"}]})
|
|
112
|
+
b = Policy({"rules": [{"name": "x", "when": {"duplicate_keys": True}, "then": "warn"}]})
|
|
113
|
+
c = Policy({"rules": [{"then": "block", "when": {"duplicate_keys": True}, "name": "x"}]}) # same, reordered
|
|
114
|
+
assert a.sha256 != b.sha256
|
|
115
|
+
assert a.sha256 == c.sha256
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_old_saved_assessments_still_load():
|
|
119
|
+
old = {"id": "abc", "verdict": "pass", "tables": [], "notify": []}
|
|
120
|
+
a = Assessment.from_dict(old)
|
|
121
|
+
assert a.created_at is None and a.policy_sha256 is None
|
bricksentry-0.1.21/SECURITY.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Security policy
|
|
2
|
-
|
|
3
|
-
bricksentry runs SQL against your data warehouse and can be called by AI agents, so we take reports seriously.
|
|
4
|
-
|
|
5
|
-
## Reporting a vulnerability
|
|
6
|
-
|
|
7
|
-
Please use GitHub's private vulnerability reporting: open the repository's **Security** tab and choose **Report a vulnerability**. Don't open a public issue for security problems.
|
|
8
|
-
|
|
9
|
-
Especially relevant:
|
|
10
|
-
|
|
11
|
-
- Any way for `preview_write` to modify a table other than its sandbox clone
|
|
12
|
-
- SQL injection through table names, keys or config values
|
|
13
|
-
- Ways for an agent to obtain a `pass` verdict that the policy should not allow
|
|
14
|
-
|
|
15
|
-
You'll get an acknowledgement as soon as possible, and a fix or mitigation plan once the report is confirmed.
|
|
16
|
-
|
|
17
|
-
## Supported versions
|
|
18
|
-
|
|
19
|
-
Only the latest release receives security fixes during the 0.x series.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.21
|
|
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.21 → bricksentry-0.1.23}/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
|
{bricksentry-0.1.21 → bricksentry-0.1.23}/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
|