Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

1.2 KB
Raw Blame
package hostagent

import (
	"os"
	"os/user"
	"strings"

	agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
)

// collectPrivilegeStatus reports the privilege the agent actually runs with.
// The values are facts about this process, not configuration: effective uid,
// the service account name, and whether the scoped privilege-helper overrides
// a least-privilege install configures are in effect. On Windows Geteuid is
// always -1, so RunningAsRoot stays false and ServiceUser carries the account
// name; the server renders the profile descriptively rather than judging it.
func collectPrivilegeStatus(commandAuthority CommandAuthorityProfile) *agentshost.PrivilegeStatus {
	status := &agentshost.PrivilegeStatus{
		RunningAsRoot:    os.Geteuid() == 0,
		CommandAuthority: string(commandAuthority),
		TypedHelper:      strings.TrimSpace(os.Getenv("PULSE_AGENT_HELPER_SOCKET")) != "",
		SmartctlHelper:   strings.TrimSpace(os.Getenv("PULSE_SMARTCTL_PATH")) != "",
		PctHelper:        strings.TrimSpace(os.Getenv("PULSE_PCT_PATH")) != "",
	}
	if current, err := user.Current(); err == nil {
		status.ServiceUser = strings.TrimSpace(current.Username)
	}
	return status
}