ckharche commited on
Commit
c4c0122
·
verified ·
1 Parent(s): e836c50

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +42 -0
  2. README.md +21 -5
Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Space: Postgres 17 and SafeSQL in one container.
2
+ #
3
+ # The Space repo only needs this file and README.md. The build clones the public GitHub
4
+ # repo, so "Factory rebuild" in the Space settings picks up the latest main. The Spider
5
+ # data and fixtures are loaded at build time; the server only ever gets the read-only
6
+ # role, whose password is generated during the build.
7
+ FROM postgres:17-bookworm
8
+
9
+ RUN apt-get update \
10
+ && apt-get install -y --no-install-recommends python3 python3-venv git ca-certificates \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Spaces run the container as uid 1000.
14
+ RUN useradd -m -u 1000 user
15
+ USER user
16
+ ENV HOME=/home/user \
17
+ PATH=/home/user/venv/bin:/usr/lib/postgresql/17/bin:$PATH \
18
+ PGDATA=/home/user/pgdata \
19
+ PGSOCKETS=/home/user/run \
20
+ PYTHONUNBUFFERED=1
21
+ WORKDIR /home/user
22
+
23
+ ARG REPO=https://github.com/ChaitanyaKharche/SafeSQL-MCP.git
24
+ ARG REF=main
25
+ RUN git clone --depth 1 --branch "$REF" "$REPO" app \
26
+ && python3 -m venv venv \
27
+ && venv/bin/pip install --no-cache-dir ./app
28
+
29
+ # Bake the database into the image. Admin access is over the local socket only; the
30
+ # server connects over TCP as the read-only role.
31
+ RUN mkdir -p "$PGSOCKETS" \
32
+ && python3 -c "import secrets; print(secrets.token_urlsafe(24))" > .reader_pw \
33
+ && initdb -U postgres --auth-local=trust --auth-host=scram-sha-256 -E UTF8 --locale=C >/dev/null \
34
+ && pg_ctl -o "-c listen_addresses='' -k $PGSOCKETS" -w start >/dev/null \
35
+ && cd app \
36
+ && SAFESQL_ADMIN_URL="postgresql://postgres@/safesql?host=$PGSOCKETS" SAFESQL_READER_PASSWORD="$(cat ../.reader_pw)" \
37
+ safesql setup-db --load evals/fixtures/spider_dev.sql.gz \
38
+ && pg_ctl -m fast -w stop >/dev/null
39
+
40
+ EXPOSE 7860
41
+ ENTRYPOINT []
42
+ CMD ["sh", "/home/user/app/deploy/huggingface/start.sh"]
README.md CHANGED
@@ -1,10 +1,26 @@
1
  ---
2
- title: SafeSQL
3
- emoji: 👀
4
- colorFrom: green
5
- colorTo: yellow
6
  sdk: docker
 
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: SafeSQL-MCP
3
+ emoji: 🛡️
4
+ colorFrom: blue
5
+ colorTo: gray
6
  sdk: docker
7
+ app_port: 7860
8
  pinned: false
9
+ license: mit
10
+ short_description: A text-to-SQL MCP server an AI agent can't break
11
  ---
12
 
13
+ # SafeSQL-MCP: try to break it
14
+
15
+ A text-to-SQL MCP server for Postgres. Every query an agent writes is parsed into a syntax
16
+ tree, checked against allowlists, cost-checked with `EXPLAIN` and run read-only under a
17
+ read-only role. On this page you can type any SQL, or fire one of the 132 attacks from the
18
+ CI suite, and see which layer stops it.
19
+
20
+ - **Playground:** the page above. It runs your SQL through the same guard as the MCP tools.
21
+ - **MCP endpoint:** `https://<this-space>.hf.space/mcp` (streamable HTTP). Connect Claude Code,
22
+ Claude Desktop or Cursor and ask questions about the Spider `world_1` database.
23
+ - **Source, evals and CI gate:** https://github.com/ChaitanyaKharche/SafeSQL-MCP
24
+
25
+ Data: [Spider](https://yale-lily.github.io/spider) (Yu et al., 2018; CC BY-SA 4.0), ported to
26
+ Postgres, plus a synthetic shop table with planted prompt injections.