mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-08 02:01:31 -07:00
Fix 'New Vault password' on vault 'edit' (#35923)
* Fix 'New Vault password' on vault 'edit'
ffe0ddea96
introduce a
change on 'ansible-vault edit' that tried to check
for --encrypt-vault-id in that mode. But '--encrypt-vault-id'
is not intended for 'edit' since the 'edit' should always
reuse the vault secret that was used to decrypt the text.
Change cli to not check for --encrypt-vault-id on 'edit'.
VaultLib.decrypt_and_get_vault_id() was change to return
the vault secret used to decrypt (in addition to vault_id
and the plaintext).
VaultEditor.edit_file() will now use 'vault_secret_used'
as returned from decrypt_and_get_vault_id() so that
an edited file always gets reencrypted with the same
secret, regardless of any vault id configuration or
cli options.
Fixes #35834
This commit is contained in:
parent
cbe2915ba5
commit
6e737c8cb6
4 changed files with 63 additions and 20 deletions
|
@ -26,6 +26,22 @@ echo "This is a test file for edit" > "${TEST_FILE_EDIT}"
|
|||
TEST_FILE_EDIT2="${MYTMPDIR}/test_file_edit2"
|
||||
echo "This is a test file for edit2" > "${TEST_FILE_EDIT2}"
|
||||
|
||||
# test case for https://github.com/ansible/ansible/issues/35834
|
||||
# (being prompted for new password on vault-edit with no configured passwords)
|
||||
|
||||
TEST_FILE_EDIT3="${MYTMPDIR}/test_file_edit3"
|
||||
echo "This is a test file for edit3" > "${TEST_FILE_EDIT3}"
|
||||
|
||||
# ansible-config view
|
||||
ansible-config view
|
||||
|
||||
# ansisle-config
|
||||
ansible-config dump --only-changed
|
||||
ansible-vault encrypt "$@" --vault-id vault-password "${TEST_FILE_EDIT3}"
|
||||
# EDITOR=./faux-editor.py ansible-vault edit "$@" "${TEST_FILE_EDIT3}"
|
||||
EDITOR=./faux-editor.py ansible-vault edit --vault-id vault-password -vvvvv "${TEST_FILE_EDIT3}"
|
||||
echo $?
|
||||
|
||||
# view the vault encrypted password file
|
||||
ansible-vault view "$@" --vault-id vault-password encrypted-vault-password
|
||||
|
||||
|
@ -336,11 +352,22 @@ EDITOR=./faux-editor.py ansible-vault edit "$@" --vault-password-file vault-pass
|
|||
head -1 "${TEST_FILE_EDIT}" | grep "${FORMAT_1_1_HEADER}"
|
||||
|
||||
# edit a 1.1 format with vault-id, should stay 1.1
|
||||
cat "${TEST_FILE_EDIT}"
|
||||
EDITOR=./faux-editor.py ansible-vault edit "$@" --vault-id vault_password@vault-password "${TEST_FILE_EDIT}"
|
||||
cat "${TEST_FILE_EDIT}"
|
||||
head -1 "${TEST_FILE_EDIT}" | grep "${FORMAT_1_1_HEADER}"
|
||||
|
||||
ansible-vault encrypt "$@" --vault-id vault_password@vault-password "${TEST_FILE_EDIT2}"
|
||||
|
||||
# verify that we aren't prompted for a new vault password on edit if we are running interactively (ie, with prompts)
|
||||
# have to use setsid nd --ask-vault-pass to force a prompt to simulate.
|
||||
# See https://github.com/ansible/ansible/issues/35834
|
||||
setsid sh -c 'tty; echo password |ansible-vault edit --ask-vault-pass vault_test.yml' < /dev/null > log 2>&1 && :
|
||||
grep 'New Vault password' log && :
|
||||
WRONG_RC=$?
|
||||
echo "The stdout log had 'New Vault password' in it and it is not supposed to. rc of grep was $WRONG_RC (1 is expected)"
|
||||
[ $WRONG_RC -eq 1 ]
|
||||
|
||||
# edit a 1.2 format with vault id, should keep vault id and 1.2 format
|
||||
EDITOR=./faux-editor.py ansible-vault edit "$@" --vault-id vault_password@vault-password "${TEST_FILE_EDIT2}"
|
||||
head -1 "${TEST_FILE_EDIT2}" | grep "${FORMAT_1_2_HEADER};vault_password"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue