From 4e45addece5db86ad1f4eed7b4fbf321b1c74d1a Mon Sep 17 00:00:00 2001 From: ulziibay-kernel <253135130+ulziibay-kernel@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:57:27 +0000 Subject: [PATCH] Document IP allowlisting for API keys Add a Limit a key to your IP ranges section with the source_ip condition: what it restricts, how it evaluates (CIDR-only values, audited 403 with the client IP, edge-proxy-reported address), and adding or changing rules on an existing key without rotating its credential. The update section covers replacing permissions in place, and the permissions reference gains a Conditions section with the condition fields and the delegation rule. Note the hosted MCP caveat while MCP support is pending. --- info/api-key-permissions.mdx | 21 ++++++++++ info/api-keys.mdx | 80 ++++++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/info/api-key-permissions.mdx b/info/api-key-permissions.mdx index 6d27711c..b35c2efe 100644 --- a/info/api-key-permissions.mdx +++ b/info/api-key-permissions.mdx @@ -15,6 +15,27 @@ This page lists everything you can grant in a scoped API key's `policy`. To crea Resources must be inside the new key's organization, or its project for a project-scoped key. Kernel checks that every object ID exists when you create the key. +## Conditions + +A statement can carry one condition that narrows it to matching requests: + +```json +"condition": { "key": "source_ip", "operator": "in", "values": ["203.0.113.0/24"] } +``` + +| Field | Value | +| --- | --- | +| `key` | `source_ip` — the request's client address. | +| `operator` | `in` — the statement matches when the address is inside one of `values`. | +| `values` | 1-16 CIDR networks, such as `203.0.113.0/24` or `2001:db8::/32`. A bare address without a mask and an entry with host bits set are rejected, as is an IPv4 network written in IPv6 notation. | + +How conditions evaluate: + +- A condition only narrows its own statement. To restrict a whole key, add the same condition to every statement. +- Requests from outside every listed network get `403` with `insufficient_scope`, recorded in your [audit logs](/info/audit-logs) with the client IP. +- A scoped key can't delegate a wider condition than it holds: a delegated key can narrow its parent's IP rules, never loosen them. +- You can add or change IP rules on an existing key without rotating its credential. See [Limit a key to your IP ranges](/info/api-keys#limit-a-key-to-your-ip-ranges). + ## Actions ### Browsers diff --git a/info/api-keys.mdx b/info/api-keys.mdx index 5fbdf2ca..91006a80 100644 --- a/info/api-keys.mdx +++ b/info/api-keys.mdx @@ -101,6 +101,8 @@ A policy is a list of **statements**. Each statement allows one **action** on on - A **resource** is either one object, `projects/{project_id}/{kind}/{id}`, or everything in a container, `projects/{project_id}/*` or `organizations/{org_id}/*`. - An **action** is `{kind}:{verb}`, such as `browsers:use` or `vaults:read`. +A statement can also carry a **condition** that narrows it to matching requests. A condition names a request attribute, a comparison operator, and that operator's values. See [Limit a key to your IP ranges](/info/api-keys#limit-a-key-to-your-ip-ranges). + Some operations need more than one action. For example, creating a browser with a profile needs `browsers:create` and `browsers:use` on the project, plus `profiles:use` on that profile. See [API key permissions](/info/api-key-permissions) for every action and what each operation requires. ### Create a scoped key @@ -171,6 +173,78 @@ Automatic cleanup only covers browsers associated with the key. Some browsers cr Scoped keys can't manage API keys, and they get `403` on endpoints that don't support scoped access yet. +## Limit a key to your IP ranges + +Add a `condition` to a statement to restrict where requests can come from. The `source_ip` condition allows the statement only when the request's client address is inside one of its CIDR networks: + +```json +{ + "statements": [ + { + "action": "browsers:use", + "resource": "projects/proj_staging_9f3k/*", + "condition": { + "key": "source_ip", + "operator": "in", + "values": ["203.0.113.0/24", "2001:db8::/32"] + } + } + ] +} +``` + +Use this when a key is pinned to a fixed egress: if the key leaks into a log, a repository, or a third-party tool, requests from anywhere else get `403` before they touch your data. + +How conditions evaluate: + +- Each entry in `values` must be a CIDR network (`203.0.113.0/24`). A bare address without a mask, an entry with host bits set, and an IPv4 network written in IPv6 notation are rejected with `400` at creation—so a mistyped mask can't silently grant a whole block. +- Requests from outside every listed network get `403` with `insufficient_scope`, and the denial is recorded in your [audit logs](/info/audit-logs) with the client IP, so you can widen the list from evidence. +- A condition only narrows its own statement. If you want a key that only works from your network, add the same condition to every statement in its policy. +- Kernel evaluates the address the trusted edge proxy reports, not a client-supplied header value, so a request can't spoof its way in. + +### Add an IP allowlist to an existing key + +You don't need to rotate a key to add, change, or remove IP rules. Update the key with a `policy`, and the credential, name, project, and expiry stay the same—your consumers keep the same secret: + + +```typescript TypeScript +await kernel.apiKeys.update('key_01jwv4tn5m8k3q2v7x9p0a1bc2', { + policy: { + statements: [ + { + action: 'browsers:use', + resource: 'projects/proj_staging_9f3k/*', + condition: { key: 'source_ip', operator: 'in', values: ['203.0.113.0/24'] }, + }, + ], + }, +}); +``` + +```python Python +client.api_keys.update( + "key_01jwv4tn5m8k3q2v7x9p0a1bc2", + policy={ + "statements": [ + { + "action": "browsers:use", + "resource": "projects/proj_staging_9f3k/*", + "condition": {"key": "source_ip", "operator": "in", "values": ["203.0.113.0/24"]}, + } + ], + }, +) +``` + + +Updating `policy` **fully replaces** the key's permissions, so send the complete policy, not just the statements you're changing. The new policy takes effect within the authorization cache (~10 seconds) and applies only to new requests—already-open browser connections keep running. + +Attaching a policy to a key that doesn't have one makes the key scoped: every action and resource the policy doesn't list is denied. There's no way to remove a policy from a key and go back to unrestricted—if you no longer need a scoped key, delete it. + + +A key used through a hosted MCP server is evaluated against the MCP server's egress address, so an IP-restricted key is denied everywhere until MCP support ships. If you route keys through a hosted MCP server, leave `source_ip` conditions off those keys for now. + + ## Deployment API keys When you deploy an app, Kernel mints a **deployment-scoped API key** for that deployment and injects it into the deployment (and every invocation it runs) as the `KERNEL_API_KEY` environment variable. Because the SDKs read `KERNEL_API_KEY` from the environment by default, your app can call the Kernel API as itself without you managing a key. @@ -245,9 +319,9 @@ func main() { ``` -## Rename or delete an API key +## Rename, update permissions, or delete an API key -Rename a key when the owner or purpose changes. Delete a key when the workload no longer needs access. +Rename a key when the owner or purpose changes. Update its `policy` to add, change, or remove IP rules and permissions without rotating the credential. Delete a key when the workload no longer needs access. An API key cannot delete itself. Authenticate with a different key when deleting a key, so the request cannot revoke the credential that is authorizing it. Deleting a key also ends its associated browsers asynchronously and discards their unsaved profile changes. @@ -391,7 +465,7 @@ To cut over immediately instead of using a grace window, pass `expire_in_days: 0 | --- | --- | --- | | `400 Bad Request` | The name is missing, `days_to_expire` is outside `1`-`3650`, `expire_in_days` is outside `0`-`3650`, or `project_id` is empty. | Send a name, choose a valid expiry, or omit `project_id` for an org-scoped key. | | `400 Bad Request` (rotate) | `days_to_expire` is shorter than `expire_in_days`, so the new key would expire before the old key's grace window ends. | Raise `days_to_expire` or lower `expire_in_days`. | -| `400 Bad Request` (scoped key) | The policy has an unknown action or a resource outside the key's organization or project, or the expiry is invalid or later than your own key's. | Check the policy against [API key permissions](/info/api-key-permissions) and send one expiry field. | +| `400 Bad Request` (scoped key) | The policy has an unknown action or a resource outside the key's organization or project, the expiry is invalid or later than your own key's, or a condition is malformed: `source_ip` values must be CIDR networks (not bare addresses, host-bit entries, or IPv4-in-IPv6 notation), name a supported `key` and `operator`, and `policy: null` isn't accepted on update. | Check the policy against [API key permissions](/info/api-key-permissions) and send one expiry field. | | `401 Unauthorized` | Kernel couldn't authenticate the request. | Set a valid `KERNEL_API_KEY`. | | `403 Forbidden` (`insufficient_scope`) | A scoped key is missing a permission. | The message names the missing action and resource. Add it to the policy. | | `404 Not Found` | The project, API key, or a resource named in the policy doesn't exist, or the caller can't access it. | Check the ID. If you're using a project-scoped key, you can only rotate keys in that same project. |