Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Securely create signing_dir (bug 1174608)
Also verifies the security of an existing signing_dir.

Change-Id: I0685b4274a94ad3974a2b2a7ab3f45830d3934bb
(cherry picked from python-keystoneclient 1736e2ffb12f70eeebed019448bc14def48aa036)
  • Loading branch information
dolph authored and apevec committed May 8, 2013
1 parent 09f2802 commit 24c25b3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions keystone/middleware/auth_token.py
Expand Up @@ -219,15 +219,20 @@ def __init__(self, app, conf):
self.signing_dirname = '%s/keystone-signing' % os.environ['HOME']
LOG.info('Using %s as cache directory for signing certificate' %
self.signing_dirname)
if (os.path.exists(self.signing_dirname) and
not os.access(self.signing_dirname, os.W_OK)):
raise ConfigurationError("unable to access signing dir %s" %
self.signing_dirname)

if not os.path.exists(self.signing_dirname):
os.makedirs(self.signing_dirname)
#will throw IOError if it cannot change permissions
os.chmod(self.signing_dirname, stat.S_IRWXU)
if os.path.exists(self.signing_dirname):
if not os.access(self.signing_dirname, os.W_OK):
raise ConfigurationError(
'unable to access signing_dir %s' % self.signing_dirname)
if os.stat(self.signing_dirname).st_uid != os.getuid():
LOG.warning(
'signing_dir is not owned by %s' % os.getlogin())
current_mode = stat.S_IMODE(os.stat(self.signing_dirname).st_mode)
if current_mode != stat.S_IRWXU:
LOG.warning(
'signing_dir mode is %s instead of %s' %
(oct(current_mode), oct(stat.S_IRWXU)))
else:
os.makedirs(self.signing_dirname, stat.S_IRWXU)

val = '%s/signing_cert.pem' % self.signing_dirname
self.signing_cert_file_name = val
Expand Down

0 comments on commit 24c25b3

Please sign in to comment.