From 03750708710b2e44a7ffa068c65f969ae4ed51f1 Mon Sep 17 00:00:00 2001 From: Maxim Masiutin Date: Wed, 28 Apr 2021 08:27:38 +0200 Subject: [PATCH] Binary GnuPG keys downloaded via URLs by the 'ansible.builtin.apt_key' module were corrupted so 'gpg' could not import them (https://github.com/ansible/ansible/issues/74424) --- .../74474-apt_key-gpg-binary-import.yaml | 3 +++ lib/ansible/modules/apt_key.py | 5 ++++- .../apt_key/samples/apt-key-example-binary.gpg | Bin 0 -> 1787 bytes .../targets/apt_key/tasks/apt_key_binary.yml | 13 +++++++++++++ test/integration/targets/apt_key/tasks/main.yml | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/74474-apt_key-gpg-binary-import.yaml create mode 100644 test/integration/targets/apt_key/samples/apt-key-example-binary.gpg create mode 100644 test/integration/targets/apt_key/tasks/apt_key_binary.yml diff --git a/changelogs/fragments/74474-apt_key-gpg-binary-import.yaml b/changelogs/fragments/74474-apt_key-gpg-binary-import.yaml new file mode 100644 index 00000000000..47e416b9439 --- /dev/null +++ b/changelogs/fragments/74474-apt_key-gpg-binary-import.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - Binary GnuPG keys downloaded via URLs by the 'ansible.builtin.apt_key' module were corrupted so 'gpg' could not import them (https://github.com/ansible/ansible/issues/74424). diff --git a/lib/ansible/modules/apt_key.py b/lib/ansible/modules/apt_key.py index 87b6410a630..58e23216a99 100644 --- a/lib/ansible/modules/apt_key.py +++ b/lib/ansible/modules/apt_key.py @@ -283,12 +283,15 @@ def download_key(module, url): def get_key_id_from_file(module, filename, data=None): + native_data = to_native(data) + is_armored = native_data.find("-----BEGIN PGP PUBLIC KEY BLOCK-----") >= 0 + global lang_env key = None cmd = [gpg_bin, '--with-colons', filename] - (rc, out, err) = module.run_command(cmd, environ_update=lang_env, data=to_native(data)) + (rc, out, err) = module.run_command(cmd, environ_update=lang_env, data=(native_data if is_armored else data), binary_data=not is_armored) if rc != 0: module.fail_json(msg="Unable to extract key from '%s'" % ('inline data' if data is None else filename), stdout=out, stderr=err) diff --git a/test/integration/targets/apt_key/samples/apt-key-example-binary.gpg b/test/integration/targets/apt_key/samples/apt-key-example-binary.gpg new file mode 100644 index 0000000000000000000000000000000000000000..3b81faed1f7d4cebf42cb0fb75744dae19860a5a GIT binary patch literal 1787 zcmajec{Cdc0tWD0uE;D>;?_u8M@-$vAQi!=TMMC`m zrA$|mI3|v^t|G23Eu|=`SW|<_uuz^#lUQc7qtZegaKI7c>rm6{-&`& zNtBxK-H1y(?2oqWM)R=rv28DBT)NSgtcR6TTErvMjUixmvuT)#)8zL(d^|#zjVj@k zeQp#x5&HUMhaE|A9w>%bTxVg$QjRnVk3;+C%u0wk8BrEHkZamXX(k-0w;JD>;=Oul zA*`svhwW;x;p{@0ScLn=Has#TkGUZ|y_w!C?o{-JP-k2-?;oV}0GY@xwk1%0GfR*y zk&P*To03ByG{dA#paaQt-AT(iCY;e9Yg?QbYy((MR50*k6D)wPc0HJt*uP8W0h&DfJx44v#yi@ zx$8DkN9FN`6$~M=4kB!7A4Iw4?n>{!^u+)4aMl}buXQ~0`D&v}pFh92_1uYkE(1(o zVSD2*gC%<=s%u(QedRoP_q5LQ*D6fE#7xfP)#>%gL;ox-t*=cj&PZxk$cx`esN8vO zrWhX$Y?w^|2mt}WHe0-3L?qHEAjCU725IRRgH*tULGjL_g(#klWtG0AIsDb7=T41{uIn$T=Vs@DoB7!e2#Q?jyB&wXVn8&^317)!3O| z=K}rvevl-Xi=U5|2gEG`<>TcCK@cD?5F`Txi6#P|e1dprvM zS`(f@cm8nZn&UWItx`6=Htsx+U?qXn1DLN$Zau&628F>cmz|#&o*TPs(S70rLo;gT z?LYM^vjXd$*u3Q><_<38)w~SC8cLK|OmVF;DXV(FbGp@Om;pWZJXozg1E`vku3?2k z@Rmj#0SbN-r)*(2f9mEWa#TR1;0&dd~4w!7JPPfnfg2XR?>6p z4#+w~<6QR^30@Q_Yk+?7URT)f-jU)=8%4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