Skip to content

Commit

Permalink
Mask permissions on private key files
Browse files Browse the repository at this point in the history
When using "nova x509-create-cert", the private key should be written to
a file with the permissions 0400, not (world-readable) 0644, in line
with how ssh private keys are treated.

bug 1112605

Change-Id: I0b20378efba38fa58f4ad9a33cd15b3432ebb8a2
Signed-off-by: Zane Bitter <zbitter@redhat.com>
  • Loading branch information
zaneb committed Feb 11, 2013
1 parent 1ea7e65 commit 0b4590c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions novaclient/v1_1/shell.py
Expand Up @@ -2149,9 +2149,13 @@ def do_x509_create_cert(cs, args):

certs = cs.certs.create()

with open(args.pk_filename, 'w') as private_key:
private_key.write(certs.private_key)
print "Wrote private key to %s" % args.pk_filename
try:
old_umask = os.umask(0o377)
with open(args.pk_filename, 'w') as private_key:
private_key.write(certs.private_key)
print "Wrote private key to %s" % args.pk_filename
finally:
os.umask(old_umask)

with open(args.cert_filename, 'w') as cert:
cert.write(certs.data)
Expand Down

0 comments on commit 0b4590c

Please sign in to comment.