V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 2m2s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-10-26 16:48:17 +00:00
parent 1c83813ec4
commit 85c46f3c4c
5 changed files with 42 additions and 41 deletions

View File

@@ -122,6 +122,7 @@ ciss_secrets_wiper() {
readonly -f ciss_secrets_wiper
#######################################
# Purpose:
# Parsing of only "*.value" keys from 'SECRETS.yaml' into Bash globals.
# If the file contains SOPS markers, decrypt once (streaming) with sops/age, then yq parses in a single pass.
# No base64, plain values preserved (including newlines). No repeated per-key decrypts or yq calls.
@@ -143,8 +144,6 @@ readonly -f ciss_secrets_wiper
# ERR_MISSING_AGE_KEY: on failure
#######################################
yaml_secret() {
# TODO: Remove debug echos
### Declare Arrays, HashMaps, and Variables.
declare -r SOPS_AGE_KEY_FILE="${CISS_SECRETS_AGE}"
declare -a __names=()
@@ -155,8 +154,7 @@ yaml_secret() {
__umask=$(umask)
umask 0077
# TODO: guard_trace on
#guard_trace on
guard_trace on
secrets_encrypted="$(yq -r '.secrets.x_files // false' -- "${secrets_if}")" || secrets_encrypted="false"
do_log "debug" "file_only" "1256() 'secrets_encrypted' according to secrets.x_files: '${secrets_encrypted}'."
@@ -209,6 +207,8 @@ yaml_secret() {
# shellcheck disable=SC1091 source=./${__SECRETS}
source "${__SECRETS}"
ciss_secrets_wiper "${__SECRETS}"
# shellcheck disable=SC2312
mapfile -t __names < <(printf '%s\n' "${!secrets_@}")
@@ -216,33 +216,30 @@ yaml_secret() {
### Keep only *_value variables
[[ "${__name}" == *_value ]] || continue
echo "__name ${__name}"
### Validate strict Bash identifier (defensive: strip accidental CR).
__name="${__name%$'\r'}"
[[ "${__name}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
echo "__name ${__name}"
### Only read if actually set; indirect check without triggering nounset.
if [[ -n "${!__name+x}" ]]; then
__val="${!__name}"
echo "__val ${__val}"
else
__val=""
echo "__val ${__val}"
fi
### Strip suffix/prefix for the map key.
__base="${__name%_value}"
echo "__base ${__base}"
__path_wo_prefix="${__base#secrets_}"
echo "__path_wo_prefix ${__path_wo_prefix}"
### Canonical CISS name.
__varname="$(ciss_secret_varname_from_path "${__path_wo_prefix}")"
echo "__varname ${__varname}"
# Assign verbatim (preserves newlines)
### Assign verbatim (preserves newlines).
unset -v "${__varname}"
declare -g "${__varname}"
printf -v "${__varname}" '%s' "${__val}"
@@ -253,16 +250,14 @@ yaml_secret() {
### Hygiene: remove the intermediate variables to reduce secret surface, e.g., unset 'secrets_*_value' after transfer.
for __name in "${__names[@]}"; do
unset -v "${__name}"
done
umask "${__umask}"
echo "Inside 1256()"
sleep 60
# TODO: guard_trace off
#guard_trace off
guard_trace off
guard_dir; return 0
}

View File

@@ -0,0 +1,76 @@
#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.git
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
# SPDX-PackageName: CISS.debian.installer
# SPDX-Security-Contact: security@coresecret.eu
guard_sourcing || return "${ERR_GUARD_SOURCE}"
#######################################
# Generates 'nuke=HASH' Bootparameter.
# Globals:
# CISS_SECRET_LUKS_NUKE
# DIR_CNF
# VAR_NUKE_HASH
# Arguments:
# None
# Returns:
# 0: on success
# ERR_GENERATE_SALT: on failure
#######################################
nuke_passphrase() {
#guard_trace on
### Declare Arrays, HashMaps, and Variables.
declare var_nuke_pwd="${CISS_SECRET_LUKS_NUKE}"
declare var_temp_nuke_hash="" var_salt="" var_nuke_rounds=""
# shellcheck disable=SC2312
var_nuke_rounds="$(
yq -r '
.recipe
| to_entries[] # iterate recipe items
| .value # the map under each item
| select(has("control") and (.control | has("nuke_rounds")))
| .control.nuke_rounds
| tostring
' "${DIR_CNF}/partitioning.yaml" | head -n1
)"
[[ -z "${var_nuke_pwd}" ]] && return 0
if ! var_salt="$(generate_salt)"; then
return "${ERR_GENERATE_SALT}"
fi
var_temp_nuke_hash=$(mkpasswd --method=sha-512 --salt="${var_salt}" --rounds="${var_nuke_rounds:-8388608}" "${var_nuke_pwd}")
declare -grx VAR_NUKE_HASH="${var_temp_nuke_hash}"
echo "Inside 1257"
echo "CISS_SECRET_LUKS_NUKE: ${CISS_SECRET_LUKS_NUKE}"
unset var_temp_nuke_hash var_nuke_pwd CISS_SECRET_LUKS_NUKE
do_log "debug" "file_only" "0105() NUKE hash starts with: [${VAR_NUKE_HASH:0:32}...]"
#guard_trace off
echo "Inside 1257"
sleep 60
guard_dir; return 0
}
### Prevents accidental 'unset -f'.
# shellcheck disable=SC2034
readonly -f nuke_passphrase
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh