feat(system): consolidate system admin and settings into one Settings panel
Replace the standalone /platform/system/* routes with a single
"系统设置" section inside the canonical Settings modal. The previous
SystemLayout.vue / SystemAdmins.vue surfaces are removed and their
functionality (system admin roster, global settings) is hosted directly
in SystemSettings.vue under the standard `.section-header` /
`.settings-group` skeleton. Legacy URLs redirect to the modal section
so external bookmarks don't 404.
Backend:
- SystemSettingService.Reset + repo.Delete: drop the DB override for a
key so the 3-tier resolver falls back to ENV / built-in default.
Idempotent (resetting a never-persisted key returns nil); emits an
audit row only on real deletions, invalidates the local cache, and
publishes to peers via the existing pubsub channel.
- TenantService.BulkSetStorageQuota: overwrite every tenant's
storage_quota in one statement. Powers POST /system/admin/tenants/
apply-default-storage-quota; bypasses the per-tenant whitelist on
PUT /tenants/:id which intentionally forbids storage_quota edits.
- AuditAction{SystemAdminPromoted,SystemAdminRevoked} constants and
emitAdminAudit() in SystemHandler — promote / revoke now leave an
audit trail with TenantID=0 and {target_email,target_username,
idempotent|changed} in details.
- SystemSetting.LastModifiedByName: derived per-request display label
(username, email fallback) so the UI shows "wizardchen" instead of
a UUID prefix without storing a denormalised column.
Frontend:
- SystemSettings.vue rewritten against the Settings modal skeleton with
auto-persisting controls (switch/select @change, input/inputnumber
@blur, tag-input + per-delta popconfirm for SSRF whitelist and admin
roster). auth.registration_mode change goes through an inline
popconfirm; cancel rolls back. Reset / bulk-apply also inline
popconfirms — no dialog modal for these per-row affordances.
- Priority hint panel surfaces the DB > ENV > default resolver order
so operators can reason about "I set the env but it doesn't show up".
- Router: /platform/system, /platform/system/settings, /platform/system/
admins are now compatibility redirects to /platform/settings?section=
system-global.
- Settings modal sized 900x700 → 1080x780 and content-wrapper 600 → 760
so the wider tables (members, system settings) breathe; <1100px
viewport still flexes to the screen.
- i18n: system.globalSettings.* keys for title / description / loading /
empty / badges / priority hint / per-key labels / reset / bulkApply /
admins (label, placeholder, save messages, popconfirm copy) across
zh-CN, en-US, ko-KR, ru-RU.
Misc:
- internal/utils/filesize.go doc: clarify MAX_FILE_SIZE_MB is a
deploy-time-only knob (nginx + docreader + frontend each cache the
env at startup); a SystemAdmin UI override would mislead operators
because nginx would still 413. Until all four layers can hot-reload
the limit in lockstep, this stays env-only.
- internal/utils/security.go: SSRF whitelist parser/runtime now drives
off SystemSettingService for live updates; ENV remains the fallback
for never-overridden deployments.
This commit is contained in:
+12
-15
@@ -8,22 +8,19 @@ import (
|
||||
// GetMaxFileSize returns the maximum file upload size in bytes.
|
||||
// Default is 50MB, can be configured via MAX_FILE_SIZE_MB environment variable.
|
||||
//
|
||||
// This is the legacy ENV-only entry point. Handlers wired with
|
||||
// interfaces.SystemSettingService should prefer reading the 3-tier
|
||||
// resolver directly:
|
||||
// MAX_FILE_SIZE_MB is intentionally a deploy-time-only knob (NOT a
|
||||
// runtime system_setting). The effective upload limit is gated by
|
||||
// three other layers that all read this env at startup and cache the
|
||||
// value:
|
||||
// - frontend nginx client_max_body_size (envsubst into nginx.conf)
|
||||
// - docreader gRPC max_send/recv_message_length
|
||||
// - frontend client-side check via window.__RUNTIME_CONFIG__
|
||||
//
|
||||
// mb := h.systemSettingSvc.GetInt(ctx, "file.max_size_mb", "MAX_FILE_SIZE_MB", 50)
|
||||
// maxBytes := mb * 1024 * 1024
|
||||
//
|
||||
// That way SystemAdmin's UI override (DB row in system_settings) takes
|
||||
// precedence over the ENV value. This function is kept for unit tests
|
||||
// and any non-handler call sites that don't have the service injected;
|
||||
// it never sees DB values, only ENV.
|
||||
//
|
||||
// We deliberately don't expose a "service-aware" wrapper here because
|
||||
// internal/types depends on internal/utils — wrapping it would create
|
||||
// an import cycle. Call sites that have a SystemSettingService should
|
||||
// just use it directly (it's only one extra line).
|
||||
// Surfacing a SystemAdmin UI knob whose effect is silently capped by
|
||||
// any of the above would mislead operators ("I raised it to 200MB but
|
||||
// nginx still returns 413"). Until all four layers can be reconfigured
|
||||
// in lockstep without container restarts, every call site must read
|
||||
// the env directly via this helper.
|
||||
func GetMaxFileSize() int64 {
|
||||
if sizeStr := os.Getenv("MAX_FILE_SIZE_MB"); sizeStr != "" {
|
||||
if size, err := strconv.ParseInt(sizeStr, 10, 64); err == nil && size > 0 {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -935,6 +936,17 @@ func SetSSRFWhitelistFromRaw(raw string) {
|
||||
// parseSSRFWhitelistRaw parses a comma-separated whitelist string into
|
||||
// a config struct. Pure function; no env reads. Always returns a
|
||||
// non-nil pointer so callers can blindly Load.
|
||||
//
|
||||
// Invalid entries (malformed CIDR like "10.0.0.0/333", wildcards
|
||||
// without a "*." prefix, etc.) are dropped with a `[ssrf-whitelist]`
|
||||
// log line rather than silently falling through to the exact-host
|
||||
// branch. Falling through used to turn "10.0.0.0/333" into a literal
|
||||
// host string that never matches anything — operators would believe
|
||||
// the entry was active when in reality their SSRF check was unchanged.
|
||||
//
|
||||
// Callers that want hard rejection (e.g. ValidateSSRFWhitelistEntries
|
||||
// for the system_settings Update path) should pre-validate before
|
||||
// passing the raw string here.
|
||||
func parseSSRFWhitelistRaw(raw string) *ssrfWhitelistConfig {
|
||||
cfg := &ssrfWhitelistConfig{
|
||||
exactHosts: make(map[string]bool),
|
||||
@@ -947,26 +959,80 @@ func parseSSRFWhitelistRaw(raw string) *ssrfWhitelistConfig {
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
// CIDR range
|
||||
// CIDR range — entries containing '/' are exclusively CIDRs.
|
||||
// A parse failure must NOT fall through to the exact-host
|
||||
// branch (which would store "10.0.0.0/333" as a literal
|
||||
// hostname that can never match anything).
|
||||
if strings.Contains(entry, "/") {
|
||||
_, ipNet, err := net.ParseCIDR(entry)
|
||||
if err == nil {
|
||||
cfg.cidrNets = append(cfg.cidrNets, ipNet)
|
||||
if err != nil {
|
||||
log.Printf("[ssrf-whitelist] dropping invalid CIDR entry %q: %v", entry, err)
|
||||
continue
|
||||
}
|
||||
cfg.cidrNets = append(cfg.cidrNets, ipNet)
|
||||
continue
|
||||
}
|
||||
// Wildcard domain: *.example.com
|
||||
if strings.HasPrefix(entry, "*.") {
|
||||
suffix := strings.ToLower(entry[1:]) // ".example.com"
|
||||
if len(suffix) <= 1 {
|
||||
log.Printf("[ssrf-whitelist] dropping bare wildcard entry %q (need *.<domain>)", entry)
|
||||
continue
|
||||
}
|
||||
cfg.suffixHosts = append(cfg.suffixHosts, suffix)
|
||||
continue
|
||||
}
|
||||
// Reject mid-string wildcards like "foo.*.bar" — they look
|
||||
// useful but neither parseSSRFWhitelistRaw nor IsSSRFWhitelisted
|
||||
// implement glob matching, so the entry would silently never
|
||||
// match. Surface it loudly.
|
||||
if strings.Contains(entry, "*") {
|
||||
log.Printf("[ssrf-whitelist] dropping unsupported wildcard pattern %q (only \"*.\" prefix is supported)", entry)
|
||||
continue
|
||||
}
|
||||
// Exact host or IP
|
||||
cfg.exactHosts[strings.ToLower(entry)] = true
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
// ValidateSSRFWhitelistEntries returns nil when every entry in `entries`
|
||||
// would be accepted by parseSSRFWhitelistRaw, or an error describing
|
||||
// the first malformed entry. Used by the system_settings Update path
|
||||
// to give the UI a clear 400 instead of silently dropping bad input
|
||||
// at parse-time.
|
||||
//
|
||||
// Validation rules mirror parseSSRFWhitelistRaw exactly:
|
||||
// - "<a>/<b>" must be a valid CIDR
|
||||
// - "*.<domain>" must have a non-empty domain after the prefix
|
||||
// - mid-string "*" is not supported
|
||||
// - everything else is treated as an exact host or literal IP
|
||||
// (we don't pre-resolve DNS here; that's a runtime concern)
|
||||
func ValidateSSRFWhitelistEntries(entries []string) error {
|
||||
for _, entry := range entries {
|
||||
entry = strings.TrimSpace(entry)
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(entry, "/") {
|
||||
if _, _, err := net.ParseCIDR(entry); err != nil {
|
||||
return fmt.Errorf("invalid CIDR %q: %w", entry, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(entry, "*.") {
|
||||
if len(entry) <= 2 {
|
||||
return fmt.Errorf("wildcard entry %q is missing a domain (use *.example.com)", entry)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if strings.Contains(entry, "*") {
|
||||
return fmt.Errorf("wildcard pattern %q is not supported (only the \"*.\" prefix is allowed)", entry)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// mergeSSRFWhitelistRaws joins two comma-separated raw strings, dropping
|
||||
// the comma when one side is empty. Exposed for the service layer's
|
||||
// "merge SSRF_WHITELIST_EXTRA into the DB-backed list" code path.
|
||||
|
||||
Reference in New Issue
Block a user