Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #333 from nbraud/validate-trusted-keys
Browse files Browse the repository at this point in the history
apt: Validate packages.trusted-keys
  • Loading branch information
andsens committed Sep 12, 2016
2 parents ad2273a + 58a7011 commit f71eac2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions bootstrapvz/common/task_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions bootstrapvz/common/tasks/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@
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
Expand Down Expand Up @@ -70,6 +101,7 @@ def run(cls, info):
class InstallTrustedKeys(Task):
description = 'Installing trusted keys'
phase = phases.package_installation
predecessors = [ValidateTrustedKeys]

@classmethod
def run(cls, info):
Expand Down

0 comments on commit f71eac2

Please sign in to comment.