<?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: Nabarun Pal</title>
    <description>The latest articles on DEV Community by Nabarun Pal (@nabarun).</description>
    <link>https://dev.to/nabarun</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%2F19222%2F60fa0b44-e1b4-41a4-b4a3-5608306a9ed6.jpg</url>
      <title>DEV Community: Nabarun Pal</title>
      <link>https://dev.to/nabarun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nabarun"/>
    <language>en</language>
    <item>
      <title>My Rubber Ducks</title>
      <dc:creator>Nabarun Pal</dc:creator>
      <pubDate>Sat, 29 Aug 2020 08:25:25 +0000</pubDate>
      <link>https://dev.to/nabarun/my-rubber-ducks-312f</link>
      <guid>https://dev.to/nabarun/my-rubber-ducks-312f</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://blog.naba.run/posts/my-rubber-ducks/"&gt;https://blog.naba.run/posts/my-rubber-ducks/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are times when I find myself stuck when solving any problem. This deadlock can arise due to several factors. Sometimes I need a new perspective of the problem. Sometimes I just need to go through my approach with a fresh mind.&lt;/p&gt;

&lt;p&gt;I can ping my colleagues to get new perspectives or explain to them what I am trying to achieve. But, not always can I find someone to listen to me since everyone is busy with their work.&lt;/p&gt;

&lt;p&gt;What I do in those situations is either&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;write down my approach on a piece of paper in the simplest terms, or&lt;/li&gt;
&lt;li&gt;talk to my &lt;strong&gt;Rubber Ducks&lt;/strong&gt; about the approach assuming that the ducks have ZERO knowledge about what I am doing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I learned about the &lt;strong&gt;Rubber Duck&lt;/strong&gt; debugging paradigm when reading &lt;a href="https://pragprog.com/titles/tpp20/the-pragmatic-programmer-20th-anniversary-edition/"&gt;The Pragmatic Programmer&lt;/a&gt; by Andrew Hunt and David Thomas. It is a gem of a book. I feel every software engineer looking to excel in their art should read the book. They discuss this method in the Debugging chapter of the book. The idea to find the cause of a problem by explaining it in very simple terms to someone else. The other person listening to you shouldn't speak a word and should just nod to what you are saying. This simple exercise of explaining your approach in very well defined and atomic steps can give you new insights to your problem.&lt;/p&gt;

&lt;p&gt;Obviously you can't have someone with you all the time to just listen to you. And here comes the importance of inanimate objects that can't speak. They are the ideal ones that you can explain your problem to. There are some positive effects like they won't ever judge you, they are always with you no matter what happens. Having said all that, I want to introduce you to my rubber ducks:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9yfuZHPh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.naba.run/images/rubber-ducks.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9yfuZHPh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.naba.run/images/rubber-ducks.jpg" alt="My rubber ducks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the front row is Goldie, then Zee, then Captain Kube and the tall bloke is Phippy. The whole gang is known as &lt;a href="https://phippy.io"&gt;Phippy and Friends&lt;/a&gt;. They are always on my table looking over me and listen to me whenever I want to speak to them. I know it's a bit intimidating someone looking at you all the time, but eventually you get along with them. ;)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Do note that this method works for me, but not necessarily would it work for everyone. I always ask people to find their own debugging comfort zone.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>abstract</category>
      <category>thoughts</category>
    </item>
    <item>
      <title>Running Tor Proxy with Docker</title>
      <dc:creator>Nabarun Pal</dc:creator>
      <pubDate>Mon, 06 Jul 2020 09:19:38 +0000</pubDate>
      <link>https://dev.to/nabarun/running-tor-proxy-with-docker-56n9</link>
      <guid>https://dev.to/nabarun/running-tor-proxy-with-docker-56n9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Originally published on &lt;a href="https://blog.naba.run/posts/running-tor-proxy-with-docker/"&gt;https://blog.naba.run/posts/running-tor-proxy-with-docker/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Today I was testing &lt;a href="https://github.com/kushaldas/dns-tor-proxy"&gt;dns-tor-proxy&lt;/a&gt; which required a SOCKS5 Tor proxy and realized I never ran a Tor service on my current machine. I use &lt;a href="https://www.torproject.org/"&gt;Tor browser&lt;/a&gt; almost daily for browsing websites I have absolutely no trust on, but not the standalone Tor proxy. In this article, I will try to set one up using the system package as well as inside a Docker container.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Tor proxy?
&lt;/h2&gt;

&lt;p&gt;A Tor proxy is a SOCKS5 proxy which routes your traffic through the Tor network. The Tor network ensures that any traffic originating from inside the network gets routed through atleast 3 random relays before exiting through the exit node.&lt;/p&gt;

&lt;p&gt;It helps you to anonymize traffic, block trackers and, prevent surveillance amongst other benefits. If you are wondering who should use Tor, the answer is every person who cares about their privacy. You can read more about the architecture &lt;a href="https://2019.www.torproject.org/about/overview.html.en#thesolution"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arch Linux
&lt;/h2&gt;

&lt;p&gt;Tor is available in the Arch package repository and can be simply installed by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install Tor&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pacman &lt;span class="nt"&gt;-S&lt;/span&gt; tor
...
&lt;span class="c"&gt;# Start the service&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start tor

&lt;span class="c"&gt;# Check whether the service is running&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;netstat &lt;span class="nt"&gt;-tunlp&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;tor
tcp     0   0   127.0.0.1:9050  0.0.0.0:&lt;span class="k"&gt;*&lt;/span&gt;   LISTEN  3808529/tor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We see above that installing &lt;code&gt;tor&lt;/code&gt; through &lt;code&gt;pacman&lt;/code&gt; set up the systemd service as well. Jump to Using the proxy for the demo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Debian/Ubuntu
&lt;/h2&gt;

&lt;p&gt;The packages in the Debian ecosystem are often outdated. To get the latest version, one almost always needs to add third-party package repositories. I am not going into detail how to install Tor in that ecosystem, since there are a &lt;strong&gt;lot&lt;/strong&gt; of distribution/version combinations. The steps are well detailed in the official Tor installation &lt;a href="https://2019.www.torproject.org/docs/debian.html.en"&gt;docs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker
&lt;/h2&gt;

&lt;p&gt;We will be building a very lightweight Docker image to reduce footprint.&lt;/p&gt;

&lt;p&gt;Let's start with the Tor configuration,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SocksPort 0.0.0.0:9050
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above should get one started with the defaults. Feel free to change the port to whatever you like. The address being listened should be &lt;code&gt;0.0.0.0&lt;/code&gt; as we would be accessing the server from outside the docker container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# set alpine as the base image of the Dockerfile&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; alpine:latest&lt;/span&gt;

&lt;span class="c"&gt;# update the package repository and install Tor&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apk update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apk add tor

&lt;span class="c"&gt;# Copy over the torrc created above and set the owner to `tor`&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; torrc /etc/tor/torrc&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; tor /etc/tor

&lt;span class="c"&gt;# Set `tor` as the default user during the container runtime&lt;/span&gt;
&lt;span class="k"&gt;USER&lt;/span&gt;&lt;span class="s"&gt; tor&lt;/span&gt;

&lt;span class="c"&gt;# Set `tor` as the entrypoint for the image&lt;/span&gt;
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt;&lt;span class="s"&gt; ["tor"]&lt;/span&gt;

&lt;span class="c"&gt;# Set the default container command&lt;/span&gt;
&lt;span class="c"&gt;# This can be overridden later when running a container&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["-f", "/etc/tor/torrc"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's build the image now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; palnabarun/tor &lt;span class="nb"&gt;.&lt;/span&gt;
Sending build context to Docker daemon  67.58kB
Step 1/6 : FROM alpine:latest
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a24bb4013296
Step 2/6 : RUN apk update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apk add tor
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Using cache
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a5ea632ba987
Step 3/6 : COPY torrc /etc/tor/torrc
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 5b351b9847bc
Step 4/6 : RUN &lt;span class="nb"&gt;chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; tor /etc/tor
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Running &lt;span class="k"&gt;in &lt;/span&gt;1f6950f03475
Removing intermediate container 1f6950f03475
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 060ded5c532c
Step 5/6 : USER tor
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Running &lt;span class="k"&gt;in &lt;/span&gt;aa0553be76dc
Removing intermediate container aa0553be76dc
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; d763c1181285
Step 6/6 : ENTRYPOINT &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"tor"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Running &lt;span class="k"&gt;in &lt;/span&gt;97fd7f9ee693
Removing intermediate container 97fd7f9ee693
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 13c889f5b018
Successfully built 13c889f5b018
Successfully tagged palnabarun/tor:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might also be wondering what is the image size?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker image &lt;span class="nb"&gt;ls&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;palnabarun/tor
palnabarun/tor  latest  13c889f5b018    About a minute ago 21.1MB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The image is just a mere 21.1MB. Building docker images using &lt;a href="https://alpinelinux.org/"&gt;Alpine Linux&lt;/a&gt; as base results in a very lightweight image.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's run the proxy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker run &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--detach&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--name&lt;/span&gt; tor &lt;span class="se"&gt;\&lt;/span&gt;
    &lt;span class="nt"&gt;--publish&lt;/span&gt; 9050:9050 &lt;span class="se"&gt;\ &lt;/span&gt;&lt;span class="c"&gt;# change the port to whatever you put in the torrc&lt;/span&gt;
    palnabarun/tor
aef03d84628b

&lt;span class="nv"&gt;$ &lt;/span&gt;docker ps | &lt;span class="nb"&gt;grep &lt;/span&gt;tor
aef03d84628b    palnabarun/tor  &lt;span class="s2"&gt;"tor"&lt;/span&gt;   31 seconds ago  Up 30 seconds   0.0.0.0:9050-&amp;gt;9050/tcp  tor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After sometime the Tor proxy will succesfully establish a Tor circuit and it will be ready to use.&lt;/p&gt;

&lt;p&gt;The Tor config and Dockerfile can be found &lt;a href="https://github.com/palnabarun/tor-docker"&gt;here&lt;/a&gt; and there is a ready to consume image on &lt;a href="https://hub.docker.com/r/palnabarun/tor"&gt;Docker Hub&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the proxy
&lt;/h2&gt;

&lt;p&gt;Let's test whether the proxy is working correctly by some simple &lt;code&gt;curl&lt;/code&gt; calls.&lt;/p&gt;

&lt;p&gt;The request below is not going through the proxy and hence would show your ISP provided IP address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl https://check.torproject.org/api/ip
&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"IsTor"&lt;/span&gt;:false,&lt;span class="s2"&gt;"IP"&lt;/span&gt;:&lt;span class="s2"&gt;"49.30.XX.XX"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we specify the Tor proxy when making the request, the IP address would be different.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;--socks5&lt;/span&gt; 127.0.0.1:9050 https://check.torproject.org/api/ip
&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"IsTor"&lt;/span&gt;:true,&lt;span class="s2"&gt;"IP"&lt;/span&gt;:&lt;span class="s2"&gt;"185.220.XXX.XXX"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, notice the value of &lt;code&gt;IsTor&lt;/code&gt; in both the cases, the service running at &lt;code&gt;check.torproject.org&lt;/code&gt; knows whether the traffic was routed through the Tor network.&lt;/p&gt;

&lt;p&gt;The very same proxy can be used in your browser by going to the Network Settings and changing to a manual proxy configuration. I, however, highly recommend to use the &lt;a href="https://www.torproject.org/"&gt;Tor browser&lt;/a&gt; if you just want to browse the internet through Tor.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: The IP addresses are partially redacted for privacy reasons.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;If you are like me who cherishes reading RFCs, check out the following links&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://svn-archive.torproject.org/svn/projects/design-paper/tor-design.pdf"&gt;The original Tor design&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt"&gt;Tor v3 onion services protocol&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>tor</category>
      <category>docker</category>
      <category>opsec</category>
      <category>privacy</category>
    </item>
  </channel>
</rss>
