Files
Febe/.gitea/scripts/segreti.sh
Alby96andClaude Opus 5.5 009e7d6710 CI e installatore: commenti degli script in inglese (#43)
La regola del progetto è «codice e commenti in inglese; interfaccia, documenti
e messaggi in italiano», e gli script di .gitea/ (script e flussi), di
installer/ e docker/entrypoint.sh avevano ancora i commenti in italiano
(decisione di Alberto del 29 novembre 2026). Cambiano solo i commenti: i
messaggi che una persona legge (echo, ::warning::, ::error::, nomi dei passi,
note della release) restano in italiano e nessun comando cambia. I programmi
awk e gli script finti delle prove erano già in inglese.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:03:13 +01:00

52 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Looks for secrets (tokens, keys, passwords) with gitleaks, at a fixed version (strumento.sh), in the whole history
# of the commit being verified: every commit it descends from, not only the last one. Each branch is checked on its
# own push (main at every merge), so a finding on one branch does not block the others. A secret never appears in
# full: --redact replaces it with REDACTED in the log and in the report, and here only rule, file, line, commit and
# fingerprint are printed.
#
# .gitea/scripts/segreti.sh [cartella del rapporto]
#
# What to do with a finding: docs/processo.md, «Rilievi di sicurezza». In short: a real secret is revoked at once
# (removing it from the history is not enough); a false alarm already checked (fake test data) goes into
# .gitleaksignore with its fingerprint and, on the line above, a comment saying what it is and who checked it.
set -euo pipefail
radice="$(git rev-parse --show-toplevel)"
rapporti="${1:-$radice/out/sicurezza}"
strumenti="${RUNNER_TEMP:-/tmp}/febe-strumenti"
if [[ "$(git -C "$radice" rev-parse --is-shallow-repository)" == "true" ]]; then
echo "Il clone è parziale: per cercare in tutta la storia serve actions/checkout con fetch-depth: 0." >&2
exit 2
fi
bash "$radice/.gitea/scripts/strumento.sh" gitleaks "$strumenti"
mkdir -p "$rapporti"
rapporto="$rapporti/gitleaks.json"
argomenti=(git "$radice" --log-opts="--full-history HEAD" --redact --no-banner --no-color --exit-code 1 --log-level warn
--report-format json --report-path "$rapporto")
[[ -f "$radice/.gitleaks.toml" ]] && argomenti+=(--config "$radice/.gitleaks.toml")
[[ -f "$radice/.gitleaksignore" ]] && argomenti+=(--gitleaks-ignore-path "$radice/.gitleaksignore")
commit=$(git -C "$radice" rev-list --count HEAD)
stato=0
"$strumenti/gitleaks" "${argomenti[@]}" || stato=$?
if ((stato == 0)); then
echo "Nessun segreto in $commit commit."
exit 0
fi
# The summary with our own JSON reader (json.sh, awk): no jq.
if [[ -s "$rapporto" ]] \
&& rilievi=$(bash "$radice/.gitea/scripts/json.sh" campi "*" RuleID,File,StartLine,Commit,Fingerprint "$rapporto"); then
quanti=0
[[ -z "$rilievi" ]] || quanti=$(wc -l <<< "$rilievi")
echo "Possibili segreti: $((quanti)) (in $commit commit). Regola, file:riga, commit, impronta per .gitleaksignore:" >&2
[[ -z "$rilievi" ]] || awk -F '\t' '{ printf " %s %s:%s commit %s impronta %s\n", $1, $2, $3, substr($4, 1, 12), $5 }' <<< "$rilievi" >&2
else
echo "gitleaks è uscito con $stato: vedi il registro qui sopra e il rapporto $rapporto." >&2
fi
exit "$stato"