Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Permission expansion + Go probe + persisted system info fallback

Juan Denis6e5bccda0138
diff --git a/agent/internal/agent/agent.go b/agent/internal/agent/agent.go
index e9b59402..ee6ffa14 100644
--- a/agent/internal/agent/agent.go
+++ b/agent/internal/agent/agent.go
@@ -613,7 +613,9 @@ func (a *Agent) sendSystemInfo(ctx context.Context) {
Hostname: info.Hostname,
OS: info.OS,
OSVersion: info.PlatformVersion,
+ Platform: info.Platform,
Architecture: info.Architecture,
+ CPUModel: info.CPUModel,
CPUCores: info.CPUThreads, // surface threads as "cores" — matches the panel's existing column
TotalMemory: info.TotalMemory,
TotalDisk: info.TotalDisk,
diff --git a/agent/internal/capabilities/capabilities.go b/agent/internal/capabilities/capabilities.go
index 92232958..7d7e142c 100644
--- a/agent/internal/capabilities/capabilities.go
+++ b/agent/internal/capabilities/capabilities.go
@@ -170,13 +170,26 @@ func probeRuntimes(ctx context.Context) map[string]string {
var versionPattern = regexp.MustCompile(`(\d+\.\d+(?:\.\d+)?)`)
func readVersion(ctx context.Context, bin string) string {
- // java and a few others print version on stderr; capture both.
- cmd := exec.CommandContext(ctx, bin, "--version")
- out, err := cmd.CombinedOutput()
- if err != nil || len(out) == 0 {
- // Some binaries reject "--version" but accept "-version" (java).
- cmd = exec.CommandContext(ctx, bin, "-version")
- out, _ = cmd.CombinedOutput()
+ // Each runtime has its own way to print version. Try a small
+ // allow-list of forms in order; the first non-empty wins.
+ // --version: python, node, php, ruby
+ // -version: java (legacy)
+ // version: go (subcommand, NOT a flag)
+ candidates := [][]string{{"--version"}, {"-version"}, {"version"}}
+ // Special-case go up front so we don't waste two failed forks on
+ // hosts where probing this matters.
+ base := strings.ToLower(filepathBase(bin))
+ if base == "go" || base == "go.exe" {
+ candidates = [][]string{{"version"}, {"--version"}}
+ }
+ var out []byte
+ for _, args := range candidates {
+ cmd := exec.CommandContext(ctx, bin, args...)
+ o, err := cmd.CombinedOutput()
+ if err == nil && len(o) > 0 {
+ out = o
+ break
+ }
}
if len(out) == 0 {
return ""
@@ -190,6 +203,16 @@ func readVersion(ctx context.Context, bin string) string {
return first
}
+// filepathBase mirrors filepath.Base without pulling the import — this
+// file already has plenty.
+func filepathBase(p string) string {
+ p = strings.ReplaceAll(p, "\\", "/")
+ if i := strings.LastIndex(p, "/"); i >= 0 {
+ p = p[i+1:]
+ }
+ return p
+}
+
// probeCron — present if `crontab` is on PATH OR a cron daemon is
// installed (we don't require it to be running; the panel can start it).
func probeCron() bool {
diff --git a/agent/internal/metrics/collector.go b/agent/internal/metrics/collector.go
index e0d53f9e..10e52e9b 100644
--- a/agent/internal/metrics/collector.go
+++ b/agent/internal/metrics/collector.go
@@ -194,7 +194,10 @@ func (c *Collector) GetSystemInfo(ctx context.Context) (*SystemInfo, error) {
info.KernelVersion = hostInfo.KernelVersion
}
- // CPU info
+ // CPU info — gopsutil's WMI/sysctl calls fail intermittently on
+ // some Windows service contexts, so fall back to runtime.NumCPU()
+ // for the count (always non-zero) and leave the model empty
+ // rather than reporting nonsense.
cpuInfo, err := cpu.InfoWithContext(ctx)
if err == nil && len(cpuInfo) > 0 {
info.CPUModel = cpuInfo[0].ModelName
@@ -210,6 +213,14 @@ func (c *Collector) GetSystemInfo(ctx context.Context) (*SystemInfo, error) {
if err == nil {
info.CPUCores = cores
}
+ // Last-resort fallback: runtime.NumCPU is always >= 1 on a
+ // running process. Better than reporting 0 cores.
+ if info.CPUCores == 0 {
+ info.CPUCores = runtime.NumCPU()
+ }
+ if info.CPUThreads == 0 {
+ info.CPUThreads = runtime.NumCPU()
+ }
// Memory
memInfo, err := mem.VirtualMemoryWithContext(ctx)
diff --git a/agent/pkg/protocol/messages.go b/agent/pkg/protocol/messages.go
index 9e341ad8..3938111c 100644
--- a/agent/pkg/protocol/messages.go
+++ b/agent/pkg/protocol/messages.go
@@ -202,15 +202,17 @@ type CapabilitiesMessage struct {
// SystemInfo contains detailed system information
type SystemInfo struct {
- Hostname string `json:"hostname"`
- OS string `json:"os"`
- OSVersion string `json:"os_version"`
- Architecture string `json:"architecture"`
- CPUCores int `json:"cpu_cores"`
- TotalMemory uint64 `json:"total_memory"`
- TotalDisk uint64 `json:"total_disk"`
+ Hostname string `json:"hostname"`
+ OS string `json:"os"`
+ OSVersion string `json:"os_version"`
+ Platform string `json:"platform,omitempty"`
+ Architecture string `json:"architecture"`
+ CPUModel string `json:"cpu_model,omitempty"`
+ CPUCores int `json:"cpu_cores"`
+ TotalMemory uint64 `json:"total_memory"`
+ TotalDisk uint64 `json:"total_disk"`
DockerVersion string `json:"docker_version,omitempty"`
- AgentVersion string `json:"agent_version"`
+ AgentVersion string `json:"agent_version"`
}
// Command actions
diff --git a/backend/app/models/server.py b/backend/app/models/server.py
index 8983fd2f..4ee520f9 100644
--- a/backend/app/models/server.py
+++ b/backend/app/models/server.py
@@ -297,6 +297,18 @@ class Server(db.Model):
return True
return False
+ # Verb tokens that mean "read this thing, don't change it." When the
+ # last component of an action matches one of these, the expander
+ # adds a `<namespace>:read` candidate so a permissions list with
+ # only generic read grants doesn't 403 on a specific list/inspect
+ # call.
+ READ_ACTION_VERBS = {
+ 'list', 'list_installed', 'list_units',
+ 'read', 'get', 'inspect', 'status', 'info',
+ 'search', 'logs', 'stats', 'available',
+ 'installed', 'current', 'show',
+ }
+
@classmethod
def _expand_permission_scope(cls, scope):
"""Add profile and legacy aliases for an agent command scope."""
@@ -322,6 +334,22 @@ class Server(db.Model):
candidate_scopes.add('system:metrics:read')
candidate_scopes.add('system:read')
+ # Generic read-action expansion for the namespaces we added in
+ # later phases (packages, systemd, runtimes, cloudflared, file,
+ # cron). When the leaf verb is a read (list/info/status/etc.),
+ # accept either an exact match, a `<ns>:read`, a `<ns>:*`, or
+ # any of the legacy `<ns>:<sub>:read` variants. Mutating verbs
+ # fall through to require explicit grants.
+ if scope_parts:
+ namespace = scope_parts[0]
+ tail = scope_parts[-1]
+ if tail in cls.READ_ACTION_VERBS:
+ candidate_scopes.add(f'{namespace}:read')
+ if len(scope_parts) >= 2:
+ candidate_scopes.add(f'{namespace}:{scope_parts[1]}:read')
+ else:
+ candidate_scopes.add(f'{namespace}:write')
+
return candidate_scopes
@staticmethod
diff --git a/frontend/src/pages/ServerDetail.jsx b/frontend/src/pages/ServerDetail.jsx
index 92f18d7a..8b1b325d 100644
--- a/frontend/src/pages/ServerDetail.jsx
+++ b/frontend/src/pages/ServerDetail.jsx
@@ -353,15 +353,20 @@ const OverviewTab = ({ server, metrics, systemInfo, onRefreshServer }) => {
<InfoList>
<InfoItem
label="Operating System"
- value={`${systemInfo?.os || server.os_type || 'Unknown'}${systemInfo?.os_version ? ` ${systemInfo.os_version}` : ''}`}
+ value={`${systemInfo?.os || server.os_type || 'Unknown'}${systemInfo?.os_version || server.os_version ? ` ${systemInfo?.os_version || server.os_version}` : ''}`}
/>
<InfoItem label="Architecture" value={systemInfo?.architecture || server.architecture || 'N/A'} />
<InfoItem
label="CPU"
- value={`${systemInfo?.cpu_model || 'N/A'}${systemInfo?.cpu_cores ? ` (${systemInfo.cpu_cores} cores)` : ''}`}
+ value={
+ ((systemInfo?.cpu_model || server.cpu_model) || 'N/A') +
+ (systemInfo?.cpu_cores || server.cpu_cores
+ ? ` (${systemInfo?.cpu_cores || server.cpu_cores} cores)`
+ : '')
+ }
/>
- <InfoItem label="Total Memory" value={formatBytes(systemInfo?.total_memory)} />
- <InfoItem label="Total Disk" value={formatBytes(systemInfo?.total_disk)} />
+ <InfoItem label="Total Memory" value={formatBytes(systemInfo?.total_memory || server.total_memory)} />
+ <InfoItem label="Total Disk" value={formatBytes(systemInfo?.total_disk || server.total_disk)} />
</InfoList>
</div>