> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formation.texturehq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Blob broker protocol

> A store-neutral boundary for keeping an install's objects without giving it a storage credential.

# Blob broker protocol v1

Status: normative for the `broker` blob store. Where this document and the
Formation client disagree, this document wins and the client is the bug.

A blob broker lets an install keep objects in a store it holds no credential
for. The install asks the broker for a short-lived signed address for one
object and one operation, then moves the bytes directly to or from the store
behind that address. The bytes never pass through the broker.

This contract is independent of any hosting operator, control plane or storage
vendor. An operator who would rather hand an install a bucket and a key pair
configures the [S3 blob store](https://docs.formation.texturehq.com/runtime/kept-attachments.md#configuration)
instead; an install has one or the other.

Two roles are used below. **The client** is Formation's `broker` blob store.
**The broker** is the service this document specifies.

## Trust model

The client is untrusted. The broker authenticates each request by its
credential and derives the caller's scope, which install it is and where that
install's objects live, from the credential's server-side meaning. Nothing a
client sends can change that scope. A key names an object within the caller's
scope and never outside it: the broker maps `key` into the scope itself, and no
key reaches another install's objects.

The store's own credential stays with the broker. A signed address is the only
authority a client ever holds over the store, and it is authority for one
operation on one object for a short time.

The broker authorizes nothing about who may read an object within an install.
That decision is the install's, made in its own database before it asks.

## Transport

The configured endpoint is an `https` URL without credentials, query or
fragment. It may carry a path prefix; every path below is relative to it and
begins with the version, `/v1`. A breaking change ships as `/v2`. `/v1` adds
only optional response fields and new error codes, which clients tolerate.

Requests carry `Authorization: Bearer <token>`. The token is opaque to the
client, which sends it to the broker and nowhere else: never to a signed
address, a log line or an error. Request and response bodies are JSON.
Responses use `Cache-Control: no-store`. A 3xx is an error; a client never
follows a redirect from the broker or from a signed address.

## Sign a request

`POST /v1/objects/sign`

| Field | Required | Meaning |
| - | - | - |
| `operation` | yes | `put`, `get` or `delete`. |
| `key` | yes | The object's key within the caller's scope: slash-separated segments of letters, digits, `.`, `_` and `-`, each starting with a letter or digit, at most 512 bytes, with no `..`. |
| `size` | for `put` | The exact number of bytes the client will send. |
| `content_type` | no | For `put`, the media type to store with the object. |

A success is `200` with:

| Field | Meaning |
| - | - |
| `url` | The signed address: an `https` URL with no credentials in its authority. |
| `method` | `PUT`, `GET` or `DELETE`, matching `operation`. |
| `headers` | Optional. Headers the client sends with the request, exactly as given. |
| `expires_at` | Optional, RFC 3339. When the address stops working. |

```json theme={null}
{
  "url": "https://objects.example.com/bucket/scope/attachments/3f2c?signature=…",
  "method": "PUT",
  "headers": { "content-type": "application/pdf" },
  "expires_at": "2026-01-01T00:05:00Z"
}
```

The client then makes that one request: the method, the address, the headers,
and for `put` a body of exactly `size` bytes. It adds no credential.

| Operation | Success from the store | Also meaningful |
| - | - | - |
| `put` | `200`, `201` or `204` | |
| `get` | `200`, with the object as the body | `404`: no such object |
| `delete` | `200` or `204` | `404`: already gone, which is success |

Any other status from the store is a failure of that operation.

### What the client refuses

The client checks an answer before using it and treats any of these as a
failure, making no further request: a body that is not the object above or is
larger than 64 KiB; a `url` that is not `https`, has no host, or carries
credentials or a fragment; a `method` other than the one the operation calls
for; a header named `Authorization`, `Cookie`, `Proxy-Authorization`, `Host`,
`Content-Length` or `Transfer-Encoding`; more than 16 headers; and an answer
that contains the client's own token.

## Errors

A refusal is a non-`200` status with:

```json theme={null}
{ "error": { "code": "too_large", "message": "Objects are limited to 8 MiB." } }
```

`code` is lowercase letters, digits and underscores, at most 64 characters.
Clients branch on `code` and status only. `message` is for an operator reading
the broker's side; the client does not repeat it. A body that is not this
envelope is still a refusal, keyed by its status.

| Status | `code` | Meaning |
| - | - | - |
| `400` | `invalid_request` | A field is missing or malformed, or the key is not a valid key. |
| `401` | `unauthorized` | The credential is missing, unknown, expired or revoked. |
| `403` | `suspended` | The credential is known and its install may not use storage now. |
| `413` | `too_large` | `size` exceeds what the broker admits. |
| `429` | `rate_limited` | Too many requests. `Retry-After` may be present. |
| `503` | `unavailable` | The broker or its store cannot serve this now. |

## Broker obligations

* Confine every signed address to the caller's scope, and to the one object
  and one method requested.
* Keep signed addresses short-lived. Five minutes is ample for one object.
* For `put`, bind the address to the declared `size` where the store can, so a
  client cannot store more than it declared.
* Never return the store's credential, and never accept a client's choice of
  bucket, prefix or scope.
* Refuse a credential whose install has been stopped or removed.
* Decide the fate of an install's objects when the install is removed. The
  client deletes objects one at a time as its own records are deleted and
  never lists or sweeps.

## Configuration

`FORMATION_BLOB_BROKER_URL` is the endpoint and `FORMATION_BLOB_BROKER_TOKEN`
the credential. Set both or neither; one without the other fails startup, as
does setting them together with `FORMATION_BLOB_S3_*`. A complete pair that
cannot be used (a non-`https` endpoint, a malformed token) is logged at startup
and the install serves without a blob store. The broker is not contacted at
startup; a wrong token or an unreachable broker shows as objects that are not
kept.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.