Commit 717e8cd7 authored by songlinfeng's avatar songlinfeng
Browse files

rootless must be root

parent 3be6c25c
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"os/user"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
...@@ -32,6 +32,7 @@ func (m rootlessCommand) build() *cli.Command { ...@@ -32,6 +32,7 @@ func (m rootlessCommand) build() *cli.Command {
c := cli.Command{ c := cli.Command{
Name: "rootless", Name: "rootless",
Usage: "Provide tools for configuring rootless container runtimes", Usage: "Provide tools for configuring rootless container runtimes",
Before: func(ctx *cli.Context) error { return validateGenOptions(ctx) },
Action: func(ctx *cli.Context) error { return run(ctx, &opts) }, Action: func(ctx *cli.Context) error { return run(ctx, &opts) },
} }
...@@ -48,6 +49,15 @@ func (m rootlessCommand) build() *cli.Command { ...@@ -48,6 +49,15 @@ func (m rootlessCommand) build() *cli.Command {
return &c return &c
} }
func validateGenOptions(c *cli.Context) error {
curUser, err := user.Current()
if err != nil || curUser.Uid != "0" {
return fmt.Errorf("Permission denied: Not running as root")
}
return nil
}
func run(c *cli.Context, opts *options) error { func run(c *cli.Context, opts *options) error {
runtime := opts.runtime runtime := opts.runtime
if runtime != "docker" && runtime != "podman" { if runtime != "docker" && runtime != "podman" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment