Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Merge remote-tracking branch 'origin/main' into feat/switch-trust-settings-ui

Timo Bozsolik-Torresf6b9ef7b2033
diff --cc console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsx
index ce497b4e9,5c8f6a5c7..cb7cc28e1
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsx
@@@ -35,22 -34,11 +34,12 @@@ import
} from '@renderer/lib/ui/dropdown-menu';
import { Spinner } from '@renderer/lib/ui/spinner';
import type { SwitchServer } from '@shared/core/switch-servers/switch-servers';
+import { GuardrailsSection } from './GuardrailsSection';
import { localServerStore } from './local-server-store';
- import { LocalServerControls } from './LocalServerControls';
- import { managedTelemetryNotice } from './managed-telemetry-notice';
import { MessagingAppsCard } from './MessagingAppsCard';
import { remoteServerStore } from './remote-server-store';
- import { RemoteServerControls } from './RemoteServerControls';
import { serverIcon } from './server-icon';
- import {
- serverDeployedTelemetry,
- serverDrift,
- serverPlacementLabel,
- serverProgress,
- serverUpgrade,
- } from './server-presentation';
- import { ServerResetSection } from './server-reset-section';
+ import { serverPlacementLabel } from './server-presentation';
import { ServerSectionTitlebar } from './server-section-titlebar';
import {
machineUnavailableReason,
diff --cc core/switch_core/db/models.py
index f48def944,997dabef6..eee12078c
--- a/core/switch_core/db/models.py
+++ b/core/switch_core/db/models.py
@@@ -2434,52 -2141,6 +2141,32 @@@ class SwitchCoreProcess(Base)
)
- # ── Feature flags ────────────────────────────────────────────────────────────
-
-
- class FeatureFlag(Base):
- """Server-global on/off switch keyed by a well-known flag name.
-
- A row exists only once a flag has been written; an absent row means the
- flag is OFF (its default). Which keys are writable is enforced in the
- application layer (see ``switch_core.feature_flags``), not by the table.
- """
-
- __tablename__ = "feature_flags"
-
- key: Mapped[str] = mapped_column(Text, primary_key=True)
- enabled: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
- updated_at: Mapped[str] = mapped_column(
- DateTime(timezone=True),
- server_default=func.now(),
- onupdate=func.now(),
- nullable=False,
- )
++# ── Trust settings ───────────────────────────────────────────────────────────
+
+
+class TrustSettings(Base):
+ """Server-global Switch Trust guardrails configuration — one row.
+
+ No row, or one with ``policy_id``/``api_key_encrypted`` unset, means the
+ check is off (see ``switch_core.trust.client.DynamicTrustClient``). ``id``
+ is a fixed constant (``db/stores/trust_settings_store.py``) rather than a
+ generated key, since there is exactly one row by construction.
+ """
+
+ __tablename__ = "trust_settings"
+
+ id: Mapped[str] = mapped_column(Text, primary_key=True)
+ endpoint: Mapped[str] = mapped_column(Text, nullable=False)
+ policy_id: Mapped[str | None] = mapped_column(Text, nullable=True)
+ api_key_encrypted: Mapped[str | None] = mapped_column(Text, nullable=True)
+ updated_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True),
+ server_default=func.now(),
+ onupdate=func.now(),
+ nullable=False,
+ )
+
+
# ── Messages ─────────────────────────────────────────────────────────────────
diff --cc core/switch_core/db/rls_ddl.py
index df4afcd7a,a234dffe9..555cc7fd9
--- a/core/switch_core/db/rls_ddl.py
+++ b/core/switch_core/db/rls_ddl.py
@@@ -133,15 -131,17 +131,22 @@@ POLICY_NAME = "tenant_isolation
# controller sockets for every tenant at once, so its lease belongs to none of
# them, and it holds no customer data, only that the process is alive.
#
+ # `cloud_machines` is a user's Switch cloud VM: one per person, whichever
+ # workspaces it serves, as the person is global. It holds the VM's lifecycle,
+ # disk and instance, and no workspace's data: what the machine runs for a
+ # workspace is that workspace's `machine_workspaces` row, which is scoped, and
+ # `tenants_of_cloud_machine` (`db/tenant_lookup.py`) is how the cloud
+ # controller, which acts for no tenant, finds which workspaces those are.
++#
+# `trust_settings` is Switch Trust's one guardrails policy for the whole
+# deployment (`docs/design/switch-trust-guardrails-v1.md`'s Settings UI
+# section) — a policy that varied per tenant would be a new scoped table, not
+# a row here.
GLOBAL_TABLES = frozenset(
{
+ "cloud_machines",
"users",
"oidc_identities",
- "feature_flags",
"deployment_identity",
"telemetry_milestones",
"telemetry_snapshot_watermark",
diff --cc core/switch_core/gateway/app.py
index 9c6421ab9,1fa9447c1..e499b0690
--- a/core/switch_core/gateway/app.py
+++ b/core/switch_core/gateway/app.py
@@@ -68,9 -62,7 +62,8 @@@ from switch_core.gateway.teams_placemen
from switch_core.gateway.template_runs import router as template_runs_router
from switch_core.gateway.templates import router as templates_router
from switch_core.gateway.tenants import router as tenants_router
+from switch_core.gateway.trust_settings import router as trust_settings_router
from switch_core.keys import Purpose
- from switch_core.providers.claude_verifier import ClaudeVerifier
from switch_core.providers.github import GitHubConnections
from switch_core.providers.hosted import HostedControllerSettings
from switch_core.room_service import RoomService
@@@ -220,7 -191,7 +192,8 @@@ def create_gateway_app
app.include_router(templates_router, tags=["templates"])
app.include_router(template_runs_router, tags=["templates"])
app.include_router(ecosystem_router, prefix="/ecosystem", tags=["ecosystem"])
+ app.include_router(trust_settings_router, tags=["trust-settings"])
+ app.include_router(feature_flags_router, tags=["feature-flags"])
app.include_router(
messaging_installs_router,
prefix="/messaging-apps",
diff --cc core/switch_core/gateway/schemas.py
index eb97e7e8e,e84a22c87..77d6baa74
--- a/core/switch_core/gateway/schemas.py
+++ b/core/switch_core/gateway/schemas.py
@@@ -1479,68 -1497,10 +1498,80 @@@ class BudgetResponse(BaseModel)
exhausted: bool
+# ── Switch Trust ──────────────────────────────────────────────────────────────
+
+
+class TrustSettingsResponse(BaseModel):
+ """Switch Trust's one server-global settings row. The API key itself is
+ never returned — `has_api_key`/`api_key_last4` only confirm one is set,
+ the way the stored secret is surfaced everywhere else in the gateway."""
+
+ endpoint: str
+ policy_id: str | None
+ has_api_key: bool
+ api_key_last4: str | None
+ enabled: bool
+
+
+class TrustSettingsUpdateRequest(BaseModel):
+ """`api_key` omitted (or null) leaves whatever key is already stored
+ untouched, so changing the endpoint or policy id doesn't force re-entering
+ the secret. Use `DELETE /trust-settings` to turn Switch Trust off.
+
+ No `timeout_seconds` here: unlike the rest of Switch Trust's settings,
+ the check timeout is fixed at deploy time (`SwitchConfig.
+ switch_trust_timeout_seconds`), not admin-editable."""
+
+ endpoint: str
+ policy_id: str | None
+ api_key: str | None = None
+
+ @model_validator(mode="after")
+ def _validate_endpoint(self) -> TrustSettingsUpdateRequest:
+ value = self.endpoint
+ if value != value.strip():
+ raise ValueError("endpoint has leading or trailing whitespace")
+ parts = urlsplit(value)
+ if parts.scheme not in ("http", "https"):
+ raise ValueError("endpoint must be an http(s) URL")
+ if not parts.netloc:
+ raise ValueError("endpoint must include a host")
+ if parts.path.strip("/"):
+ raise ValueError(
+ "endpoint is the service's base URL — /guardrails/check is "
+ "appended to it, so it must have no path of its own"
+ )
+ if parts.query or parts.fragment:
+ raise ValueError(
+ "endpoint must be a bare base URL: a query or fragment is "
+ "dropped when /guardrails/check is appended, so it would "
+ "silently never be sent"
+ )
+ return self
+
+ @model_validator(mode="after")
+ def _validate_api_key(self) -> TrustSettingsUpdateRequest:
+ if self.api_key is not None and not self.api_key.strip():
+ raise ValueError(
+ "api_key must not be blank; omit it to leave the stored key "
+ "unchanged, or use DELETE /trust-settings to turn Switch "
+ "Trust off"
+ )
+ return self
+
+ @field_validator("policy_id")
+ @classmethod
+ def _blank_policy_id_is_unset(cls, value: str | None) -> str | None:
+ return value.strip() if value and value.strip() else None
++
++
++# ── Feature flags ────────────────────────────────────────────────────────────
++
++
+ class FeatureFlagState(BaseModel):
+ key: str
+ enabled: bool
+
+
+ class FeatureFlagsResponse(BaseModel):
+ flags: list[FeatureFlagState]
diff --cc core/switch_core/migrations/versions/dce217a97f54_merge_trust_settings_migration_head_.py
index 000000000,000000000..8a24bb7c8
new file mode 100644
--- /dev/null
+++ b/core/switch_core/migrations/versions/dce217a97f54_merge_trust_settings_migration_head_.py
@@@ -1,0 -1,0 +1,14 @@@
++"""Merge the trust-settings migration head with main's head."""
++
++revision = "dce217a97f54"
++down_revision = ("cba933f98e1c", "d5f9a3c71b84")
++branch_labels = None
++depends_on = None
++
++
++def upgrade() -> None:
++ pass
++
++
++def downgrade() -> None:
++ pass