apt_repository, handle both new/old gpgp stds (#78735) (#78909)

* apt_repository, handle both new/old gpgp stds

(cherry picked from commit c7cde2645d)
pull/78945/head
Brian Coca 2 years ago committed by GitHub
parent 6b8432850f
commit 7209c0b3d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- apt_repository will use the trust repo directories in order of preference (more appropriate to less) as they exist on the target.

@ -177,8 +177,8 @@ except ImportError:
HAVE_PYTHON_APT = False HAVE_PYTHON_APT = False
APT_KEY_DIRS = ['/etc/apt/keyrings', '/etc/apt/trusted.gpg.d', '/usr/share/keyrings']
DEFAULT_SOURCES_PERM = 0o0644 DEFAULT_SOURCES_PERM = 0o0644
VALID_SOURCE_TYPES = ('deb', 'deb-src') VALID_SOURCE_TYPES = ('deb', 'deb-src')
@ -482,7 +482,7 @@ class UbuntuSourcesList(SourcesList):
found = False found = False
keyfiles = ['/etc/apt/trusted.gpg'] # main gpg repo for apt keyfiles = ['/etc/apt/trusted.gpg'] # main gpg repo for apt
for other_dir in ('/etc/apt/trusted.gpg.d', '/usr/share/keyrings'): for other_dir in APT_KEY_DIRS:
# add other known sources of gpg sigs for apt, skip hidden files # add other known sources of gpg sigs for apt, skip hidden files
keyfiles.extend([os.path.join(other_dir, x) for x in os.listdir(other_dir) if not x.startswith('.')]) keyfiles.extend([os.path.join(other_dir, x) for x in os.listdir(other_dir) if not x.startswith('.')])
@ -522,7 +522,14 @@ class UbuntuSourcesList(SourcesList):
command = [self.apt_key_bin, 'adv', '--recv-keys', '--no-tty', '--keyserver', 'hkp://keyserver.ubuntu.com:80', command = [self.apt_key_bin, 'adv', '--recv-keys', '--no-tty', '--keyserver', 'hkp://keyserver.ubuntu.com:80',
info['signing_key_fingerprint']] info['signing_key_fingerprint']]
else: else:
keyfile = '/usr/share/keyrings/%s-%s-%s.gpg' % (os.path.basename(source).replace(' ', '-'), ppa_owner, ppa_name) # use first available key dir, in order of preference
for keydir in APT_KEY_DIRS:
if os.path.exists(keydir):
break
else:
self.module.fail_json("Unable to find any existing apt gpgp repo directories, tried the following: %s" % ', '.join(APT_KEY_DIRS))
keyfile = '%s/%s-%s-%s.gpg' % (keydir, os.path.basename(source).replace(' ', '-'), ppa_owner, ppa_name)
command = [self.gpg_bin, '--no-tty', '--keyserver', 'hkp://keyserver.ubuntu.com:80', '--export', info['signing_key_fingerprint']] command = [self.gpg_bin, '--no-tty', '--keyserver', 'hkp://keyserver.ubuntu.com:80', '--export', info['signing_key_fingerprint']]
rc, stdout, stderr = self.module.run_command(command, check_rc=True, encoding=None) rc, stdout, stderr = self.module.run_command(command, check_rc=True, encoding=None)

Loading…
Cancel
Save