Skip to content

Commit 553efe5

Browse files
committed
Abort as soon as possible when running as root
Signed-off-by: Jan Dubois <[email protected]>
1 parent b9b9aa6 commit 553efe5

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cmd/limactl/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const (
3333
)
3434

3535
func main() {
36+
if os.Geteuid() == 0 && (len(os.Args) < 2 || os.Args[1] != "generate-doc") {
37+
panic("must not run as the root user")
38+
}
39+
3640
yq.MaybeRunYQ()
3741
if runtime.GOOS == "windows" {
3842
extras, hasExtra := os.LookupEnv("_LIMA_WINDOWS_EXTRA_PATH")
@@ -128,9 +132,6 @@ func newApp() *cobra.Command {
128132
return errors.New("limactl is running under rosetta, please reinstall lima with native arch")
129133
}
130134

131-
if os.Geteuid() == 0 && cmd.Name() != "generate-doc" {
132-
return errors.New("must not run as the root user")
133-
}
134135
// Make sure either $HOME or $LIMA_HOME is defined, so we don't need
135136
// to check for errors later
136137
dir, err := dirnames.LimaDir()

0 commit comments

Comments
 (0)