mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #8020 from msabramo/error_when_private_key_file_permissions_incorrect
Error if private_key_file is group/world readable
This commit is contained in:
commit
03d150de35
1 changed files with 10 additions and 0 deletions
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
|
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
|
|
||||||
|
@ -31,5 +34,12 @@ class Connector(object):
|
||||||
conn = utils.plugins.connection_loader.get(transport, self.runner, host, port, user=user, password=password, private_key_file=private_key_file)
|
conn = utils.plugins.connection_loader.get(transport, self.runner, host, port, user=user, password=password, private_key_file=private_key_file)
|
||||||
if conn is None:
|
if conn is None:
|
||||||
raise AnsibleError("unsupported connection type: %s" % transport)
|
raise AnsibleError("unsupported connection type: %s" % transport)
|
||||||
|
if private_key_file:
|
||||||
|
# If private key is readable by user other than owner, flag an error
|
||||||
|
st = os.stat(private_key_file)
|
||||||
|
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 - "
|
||||||
|
"you will probably get an SSH failure"
|
||||||
|
% (private_key_file,))
|
||||||
self.active = conn.connect()
|
self.active = conn.connect()
|
||||||
return self.active
|
return self.active
|
||||||
|
|
Loading…
Reference in a new issue