Skip to content
Snippets Groups Projects
Commit f0f7d444 authored by Romain Foucault's avatar Romain Foucault Committed by GitHub
Browse files

Merge pull request #278 from nono/drop-root

Prevent running cozy-stack serve as root accidentally
parents a4f7723f 8a3ea3e3
No related merge requests found
package cmd package cmd
import ( import (
"errors"
"os"
log "github.com/Sirupsen/logrus"
"github.com/cozy/cozy-stack/pkg/instance" "github.com/cozy/cozy-stack/pkg/instance"
"github.com/cozy/cozy-stack/web" "github.com/cozy/cozy-stack/web"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var flagAllowRoot bool
// serveCmd represents the serve command // serveCmd represents the serve command
var serveCmd = &cobra.Command{ var serveCmd = &cobra.Command{
Use: "serve", Use: "serve",
...@@ -14,6 +20,10 @@ var serveCmd = &cobra.Command{ ...@@ -14,6 +20,10 @@ var serveCmd = &cobra.Command{
It will accept HTTP requests on localhost:8080 by default. It will accept HTTP requests on localhost:8080 by default.
Use the --port and --host flags to change the listening option.`, Use the --port and --host flags to change the listening option.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
if !flagAllowRoot && os.Getuid() == 0 {
log.Errorf("Use --allow-root if you really want to start with the root user")
return errors.New("Starting cozy-stack serve as root not allowed")
}
if err := instance.StartJobs(); err != nil { if err := instance.StartJobs(); err != nil {
return err return err
} }
...@@ -38,4 +48,5 @@ var serveAppDir = &cobra.Command{ ...@@ -38,4 +48,5 @@ var serveAppDir = &cobra.Command{
func init() { func init() {
RootCmd.AddCommand(serveCmd) RootCmd.AddCommand(serveCmd)
RootCmd.AddCommand(serveAppDir) RootCmd.AddCommand(serveAppDir)
serveCmd.Flags().BoolVar(&flagAllowRoot, "allow-root", false, "Allow to start as root (disabled by default)")
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment