0Pricing
Git Advanced: Monorepo, Submodules & Workflows · درس

تأمين Git في DevOps: الأسرار والتوقيع والخطافات

تعلّم كيفية إبقاء الأسرار خارج Git، والتحقق من هوية المؤلف باستخدام عمليات commit موقّعة، وفرض السياسات تلقائيًا باستخدام hooks في مسارات DevOps والأتمتة.

تأمين Git في DevOps: الأسرار والتوقيع والخطافات درس مجاني في Git Advanced: Monorepo, Submodules & Workflows على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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.

الأسئلة الشائعة

هل درس «تأمين Git في DevOps: الأسرار والتوقيع والخطافات» مجاني؟

نعم — نص درس «تأمين Git في DevOps: الأسرار والتوقيع والخطافات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Git Advanced: Monorepo, Submodules & Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة Git Advanced: Monorepo, Submodules & Workflows 4 دروس في المجموع.

ماذا ستتعلم في «تأمين Git في DevOps: الأسرار والتوقيع والخطافات»؟

تعلّم كيفية إبقاء الأسرار خارج Git، والتحقق من هوية المؤلف باستخدام عمليات commit موقّعة، وفرض السياسات تلقائيًا باستخدام hooks في مسارات DevOps والأتمتة. تتمرن على Git Advanced: Monorepo, Submodules & Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Git Advanced: Monorepo, Submodules & Workflows؟

لا تُشترط خبرة سابقة. Git Advanced: Monorepo, Submodules & Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «تأمين Git في DevOps: الأسرار والتوقيع والخطافات»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Git Advanced: Monorepo, Submodules & Workflows هذا؟

نعم. كل درس في Git Advanced: Monorepo, Submodules & Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. مبادئ GitOps وتطبيقها
  2. أتمتة مهام Git باستخدام البرامج النصية
  3. تكامل Git مع CI/CD
  4. تأمين Git في DevOps: الأسرار والتوقيع والخطافات
← العودة إلى Git Advanced: Monorepo, Submodules & Workflows