<?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 Joe Blue on Medium]]></title>
        <description><![CDATA[Stories by Joe Blue on Medium]]></description>
        <link>https://medium.com/@joe-blue?source=rss-91eedf33fc0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Qeez2h5fvw4j0kuGBdTreg.jpeg</url>
            <title>Stories by Joe Blue on Medium</title>
            <link>https://medium.com/@joe-blue?source=rss-91eedf33fc0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:45:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joe-blue/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[How to Use Git/GitHub without asking for authentication always: Passwordless Usage of Private Git…]]></title>
            <link>https://medium.com/clarusway/how-to-use-git-github-without-asking-for-authentication-always-passwordless-usage-of-private-git-8c32489bc2e9?source=rss-91eedf33fc0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c32489bc2e9</guid>
            <category><![CDATA[git-authentication]]></category>
            <category><![CDATA[git-credentials]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[passwordless]]></category>
            <category><![CDATA[github-authentication]]></category>
            <dc:creator><![CDATA[Joe Blue]]></dc:creator>
            <pubDate>Wed, 30 Dec 2020 05:02:42 GMT</pubDate>
            <atom:updated>2020-12-30T21:26:21.817Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Use Git/GitHub without asking for authentication always: Passwordless Usage of Private Git Repositories</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*huh_bb-D9fgc5SBgwJu7lw.jpeg" /><figcaption>Passwordless Authentication for Git-Based Repositories</figcaption></figure><p>The authentication to access the source code repositories like GitHub, GitLab, Bitbucket, etc., is crucial. These repositories are all git-based. However, when working with these repositories&#39; private instances, it is very annoying and boring to enter the credentials at each code interaction attempt.</p><p>There are some workarounds or ways to get rid of entering the credentials, namely username-password, each time to interact with the repositories. Let’s take a look at these options and briefly discuss them.</p><p><strong>Firstly</strong>, when cloning the repository, you can enter the username and the password to the clone link. To clone a repository, go to the repository, click the Code, and then copy the link by clicking the copy to clipboard icon as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*eO9a9lslGKBePNj8_CQG-w.jpeg" /></figure><p>The copied link as follows:</p><pre>https://github.com/JBCodeWorld/test.git</pre><p>To clone the repo without the username and the password authentication, enter those values to the link as follows:</p><pre>git clone https://<strong>username:password@</strong>github.com/JBCodeWorld/test.git</pre><p>If you already cloned or checked out the repo, go to the path-to-repo/.git/config file and update URL accordingly with the username and the password .</p><pre>[core]<br> repositoryformatversion = 0<br> filemode = true<br> bare = false<br> logallrefupdates = true<br>[remote &quot;origin&quot;]<br> url = https://<strong>username:password@</strong>github.com/JBCodeWorld/test.git<br> fetch = +refs/heads/*:refs/remotes/origin/*<br>[branch &quot;master&quot;]<br> remote = origin<br> merge = refs/heads/master</pre><p>As you see, the credentials information exposed in command history and also not encrypted in the file, and only protected with routine user file permissions.</p><p><strong>Secondly</strong>, you can use the credential.helper to store or cache the credentials. The store option saves the credentials in a file named as ~/.git-credentials for each URL context. To activate this option,</p><pre>$ git config credential.helper store    <br>OR<br>$ git config --global credential.helper store</pre><p>After that, on the first interaction with the repository, the credentials are retrieved from the user and stored as follows:</p><pre>ubuntu@ubuntu:~/test$ git pull<br>Username for &#39;https://github.com&#39;: jbcodeworld<br>Password for &#39;https://jbcodeworld@github.com&#39;: <br>Already up to date.<br>ubuntu@ubuntu:~/test$</pre><p>When the ~/.git-credentials checked, the credentials are stored as unencrypted. The file is protected only by standard user file permissions.</p><pre>ubuntu@ubuntu:~$ cat ~/.git-credentials <br>https://&lt;user-name&gt;:&lt;password&gt;@github.com</pre><p>You can also store the credentials information in the memory for a certain amount of time. To activate this;</p><pre>$ git config credential.helper cache<br>OR<br>$ git config --global credential.helper cache</pre><p>Again, in the first interaction with the repository, the credentials are retrieved from the user and stored in the cache as follows:</p><pre>ubuntu@ubuntu:~/test$ git config --global credential.helper cache<br>ubuntu@ubuntu:~/test$ git pull<br>Username for &#39;https://github.com&#39;: jbcodeworld<br>Password for &#39;https://jbcodeworld@github.com&#39;: <br>Already up to date.<br>ubuntu@ubuntu:~/test$</pre><p>The time unit for the cache is in seconds and default is 15 minutes. When this time elapsed, git will force you to enter your username and password again. You can overwrite the default as follows, for example, for one day (1 day = 24 hours × 60 minutes × 60 seconds = 86400 seconds);</p><pre>$ git config --global credential.helper &#39;cache --timeout=86400&#39;<br>OR<br>$ git config --global credential.helper &#39;cache --timeout=86400&#39;</pre><p>If you would like the daemon to <strong>exit</strong> early, <strong>revoke</strong> all cached credentials<strong> </strong>before their timeout, you can issue an exit action:</p><pre>git credential-cache exit</pre><p><strong>Thirdly</strong>, a token can be created at the repository and be used for authentication. To create the token, you can follow these steps;</p><p>You can also follow the same step from the git <a href="https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token">documentation</a>.</p><p>Step 1: In the upper-right corner of any page, click your profile photo, then click Settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*uU6sl2wwh26WoUqDUZfGuw.jpeg" /></figure><p>Step 2: In the left sidebar, click Developer Settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*O3cOAjtbMpm43Iv_o0aKKA.jpeg" /></figure><p>Step 3: In the left sidebar, click Personel access tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*_b7SGwF4BvrLM6IAiyYBAw.jpeg" /></figure><p>Step 4: In the right-upper corner, clickGenerate new token .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*myHkTmH28fXickppIzteqw.jpeg" /></figure><p>Step 5: If prompted, confirm your GitHub password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*OQhk6BoDEQQQ1tDMxQAOCA.jpeg" /></figure><p>Step 6: Give your token a descriptive name. Select the scopes, or permissions; you’d like to grant this token. To use your token to access repositories from the command line, select repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*klttuD6UlC_s6vvQe_JV9A.jpeg" /></figure><p>Step 7: Finally, click the Generate token button to generate the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*WBLTlnbhgGtwfXMtbmsHxg.jpeg" /></figure><p>Step 8: Confirm the checkmark and then click the copy to clipboard icon to copy the token to your clipboard. For security reasons, after you navigate off the page, you will not be able to see the token again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*8WhZ-yZn2PNbR8N9xyyV6Q.jpeg" /></figure><p>These are the steps to create the token successfully. After this, the token can be used at the git URL as in the first option. You can use the token when cloning like this;</p><pre>git clone https://<strong>c904a061a164cb45a9abf5dbc6c8b8f4c16d6dd7@</strong>github.com/JBCodeWorld/test.git</pre><p>If you have already cloned the repository, then you can update the URL in the .git/config file in the repository by placing the token between https:// and <strong>@</strong>github.com.</p><pre>ubuntu@ubuntu:~/test$ cat .git/config<br>[core]<br> repositoryformatversion = 0<br> filemode = true<br> bare = false<br> logallrefupdates = true<br>[remote &quot;origin&quot;]<br> url = https://<strong>c904a061a164cb45a9abf5dbc6c8b8f4c16d6dd7@</strong>github.com/JBCodeWorld/test.git<br>.....</pre><p>After entering the token to the URL in the .git/config file, git will not ask for authentication anymore.</p><p><strong>Fourthly</strong>, a new SSH key can be added to your GitHub account and be used for authentication. To create the SSH key, you can follow these steps;</p><p>You can also follow the same step from the git <a href="https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account">documentation</a>.</p><p>Let’s create the SSH Keys first. To to do so, go to your terminal and type;</p><pre>ssh-keygen -t rsa</pre><p>When the command is entered, press enter key for all options. You can also enter a password, but we will not activate the password in this study. You will see a screen like this;</p><pre>ubuntu@ubuntu:~$ ssh-keygen -t rsa<br>Generating public/private rsa key pair.<br>Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): <br>Enter passphrase (empty for no passphrase): <br>Enter same passphrase again: <br>Your identification has been saved in /home/ubuntu/.ssh/id_rsa.<br>Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.<br>The key fingerprint is:<br>SHA256:TAS8DyOa8vKITV0R4HP1PHM7aQ6wLMqZmgq7lJYfDgQ ubuntu@ubuntu<br>The key&#39;s randomart image is:<br>+---[RSA 2048]----+<br>|    .oo.o        |<br>|   .  .+ o       |<br>|E   o o.o = .    |<br>|.   .o+= o + o   |<br>| . o .o+S . =    |<br>|o =o = ..  + .   |<br>|.O..*       .    |<br>|*==o.            |<br>|*==o             |<br>+----[SHA256]-----+<br>ubuntu@ubuntu:~$</pre><p>ssh-keygen will create two keys in the ~/.ssh folder. These are <em>private </em>id_rsa , and <em>public </em>id_rsa.pub keys.</p><pre>ubuntu@ubuntu:~$ ls ~/.ssh<br>config  <strong>id_rsa</strong>  <strong>id_rsa.pub</strong>  known_hosts<br>ubuntu@ubuntu:~$</pre><p>The contents of public key, id_rsa.pub, must be copied to the GitHub.</p><pre>ubuntu@ubuntu:~$ cat ~/.ssh/id_rsa.pub<br>ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8QqytxbuCxgW7TWO+FPXlxycx+F9Q9IDtaS7Jr0IZeF00Jhn1nVLsKtBNJe5ZxSbvYtflWdLcaHn0tRV8GNbZG2PSJ6iPGU051D2altyFQ+8ySKW11AJn72kdHyLt1Kjbe0byk5qp1vpzzay/mtcEA/CWAoecT+1p2D592vRW8Zj5ASAf1HcfVBPyNLi2S2kYFsk/4i6pHt3VdrQUMdLCs1U6aS2xpEzLf/ZiR9zNzdYkS062UJkMtyYFTOr5GyPuSBb/o47mkqS5zz9lruhgIQbMXr3Wa4TMRQHtM5lzMFRjNcUgUGY+YjXvHiJsi1uhYdA8PJcgEVWYsQGKnK69 ubuntu@ubuntu</pre><p>After the creation of ssh keys, the steps at GitHub can be done as follows;</p><p>Step 1: In the upper-right corner of any page, click your profile photo, then click Settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/282/1*uU6sl2wwh26WoUqDUZfGuw.jpeg" /></figure><p>Step 2: In the user settings sidebar, click SSH and GPG keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/243/1*kIE8zkQKWSD-TK-4hZVeuw.jpeg" /></figure><p>Step 3: Click New SSH key or Add SSH key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*I8iE6o17n6XOb4rQLUUhXA.jpeg" /></figure><p>Step 4: In the Title field, add a descriptive label for the new key. Paste the ~/.ssh/id_rsa.pub key content to the Key field. Click Add SSH key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*ThtvFItRUUDrsd--_8Rz0g.jpeg" /></figure><p>Step 5: If prompted, confirm your GitHub password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*OQhk6BoDEQQQ1tDMxQAOCA.jpeg" /></figure><p>Step 6: Verify that the key is added as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*BRt-IX1hNBe8y7hFxZsh2w.jpeg" /></figure><p>After adding the public key to GitHub, git will not ask for authentication anymore. But for this, we have to do some settings in the configuration.</p><p><strong><em>Firstly</em></strong>, let’s authenticate the connection with the command ssh -T git@github.com. You may see a warning like this:</p><pre>ubuntu@ubuntu:~$ ssh -T git@github.com<br>The authenticity of host &#39;github.com (140.82.121.4)&#39; can&#39;t be established.<br>RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.<br>Are you sure you want to continue connecting (yes/no)? yes<br>Warning: Permanently added &#39;github.com,140.82.121.4&#39; (RSA) to the list of known hosts.<br>Hi JBCodeWorld! You&#39;ve successfully authenticated, but GitHub does not provide shell access.</pre><p><strong><em>Secondly</em></strong>, to use GitHub with shell access, we must use shell syntax as follows;</p><pre>git clone git@github.com:&lt;url-repo&gt;.git</pre><p>In our case;</p><pre>git clone git@github.com:JBCodeWorld/test.git<br>Cloning into &#39;test&#39;...<br>remote: Enumerating objects: 15, done.<br>remote: Counting objects: 100% (15/15), done.<br>remote: Compressing objects: 100% (9/9), done.<br>remote: Total 15 (delta 0), reused 6 (delta 0), pack-reused 0<br>Receiving objects: 100% (15/15), done.</pre><p>If you have already cloned and worked on a repository, then you must redefine the ssh URL for remote origin in the repository:</p><pre>git remote set-url origin git@github.com:&lt;url-repo&gt;.git</pre><p>In our case;</p><pre>ubuntu@ubuntu:~/test$ git remote set-url origin git@github.com:JBCodeWorld/test.git<br>ubuntu@ubuntu:~/test$ git push<br>Counting objects: 3, done.<br>Delta compression using up to 2 threads.<br>Compressing objects: 100% (2/2), done.<br>Writing objects: 100% (3/3), 294 bytes | 294.00 KiB/s, done.<br>Total 3 (delta 0), reused 0 (delta 0)<br>To github.com:JBCodeWorld/test.git<br>   9b7e69d..2391466  master -&gt; master<br>ubuntu@ubuntu:~/test$</pre><p><strong><em>Finally</em></strong>, you can enjoy passwordless git operations. You can choose the one that suits your needs. However, I would highly recommend using more secure options that do not disclose your credentials or make it hard to be stolen.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c32489bc2e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clarusway/how-to-use-git-github-without-asking-for-authentication-always-passwordless-usage-of-private-git-8c32489bc2e9">How to Use Git/GitHub without asking for authentication always: Passwordless Usage of Private Git…</a> was originally published in <a href="https://medium.com/clarusway">Clarusway</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Private Container Registry: Repository and Web Service]]></title>
            <link>https://medium.com/clarusway/creating-a-private-container-registry-repository-and-web-service-8c753b54f55c?source=rss-91eedf33fc0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c753b54f55c</guid>
            <category><![CDATA[container-registry]]></category>
            <category><![CDATA[private-docker-registry]]></category>
            <category><![CDATA[private-registry]]></category>
            <category><![CDATA[dockerhub]]></category>
            <dc:creator><![CDATA[Joe Blue]]></dc:creator>
            <pubDate>Wed, 30 Dec 2020 05:02:25 GMT</pubDate>
            <atom:updated>2020-12-30T21:53:34.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*OvIY-LZD4Y-edFTI8J5ZrQ.jpeg" /><figcaption>Private Container Registry and Clients</figcaption></figure><h3>What is a Container Registry?</h3><p>The containers are created from the images. These images need to be stored and used from a scalable and secure repository. Like the other repositories, the container registry also must provide a fast way to pull and push images with correct policies and credentials.</p><p>The most popular container registry hosting the images is Docker Hub. The Docker and Kubernetes are usually using the images via this service. There are many public images freely available, but you don’t have full control over the registry, and day by day, you will meet with some restrictions. Moreover, when it comes to using private images, security is a concern, and it may also be expensive.</p><p>Therefore, hosting your private registry can be useful in many situations. Private registries offer many different storage and authentication options and can be customized according to your personal needs.</p><h3><strong>Why Use a Private Container Registry?</strong></h3><p>Here are some basic reasons for using your personal private registry instead of a public registry like DockerHub.</p><ul><li>You have full control over the storage location of the private registry.</li><li>You can set up policies as you wish</li><li>Wide options to secure and share your images</li><li>Special configuration options for logging, authentication, load balancing, etc.</li></ul><p>There are some images like DockerHub’s <a href="https://hub.docker.com/_/registry">registry</a> and CNCF’s <a href="https://goharbor.io/">Harbor </a>to configure and use as a private registry. In this study, we will go on with DockerHub’s registry image.</p><h3><strong>AWS ec2-instance Security Settings for Container Registry</strong></h3><p>We will deploy the registry to an AWS ec2-instance for the showcase. It will host the image repository. That’s why it is important to emphasize the security group permissions.</p><pre>HTTP   TCP 80   IP: 0.0.0.0/0 -<br>HTTP   TCP 443, IP: 0.0.0.0/0 -<br>SSH    TCP 22   IP: 0.0.0.0/0 -<br>Custom TCP 5000 IP: 0.0.0.0/0 -<br>Custom TCP 5000 IP: ::/0 -</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*Fd9GnYUDMoUHvbf5J-W3Qw.jpeg" /><figcaption>Security Settings for AWS ec2-instance</figcaption></figure><h3>Create a Simple Registry</h3><p>Let’s create a folder to start our journey at the home directory;</p><pre>mkdir -p docker-hub/data<br>chmod 777 -R docker-hub/data</pre><p>The data folder will store the registry data.</p><p>We will use docker-compose structure to create and manage the registry.</p><p>To create a simple registry, we can use a basic registry image from Docker Hub. The docker-compose.yaml file content is as follows:</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  docker-registry:<br>    image: registry:2<br>    restart : always<br>    container_name: docker-registry<br>    ports:<br>    - &quot;5000:5000&quot;<br>    environment:<br>      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data<br>    volumes:<br>      - ./data:/data</pre><p>The directory structure is as follows:</p><pre>docker-hub<br>├── data<br>└── docker-compose.yaml</pre><p>Now, run the docker-compose under docker-hub directory.</p><pre>docker-compose up -d</pre><h3><strong>Pushing an Image to the Registry</strong></h3><p>The registry is ready to store the images. To do that, we need to create an image that is labeled correctly. The correct convention for labeling is as follows:</p><pre>&lt;ip&gt;:&lt;port-number&gt;/&lt;image-name&gt;:&lt;tag&gt;<br>&lt;dns-name&gt;:&lt;port-number&gt;/&lt;image-name&gt;:&lt;tag&gt;</pre><p>For example, we can pull an image from the docker hub, or create an image from scratch and tag it for our private registry.</p><pre>docker pull alpine<br>docker tag alpine localhost:5000/my-alpine</pre><p>To push the image, we need to login into our private registry if it requires the credentials.</p><pre>docker login localhost:5000</pre><p>Now we can push the image using the push command:</p><pre>docker push localhost:5000/my-alpine</pre><h3><strong>Pulling an Image from </strong>the Registry</h3><p>The pulling of images from the private registry is very straightforward. Again, to pull the image, we need to login into our private registry if it requires credentials.</p><pre>docker login localhost:5000</pre><p>Now we can pull the image using the pull command:</p><pre>docker pull localhost:5000/my-alpine</pre><h3>Adding Web Service to the Private Registry</h3><p>It is a good idea to monitor or see the images via a web browser, as in Docker Hub. To realize this, we can use konradkleine/docker-registry-frontend image. There is enough configuration information on the related <a href="https://hub.docker.com/r/konradkleine/docker-registry-frontend">documentation</a> page. The docker-compose.yaml file is updated to capture this feature.</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  docker-registry:<br>    image: registry:2<br>    restart : always<br>    container_name: docker-registry<br>    ports:<br>    - &quot;5000:5000&quot;<br>    environment:<br>      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data<br>    volumes:<br>      - ./data:/data</pre><pre>  docker-registry-ui:<br>    image: konradkleine/docker-registry-frontend:v2<br>    restart : always<br>    container_name: docker-registry-ui<br>    ports:<br>    - 80:80<br>    environment:<br>      ENV_DOCKER_REGISTRY_HOST: ip-172-31-82-125.ec2.internal<br>      ENV_DOCKER_REGISTRY_PORT: 5000</pre><p>For the ENV_DOCKER_REGISTRY_HOST, we could use a service name, but as we intend to use this registry as a service, we need a secure SSL connection and a reachable ip or dns name. That is why we used ip-172–31–82–125.ec2.internal, which is reachable from the AWS network internally. A DNS name can also be used instead of this static IP. You can also set the storage location with the help of an environment variable, REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY.</p><p>We have added the my-nginx and httpd images to the registry. The web browser screenshots are presented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*xfKc4JiNUwDYzok14jDVnw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*oWUEBUOpNarYavUj-fcGDw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*EiE1L_BMbcLaWvRbJqo85A.jpeg" /><figcaption>Web interface screenshots of private container registry</figcaption></figure><h3><strong>Adding a Certificate </strong>to the Registry</h3><p>For a secure connection and remote client access, you need certificates. We will show to configure a secure connection with SSL certificates. If you already acquired a .cert and .key from your Certification Authority, then you just need the copy them to under certs directory. Go to docker-hub and then,</p><pre>mkdir certs<br>chmod 777 -R certs</pre><p>Now copy the .crt and .key file to certs directory.</p><p>If you don’t have them, here is a way of creating a self-signed Certification Authorization Key. For this purpose, we need the openssl package. If openssl not present, install it.</p><pre>yum -y install openssl</pre><p>Let’s create certification keys for docker-registry. Command prompt must be at the same level as certs folder. Run the command as follows;</p><pre>openssl req \<br>  -newkey rsa:4096 -nodes -sha256 -keyout ./certs/domain.key \<br>  -x509 -days 3650 -out ./certs/domain.crt</pre><p>When creating keys, Common Name (eg, your name or your server’s hostname) part is critical. It must be the hostname/ip of the docker-registry host. When AWS considered, private ip/hostname of docker-registry host can be used. The private IP of an ec2 instance is like ip-172–31–82–125.ec2.internal. You can go with defaults (just press enter) or enter the appropriate values for the rest.</p><pre>[ec2-user@ip-172-31-82-125 docker-hub]$ openssl req \<br>&gt;   -newkey rsa:4096 -nodes -sha256 -keyout ./certs/domain.key \<br>&gt;   -x509 -days 3650 -out ./certs/domain.crt<br>Generating a 4096 bit RSA private key<br>...............................................................................++<br>.......................................................................................................................................................++<br>writing new private key to &#39;./certs/domain.key&#39;<br>-----<br>You are about to be asked to enter information that will be incorporated<br>into your certificate request.<br>What you are about to enter is what is called a Distinguished Name or a DN.<br>There are quite a few fields but you can leave some blank<br>For some fields there will be a default value,<br>If you enter &#39;.&#39;, the field will be left blank.<br>-----<br>Country Name (2 letter code) [XX]:<br>State or Province Name (full name) []:<br>Locality Name (eg, city) [Default City]:<br>Organization Name (eg, company) [Default Company Ltd]:<br>Organizational Unit Name (eg, section) []:<br>Common Name (eg, your name or your server&#39;s hostname) []:<strong>ip-172-31-82-125.ec2.internal</strong><br>Email Address []:</pre><h3>Adding a Certificate to the Registry <strong>with the Help of </strong><strong>openssl.conf File</strong></h3><p>You can also use a file to set the openssl configuration settings as an alternative. For this, prepare an openssl.conf file for your needs. We will use the following settings for the parameters:</p><pre>[ req ]<br>distinguished_name = req_distinguished_name<br>x509_extensions     = req_ext<br>default_md         = sha256<br>prompt             = no<br>encrypt_key        = no</pre><pre>[ req_distinguished_name ]<br>countryName            = &quot;US&quot;<br>localityName           = &quot;Bristow&quot;<br>organizationName       = &quot;Clarusway&quot;<br>organizationalUnitName = &quot;Clarusway&quot;<br>commonName             = &quot;ip-172-31-82-125.ec2.internal&quot;<br>emailAddress           = &quot;<a href="/service/mailto:test@example.com">test@example.com</a>&quot;</pre><pre>[ req_ext ]<br>subjectAltName = <a href="http://twitter.com/alt_names">@alt_names</a></pre><pre>[alt_names]<br>DNS = &quot;ip-172-31-82-125.ec2.internal&quot;</pre><p>Run the command as follows;</p><pre>openssl req \<br> -x509 -newkey rsa:4096 -days 3650 -config openssl.conf \<br> -keyout certs/domain.key -out certs/domain.crt</pre><p>The command output should look like this.</p><pre>openssl req \<br>&gt;  -x509 -newkey rsa:4096 -days 3650 -config openssl.conf \<br>&gt;  -keyout certs/domain.key -out certs/domain.crt<br>Generating a 4096 bit RSA private key<br>...........................................++<br>...............++<br>writing new private key to &#39;certs/domain.key&#39;<br>-----</pre><p>The folder structure should be like this.</p><pre>docker-hub<br>├── certs<br>│   ├── domain.crt<br>│   └── domain.key<br>├── data<br>└── docker-compose.yaml</pre><p>Now, it is time to update the docker-compose.yaml file to include the certificates.</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  docker-registry:<br>    image: registry:2<br>    restart : always<br>    container_name: docker-registry<br>    ports:<br>    - &quot;5000:5000&quot;<br>    environment:<br>      REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt<br>      REGISTRY_HTTP_TLS_KEY: /certs/domain.key<br>      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data<br>    volumes:<br>      - ./certs:/certs<br>      - ./data:/data</pre><pre>  docker-registry-ui:<br>    image: konradkleine/docker-registry-frontend:v2<br>    container_name: docker-registry-ui<br>    ports:<br>    - 443:443<br>    environment:<br>      ENV_DOCKER_REGISTRY_HOST: ip-172-31-82-125.ec2.internal<br>      ENV_DOCKER_REGISTRY_PORT: 5000<br>      ENV_USE_SSL: &quot;yes&quot;<br>      ENV_DOCKER_REGISTRY_USE_SSL: 1<br>    volumes:<br>      - ./certs/domain.crt:/etc/apache2/server.crt:ro <br>      - ./certs/domain.key:/etc/apache2/server.key:ro</pre><p>This time, for the web browser link, we have to use https connection. In our case, <a href="https://ec2-35-172-118-174.compute-1.amazonaws.com/">https://ec2-35-172-118-174.compute-1.amazonaws.com/</a> will be used. As we get a certificate for a private IP address (ip-172–31–82–125.ec2.internal), we can ignore the security warning and go on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*FIhNyfEi0BlPbaoE4ayecg.jpeg" /><figcaption>Web Interface after SSL Activation</figcaption></figure><h3>Client Machine Settings to Use the Registry</h3><p>The domain.crt must be copied to the clients. The path should be /etc/docker/certs.d/&lt;private-docker-hub-ip or dns-name&gt;:&lt;port-no&gt;/. In our case, copy the file to the clients and then at clients move the file to the correct path with root privileges (with sudo or root user):</p><pre>[root@docker-client1 ~]# mkdir -p /etc/docker/certs.d/ip-172-31-82-125.ec2.internal:5000/</pre><pre>[root@docker-client1 ~]# cp -rf ./domain.crt /etc/docker/certs.d/ip-172-31-82-125.ec2.internal:5000/</pre><p>The domain.crt can also be copied to /root/domain.crt /etc/docker/certs.d/ip-172–31–82–125.ec2.internal:5000/ directory at registry (private-docker-hub) node.</p><p>After this setting, we can pull and push images at the clients with a secure connection.</p><h3>Creating the Authentification File</h3><p>In the registry, for authentication, we will use an username and a password. To create the password, we will need htpasswd package to be installed.</p><p>If this package is not installed, for ubuntu-based Linux OS;</p><pre>sudo apt install apache2-utils -y</pre><p>For fedora-centos-based Linux OS;</p><pre>sudo yum install httpd-tools -y</pre><p>After verification of the presence of htpassw package, we can create a folder to go on our journey. Let’s create the folders to hold the password file;</p><pre>mkdir -p docker-hub/auth</pre><p>This is the folder to store our password file. Next, the password for a selected user can be created. Let’s create a username and password.</p><pre>cd docker-hub/auth<br>htpasswd -Bc registry.password clarusway</pre><p>The last parameter is the name of the user; in this case clarusway. After executing the command, you will be prompted to enter your password. In this study, clarusway is selected for both username and password.</p><p>Final docker-compose files with Certification Authorization Key and username and password authentication;</p><pre>version: &#39;3&#39;</pre><pre>services:<br>  docker-registry:<br>    image: registry:2<br>    restart : always<br>    container_name: docker-registry<br>    ports:<br>    - &quot;5000:5000&quot;<br>    environment:<br>      REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt<br>      REGISTRY_HTTP_TLS_KEY: /certs/domain.key<br>      REGISTRY_AUTH: htpasswd<br>      REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm<br>      REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password<br>      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data<br>    volumes:<br>      - ./certs:/certs<br>      - ./auth:/auth<br>      - ./data:/data</pre><pre>  docker-registry-ui:<br>    image: konradkleine/docker-registry-frontend:v2<br>    restart : always<br>    container_name: docker-registry-ui<br>    ports:<br>    - 443:443<br>    environment:<br>      ENV_DOCKER_REGISTRY_HOST: ip-172-31-82-125.ec2.internal<br>      ENV_DOCKER_REGISTRY_PORT: 5000<br>      ENV_USE_SSL: &quot;yes&quot;<br>      ENV_DOCKER_REGISTRY_USE_SSL: 1<br>    volumes:<br>      - ./certs/domain.crt:/etc/apache2/server.crt:ro <br>      - ./certs/domain.key:/etc/apache2/server.key:ro</pre><p>The folder structure should be like this;</p><pre>docker-hub<br>├── auth<br>│   └── registry.password<br>├── certs<br>│   ├── domain.crt<br>│   └── domain.key<br>├── data<br>└── docker-compose.yaml</pre><p>Now, run the docker-compose under docker-hub directory. Let’s check the web interface. When the default page loaded, we see the Welcome Screen. After hitting the Browse repositories button, a login attempt is observed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*qNtaCZdgwKP_jRfTv1F3jQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*Y7AIKOhDWD3hRUeUUG5o5w.jpeg" /><figcaption>Web Interface after Authentication Activation</figcaption></figure><h3><strong>Sample Usage At Clients</strong></h3><p>The client should log in and use the reachable IP(DNS)&amp;port number of this registry to pull and push the images.</p><p>After authentication setting activation, we have to log in to ip-172–31–82–125.ec2.internal:5000 to pull and push the images at the clients.</p><pre>docker login ip-172-31-82-125.ec2.internal:5000</pre><pre>docker pull ip-172-31-82-125.ec2.internal:5000/my-alpine</pre><pre>docker tag &lt;image&gt;:tag ip-172-31-82-125.ec2.internal:5000/&lt;new-name&gt;:tag</pre><pre>docker push ip-172-31-82-125.ec2.internal:5000/&lt;new-name&gt;:tag</pre><p>A sample image pull showcase is as follows:</p><pre>[ec2-user@ip-172-31-45-163 ~]$ docker login ip-172-31-82-125.ec2.internal:5000<br>Username: clarusway<br>Password: <br>WARNING! Your password will be stored unencrypted in /home/ec2-user/.docker/config.json.<br>Configure a credential helper to remove this warning. See<br><a href="https://docs.docker.com/engine/reference/commandline/login/#credentials-store">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</a></pre><pre>Login Succeeded<br>[ec2-user@ip-172-31-45-163 ~]$ docker pull ip-172-31-82-125.ec2.internal:5000/my-alpine:latest<br>latest: Pulling from my-alpine<br>Digest: sha256:074d3636ebda6dd446d0d00304c4454f468237fdacf08fb0eeac90bdbfa1bac7<br>Status: Downloaded newer image for ip-172-31-82-125.ec2.internal:5000/my-alpine:latest<br>ip-172-31-82-125.ec2.internal:5000/my-alpine:latest<br>[ec2-user@ip-172-31-45-163 ~]$</pre><p>I hope this study addresses and solves the issues of hosting and using a private container registry. You can freely and securely use the containers in popular tools like <a href="https://hub.docker.com/">Docker</a>, <a href="https://containerd.io/">containerd</a>, <a href="http://mesos.apache.org/documentation/latest/mesos-containerizer/">Mesos Containerizer</a>, <a href="https://coreos.com/rkt/docs/latest/">CoreOS rkt</a>, and <a href="https://linuxcontainers.org/">LXC Linux Containers</a>. Moreover, I have explained how to use private registries with Kubernetes in the “<a href="https://medium.com/clarusway/how-to-use-images-from-a-private-container-registry-for-kubernetes-aws-ecr-hosted-private-13a759e2c4ea?source=friends_link&amp;sk=8440eddb8f782c413987c9a4b85eaff9">How to use images from a private container registry for Kubernetes: AWS ECR, Hosted Private Container Registry</a>”.</p><h3>References</h3><p><a href="https://gabrieltanner.org/blog/docker-registry">https://gabrieltanner.org/blog/docker-registry</a></p><p><a href="https://www.learnitguide.net/2018/07/create-your-own-private-docker-registry.html">https://www.learnitguide.net/2018/07/create-your-own-private-docker-registry.html</a></p><p><a href="https://www.youtube.com/watch?v=SEpR35HZ_hQ">https://www.youtube.com/watch?v=SEpR35HZ_hQ</a></p><p><a href="https://hub.docker.com/r/konradkleine/docker-registry-frontend">https://hub.docker.com/r/konradkleine/docker-registry-frontend</a></p><p><a href="https://github.com/justmeandopensource/docker/tree/master/docker-compose-files/docker-registry">https://github.com/justmeandopensource/docker/tree/master/docker-compose-files/docker-registry</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c753b54f55c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clarusway/creating-a-private-container-registry-repository-and-web-service-8c753b54f55c">Creating a Private Container Registry: Repository and Web Service</a> was originally published in <a href="https://medium.com/clarusway">Clarusway</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use images from a private container registry for Kubernetes: AWS ECR, Hosted Private…]]></title>
            <link>https://medium.com/clarusway/how-to-use-images-from-a-private-container-registry-for-kubernetes-aws-ecr-hosted-private-13a759e2c4ea?source=rss-91eedf33fc0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/13a759e2c4ea</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws-ecr]]></category>
            <category><![CDATA[kubernetes-deployment]]></category>
            <category><![CDATA[container-registry]]></category>
            <category><![CDATA[kubernetes-secret]]></category>
            <dc:creator><![CDATA[Joe Blue]]></dc:creator>
            <pubDate>Thu, 24 Dec 2020 11:31:13 GMT</pubDate>
            <atom:updated>2021-07-09T11:31:24.443Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use images from a private container registry for Kubernetes: AWS ECR, Hosted Private Container Registry.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*amSOjJMoQxygWI_qBhEW-w.jpeg" /><figcaption>Accessing the hosted private container registry from Kubernetes</figcaption></figure><p>Some container registry providers in the industry give public and private access to the images in the registry repositories. For public access, as in Docker Hub, there is no issue which you have to tackle down in the Kubernetes(K8s) cluster. However, when it comes to private images, you have to define a way to access those images securely. In this article, the described methodology in the Kubernetes to access the private container registry will be explained.</p><p>Before continuing with the Kubernetes, make sure to apply the Client Machine Settings to Use the Registry to all worker nodes of K8s defined at the <a href="https://medium.com/clarusway/creating-a-private-container-registry-repository-and-web-service-8c753b54f55c?source=friends_link&amp;sk=d1898dd4030e23f7b27ee7f317edca32">Creating a Private Container Registry: Repository and Web Service</a>.</p><h3>The Structure of the Deployment Object</h3><p>Kubernetes Deployment, and the Pod object, has a special tag/field, imagePullSecret, to interact with private repositories. With this tag, you can reference the object&#39;s name that holds the required credentials information to interact with the private registry. A sample Deployment file with settings is shown below.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: my-app<br>  labels:<br>    app: my-app<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: my-app<br>  template:<br>    metadata:<br>      labels:<br>        app: my-app<br>    spec:<br><strong>      imagePullSecrets:<br>      - name: secret-registry</strong><br>      containers:<br>      - name: my-app<br>        image: ip-172-31-82-125.ec2.internal:5000/nginx<br>        #image: 046402772087.dkr.ecr.us-east-1.amazonaws.com/my-nginx:latest<br>        imagePullPolicy: Always<br>        ports:<br>          - containerPort: 80</pre><p>The private registry access information is stored in Secret file, this file referenced in Deployment file with imagePullSecret field. The name is the file that contains the secret information to access the private registry.</p><h3>The Structure of Secret Object</h3><p>The Kubernetes Secret object has a special type of kind for private registries as;</p><pre>type: kubernetes.io/dockercfg<br>type: kubernetes.io/dockerconfigjson</pre><p>Let’s remember the structure of Secret object:</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: secret-registry<br>type: <strong>kubernetes.io/dockercfg</strong><br>data:<br>  <strong>.dockercfg:</strong> |<br>    &quot;&lt;base64 encoded ~/.docker/config.json-file&gt;&quot;</pre><p>or</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: secret-registry<br>type: <strong>kubernetes.io/dockerconfigjson</strong><br>data:<br>  <strong>.dockerconfigjson:</strong> |<br>    &quot;&lt;base64 encoded ~/.docker/config.json-file&gt;&quot;</pre><p>As long as we have defined this secret file and referenced it in the Deployment or Pod definition file, the access to the private registry should run smoothly.</p><p>Now let’s discuss the ways to create the Secret file.</p><h3>Create Secret Object from login Command</h3><p>When we login into the container registry, the credentials are saved in the ~/.docker/config.json file. We can get the required information from this file and can place it inside the Secret file data portion.</p><p>For AWS ECR;</p><pre>aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin &lt;your-id&gt;.dkr.ecr.us-east-1.amazonaws.com</pre><p>For hosted private container registry;</p><pre>docker login -u username -p password  <a href="https://private-registry/">https://private-registry</a></pre><p><strong>Firstly</strong>, after logging in to the container registry, create secret data from the stored data as follows;</p><pre>cat ~/.docker/config.json | base64</pre><p>You can now copy the output as secret data and place it in the file&#39;s data portion. Next, give it a try in the K8s cluster.</p><h3>Create Secret Object with kubectl Command</h3><p>It is also possible to create the Secret object with the help of kubectl command. They are listed as follows.</p><p><strong>Secondly</strong>, you can also create the Secret object from ~/.docker/config.json directly as follows;</p><pre>kubectl create secret generic secret-registry \<br>  --from-file=.dockerconfigjson=~/.docker/config.json \<br>  --type=kubernetes.io/dockerconfigjson</pre><p><strong>Thirdly</strong>, you can also create the Secret object by entering the credentials as follows;</p><pre>kubectl create secret docker-registry secret-registry \<br>  --docker-server=<a href="https://private-registry/">https://private-registry</a> \<br>  --docker-username=user-name \<br>  --docker-password=password</pre><p>Note that when it comes to AWS ECR, the command aws ecr get-login-password --region us-east-1 gives the password and user-name is AWS.</p><p>ECR link is like this;<br>--docker-server=https://&lt;your-id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com</p><p>The <strong>secret-registry</strong> is the name of the Secret object to reference inside the Deployment or Pod file.</p><p>Finally, you can test the configuration by applying the Deployment and Secret files accordingly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13a759e2c4ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/clarusway/how-to-use-images-from-a-private-container-registry-for-kubernetes-aws-ecr-hosted-private-13a759e2c4ea">How to use images from a private container registry for Kubernetes: AWS ECR, Hosted Private…</a> was originally published in <a href="https://medium.com/clarusway">Clarusway</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>