You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/vault
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
7 years ago
..
invalid_format Better handling of malformed vault data envelope (#32515) 7 years ago
roles Support multiple vault passwords (#22756) 7 years ago
aliases Initial ansible-test implementation. (#18556) 8 years ago
empty-password Vault secrets empty password (#28186) 7 years ago
encrypted_file_encrypted_var_password Support multiple vault passwords (#22756) 7 years ago
example1_password Support multiple vault passwords (#22756) 7 years ago
example2_password Support multiple vault passwords (#22756) 7 years ago
example3_password Support multiple vault passwords (#22756) 7 years ago
faux-editor.py Use vault_id when encrypted via vault-edit (#30772) 7 years ago
format_1_0_AES.yml Cyptography pr 20566 rebase (#25560) 7 years ago
format_1_1_AES.yml Cyptography pr 20566 rebase (#25560) 7 years ago
format_1_1_AES256.yml Cyptography pr 20566 rebase (#25560) 7 years ago
format_1_2_AES256.yml Support multiple vault passwords (#22756) 7 years ago
password-script.py Support multiple vault passwords (#22756) 7 years ago
runme.sh Better handling of malformed vault data envelope (#32515) 7 years ago
runme_change_pip_installed.sh Cyptography pr 20566 rebase (#25560) 7 years ago
test-vault-client.py Vault secrets script client inc new 'keyring' client (#27669) 7 years ago
test_vault.yml
test_vault_embedded.yml
test_vault_embedded_ids.yml Support multiple vault passwords (#22756) 7 years ago
test_vault_file_encrypted_embedded.yml Support multiple vault passwords (#22756) 7 years ago
test_vaulted_inventory.yml add a intg test for vault encrypted inventory (#18550) 8 years ago
test_vaulted_template.yml Allow template files to be vaulted (#22951) 7 years ago
vault-password
vault-password-ansible Cyptography pr 20566 rebase (#25560) 7 years ago
vault-password-wrong Cyptography pr 20566 rebase (#25560) 7 years ago
vault-secret.txt
vaulted.inventory add a intg test for vault encrypted inventory (#18550) 8 years ago