Skip to main content

Plugin backends

Some work cannot run in the browser and cannot be written as a request template. For that work, a package can carry server-side code in its backend/ directory. The person who deploys FINOS Workspace builds that code, runs it as a restricted process of its own, and lists it in WIDGET_PLUGIN_BACKENDS, as Run a plugin backend explains. The API is the only caller of a backend.

In the manifest​

The manifest declares the backend's routes, the secrets that the routes send, the data sources that the backend reads, and whether the backend learns a pseudonymous id of the user:

"secrets": [{ "name": "model_key", "purpose": "Authenticates to the forecast model" }],
"dataSources": [{ "id": "sales", "purpose": "The sales of the user's organization" }],
"identity": "pseudonymous",
"server": {
"network": ["https://models.example.org"],
"backend": {
"protocol": 1,
"routes": [
{
"id": "forecast",
"args": { "region": { "type": "string", "maxLength": 8, "required": true } },
"secrets": ["model_key"],
"response": { "maxBytes": 1048576, "timeoutMs": 10000 }
}
]
}
}

The tables are generated from the model that the backend validates the manifest with. The backend has these properties:

  • protocol1required

    The version of the protocol that the API speaks with the backend.

  • routesRoute[]requiredminItems 1maxItems 32

    The routes that the backend serves.

    4 nested properties
    • argsobjectmaxProperties 32

      The arguments that the route accepts, by name. The API checks them before it makes the call.

    • idstringrequiredpattern ^[a-z][a-z0-9_-]{0,63}$

      The route's id, unique within the backend.

    • The limits of the route's answer.

    • secretsstring[]maxItems 16

      The secrets that the route sends, by name. Each one is declared in the manifest's secrets.

A route has these properties:

  • argsobjectmaxProperties 32

    The arguments that the route accepts, by name. The API checks them before it makes the call.

  • idstringrequiredpattern ^[a-z][a-z0-9_-]{0,63}$

    The route's id, unique within the backend.

  • The limits of the route's answer.

  • secretsstring[]maxItems 16

    The secrets that the route sends, by name. Each one is declared in the manifest's secrets.

The response of a route has these properties:

  • maxBytesintegerdefault 1048576minimum 1maximum 5242880

    The most bytes that the route may answer with. The deployment caps the value as well.

  • timeoutMsintegerdefault 10000minimum 100maximum 30000

    How long a call may take, in milliseconds. The deployment caps the value as well.

A data source has these properties:

  • idstringrequiredpattern ^[a-z][a-z0-9_-]{0,63}$

    The data source's id, unique within the plugin.

  • purposestringrequiredmaxLength 300

    What the backend reads from the data source. Admins read this text in the review.

A widget lists the routes that it may call as "server": { "routes": ["forecast"] }, asks for the permission core:backend:call, and then calls a route from its module:

const [forecast] = await experimental.invoke("core:backend:call", {
route: "forecast",
args: { region: "emea" },
});

What the backend answers​

The API talks to the backend over HTTP on its internal address. It sends two kinds of requests:

RequestAnswer
GET /.workspace/identityThe backend answers with { "plugin": "<id>", "version": "<version>", "digest": "<version digest>", "protocol": 1 }. The digest is the one that plugin_check --digest prints for the package that the backend was built from. The API routes nothing to a backend whose answer does not match the approved version.
POST /.workspace/routes/<route-id>The request body is { "args": {...}, "widget": { "id", "instanceId" }, "caller": {} }. The request carries the header X-Workspace-Call with the call's token and, for each secret of the route, a header that starts with X-Workspace-Secret- and ends with the secret's name, in which underscores in the name become hyphens. The backend answers with JSON that stays within the route's limits.

The backend that the repository's examples ship also answers /.workspace/health with any 200 response, which the health check of its container can use. The API never sends that request, so a backend does not need to answer it.

The protocol version is 1. The API checks a backend's identity with a timeout of 5 seconds, and it trusts the answer for 60 seconds before it asks again. The result of a check is one of ok, mismatch, unreachable or unregistered, and the API routes calls only for ok.

Rules for a backend​

Network. The server.network list names everything that the backend contacts. It contains https origins, and it contains tcp://host:port for anything else, such as a database. The deployment enforces the list around the backend. A host that belongs to the deployment rather than to the package, such as its database, is added by a superuser's override, and the package names that host in its purpose texts and in its README.

Arguments. The API checks the arguments against the route's args before it makes the call, using the same types as proxies. A string argument of a route may have a maxLength of up to 32,768 characters, because it travels in the call's JSON body. A proxy's strings are shorter, as the argument table on Plugin proxies and secrets shows.

The caller. The caller object is empty, unless the admin approved identity: "pseudonymous". In that case it is { "id": "<pseudonymous id>" }. The id is an HMAC of the plugin id and the user id. It is stable for one user within one plugin and different in every other plugin, and it is never the user's name, email address or FINOS Workspace id.

Data of the user. A backend reads a data source that it declares by sending the call's token to the broker. It sends POST <API>/internal/plugin-broker/data/<data-source-id> with the header X-Workspace-Call, the header Origin: <the web app's origin> and a body of the form { "path": "/<path under the backend's URL>", "method": "GET", "query": {...}, "body": ... }. The deployment gives the backend its origin value, and the API refuses requests from origins that it does not allow. The broker answers with { "status", "content_type", "body" }. The organization chooses which of its backends serves each data source, and the user's own access applies. The API adds the backend's credentials itself, so the plugin never holds them.

The token. The call token carries the prefix wpc1. and is encrypted and authenticated with a key that is derived from WORKSPACE_AES_KEY. It lasts 60 seconds and is opaque to the backend.

Limits. A route's maxBytes may be at most 5 MiB, and its timeoutMs may be at most 30 seconds. The table of the route's response above shows the defaults. The deployment caps both values, by default at 5 MiB and 30 seconds. The API rate limits calls, by default at 60/minute for each user and 600/minute for each plugin, and it lets at most 8 calls of one plugin run at the same time in each API process. After 5 failures in a row, such as time-outs, errors or 5xx answers, the API pauses calls to the backend for 30 seconds. A 4xx answer from the backend is passed on as a refusal and does not count as a failure.

Errors in the frame. A refused call rejects with out_of_scope when the widget does not list the route. It rejects with invalid_args, not_granted, rate_limited, timeout or too_large when the matching condition holds. In every other case it rejects with unavailable, for example when the backend is not registered, when it runs another version, when calls are paused, when a secret is not set, or when the backend itself returned an error.

Review. The admin who reviews the plugin sees that code runs on the server. The review lists each route with the secrets that it sends, each data source, and the pseudonymous id if the plugin asks for it.

Logs. The API writes one log line for each call with the plugin, the widget, the outcome, the number of bytes and the duration. It never logs arguments, bodies or secrets.