console_conf: identity: allow use of prepared host keys fingerprints

In strict snap confinement, sshd config or host keys are not accessible.
If strict confinement is detected, instead allow reuse of
the host keys fingerprints already prepared by invoking process.
Prepared fingerprints are stored in: /run/console-conf/host-fingerprints.txt

Signed-off-by: Ondrej Kubik <ondrej.kubik@canonical.com>
This commit is contained in:
Ondrej Kubik 2023-10-10 14:09:22 +01:00 committed by Maciej Borzecki
parent 5a1a2b0faa
commit e6aa7e1dcc
1 changed files with 13 additions and 1 deletions

View File

@ -19,6 +19,7 @@ import os
import pwd import pwd
import shlex import shlex
import sys import sys
from pathlib import Path
from console_conf.ui.views import IdentityView, LoginView from console_conf.ui.views import IdentityView, LoginView
from subiquitycore.snapd import SnapdConnection from subiquitycore.snapd import SnapdConnection
@ -116,10 +117,21 @@ def write_login_details(fp, username, ips):
) )
else: else:
first_ip = ips[0] first_ip = ips[0]
key_info = None
if os.getenv("SNAP_CONFINEMENT", "classic") == "strict":
# if we run in confinement, we have no direct accesss to host
# keys info use prepared finger prints if exist
host_fingerprints_path = "/run/console-conf/host-fingerprints.txt"
host_fingerprints = Path(host_fingerprints_path)
if host_fingerprints.is_file():
fingerprints = open(host_fingerprints_path, "r")
key_info = fingerprints.read()
else:
key_info = host_key_info()
fp.write( fp.write(
login_details_tmpl.format( login_details_tmpl.format(
sshcommands=sshcommands, sshcommands=sshcommands,
host_key_info=host_key_info(), host_key_info=key_info,
tty_name=tty_name, tty_name=tty_name,
first_ip=first_ip, first_ip=first_ip,
version=version, version=version,