Skip to content

Commit 1d0dc8f

Browse files
feat(rbac): enhance function registration with new hooks and RBAC con… (#1373)
1 parent 9ea9e4e commit 1d0dc8f

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

docs/modules/module-worker.mdx

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ modules:
4444
auth_function_id: my-project::auth-function
4545
on_trigger_registration_function_id: my-project::on-trigger-reg
4646
on_trigger_type_registration_function_id: my-project::on-trigger-type-reg
47+
on_function_registration_function_id: my-project::on-function-reg
4748
expose_functions:
4849
- match("engine::*")
4950
- match("*::public")
@@ -100,7 +101,7 @@ The middleware is responsible for calling the target function (e.g. via `trigger
100101

101102
## RBAC
102103

103-
When the `rbac` block is present in a `WorkerModule` entry, that listener enforces role-based access control: authentication on connect, function-level authorization, and trigger registration controls.
104+
When the `rbac` block is present in a `WorkerModule` entry, that listener enforces role-based access control: authentication on connect, function invocation authorization, and gated function/trigger registration.
104105

105106
<Info title="How-to guidance">
106107
For step-by-step instructions on enabling RBAC, writing auth and middleware functions, and connecting workers, see [Worker RBAC](../how-to/worker-rbac).
@@ -142,6 +143,10 @@ On connection to an RBAC port, the optional auth function is called with the req
142143
Function ID to invoke when a worker attempts to register a trigger type. Receives the trigger type details and auth context. Must return `true` to allow the registration.
143144
</ResponseField>
144145

146+
<ResponseField name="on_function_registration_function_id" type="string">
147+
Function ID to invoke when a worker attempts to register a function. Receives the function details and auth context. Must return `true` to allow the registration. See [Function Registration](#function-registration).
148+
</ResponseField>
149+
145150
### Function Filters
146151

147152
#### Wildcard Match
@@ -207,6 +212,9 @@ The auth function must return:
207212
<ResponseField name="allow_trigger_type_registration" type="boolean">
208213
Whether this worker can register new trigger types. Defaults to `false`.
209214
</ResponseField>
215+
<ResponseField name="allow_function_registration" type="boolean">
216+
Whether this worker can register new functions. Defaults to `true`.
217+
</ResponseField>
210218
<ResponseField name="context" type="Record&lt;string, unknown&gt;">
211219
Arbitrary context object passed to the middleware function on every invocation. Defaults to empty object.
212220
</ResponseField>
@@ -220,15 +228,44 @@ The auth function must return:
220228
4. If any `expose_functions` filter matches -- **allowed**
221229
5. Otherwise -- **denied**
222230

223-
### Trigger Registration
231+
### Registration Gating
232+
233+
Workers on an RBAC port can register functions, trigger types, and triggers when permitted by the auth result.
234+
235+
#### Function Registration
224236

225-
Workers on an RBAC port can register trigger types and triggers when permitted by the auth result.
237+
A worker can register a function if **both** conditions are met:
238+
1. `allow_function_registration` is `true` in the auth result (defaults to `true`)
239+
2. If `on_function_registration_function_id` is configured, the hook returns `true`
226240

227-
**Trigger type registration** requires both conditions:
241+
The hook receives:
242+
243+
<Expandable title="FunctionRegistrationHookInput">
244+
<ResponseField name="function_id" type="string" required>
245+
The function ID being registered.
246+
</ResponseField>
247+
<ResponseField name="description" type="string">
248+
Optional description provided by the worker.
249+
</ResponseField>
250+
<ResponseField name="metadata" type="Record&lt;string, unknown&gt;">
251+
Optional metadata provided by the worker.
252+
</ResponseField>
253+
<ResponseField name="context" type="Record&lt;string, unknown&gt;" required>
254+
The context from the auth result for this session.
255+
</ResponseField>
256+
</Expandable>
257+
258+
If either check fails, the registration is silently dropped.
259+
260+
#### Trigger Type Registration
261+
262+
A worker can register a trigger type if **both** conditions are met:
228263
1. `allow_trigger_type_registration` is `true` in the auth result
229264
2. If `on_trigger_type_registration_function_id` is configured, the hook returns `true`
230265

231-
**Trigger registration** requires both conditions:
266+
#### Trigger Registration
267+
268+
A worker can register a trigger if **both** conditions are met:
232269
1. The trigger's `trigger_type` is in `allowed_trigger_types` from the auth result
233270
2. If `on_trigger_registration_function_id` is configured, the hook returns `true`
234271

@@ -249,8 +286,8 @@ The Worker module uses the standard iii engine WebSocket protocol. SDK workers c
249286
| Type | Fields | Description |
250287
|------|--------|-------------|
251288
| `registerworker` | `runtime`, `version`, `name`, `os`, `telemetry`, `pid` | Register the worker and send metadata. |
252-
| `registerfunction` | `function_id`, `metadata` | Register a function. Not allowed on RBAC ports. |
253-
| `unregisterfunction` | `function_id` | Unregister a function. Not allowed on RBAC ports. |
289+
| `registerfunction` | `function_id`, `description?`, `metadata?` | Register a function. On RBAC ports, requires `allow_function_registration` and, if `on_function_registration_function_id` is configured, the hook must return `true`; otherwise the registration is silently dropped. |
290+
| `unregisterfunction` | `function_id` | Unregister a function owned by this worker. |
254291
| `invokefunction` | `invocation_id`, `function_id`, `data` | Invoke a function. RBAC checks apply on RBAC ports. |
255292
| `registertriggertype` | `id`, `description` | Register a new trigger type. On RBAC ports, requires `allow_trigger_type_registration`. |
256293
| `registertrigger` | `id`, `trigger_type`, `function_id`, `config` | Register a trigger. On RBAC ports, requires the type to be in `allowed_trigger_types`. |

0 commit comments

Comments
 (0)