mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
e238ae999b
Make pyca/cryptography the preferred backend for cryptographic needs (mainly vault) falling back to pycrypto pyca/cryptography is already implicitly a dependency in many cases through paramiko (2.0+) as well as the new openssl_publickey module, which requires pyOpenSSL 16.0+. Additionally, pyca/cryptography is an optional dep for better performance with vault already. This commit leverages cryptography's padding, constant time comparisons, and CBC/CTR modes to reduce the amount of code ansible needs to maintain. * Handle wrong password given for VaultAES format * Do not display deprecation warning for cryptography on python-2.6 * Namespace all of the pycrypto imports and always import them Makes unittests better and the code less likely to get stupid mistakes (like using HMAC from cryptogrpahy when the one from pycrypto is needed) * Add back in atfork since we need pycrypto to reinitialize its RNG just in case we're being used with old paramiko * contrib/inventory/gce: Remove spurious require on pycrypto (cherry picked from commit 9e16b9db275263b3ea8d1b124966fdebfc9ab271) * Add cryptography to ec2_win_password module requirements * Fix python3 bug which would pass text strings to a function which requires byte strings. * Attempt to add pycrypto version to setup deps * Change hacking README for dual pycrypto/cryptography * update dependencies for various CI scripts * additional CI dockerfile/script updates * add paramiko to the windows and sanity requirement set This is needed because ansible lists it as a requirement. Previously the missing dep wasn't enforced, but cryptography imports pkg_resources so you can't ignore a requirement any more * Add integration test cases for old vault and for wrong passwords * helper script for manual testing of pycrypto/cryptography * Skip the pycrypto tests so that users without it installed can still run the unittests * Run unittests for vault with both cryptography and pycrypto backend
87 lines
3.8 KiB
Bash
Executable file
87 lines
3.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -eux
|
|
|
|
MYTMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
|
|
trap 'rm -rf "${MYTMPDIR}"' EXIT
|
|
|
|
# create a test file
|
|
TEST_FILE="${MYTMPDIR}/test_file"
|
|
echo "This is a test file" > "${TEST_FILE}"
|
|
|
|
TEST_FILE_OUTPUT="${MYTMPDIR}/test_file_output"
|
|
|
|
# old format
|
|
ansible-vault view "$@" --vault-password-file vault-password-ansible format_1_0_AES.yml
|
|
|
|
ansible-vault view "$@" --vault-password-file vault-password-ansible format_1_1_AES.yml
|
|
|
|
# old format, wrong password
|
|
echo "The wrong password tests are expected to return 1"
|
|
ansible-vault view "$@" --vault-password-file vault-password-wrong format_1_0_AES.yml && :
|
|
WRONG_RC=$?
|
|
echo "rc was $WRONG_RC (1 is expected)"
|
|
[ $WRONG_RC -eq 1 ]
|
|
|
|
ansible-vault view "$@" --vault-password-file vault-password-wrong format_1_1_AES.yml && :
|
|
WRONG_RC=$?
|
|
echo "rc was $WRONG_RC (1 is expected)"
|
|
[ $WRONG_RC -eq 1 ]
|
|
|
|
ansible-vault view "$@" --vault-password-file vault-password-wrong format_1_1_AES256.yml && :
|
|
WRONG_RC=$?
|
|
echo "rc was $WRONG_RC (1 is expected)"
|
|
[ $WRONG_RC -eq 1 ]
|
|
|
|
set -eux
|
|
|
|
# new format, view
|
|
ansible-vault view "$@" --vault-password-file vault-password format_1_1_AES256.yml
|
|
|
|
# encrypt it
|
|
ansible-vault encrypt "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
ansible-vault view "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
ansible-vault decrypt "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
# new password file for rekeyed file
|
|
NEW_VAULT_PASSWORD="${MYTMPDIR}/new-vault-password"
|
|
echo "newpassword" > "${NEW_VAULT_PASSWORD}"
|
|
|
|
ansible-vault encrypt "$@" --vault-password-file vault-password "${TEST_FILE}"
|
|
|
|
ansible-vault rekey "$@" --vault-password-file vault-password --new-vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}"
|
|
|
|
ansible-vault view "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}"
|
|
|
|
ansible-vault decrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "${TEST_FILE}"
|
|
|
|
# reading/writing to/from stdin/stdin (See https://github.com/ansible/ansible/issues/23567)
|
|
ansible-vault encrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --output="${TEST_FILE_OUTPUT}" < "${TEST_FILE}"
|
|
ansible-vault view "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" - < "${TEST_FILE_OUTPUT}"
|
|
ansible-vault decrypt "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --output=- < "${TEST_FILE_OUTPUT}"
|
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" "a test string"
|
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --name "blippy" "a test string names blippy"
|
|
|
|
|
|
# from stdin
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" < "${TEST_FILE}"
|
|
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --stdin-name "the_var_from_stdin" < "${TEST_FILE}"
|
|
|
|
# write to file
|
|
ansible-vault encrypt_string "$@" --vault-password-file "${NEW_VAULT_PASSWORD}" --name "blippy" "a test string names blippy" --output "${MYTMPDIR}/enc_string_test_file"
|
|
|
|
|
|
# test playbooks using vaulted files
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password --list-tasks
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password --list-hosts
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password --syntax-check
|
|
ansible-playbook test_vault.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|
|
ansible-playbook test_vault_embedded.yml -i ../../inventory -v "$@" --vault-password-file vault-password --syntax-check
|
|
ansible-playbook test_vault_embedded.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|
|
ansible-playbook test_vaulted_inventory.yml -i vaulted.inventory -v "$@" --vault-password-file vault-password
|
|
ansible-playbook test_vaulted_template.yml -i ../../inventory -v "$@" --vault-password-file vault-password
|