Take authorized_keys on the cidata drive instead of ssh.json
The JSON wrapper was the one piece of autoinstall input that wasn't an existing format: the other files are the configurator's own output, and the keys end up in sshd's authorized_keys anyway. So take that file directly -- one key per line, comments and key options work as they do everywhere else -- and drop the parsing in between. The only thing JSON bought was parse-error detection, and the phase still fails loudly when the file carries no usable keys. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be68a76a44
commit
f11a70c6ba
9 files changed
+80
-86
No files matched your search
@@ -38,15 +38,15 @@ mount -o ro "$device" "$mnt" || exit 1
|
||||
loaded=1
|
||||
if [[ -f $mnt/user_configuration.json && -f $mnt/user_credentials.json ]]; then
|
||||
files=("$mnt"/user_configuration.json "$mnt"/user_credentials.json)
|
||||
for file in user_full_name.txt user_email_address.txt user_encrypt_installation.txt ssh.json; do
|
||||
for file in user_full_name.txt user_email_address.txt user_encrypt_installation.txt authorized_keys; do
|
||||
[[ -f $mnt/$file ]] && files+=("$mnt/$file")
|
||||
done
|
||||
if cp "${files[@]}" "$dest"/; then
|
||||
loaded=0
|
||||
else
|
||||
# A partial copy must not leave files behind: the wizard cleans up only
|
||||
# what it writes itself, so a half-copied ssh.json would leak into the
|
||||
# interactive install that follows.
|
||||
# what it writes itself, so a half-copied authorized_keys would leak into
|
||||
# the interactive install that follows.
|
||||
for file in "${files[@]}"; do
|
||||
rm -f "$dest/${file##*/}"
|
||||
done
|
||||
|
||||
@@ -11,13 +11,13 @@ set -eEo pipefail
|
||||
# doesn't choke on flags it doesn't recognize.
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--config) export OMARCHY_INSTALL_CONFIG="$2"; shift 2 ;;
|
||||
--creds) export OMARCHY_INSTALL_CREDS="$2"; shift 2 ;;
|
||||
--full-name-file) export OMARCHY_INSTALL_FULL_NAME_FILE="$2"; shift 2 ;;
|
||||
--email-file) export OMARCHY_INSTALL_EMAIL_FILE="$2"; shift 2 ;;
|
||||
--encrypt-file) export OMARCHY_INSTALL_ENCRYPT_FILE="$2"; shift 2 ;;
|
||||
--ssh-keys-file) export OMARCHY_INSTALL_SSH_KEYS_FILE="$2"; shift 2 ;;
|
||||
*) echo "omarchy-iso-install: unknown arg $1" >&2; exit 2 ;;
|
||||
--config) export OMARCHY_INSTALL_CONFIG="$2"; shift 2 ;;
|
||||
--creds) export OMARCHY_INSTALL_CREDS="$2"; shift 2 ;;
|
||||
--full-name-file) export OMARCHY_INSTALL_FULL_NAME_FILE="$2"; shift 2 ;;
|
||||
--email-file) export OMARCHY_INSTALL_EMAIL_FILE="$2"; shift 2 ;;
|
||||
--encrypt-file) export OMARCHY_INSTALL_ENCRYPT_FILE="$2"; shift 2 ;;
|
||||
--authorized-keys-file) export OMARCHY_INSTALL_AUTHORIZED_KEYS_FILE="$2"; shift 2 ;;
|
||||
*) echo "omarchy-iso-install: unknown arg $1" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class InstallContext:
|
||||
full_name: str
|
||||
email: str
|
||||
encrypt: bool
|
||||
ssh_keys_path: Path | None
|
||||
authorized_keys_path: Path | None
|
||||
|
||||
user_configuration: dict
|
||||
user_credentials: dict
|
||||
@@ -60,7 +60,7 @@ class InstallContext:
|
||||
full_name=_read_text(os.environ.get("OMARCHY_INSTALL_FULL_NAME_FILE")),
|
||||
email=_read_text(os.environ.get("OMARCHY_INSTALL_EMAIL_FILE")),
|
||||
encrypt=_read_text(os.environ.get("OMARCHY_INSTALL_ENCRYPT_FILE")).lower() in ("true", "yes", "1"),
|
||||
ssh_keys_path=_optional_path(os.environ.get("OMARCHY_INSTALL_SSH_KEYS_FILE")),
|
||||
authorized_keys_path=_optional_path(os.environ.get("OMARCHY_INSTALL_AUTHORIZED_KEYS_FILE")),
|
||||
user_configuration=user_configuration,
|
||||
user_credentials=json.loads(creds_path.read_text()),
|
||||
arch_config_path=arch_config_path,
|
||||
@@ -107,8 +107,8 @@ def _default_omarchy_install(user_configuration: dict) -> dict[str, Any]:
|
||||
|
||||
def _optional_path(path: str | None) -> Path | None:
|
||||
"""A path the caller always passes but that need not exist. The live ISO
|
||||
passes --ssh-keys-file on every install; only autoinstall drives put a file
|
||||
there."""
|
||||
passes --authorized-keys-file on every install; only autoinstall drives put
|
||||
a file there."""
|
||||
if not path:
|
||||
return None
|
||||
p = Path(path)
|
||||
|
||||
@@ -22,7 +22,6 @@ Phase ordering (full-disk and protected/pre-mounted):
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
@@ -1314,10 +1313,10 @@ def configure_login(ctx: InstallContext) -> None:
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
def configure_ssh_access(ctx: InstallContext) -> None:
|
||||
if ctx.ssh_keys_path is None:
|
||||
if ctx.authorized_keys_path is None:
|
||||
return
|
||||
|
||||
keys = _authorized_keys(ctx.ssh_keys_path)
|
||||
keys = _authorized_keys(ctx.authorized_keys_path)
|
||||
info(f"› installing {len(keys)} SSH key(s) for {ctx.username}")
|
||||
|
||||
ssh_dir = ctx.target / "home" / ctx.username / ".ssh"
|
||||
@@ -1362,21 +1361,20 @@ def configure_ssh_access(ctx: InstallContext) -> None:
|
||||
|
||||
|
||||
def _authorized_keys(path: Path) -> list[str]:
|
||||
"""Parse the autoinstall ssh.json: a JSON array of public key strings.
|
||||
"""Read the autoinstall authorized_keys: sshd's own format, one public key
|
||||
per line, with blank lines and # comments dropped.
|
||||
|
||||
Raise rather than skip on anything unusable. An install that "succeeds"
|
||||
into a machine nobody can log into is worse than one that stops with the
|
||||
reason on screen.
|
||||
"""
|
||||
try:
|
||||
keys = json.loads(path.read_text())
|
||||
except (OSError, json.JSONDecodeError) as exc:
|
||||
raise RuntimeError(f"{path} is not readable JSON: {exc}") from exc
|
||||
lines = path.read_text().splitlines()
|
||||
except OSError as exc:
|
||||
raise RuntimeError(f"{path} is not readable: {exc}") from exc
|
||||
|
||||
if not isinstance(keys, list) or not all(isinstance(key, str) for key in keys):
|
||||
raise RuntimeError(f"{path} must be a JSON array of public key strings")
|
||||
|
||||
keys = [key.strip() for key in keys if key.strip()]
|
||||
keys = [line.strip() for line in lines]
|
||||
keys = [key for key in keys if key and not key.startswith("#")]
|
||||
if not keys:
|
||||
raise RuntimeError(f"{path} contains no SSH keys")
|
||||
|
||||
|
||||
Reference in new issue
Block a user