1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test
Adrian Likins 9c58827410
Better handling of malformed vault data envelope (#32515)
* Better handling of malformed vault data envelope

If an embedded vaulted variable ('!vault' in yaml)
had an invalid format, it would eventually cause
an error for seemingly unrelated reasons.
"Invalid" meaning not valid hexlify (extra chars,
non-hex chars, etc).

For ex, if a host_vars file had invalid vault format
variables, on py2, it would cause an error like:

  'ansible.vars.hostvars.HostVars object' has no
  attribute u'broken.example.com'

Depending on where the invalid vault is, it could
also cause "VARIABLE IS NOT DEFINED!". The behavior
can also change if ansible-playbook is py2 or py3.

Root cause is errors from binascii.unhexlify() not
being handled consistently.

Fix is to add a AnsibleVaultFormatError exception and
raise it on any unhexlify() errors and to handle it
properly elsewhere.

Add a _unhexlify() that try/excepts around a binascii.unhexlify()
and raises an AnsibleVaultFormatError on invalid vault data.
This is so the same exception type is always raised for this
case. Previous it was different between py2 and py3.

binascii.unhexlify() raises a binascii.Error if the hexlified
blobs in a vault data blob are invalid.

On py2, binascii.Error is a subclass of Exception.
On py3, binascii.Error is a subclass of TypeError

When decrypting content of vault encrypted variables,
if a binascii.Error is raised it propagates up to
playbook.base.Base.post_validate(). post_validate()
handles exceptions for TypeErrors but not for
base Exception subclasses (like py2 binascii.Error).

* Add a display.warning on vault format errors
* Unit tests for _unhexlify, parse_vaulttext*
* Add intg test cases for invalid vault formats

Fixes #28038
2017-11-10 14:24:56 -05:00
..
cache Update ansible-test sanity command. (#31958) 2017-10-26 00:21:46 -07:00
compile Docs how to test (2nd) (#24094) 2017-04-28 09:08:26 +01:00
integration Better handling of malformed vault data envelope (#32515) 2017-11-10 14:24:56 -05:00
legacy remove unused ssh pipelining setters 2017-10-03 09:22:01 -04:00
results Collect data from integration test runs. (#28650) 2017-08-25 18:14:47 -04:00
runner Update ansible-test sanity command. (#31958) 2017-10-26 00:21:46 -07:00
sanity Add ISSU capability and fix workflow bug for nxos_install_os module (#32540) 2017-11-09 14:54:19 +00:00
units Better handling of malformed vault data envelope (#32515) 2017-11-10 14:24:56 -05:00
utils Provide details via DCI Env (#32770) 2017-11-09 22:12:50 +00:00