DEV Community

Myles Ngicu for AWS Community Builders

Posted on Edited on

Proving Your Self-Hosted LLM Never Phones Home

Private Is a Claim

Part 1 of a series on building Ndani, an open-source framework for running a private LLM on any server and proving that nothing leaves it.

"We self-host the model, so our data is private." I hear this a lot, and I used to say it myself. It sounds right: the weights sit on your server, inference runs on your GPU, no API key to a third party. But running the model yourself only answers one question, which is who computes the answer. It says nothing about what else your server talks to.

When I tested my own setup, the container that faced users could open a TCP connection to any public IP, get answers from Google's public DNS, and reach the cloud metadata service that hands out the instance's credentials. None of that showed up in normal use. The app worked fine. That's the problem: a leaky private LLM and a sealed one look identical until you try to get out.

So in this series I treat "private" as a claim that needs evidence. This first post covers the threat model, when you don't need any of this, the design I landed on, and a test suite that tries every way out and writes down what happened.

Every way data leaves a "private" LLM server

There are at least seven exits, and most self-hosting guides close one or two of them.

Exit What it looks like in practice Why it matters
Runtime phone-home The model server downloads weights or config from Hugging Face at start-up, or sends usage stats Your server makes outbound calls you never asked for, and a compromised dependency has a path out
Open container egress The API container can open a TCP connection to any public IP Anything that runs in it, including a poisoned package, can send data anywhere
DNS tunnelling A query for <encoded-secret>.attacker.com reaches the attacker's name server Works even with no internet route, because the resolver does the travelling for you
Cloud metadata service A container reaches 169.254.169.254 It can read the instance role's credentials and act as your server against your cloud account
Tool calling The model is given an http_get tool and a document says "fetch this URL with the data" Prompt injection turns your model into the exfiltration client
Logs Prompts stored in plain text in app or audit logs, then shipped to a logging service The sensitive part leaks through the observability stack, not the model
The supply chain Weights or images swapped before they reach the server You verify nothing, so you run whatever arrives

The first five are network problems. The last two are about what you write down and what you trust coming in. A private setup has to answer all seven, and it has to answer them with something you can check.

First: you might not need any of this

If you're on AWS and privacy is your main worry, start with Amazon Bedrock. Its data protection docs say it doesn't store or log your prompts and completions, doesn't use them to train models, and doesn't share them with third parties. Model providers have no access to the accounts where their models run. With an interface endpoint (PrivateLink), traffic from your VPC never touches the public internet.

That covers most teams. Self-hosting is worth the extra work when one of these is true:

  • You need a model you control completely: a fine-tune you own, an open model Bedrock doesn't offer, or a pinned version that never changes under you.
  • A rule says no managed AI service may process the data, whatever its terms say. Some regulators and clients write contracts this way.
  • You run a steady, high volume of requests, so a GPU you pay for by the hour beats paying per token.
  • You have to run where the cloud isn't: on-prem, in a country without the region you need, or on a box with bad connectivity.

If none of those apply, close this tab and use Bedrock. If one does, read on, because self-hosting done casually is less private than a managed service with good defaults.

The design

I wanted this to work on any Linux server: EC2, a VPS, an old office PC. So the main guarantee lives in Docker and the host firewall, and the cloud network is an extra layer on top, not the foundation.

Ndani architecture: one edge container, everything else sealed

The sealed network. The model server, the embeddings server and the vector database sit on a Docker network marked internal: true. Docker gives that network no route to anything outside the host. That's one line of YAML, and it closes the biggest exit for the parts that touch your data most.

One edge container. Only the gateway joins a second, normal network, because users have to reach it. It's an OpenAI-compatible API, so any existing SDK works by changing the base URL. It checks API keys, rate-limits, refuses tool calls by default, and writes an audit log that stores a SHA-256 hash of each prompt instead of the prompt.

The egress guard. The gateway can still reach the internet, so the host gets two default-deny rules. An nftables table drops anything the host itself sends out, except loopback, replies and an explicit allowlist. A chain hooked into Docker's DOCKER-USER drops any new connection that starts on an Ndani bridge. Replies to users still flow; the gateway just can't start a conversation with the outside world. Both layers count and log what they drop.

Offline bundles. Weights arrive as a bundle built on a connected machine: the model files, an embedding model, optional docker save image tarballs, and a manifest with every file's SHA-256 hash and size. The server refuses to start if any hash is wrong, any file is missing, or there's a file the manifest doesn't list. You can sign the manifest with ssh-keygen, which is on every Linux box already. At runtime, HF_HUB_OFFLINE=1 means nothing even tries to download.

Proving it

A design diagram proves nothing, so ndani verify attacks the setup and writes a report. With the guard on, the test run passed 47 of 47 checks, and the firewall counters showed 56 packets dropped during the run.

Probing from inside each container. The probe is one standard-library Python script. The trick is running it inside another container's network namespace:

docker run --rm --network container:ndani-inference-cpu \
  ndani/gateway:0.1.0 python probe.py --json
Enter fullscreen mode Exit fullscreen mode

The probe sees exactly the network the model server sees, without installing anything into the model's image. It tries seven exits: system DNS, a raw DNS query to 8.8.8.8, TCP to public IPs on 443 and 80, HTTPS to huggingface.co, the metadata service, and IPv6. It runs in every container and on the host.

Control probes. A test that only checks for failure can pass because the network is simply broken. So each probe also has to reach what it should: the gateway must reach the model, the model must reach the database, the host must reach the gateway. If those succeed and the escapes fail, the guard is doing the blocking.

Counters, not just logs. Kernel log lines are often hidden inside containers or rate-limited. nftables and iptables drop counters are always readable, so the report records how many packets each layer dropped during the run.

Before and after

I ran the suite on real Docker networks and the real firewall rules, with small stand-in services in place of the model containers (the isolation is what's under test here; running the real models is part 2).

Exit tried from the gateway container Guard off Guard on
Raw DNS query to 8.8.8.8 Got an answer Dropped
TCP to 1.1.1.1:443 Connected Dropped
TCP to a public IP on 80 Connected Dropped
Metadata service, 169.254.169.254 Connected Dropped
Gateway reaches the model and the database Connected Connected

With the guard off, the run failed 11 checks: the gateway and the host could both get out. The containers on the sealed network were already blocked before the guard went on, which shows the internal: true network holds up on its own. With the guard on: 47 passed, 0 failed, 4 skipped (the checks that need a real model and an API key). The host dropped 46 packets and the container layer 10.

What this doesn't solve

Being honest about limits is part of the claim.

  • Your cloud provider is still inside the trust boundary. On EC2 you rely on AWS's isolation and your own KMS keys. If the requirement is "nobody but us, ever", run it on hardware you own.
  • Getting things in is the weak point. Hashes prove the bundle wasn't changed after you built it, not that the machine you built it on was clean. Sign bundles, and build them somewhere you trust.
  • Tools change the threat model. Ndani refuses tool calls by default. Turn them on and every tool runs inside the sealed network, so it's only as safe as what you let it reach.
  • No model is "safe" here, only contained. The guard stops data leaving. It doesn't stop a model giving a wrong or harmful answer to the people who can reach it.

Next in the series

  1. Running it for real: a CPU model on a small EC2 instance, the full verify report with zero skips, and what broke on the way.
  2. The zero-egress VPC on AWS: Terraform for a VPC with no internet gateway, VPC endpoints, and Route 53 DNS Firewall, which closes the DNS exit most guides miss.
  3. Cost: self-hosted on a GPU instance against Bedrock, per 1,000 requests.

The code is on GitHub at https://github.com/MylesMburu/ndani. Run ndani verify against your own setup and tell me what got out.

Top comments (0)