Merge pull request #3087 from dachary/wip-9785-dmcrypt-keys-permissions

ceph-disk: dmcrypt file permissions

Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2014-12-05 08:39:30 -08:00
commit d7a9bf7cdb

View File

@ -792,11 +792,13 @@ def get_or_create_dmcrypt_key(
# make a new key
try:
if not os.path.exists(key_dir):
os.makedirs(key_dir)
os.makedirs(key_dir, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
with file('/dev/urandom', 'rb') as i:
key = i.read(256)
with file(path, 'wb') as key_file:
key_file.write(key)
fd = os.open(path, os.O_WRONLY|os.O_CREAT,
stat.S_IRUSR|stat.S_IWUSR)
assert os.write(fd, key) == len(key)
os.close(fd)
return path
except:
raise Error('unable to read or create dm-crypt key', path)