Self-service mocks
On a public instance mocks are normally read-only: changing one needs the admin token. With self-service on, visitors create and manage their own mocks without an account: drop a spec into the console, get a URL, point a gateway at it. Other visitors cannot see, change or delete those mocks, and the instance's own mocks stay read-only for them.
It is made for a hosted demo, so it comes with a time allowance (one hour, extendable), an optional email step to keep going, a separate domain for the mocks and restrictions on what a visitor's mock may send. It is off by default, also in public mode.
Turning it on
RUSTYBIN_PUBLIC_MODE=true \
RUSTYBIN_CONTROL_AUTH=open \
RUSTYBIN_MOCKS_SELF_SERVICE=true \
RUSTYBIN_MOCKS_SELF_SERVICE_HOST=rustybin-mock.dev \
RUSTYBIN_LEADS_WEBHOOK_URL=https://hooks.example.com/rustybin-leads \
RUSTYBIN_LEADS_WEBHOOK_TOKEN=change-me \
RUSTYBIN_PRIVACY_URL=https://example.com/privacy \
RUSTYBIN_ADMIN_TOKEN=change-me-to-a-long-random-value \
rustybin
Self-service needs public mode (outside it everyone may already manage mocks) and
a control plane visitors can reach: RUSTYBIN_CONTROL_AUTH=open, set on purpose
(public mode still guards global changes with the admin token), the
password sign-in for an operator who signs in, or
shared mode, where API keys own their mocks. With
token or jwt control auth it is ignored with a warning.
Every setting is in Configuration.
An operator who signs in
With the password sign-in, visitors stay anonymous and only the operator has an account:
RUSTYBIN_PUBLIC_MODE=true \
RUSTYBIN_MOCKS_SELF_SERVICE=true \
RUSTYBIN_MOCKS_SELF_SERVICE_HOST=rustybin-mock.dev \
RUSTYBIN_CONSOLE_USER=operator \
RUSTYBIN_CONSOLE_PASSWORD_HASH='$argon2id$v=19$...' \
RUSTYBIN_PRIVACY_URL=https://example.com/privacy \
rustybin
A caller without a credential is a visitor, exactly as on an open control plane, and
holds nothing more. The console opens as a visitor's and has a Sign in button; the
operator signs in there, with the rustybin CLI or with
POST /_rustybin/login, and then holds the whole instance:
# A caller without a credential creates a mock as a visitor...
POST {{signin_url}}/_rustybin/mocks
X-Rustybin-Session: docs-sign-in-visitor
{"spec": "{\"openapi\":\"3.0.3\",\"info\":{\"title\":\"Orders\",\"version\":\"1\"},\"paths\":{\"/orders\":{\"get\":{\"operationId\":\"list\",\"responses\":{\"200\":{\"description\":\"ok\"}}}}}}"}
HTTP 201
[Captures]
visitor_mock: jsonpath "$.name"
[Asserts]
jsonpath "$.manage_token" exists
# ...and reaches nothing that is the operator's.
GET {{signin_url}}/_rustybin/settings
HTTP 401
GET {{signin_url}}/_rustybin/users
HTTP 401
# The operator signs in...
POST {{signin_url}}/_rustybin/login
{"username": "operator", "password": "docs-operator-password"}
HTTP 200
[Captures]
operator_token: jsonpath "$.token"
# ...and holds the instance, a visitor's mocks too.
GET {{signin_url}}/_rustybin/mocks?owner=all
Authorization: Bearer {{operator_token}}
HTTP 200
[Asserts]
jsonpath "$.mocks[0].name" == "{{visitor_mock}}"
GET {{signin_url}}/_rustybin/settings
Authorization: Bearer {{operator_token}}
HTTP 200
Three things differ from an open control plane. A credential that fails is refused
with 401, never treated as a visitor, so a console learns its session ended.
Routes that mean a signed-in caller (/_rustybin/session, /_rustybin/me,
/_rustybin/projects) answer 401 to a visitor. And the
OAuth sign-in for agents is off, because a
stranger's agent reaches /_rustybin/mcp as a visitor and nothing would ask it to
sign in: give an agent a token instead.
The password is the only thing between a stranger and the instance, and the sign-in
throttles by address, so name your proxy's header as
Behind a proxy says, and start with the hash (rustybin password hash) rather than
the password. The default password refuses to start in public mode.
The examples on this page run against a documentation instance with the mocks
domain mocks.example, 10 minute periods (so Extend is open at once) and one
anonymous visit per session.
A visit and its manage token
The first mock a visitor creates starts a visit and answers with a
manage_token (rbm_ and 160 random bits), shown once. The server keeps only
its SHA-256. Every later call that manages the visitor's mocks sends it as
X-Rustybin-Mock-Token:
POST {{ss_url}}/_rustybin/mocks
X-Rustybin-Session: docs-visitor-a
{
"spec": {
"openapi": "3.0.3",
"info": {"title": "Orders", "version": "1"},
"paths": {
"/orders/{id}": {"get": {"operationId": "getOrder",
"parameters": [{"name": "id", "in": "path", "required": true, "schema": {"type": "integer"}}],
"responses": {"200": {"description": "ok", "content": {"application/json": {
"schema": {"type": "object", "properties": {"id": {"type": "integer"}}}}}}}}},
"/receipt": {"get": {"operationId": "getReceipt",
"responses": {"200": {"description": "ok", "content": {"text/html": {"example": "<h1>Thanks</h1>"}}}}}}
}
}
}
HTTP 201
[Captures]
mock_token: jsonpath "$.manage_token"
mock_name: jsonpath "$.name"
[Asserts]
jsonpath "$.name" matches /^orders-[a-z2-7]{6}$/
jsonpath "$.owner" == "visit"
jsonpath "$.manage_token" startsWith "rbm_"
jsonpath "$.url" contains ".mocks.example"
jsonpath "$.visit.expires_in_secs" >= 595
jsonpath "$.visit.next_extension" == "free"
- The name is the slug the visitor picked (default: from
info.title, at most 33 characters) plus a random six character suffix, so mock names are not guessable and nobody can take a name someone else is using. - More mocks from the same token join the visit, up to three per visitor
(
RUSTYBIN_MOCKS_PER_OWNER). statefulmode is off for visitors: their mocks answer from the spec only, never with data callers sent. It stores what callers send, the closest thing here to free file hosting, so it takesRUSTYBIN_MOCKS_SELF_SERVICE_STATEFUL=true, and then a visitor's mock keeps at most 50 items and 64 KiB, in memory, for as long as the mock lives.- Visitor mocks cannot be renamed.
Anyone may call the mock's URL (that is the point). Everything else about it belongs to its owner: for another caller it does not exist.
GET {{ss_url}}/_rustybin/mocks/{{mock_name}}
HTTP 404
GET {{ss_url}}/_rustybin/mocks/{{mock_name}}
X-Rustybin-Mock-Token: {{mock_token}}
HTTP 200
[Asserts]
jsonpath "$.can_manage" == true
jsonpath "$.yours" == true
The console keeps the token in the browser's local
storage, so visitors never handle it. Copy manage link gives a URL with the
token in the fragment (/ui/#/mocks&mock_token=..., never sent to the server) to
open the mocks in another browser or hand them to a teammate.
POST /_rustybin/mocks/visit/token replaces the token (old links stop working).
Time
The clock belongs to the visit: all of a visitor's mocks share one expiry, and Extend moves it for all of them.
| Step | Default | Setting |
|---|---|---|
| A visit starts with | 1 hour | RUSTYBIN_MOCKS_VISIT_MINUTES (also the length of each extension) |
| Extend, without an email address, up to | 3 hours | RUSTYBIN_MOCKS_ANON_HOURS |
| Extend with an email address, up to | 6 hours per UTC day | RUSTYBIN_MOCKS_DAILY_HOURS |
| Anonymous visits per session and UTC day | 3 | RUSTYBIN_MOCKS_ANON_VISITS_PER_DAY |
- Extend opens 15 minutes before the visit ends, one period at a time.
- The hours of a day count per email address, including the anonymous hours of the visit that gave it. An address used up today cannot start another visit until midnight UTC.
- When a visit ends, its mocks and their traffic are deleted.
- The session (
X-Rustybin-Session, else the client IP) limits anonymous visits. That is a speed bump, not protection: the instance-wide caps below are.
GET {{ss_url}}/_rustybin/mocks/visit
X-Rustybin-Mock-Token: {{mock_token}}
HTTP 200
[Asserts]
jsonpath "$.minutes_used" == 10
jsonpath "$.minutes_allowed" == 60
jsonpath "$.extendable" == true
jsonpath "$.mocks" count == 1
jsonpath "$.mock_cap" == 3
POST {{ss_url}}/_rustybin/mocks/visit/extend
X-Rustybin-Mock-Token: {{mock_token}}
HTTP 200
[Asserts]
jsonpath "$.minutes_used" == 20
jsonpath "$.expires_in_secs" >= 1190
When the free time is used, Extend answers 403 rustybin_email_required; the same
happens when a session that used its anonymous visits creates a mock without a
token. The answer carries the privacy notice link and the consent mode for the
form:
POST {{ss_url}}/_rustybin/mocks
X-Rustybin-Session: docs-visitor-a
{"spec": {"openapi": "3.0.3", "info": {"title": "Second", "version": "1"}, "paths": {}}}
HTTP 403
[Asserts]
jsonpath "$.error" == "rustybin_email_required"
jsonpath "$.privacy_url" == "https://example.com/privacy"
jsonpath "$.consent" == "checkbox"
The visitor then sends the address with Extend
({"email": "...", "marketing_consent": true}), or starts a visit with it:
POST {{ss_url}}/_rustybin/mocks/visit
X-Rustybin-Session: docs-visitor-a
{"email": "ada@example.com", "marketing_consent": true}
HTTP 201
[Captures]
second_token: jsonpath "$.manage_token"
[Asserts]
jsonpath "$.visit.email_given" == true
jsonpath "$.visit.minutes_allowed" == 360
| Answer | When |
|---|---|
409 rustybin_extend_too_early | More than 15 minutes left (extendable_at says when) |
403 rustybin_email_required | The next period needs an email address |
429 rustybin_daily_limit | The address used today's hours (resets_at, Retry-After) |
429 rustybin_visit_limit | The free time is used and email capture is off |
409 rustybin_mock_cap | The visitor already has the most mocks allowed |
503 rustybin_mocks_busy | The instance holds as many visits or visitor mocks as it may (Retry-After) |
429 rustybin_mocks_rate_limited | Mocks created too fast (Retry-After) |
503 rustybin_self_service_paused | An operator paused self-service |
The come-back answers carry self_host_url, a link to running your own Rustybin,
which has none of these limits.
The email step and leads
Email capture is on when Rustybin has somewhere to deliver the address
(RUSTYBIN_LEADS_WEBHOOK_URL and/or RUSTYBIN_LEADS_FILE) and a privacy
notice to link (RUSTYBIN_PRIVACY_URL). Without it a visit simply ends after the
anonymous hours.
-
The form (console) has one email field, a separate unticked "Send me product news" checkbox and a line with the privacy notice. Giving the address unlocks more time; the checkbox is the marketing consent.
RUSTYBIN_LEADS_CONSENT=noticedrops the checkbox where a notice is enough; confirm the wording with whoever handles your legal side. -
Delivery: Rustybin
POSTs each address to the webhook as JSON, withAuthorization: Bearer $RUSTYBIN_LEADS_WEBHOOK_TOKENwhen set, so any automation tool or CRM endpoint can take it:{"email": "ada@example.com", "marketing_consent": true, "consent_mode": "checkbox", "source": "mock_extend", "captured_at": "2026-10-18T10:00:00Z", "visit_minutes": 240, "mocks": ["orders-k3f9q2"]}Failed deliveries are retried with backoff for an hour from a bounded queue (1,000 leads);
RUSTYBIN_LEADS_FILEappends the same JSON, one line per lead. -
Privacy: the address is never logged, captured in traffic or the inspector, exported or counted with a label. The daily ledger keeps only a salted hash (
RUSTYBIN_LEADS_SALT; generated at startup when unset, so set it to keep daily counts across restarts), andGET /_rustybin/mocks/visitonly saysemail_given. -
Addresses are not verified; your mailing tool's double opt-in can do that.
The mocks domain
A visitor controls the bodies and headers of their mock, so visitor mocks should
not share a site with the console or your main domain. Set
RUSTYBIN_MOCKS_SELF_SERVICE_HOST to a separate registrable domain (not a
subdomain of your site, which browsers treat as the same site and reputation
systems such as Safe Browsing can flag together with it):
GET {{ss_url}}/orders/7
Host: {{mock_name}}.mocks.example
HTTP 200
[Asserts]
jsonpath "$.id" == 7
header "X-Content-Type-Options" == "nosniff"
header "Content-Security-Policy" contains "sandbox"
<name>.<domain>/<path>is served by that mock; the served spec names that URL as its server.- The domain serves nothing else: the console, the control plane and every other
route answer
404there. The bare domain redirects toRUSTYBIN_MOCKS_SELF_SERVICE_HOME(else404). - On the main host,
/mock/<name>of a visitor mock answers404with the right URL, and so do its served spec (/mock/<name>/_rustybin/openapi.json,.yaml) and its MCP server. Instance mocks keep working on both. - Hosts are compared without a trailing dot:
rustybin-mock.dev.is the mocks domain likerustybin-mock.dev.
GET {{ss_url}}/mock/{{mock_name}}/orders/7
HTTP 404
[Asserts]
jsonpath "$.url" == "https://{{mock_name}}.mocks.example"
GET {{ss_url}}/_rustybin/mocks
Host: {{mock_name}}.mocks.example
HTTP 404
DNS and TLS (for example on Cloudflare): a proxied wildcard record
*.rustybin-mock.dev and the apex pointing at the instance; Cloudflare's edge
certificate covers the apex and the first-level wildcard; give the origin a
certificate for *.rustybin-mock.dev too (an origin certificate or ACME DNS-01)
and use SSL mode "Full (strict)". Set RUSTYBIN_TRUST_FORWARD=true behind the
proxy so sessions see client addresses.
Without a mocks domain, visitor mocks are served under /mock/<name> on the main
host with the same restrictions: fine for trying it out, not for a public demo.
What visitor mocks cannot send
Whatever the spec or the settings say, every response of a visitor mock:
- carries
X-Content-Type-Options: nosniff,X-Frame-Options: DENYandContent-Security-Policy: sandbox; default-src 'none'; frame-ancestors 'none'; - never sets
Set-Cookie, Content-Security-Policy, HSTS,Clear-Site-DataorAccess-Control-Allow-Credentials, and never redirects to another host (Location,RefreshandContent-Locationare dropped when a browser would leave the domain: an absolute URL,//host, or/\hostand\/host, since browsers read\as/; tabs and newlines are ignored as browsers do); - serves only inert media types: JSON (
*+json), XML, YAML, CSV, plain text,application/octet-streamand form data. HTML, SVG, JavaScript and anything else go out astext/plain.
GET {{ss_url}}/receipt
Host: {{mock_name}}.mocks.example
HTTP 200
[Asserts]
header "Content-Type" == "text/plain; charset=utf-8"
body == "<h1>Thanks</h1>"
Dropped headers and media types show up as warnings in the deploy report; configured headers that would be dropped are refused when saving.
Whose traffic a caller reads
A captured request holds what its sender presented, credentials included, so on a
shared instance a mock that belongs to nobody in particular (the built-in petstore,
any instance mock) shows each caller its own calls:
- a caller without a credential on a public instance reads the calls of its own
session (
X-Rustybin-Session, else its address); - an API key in shared mode reads its own calls;
- the operator, and anyone signed in with
traffic.read, reads all of them; - a visitor's own mock is read by its owner, who reads every call to it, whoever sent it (a gateway in front of the mock, for example).
This holds on every way in: the requests list, one request by number, the live feed,
the rule tester and the get_mock_traffic and wait_for_requests tools. A call that
comes through a gateway keeps your session only if the gateway forwards
X-Rustybin-Session, and a call through a mock's own MCP server carries your address.
GET {{ss_url}}/mock/petstore/v1/pets/1
X-Rustybin-Session: docs-visitor-c
Authorization: Bearer a-credential-of-visitor-c
HTTP 200
GET {{ss_url}}/_rustybin/mocks/petstore/requests
X-Rustybin-Session: docs-visitor-c
HTTP 200
[Asserts]
jsonpath "$.total" == 1
jsonpath "$.requests[0].path" == "/v1/pets/1"
GET {{ss_url}}/_rustybin/mocks/petstore/requests
X-Rustybin-Session: docs-visitor-d
HTTP 200
[Asserts]
jsonpath "$.total" == 0
jsonpath "$.requests" count == 0
Behind a proxy
Every limit here counts the client's address, so the instance must learn it from something a client cannot write. Behind a proxy, have the proxy set one header from the address it verified, and name that header. With Caddy:
reverse_proxy rustybin:8080 {
header_up X-Real-IP {client_ip}
}
and RUSTYBIN_TRUST_FORWARD=true, RUSTYBIN_TRUST_FORWARD_HEADER=x-real-ip. With only
RUSTYBIN_TRUST_FORWARD, every forwarding header is believed, so a visitor who sends
Fly-Client-IP or Forwarded chooses the address the limits count, and behind a CDN
X-Forwarded-For ends in the CDN's address, which all its visitors would share. The
instance warns at startup and GET /_rustybin/diagnostics reports client_address.
Limits
| What | Default | Setting |
|---|---|---|
| Mocks per visitor (or API key) | 3 | RUSTYBIN_MOCKS_PER_OWNER |
| Visitor mocks on the instance | 200 | RUSTYBIN_MOCKS_SELF_SERVICE_MAX |
| Memory all visitor mocks hold together | 192 MiB | RUSTYBIN_MOCKS_SELF_SERVICE_MAX_MB |
| Running visits | twice the visitor mock cap | |
| Creations per session per hour | 10 | RUSTYBIN_MOCKS_CREATE_PER_HOUR |
| Creations on the instance per minute | 30 | |
| Blocked names | none | RUSTYBIN_MOCKS_BLOCKED_NAMES (comma separated globs, *paypal*,login*) |
Visits and creations are counted per client address and session: visitors behind one address keep their own counts, up to 20 sessions per address per day; past that the address's new sessions share one count, so a new session header per request starts nothing new. Spec compiles are limited to 30 a minute per visitor, and per address before a visit has started (see Limits). Spec size, operations, rules, revisions and captured calls follow the public mode limits. A full instance never evicts someone else's mocks.
The memory budget counts what each revision a visitor's mocks keep holds, measured from
the document and not from its size on disk: a spec of a few hundred kilobytes can take
tens of megabytes. Past the budget a new mock or an edit answers 503 until visits end.
Set it to about a third of the memory you give the instance. A visitor mock's MCP tools
also expand a limited amount of schema between them, and the deploy report keeps a
limited amount of generated request bodies, so a large spec keeps every tool, with the
last schemas marked as not expanded, and an operation's detail still shows its whole
sample request.
Operators
With admin rights (RUSTYBIN_ADMIN_TOKEN, or signed in):
GET {{ss_url}}/_rustybin/mocks/visits
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.count" == 2
jsonpath "$.visitor_mocks" == 1
jsonpath "$.visits[0].owner" startsWith "v:"
| Route | |
|---|---|
GET /_rustybin/mocks?owner=all | Every mock, with owner_fingerprint for visitor mocks (without owner=all, admins see the instance's mocks and their own) |
GET /_rustybin/mocks/visits | Running visits: id, fingerprint, times, minutes granted, whether an email was given, mocks |
DELETE /_rustybin/mocks/visits/{id} | End one visit and delete its mocks |
DELETE /_rustybin/mocks/visits | End every visit |
POST /_rustybin/mocks/visits/pause and /resume | Stop (or allow again) new visits and visitor mocks; running visits keep their time |
POST {{ss_url}}/_rustybin/mocks/visits/pause
Authorization: Bearer {{admin_token}}
HTTP 200
POST {{ss_url}}/_rustybin/mocks
X-Rustybin-Mock-Token: {{second_token}}
{"spec": {"openapi": "3.0.3", "info": {"title": "Third", "version": "1"}, "paths": {}}}
HTTP 503
[Asserts]
header "Retry-After" exists
jsonpath "$.error" == "rustybin_self_service_paused"
POST {{ss_url}}/_rustybin/mocks/visits/resume
Authorization: Bearer {{admin_token}}
HTTP 200
Admins can change or delete any mock. The metrics
include rustybin_mock_visits, rustybin_mock_visit_events_total{event} and
rustybin_mock_leads_total{result} (never an address); per-mock request series
stay off in public mode. Visit starts, extensions and endings are logged with the
owner fingerprint, never the token or the address.
A visitor can end their own visit (and delete its mocks) at once:
DELETE {{ss_url}}/_rustybin/mocks/visit
X-Rustybin-Mock-Token: {{mock_token}}
HTTP 200
[Asserts]
jsonpath "$.ended" == true
jsonpath "$.deleted" count == 1
Shared mode
In shared mode a mock created with an API key belongs to that key: no manage token, no visit clock (the key's plan limits apply), the same per-owner cap and response restrictions. Calls to the mock need a key, like every data-plane request in shared mode.
Restarts and replicas
With RUSTYBIN_MOCKS_STATE_DIR, visitor mocks are saved with their owner, and
visits and the day's ledger in _visits.json, so a restart keeps visits running;
mocks of visits that ended meanwhile are deleted on load. Captured traffic and
email addresses are never saved: the ledger keeps salted hashes of addresses. It
does keep each visit's session key, which is the client IP when the visitor sends no
X-Rustybin-Session, to count anonymous visits per day.
Visits live in memory on one instance. Run a self-service demo as a single instance, or route every request for a mock (its host on the mocks domain) to the same replica.
Routes
| Route | Who | |
|---|---|---|
POST /_rustybin/mocks | anyone | Create a mock (starts a visit without a token) |
GET /_rustybin/mocks/visit | the visitor | The visit: expires_at, extendable, next_extension (free, email, allowance or none), minutes used and allowed, email_given, mocks |
POST /_rustybin/mocks/visit | anyone | Start a visit, optionally with {"email", "marketing_consent"} |
POST /_rustybin/mocks/visit/extend | the visitor | One more period (optionally with the email step) |
POST /_rustybin/mocks/visit/token | the visitor | A new manage token |
DELETE /_rustybin/mocks/visit | the visitor | End the visit, delete its mocks |
Every /_rustybin/mocks/{name}* route | the owner, admins | As for any mock |
On every surface
The same job from the API, the console, the command line, an agent and the configuration document.
| Surface | Where |
|---|---|
| API | The routes above and the operator routes |
| Console | The mocks view with the visit banner, Extend and Copy manage link |
| CLI | rustybin visit get | start | extend | rotate-token | end (with --mock-token), rustybin visits list | end | end-all | pause | resume (reference) |
| Management MCP | get_visit, extend_visit, list_visits, end_visit, pause_self_service, resume_self_service; a new manage token is console or CLI only (a credential shown once) (agent page) |
rustybin.yaml | None: visits and visitor mocks belong to their visitors, never to the instance document |
| Environment | RUSTYBIN_MOCKS_SELF_SERVICE*, RUSTYBIN_MOCKS_* and RUSTYBIN_LEADS_* (configuration) |