def testModeSudo( self ): assert not cuisine.mode(cuisine.MODE_SUDO) cuisine.mode_sudo() assert cuisine.mode(cuisine.MODE_SUDO) cuisine.mode_user() assert not cuisine.mode(cuisine.MODE_SUDO) # We use the mode changer to switch to sudo temporarily with cuisine.mode_sudo(): assert cuisine.mode(cuisine.MODE_SUDO) assert cuisine.mode(cuisine.MODE_LOCAL) # We go into sudo from sudo with cuisine.mode_sudo(): assert cuisine.mode(cuisine.MODE_SUDO)
def testModeSudo(self): assert not cuisine.mode(cuisine.MODE_SUDO) cuisine.mode_sudo() assert cuisine.mode(cuisine.MODE_SUDO) cuisine.mode_user() assert not cuisine.mode(cuisine.MODE_SUDO) # We use the mode changer to switch to sudo temporarily with cuisine.mode_sudo(): assert cuisine.mode(cuisine.MODE_SUDO) assert cuisine.mode(cuisine.MODE_LOCAL) # We go into sudo from sudo with cuisine.mode_sudo(): assert cuisine.mode(cuisine.MODE_SUDO)
def initialize(): """Log in to the server as root and create the initial user/group""" env.user = '******' mode_user() group_ensure(env.remote_group) user_ensure(env.remote_user, shell='/bin/bash') group_user_ensure(env.remote_user, env.remote_group) # copy local public key to user's authorized_keys for convenience if os.path.exists('~/.ssh/id_rsa.pub'): f = open('~/.ssh/id_rsa.pub', 'rb') ssh_authorize(env.remote_user, f.read()) f.close() file_append("/etc/sudoers", "%(remote_user)s ALL=(ALL) NOPASSWD:ALL\n" % env)
def sudo_ensure(): """Ensure the 'sudo' command is installed""" select_package("apt") with mode_user(): # The below works but is too slow # run("apt-get update") # run("apt-get install sudo") package_ensure(["sudo"]) # No idea why this didn't work
def main(): options = CollectlParseOptions() if options.check_database_connection: PostgresCollectlSqlDumper(options) if options.remote_host: env.user = options.remote_user env.host_string = options.remote_host env.key_filename = options.ssh_key env.disable_known_hosts = True mode_user() else: print "Mode local" mode_local() if options.scan: for host in options.hosts: print "Handling host %s" % host CollectlDirectoryScanner(options, host).execute()
def sudo_ensure(): """Ensure the 'sudo' command is installed""" select_package("apt") with mode_user(): # The below works but is too slow #run("apt-get update") #run("apt-get install sudo") package_ensure(["sudo"]) # No idea why this didn't work
def testSudoApplication( self ): tmpdir = tempfile.mkdtemp() try: with cd(tmpdir), cuisine.mode_sudo(): cuisine.run('echo "test" > test.txt') cuisine.run('chmod 0600 test.txt') with cd(tmpdir), cuisine.mode_user(), settings(warn_only=True): listing = cuisine.run('ls -la test.txt').split() self.assertEqual('root', listing[2]) # user self.assertEqual('root', listing[3]) # group result = cuisine.run('cat test.txt') self.assertTrue(result.failed) self.assertIn('Permission denied', result) finally: shutil.rmtree(tmpdir)