|
@@ -44,6 +44,7 @@ A non-admin key may carry a `scope` object that restricts what it can do. Scoped
|
|
|
|
|
|
|
|
**The Origin allow-list now covers the collections LISTING too** (0.15.0+). It always covered document and vector operations; the listing authorized through the project grant plus the scope filter and never consulted the list, so a key with an allow-list could enumerate a project's collection names, document counts and sizes from ANY origin while being refused every document in them. That mattered because a browser-publishable key is, by definition, a key anyone can read. Now `GET /projects/{p}/collections` answers **403** `forbidden` for an origin outside the list, exactly as a document read does.
|
|
**The Origin allow-list now covers the collections LISTING too** (0.15.0+). It always covered document and vector operations; the listing authorized through the project grant plus the scope filter and never consulted the list, so a key with an allow-list could enumerate a project's collection names, document counts and sizes from ANY origin while being refused every document in them. That mattered because a browser-publishable key is, by definition, a key anyone can read. Now `GET /projects/{p}/collections` answers **403** `forbidden` for an origin outside the list, exactly as a document read does.
|
|
|
- **A key with NO `origins` is unaffected** - an empty list means any origin, which is what a server-side key should use.
|
|
- **A key with NO `origins` is unaffected** - an empty list means any origin, which is what a server-side key should use.
|
|
|
|
|
+- `ip_allow` on a KEY scope is **refused with 422 `unsupported_option`**, not stored. Nothing checks it for an API key, and a control that reads back from the server while never being applied is worse than one that is absent - an operator would believe a key was pinned to their office address. It is a **function policy** field only (see the policy route). For a browser key, `origins` is the control that works; a server-side key has none today, because a non-browser client sends no `Origin` header.
|
|
|
- **An ABSENT `Origin` header is refused when a list IS set**, on the listing and on every other capability-checked route alike. This is long-standing behaviour rather than new, and it is why **a key intended for server-side use must not carry an allow-list at all**: a non-browser client sends no Origin, so it can never satisfy one. A test pins the two routes to the same answer so they cannot drift apart again.
|
|
- **An ABSENT `Origin` header is refused when a list IS set**, on the listing and on every other capability-checked route alike. This is long-standing behaviour rather than new, and it is why **a key intended for server-side use must not carry an allow-list at all**: a non-browser client sends no Origin, so it can never satisfy one. A test pins the two routes to the same answer so they cannot drift apart again.
|
|
|
|
|
|
|
|
**A scope refusal names what it refused and what you hold** (0.15.0+). A 403 `forbidden` from a scoped key carries a message naming the collection and the operation asked, plus the collections the key IS granted, and `error.details` with `collection`, `operation` and `granted` (each `{collection, ops}`). **The status is 403 whether the collection is outside your scope OR does not exist, and that is deliberate** - answering 404 for an absent collection would let a scoped key discover which collections exist in its project outside its own scope. So the message says as much: only you can tell a misspelled name from one nobody provisioned, and the answer will not tell you. Before 0.15.0 the message was just "scope does not permit this operation", which named neither and sent people to re-verify their key rather than the string.
|
|
**A scope refusal names what it refused and what you hold** (0.15.0+). A 403 `forbidden` from a scoped key carries a message naming the collection and the operation asked, plus the collections the key IS granted, and `error.details` with `collection`, `operation` and `granted` (each `{collection, ops}`). **The status is 403 whether the collection is outside your scope OR does not exist, and that is deliberate** - answering 404 for an absent collection would let a scoped key discover which collections exist in its project outside its own scope. So the message says as much: only you can tell a misspelled name from one nobody provisioned, and the answer will not tell you. Before 0.15.0 the message was just "scope does not permit this operation", which named neither and sent people to re-verify their key rather than the string.
|
|
@@ -227,7 +228,13 @@ Requires a `kind=vector` collection. Vectors are stored with cosine-similarity i
|
|
|
All settings endpoints require an admin key.
|
|
All settings endpoints require an admin key.
|
|
|
|
|
|
|
|
- `GET /api/v1/settings` - Return current settings as JSON. `openai_api_key` is masked: the field is absent and `openai_api_key_set` (bool) indicates whether a key is configured.
|
|
- `GET /api/v1/settings` - Return current settings as JSON. `openai_api_key` is masked: the field is absent and `openai_api_key_set` (bool) indicates whether a key is configured.
|
|
|
-- `PUT /api/v1/settings` `{openai_api_base?, openai_api_key?, default_embedding_model?, cors_origins?, session_ttl_minutes?, webui_enabled?, default_project?, embedding_connect_timeout_sec?, embedding_read_timeout_sec?, embedding_cache_size?, embedding_cache_ttl_sec?, embedding_cache_max_bytes?, embedding_cache_normalize?, embedding_client_pool_size?, captcha_provider?, captcha_secret?, captcha_verify_url?}` - Merge the supplied fields into the current settings and persist. Omit `openai_api_key` or `captcha_secret` (or pass an empty string) to keep the existing secret. Changes are hot-reloaded immediately; cache settings are applied instantly via `reconfigure()`.
|
|
|
|
|
|
|
+- `PUT /api/v1/settings` `{openai_api_base?, openai_api_key?, default_embedding_model?, cors_origins?, session_ttl_minutes?, webui_enabled?, default_project?, embedding_connect_timeout_sec?, embedding_read_timeout_sec?, embedding_cache_size?, embedding_cache_ttl_sec?, embedding_cache_max_bytes?, embedding_cache_normalize?, embedding_client_pool_size?, captcha_provider?, captcha_secret?, captcha_verify_url?, client_ip_header?, client_ip_header_is_list?, trusted_proxy_cidrs?}` - Merge the supplied fields into the current settings and persist. Omit `openai_api_key` or `captcha_secret` (or pass an empty string) to keep the existing secret. Changes are hot-reloaded immediately; cache settings are applied instantly via `reconfigure()`.
|
|
|
|
|
+
|
|
|
|
|
+**Who the server thinks is calling** (`client_ip_header`, `client_ip_header_is_list`, `trusted_proxy_cidrs`). These decide the address a function policy's `ip_allow` is matched against, and the address written to the server's own access log. The rule that matters: a header is believed **only when the request arrived from an address in `trusted_proxy_cidrs`** - a header is text the client writes, so otherwise the caller would choose its own answer. Defaults are `X-Real-IP`, not-a-list, and loopback, which is what nginx in front of a loopback-bound vectorapi produces.
|
|
|
|
|
+- `client_ip_header: ""` reads no header at all and treats the peer address as the caller. That is the correct setting when nothing proxies the port.
|
|
|
|
|
+- `client_ip_header_is_list: true` for an `X-Forwarded-For` style header. The **last** element is used, not the first: nginx's `$proxy_add_x_forwarded_for` is "whatever the client sent, plus the real peer appended", so the first element is caller-controlled and only the last was vouched for by the proxy.
|
|
|
|
|
+- A `trusted_proxy_cidrs` entry that is not a CIDR range or bare address is refused with **422 `validation`** naming the entry, rather than dropped silently: a typo that disabled proxy trust would make every request appear to come from the proxy, which still looks like an address and so goes unnoticed.
|
|
|
|
|
+- **Getting these wrong refuses every caller of a function that uses `ip_allow`, not merely the wrong ones.** That is the deliberate fail-closed direction.
|
|
|
|
|
|
|
|
## Project embedding settings
|
|
## Project embedding settings
|
|
|
|
|
|
|
@@ -376,7 +383,8 @@ export default async function (ctx) {
|
|
|
- `GET /api/v1/projects/{project}/functions/{id}` - Get one function, **including** `source`.
|
|
- `GET /api/v1/projects/{project}/functions/{id}` - Get one function, **including** `source`.
|
|
|
- `PUT /api/v1/projects/{project}/functions/{id}` `{source, path?}` - Push code. The id the script declares must equal the id in the URL; a mismatch is **422** `id_mismatch` (with `error.details.declared` and `error.details.url`) rather than a rename, because the URL would otherwise move code onto another function's policy. A PUT to an unused id registers it (**201**).
|
|
- `PUT /api/v1/projects/{project}/functions/{id}` `{source, path?}` - Push code. The id the script declares must equal the id in the URL; a mismatch is **422** `id_mismatch` (with `error.details.declared` and `error.details.url`) rather than a rename, because the URL would otherwise move code onto another function's policy. A PUT to an unused id registers it (**201**).
|
|
|
- `DELETE /api/v1/projects/{project}/functions/{id}` - Delete the function, its code and its policy.
|
|
- `DELETE /api/v1/projects/{project}/functions/{id}` - Delete the function, its code and its policy.
|
|
|
-- `PUT /api/v1/projects/{project}/functions/{id}/policy` `{policy:{rules, origins?, rate_limit_per_min?, expires_at?}}` **(admin)** - Replace what the function may touch. Same vocabulary as a key scope (`rules` of `{collection, ops}` over `read`/`list`/`search`/`insert`/`update`/`delete`), with one difference: an **empty** rule set is legal and means the function reaches nothing. This is the only route that changes a policy.
|
|
|
|
|
|
|
+- `PUT /api/v1/projects/{project}/functions/{id}/policy` `{policy:{rules, origins?, ip_allow?, rate_limit_per_min?, expires_at?}}` **(admin)** - Replace what the function may touch. Same vocabulary as a key scope (`rules` of `{collection, ops}` over `read`/`list`/`search`/`insert`/`update`/`delete`), with one difference: an **empty** rule set is legal and means the function reaches nothing. This is the only route that changes a policy.
|
|
|
|
|
+ - `ip_allow` (array of CIDR ranges or bare addresses, default empty = no restriction) pins the function to caller addresses. **It fails closed**: a non-empty list refuses any request whose address the server could not establish, so a wrong `trusted_proxy_cidrs` refuses everyone rather than the wrong ones. A malformed entry is refused at write time with 422 `validation`; one that somehow reached storage removes only itself and never widens the list. Checked **before** authentication and before the rate limit, so a refused caller cannot spend the function's minute budget - and the refusal writes **no run-log row**, because nothing ran.
|
|
|
- `PUT /api/v1/projects/{project}/functions/{id}/enabled` `{enabled}` - Enable or disable a function.
|
|
- `PUT /api/v1/projects/{project}/functions/{id}/enabled` `{enabled}` - Enable or disable a function.
|
|
|
- `POST /api/v1/projects/{project}/functions/{id}/invoke` `{method?, path?, params?, query?, headers?, body?}` - Run the function once and record the run. Every field is optional: an empty body invokes it with its declared route as the path and `POST` as the method.
|
|
- `POST /api/v1/projects/{project}/functions/{id}/invoke` `{method?, path?, params?, query?, headers?, body?}` - Run the function once and record the run. Every field is optional: an empty body invokes it with its declared route as the path and `POST` as the method.
|
|
|
**THE BODY IS AN ENVELOPE DESCRIBING THE REQUEST TO SYNTHESISE, NOT THE FUNCTION'S PAYLOAD - and getting that wrong used to answer 200.** A payload goes under `body`:
|
|
**THE BODY IS AN ENVELOPE DESCRIBING THE REQUEST TO SYNTHESISE, NOT THE FUNCTION'S PAYLOAD - and getting that wrong used to answer 200.** A payload goes under `body`:
|
|
@@ -398,6 +406,11 @@ export default async function (ctx) {
|
|
|
- The key is used for the gate and is **not** forwarded to the function - `Authorization` has always been stripped - so a function cannot see, log or reuse the caller's credential.
|
|
- The key is used for the gate and is **not** forwarded to the function - `Authorization` has always been stripped - so a function cannot see, log or reuse the caller's credential.
|
|
|
- **A key-gated function (`auth: 'key'`) AUTHENTICATES the caller and grants them NOTHING - so send your LEAST privileged key, not one scoped to the collections the function reads.** The function still reads and writes under its own stored policy, exactly as it does when public; the key only answers "may this caller invoke the route at all". A key with an empty rule set works and is the right choice. Worth stating because the natural guess is the opposite - that a function reading `kb_facts` needs a caller key carrying `search` on `kb_facts` - and guessing that way over-grants a credential that is, by design, going into a third-party tool configuration. Reported by a consumer who used a least-privileged key, found it worked, and pointed out that nothing said so.
|
|
- **A key-gated function (`auth: 'key'`) AUTHENTICATES the caller and grants them NOTHING - so send your LEAST privileged key, not one scoped to the collections the function reads.** The function still reads and writes under its own stored policy, exactly as it does when public; the key only answers "may this caller invoke the route at all". A key with an empty rule set works and is the right choice. Worth stating because the natural guess is the opposite - that a function reading `kb_facts` needs a caller key carrying `search` on `kb_facts` - and guessing that way over-grants a credential that is, by design, going into a third-party tool configuration. Reported by a consumer who used a least-privileged key, found it worked, and pointed out that nothing said so.
|
|
|
**Order the rollout header-first.** Put the `Authorization` header into the calling tool, confirm it works against the still-ungated route, and only then set `auth: 'key'`. Reversed, the route answers 401 for however long it takes someone to notice - and in front of an assistant or voice agent that presents as "it does not know anything" rather than as an auth failure.
|
|
**Order the rollout header-first.** Put the `Authorization` header into the calling tool, confirm it works against the still-ungated route, and only then set `auth: 'key'`. Reversed, the route answers 401 for however long it takes someone to notice - and in front of an assistant or voice agent that presents as "it does not know anything" rather than as an auth failure.
|
|
|
|
|
+- **A function policy may pin the route to caller ADDRESSES** (`ip_allow`, 0.18.2+). Outside the list is **403** `ip_not_allowed`. Four properties, none of them guessable:
|
|
|
|
|
+ - **It is checked FIRST**, ahead of the `auth: 'key'` gate and ahead of the rate limit. So a caller who is not permitted to be here cannot spend the function's minute budget, and cannot have a token checked.
|
|
|
|
|
+ - **The refusal writes NO run-log row**, because nothing ran. That matters if you currently gate a public function with a token compared inside the script: a script-side check RUNS the function first, so every wrong-token request appends a row to your own run log, and a sustained flood evicts your real runs. An address gate refuses before the runner is involved.
|
|
|
|
|
+ - **It fails closed.** A non-empty list refuses any request whose address the server could not establish, so a wrong `trusted_proxy_cidrs` in global settings refuses *everyone* rather than the wrong ones.
|
|
|
|
|
+ - **The message does not echo your address back.** It is in the server's own access log for an operator to read; reflecting it would hand a prober a free "what do you think my address is" oracle. Ask an operator rather than guessing from the response.
|
|
|
- **The function's `rate_limit_per_min` policy now applies to CALLS on this route** (since 0.15.0), not only to the function's data access. `0` means unlimited, as everywhere else. Over the ceiling is **429** `rate_limited` with `Retry-After: 60`. Three things worth knowing:
|
|
- **The function's `rate_limit_per_min` policy now applies to CALLS on this route** (since 0.15.0), not only to the function's data access. `0` means unlimited, as everywhere else. Over the ceiling is **429** `rate_limited` with `Retry-After: 60`. Three things worth knowing:
|
|
|
- **The two ceilings are counted SEPARATELY against the same number.** A limit of 60 means up to 60 calls a minute AND up to 60 data operations a minute; it does not mean a function doing three reads per call gets 15 calls. Adding a read to a script therefore cannot lower its own request ceiling.
|
|
- **The two ceilings are counted SEPARATELY against the same number.** A limit of 60 means up to 60 calls a minute AND up to 60 data operations a minute; it does not mean a function doing three reads per call gets 15 calls. Adding a read to a script therefore cannot lower its own request ceiling.
|
|
|
- **The ceiling is per FUNCTION, not per caller.** It bounds the DAMAGE - mail sent, paid API calls made, on the tenant's quota and sender reputation - rather than the denial: one abusive caller can still exhaust a public function's minute and shut out legitimate ones. Per-caller limiting needs an identity, which is what `auth: 'key'` gives you and an anonymous request does not have.
|
|
- **The ceiling is per FUNCTION, not per caller.** It bounds the DAMAGE - mail sent, paid API calls made, on the tenant's quota and sender reputation - rather than the denial: one abusive caller can still exhaust a public function's minute and shut out legitimate ones. Per-caller limiting needs an identity, which is what `auth: 'key'` gives you and an anonymous request does not have.
|