Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Add simple check for root permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
twelho committed Jun 10, 2019
1 parent b2db0c0 commit 6adbfa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,22 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
Use: "ignite",
Short: "ignite: easily run Firecracker VMs",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Ignite needs to run as root for now, see
// https://github.com/weaveworks/ignite/issues/46
// TODO: Remove this when ready
ok, err := util.TestRoot()
if err != nil {
panic(err)
} else if !ok {
fmt.Println("This program needs to run as root.")
os.Exit(1)
}

// TODO: Handle this error more softly?
if err := util.CreateDirectories(); err != nil {
panic(err)
}

logs.InitLogs()
},
Long: dedent.Dedent(fmt.Sprintf(`
Expand Down
10 changes: 10 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"os/exec"
"os/user"
"path"
"strings"
"time"
Expand Down Expand Up @@ -171,3 +172,12 @@ func MatchPrefix(prefix string, fields ...string) []string {

return prefixMatches
}

func TestRoot() (bool, error) {
user, err := user.Current()
if err != nil {
return false, err
}

return user.Uid == "0", nil
}

0 comments on commit 6adbfa2

Please sign in to comment.