CHAPTER 10 OF 12
Control access and protect your data
Set trust boundaries, authenticate requests and limit what the model can do.
In this chapter
Local inference is one boundary
Running weights locally can keep inference requests on a machine you control. The surrounding application may still fetch metadata, update software, write logs, sync files or contact external services. Map those paths explicitly. A local chat label should mean the conversation is processed locally, not merely that the interface is installed on your device.
Begin with assets and permissions: model files, personal documents, prompts, outputs, credentials and operational logs. Decide who may read each asset and which process may access it. If a model has no tools, a generated command is just text. If an application automatically runs that command, the application's permissions become part of the threat model.
Authentication answers who may call the service. Authorization answers what that caller may do. Encryption protects data in transit. Rate limits, bounded inputs and concurrency controls help preserve availability. None of these establishes factual accuracy; answer evaluation remains a separate layer.
Keep a small exposed surface
The companion gateway binds only to loopback, requires a bearer token, accepts a bounded prompt, and calls a fixed runtime. It does not accept a caller-supplied backend URL, file path, shell command or model-management operation. It also avoids logging the token and prompt.
This is a teaching gateway, not a production server. It has no public TLS termination, durable abuse controls, organizational identity integration or comprehensive security assessment. For access from another machine, use an explicit private connection such as the SSH tunnel in chapter 9. A public service needs a separate deployment design and verification.
Retrieved documents and web pages are untrusted inputs. Their text must not redefine the application's permissions. Separate content from instructions where possible, but assume a model can still be influenced by embedded text. Validate proposed actions and enforce authorization in ordinary application code.
Prerequisites
Complete the local API chapter. Use fictional prompts for these checks and keep the model server running. The automated access test creates a temporary token in memory and closes its temporary listener when finished.
Steps
Run the access-control checks:
python3 rtm_lab.py security --output access-checks.jsonVerify that a request without credentials receives 401, an authorized health request succeeds, and an oversized body receives 413. The report also preserves the authorized inference answer separately from the access result.
To run the gateway interactively, generate a token in your terminal and start the service:
export RTM_LAB_TOKEN="$(python3 -c \
'import secrets; print(secrets.token_urlsafe(32))')"
python3 rtm_lab.py serveThe server uses port 11436 by default and sends prompts to the configured loopback runtime. Use Control-C to stop it. Clear the terminal variable when finished:
unset RTM_LAB_TOKENInspect where your own client stores the token. Avoid committing it, placing it in URLs, pasting it into screenshots, or logging request headers. If exposed, replace it and invalidate the old one.
Expected results
The automated checks passed in the reference run. They establish the tested HTTP boundaries, not comprehensive security. The gateway should not listen on a public network address. An incorrect extraction answer should remain a task failure even when authentication worked.
Common failures
A reverse proxy can accidentally expose an internal endpoint. A wildcard origin policy can broaden browser access. Error logs can contain sensitive prompts. A retrieved passage can ask for an unrelated action. A bearer token copied into a shared document becomes available to its readers. Address these at the application and deployment layers; asking the model to be careful is insufficient.
For personal documents, document deletion must include derived indexes, cached passages and retained outputs according to your retention rules. Do not promise deletion based only on removing the original file from a visible list.
Exercise
Draw the data path for your application. Mark each location where prompts, documents, outputs or credentials exist. Choose one failure, such as a leaked token or an injected instruction, and describe a test that would show the relevant boundary working.
Sources
The OWASP guidance on prompt injection discusses the instruction/data problem. Python's HTTP server documentation describes the teaching server's limitations. The actual companion checks are preserved in the book evidence.