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

Commit

Permalink
Merge pull request vitessio#5644 from RickyRajinder/root-exec-protection
Browse files Browse the repository at this point in the history
Add execute as root check to mysqlctl
  • Loading branch information
morgo authored Jan 2, 2020
2 parents 0d4f04f + 53583c7 commit 6d5f332
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/cmd/mysqlctl/mysqlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"golang.org/x/net/context"

"vitess.io/vitess/go/cmd"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/flagutil"
"vitess.io/vitess/go/mysql"
Expand Down Expand Up @@ -235,6 +236,10 @@ func main() {
fmt.Fprintf(os.Stderr, "\n")
}

if cmd.IsRunningAsRoot() {
fmt.Fprintln(os.Stderr, "mysqlctl cannot be ran as root. Please run as a different user")
exit.Return(1)
}
dbconfigs.RegisterFlags(dbconfigs.Dba)
flag.Parse()

Expand Down
6 changes: 6 additions & 0 deletions go/cmd/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"os/exec"
"strings"
"syscall"
)

// DetachFromTerminalAndExit allows a command line program to detach from the terminal and continue running
Expand All @@ -41,3 +42,8 @@ func DetachFromTerminalAndExit() {
fmt.Println("[PID]", cmd.Process.Pid)
os.Exit(0)
}

// IsRunningAsRoot checks if a component is being ran as root
func IsRunningAsRoot() bool {
return syscall.Geteuid() == 0
}

0 comments on commit 6d5f332

Please sign in to comment.