summaryrefslogtreecommitdiff
path: root/lib/ansible/parsing/dataloader.py
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2017-02-15 14:08:30 -0800
committerToshio Kuratomi <a.badger@gmail.com>2017-02-15 15:27:45 -0800
commitda9b7a055352d1200956fca6cd864e403bbb5379 (patch)
treed52712b3c333e772ee8b7cd42b1117daa76e0071 /lib/ansible/parsing/dataloader.py
parent7164956cc638a59cb3209ead14240754f6497b3b (diff)
downloadansible-da9b7a055352d1200956fca6cd864e403bbb5379.tar.gz
Retain vault password as bytes in 2.2vault-pass-nonutf8-2.2-compat
Prior to 2.2.1, the vault password was read in as byes and then remained bytes all the way through the code. A bug existed where bytes and text were mixed, leading to a traceback with non-ascii passwords. In devel, this was fixed by changing the read in password to text type to match with our overall strategy of converting at the borders. This was backported to stable-2.2 for the 2.2.1 release. On reflection, this should not have been backported as it causes passwords which were originally non-utf-8 to become utf-8. People will then have their working 2.2.x vault files become in-accessible. this commit pipes bytes all the way through the system for vault password. That way if a password is read in as a non-utf-8 character sequence, it will continue to work in 2.2.2+. This change is only for the 2.2 branch, not for 2.3 and beyond. Why not everywhere? The reason is that non-utf-8 passwords will cause problems when vault files are shared between systems or users. If the password is read from the prompt and one user/machine has a latin1 encoded locale while a second one has utf-8, the non-ascii password typed in won't match between machines. Deal with this by making sure that when we encrypt the data, we always use valid utf-8. Fixes #20398
Diffstat (limited to 'lib/ansible/parsing/dataloader.py')
-rw-r--r--lib/ansible/parsing/dataloader.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/ansible/parsing/dataloader.py b/lib/ansible/parsing/dataloader.py
index 6bac8e7237..a47638ec6c 100644
--- a/lib/ansible/parsing/dataloader.py
+++ b/lib/ansible/parsing/dataloader.py
@@ -71,9 +71,9 @@ class DataLoader():
# initialize the vault stuff with an empty password
self.set_vault_password(None)
- def set_vault_password(self, vault_password):
- self._vault_password = vault_password
- self._vault = VaultLib(password=vault_password)
+ def set_vault_password(self, b_vault_password):
+ self._b_vault_password = b_vault_password
+ self._vault = VaultLib(b_password=b_vault_password)
def load(self, data, file_name='<string>', show_content=True):
'''
@@ -151,7 +151,7 @@ class DataLoader():
def _safe_load(self, stream, file_name=None):
''' Implements yaml.safe_load(), except using our custom loader class. '''
- loader = AnsibleLoader(stream, file_name, self._vault_password)
+ loader = AnsibleLoader(stream, file_name, self._b_vault_password)
try:
return loader.get_single_data()
finally:
@@ -359,7 +359,7 @@ class DataLoader():
raise AnsibleError("Problem running vault password script %s (%s)."
" If this is not a script, remove the executable bit from the file." % (' '.join(this_path), to_native(e)))
stdout, stderr = p.communicate()
- self.set_vault_password(stdout.strip('\r\n'))
+ self.set_vault_password(stdout.strip(b'\r\n'))
else:
try:
f = open(this_path, "rb")
@@ -397,7 +397,7 @@ class DataLoader():
raise AnsibleFileNotFound("the file_name '%s' does not exist, or is not readable" % to_native(file_path))
if not self._vault:
- self._vault = VaultLib(password="")
+ self._vault = VaultLib(b_password="")
real_path = self.path_dwim(file_path)
@@ -411,7 +411,7 @@ class DataLoader():
# the decrypt call would throw an error, but we check first
# since the decrypt function doesn't know the file name
data = f.read()
- if not self._vault_password:
+ if not self._b_vault_password:
raise AnsibleParserError("A vault password must be specified to decrypt %s" % file_path)
data = self._vault.decrypt(data, filename=real_path)