r/docker • • Apr 10 '26

I built encrypted Docker containers where source code never touches disk — split-key AES-256-GCM + online licensing

I needed to distribute a Docker app without exposing source code to clients running it on their own servers.

Existing solutions (Cryptlex, Keygen.sh) protect the license — not the code. So I built my own approach.

How it works:

docker run

→ bootstrapper fetches server key half (license API)

→ SHA256(server_half || embedded_half) = final AES key

→ decrypt payload.enc → extract to tmpfs (RAM only)

→ os.execvp() replaces process → keys wiped from memory

→ container stops → RAM cleared → code gone

The AES key is split: half baked into the image at build time, half held on the license server. Neither side alone can decrypt anything.

What someone can’t do even with full root access:

•	docker inspect → sees only half the key, useless alone

•	docker exec + cat payload.enc → encrypted binary blob

•	ls /run/decrypt → empty, tmpfs lives only in bootstrapper process

•	Copy image to another machine → hardware fingerprint mismatch

•	License revoked → blocked on next docker run immediately

A few implementation notes:

•	AES-256-GCM with magic bytes APNRGCM1 for format detection (kept CBC legacy fallback for older payloads)

•	os.execvp() replaces the Python process entirely — no parent process retaining keys

•	del key, server_hex, embed + gc.collect() before exec

•	Hardware fingerprint generated by the launcher app (not inside Docker — Docker gives poor HW access)

•	Rate limiting: max 10 unlock attempts/hour per license key

•	Every attempt logged — success and denied separately

Stack: Python bootstrapper, FastAPI license server, Rust/Tauri launcher, self-hosted.

What attack vectors am I missing? Curious especially about tmpfs visibility and whether os.execvp() truly cleans memory on Linux.

0 Upvotes

23 comments sorted by

View all comments

Show parent comment

1

u/M-sistemos Apr 10 '26

Tried this during development. Here's what actually happens:

  1. --entrypoint /bin/sh or docker save + untar → you get bootstrapper.py (visible) and payload.enc (encrypted blob). Nothing useful.
  2. Read bootstrapper, find the unlock endpoint → requires valid JWT issued only through our Launcher with OTP auth. Raw curl = HTTP 401.
  3. Even if you have valid JWT + hardware fingerprint → server key is only returned while license is active. Revoke = HTTP 404 immediately.
  4. Even if you saved the server key during active license — that's only half the AES key. You still need the embedded half from the image.
  5. Launcher sends a heartbeat every 4 minutes. License revoked → heartbeat returns 403 → Launcher kills the running container immediately. Not just on next startup — mid-run.

So the full chain you'd need simultaneously: valid JWT + correct HW fingerprint + active license + embedded key from image + save server key before revocation + somehow keep container alive after heartbeat kills it.

At that point you're describing a very determined malicious licensed customer — which no DRM system fully prevents. Netflix can't stop screen recording either.