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

rootless must be root

parent 3be6c25c
......@@ -5,7 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"os/user"
"github.com/urfave/cli/v2"
)
......@@ -32,6 +32,7 @@ func (m rootlessCommand) build() *cli.Command {
c := cli.Command{
Name: "rootless",
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) },
}
......@@ -48,6 +49,15 @@ func (m rootlessCommand) build() *cli.Command {
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 {
runtime := opts.runtime
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