server-prep.sh: valid_pubkey accepts a private key when bash is older than 5.1

Aperta Adatta ai principianti
#222 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bash, shell
Ambito
cli, security

Direzione di ricerca

Leggi valid_pubkey in server-prep.sh e il test della chiave privata in tests/unit/server-prep.bats, aggiunto in #214. Aggiorna il controllo per usare ssh-keygen -l -f - con lo standard input, quindi rimuovi lo skip del test in base alla versione di bash. Il lavoro è completato quando le chiavi private vengono rifiutate e quelle pubbliche accettate in tutte le versioni di bash supportate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

claude enhancement priority: low size: S

What

valid_pubkey in server-prep.sh checks a key with:

valid_pubkey() { [[ -n "$1" ]] && ssh-keygen -l -f /dev/stdin <<<"$1" >/dev/null 2>&1; }

Whether it rejects a private key depends on how bash passes the herestring:

  • bash 5.1 and later pass a short herestring through a pipe. ssh-keygen sees "PRIVATE KEY" on the first line, opens /dev/stdin again to read it as a private key, finds the pipe empty and fails: the key is rejected (good).
  • bash 5.0 and older use a temporary file. Opening /dev/stdin again reads the file from the start, ssh-keygen fingerprints the private key and exits 0: the private key is accepted as ADMIN_PUBKEY or PANEL_PUBKEY.

Every supported system (Ubuntu 22.04+, Debian 12/13) has bash 5.1 or later, so this does not happen on a server today. It is a robustness fix, so the check does not depend on the bash version.

Checked with OpenSSH 10.2: a private key given as a regular file on stdin to ssh-keygen -l -f /dev/stdin exits 0; with -f - it exits 255 both from a pipe and from a file, and a public key still exits 0.

Proposed change

Read the key from standard input with -f -, which never falls back to loading a private key:

valid_pubkey() { [[ -n "$1" ]] && printf '%s\n' "$1" | ssh-keygen -l -f - >/dev/null 2>&1; }

ssh-keygen -l -f - (fingerprint from standard input) is much older than the OpenSSH of any supported system.

Then the private-key test in tests/unit/server-prep.bats (from #214) no longer needs its skip before bash 5.1.

Where it came from

Review of #214 (bats unit tests): https://github.com/exceev-consulting/server-prep/pull/214

🤖 Automated by Claude Code (review-fixer routine). A maintainer reviews before anything is merged.

Lingua principale
Shell
Stelle
2
Fork
3
Merge medio
2g 14m
PR unite (30g)
47

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di exceev-consulting/server-prep

Tutte le issue di exceev-consulting/server-prep

Issue simili

Altre issue su Shell/Bash

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.