fix(ci): проверка sops должна обходить все secrets/, а не только корневой
Проверка #7 искала файлы только в secrets/ и не замечала вложенные каталоги: modules/server/secrets/, modules/containers/secrets/, modules/essentials/secrets/, modules/wsl/secrets/. Теперь обходятся все файлы под */secrets/*, а совпадения, требующие непривязанного правила (поведение sops для вложенных каталогов), перечисляются отдельно — предположение видно, а не спрятано. PASS: 2 FAIL: 0; 13 файлов помечены как требующие непривязанного правила.
This commit is contained in:
1 parent
029725499c
commit
95a4f92075
1 file changed
+24
-5
+24
-5
@@ -72,19 +72,38 @@ check_nix_flake_check() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
check_sops_path_regex() {
|
check_sops_path_regex() {
|
||||||
echo "Check #7: secrets/ files match .sops.yaml path_regex ..."
|
echo "Check #7: sops-encrypted files match .sops.yaml path_regex ..."
|
||||||
local regex
|
local regex
|
||||||
regex=$(awk -F'path_regex:[[:space:]]*' '/path_regex:/ {print $2; exit}' .sops.yaml)
|
regex=$(awk -F'path_regex:[[:space:]]*' '/path_regex:/ {print $2; exit}' .sops.yaml)
|
||||||
if [ -z "${regex:-}" ]; then
|
if [ -z "${regex:-}" ]; then
|
||||||
echo " SKIP: no path_regex found in .sops.yaml"
|
echo " SKIP: no path_regex found in .sops.yaml"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
local mismatches=()
|
local mismatches=() unanchored=() f
|
||||||
while IFS= read -r -d '' f; do
|
# Every file under any `secrets/` directory is a candidate for the sops
|
||||||
if ! printf '%s\n' "$f" | grep -Eqx "${regex}"; then
|
# creation rule — not only the ones in the top-level `secrets/`. The
|
||||||
|
# repo keeps them in five places: secrets/, modules/server/secrets/,
|
||||||
|
# modules/containers/secrets/, modules/essentials/secrets/ and
|
||||||
|
# modules/wsl/secrets/.
|
||||||
|
#
|
||||||
|
# Matching semantics: sops compares path_regex against the path, and the
|
||||||
|
# comparison is not anchored at the start of the path for a rule like
|
||||||
|
# `secrets/[^/]+...`. A file is therefore counted as protected when it
|
||||||
|
# matches the rule, and files that match only in the unanchored form are
|
||||||
|
# listed separately so the assumption stays visible instead of silent.
|
||||||
|
while IFS= read -r f; do
|
||||||
|
f="${f#./}"
|
||||||
|
if ! printf '%s\n' "$f" | grep -Eq "${regex}"; then
|
||||||
mismatches+=("$f")
|
mismatches+=("$f")
|
||||||
|
elif ! printf '%s\n' "$f" | grep -Eq "^${regex}"; then
|
||||||
|
unanchored+=("$f")
|
||||||
fi
|
fi
|
||||||
done < <(find secrets -type f -print0 2>/dev/null)
|
done < <(find . -type f -path '*/secrets/*' -not -path './.git/*' 2>/dev/null | sort)
|
||||||
|
if [ "${#unanchored[@]}" -gt 0 ]; then
|
||||||
|
echo " NOTE: ${#unanchored[@]} file(s) match the rule only when it is not anchored"
|
||||||
|
echo " at the start of the path (sops behaviour for nested secrets/):"
|
||||||
|
printf ' %s\n' "${unanchored[@]}"
|
||||||
|
fi
|
||||||
if [ "${#mismatches[@]}" -eq 0 ]; then
|
if [ "${#mismatches[@]}" -eq 0 ]; then
|
||||||
report 0 "sops path_regex ($regex)"
|
report 0 "sops path_regex ($regex)"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in new issue
Block a user