def enforce_file_permissions(path):
# source: dcos-cli
"""Enforce 400 or 600 permissions on file
:param path: Path to the TOML file
:type path: str
:rtype: None
"""
if not os.path.isfile(path):
raise Exception('Path [{}] is not a file'.format(path))
permissions = oct(stat.S_IMODE(os.stat(path).st_mode))
if permissions not in ['0o600', '0600', '0o400', '0400']:
if os.path.realpath(path) != path:
path = '%s (pointed to by %s)' % (os.path.realpath(path), path)
msg = (
"Permissions '{}' for configuration file '{}' are too open. "
"File must only be accessible by owner. "
"Aborting...".format(permissions, path))
raise Exception(msg)
评论列表
文章目录