<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alex Hatzenbuhler</title>
    <description>The latest articles on DEV Community by Alex Hatzenbuhler (@hatz).</description>
    <link>https://dev.to/hatz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F179309%2F1b43af57-c5a9-4348-a901-ee951c6236d2.png</url>
      <title>DEV Community: Alex Hatzenbuhler</title>
      <link>https://dev.to/hatz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hatz"/>
    <language>en</language>
    <item>
      <title>Protecting yourself from committing secrets in one line</title>
      <dc:creator>Alex Hatzenbuhler</dc:creator>
      <pubDate>Fri, 08 Nov 2019 01:08:40 +0000</pubDate>
      <link>https://dev.to/hatz/protecting-yourself-from-committing-secrets-in-one-line-5afp</link>
      <guid>https://dev.to/hatz/protecting-yourself-from-committing-secrets-in-one-line-5afp</guid>
      <description>&lt;p&gt;There are many times when your project will contain some kind of data that you wouldn't want to end up in git - secrets, passwords, keys, etc. Committing secrets leads to insecure applications and the headache of rotating passwords.&lt;/p&gt;

&lt;p&gt;awslabs has a great utility to prevent you from this aptly named &lt;a href="https://github.com/awslabs/git-secrets"&gt;&lt;code&gt;git-secrets&lt;/code&gt;&lt;/a&gt;. This project works by using a &lt;a href="https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks"&gt;git hook&lt;/a&gt; that scans your repository for prohibited patterns on every commit. If something in your codebase matches a given pattern the commit is rejected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;» git commit -m "Add password"
password.txt:1:password: ThisIsAPassword

[ERROR] Matched one or more prohibited patterns
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;git-secrets&lt;/code&gt; has a lot of good information on installing it locally, but there were a few things I felt were missing. I found that my team was slow to adopt this and everyone ended up with a different configuration. Installing it manually for every repo was a chore that I had no intention of doing.&lt;/p&gt;

&lt;p&gt;To fill these holes I made &lt;a href="https://github.com/ahatzz11/git-secrets-installer"&gt;&lt;strong&gt;&lt;code&gt;git-secrets-installer&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt;, a small project that installs &lt;code&gt;git-secrets&lt;/code&gt; with some smart defaults in one line. &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/ahatzz11"&gt;
        ahatzz11
      &lt;/a&gt; / &lt;a href="https://github.com/ahatzz11/git-secrets-installer"&gt;
        git-secrets-installer
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Easy setup for git-secrets
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;To fill the holes of &lt;code&gt;git-secrets&lt;/code&gt;, the installer does a few things for you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;git-secrets&lt;/code&gt; on your machine&lt;/li&gt;
&lt;li&gt;Install hooks on all existing local git repositories&lt;/li&gt;
&lt;li&gt;Turn on automatic hook installation on future clones&lt;/li&gt;
&lt;li&gt;Create a default ruleset to match the following patterns:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(.*)password:
(.*)password=
(.*)secret:
(.*)secret=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing
&lt;/h2&gt;

&lt;p&gt;As promised in the title, installation and setup is just one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/ahatzz11/git-secrets-installer &amp;amp;&amp;amp; cd git-secrets-installer &amp;amp;&amp;amp; chmod +x install-git-secrets.sh &amp;amp;&amp;amp; ./install-git-secrets.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed you will have to restart your terminal. Verify everything worked by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git secrets --list --global
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🎉 You are now protected from committing secrets! 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Useful commands
&lt;/h2&gt;

&lt;p&gt;Add a pattern to the ruleset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git secrets --add --global $textToMatch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add a pattern to the allowed list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git secrets --add --allowed --global $allowedTextOrPattern
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  More Details
&lt;/h3&gt;

&lt;p&gt;There are a few other pieces worth noting: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The patterns that are matched above are case insensitive, so &lt;code&gt;password&lt;/code&gt; and &lt;code&gt;PassWord&lt;/code&gt; will both be caught.&lt;/li&gt;
&lt;li&gt;There are some default literals that are allowed, such as &lt;code&gt;1234567890&lt;/code&gt; and &lt;code&gt;cassandra&lt;/code&gt;. These are often used as default passwords for tests and other things and should never be used as real passwords because they are not very secure.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;***REMOVED***&lt;/code&gt; is also an allowed literal, which comes from &lt;a href="https://rtyley.github.io/bfg-repo-cleaner/"&gt;bfg&lt;/a&gt; when removing passwords.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>secrets</category>
      <category>scripts</category>
    </item>
  </channel>
</rss>
