From ff12ba72b50745a9d6ef0544bfdc6fe02edf6e2a Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 23 Nov 2023 07:48:29 +0100 Subject: [PATCH] confd: exctract password also for failure-config This patch adds generation of the 20-authentication.json snippet also for failure-config. The gen-admin-auth script is extended with shell parameter, since the default shell differs from factory-config. Signed-off-by: Joachim Wiberg --- src/confd/bin/bootstrap | 11 +++++++++-- src/confd/bin/gen-admin-auth | 6 ++++-- src/confd/share/failure.d/10-authentication.json | 12 ------------ src/confd/share/failure.d/Makefile.am | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 src/confd/share/failure.d/10-authentication.json diff --git a/src/confd/bin/bootstrap b/src/confd/bin/bootstrap index 67c68025..dec9667f 100755 --- a/src/confd/bin/bootstrap +++ b/src/confd/bin/bootstrap @@ -83,8 +83,9 @@ factory() # shellcheck disable=SC2086 gen-interfaces $GEN_IFACE_OPTS >"$FACTORY_D/20-interfaces.json" - if ! gen-admin-auth >"$FACTORY_D/10-authentication.json"; then - console_error "Unable to create factory config, gen-admin-auth failed" + # Extract password for admin user from VPD + if ! gen-admin-auth infix-shell-type:clish >"$FACTORY_D/20-authentication.json"; then + console_error "Unable to create factory-config, gen-admin-auth failed" return fi @@ -107,6 +108,12 @@ failure() gen-hostname "$FAIL_HOSTNAME" >"$FAILURE_D/20-hostname.json" gen-interfaces >"$FAILURE_D/20-interfaces.json" + # Same password as factory-config, but another login shell + if ! gen-admin-auth infix-shell-type:bash >"$FAILURE_D/20-authentication.json"; then + console_error "Unable to create failure-config, gen-admin-auth failed" + return + fi + [ -s "$FAILURE_D/20-hostkey.json" ] || gen-hostkeys >"$FAILURE_D/20-hostkey.json" # Optional failure/error config to generate (or override) for br2-externals diff --git a/src/confd/bin/gen-admin-auth b/src/confd/bin/gen-admin-auth index 8c28d890..ac19718d 100755 --- a/src/confd/bin/gen-admin-auth +++ b/src/confd/bin/gen-admin-auth @@ -1,6 +1,8 @@ #!/bin/sh +# This script extracts the admin user's password hash from VPD -pwhash="$(cat /run/system.json | jq '.pwhash')" +shell="$1" +pwhash="$(jq .pwhash /run/system.json)" if [ -z "$pwhash" ] || [ "$pwhash" = "null" ]; then exit 1 @@ -14,7 +16,7 @@ cat <