<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by avi on Medium]]></title>
        <description><![CDATA[Stories by avi on Medium]]></description>
        <link>https://medium.com/@avi?source=rss-4e279ce8d6b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yE1l7pHuiJb-KL-W3iYygw.jpeg</url>
            <title>Stories by avi on Medium</title>
            <link>https://medium.com/@avi?source=rss-4e279ce8d6b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:21:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@avi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Access private Github repos in docker build]]></title>
            <link>https://medium.com/@avi/fidelius-e4b2d8b6b1df?source=rss-4e279ce8d6b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4b2d8b6b1df</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[secrets]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[avi]]></dc:creator>
            <pubDate>Fri, 16 Feb 2018 17:39:43 GMT</pubDate>
            <atom:updated>2018-02-17T17:46:43.374Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>A work around for leaky build secrets.</h4><p>Managing build time secrets can be a huge pain with docker. If you’ve built a docker image with private repositories, you might benefit from reading this.</p><p><a href="#a82a">Skip to the meat</a></p><p>There are multiple solutions floating around the internet for this problem. We’ll start with the obviously bad ones and work our way up.</p><h4>Copy the SSH key</h4><p><a href="https://stackoverflow.com/questions/18136389/using-ssh-keys-inside-docker-container">This</a> is a really bad idea. Any secret keys in the final Docker image. You might delete the secret after using it and think you are safe.</p><p><em>The secret used becomes the part of the build history.</em></p><h4>Pass token as a build time arg</h4><p>This is not a <a href="https://stackoverflow.com/questions/33621242/why-is-arg-in-a-dockerfile-not-recommended-for-passing-secrets">secure solution</a> either. As the official <a href="https://docs.docker.com/engine/reference/builder/#arg">docker docs</a> say:</p><blockquote><strong>Warning</strong>: It is not recommended to use build-time variables for passing secrets like github keys, user credentials etc. Build-time variable values are visible to any user of the image with the docker history command.</blockquote><p>It is not possible to <a href="https://github.com/moby/moby/issues/33343">pass</a> <a href="https://github.com/moby/moby/issues/6396">secrets</a> securely, cleanly to docker builds. <a href="https://github.com/moby/moby/issues/13490">This issue</a> filed on Github goes more into the details why existing solutions (and hacks) are bad.</p><h4>Multi stage builds</h4><p>As <a href="https://vsupalov.com/build-docker-image-clone-private-repo-ssh-key/#multi-stage-builds">this</a> article suggests, you can use multi stage builds and use the intermediate build stage to pull all dependencies and pass them to your final image.</p><p>The <a href="https://forums.docker.com/t/tag-intermediate-build-stages-multi-stage-build/34795">intermediate build stage</a> exists in the system long after you have left.</p><p>This solution does not work well and is riddled with traps if your private dependency has some setup work. You could easily miss copying a python/node package’s dependency.</p><p><em>Subtle differences in the build environment and running environment can result in failed builds and hours of frustration.</em></p><h4>State of things at <a href="https://verloop.io/">Verloop</a></h4><p>We use <a href="https://cloud.google.com/container-builder/">Container Builder</a> to build docker images. GCP does not provide any <a href="https://github.com/GoogleCloudPlatform/cloud-builders/issues/44">solution for this</a> problem.</p><p>We could build the Go binary and move it to the docker image. But that just solves it for one language on the happy path.</p><p><em>This solution would not work for our python and node servers.</em></p><p><em>pip install</em> and <em>npm install</em> need access to private repos from within the container.</p><p>We needed something that would work always, with all current and future languages we dive into.</p><h3>Invert the problem</h3><p>When really backed against the wall, one exercise we often try is to invert the problem on it’s head.</p><blockquote>What if leaking the secret was not a big deal?</blockquote><p>As soon as we asked this question, an old idea from our documentation server came to mind.</p><p>Back when we needed to centralise documentation of all our services, we needed to pull code from multiple Github repos in every build.</p><p>Maintaining these many deploy keys wasn’t ideal. A little known feature of github integrations had come to our rescue.</p><p><em>Short lived access tokens!</em></p><h3>Fidelius</h3><p>In under 100 lines of code, <a href="https://github.com/verloop/fidelius/releases">Fidelius</a> completely does away with the problem of having leaked access tokens. It produces a token that becomes safe to leak after an hour!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ahbJCl-z8ZvHx-Prf9u2Ng.jpeg" /><figcaption>*After they expire!</figcaption></figure><blockquote>If the tokens mean nothing, you can leak all of them!</blockquote><p>Fidelius shares a secret with you that you can’t share with others, because sharing it is useless.</p><h3>How Fidelius works?</h3><p>Fidelius uses a companion Github Integration. It fetches a temporary Github access token. This token expires after <strong>one hour</strong>.</p><p>We use that token in the Cloud Builder or within the Docker build.</p><p>Fidelius can also generate a valid .gitconfig file which you can use or update an existing .gitconfig.</p><p>The build history and the final docker image will have an expired token.</p><p>Since the process gives the app read access to your repository, you should create your own app.</p><h3>DIY steps</h3><h4>Create Github App</h4><p>Create a <a href="https://github.com/settings/apps/new">new Github App</a> with permission Repository Contentsset to Read Only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OAqiUF-9JtOZkWL-1QvVYA.png" /><figcaption>Repository contents</figcaption></figure><p>You can check an example app at <a href="https://github.com/apps/fidelius-charm">Fidelius Charm</a></p><p>On page https://github.com/settings/apps/&lt;your-app&gt;, scroll down to the <em>About</em> section.</p><p>Note the Github app ID, this will be useful later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DCtYHUlJFVu-BNpPhQWHKQ.png" /><figcaption>9045 in the sample app</figcaption></figure><h4>Generate Private key</h4><p>Scroll further below and click <em>Generate private key</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hacM3xFscs5w6gUHDtj2OQ.png" /><figcaption>Keep the key safe, it is your life</figcaption></figure><h4>Install the app</h4><p>Scroll back up and click installations. <br>You should now be on the page https://github.com/settings/apps/&lt;your-app&gt;/installations</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WbBKfPlOfD3hZ8atPYc2fw.png" /><figcaption>Click install on the org</figcaption></figure><p>On the next screen, select the repositories you’ll need in your build and click install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVp8sqAxCe6i7zwQZue3Xg.png" /><figcaption>very sekrit</figcaption></figure><h3>Copy the installation ID</h3><p>On the next screen, you will see your installation id as part of the URL</p><p>https://github.com/organizations/&lt;org&gt;/settings/installations/88254</p><p>Here <strong>88254</strong> is the installation id.</p><p>You can also go back to your app page and check it in the webhooks github tried to deliver under “Advanced”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZNfO9jwUQUU48YnByvEhPw.png" /><figcaption>88254</figcaption></figure><h3>Using Fidelius</h3><p>Make Fidelius part of your build step, either generate the access token or place the .gitconfig at an appropriate place.</p><p>If you want to pass the token to docker build, you can do something like this:</p><pre>$ fidelius --gh-integration-id=9045 --gh-installation-id=88254 --gh-private-key=private_key.pem</pre><pre>v1.20dfff65bb3cff4cbe2330ef10f41d43b441a772</pre><p><em>Yes that’s a real token that gives access to all of Verloop’s secrets!</em></p><p>If you pass a path a --git-config-out argument, it will write appropriate git config to that file:</p><pre>$ fidelius --gh-integration-id=9045 --gh-installation-id=88254 --gh-private-key=private_key.pem --git-config-out=/root/.gitconfig</pre><blockquote><strong>Disclaimer</strong></blockquote><blockquote>If you are going to release the image to the public, use a trigger that is set to fire at least an hour after the image is built.</blockquote><h4>But my code is not on Github!</h4><p>If your code is not on Github, you can still use this design with a reverse proxy server to give out timed tokens.</p><blockquote>The idea of using short lived tokens to make password leaks irrelevant is liberating!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4b2d8b6b1df" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>