Commit 6795119f authored by Marco Mariani's avatar Marco Mariani

Check that 'slapos node' commands are run as root.

parent fa924818
......@@ -2,6 +2,7 @@
import logging
from slapos.cli.command import must_be_root
from slapos.cli.config import ConfigCommand
from slapos.bang import do_bang
......@@ -19,6 +20,7 @@ class BangCommand(ConfigCommand):
help='Message for bang')
return ap
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
do_bang(configp, args.message)
# -*- coding: utf-8 -*-
import argparse
import functools
import os
import sys
import cliff
class Command(cliff.command.Command):
def get_parser(self, prog_name):
parser = argparse.ArgumentParser(
description=self.get_description(),
......@@ -14,3 +18,12 @@ class Command(cliff.command.Command):
)
return parser
def must_be_root(func):
@functools.wraps(func)
def func(self, *args, **kw):
if os.getuid() != 0:
self.app.log.error('This slapos command must be run as root.')
sys.exit(5)
return func
......@@ -3,6 +3,7 @@
import logging
import sys
from slapos.cli.command import must_be_root
from slapos.cli.config import ConfigCommand
from slapos.format import do_format, FormatConfig, tracing_monkeypatch, UsageError
......@@ -55,6 +56,7 @@ class FormatCommand(ConfigCommand):
return ap
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
......
......@@ -3,7 +3,7 @@
import logging
import sys
from slapos.cli.command import Command
from slapos.cli.command import Command, must_be_root
from slapos.register.register import do_register, RegisterConfig
......@@ -66,6 +66,7 @@ class RegisterCommand(Command):
return ap
@must_be_root
def take_action(self, args):
try:
conf = RegisterConfig(logger=self.log)
......
......@@ -2,6 +2,7 @@
import logging
from slapos.cli.command import must_be_root
from slapos.cli.config import ConfigCommand
from slapos.grid.utils import setRunning, setFinished
......@@ -57,6 +58,7 @@ class SlapgridCommand(ConfigCommand):
help='Launch slapgrid without delay. Default behavior.')
return ap
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
options = merged_options(args, configp)
......
......@@ -4,6 +4,7 @@ import argparse
import logging
import os
from slapos.cli.command import must_be_root
from slapos.cli.config import ConfigCommand
from slapos.grid.svcbackend import launchSupervisord
......@@ -22,6 +23,7 @@ class SupervisorctlCommand(ConfigCommand):
help='parameters passed to supervisorctl')
return ap
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
instance_root = configp.get('slapos', 'instance_root')
......
......@@ -3,6 +3,7 @@
import logging
import os
from slapos.cli.command import must_be_root
from slapos.cli.config import ConfigCommand
from slapos.grid.svcbackend import launchSupervisord
......@@ -12,6 +13,7 @@ class SupervisordCommand(ConfigCommand):
log = logging.getLogger('supervisord')
@must_be_root
def take_action(self, args):
configp = self.fetch_config(args)
instance_root = configp.get('slapos', 'instance_root')
......
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