跳到正文
Skillpedia
API 与服务器(后端)19k · #10490

iii-worker-manager

它能做什么

设置工作进程用来连接 iii 引擎的监听器,并控制每个连接可以使用哪些函数。适合需要向其他工作进程或网络开放 iii 引擎、并且要做访问控制的开发者。

适用场景

  • ✓当你希望另一个网络上的工作进程安全地连接你的引擎时。
  • ✓当你需要限制已连接的工作进程可以调用哪些函数时。
  • ✓当你想记录或限制经过引擎的每一次调用时。

技能链接

https://github.com/iii-hq/iii/blob/main/engine/src/workers/worker/skills/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/iii-hq/iii/blob/main/engine/src/workers/worker/skills/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我把 iii 引擎开放给不可信的网络,并设置访问规则,限制每个已连接的工作进程可以调用的内容。”

每周 5 个新技能,1 分钟读完。

工作原理

该技能会在不同端口上配置 WebSocket 监听器,每个监听器都有自己的访问规则。每个连接都会进行访问检查,还可以使用可选的中间件函数,在调用到达目标之前进行审计、限流或修改。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

iii-worker-manager

The iii-worker-manager is a mandatory engine worker that opens WebSocket listeners. The base engine.workers.iii-worker-manager entry sets the main port (49134 by default); #instance entries open separate listeners with their own RBAC, middleware, and registration hooks. Channels are mounted on every listener at /ws/channels/{channel_id}.

When to Use

  • Exposing the engine to an untrusted network — RBAC is mandatory, never open the engine port itself. Use the standalone rbac-proxy worker (iii trigger compose::add worker=rbac-proxy), which applies these RBAC rules on its own port out of process. A second #instance listener with an rbac block and an auth_function_id is the in-engine alternative.
  • Restricting which functions a connected worker can invoke — combine expose_functions filters (operator-side) with forbidden_functions from AuthResult (per-session, hard deny).
  • Auditing, rate-limiting, or enriching every invocation — set middleware_function_id on the listener; the middleware decides whether to call the target and what to return.
  • Per-tenant or per-session namespace isolation — return function_registration_prefix from the auth function so every function/trigger this session registers is transparently prefixed without the worker code knowing.
  • Gating dynamic registration — wire on_function_registration_function_id, on_trigger_registration_function_id, or on_trigger_type_registration_function_id to validate or rewrite registrations.

Boundaries

  • The infrastructure carve-out (engine::channels::create, engine::workers::register, engine::log::*, engine::baggage::*) is always allowed on RBAC listeners regardless of expose_functions. Adding one of those IDs to forbidden_functions denies it but logs a warning — workers may behave unpredictably (broken setup, lost logs, missing context).
  • The engine port must remain internal. Only rbac-proxy or an RBAC-protected #instance listener may face an external network.
  • The middleware is not a pre-handler — it must invoke the target function itself (typically via iii.trigger) and return its result. Returning early without invoking simply skips the call.
  • forbidden_functions from the auth result wins over both allowed_functions and expose_functions. There is no way for a session to override an operator's deny list.
  • Registration hooks return mapped fields or throw to deny. Omitted result fields keep their original values; returning {} is a no-op (allow as-is).
  • Triggers and functions registered through an RBAC session are scoped to that session and cleaned up automatically on disconnect.

Configuration

Two listeners — one internal, one external with in-engine RBAC (the rbac-proxy worker accepts the same rbac block through the configuration worker instead):

engine:
  workers:
    iii-worker-manager:
      port: 49134

    "iii-worker-manager#rbac":
      host: 0.0.0.0
      port: 49135
      middleware_function_id: my-project::middleware
      rbac:
        auth_function_id: my-project::auth
        on_function_registration_function_id: my-project::on-fn-reg
        on_trigger_registration_function_id: my-project::on-trig-reg
        on_trigger_type_registration_function_id: my-project::on-trig-type-reg
        expose_functions:
          - match("api::*")
          - match("*::public")
          - metadata:
              public: true

Auth function

Receives AuthInput { headers, query_params, ip_address }, returns AuthResult. Throw to reject the connection.

import type { AuthInput, AuthResult } from '@iii-dev/helpers/worker-connection-manager'

iii.registerFunction(
  'my-project::auth',
  async (input: AuthInput): Promise<AuthResult> => {
    const token = input.headers?.['authorization']?.replace(/^Bearer\s+/i, '')
    if (!token) throw new Error('Missing credentials')

    const user = await validateToken(token)

    return {
      allowed_functions: [],
      forbidden_functions: user.role === 'readonly'
        ? ['api::users::delete', 'api::users::update']
        : [],
      allowed_trigger_types: user.role === 'admin' ? ['cron', 'webhook'] : undefined,
      allow_trigger_type_registration: user.role === 'admin',
      function_registration_prefix: `tenant-${user.tenant_id}`,
      context: { user_id: user.id, role: user.role, tenant_id: user.tenant_id },
    }
  },
)

`A

常见问题

我应该把引擎端口直接开放到互联网上吗?

不应该。面对不可信的网络时必须设置访问规则,推荐使用单独的代理工作进程来执行这些规则。

每个客户可以拥有独立的命名空间吗?

可以。认证函数可以为会话注册的每个函数和触发器添加前缀,从而隔离每个租户。

中间件做什么?

它会看到其监听器上的每一次调用,并决定是否继续传递该调用,以及返回什么结果。

详情

作者的原始描述

WebSocket listener that SDK workers connect to. Use to expose the engine to trusted (internal) and untrusted (RBAC-protected) workers, gate function and trigger registration, and audit or transform every invocation through a middleware function. Mounts channel WebSocket endpoints on every listener.

repo: iii-hq/iii

热度

GitHub 星标
19k
排名
#10490
许可证
—
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能