Merge pull request #333 from nbraud/validate-trusted-keys

apt: Validate packages.trusted-keys
This commit is contained in:
Anders Ingemann 2016-09-12 07:38:31 +02:00 committed by GitHub
commit f71eac2c39
2 changed files with 33 additions and 0 deletions

View file

@ -121,6 +121,7 @@ def get_apt_group(manifest):
if 'sources' in manifest.packages:
group.append(apt.AddManifestSources)
if 'trusted-keys' in manifest.packages:
group.append(apt.ValidateTrustedKeys)
group.append(apt.InstallTrustedKeys)
if 'preferences' in manifest.packages:
group.append(apt.AddManifestPreferences)

View file

@ -6,6 +6,37 @@ import logging
import os
class ValidateTrustedKeys(Task):
description = 'Validate apt trusted keys'
phase = phases.validation
@classmethod
def run(cls, info):
from bootstrapvz.common.tools import log_call
for i, key_path in enumerate(info.manifest.packages.get('trusted-keys', {})):
if not os.path.isfile(key_path):
info.manifest.validation_error('File not found: {}'.format(key_path),
['packages', 'trusted-keys', i])
from tempfile import mkdtemp
from shutil import rmtree
tempdir = mkdtemp()
status, _, _ = log_call(
['gpg', '--quiet',
'--homedir', tempdir,
'--keyring', key_path,
'-k']
)
rmtree(tempdir)
if status != 0:
info.manifest.validation_error('Invalid GPG keyring: {}'.format(key_path),
['packages', 'trusted-keys', i])
class AddManifestSources(Task):
description = 'Adding sources from the manifest'
phase = phases.preparation
@ -70,6 +101,7 @@ class AddManifestPreferences(Task):
class InstallTrustedKeys(Task):
description = 'Installing trusted keys'
phase = phases.package_installation
predecessors = [ValidateTrustedKeys]
@classmethod
def run(cls, info):