Эх сурвалжийг харах

feat: the deployment's own hostnames are editable from the UI SV-132

CLOSES A DEAD END found by the agent that restructured Settings. The server has
carried `admin_hostname` and `global_hostnames` in global settings since
0.19.0, and the web UI modelled NEITHER - it could not read them, let alone
write them. Meanwhile the project hostnames panel told the operator, in so many
words, to "set an admin hostname or a global hostname in the global settings",
which was a screen that did not exist.

The consequence was worse than a missing form: setting one of these is what
turns host gating ON, so without this control every project hostname in a
deployment is stored and INERT with no UI path to change that. An operator
could add a hostname, be told it was inert, be told where to fix it, and find
nothing there.

The panel leads with the CONSEQUENCE rather than the fields, because saving
here changes behaviour for every request to the deployment including the
operator's own next one: green when gating is in force, amber when every
project hostname is stored and doing nothing. It also states the way back in -
a request arriving on the loopback interface is always the admin surface, so
naming the deployment is not a one-way door - because an operator about to
make a service-wide change needs to know the recovery path BEFORE making it,
not while recovering.

And it says plainly that certificates are not issued from this screen, since a
name without one refuses every handshake rather than serving another
hostname's certificate.

The pointer in the project panel now names a panel that exists. Reworded twice:
the first version put a bare `>` in JSX text, which TSX rejects.
fszontagh 6 өдөр өмнө
parent
commit
092bc5f59c

+ 8 - 0
webui/src/pages/Settings.tsx

@@ -6,6 +6,7 @@ import { useAuthStore } from '@/stores/authStore'
 import EmbeddingsTab from '@/pages/settings/EmbeddingsTab'
 import CacheTab from '@/pages/settings/CacheTab'
 import AccessTab from '@/pages/settings/AccessTab'
+import DeploymentHostnamesTab from '@/pages/settings/DeploymentHostnamesTab'
 import WebuiTab from '@/pages/settings/WebuiTab'
 import ProjectEmbeddingsTab from '@/pages/settings/ProjectEmbeddingsTab'
 import ProjectFunctionsTab from '@/pages/settings/ProjectFunctionsTab'
@@ -85,6 +86,13 @@ export default function Settings() {
           adminOnly: true,
           render: () => <AccessTab />,
         },
+        {
+          id: 'deployment-hostnames',
+          label: 'Hostnames & TLS',
+          blurb: "This deployment's own names, and host gating",
+          adminOnly: true,
+          render: () => <DeploymentHostnamesTab />,
+        },
         {
           id: 'webui',
           label: 'Web UI',

+ 115 - 0
webui/src/pages/settings/DeploymentHostnamesTab.tsx

@@ -0,0 +1,115 @@
+import { useEffect, useState } from 'react'
+import { useQuery, useQueryClient } from '@tanstack/react-query'
+import { api } from '@/api/client'
+import { controlCls, FormRow, SaveButton } from '@/components/form'
+import { useToastStore } from '@/stores/toastStore'
+import { ApiError } from '@/types'
+import type { SettingsView } from '@/types'
+
+/// The deployment's OWN hostnames: the admin name and any global names.
+///
+/// This tab exists because the project hostnames panel pointed at it and it did
+/// not exist. The server has carried `admin_hostname` and `global_hostnames` in
+/// global settings since 0.19.0, and the UI modelled neither - so an operator
+/// could store a project hostname, be told it was inert, be told to fix that in
+/// global settings, and find nothing there.
+export default function DeploymentHostnamesTab() {
+  const push = useToastStore((s) => s.push)
+  const qc = useQueryClient()
+  const q = useQuery({ queryKey: ['settings'], queryFn: () => api.getSettings() })
+
+  const [admin, setAdmin] = useState('')
+  const [globals, setGlobals] = useState('')
+  const [saving, setSaving] = useState(false)
+
+  useEffect(() => {
+    const d = q.data as SettingsView | undefined
+    if (!d) return
+    setAdmin(d.admin_hostname ?? '')
+    setGlobals((d.global_hostnames ?? []).join('\n'))
+  }, [q.data])
+
+  const list = globals.split('\n').map((x) => x.trim()).filter(Boolean)
+  const gatingOn = admin.trim().length > 0 || list.length > 0
+
+  const submit = async (e: React.FormEvent) => {
+    e.preventDefault()
+    setSaving(true)
+    try {
+      await api.updateSettings({ admin_hostname: admin.trim(), global_hostnames: list })
+      await qc.invalidateQueries({ queryKey: ['settings'] })
+      push('Deployment hostnames saved.', 'success')
+    } catch (err) {
+      push(err instanceof ApiError ? err.message : String(err), 'error')
+    } finally {
+      setSaving(false)
+    }
+  }
+
+  if (q.isLoading) return <p className="text-sm text-slate-400">Loading...</p>
+
+  return (
+    <form onSubmit={submit} className="flex flex-col gap-5">
+      {/* The consequence first. Setting either field changes behaviour for
+          EVERY request to this deployment, including the operator's own next
+          one, so it must not read as an ordinary text box. */}
+      <div
+        className={
+          gatingOn
+            ? 'rounded-md border border-emerald-500/30 bg-emerald-500/5 p-3'
+            : 'rounded-md border border-amber-500/30 bg-amber-500/5 p-3'
+        }
+      >
+        <p className="text-sm font-medium text-slate-100">
+          {gatingOn ? 'Host gating is in force.' : 'Host gating is OFF.'}
+        </p>
+        <p className="mt-1 text-xs text-slate-400">
+          {gatingOn
+            ? 'Every request carrying an unregistered Host answers 404, and each project hostname serves only its own project.'
+            : 'Every project hostname stored anywhere in this deployment is saved and INERT. Naming the deployment here is what turns gating on.'}
+        </p>
+        <p className="mt-2 text-xs text-slate-500">
+          A request arriving on the LOOPBACK interface is always treated as the admin surface, so
+          setting a name here is not a one-way door: you can always reach this service from the
+          machine itself to correct a mistake.
+        </p>
+      </div>
+
+      <FormRow
+        label="Admin hostname"
+        hint="Serves everything: the API, functions, this web UI and /docs. Leave empty for none."
+      >
+        <input
+          type="text"
+          value={admin}
+          onChange={(e) => setAdmin(e.target.value)}
+          placeholder="admin.example.com"
+          className={`${controlCls} w-full max-w-lg font-mono`}
+        />
+      </FormRow>
+
+      <FormRow
+        label="Global hostnames"
+        hint="One per line. Serve every project's API with the project named in the path. No web UI, no /docs."
+      >
+        <textarea
+          value={globals}
+          onChange={(e) => setGlobals(e.target.value)}
+          rows={4}
+          placeholder={'api.example.com'}
+          className={`${controlCls} w-full max-w-lg font-mono`}
+        />
+      </FormRow>
+
+      <p className="text-xs text-slate-500">
+        A certificate is needed for each name before it can serve: a hostname without one gets a
+        refused TLS handshake rather than another hostname's certificate. Certificates are issued
+        by the reconciler on this host, not from this screen.
+      </p>
+
+      <div>
+        <SaveButton saving={saving} />
+      </div>
+    </form>
+  )
+}

+ 1 - 1
webui/src/pages/settings/ProjectHostnamesTab.tsx

@@ -206,7 +206,7 @@ export default function ProjectHostnamesTab() {
             <strong>Stored, and not in force.</strong> This deployment has not
             named itself, so the server is not gating on hostnames and nothing
             below serves anything today. Set an admin hostname or a global
-            hostname in the global settings to turn gating on; every name stored
+            hostname under the Global section's Hostnames and TLS panel to turn gating on; every name stored
             here takes effect at that moment, with no further change needed.
           </p>
           {storedCount > 0 && (

+ 7 - 0
webui/src/types/index.ts

@@ -91,6 +91,13 @@ export interface FindResult {
   total?: number
 }
 export interface SettingsView {
+  // The DEPLOYMENT's own hostnames. Setting either of these is what turns host
+  // gating on service-wide; until then every project hostname is stored and
+  // INERT. The UI could not previously read these at all, while the project
+  // hostnames panel told the operator to set them "in the global settings" -
+  // a screen that did not exist.
+  admin_hostname?: string
+  global_hostnames?: string[]
   openai_api_base: string
   openai_api_key_set: boolean
   default_embedding_model: string