Skip to content

Commit 4e0f45a

Browse files
authored
fix: refuse to run as root (#632)
1 parent d396e9c commit 4e0f45a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cmd/arduino-app-cli/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ func main() {
8181
if err != nil {
8282
feedback.Fatal(fmt.Sprintf("invalid config: %s", err), feedback.ErrGeneric)
8383
}
84+
85+
if os.Geteuid() == 0 && !configuration.AllowRoot {
86+
feedback.Fatal("arduino-app-cli must not be run as root. Try `su - arduino` before this command.", feedback.ErrGeneric)
87+
}
88+
8489
if err := run(configuration); err != nil {
8590
feedback.FatalError(err, 1)
8691
}

internal/orchestrator/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log/slog"
66
"os"
77
"path"
8+
"strconv"
89
"strings"
910

1011
"github.com/arduino/go-paths-helper"
@@ -22,6 +23,7 @@ type Configuration struct {
2223
PythonImage string
2324
UsedPythonImageTag string
2425
RunnerVersion string
26+
AllowRoot bool
2527
}
2628

2729
func NewFromEnv() (Configuration, error) {
@@ -90,6 +92,11 @@ func NewFromEnv() (Configuration, error) {
9092
pythonImage, usedPythonImageTag := getPythonImageAndTag()
9193
slog.Debug("Using pythonImage", slog.String("image", pythonImage))
9294

95+
allowRoot, err := strconv.ParseBool(os.Getenv("ARDUINO_APP_CLI__ALLOW_ROOT"))
96+
if err != nil {
97+
allowRoot = false
98+
}
99+
93100
c := Configuration{
94101
appsDir: appsDir,
95102
configDir: configDir,
@@ -99,6 +106,7 @@ func NewFromEnv() (Configuration, error) {
99106
PythonImage: pythonImage,
100107
UsedPythonImageTag: usedPythonImageTag,
101108
RunnerVersion: runnerVersion,
109+
AllowRoot: allowRoot,
102110
}
103111
if err := c.init(); err != nil {
104112
return Configuration{}, err

0 commit comments

Comments
 (0)