mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
added error handling on private key stat in case it is saved in agent
but not in filesystem
This commit is contained in:
parent
394ebe7947
commit
a2ba0c03e4
1 changed files with 8 additions and 1 deletions
|
@ -36,7 +36,14 @@ class Connector(object):
|
||||||
raise AnsibleError("unsupported connection type: %s" % transport)
|
raise AnsibleError("unsupported connection type: %s" % transport)
|
||||||
if private_key_file:
|
if private_key_file:
|
||||||
# If private key is readable by user other than owner, flag an error
|
# If private key is readable by user other than owner, flag an error
|
||||||
|
try:
|
||||||
st = os.stat(private_key_file)
|
st = os.stat(private_key_file)
|
||||||
|
except IOError, e:
|
||||||
|
if e.errno == errno.ENOENT: # file is missing, might be agent
|
||||||
|
st = { 'st_mode': False }
|
||||||
|
else:
|
||||||
|
raise(e)
|
||||||
|
|
||||||
if st.st_mode & (stat.S_IRGRP | stat.S_IROTH):
|
if st.st_mode & (stat.S_IRGRP | stat.S_IROTH):
|
||||||
raise AnsibleError("private_key_file (%s) is group-readable or world-readable and thus insecure - "
|
raise AnsibleError("private_key_file (%s) is group-readable or world-readable and thus insecure - "
|
||||||
"you will probably get an SSH failure"
|
"you will probably get an SSH failure"
|
||||||
|
|
Loading…
Reference in a new issue