@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +5 -5
- package/dist/admin/admin.module.d.ts +3 -2
- package/dist/admin/admin.module.js +9 -5
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/org-network.controller.d.ts +30 -0
- package/dist/admin/org-network.controller.js +77 -0
- package/dist/admin/org-network.schemas.d.ts +16 -0
- package/dist/admin/org-network.schemas.js +27 -0
- package/dist/admin/org-network.service.d.ts +41 -0
- package/dist/admin/org-network.service.js +101 -0
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +54 -47
- package/dist/config/schema.js +198 -42
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/event-log.js +4 -1
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.d.ts +8 -1
- package/dist/ctx/create-ctx.js +13 -3
- package/dist/ctx/net.d.ts +50 -0
- package/dist/ctx/net.js +67 -0
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +27 -6
- package/dist/devices/devices.service.js +2 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +10 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +9 -4
- package/dist/extensions/host.js +14 -8
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +4 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/database/transaction-host.d.ts +32 -1
- package/dist/infra/database/transaction-host.js +30 -4
- package/dist/infra/database/xact-lock.d.ts +16 -0
- package/dist/infra/database/xact-lock.js +28 -1
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/net/public-address.d.ts +21 -1
- package/dist/net/public-address.js +56 -10
- package/dist/net/safe-fetch.d.ts +4 -1
- package/dist/net/safe-fetch.js +15 -4
- package/dist/orgs/directory-sync.js +2 -0
- package/dist/orgs/members.service.js +5 -0
- package/dist/orgs/network-allowances.service.d.ts +79 -0
- package/dist/orgs/network-allowances.service.js +371 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +9 -2
- package/dist/orgs/org-lock.d.ts +28 -2
- package/dist/orgs/org-lock.js +59 -4
- package/dist/orgs/orgs.controller.d.ts +11 -2
- package/dist/orgs/orgs.controller.js +19 -3
- package/dist/orgs/orgs.module.d.ts +3 -2
- package/dist/orgs/orgs.module.js +6 -2
- package/dist/orgs/orgs.schemas.d.ts +12 -0
- package/dist/orgs/orgs.schemas.js +5 -0
- package/dist/orgs/orgs.service.js +6 -1
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +7 -7
- package/dist/overrides.js +4 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.js +1 -1
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +11 -3
- package/dist/platform/ops/orgs.ops.js +139 -5
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/checkpointer.d.ts +3 -0
- package/dist/runtime/checkpointer.js +7 -4
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +9 -3
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.d.ts +56 -3
- package/dist/runtime/run-execution.js +81 -11
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/step-log.d.ts +5 -0
- package/dist/runtime/step-log.js +9 -4
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/runtime/waits.js +3 -1
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connector-content.js +1 -0
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +65 -6
- package/dist/tools/drift.d.ts +6 -2
- package/dist/tools/drift.js +10 -5
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +17 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/src/migrations/0145_org_network_allowances.sql +12 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -179,23 +179,27 @@ export declare const OUTBOX_JOBS: {
|
|
|
179
179
|
};
|
|
180
180
|
readonly "scope-item": {
|
|
181
181
|
readonly queue: "cap-kernel-plugin-scope";
|
|
182
|
-
readonly idempotent: "the
|
|
182
|
+
readonly idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads";
|
|
183
183
|
readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
|
|
184
184
|
readonly opts: {
|
|
185
|
-
readonly attempts:
|
|
185
|
+
readonly attempts: 7;
|
|
186
|
+
readonly backoff: {
|
|
187
|
+
readonly type: "exponential";
|
|
188
|
+
readonly delay: 5000;
|
|
189
|
+
};
|
|
186
190
|
readonly removeOnComplete: true;
|
|
187
191
|
readonly removeOnFail: true;
|
|
188
192
|
};
|
|
189
193
|
};
|
|
190
|
-
readonly "scope-item-
|
|
194
|
+
readonly "scope-item-chunk": {
|
|
191
195
|
readonly queue: "cap-kernel-plugin-scope";
|
|
192
|
-
readonly idempotent: "the sync converges each (item, org) from
|
|
196
|
+
readonly idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing";
|
|
193
197
|
readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
|
|
194
198
|
readonly opts: {
|
|
195
|
-
readonly attempts:
|
|
199
|
+
readonly attempts: 7;
|
|
196
200
|
readonly backoff: {
|
|
197
201
|
readonly type: "exponential";
|
|
198
|
-
readonly delay:
|
|
202
|
+
readonly delay: 5000;
|
|
199
203
|
};
|
|
200
204
|
readonly removeOnComplete: true;
|
|
201
205
|
readonly removeOnFail: true;
|
|
@@ -206,7 +210,11 @@ export declare const OUTBOX_JOBS: {
|
|
|
206
210
|
readonly idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing";
|
|
207
211
|
readonly processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts";
|
|
208
212
|
readonly opts: {
|
|
209
|
-
readonly attempts:
|
|
213
|
+
readonly attempts: 7;
|
|
214
|
+
readonly backoff: {
|
|
215
|
+
readonly type: "exponential";
|
|
216
|
+
readonly delay: 5000;
|
|
217
|
+
};
|
|
210
218
|
readonly removeOnComplete: true;
|
|
211
219
|
readonly removeOnFail: true;
|
|
212
220
|
};
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin scope queue's one retry policy (`scope-item`, `scope-item-chunk`, `scope-org`): 7
|
|
3
|
+
* attempts, 5 s doubling, so the retries wait 5 + 10 + 20 + 40 + 80 + 160 = 315 s (about five
|
|
4
|
+
* minutes) before the last attempt. That is the window a replica has to load an extension its
|
|
5
|
+
* deploy enabled: the enable's `kernel.plugins.changed` message reconciles every replica at once,
|
|
6
|
+
* and if a replica misses it, its periodic reconcile does within
|
|
7
|
+
* `extensionHost.reconcileIntervalSeconds` (default 60 s). An interval longer than the window (it
|
|
8
|
+
* is not capped: tests set an hour to keep the periodic reconcile out of the way) leaves such a
|
|
9
|
+
* replica's chunk to its last attempt, which records `catalog.not_deployed` for the pair until the
|
|
10
|
+
* next sync of the item.
|
|
11
|
+
* Removed once done, so the next add of the same id is not swallowed.
|
|
12
|
+
*/
|
|
13
|
+
const SCOPE_JOB_OPTS = {
|
|
14
|
+
attempts: 7,
|
|
15
|
+
backoff: { type: "exponential", delay: 5_000 },
|
|
16
|
+
removeOnComplete: true,
|
|
17
|
+
removeOnFail: true,
|
|
18
|
+
};
|
|
1
19
|
/**
|
|
2
20
|
* Every job name added through the outbox. The task that introduces a job name adds its entry; a
|
|
3
21
|
* name without one does not type-check as an `OutboxJobName` (`add` does not check it at runtime).
|
|
@@ -157,40 +175,38 @@ export const OUTBOX_JOBS = {
|
|
|
157
175
|
removeOnFail: true,
|
|
158
176
|
},
|
|
159
177
|
},
|
|
160
|
-
// `catalog/scope-
|
|
161
|
-
// scope, disabled flag, list, owner or platform version,
|
|
162
|
-
//
|
|
163
|
-
//
|
|
178
|
+
// `catalog/scope-jobs.ts` SCOPE_ITEM_JOB: owed by every transaction that changes what an item's
|
|
179
|
+
// sync converges to (its scope, disabled flag, list, owner or platform version, an import's
|
|
180
|
+
// commit deploying no extension) and by the deploy of its extension (enable, a new version of an
|
|
181
|
+
// enabled one, an approval), under `scopeItemJobId` (one per owing transaction, spec §8.1)
|
|
164
182
|
"scope-item": {
|
|
165
183
|
queue: "cap-kernel-plugin-scope",
|
|
166
|
-
idempotent: "the
|
|
184
|
+
idempotent: "the fan-out owes the same chunk job ids again (`<item job id>-c<n>`), which the outbox and BullMQ dedupe, and each chunk converges from what it reads",
|
|
167
185
|
processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
|
|
168
|
-
//
|
|
169
|
-
// add of the same id is not swallowed
|
|
170
|
-
opts:
|
|
186
|
+
// the plugin scope queue's one retry policy (a PG or Redis blip); removed once done, so the
|
|
187
|
+
// next add of the same id is not swallowed
|
|
188
|
+
opts: SCOPE_JOB_OPTS,
|
|
171
189
|
},
|
|
172
|
-
// `catalog/scope-jobs.ts`
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
"scope-item-backstop": {
|
|
190
|
+
// `catalog/scope-jobs.ts` SCOPE_CHUNK_JOB: owed by a scope-item job, one per chunk of orgs, under
|
|
191
|
+
// `scopeChunkJobId`
|
|
192
|
+
"scope-item-chunk": {
|
|
176
193
|
queue: "cap-kernel-plugin-scope",
|
|
177
|
-
idempotent: "the sync converges each (item, org) from
|
|
194
|
+
idempotent: "the sync converges each (item, org) from the scope, switches and installs it reads under the org's lock, and the installer re-checks under the org row lock, so a second run changes nothing",
|
|
178
195
|
processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
|
|
179
|
-
// retried while the item's extension is not
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
removeOnFail: true,
|
|
186
|
-
},
|
|
196
|
+
// retried while the item's extension is enabled but not loaded on the replica (the job throws
|
|
197
|
+
// after its other pairs, P3-38): 5 s doubling, about five minutes in all; the last attempt
|
|
198
|
+
// installs anyway and records what fails. A pair's own failure is recorded and does not fail
|
|
199
|
+
// the job; a retry of a deferred chunk attempts every pair again, a failed one included
|
|
200
|
+
// (idempotent: it converges from what it reads)
|
|
201
|
+
opts: SCOPE_JOB_OPTS,
|
|
187
202
|
},
|
|
188
|
-
// `catalog/scope-
|
|
203
|
+
// `catalog/scope-jobs.ts` SCOPE_ORG_JOB: owed by an org's creation, under `scopeOrgJobId`
|
|
189
204
|
"scope-org": {
|
|
190
205
|
queue: "cap-kernel-plugin-scope",
|
|
191
206
|
idempotent: "the sync converges each (item, org) of the org from what it reads, so a second run changes nothing",
|
|
192
207
|
processedIn: "packages/kernel/src/catalog/scope-sync-workers.ts",
|
|
193
|
-
|
|
208
|
+
// as a chunk job: retried while one of its items' extensions is not loaded on the replica
|
|
209
|
+
opts: SCOPE_JOB_OPTS,
|
|
194
210
|
},
|
|
195
211
|
// `catalog/job-ids.ts` OWNED_PLUGIN_CLEANUP_JOB: owed by the removal of an org-owned plugin
|
|
196
212
|
// (and by a confirmation that took out the extension of an item removed meanwhile), under
|
|
@@ -38,7 +38,6 @@ import { GatewayRole } from "../roles/gateway-role.js";
|
|
|
38
38
|
import { WorkerRole } from "../roles/worker-role.js";
|
|
39
39
|
import { UsageReporter } from "../runtime/usage-report.js";
|
|
40
40
|
import { sandboxConfigWarnings } from "../sandbox/sandbox.service.js";
|
|
41
|
-
import { warnLegacyToolKeys } from "../tools/legacy-data.js";
|
|
42
41
|
import { KERNEL_APP_OPTIONS } from "./tokens.js";
|
|
43
42
|
/**
|
|
44
43
|
* The stop phase budgets. Each phase waits `min(its budget, what is left of the total)`, where the
|
|
@@ -204,10 +203,6 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
204
203
|
// In flight for the stop: aborted when the shutdown begins, which then waits for its session to end
|
|
205
204
|
await this.shutdown.trackInFlight(migrate(config.db.url, { schema: KERNEL_SCHEMA, dir: KERNEL_MIGRATIONS_DIR }, { connectTimeoutMs: config.db.connectTimeoutMs, signal: this.shutdown.signal }));
|
|
206
205
|
this.checkpoint();
|
|
207
|
-
// Rows still holding a release-candidate tool key that migration 0063 could not map: one
|
|
208
|
-
// read-only count, a WARN when there are any (tool naming spec §8.2); never blocks the start
|
|
209
|
-
await warnLegacyToolKeys(this.kdb.db, this.log).catch((e) => this.log.warn("tools.legacy_key_count_failed", { error: errMsg(e) }));
|
|
210
|
-
this.checkpoint();
|
|
211
206
|
// official 清单来源按配置同步(幂等;每个副本启动时都做)
|
|
212
207
|
await this.marketplaces.syncOfficialFromConfig();
|
|
213
208
|
// The bootstrap plugins (spec §7), once per manifest across replicas (the Redis lock
|
|
@@ -255,8 +250,7 @@ let KernelLifecycle = class KernelLifecycle {
|
|
|
255
250
|
// start gate: their timers are armed at application bootstrap, but no tick runs before the
|
|
256
251
|
// worker role opens the start gate here; the runOnStart jobs run then), the gateway role's
|
|
257
252
|
// supervisor and webhook inbound
|
|
258
|
-
|
|
259
|
-
await worker.start(() => this.checkpoint());
|
|
253
|
+
worker?.start();
|
|
260
254
|
if (gateway)
|
|
261
255
|
await gateway.start(() => this.checkpoint());
|
|
262
256
|
// Routes stay mounted and are resolved live: 503 extension.unavailable after an extension is revoked, back after it reloads (C17)
|
|
@@ -64,13 +64,12 @@ export declare class ModelEnablement {
|
|
|
64
64
|
private disabledKeys;
|
|
65
65
|
private rowsOf;
|
|
66
66
|
/**
|
|
67
|
-
* The extensions `orgId`
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* Read from PG on every call (one small query; the switch has its own writers, nothing to evict).
|
|
67
|
+
* The extensions enabled in `orgId` ({@link enabledExtensionsQuery}: the org's own switch on, or
|
|
68
|
+
* a required bootstrap plugin): a model provider is on in an org only then, like every other
|
|
69
|
+
* extension. Read from PG on every call (one small query; the switch has its own writers, nothing
|
|
70
|
+
* to evict).
|
|
72
71
|
*/
|
|
73
|
-
|
|
72
|
+
enabledIn(orgId: string): Promise<Set<string>>;
|
|
74
73
|
/** Whether neither the platform nor `orgId` disabled the model (the lists only; see the class). */
|
|
75
74
|
isEnabled(orgId: string, provider: string, model: string): Promise<boolean>;
|
|
76
75
|
/**
|
|
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Inject, Injectable, Module } from "@nestjs/common";
|
|
11
11
|
import { ApiError } from "../errors.js";
|
|
12
|
+
import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
12
13
|
import { ExtensionRegistry, ExtensionRegistryModule } from "../extensions/registry.js";
|
|
13
14
|
import { audit } from "../identity/audit.js";
|
|
14
15
|
import { SuperAdminLock, SuperAdminLockModule } from "../identity/super-admin.js";
|
|
@@ -73,21 +74,13 @@ let ModelEnablement = class ModelEnablement {
|
|
|
73
74
|
return q.execute();
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
|
-
* The extensions `orgId`
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* Read from PG on every call (one small query; the switch has its own writers, nothing to evict).
|
|
77
|
+
* The extensions enabled in `orgId` ({@link enabledExtensionsQuery}: the org's own switch on, or
|
|
78
|
+
* a required bootstrap plugin): a model provider is on in an org only then, like every other
|
|
79
|
+
* extension. Read from PG on every call (one small query; the switch has its own writers, nothing
|
|
80
|
+
* to evict).
|
|
81
81
|
*/
|
|
82
|
-
async
|
|
83
|
-
const rows = await this.db
|
|
84
|
-
.selectFrom("extension_org_configs as eoc")
|
|
85
|
-
.leftJoin("extension_installs as ri", (j) => j.onRef("ri.name", "=", "eoc.plugin").on("ri.required", "=", true))
|
|
86
|
-
.select("eoc.plugin")
|
|
87
|
-
.where("eoc.org_id", "=", orgId)
|
|
88
|
-
.where("eoc.enabled", "=", false)
|
|
89
|
-
.where("ri.name", "is", null)
|
|
90
|
-
.execute();
|
|
82
|
+
async enabledIn(orgId) {
|
|
83
|
+
const rows = await enabledExtensionsQuery(this.db, orgId).execute();
|
|
91
84
|
return new Set(rows.map((r) => r.plugin));
|
|
92
85
|
}
|
|
93
86
|
/** Whether neither the platform nor `orgId` disabled the model (the lists only; see the class). */
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/** Whether connecting to this (resolved) IP is forbidden: private, loopback, reserved, or unparseable. */
|
|
2
2
|
export declare function isForbiddenAddress(ip: string): boolean;
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Link-local (incl. cloud metadata 169.254.169.254), another cloud metadata endpoint
|
|
5
|
+
* (`100.100.100.200`, `fd00:ec2::254`) or unparseable: forbidden whatever the exemptions.
|
|
6
|
+
*/
|
|
4
7
|
export declare function isLinkLocalAddress(ip: string): boolean;
|
|
8
|
+
/** Loopback (`127.0.0.0/8`, `::1`) or unspecified (`0.0.0.0/8`, `::`), embedded forms included. */
|
|
9
|
+
export declare function isLoopbackOrUnspecifiedAddress(ip: string): boolean;
|
|
5
10
|
/** A hostname normalized for comparison: lower case, no IPv6 brackets, no trailing dots. */
|
|
6
11
|
export declare function normalizeHost(host: string): string;
|
|
7
12
|
/** `localhost`, `127.0.0.0/8` or `::1` (as written in a URL). */
|
|
@@ -30,6 +35,15 @@ export type NetPolicy = {
|
|
|
30
35
|
url: string;
|
|
31
36
|
noProxy: string[];
|
|
32
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Set for an extension's request (`ctx.net.fetch`): loopback and unspecified addresses are
|
|
40
|
+
* refused whatever the exemptions (unless `allowInsecureLoopback`), `*.domain` entries in
|
|
41
|
+
* `allowPrivateHosts` match subdomains (never the apex), and a refused private address says
|
|
42
|
+
* `privateHint` (where such an endpoint is allowed) instead of the marketplace hint.
|
|
43
|
+
*/
|
|
44
|
+
extension?: {
|
|
45
|
+
privateHint: string;
|
|
46
|
+
};
|
|
33
47
|
};
|
|
34
48
|
export type LookupFn = (host: string) => Promise<{
|
|
35
49
|
address: string;
|
|
@@ -60,6 +74,12 @@ export declare function parseCidr(s: string): [string, number, "ipv4" | "ipv6"]
|
|
|
60
74
|
export declare function privateHostEntryProblem(entry: string): string | null;
|
|
61
75
|
/** A valid `marketplaces.allowPrivateHosts` entry (see {@link privateHostEntryProblem}). */
|
|
62
76
|
export declare function isPrivateHostEntry(entry: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether a host entry of `policy.allowPrivateHosts` (a hostname, a `*.domain` wildcard, an IP or a
|
|
79
|
+
* CIDR) names `host`, ignoring trusted origins: such entries exempt https requests only, so a
|
|
80
|
+
* refused plain-http request to that host can point at an `http://host:port` origin entry.
|
|
81
|
+
*/
|
|
82
|
+
export declare function hostEntryExempts(host: string, policy: NetPolicy): boolean;
|
|
63
83
|
/**
|
|
64
84
|
* Resolves `host` (an IP literal is taken as is) and returns every address, in resolution order,
|
|
65
85
|
* after checking that each is public or exempt by `policy`. `origin` is the request URL's origin:
|
|
@@ -15,8 +15,12 @@ import { BlockList, isIP } from "node:net";
|
|
|
15
15
|
* the embedded IPv4 address (proxy.mjs falls through to the IPv6 table, where they are not blocked);
|
|
16
16
|
* a host behind a SIIT translator could otherwise reach a private IPv4 address.
|
|
17
17
|
*
|
|
18
|
-
* Link-local addresses (`169.254.0.0/16`, including cloud metadata, and `fe80::/10`)
|
|
19
|
-
*
|
|
18
|
+
* Link-local addresses (`169.254.0.0/16`, including cloud metadata, and `fe80::/10`) and the cloud
|
|
19
|
+
* metadata endpoints outside link-local (AWS IPv6 `fd00:ec2::254`, Alibaba Cloud `100.100.100.200`)
|
|
20
|
+
* stay forbidden whatever the exemptions: no internal mirror lives there.
|
|
21
|
+
*
|
|
22
|
+
* Extension requests (`ctx.net`, {@link NetPolicy.extension}) also refuse loopback and unspecified
|
|
23
|
+
* addresses whatever the exemptions (the kernel's own host), unless `allowInsecureLoopback` (tests).
|
|
20
24
|
*/
|
|
21
25
|
const BLOCKED_V4 = [
|
|
22
26
|
["0.0.0.0", 8], // unspecified / this network
|
|
@@ -51,9 +55,18 @@ for (const [a, p] of BLOCKED_V4)
|
|
|
51
55
|
blocked.addSubnet(a, p, "ipv4");
|
|
52
56
|
for (const [a, p] of BLOCKED_V6)
|
|
53
57
|
blocked.addSubnet(a, p, "ipv6");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
/** Never allowed, whatever the exemptions: link-local and the cloud metadata endpoints. */
|
|
59
|
+
const neverAllowed = new BlockList();
|
|
60
|
+
neverAllowed.addSubnet("169.254.0.0", 16, "ipv4");
|
|
61
|
+
neverAllowed.addSubnet("fe80::", 10, "ipv6");
|
|
62
|
+
neverAllowed.addAddress("100.100.100.200", "ipv4"); // Alibaba Cloud metadata (inside CGNAT)
|
|
63
|
+
neverAllowed.addAddress("fd00:ec2::254", "ipv6"); // AWS IMDS over IPv6 (inside ULA)
|
|
64
|
+
/** Loopback and unspecified: never allowed for extension requests (see the file header). */
|
|
65
|
+
const loopbackOrUnspecified = new BlockList();
|
|
66
|
+
loopbackOrUnspecified.addSubnet("127.0.0.0", 8, "ipv4");
|
|
67
|
+
loopbackOrUnspecified.addSubnet("0.0.0.0", 8, "ipv4");
|
|
68
|
+
loopbackOrUnspecified.addAddress("::1", "ipv6");
|
|
69
|
+
loopbackOrUnspecified.addAddress("::", "ipv6");
|
|
57
70
|
/** An IPv6 address as its 8 16-bit groups; null when it cannot be parsed. */
|
|
58
71
|
function v6Groups(ip) {
|
|
59
72
|
let s = ip.toLowerCase();
|
|
@@ -118,9 +131,16 @@ function inTable(ip, table) {
|
|
|
118
131
|
export function isForbiddenAddress(ip) {
|
|
119
132
|
return inTable(ip, blocked);
|
|
120
133
|
}
|
|
121
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Link-local (incl. cloud metadata 169.254.169.254), another cloud metadata endpoint
|
|
136
|
+
* (`100.100.100.200`, `fd00:ec2::254`) or unparseable: forbidden whatever the exemptions.
|
|
137
|
+
*/
|
|
122
138
|
export function isLinkLocalAddress(ip) {
|
|
123
|
-
return inTable(ip,
|
|
139
|
+
return inTable(ip, neverAllowed);
|
|
140
|
+
}
|
|
141
|
+
/** Loopback (`127.0.0.0/8`, `::1`) or unspecified (`0.0.0.0/8`, `::`), embedded forms included. */
|
|
142
|
+
export function isLoopbackOrUnspecifiedAddress(ip) {
|
|
143
|
+
return inTable(ip, loopbackOrUnspecified);
|
|
124
144
|
}
|
|
125
145
|
/** A hostname normalized for comparison: lower case, no IPv6 brackets, no trailing dots. */
|
|
126
146
|
export function normalizeHost(host) {
|
|
@@ -201,6 +221,14 @@ function exemptions(host, policy, origin) {
|
|
|
201
221
|
cidrs.addAddress("::1", "ipv6");
|
|
202
222
|
}
|
|
203
223
|
for (const entry of policy.allowPrivateHosts) {
|
|
224
|
+
// a `*.domain` wildcard (extension requests): a name under the domain, never the apex
|
|
225
|
+
if (entry.startsWith("*.")) {
|
|
226
|
+
const base = normalizeHost(entry.slice(2));
|
|
227
|
+
if (policy.extension && !literal && HOSTNAME.test(base) && host.endsWith(`.${base}`)) {
|
|
228
|
+
all = true;
|
|
229
|
+
}
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
204
232
|
if (!isPrivateHostEntry(entry))
|
|
205
233
|
continue;
|
|
206
234
|
const cidr = parseCidr(entry);
|
|
@@ -248,6 +276,15 @@ function allowedBy(cidrs, ip) {
|
|
|
248
276
|
}
|
|
249
277
|
return false;
|
|
250
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Whether a host entry of `policy.allowPrivateHosts` (a hostname, a `*.domain` wildcard, an IP or a
|
|
281
|
+
* CIDR) names `host`, ignoring trusted origins: such entries exempt https requests only, so a
|
|
282
|
+
* refused plain-http request to that host can point at an `http://host:port` origin entry.
|
|
283
|
+
*/
|
|
284
|
+
export function hostEntryExempts(host, policy) {
|
|
285
|
+
const { all, cidrs } = exemptions(host, { ...policy, allowInsecureLoopback: false }, undefined);
|
|
286
|
+
return all || (isIP(host) !== 0 && allowedBy(cidrs, host));
|
|
287
|
+
}
|
|
251
288
|
/**
|
|
252
289
|
* Resolves `host` (an IP literal is taken as is) and returns every address, in resolution order,
|
|
253
290
|
* after checking that each is public or exempt by `policy`. `origin` is the request URL's origin:
|
|
@@ -272,11 +309,20 @@ export async function resolvePublic(host, policy, lookup = defaultLookup, origin
|
|
|
272
309
|
throw new NetDeniedError("net.dns_failed", h, `Cannot resolve ${h}.`);
|
|
273
310
|
}
|
|
274
311
|
const ex = exemptions(h, policy, origin);
|
|
275
|
-
|
|
312
|
+
// extension requests never reach the kernel's own host, whatever the exemptions
|
|
313
|
+
const ownHost = (a) => policy.extension !== undefined &&
|
|
314
|
+
!policy.allowInsecureLoopback &&
|
|
315
|
+
isLoopbackOrUnspecifiedAddress(a);
|
|
316
|
+
const refused = (a) => isForbiddenAddress(a) &&
|
|
317
|
+
(isLinkLocalAddress(a) || ownHost(a) || (!ex.all && !allowedBy(ex.cidrs, a)));
|
|
276
318
|
if (addrs.some(refused)) {
|
|
319
|
+
const hint = policy.extension?.privateHint ??
|
|
320
|
+
"add the hostname to marketplaces.allowPrivateHosts to allow an internal host";
|
|
277
321
|
throw new NetDeniedError("net.private_address", h, addrs.some(isLinkLocalAddress)
|
|
278
|
-
? `Access to ${h} is refused: it resolves to a link-local address, which is never allowed.`
|
|
279
|
-
:
|
|
322
|
+
? `Access to ${h} is refused: it resolves to a link-local or cloud metadata address, which is never allowed.`
|
|
323
|
+
: addrs.some(ownHost)
|
|
324
|
+
? `Access to ${h} is refused: it resolves to a loopback address (the kernel's own host), which is never allowed.`
|
|
325
|
+
: `Access to ${h} is refused: it resolves to a private or reserved address (${hint}).`);
|
|
280
326
|
}
|
|
281
327
|
return addrs;
|
|
282
328
|
}
|
package/dist/net/safe-fetch.d.ts
CHANGED
|
@@ -12,7 +12,8 @@ import { type LookupFn, type NetPolicy } from "./public-address.js";
|
|
|
12
12
|
* `noProxy` tunnels through the proxy (`proxy.ts`) instead: the host is not resolved locally
|
|
13
13
|
* (the proxy resolves it and owns SSRF protection for the resolved address), but an IP-literal
|
|
14
14
|
* host is still checked against the private ranges and `allowPrivateHosts`;
|
|
15
|
-
* - redirects are never followed: a 3xx (other than 304) is {@link NetDeniedError} `net.redirect
|
|
15
|
+
* - redirects are never followed: a 3xx (other than 304) is {@link NetDeniedError} `net.redirect`,
|
|
16
|
+
* or, with `redirects: "return"`, returned to the caller as is (its body unread);
|
|
16
17
|
* - with `maxBytes`, a declared or streamed body over the limit is {@link NetBodyTooLargeError}.
|
|
17
18
|
*/
|
|
18
19
|
/** The response body is larger than `maxBytes`. */
|
|
@@ -32,6 +33,8 @@ export declare function safeFetch(url: string, init: RequestInit & {
|
|
|
32
33
|
}, policy: NetPolicy, opts?: {
|
|
33
34
|
lookup?: LookupFn;
|
|
34
35
|
maxBytes?: number;
|
|
36
|
+
/** A 3xx response (other than 304): `refuse` (default) rejects with `net.redirect`, `return` returns it. */
|
|
37
|
+
redirects?: "refuse" | "return";
|
|
35
38
|
/** Tests only: wraps the pinned dispatcher (defaults to {@link pinnedAgent}). */
|
|
36
39
|
dispatcherFor?: (ips: string[]) => Agent;
|
|
37
40
|
/** Tests only: builds the proxy dispatcher (defaults to {@link proxyAgent}). */
|
package/dist/net/safe-fetch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isIP } from "node:net";
|
|
2
2
|
import { Agent, fetch as undiciFetch } from "undici";
|
|
3
3
|
import { bypassesProxy, proxyAgent } from "./proxy.js";
|
|
4
|
-
import { isLoopbackHost, NetDeniedError, normalizeHost, resolvePublic, } from "./public-address.js";
|
|
4
|
+
import { hostEntryExempts, isLoopbackHost, NetDeniedError, normalizeHost, resolvePublic, } from "./public-address.js";
|
|
5
5
|
/**
|
|
6
6
|
* `fetch` for URLs that come from a marketplace or an admin (spec §5.1):
|
|
7
7
|
* - https only; plain http only for a loopback host under `allowInsecureLoopback` (testing), or
|
|
@@ -14,7 +14,8 @@ import { isLoopbackHost, NetDeniedError, normalizeHost, resolvePublic, } from ".
|
|
|
14
14
|
* `noProxy` tunnels through the proxy (`proxy.ts`) instead: the host is not resolved locally
|
|
15
15
|
* (the proxy resolves it and owns SSRF protection for the resolved address), but an IP-literal
|
|
16
16
|
* host is still checked against the private ranges and `allowPrivateHosts`;
|
|
17
|
-
* - redirects are never followed: a 3xx (other than 304) is {@link NetDeniedError} `net.redirect
|
|
17
|
+
* - redirects are never followed: a 3xx (other than 304) is {@link NetDeniedError} `net.redirect`,
|
|
18
|
+
* or, with `redirects: "return"`, returned to the caller as is (its body unread);
|
|
18
19
|
* - with `maxBytes`, a declared or streamed body over the limit is {@link NetBodyTooLargeError}.
|
|
19
20
|
*/
|
|
20
21
|
/** The response body is larger than `maxBytes`. */
|
|
@@ -83,7 +84,14 @@ export async function safeFetch(url, init, policy, opts = {}) {
|
|
|
83
84
|
((policy.allowInsecureLoopback && isLoopbackHost(host)) ||
|
|
84
85
|
policy.trustedOrigins.some((o) => originOf(o) === target.origin));
|
|
85
86
|
if (target.protocol !== "https:" && !insecureOk) {
|
|
86
|
-
|
|
87
|
+
// an extension request to a host the org allows only as a host entry (https only): name the
|
|
88
|
+
// origin entry that would allow plain http
|
|
89
|
+
const hint = policy.extension !== undefined &&
|
|
90
|
+
target.protocol === "http:" &&
|
|
91
|
+
hostEntryExempts(host, policy)
|
|
92
|
+
? ` ${host} is allowed for the organization over https only; to allow plain http, ask a super admin to allow the origin ${target.origin}.`
|
|
93
|
+
: "";
|
|
94
|
+
throw new NetDeniedError("net.insecure_url", host, `The URL must use https (${host}).${hint}`);
|
|
87
95
|
}
|
|
88
96
|
const proxy = policy.proxy;
|
|
89
97
|
const proxied = proxy !== undefined &&
|
|
@@ -126,7 +134,10 @@ export async function safeFetch(url, init, policy, opts = {}) {
|
|
|
126
134
|
}
|
|
127
135
|
// close() waits for the in-flight request (the body still being read) before it closes
|
|
128
136
|
void agent.close().catch(() => { });
|
|
129
|
-
if (res.status >= 300 &&
|
|
137
|
+
if (res.status >= 300 &&
|
|
138
|
+
res.status < 400 &&
|
|
139
|
+
res.status !== 304 &&
|
|
140
|
+
(opts.redirects ?? "refuse") === "refuse") {
|
|
130
141
|
await res.body?.cancel().catch(() => { });
|
|
131
142
|
throw new NetDeniedError("net.redirect", host, `${host} responded with a redirect (${res.status}); redirects are not followed.`, res.status);
|
|
132
143
|
}
|
|
@@ -599,6 +599,8 @@ let DirectorySync = class DirectorySync {
|
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
601
|
async offboardIn(orgId, source, accountId) {
|
|
602
|
+
// offboarding: the org admission lock first (`Offboarding.offboard`)
|
|
603
|
+
await this.orgLock.lockForRemoval(orgId);
|
|
602
604
|
if (!(await this.orgLock.tryLock(orgId)))
|
|
603
605
|
return undefined;
|
|
604
606
|
const row = await this.db
|
|
@@ -143,6 +143,10 @@ let MembersService = class MembersService {
|
|
|
143
143
|
await this.removeIn(orgId, targetId, actorAccountId, actorTokenId);
|
|
144
144
|
}
|
|
145
145
|
async removeIn(orgId, targetId, actorAccountId, actorTokenId) {
|
|
146
|
+
// an unauthorized call is refused before it holds off the org's run writes
|
|
147
|
+
await this.orgLock.precheck(orgId, actorAccountId, "org.members.manage");
|
|
148
|
+
// offboarding: the org admission lock first (`Offboarding.offboard`)
|
|
149
|
+
await this.orgLock.lockForRemoval(orgId);
|
|
146
150
|
const { role: actorRole } = await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.members.manage");
|
|
147
151
|
const before = await this.requireMember(orgId, targetId);
|
|
148
152
|
await rejectAnonymousGuest(this.db.db, targetId);
|
|
@@ -167,6 +171,7 @@ let MembersService = class MembersService {
|
|
|
167
171
|
await this.leaveIn(orgId, accountId, actorTokenId);
|
|
168
172
|
}
|
|
169
173
|
async leaveIn(orgId, accountId, actorTokenId) {
|
|
174
|
+
await this.orgLock.lockForRemoval(orgId);
|
|
170
175
|
await this.orgLock.lock(orgId);
|
|
171
176
|
const before = await this.requireMember(orgId, accountId);
|
|
172
177
|
const actor = {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { WriteActor } from "../identity/write-actor.js";
|
|
2
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
+
import { OrgLock } from "./org-lock.js";
|
|
5
|
+
/**
|
|
6
|
+
* Org network allowances (plugin safe fetch spec): the internal endpoints a super admin lets one
|
|
7
|
+
* org's extension requests (`ctx.net.fetch` made for that org) reach although they resolve to
|
|
8
|
+
* private or loopback addresses. Stored in `capybara.org_network_allowances`, read from PG on every
|
|
9
|
+
* call (no in-process cache: a removal takes effect on the next request on every replica).
|
|
10
|
+
*
|
|
11
|
+
* An entry is one of:
|
|
12
|
+
* - a hostname or a `*.domain` wildcard (https, any port; the domain has at least two labels and is
|
|
13
|
+
* not a known public suffix);
|
|
14
|
+
* - an IP address or a CIDR (IP-literal URL hosts only, within `MIN_CIDR_PREFIX`);
|
|
15
|
+
* - an origin `http(s)://host[:port]`: exactly that scheme, host and port, plain http included.
|
|
16
|
+
* Link-local and cloud metadata addresses (`100.100.100.200`, `fd00:ec2::254`), loopback and
|
|
17
|
+
* unspecified addresses are never allowed (`localhost` names included), nor IPv6 forms that embed an IPv4 address, so entries naming them are refused.
|
|
18
|
+
*/
|
|
19
|
+
/** The most entries one org may hold. */
|
|
20
|
+
export declare const ORG_NETWORK_ALLOWANCES_MAX = 200;
|
|
21
|
+
/**
|
|
22
|
+
* Why an allowance entry is invalid (English, shown to the super admin), or null when it is valid
|
|
23
|
+
* (see the file header for the accepted forms). Reuses `privateHostEntryProblem` for hosts, IPs and
|
|
24
|
+
* CIDRs; refuses link-local, loopback and unspecified addresses (also as `localhost` names, numeric
|
|
25
|
+
* hosts and inside origins), IPv6 forms that embed IPv4, wildcards over a public suffix, and
|
|
26
|
+
* origins with a path, query, fragment or credentials.
|
|
27
|
+
*/
|
|
28
|
+
export declare function allowanceEntryProblem(entry: string): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* The stored form of a valid entry: hosts lower case without brackets or trailing dots, IPv6
|
|
31
|
+
* addresses and CIDRs in canonical spelling, origins as scheme, host and port (default ports
|
|
32
|
+
* dropped), so one endpoint is stored once.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeAllowanceEntry(entry: string): string;
|
|
35
|
+
export type OrgNetworkAllowance = {
|
|
36
|
+
id: string;
|
|
37
|
+
entry: string;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
createdBy: string | null;
|
|
40
|
+
};
|
|
41
|
+
/** What an org's allowances exempt, in the shape of `NetPolicy` (`net/public-address.ts`). */
|
|
42
|
+
export type OrgNetworkPolicy = {
|
|
43
|
+
allowPrivateHosts: string[];
|
|
44
|
+
trustedOrigins: string[];
|
|
45
|
+
};
|
|
46
|
+
export declare class OrgNetworkAllowances {
|
|
47
|
+
private readonly db;
|
|
48
|
+
readonly txHost: TransactionHost;
|
|
49
|
+
private readonly orgLock;
|
|
50
|
+
constructor(db: KernelDb, txHost: TransactionHost, orgLock: OrgLock);
|
|
51
|
+
/** The org's entries, oldest first. */
|
|
52
|
+
list(orgId: string): Promise<OrgNetworkAllowance[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Adds an entry (super admin only; the route enforces it). Refuses an invalid entry with
|
|
55
|
+
* `org.network_allowance_invalid` and the reason; an entry already listed is returned as is,
|
|
56
|
+
* without a second audit event. `actor.tokenId` (a personal access token) and `auditDetail` (e.g.
|
|
57
|
+
* `viaAgent`) go into the audit event; the caller's detail cannot override `entry`.
|
|
58
|
+
*/
|
|
59
|
+
add(orgId: string, entry: string, actor: WriteActor, auditDetail?: Record<string, unknown>): Promise<OrgNetworkAllowance>;
|
|
60
|
+
/**
|
|
61
|
+
* Removes the org's entry `id`; false (and no audit event) when the org has no such entry. The
|
|
62
|
+
* actor and `auditDetail` are recorded as {@link add}'s.
|
|
63
|
+
*/
|
|
64
|
+
remove(orgId: string, id: string, actor: WriteActor, auditDetail?: Record<string, unknown>): Promise<boolean>;
|
|
65
|
+
/** An allowance audit event in the org; the caller's detail first, so `entry` wins. */
|
|
66
|
+
private audit;
|
|
67
|
+
/**
|
|
68
|
+
* The exemptions of an org-bound request: origins become `trustedOrigins`, hosts, wildcards, IPs
|
|
69
|
+
* and CIDRs `allowPrivateHosts`. A deleted (or unknown) org allows nothing.
|
|
70
|
+
*/
|
|
71
|
+
policyFor(orgId: string): Promise<OrgNetworkPolicy>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* {@link OrgNetworkAllowances} alone (its only dependencies are the global database providers), so
|
|
75
|
+
* the extension host (`ctx.net`) can read the allowances without importing the orgs domain, which
|
|
76
|
+
* itself imports the extensions domain.
|
|
77
|
+
*/
|
|
78
|
+
export declare class OrgNetworkAllowancesModule {
|
|
79
|
+
}
|