From ce423165ca5ce124eaf97936adebc8a179f40011 Mon Sep 17 00:00:00 2001 From: Martin Magr Date: Wed, 11 Dec 2013 13:25:36 +0100 Subject: [PATCH] Revert "Move packstack logs to /var/log/packstack" Due to security reasons. This reverts commit 075eb3f5a80bc2ec881a80ff56e3190843886d03. Change-Id: Ie12d3a57d9d25cb5d89c88e7761b1b8db7793b06 --- packstack/installer/basedefs.py | 72 ++++++++++---------------------- packstack/installer/run_setup.py | 2 +- packstack/plugins/puppet_950.py | 2 +- 3 files changed, 24 insertions(+), 52 deletions(-) diff --git a/packstack/installer/basedefs.py b/packstack/installer/basedefs.py index 1f3f665d3..d4d38d89a 100644 --- a/packstack/installer/basedefs.py +++ b/packstack/installer/basedefs.py @@ -9,66 +9,38 @@ import pwd import sys import datetime import tempfile -import random -import string -import errno -import logging from .utils import get_current_user -# Iinitializes the directory by creating it or -# changing ownsership it already exists. -# in case there's a problem it falls back to the -# default directory -# returns the name of the created directory -def init_directory(dirname, force_ownership=True): - try: - os.makedirs(dirname, 0700) - except OSError as e: - if e.errno == errno.EEXIST and os.path.isdir(dirname): - # directory is already created, check ownership - stat = os.stat(dirname) - if (force_ownership and stat.st_uid == 0 and - os.getuid() != stat.st_uid): - print ('%s is already created and owned by root. Please change ' - 'ownership and try again.' % dirname) - sys.exit(1) - elif e.errno == errno.EACCES: - logging.info("Can't create directory %s." % dirname) - return None - else: - raise - finally: - uid, gid = get_current_user() - if uid != 0 and os.getuid() == 0: - try: - os.chown(dirname, uid, gid) - except Exception, ex: - if force_ownership: - print ('Unable to change owner of %s. Please fix ownership' - ' manually and try again.' % dirname) - sys.exit(1) - return dirname APP_NAME = "Installer" FILE_YUM_VERSION_LOCK = "/etc/yum/pluginconf.d/versionlock.list" -PACKSTACK_VAR_DIR = init_directory("/var/tmp/packstack") -PACKSTACK_LOG_DIR = init_directory("/var/log/packstack", force_ownership=False) -if not PACKSTACK_LOG_DIR: - PACKSTACK_LOG_DIR = PACKSTACK_VAR_DIR +PACKSTACK_VAR_DIR = "/var/tmp/packstack" +try: + os.mkdir(PACKSTACK_VAR_DIR, 0700) +except OSError: + # directory is already created, check ownership + stat = os.stat(PACKSTACK_VAR_DIR) + if stat.st_uid == 0 and os.getuid() != stat.st_uid: + print ('%s is already created and owned by root. Please change ' + 'ownership and try again.' % PACKSTACK_VAR_DIR) + sys.exit(1) +finally: + uid, gid = get_current_user() + + if uid != 0 and os.getuid() == 0: + try: + os.chown(PACKSTACK_VAR_DIR, uid, gid) + except Exception, ex: + print ('Unable to change owner of %s. Please fix ownership ' + 'manually and try again.' % PACKSTACK_VAR_DIR) + sys.exit(1) _tmpdirprefix = datetime.datetime.now().strftime('%Y%m%d-%H%M%S-') -LOG_DIR = "" -VAR_DIR = tempfile.mkdtemp(prefix=_tmpdirprefix, dir=PACKSTACK_VAR_DIR,) -if PACKSTACK_VAR_DIR != PACKSTACK_LOG_DIR: - LOG_DIR = VAR_DIR.replace("tmp", "log") - init_directory(LOG_DIR) -else: - LOG_DIR = VAR_DIR - - +VAR_DIR = tempfile.mkdtemp(prefix=_tmpdirprefix, dir=PACKSTACK_VAR_DIR) +DIR_LOG = VAR_DIR PUPPET_MANIFEST_RELATIVE = "manifests" PUPPET_MANIFEST_DIR = os.path.join(VAR_DIR, PUPPET_MANIFEST_RELATIVE) diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index 85c7283c9..d111452f1 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -36,7 +36,7 @@ def initLogging (debug): try: logFilename = "openstack-setup.log" - logFile = os.path.join(basedefs.LOG_DIR, logFilename) + logFile = os.path.join(basedefs.DIR_LOG, logFilename) # Create the log file with specific permissions, puppet has a habbit of putting # passwords in logs diff --git a/packstack/plugins/puppet_950.py b/packstack/plugins/puppet_950.py index 5d01c733a..7ca618da5 100644 --- a/packstack/plugins/puppet_950.py +++ b/packstack/plugins/puppet_950.py @@ -141,7 +141,7 @@ def waitforpuppet(currently_running): # Once a remote puppet run has finished, we retrieve the log # file and check it for errors local_server = utils.ScriptRunner() - log = os.path.join(basedefs.LOG_DIR, + log = os.path.join(basedefs.PUPPET_MANIFEST_DIR, os.path.basename(finished_logfile).replace(".finished", ".log")) local_server.append('scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@%s:%s %s' % (hostname, finished_logfile, log)) # To not pollute logs we turn of logging of command execution