run as superuser
Some checks failed
CI / test-build (push) Has been cancelled

This commit is contained in:
2025-12-20 19:29:41 +00:00
parent 6202ef8e83
commit b1a47685f9
4 changed files with 42 additions and 95 deletions

View File

@@ -61,7 +61,7 @@ func (s *NFSService) ApplyConfiguration(exports []models.NFSExport) error {
finalTmpPath := s.exportsPath + ".atlas.tmp"
// Use sudo tee to write directly to /etc (requires root permissions)
teeCmd := exec.Command("sudo", "-n", "tee", finalTmpPath)
teeCmd := exec.Command("tee", finalTmpPath)
teeCmd.Stdin = strings.NewReader(config)
var teeStderr bytes.Buffer
teeCmd.Stderr = &teeStderr
@@ -73,13 +73,13 @@ func (s *NFSService) ApplyConfiguration(exports []models.NFSExport) error {
}
// Set proper permissions on temp file
chmodCmd := exec.Command("sudo", "-n", "chmod", "644", finalTmpPath)
chmodCmd := exec.Command("chmod", "644", finalTmpPath)
_ = chmodCmd.Run() // Ignore errors, might already have correct permissions
// Backup existing exports using sudo
backupPath := s.exportsPath + ".backup"
if _, err := os.Stat(s.exportsPath); err == nil {
cpCmd := exec.Command("sudo", "-n", "cp", s.exportsPath, backupPath)
cpCmd := exec.Command("cp", s.exportsPath, backupPath)
if err := cpCmd.Run(); err != nil {
// Non-fatal, log but continue
// Try direct copy as fallback
@@ -89,7 +89,7 @@ func (s *NFSService) ApplyConfiguration(exports []models.NFSExport) error {
// Atomically replace exports file using sudo
// Use cp + rm instead of mv for better cross-device compatibility
cpCmd := exec.Command("sudo", "-n", "cp", finalTmpPath, s.exportsPath)
cpCmd := exec.Command("cp", finalTmpPath, s.exportsPath)
cpStderr := bytes.Buffer{}
cpCmd.Stderr = &cpStderr
if err := cpCmd.Run(); err != nil {
@@ -100,7 +100,7 @@ func (s *NFSService) ApplyConfiguration(exports []models.NFSExport) error {
}
// Remove temp file after successful copy
rmCmd := exec.Command("sudo", "-n", "rm", "-f", finalTmpPath)
rmCmd := exec.Command("rm", "-f", finalTmpPath)
_ = rmCmd.Run() // Ignore errors, file might not exist
// Reload NFS exports with error recovery
@@ -163,7 +163,7 @@ func (s *NFSService) generateExports(exports []models.NFSExport) (string, error)
func (s *NFSService) reloadExports() error {
// Use exportfs -ra to reload all exports (requires root)
// Try with sudo first
cmd := exec.Command("sudo", "-n", "exportfs", "-ra")
cmd := exec.Command("exportfs", "-ra")
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
@@ -239,7 +239,7 @@ func (s *NFSService) applyZFSShareNFS(exports []models.NFSExport) error {
for _, export := range exports {
if !export.Enabled {
// Disable sharenfs for disabled exports
cmd := exec.Command("sudo", "-n", zfsPath, "set", "sharenfs=off", export.Dataset)
cmd := exec.Command(zfsPath, "set", "sharenfs=off", export.Dataset)
if err := cmd.Run(); err != nil {
// Log but continue - might not have permission or dataset doesn't exist
continue
@@ -310,7 +310,7 @@ func (s *NFSService) applyZFSShareNFS(exports []models.NFSExport) error {
}
// Set sharenfs property using sudo (atlas user has permission via sudoers)
cmd := exec.Command("sudo", "-n", zfsPath, "set", fmt.Sprintf("sharenfs=%s", sharenfsValue.String()), export.Dataset)
cmd := exec.Command(zfsPath, "set", fmt.Sprintf("sharenfs=%s", sharenfsValue.String()), export.Dataset)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {