Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initvm: add an option for additional Debian archive key location #375

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion elbepack/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def run_command(argv):
default=True,
help="Skip building Source CDROM")

oparser.add_option(
"--keys_dir",
dest="keys_dir",
default=None,
help="directory, where to find the debian archive keys")

(opt, args) = oparser.parse_args(argv)

if not args:
Expand Down Expand Up @@ -172,7 +178,7 @@ def run_command(argv):
os.putenv("no_proxy", "localhost,127.0.0.1")

try:
copy_kinitrd(xml.node("/initvm"), out_path)
copy_kinitrd(xml.node("/initvm"), out_path, opt.keys_dir)
except NoKinitrdException as e:
msg = str(e)
logging.error("Failure to download kernel/initrd debian Package:")
Expand Down
6 changes: 6 additions & 0 deletions elbepack/commands/initvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def run_command(argv):
default=False,
help="Also make 'initvm submit' build an SDK.")

oparser.add_option(
"--keys_dir",
dest="keys_dir",
default=None,
help="directory, where to find the debian archive keys")

PreprocessWrapper.add_options(oparser)

(opt, args) = oparser.parse_args(argv)
Expand Down
21 changes: 12 additions & 9 deletions elbepack/debinstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, base_url, fname, fname_list):
m.group(1))


def setup_apt_keyring(gpg_home, keyring_fname):
def setup_apt_keyring(gpg_home, keyring_fname, keys_dir):
ring_path = os.path.join(gpg_home, keyring_fname)
if not os.path.isdir("/etc/apt/trusted.gpg.d"):
print("/etc/apt/trusted.gpg.d doesn't exist")
Expand All @@ -90,13 +90,16 @@ def setup_apt_keyring(gpg_home, keyring_fname):
'--batch ' \
f'--homedir "{gpg_home}"'

trustkeys = os.listdir("/etc/apt/trusted.gpg.d")
trustkeys = [os.path.join("/etc/apt/trusted.gpg.d", f)
for f in os.listdir("/etc/apt/trusted.gpg.d")]
if keys_dir:
trustkeys = trustkeys + [os.path.join(keys_dir, f)
for f in os.listdir(keys_dir)]

for key in trustkeys:
print(f"Import {key}: ")
try:
system(
f'gpg {gpg_options} '
f'--import "{os.path.join("/etc/apt/trusted.gpg.d", key)}"')
system(f'gpg {gpg_options} --import "{key}"')
except CommandError:
print(f'adding keyring "{key}" to keyring "{ring_path}" failed')

Expand Down Expand Up @@ -144,11 +147,11 @@ def verify_release(tmp, base_url):
sig.close()


def download_kinitrd(tmp, suite, mirror, skip_signature=False):
def download_kinitrd(tmp, suite, mirror, keys_dir, skip_signature=False):
base_url = f"{mirror.replace('LOCALMACHINE', 'localhost')}/dists/{suite}/"
installer_path = "main/installer-amd64/current/images/"

setup_apt_keyring(tmp.fname('/'), 'pubring.gpg')
setup_apt_keyring(tmp.fname('/'), 'pubring.gpg', keys_dir)

# download release file
download(base_url + "Release", tmp.fname('Release'))
Expand Down Expand Up @@ -201,7 +204,7 @@ def get_primary_mirror(prj):
return mirror


def copy_kinitrd(prj, target_dir):
def copy_kinitrd(prj, target_dir, keys_dir):

suite = prj.text("suite")

Expand All @@ -217,7 +220,7 @@ def copy_kinitrd(prj, target_dir):
os.path.join(target_dir, "initrd.gz"))
else:
mirror = get_primary_mirror(prj)
download_kinitrd(tmp, suite, mirror, prj.has("noauth"))
download_kinitrd(tmp, suite, mirror, keys_dir, prj.has("noauth"))

copyfile(tmp.fname("initrd.gz"),
os.path.join(target_dir, "initrd.gz"))
Expand Down
3 changes: 3 additions & 0 deletions elbepack/initvmaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ def execute(self, initvmdir, opt, args):
if not opt.build_sources:
init_opts += ' --skip-build-source'

if opt.keys_dir:
init_opts += f' --keys_dir "{opt.keys_dir}"'

with PreprocessWrapper(xmlfile, opt) as ppw:
if cdrom:
system(
Expand Down