Skip to content

Commit

Permalink
Create cache file with 0600 permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesls committed Dec 15, 2014
1 parent 366b6b7 commit 22d4cea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion awscli/customizations/assumerole.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def __setitem__(self, cache_key, value):
"JSON serializable: %s" % value)
if not os.path.isdir(self._working_dir):
os.makedirs(self._working_dir)
with open(full_key, 'w') as f:
with os.fdopen(os.open(full_key,
os.O_WRONLY | os.O_CREAT, 0o600), 'w') as f:
f.write(file_content)

def _convert_cache_key(self, cache_key):
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/customizations/test_assumerole.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import shutil
import tempfile
import os
import platform
from datetime import datetime, timedelta

import mock
Expand Down Expand Up @@ -353,3 +354,10 @@ def test_working_dir_does_not_exist(self):
def test_key_error_raised_when_cache_key_does_not_exist(self):
with self.assertRaises(KeyError):
self.cache['foo']

@unittest.skipIf(platform.system() not in ['Darwin', 'Linux'],
'File permissions tests not supported on Windows.')
def test_permissions_for_file_restricted(self):
self.cache['mykey'] = {'foo': 'bar'}
filename = os.path.join(self.tempdir, 'mykey.json')
self.assertEqual(os.stat(filename).st_mode & 0xFFF, 0o600)

0 comments on commit 22d4cea

Please sign in to comment.