0Pricing
Git Advanced: Monorepo, Submodules & Workflows · レッスン

DevOpsにおけるGitのセキュリティ:シークレット、署名、フック

DevOpsおよび自動化パイプラインで、Gitに秘密情報を含めない方法、署名付きコミットで作成者を検証する方法、フックでポリシーを自動的に適用する方法を学びます。

「DevOpsにおけるGitのセキュリティ:シークレット、署名、フック」はCoddyKit上の無料Git Advanced: Monorepo, Submodules & Workflowsレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはGit Advanced: Monorepo, Submodules & Workflows学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Git Advanced: Monorepo, Submodules & Workflowsコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.json

Scanning for Leaked Secrets

Automated scanners catch secrets before they merge. Wire one into CI so a leaked token fails the build.

gitleaks detect --source . --verbose

If 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-paths

Signing 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 HEAD

Client-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 1

Server-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
done

Branch 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.

よくある質問

「DevOpsにおけるGitのセキュリティ:シークレット、署名、フック」レッスンは無料ですか?

はい。「DevOpsにおけるGitのセキュリティ:シークレット、署名、フック」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Git Advanced: Monorepo, Submodules & Workflowsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Git Advanced: Monorepo, Submodules & Workflowsコースには全4レッスンが含まれています。

「DevOpsにおけるGitのセキュリティ:シークレット、署名、フック」で何を学びますか?

DevOpsおよび自動化パイプラインで、Gitに秘密情報を含めない方法、署名付きコミットで作成者を検証する方法、フックでポリシーを自動的に適用する方法を学びます。 ブラウザで直接実行するハンズオンコードでGit Advanced: Monorepo, Submodules & Workflowsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Git Advanced: Monorepo, Submodules & Workflowsを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのGit Advanced: Monorepo, Submodules & Workflowsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「DevOpsにおけるGitのセキュリティ:シークレット、署名、フック」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このGit Advanced: Monorepo, Submodules & Workflowsレッスンでコードを書いて実行できますか?

はい。すべてのGit Advanced: Monorepo, Submodules & Workflowsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. GitOpsの原則と実装
  2. スクリプトによるGitタスクの自動化
  3. GitとCI/CDの統合
  4. DevOpsにおけるGitのセキュリティ:シークレット、署名、フック
← Git Advanced: Monorepo, Submodules & Workflowsに戻る