Skip to content

Commit

Permalink
apt: kill spawned keyboxd after gpg cmd interaction
Browse files Browse the repository at this point in the history
gnupg version 2.4.4 spawns keyboxd daemon automatically when
interacting with gpg on the commandline.

Cleanup this spawned daemon after cloud-init is done setting up
any APT configuration to avoid leaving resident 'unused' processes
on the system.
  • Loading branch information
blackboxsw committed Feb 29, 2024
1 parent c8507a4 commit 12126f5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
12 changes: 11 additions & 1 deletion cloudinit/config/cc_apt_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,17 @@ def apply_apt(cfg, cloud):
# GH: 4344 - stop gpg-agent/dirmgr daemons spawned by gpg key imports.
# Daemons spawned by cloud-config.service on systemd v253 report (running)
gpg_process_out, _err = subp.subp(
["ps", "-o", "ppid,pid", "-C", "dirmngr", "-C", "gpg-agent"],
[
"ps",
"-o",
"ppid,pid",
"-C",
"keyboxd",
"-C",
"dirmngr",
"-C",
"gpg-agent",
],
capture=True,
rcs=[0, 1],
)
Expand Down
36 changes: 33 additions & 3 deletions tests/unittests/config/test_apt_configure_sources_list_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,17 @@ def test_apt_v1_source_list_by_distro(self, distro, mirror, tmpdir):
assert 0o644 == stat.S_IMODE(sources_file.stat().mode)

self.subp.assert_called_once_with(
["ps", "-o", "ppid,pid", "-C", "dirmngr", "-C", "gpg-agent"],
[
"ps",
"-o",
"ppid,pid",
"-C",
"keyboxd",
"-C",
"dirmngr",
"-C",
"gpg-agent",
],
capture=True,
rcs=[0, 1],
)
Expand Down Expand Up @@ -220,7 +230,17 @@ def test_apt_v1_srcl_distro_mirrorfail(
mockresolve.assert_any_call("http://does.not.exist")
mockresolve.assert_any_call(mirrorcheck)
self.subp.assert_called_once_with(
["ps", "-o", "ppid,pid", "-C", "dirmngr", "-C", "gpg-agent"],
[
"ps",
"-o",
"ppid,pid",
"-C",
"keyboxd",
"-C",
"dirmngr",
"-C",
"gpg-agent",
],
capture=True,
rcs=[0, 1],
)
Expand Down Expand Up @@ -282,7 +302,17 @@ def test_apt_v1_srcl_custom(
assert expected == sources_file.read()
assert 0o644 == stat.S_IMODE(sources_file.stat().mode)
self.subp.assert_called_once_with(
["ps", "-o", "ppid,pid", "-C", "dirmngr", "-C", "gpg-agent"],
[
"ps",
"-o",
"ppid,pid",
"-C",
"keyboxd",
"-C",
"dirmngr",
"-C",
"gpg-agent",
],
capture=True,
rcs=[0, 1],
)
12 changes: 11 additions & 1 deletion tests/unittests/config/test_apt_configure_sources_list_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,17 @@ def test_apt_v3_srcl_custom_deb822_feature_aware(
assert expected == sources_file.read()
assert 0o644 == stat.S_IMODE(sources_file.stat().mode)
self.subp.assert_called_once_with(
["ps", "-o", "ppid,pid", "-C", "dirmngr", "-C", "gpg-agent"],
[
"ps",
"-o",
"ppid,pid",
"-C",
"keyboxd",
"-C",
"dirmngr",
"-C",
"gpg-agent",
],
capture=True,
rcs=[0, 1],
)
2 changes: 2 additions & 0 deletions tests/unittests/config/test_apt_source_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,8 @@ def test_apt_src_ppa(self, apt_lists, mocker):
"-o",
"ppid,pid",
"-C",
"keyboxd",
"-C",
"dirmngr",
"-C",
"gpg-agent",
Expand Down

0 comments on commit 12126f5

Please sign in to comment.