Admin Config Visualization
The Admin console now ships a structured configuration editor that replaces the raw YAML textarea with field-typed controls, live validation, save-time diff review, historical revision rollback, and a runtime override layer for temporary changes.
Goals
- Structured form editing for
FileConfig, instead of editing YAML by hand. - Live validation as fields are touched; errors are surfaced with field paths (e.g.
clients[2].clientSecret). - Diff preview before save and a revision history with rollback.
- Runtime override layer for in-process, non-persistent changes (e.g. temporarily raise a client's bandwidth).
- Session ↔ config match view that tells operators which YAML entry each online tunnel maps to.
Architecture
API
All endpoints live under /api/v1. Errors are returned as {"ok": false, "error": "..."}.
| Method | Path | Purpose |
|---|---|---|
| GET | /config | Returns parsed FileConfig. ?maskSecrets=false to include secrets. |
| GET | /config/raw | Returns the on-disk YAML. |
| GET | /config/schema | Returns UI schema groups & fields. |
| POST | /config/validate | {"yaml": "..."} → {ok, errors[]} (no write). |
| PUT | /config | {"yaml", "summary"} → writes, persists revision, audits diff, reloads. |
| GET | /config/revisions | Most recent revisions, newest first. |
| GET | /config/revisions/:id | One revision (includes full YAML). |
| POST | /config/revisions/:id/restore | Restores a revision; creates a new revision that records the lineage. |
| GET | /overrides | Active override patches. |
| PUT | /overrides | {"path", "value"} → sets a runtime override. |
| DELETE | /overrides/clear-all | Wipes all runtime overrides. |
| DELETE | /overrides/{path} | Removes one runtime override. |
Structured form (PR-1)
internal/server/config/validate.goexposesValidationError {Path, Message}and aValidateWithDetails(*FileConfig) []ValidationErrorfunction. The legacyValidateis preserved (nowerrors.Joinof the structured errors).internal/server/admin/handler/api.goaddsPOST /config/validateandGET /config/schema.internal/server/admin/service/schema.goreturns a staticConfigSchemadescription (groups + field definitions). It is pure (no file I/O), so it's trivially unit-tested.- Front-end (
admin/src/schema/renderers.tsx) renders typed controls:string,int,port,bool,enum,duration,secret, plus aCardListfor arrays of clients and tunnels. admin/src/schema/serialize.tsroundtrips structuredvaluesto YAML. Comments are intentionally not preserved (YAML library limitation); an "escape hatch" YAML tab remains for users who need to keep comments.
Secret handling
Secrets are masked on GET /api/v1/config by default. The admin UI uses ?maskSecrets=false to fetch the full document and stores the unmasked values in a React useRef for the duration of the edit session. The form widget renders *** for secret fields; on submit the original unmasked value is re-filled into the YAML before it is sent to the server. Emptying the field is treated as an explicit deletion.
Pass-through for unknown fields
The schema does not enumerate every possible key in the YAML. When the structured form serializes its values back, fields that aren't in the schema are preserved from the source YAML verbatim. This keeps the editor working as new fields are added to the Go config without forcing a frontend release.
Diff preview & history (PR-2)
AuditLoggains aDiffcolumn.Audit.Recordaccepts an optional diff string (""means none).- A new
ConfigRevisiontable stores append-only snapshots of the YAML. The most recent 200 are kept; older ones are trimmed by an opportunisticcleanup()after each save. ConfigService.SaveRaw(in SaveRawInput) (*SaveRawResult, error)writes the revision first, then atomically writes the file viaSaveRawAtomic, then triggersManager.Reload. If the file write fails, the orphan revision row is overwritten on the next save.ConfigService.Restore(revID, in)writes a new revision withsummary="restored from #N"and audits the lineage ({"fromId":N,"toId":M}in theDiffcolumn).- The save flow in the UI shows a diff modal (red/green/gray per line) before committing, and the Revisions panel on the right shows the last 20 snapshots, each with a one-click restore (with a revert diff confirmation).
Runtime override layer (PR-3)
internal/server/config/override.godefinesOverride { patches map[string]json.RawMessage }withSet/Get/Delete/ClearAll/List/Apply.- Patches are addressed by JSON-pointer-like paths:
clients[0].clientSecret,publicHTTPNoAuth.timeout,domain, etc. Setvalidates that the path resolves against a zero-valuedFileConfig; unknown paths fail-fast at API time, not at apply time.Apply(base)deep-copiesbasevia JSON round-trip and writes the patches into the copy. The original*FileConfigis never mutated.Manager.EffectiveConfig()returnsoverride.Apply(ref.Get()); the reload callback uses this to apply overrides without the cost of copying on everyGet.- The Status page shows a yellow banner whenever there is at least one active override. The Config page has a dedicated "Override" tab where patches can be added, listed, removed, or cleared in bulk.
- Concurrency:
Overrideuses async.RWMutex. Tested under-racewith concurrentSet/Apply/Delete/ClearAll.
Sessions ↔ config match (PR-4)
SessionViewgainsConfigIndex,ConfigMatch(exact/partial/missing), andMatchIssues.Monitor.matchSessionwalkscfg.Clientsto find the index whoseClientIDmatchestm.ClientId. Sessions withanonymous-*ids are reported as missing.- The match column in the Sessions page is filterable (all / exact / partial / missing). Click on a row's config cell to see the issue text in a tooltip ("client secret in YAML is empty", "client id not in YAML", etc.).
- Secrets are never compared or displayed: only the configured secret is referenced. A session that successfully authenticated is reported as
exact, even if the YAML was later edited.
Risks & limitations
| Risk | Mitigation |
|---|---|
| YAML comments lost on round-trip | The "YAML 源" tab is preserved as an escape hatch for users who need to keep comments. |
| Override ↔ Ref concurrency | Override.Apply deep-copies the base; *FileConfig is never mutated. Tested under -race. |
| Revision table growth | Opportunistic cleanup() keeps ≤200 rows. Configurable via admin.revisions.maxKeep. |
| Accidentally changing a secret | Diff preview, type-to-confirm secret field, audit diff not stored when caller passes masked content. |
| New Go config fields without UI | Pass-through preserves unrecognized fields in the source YAML. |
SaveRaw non-atomic between SQLite and file | Documented; failure window is between the two writes; the next save overwrites the orphan revision. |