<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>nunogrl.com - authentication</title><link href="https://nunogrl.com/" rel="alternate"></link><link href="https://nunogrl.com/categories/authentication/atom.xml" rel="self"></link><id>https://nunogrl.com/</id><updated>2024-03-21T00:00:00+00:00</updated><entry><title>Enforcing GPG-Signed Commits in Git</title><link href="https://nunogrl.com/articles/enforcing-gpg-signed-commits-git/" rel="alternate"></link><published>2024-03-21T00:00:00+00:00</published><updated>2024-03-21T00:00:00+00:00</updated><author><name>Nuno Leitao</name></author><id>tag:nunogrl.com,2024-03-21:/articles/enforcing-gpg-signed-commits-git/</id><summary type="html">&lt;p class="first last"&gt;Learn how to enforce GPG-signed commits in Git to prevent commit impersonation and ensure code authenticity&lt;/p&gt;
</summary><content type="html">&lt;div class="section" id="problem-solution"&gt;
&lt;h2&gt;🚀 Problem &amp;amp; Solution&lt;/h2&gt;
&lt;div class="section" id="context-backstory"&gt;
&lt;h3&gt;📌 &lt;strong&gt;Context / Backstory&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;In our collaborative development environment, we discovered that Git's flexibility allows commits under any name and email. This became a security concern when we realized that GitHub identifies users by email, not SSH keys.&lt;/p&gt;
&lt;div class="mermaid" id="mermaid-diagram-1842184663821928552"&gt;
sequenceDiagram
  participant Alice
  participant Bob
  participant GitHub

  Alice-&gt;&gt;GitHub: Commit signed with alice@example.com (GPG signed)
  GitHub-&gt;&gt;GitHub: Shows "Verified" commit from Alice

  Bob-&gt;&gt;GitHub: Commit using alice@example.com (no signature)
  GitHub-&gt;&gt;GitHub: Shows commit as from "Alice" (Unverified)

  Note over GitHub: GitHub matches commits by email, not by SSH or true identity.&lt;/div&gt;&lt;/div&gt;
&lt;div class="section" id="the-problem"&gt;
&lt;h3&gt;⚠️ &lt;strong&gt;The Problem&lt;/strong&gt;&lt;/h3&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Anyone with repository access can spoof another contributor's identity&lt;/li&gt;
&lt;li&gt;Commit history could be manipulated without detection&lt;/li&gt;
&lt;li&gt;No cryptographic proof of commit authenticity&lt;/li&gt;
&lt;li&gt;GitHub's user identification relies solely on email addresses&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="the-solution"&gt;
&lt;h3&gt;💡 &lt;strong&gt;The Solution&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;We implemented mandatory GPG-signed commits, which:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Cryptographically verify commit authenticity&lt;/li&gt;
&lt;li&gt;Prevent identity spoofing&lt;/li&gt;
&lt;li&gt;Create traceable commit history&lt;/li&gt;
&lt;li&gt;Integrate with GitHub's verification system&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="who-this-helps"&gt;
&lt;h3&gt;👥 &lt;strong&gt;Who This Helps&lt;/strong&gt;&lt;/h3&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Security-conscious development teams&lt;/li&gt;
&lt;li&gt;Open-source project maintainers&lt;/li&gt;
&lt;li&gt;Regulated environments requiring audit trails&lt;/li&gt;
&lt;li&gt;Organizations needing verified commit history&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="technical-implementation"&gt;
&lt;h2&gt;⚙️ Technical Implementation&lt;/h2&gt;
&lt;p&gt;Let's visualize the GPG signing workflow:&lt;/p&gt;
&lt;div class="mermaid" id="mermaid-diagram--3822165489569652770"&gt;
flowchart LR
   C[Commit] --&gt;|Sign| G[GPG Key]
   G --&gt;|Verify| GH[GitHub]

   subgraph "Local System"
   C
   G
   end

   subgraph "Remote"
   GH
   end

   style GH fill:#f96,stroke:#333
   style G fill:#9f6,stroke:#333&lt;/div&gt;&lt;div class="section" id="setting-up-gpg-keys"&gt;
&lt;h3&gt;1️⃣ Setting Up GPG Keys&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# Generate a new GPG key&lt;/span&gt;
gpg&lt;span class="w"&gt; &lt;/span&gt;--full-generate-key

&lt;span class="c1"&gt;# List your keys&lt;/span&gt;
gpg&lt;span class="w"&gt; &lt;/span&gt;--list-secret-keys&lt;span class="w"&gt; &lt;/span&gt;--keyid-format&lt;span class="o"&gt;=&lt;/span&gt;long
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="configuring-git"&gt;
&lt;h3&gt;2️⃣ Configuring Git&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;Configure&lt;span class="w"&gt; &lt;/span&gt;Git&lt;span class="w"&gt; &lt;/span&gt;to&lt;span class="w"&gt; &lt;/span&gt;use&lt;span class="w"&gt; &lt;/span&gt;your&lt;span class="w"&gt; &lt;/span&gt;GPG&lt;span class="w"&gt; &lt;/span&gt;key
&lt;span class="gp"&gt;$ &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;config&lt;span class="w"&gt; &lt;/span&gt;--global&lt;span class="w"&gt; &lt;/span&gt;user.signingkey&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;YOUR_KEY_ID&amp;gt;
&lt;span class="gp"&gt;$ &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;config&lt;span class="w"&gt; &lt;/span&gt;--global&lt;span class="w"&gt; &lt;/span&gt;commit.gpgsign&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;span class="gp"&gt;$ &lt;/span&gt;git&lt;span class="w"&gt; &lt;/span&gt;config&lt;span class="w"&gt; &lt;/span&gt;--global&lt;span class="w"&gt; &lt;/span&gt;gpg.program&lt;span class="w"&gt; &lt;/span&gt;gpg
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="github-integration"&gt;
&lt;h3&gt;3️⃣ GitHub Integration&lt;/h3&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Export your public GPG key:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;gpg&lt;span class="w"&gt; &lt;/span&gt;--armor&lt;span class="w"&gt; &lt;/span&gt;--export&lt;span class="w"&gt; &lt;/span&gt;&amp;lt;YOUR_KEY_ID&amp;gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;ol class="arabic simple" start="2"&gt;
&lt;li&gt;Add the key to your GitHub account settings&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class="section" id="enforcing-signed-commits"&gt;
&lt;h3&gt;4️⃣ Enforcing Signed Commits&lt;/h3&gt;
&lt;p&gt;In GitHub repository settings:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Navigate to Settings &amp;gt; Branches&lt;/li&gt;
&lt;li&gt;Add branch protection rule&lt;/li&gt;
&lt;li&gt;Enable &amp;quot;Require signed commits&amp;quot;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="troubleshooting-debugging"&gt;
&lt;h2&gt;🛠️ Troubleshooting &amp;amp; Debugging&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;strong&gt;GPG signing fails&lt;/strong&gt;: Check &lt;cite&gt;gpg-agent&lt;/cite&gt; configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GitHub doesn't show &amp;quot;Verified&amp;quot;&lt;/strong&gt;: Ensure GPG key is added to GitHub&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CI/CD issues&lt;/strong&gt;: Set up proper &lt;cite&gt;GNUPGHOME&lt;/cite&gt; environment&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Smart card/YubiKey&lt;/strong&gt;: Verify proper card reader access&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="optimizations-best-practices"&gt;
&lt;h2&gt;🔁 Optimizations &amp;amp; Best Practices&lt;/h2&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Use GPG subkeys instead of master keys&lt;/li&gt;
&lt;li&gt;Implement regular key rotation&lt;/li&gt;
&lt;li&gt;Set up separate signing keys for different contexts&lt;/li&gt;
&lt;li&gt;Use environment isolation in CI/CD pipelines&lt;/li&gt;
&lt;li&gt;Consider hardware security keys (YubiKey) for key storage&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="conclusion-takeaways"&gt;
&lt;h2&gt;✅ Conclusion &amp;amp; Takeaways&lt;/h2&gt;
&lt;p&gt;GPG-signed commits provide a robust security layer for Git workflows, ensuring:
- Verified commit authenticity
- Protected repository history
- Clear accountability
- Compliance with security best practices&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="comments-next-steps"&gt;
&lt;h2&gt;💬 Comments &amp;amp; Next Steps&lt;/h2&gt;
&lt;p&gt;How do you handle commit verification in your organization? Share your experience or ask questions below!&lt;/p&gt;
&lt;/div&gt;
</content><category term="Infrastructure Security"></category><category term="git"></category><category term="gpg"></category><category term="security"></category><category term="devops"></category><category term="version-control"></category><category term="cryptography"></category><category term="authentication"></category></entry></feed>