Proteggere Git in DevOps: secret, firma e hook
Imparate a tenere i segreti fuori da Git, a verificare l’autore tramite commit firmati e ad applicare automaticamente le policy con gli hook nelle pipeline DevOps e di automazione.
Proteggere Git in DevOps: secret, firma e hook è una lezione Git Advanced: Monorepo, Submodules & Workflows gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Git Advanced: Monorepo, Submodules & Workflows, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Git Advanced: Monorepo, Submodules & Workflows include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Git Is a Security Surface
In DevOps, Git drives deployments. That makes the repository a security surface: a leaked secret or a forged commit can compromise production. Securing Git is part of securing the pipeline.
Keep Secrets Out of History
Never commit API keys, tokens, or passwords. Once in history, a secret is effectively public forever, even after deletion, because the old commit still contains it.
Use a .gitignore and environment variables instead.
.env
*.pem
secrets/
config/credentials.jsonScanning for Leaked Secrets
Automated scanners catch secrets before they merge. Wire one into CI so a leaked token fails the build.
gitleaks detect --source . --verboseIf a Secret Leaks
If a secret reaches the remote, two steps are mandatory:
- Rotate the credential immediately — assume it is compromised
- Purge it from history with a tool like
git filter-repo
Rotation matters more than purging.
git filter-repo --path config/credentials.json --invert-pathsSigning Commits
Signed commits prove who authored them. In automated environments this prevents impersonation and lets pipelines trust commit authorship.
git config commit.gpgsign true
git commit -S -m 'Deploy config update'Verifying Signatures
CI can require that every commit on a protected branch is signed and verified, rejecting unsigned or unknown-key commits before they deploy.
git log --show-signature -1
git verify-commit HEADClient-Side Hooks
Hooks run scripts at Git lifecycle events. A pre-commit hook can block secrets or run linters before a commit is ever created.
#!/bin/sh
# .git/hooks/pre-commit
gitleaks protect --staged || exit 1Server-Side Hooks
Client hooks can be bypassed. Server-side hooks (pre-receive) enforce policy centrally, rejecting non-compliant pushes for everyone, no matter their local setup.
#!/bin/sh
# pre-receive: reject force pushes to main
while read old new ref; do
if [ "$ref" = 'refs/heads/main' ]; then
echo 'Direct pushes to main are blocked'; exit 1
fi
doneBranch Protection as Policy
Platform branch-protection rules complement hooks: require reviews, passing CI, and signed commits before merge. Policy enforced at the platform cannot be bypassed locally.
Least Privilege for Automation
Deploy bots should use scoped, short-lived tokens, not personal credentials. Grant only the access a job needs, and rotate tokens regularly to limit blast radius.
Auditing the Audit Trail
Git history and platform logs form an audit trail. Protect them: disallow history rewrites on shared branches and review who has admin rights, so the record of what shipped stays trustworthy.
Quick Check
Test your understanding of Git security in DevOps.
Recap
You learned to secure Git in DevOps: keep secrets out of history, scan automatically, rotate then purge on leaks, use signed commits, enforce policy with client and server-side hooks and branch protection, and apply least privilege to automation tokens.
Domande Frequenti
La lezione «Proteggere Git in DevOps: secret, firma e hook» è gratuita?
Sì — il testo completo di «Proteggere Git in DevOps: secret, firma e hook» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Git Advanced: Monorepo, Submodules & Workflows, passa a CoddyKit PRO. Il corso Git Advanced: Monorepo, Submodules & Workflows include 4 lezioni in totale.
Cosa imparerò in «Proteggere Git in DevOps: secret, firma e hook»?
Imparate a tenere i segreti fuori da Git, a verificare l’autore tramite commit firmati e ad applicare automaticamente le policy con gli hook nelle pipeline DevOps e di automazione. Eserciti Git Advanced: Monorepo, Submodules & Workflows con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Git Advanced: Monorepo, Submodules & Workflows?
Non è richiesta alcuna esperienza precedente. Git Advanced: Monorepo, Submodules & Workflows su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Proteggere Git in DevOps: secret, firma e hook»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Git Advanced: Monorepo, Submodules & Workflows?
Sì. Ogni lezione Git Advanced: Monorepo, Submodules & Workflows include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Principi e implementazione di GitOps
- Automatizzare le attività Git con gli script
- Integrazione di Git con CI/CD
- Proteggere Git in DevOps: secret, firma e hook