bricksentry 0.1.21__tar.gz → 0.1.22__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.22}/CHANGELOG.md +9 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/PKG-INFO +2 -2
- {bricksentry-0.1.21 → bricksentry-0.1.22}/README.md +1 -1
- bricksentry-0.1.22/SECURITY.md +31 -0
- bricksentry-0.1.22/deploy/container/Dockerfile +29 -0
- bricksentry-0.1.22/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/pyproject.toml +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.22}/server.json +2 -2
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/cli.py +4 -2
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/github.py +2 -1
- bricksentry-0.1.22/src/bricksentry/netguard.py +79 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/notify.py +6 -3
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/databricks_template_schema.json +2 -2
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_0121.py +1 -1
- bricksentry-0.1.22/tests/test_0122.py +97 -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.22}/.gitignore +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/LICENSE +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/action.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/scripts/render_demo_image.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/assess.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/backends/databricks_backend.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/diff.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/history.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/job.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/job_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/models.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/policy.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/conftest.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_0110.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_0112.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_0114.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_0120.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_018.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_019.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_demo.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_diff.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.21 → bricksentry-0.1.22}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.22 (2026-11-15)
|
|
4
|
+
|
|
5
|
+
Security hardening, following a review on the Canopii MCP Trust Index:
|
|
6
|
+
|
|
7
|
+
- **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.
|
|
8
|
+
- **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.
|
|
9
|
+
- `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.
|
|
10
|
+
- `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.
|
|
11
|
+
|
|
3
12
|
## 0.1.21 (2026-11-13)
|
|
4
13
|
|
|
5
14
|
- `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,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.22
|
|
4
4
|
Summary: Change-safety for Databricks 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
|
|
@@ -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
|
|
|
@@ -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
|
|
|
@@ -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.22
|
|
@@ -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.22"
|
|
8
8
|
description = "Change-safety for Databricks 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.22",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.22",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -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:
|
|
@@ -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
|
|
|
@@ -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())
|
{bricksentry-0.1.21 → bricksentry-0.1.22}/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.22",
|
|
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.22.",
|
|
93
93
|
"order": 10
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -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")
|
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.22}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.21 → bricksentry-0.1.22}/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
|
{bricksentry-0.1.21 → bricksentry-0.1.22}/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
|