Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)19k · #10490

iii-worker-manager

Skill này làm gì

Thiết lập listener mà các worker dùng để kết nối tới engine iii, và kiểm soát mỗi kết nối được dùng những hàm nào. Dành cho lập trình viên mở engine iii cho worker khác hoặc mạng khác và cần kiểm soát truy cập.

Khi nào nên dùng

  • ✓Khi bạn muốn các worker ở mạng khác kết nối tới engine của mình một cách an toàn.
  • ✓Khi bạn cần giới hạn các hàm mà một worker đã kết nối có thể gọi.
  • ✓Khi bạn muốn ghi log hoặc giới hạn tần suất mọi lệnh gọi đi qua engine.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/iii-hq/iii/blob/main/engine/src/workers/worker/skills/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Mở engine iii của tôi cho một mạng không tin cậy, với các quy tắc truy cập giới hạn những gì mỗi worker kết nối có thể gọi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill cấu hình các listener WebSocket trên các cổng riêng, mỗi cổng có quy tắc truy cập riêng. Kiểm tra truy cập chạy cho từng kết nối, và một hàm middleware tùy chọn có thể kiểm toán, giới hạn tần suất hoặc thay đổi mỗi lệnh gọi trước khi nó đến đích.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

Câu hỏi thường gặp

Tôi có nên mở cổng engine trực tiếp ra internet không?

Không. Quy tắc truy cập là bắt buộc với mạng không tin cậy, và một worker proxy riêng là cách được khuyến nghị để thi hành chúng.

Mỗi khách hàng có thể có một namespace riêng không?

Có. Một hàm xác thực có thể thêm tiền tố vào mọi hàm và trigger mà một phiên đăng ký, nhờ đó cô lập từng tenant.

Middleware làm gì?

Nó thấy mọi lần gọi trên listener của nó và quyết định có chuyển tiếp lệnh gọi hay không và trả về gì.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
19k
Vị trí xếp hạng
#10490
Giấy phép
—
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự