<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Tag: Security - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/tag/security/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Tue, 25 Jan 2022 04:20:53 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://ryandaniels.ca/wp-content/uploads/2019/07/img_5907-small-blur-square-100x100.jpg</url>
	<title>Tag: Security - Ryan Daniels</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<item>
		<title>Firefox, I love you but you&#8217;re bringing me down</title>
		<link>https://ryandaniels.ca/blog/firefox-i-love-you-but-youre-bringing-me-down/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 25 Jan 2022 00:56:00 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Firefox]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2604</guid>

					<description><![CDATA[<figure class="alignleft size-full is-resized"><img src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_Logo-2021-256.png" alt="" class="wp-image-2780" width="150" height="150"/></figure>
<p>I love Firefox. I'm a Firefox user, and hopefully always will be. Firefox is better than any other browser (plus it's free and open-source). However, there have been a few technical things that I don't like.</p>
<p>The post <a href="https://ryandaniels.ca/blog/firefox-i-love-you-but-youre-bringing-me-down/">Firefox, I love you but you&#8217;re bringing me down</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="alignright size-full"><img fetchpriority="high" decoding="async" width="256" height="256" src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_Logo-2021-256.png" alt="Firefox, I love you but you're bringing me down" class="wp-image-2780"/></figure></div>



<p>I love Firefox. I&#8217;m a Firefox user, and hopefully always will be. Firefox is better than any other browser (plus it&#8217;s <a href="https://en.wikipedia.org/wiki/Firefox" target="_blank" rel="noreferrer noopener">free and open-source</a>). However, there have been a few technical things that I don&#8217;t like.</p>



<span id="more-2604"></span>



<ul class="wp-block-list"><li>Endless promotion of Mozilla VPN</li><li>Firefox DNS over HTTPS silently fails</li><li>Compact Toolbar Density not supported</li></ul>



<p>Queue track: <a href="https://www.youtube.com/watch?v=c5kM3iwYVi0" target="_blank" rel="noreferrer noopener">LCD Soundsystem &#8211; New York, I Love You but You&#8217;re Bringing Me Down</a></p>



<p>But, since Firefox can be customized, you can change these settings to what you like.</p>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-55ed902e      "
					data-scroll= ""
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
													</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#mozilla-vpn-please-stop-bothering-me" class="uagb-toc-link__trigger">Mozilla VPN &#8211; Please stop bothering me</a><li class="uagb-toc__list"><a href="#firefox-dns-over-https-silently-fails-open" class="uagb-toc-link__trigger">Firefox DNS over HTTPS silently fails open</a><li class="uagb-toc__list"><a href="#compact-toolbar-density-option-missing" class="uagb-toc-link__trigger">Compact Toolbar Density option missing</a><li class="uagb-toc__list"><a href="#conclusion" class="uagb-toc-link__trigger">Conclusion</a></ol>					</div>
									</div>
				</div>
			


<h2 class="wp-block-heading" id="mozilla-vpn-please-stop-bothering-me">Mozilla VPN &#8211; Please stop bothering me</h2>



<p>Since Firefox 93, <a href="https://vpn.mozilla.org/" target="_blank" rel="noreferrer noopener">Mozilla VPN</a> promotions won&#8217;t go away. I understand Mozilla needs to make money. But I don&#8217;t want to constantly see this ad. I get it, you offer a VPN service. Unfortunately, there isn&#8217;t an easy way to hide the ads for their VPN. There isn&#8217;t even a documented way for the &#8220;user.js&#8221; settings, however I figured out a way to hide them when opening a new &#8220;Private&#8221; browsing window. This works in Firefox 94 to current (Firefox 96), and hopefully keeps working!</p>



<p>Update the <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/#how-to-automatically-change-firefox-settings">Firefox user.js</a> settings to fix this:</p>



<pre class="wp-block-code"><code>// FF94
user_pref("browser.privatebrowsing.vpnpromourl", "");</code></pre>



<p>Before and after:</p>



<figure class="wp-block-gallery has-nested-images columns-default wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-large"><a href="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad.png" rel="lightbox[2604]"><img decoding="async" width="768" height="630" data-id="2752" src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad.png" alt="Firefox VPN ad" class="wp-image-2752" srcset="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad.png 768w, https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-731x600.png 731w, https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-300x246.png 300w" sizes="(max-width: 768px) 100vw, 768px" /></a></figure>



<figure class="wp-block-image size-large"><a href="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone.png" rel="lightbox[2604]"><img decoding="async" width="768" height="385" data-id="2753" src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone.png" alt="Firefox VPN ad removed" class="wp-image-2753" srcset="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone.png 768w, https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone-300x150.png 300w" sizes="(max-width: 768px) 100vw, 768px" /></a></figure>
</figure>



<h2 class="wp-block-heading" id="firefox-dns-over-https-silently-fails-open">Firefox DNS over HTTPS silently fails open</h2>



<p>Firefox has a built-in option for <a href="https://en.wikipedia.org/wiki/DNS_over_HTTPS" target="_blank" rel="noreferrer noopener">DNS over HTTPS</a> (DOH). It&#8217;s great that you can set this up and add another layer of security from prying eyes. This actually isn&#8217;t a new thing, it has been around since Firefox 62.</p>



<p>However, I recently found out that it fails open by default with no warning.</p>



<p>What does this mean?<br>If the DNS over HTTPS server you pick stops working, Firefox silently fails to use DNS over HTTPS and uses your system&#8217;s default DNS settings instead. And there is no warning when this happens.</p>



<p>They say, a false sense of security is worse than no security at all. You thought you were more secure with DNS over HTTPS.</p>



<p>Read more about the option from: <br><a href="https://support.mozilla.org/en-US/kb/connection-settings-firefox" target="_blank" rel="noreferrer noopener">Connection settings in Firefox</a><br><a href="https://support.mozilla.org/en-US/kb/firefox-dns-over-https" target="_blank" rel="noreferrer noopener">Firefox about DNS-over-HTTPS</a></p>



<p id="block-4bd57f8a-e494-498d-bab3-6fe636aa0de2">And also read the <a href="https://wiki.mozilla.org/Trusted_Recursive_Resolver" target="_blank" rel="noreferrer noopener">Trusted Recursive Resolver</a> wiki page carefully about the different options.</p>



<p>You can fix this by changing the setting for &#8220;network.trr.mode&#8221; to 3, which will force Firefox to only use the resolver you specify for DOH and if it fails, then Firefox won&#8217;t use the system&#8217;s DNS.</p>



<p>In the <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/#how-to-automatically-change-firefox-settings">Firefox user.js</a> settings file add:</p>



<pre class="wp-block-code"><code>//trr.mode 5 is no DOH. 2 is enable DOH. 3 is no failback to system dns
user_pref("network.trr.mode", 3);
user_pref("network.trr.default_provider_uri", "https://dns.quad9.net/dns-query");
user_pref("network.trr.uri", "https://dns.quad9.net/dns-query");
user_pref("network.trr.custom_uri", "https://dns.quad9.net/dns-query");
user_pref("network.trr.bootstrapAddress", "9.9.9.9");</code></pre>



<p>The above also sets the DOH resolver to <a href="https://www.quad9.net/" target="_blank" rel="noreferrer noopener">Quad9</a>.</p>



<p id="block-4bd57f8a-e494-498d-bab3-6fe636aa0de2">Also note:<br>When you change the setting (URL or Disable/Enable) in the Firefox Settings, it will reset &#8220;network.trr.mode&#8221; to 2 so you need to change this again!</p>



<h2 class="wp-block-heading" id="compact-toolbar-density-option-missing">Compact Toolbar Density option missing</h2>



<p>I like the &#8220;Compact&#8221; Toolbar Density option because I don&#8217;t want a huge waste of space at the top of my Firefox window. I want to be able to optimize for these wide monitors we have, so vertical space is at a premium! Since Firefox 89 this <a href="https://support.mozilla.org/en-US/kb/compact-mode-workaround-firefox" target="_blank" rel="noreferrer noopener">has been hidden behind a configuration setting</a>.</p>



<p>With this setting in the <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/#how-to-automatically-change-firefox-settings">user.js</a> you now have the Compact option again in Firefox:</p>



<pre class="wp-block-code"><code>// FF89
// Compact mode workaround in Firefox
// https://support.mozilla.org/en-US/kb/compact-mode-workaround-firefox
user_pref("browser.compactmode.show", true); // &#91;DEFAULT: false]</code></pre>



<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>



<p>Firefox is my browser of choice, and it is free and open-source. Its ability for customization means you can change it to your liking too. So these technical issues will (hopefully) always have a work-around.</p>
<p>The post <a href="https://ryandaniels.ca/blog/firefox-i-love-you-but-youre-bringing-me-down/">Firefox, I love you but you&#8217;re bringing me down</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2604</post-id>	</item>
		<item>
		<title>Secure Docker with iptables firewall and Ansible</title>
		<link>https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 24 May 2020 19:11:41 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2290</guid>

					<description><![CDATA[<figure class="alignleft wp-block-image size-thumbnail"><img src="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-200x300.jpg" alt="" class="wp-image-2489"/></figure>
<p>Out of the box, security with Docker (and Docker Swarm) over the network is bad. Okay, that's not entirely true. Out of the box when you have no containers started, it's fine. But after you start a container, and if you publish a port, they are exposed to the outside world by default. And it's not easy to fix. You need to create a custom Docker firewall with iptables.<br />
&#160;</p>
<p>The post <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">Secure Docker with iptables firewall and Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Out of the box, security with Docker (and Docker Swarm) over the network is bad. Okay, that&#8217;s not entirely true. Out of the box when you have no containers started, it&#8217;s fine. But after you start a container, and if you publish a port, they are exposed to the outside world by default. And it&#8217;s not easy to fix. You need to create a custom Docker firewall with iptables.</p>



<p>Let&#8217;s discuss the background of firewall issues with Docker, and a working solution for my use case (either setup manually or using Ansible). By the end we will use a firewall on the server to lock down everything by default, only allowing my trusted IPs! With the option to open specified ports publicly (like SSH).</p>



<p>Note: This solution works with CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<span id="more-2290"></span>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-5708b17e-d0f5-4528-8221-706c39a8a865      "
					data-scroll= ""
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							Table Of Contents						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#background" class="uagb-toc-link__trigger">Background</a><li class="uagb-toc__list"><a href="#roll-your-own-solution" class="uagb-toc-link__trigger">Roll your own solution</a><li class="uagb-toc__list"><a href="#problems-i-need-to-solve" class="uagb-toc-link__trigger">Problems I need to solve</a><li class="uagb-toc__list"><a href="#solution-docker-firewall-with-iptables-and-ipset" class="uagb-toc-link__trigger">Solution &#8211; Docker firewall with iptables and ipset</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#high-level-summary" class="uagb-toc-link__trigger">High level summary</a></li></ul></li><li class="uagb-toc__list"><a href="#warnings" class="uagb-toc-link__trigger">Warnings</a><li class="uagb-toc__list"><a href="#the-manual-way" class="uagb-toc-link__trigger">The manual way</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#prep" class="uagb-toc-link__trigger">Prep</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#configure-ipset" class="uagb-toc-link__trigger">Configure ipset</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#configure-iptables" class="uagb-toc-link__trigger">Configure iptables</a></li></ul></li></ul></li><li class="uagb-toc__list"><a href="#the-automatic-way-with-ansible" class="uagb-toc-link__trigger">The Automatic way with Ansible</a><li class="uagb-toc__list"><a href="#conclusion" class="uagb-toc-link__trigger">Conclusion</a><li class="uagb-toc__list"><a href="#references" class="uagb-toc-link__trigger">References</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#background-for-dockers-undocumented-use-of-iptables-input-chain" class="uagb-toc-link__trigger">Background for Docker&#039;s undocumented use of iptables INPUT chain</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#references-and-links" class="uagb-toc-link__trigger">References and links</a></ul></ul></ul></ol>					</div>
									</div>
				</div>
			


<h2 class="wp-block-heading">Background</h2>



<div class="wp-block-image"><figure class="alignright size-medium"><img loading="lazy" decoding="async" width="400" height="600" src="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-400x600.jpg" alt="Docker punches a hole through firewall" class="wp-image-2489" srcset="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-400x600.jpg 400w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-480x720.jpg 480w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-200x300.jpg 200w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye.jpg 533w" sizes="auto, (max-width: 400px) 100vw, 400px" /><figcaption><sup>Image credit: <a rel="noreferrer noopener" href="https://www.pexels.com/photo/brown-human-eye-2873058/" target="_blank">Jonathan Borba</a></sup></figcaption></figure></div>



<p>Firstly, even if you were using a firewall like iptables, Docker makes that useless. Docker punches a whole right through your firewall!</p>



<p>And if you <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">try another firewall, like firewalld</a>? Docker Swarm (and even regular Docker) with firewalld is a complete mess. Restart the firewalld service, or change the firewalld config, and you lost all the config that Docker needed. Now you have to restart Docker! What happens if the firewalld service failed and restarted? That Docker Swarm node is out of service.</p>



<p>Keep in mind, when I mention Docker, it means the regular Docker Engine. Docker Swarm means SwarmKit, which is the newer way of using Swarm. (The old way is the standalone solution which is old and not referenced at all here).</p>



<p>There are many attempts to solve this problem by users of Docker. Unfortunately the Docker team has been pretty quiet about these issues. They recommend a manual user solution, and to disable Docker&#8217;s use of iptables. I&#8217;m speculating here, but it seems like any future change from Docker will likely be a breaking change since this is a complicated issue to fix.</p>



<p>The attempted solutions (from users) are not very straight forward for a normal Docker user. And that&#8217;s the real issue. On top of that, out of the box (after you start one service with a published port), there is no security at the network layer. Anyone can connect to an exposed container&#8217;s port. Most importantly, even if you think you have a firewall protecting you.. Wrong, you don&#8217;t! With normal Docker, you can bind your service to your localhost which helps. But what about Docker Swarm? Nope, that doesn&#8217;t work.</p>



<p>There&#8217;s a great article about &#8220;<a rel="noreferrer noopener" href="https://utcc.utoronto.ca/~cks/space/blog/tech/SecurityChoiceProblem" data-type="URL" data-id="https://utcc.utoronto.ca/~cks/space/blog/tech/SecurityChoiceProblem" target="_blank">The problem of forcing users to make choices (in security)</a>.&#8221; Definitely worth the read!</p>



<h2 class="wp-block-heading">Roll your own solution</h2>



<p>Until this is actually addressed in Docker, our only hope is to find the simplest solution possible. And turning off iptables integration in Docker is unacceptable (which is constantly recommended by the Docker developers). The other option is to move on from Docker and/or Docker Swarm. I hear this thing called Kubernetes is pretty great. Anyways, back to Docker. <br>Many people have spent hours trying to learn, and figure out iptables as a solution to this. You need to roll your own solution apparently! So iptables is probably the best approach, since that is what Docker needs to use to do it&#8217;s magic (and most other firewalls are just a wrapper for iptables anyway depending on your OS).</p>



<p>Something <s>fun</s> I found out while testing this, <a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">Docker Swarm uses iptables in an undocumented way</a>. Docker Swarm uses the iptables INPUT chain! It&#8217;s only for encrypted overlay networks. But it&#8217;s not very fun realizing that! All of a sudden rules are being appended to the INPUT chain.</p>



<p>Okay, enough backstory. On with my futile attempt to roll my own solution. This took way longer than I thought it would! But it does work! Currently it works at least.. (That&#8217;s why I use the word futile!)</p>



<h2 class="wp-block-heading">Problems I need to solve</h2>



<ol class="wp-block-list"><li>Only allow traffic from multiple &#8220;trusted&#8221; IP addresses to my servers. Not all of these IPs will be in the same &#8220;IP block/range&#8221; either. This will be to all services running directly on the server, and also all of the Docker containers.</li><li>Let only specific ports be publicly accessible, like SSH.</li><li>I&#8217;m not managing which containers are accessible through the firewall. Meaning, I&#8217;m not manually adding ports into my firewall solution. That kind of manual work is not happening. I need a dynamic, and flexible solution that blocks by default except to my trusted IPs.</li><li>The firewall solution must be simple. More complex means more room for error.</li><li>The firewall solution must not impact performance significantly.</li><li>Restarting the firewall won&#8217;t break Docker. </li><li>Restarting Docker won&#8217;t break the firewall.</li><li>No impact to running server processes or Docker services when making a change. Things need to keep working! <br>Firewall changes need to happen online and not impact Docker. Meaning I can&#8217;t be restarting Docker because I made a firewall change.<br>Docker &#8220;changes&#8221; need to happen online. Meaning I can&#8217;t be restarting the firewall because I made a Docker change. (A Docker &#8220;change&#8221; means starting/stopping a container).</li></ol>



<p>That sounds very simple! Unfortunately, it is not with Docker (and Docker Swarm).</p>



<h2 class="wp-block-heading">Solution &#8211; Docker firewall with iptables and ipset</h2>



<p>If you don&#8217;t know much about iptables, or ipset, that&#8217;s okay. You don&#8217;t really need to know. You should have some basic understandings though, so you don&#8217;t break your servers! The <a rel="noreferrer noopener" href="https://wiki.archlinux.org/index.php/Iptables#Chains" target="_blank">Arch Linux wiki</a> has great information about iptables. Including this helpful <a rel="noreferrer noopener" href="https://www.frozentux.net/iptables-tutorial/chunkyhtml/images/tables_traverse.jpg" target="_blank" rel="lightbox[2290]">visual</a> about the iptables flow.</p>



<p>Note: This solution works with CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<h3 class="wp-block-heading">High level summary</h3>



<p>iptables with ipset will handle all of this for us. And keep our servers, and Docker locked down from the network level. </p>



<p>In this solution, we will use the iptables INPUT chain to jump to another chain (let&#8217;s call our custom chain FILTERS), but return if there&#8217;s some legitimate looking traffic, so the Swarm overlay can do whatever it wants in INPUT with IPSEC, or whatever it is appending to INPUT.<br>Inside our custom chain FILTERS, we drop everything that doesn&#8217;t match our trusted list of IPs. We also allow our SSH port and the basic default iptables stuff.. You can also add any OS port to be publicly accessible.<br>The DOCKER-USER chain only needs a few entries. Any internal Docker traffic is returned, and it will drop any other traffic that&#8217;s not in our allowed IP list. You can also add any container port to be publicly accessible.</p>



<p>One of the dangers with this approach is if Docker changes it&#8217;s behaviour our firewall could break, or our Docker services could stop working. Since Docker doesn&#8217;t offer any solution for their users, we need our own solution. So keep in mind that you need to test this when upgrading to a new version of Docker. That is the trade-off with a &#8220;roll your own&#8221; solution. But what choice do we have?</p>



<p>I&#8217;ve created an <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Role: iptables for Docker</a>, on <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker" target="_blank">GitHub</a> and <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Galaxy</a>.</p>



<h2 class="wp-block-heading">Warnings</h2>



<p><strong>Warning: Be sure you have everything needed in your configuration. Once the iptables firewall is started it blocks anything that wasn’t added! Don&#8217;t lock yourself out of your server. Be sure to have another way to connect, like a console.</strong></p>



<p><strong>Disclaimer: Keep in mind, you should test all of this in your lab or staging environments. I can’t guarantee this will be 100% safe and can’t be held responsible for anything going wrong!</strong></p>



<p><strong>SELinux Bug</strong>: If using SELinux, currently there&#8217;s a bug with SELinux which prevents saving the iptables rules to the iptables.save file.<br><strong>Impact</strong>: Saving the iptables rules a 2nd time will silently fail. Workaround has been added so SELinux allows chmod to interact with the iptables.save file. <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker/blob/master/README.md#selinux-manual-workaround-for-iptables-and-chmod" target="_blank">See notes on GitHub for SELinux workaround steps</a>. Alternatively you could disable SELinux, but that&#8217;s not recommended. Bug report: <a rel="noreferrer noopener" href="https://bugs.centos.org/view.php?id=12648" target="_blank">https://bugs.centos.org/view.php?id=12648</a></p>



<h2 class="wp-block-heading">The manual way</h2>



<p>Run the commands below. These commands are only for CentOS/RHEL 7. If you don&#8217;t want to do this manually, jump to the <a href="#the-automatic-way-with-ansible">Automatic section, using Ansible</a> (which also works with Ubuntu).</p>



<h3 class="wp-block-heading">Prep</h3>



<p>Make note of what you already have in iptables (if you are already using it). Be sure you have some background with iptables, since you could break things!</p>



<pre class="wp-block-code"><code># iptables -nvL --line-numbers</code></pre>



<p>Install the required packages for CentOS / RHEL:</p>



<pre class="wp-block-code"><code># yum install iptables iptables-services ipset ipset-service</code></pre>



<h3 class="wp-block-heading">Configure ipset</h3>



<p>ipset allows you to add a list of IPs that you can use with iptables. In our case, we will add a list of IPs we want to be able to connect to our servers.</p>



<p>Configure ipset with a setname of <code>ip_allow</code>.<br>Add IPs you want to allow. Change the IPs below to your actual trusted/allowed IP ranges. Be sure to include your Docker server IPs here, because if you don&#8217;t they can&#8217;t communicate with eachother:</p>



<pre class="wp-block-code"><code># mkdir -p /etc/sysconfig/ipset.d
# vi /etc/sysconfig/ipset.d/ip_allow.set

create -exist ip_allow hash:ip family inet hashsize 1024 maxelem 65536
add ip_allow 192.168.1.123
add ip_allow 192.168.100.0/24
add ip_allow 192.168.101.0/24
add ip_allow 192.168.102.0/24</code></pre>



<p>Start, and Enable the ipset service:</p>



<pre class="wp-block-code"><code># systemctl status ipset
# systemctl start ipset
# systemctl enable ipset</code></pre>



<p>See what ipset has in it&#8217;s loaded configuration:</p>



<pre class="wp-block-code"><code># ipset list | head</code></pre>



<p>Important: Make note of the size of &#8220;Number of entries&#8221;. If that number is close to the maxelem size (65536), then you need to delete the ipset and re-create it with a larger max size. If you only use a few IP ranges like above, you don&#8217;t need to worry and will be well below the limit.</p>



<h3 class="wp-block-heading">Configure iptables</h3>



<p>Next up, iptables. iptables is our solution for a firewall. We will create a file with our rules and then add those rules into iptables. The important part is to not flush the existing rules if you are already using Docker  (or Docker Swarm) on your server.</p>



<p>Create an iptables file to use with iptables-restore, to add the rules into iptables:</p>



<pre class="wp-block-code"><code># vi iptables-rules.txt</code></pre>



<p>Add below to the file. There is a lot going on here..</p>



<pre class="wp-block-code"><code>*filter
:DOCKER-USER - &#91;0:0]
:FILTERS - &#91;0:0]
#Can't flush INPUT. wipes out docker swarm encrypted overlay rules
#-F INPUT
#Use ansible or run manually once instead to add -I INPUT -j FILTERS
#-I INPUT -j FILTERS
-F DOCKER-USER
-A DOCKER-USER -m state --state RELATED,ESTABLISHED -j RETURN
-A DOCKER-USER -i docker_gwbridge -j RETURN
-A DOCKER-USER -s 172.18.0.0/16 -j RETURN
-A DOCKER-USER -i docker0 -j RETURN
-A DOCKER-USER -s 172.17.0.0/16 -j RETURN
#Below Docker ports open to everyone if uncommented
#-A DOCKER-USER -p tcp -m tcp -m multiport --dports 8000,8001 -j RETURN
#-A DOCKER-USER -p udp -m udp -m multiport --dports 9000,9001 -j RETURN
-A DOCKER-USER -m set ! --match-set ip_allow src -j DROP
-A DOCKER-USER -j RETURN
-F FILTERS
#Because Docker Swarm encrypted overlay network just appends rules to INPUT. Has to be at top unfortunately
-A FILTERS -p udp -m policy --dir in --pol ipsec -m udp -m set --match-set ip_allow src --dport 4789 -j RETURN
-A FILTERS -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FILTERS -p icmp -j ACCEPT
-A FILTERS -i lo -j ACCEPT
#Below OS ports open to everyone if uncommented
-A FILTERS -p tcp -m state --state NEW -m tcp -m multiport --dports 22 -j ACCEPT
#-A FILTERS -p udp -m udp -m multiport --dports 53,123 -j ACCEPT
-A FILTERS -m set ! --match-set ip_allow src -j DROP
-A FILTERS -j RETURN
COMMIT</code></pre>



<p>Use iptables-restore to add the above rules into iptables. The very important flag is <code>-n</code>. That makes sure we don&#8217;t flush the iptables rules if we have rules already in Docker (or Docker Swarm).</p>



<pre class="wp-block-code"><code># iptables-restore -n &lt; iptables-rules.txt</code></pre>



<p>Next, add a rule to the INPUT chain, so we start using the new rules in FILTERS. It has to be at the top, and only needs to be added once:</p>



<pre class="wp-block-code"><code># iptables -I INPUT 1 -j FILTERS</code></pre>



<p>Save the iptables rules:</p>



<pre class="wp-block-code"><code># /usr/libexec/iptables/iptables.init save</code></pre>



<p>That will save any existing and our new iptables rules to the iptables configuration file so it will be persistent after a reboot.</p>



<p>In addition, it was needed to run the above iptables command manually since we want to ensure it&#8217;s only inserted once. And we can&#8217;t flush the INPUT chain to ensure that since Docker Swarm could have rules there already.</p>



<p>Start and Enable the iptables service:</p>



<pre class="wp-block-code"><code># systemctl status iptables
# systemctl start iptables
# systemctl enable iptables</code></pre>



<p>If you want to customize the iptables rules to allow more ports to be open to everyone, just add the port to the appropriate rule in the iptables file (tcp or udp), then re-run the same commands from above:</p>



<pre class="wp-block-code"><code># iptables-restore -n &lt; iptables-rules.txt
# /usr/libexec/iptables/iptables.init save</code></pre>



<p><strong>Don&#8217;t miss the <a href="#warnings">Warnings</a> from above! Especially about SELinux.</strong></p>



<p>If you don&#8217;t want to do all of that manually, and you use Ansible, then do this instead..</p>



<h2 class="wp-block-heading">The Automatic way with Ansible</h2>



<p>Manually run all of the above, on every Docker server is not ideal. Let&#8217;s use Ansible instead!</p>



<p>I&#8217;ve created an <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Role: iptables for Docker</a>, on <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker" target="_blank">GitHub</a> and <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Galaxy</a>. </p>



<p>This works on CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<p>Install the Ansible Role using Ansible Galaxy:</p>



<pre class="wp-block-code"><code>$ ansible-galaxy install ryandaniels.iptables_docker</code></pre>



<p>Or, clone the GitHub project:</p>



<pre class="wp-block-code"><code>$ git clone https://github.com/ryandaniels/ansible-role-iptables-docker.git roles/ryandaniels.iptables_docker</code></pre>



<p>Create the Ansible Playbook, called iptables_docker.yml:</p>



<pre class="wp-block-code"><code>---
- hosts: '{{ inventory }}'
  become: yes
  vars:
    # Use this role
    iptables_docker_managed: true
  roles:
  - ryandaniels.iptables_docker</code></pre>



<p>Make configuration changes to add desired IP addresses and ports as needed.</p>



<p><strong>Don&#8217;t miss the <a href="#warnings">Warnings</a> from above!</strong></p>



<p>Then run the playbook:</p>



<pre class="wp-block-code"><code>$ ansible-playbook iptables_docker.yml --extra-vars "inventory=centos7" -i hosts-dev</code></pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In conclusion, now we have secured our Docker (and Docker Swarm) environments using Ansible to perform the installation and configuration of iptables! None of our Docker published ports are exposed to the world, unless we want them to be! We have created a custom Docker firewall with iptables. Hopefully, some day this will be the default behaviour and shipped with Docker out of the box! Dare to dream. Security is hard.</p>



<h2 class="wp-block-heading">References</h2>



<h3 class="wp-block-heading">Background for Docker&#8217;s undocumented use of iptables INPUT chain</h3>



<p><a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">See my previous post about this</a>.</p>



<h3 class="wp-block-heading">References and links</h3>



<p>References, notes, and links about the Docker firewall discussion:</p>



<ul class="wp-block-list"><li><a rel="noreferrer noopener" href="https://docs.docker.com/network/overlay/#encrypt-traffic-on-an-overlay-network" target="_blank">Docker Documentation &#8211; Overlay Networks</a></li><li><a rel="noreferrer noopener" href="https://github.com/docker/for-linux/issues/690" target="_blank">Docker bypasses ufw firewall rules</a></li><li><a rel="noreferrer noopener" href="https://unrouted.io/2017/08/15/docker-firewall/" target="_blank">unrouted</a> &#8211; Solution using iptables. Not for Swarm. It clobbers the INPUT chain, which is used by encrypted overlay with Docker Swarm</li><li><a rel="noreferrer noopener" href="https://github.com/moby/moby/issues/22054" target="_blank">The big thread about Docker and a firewall</a></li><li><a rel="noreferrer noopener" href="https://wiki.archlinux.org/index.php/Iptables#Chains" target="_blank">Arch Linux wiki to the rescue to show iptables</a> flow which links to a <a rel="noreferrer noopener" href="https://www.frozentux.net/iptables-tutorial/chunkyhtml/images/tables_traverse.jpg" target="_blank" rel="lightbox[2290]">great visual</a><br><br></li></ul>
<p>The post <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">Secure Docker with iptables firewall and Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2290</post-id>	</item>
		<item>
		<title>Docker and the iptables INPUT chain</title>
		<link>https://ryandaniels.ca/blog/docker-iptables-input-chain/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 19 May 2020 01:02:55 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2393</guid>

					<description><![CDATA[<p>When testing Docker and iptables I stumbled upon something interesting. It appears Docker uses the iptables INPUT chain in an undocumented way. Well that's interesting..</p>
<p>The post <a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">Docker and the iptables INPUT chain</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When testing Docker and iptables I stumbled upon something interesting. It appears Docker uses the iptables INPUT chain in an undocumented way. Well that&#8217;s interesting.. Why Docker, Why?</p>



<p>I could find pretty much nothing about this, anywhere.</p>



<p>Wait, let&#8217;s take a step back. What am I talking about?</p>



<p>I was testing iptables with Docker. What a nightmare. Anyways, I noticed something strange with my three node Docker Swarm test VMs. Some very strange rules at the top of the iptables INPUT chain.</p>



<pre class="wp-block-code"><code># iptables -nvL INPUT
Chain INPUT (policy ACCEPT 33477 packets, 8115K bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            policy match dir in pol ipsec udp dpt:4789 u32 "0x0>>0x16&amp;0x3c@0xc&amp;0xffffff00=0x100600"
    0     0 DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:4789 u32 "0x0>>0x16&amp;0x3c@0xc&amp;0xffffff00=0x100600"
   21  3669 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            policy match dir in pol ipsec udp dpt:4789 u32 "0x0>>0x16&amp;0x3c@0xc&amp;0xffffff00=0x100100"
    0     0 DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:4789 u32 "0x0>>0x16&amp;0x3c@0xc&amp;0xffffff00=0x100100"
    1   101 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            policy match dir in pol ipsec udp dpt:4789 u32 "0x0>>0x16&amp;0x3c@0xc&amp;0xffffff00=0x100200"
    0     0 DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:4789 u32 "0x0>>0x16&amp;0x3c@0xc&amp;0xffffff00=0x100200"</code></pre>



<p>What is that? Some kind of rules using a Docker port, and something about IPSEC.</p>



<p>Searching the internet has no information about this, that I could find at least. Only some random Docker issues on GitHub. It does have some similar details in the INPUT chain though.</p>



<p>Also found were two references to the Docker documentation.</p>



<p>The Docker documentation does have a pretty good section about <a rel="noreferrer noopener" href="https://docs.docker.com/network/iptables/" target="_blank">iptables</a>. But no mention of the <code>INPUT</code> chain. They very specifically say they only modify the <code>DOCKER-USER</code> and <code>DOCKER</code> chains in iptables.</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="907" height="292" src="https://ryandaniels.ca/wp-content/uploads/2020/05/image.png" alt="docker iptables input chain" class="wp-image-2399" srcset="https://ryandaniels.ca/wp-content/uploads/2020/05/image.png 907w, https://ryandaniels.ca/wp-content/uploads/2020/05/image-800x258.png 800w, https://ryandaniels.ca/wp-content/uploads/2020/05/image-300x97.png 300w, https://ryandaniels.ca/wp-content/uploads/2020/05/image-768x247.png 768w" sizes="auto, (max-width: 907px) 100vw, 907px" /><figcaption>Source: <a href="https://docs.docker.com/network/iptables/#add-iptables-policies-before-dockers-rules" target="_blank" rel="noreferrer noopener">Docker documentation for iptables</a></figcaption></figure>



<p>There&#8217;s also some information about the <a rel="noreferrer noopener" href="https://docs.docker.com/network/overlay/#encrypt-traffic-on-an-overlay-network" target="_blank">overlay network in the Docker documentation</a>, but unfortunately it&#8217;s also very high level. No details about the Docker magic that makes all the networking work seamlessly! However, it does mention using IPSEC. Time to do some testing.</p>



<p>When testing in Docker Swarm, by starting containers which use an encrypted overlay I get those iptables rules in the INPUT chain. <s>Fun!</s></p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Not a very exciting mystery. But very unexpected that Docker is modifying the INPUT chain in iptables! That changes a few thing when trying to secure Docker.. Hopefully other people weren&#8217;t relying on having the last rule in the INPUT chain. </p>



<p>Only Docker knows how their next version of Docker will behave. Anything a user does to try and secure Docker at the network layer is futile.</p>



<p>That being said, I&#8217;ve attempted to <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">secure Docker with an iptables firewall</a>. Check it out!</p>
<p>The post <a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">Docker and the iptables INPUT chain</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2393</post-id>	</item>
		<item>
		<title>Manage firewalld with Ansible</title>
		<link>https://ryandaniels.ca/blog/ansible-manage-firewalld/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 19 Apr 2020 21:45:00 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2180</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/"><img class="alignleft size-thumbnail wp-image-1170" src="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-e1517962271957-150x150.png" alt="Ansible manage firewalld" width="150" height="150" /></a> Managing firewalld can be a tricky. Especially if you have many servers to manage. Ansible can help manage firewalld rules for you!</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">Manage firewalld with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Managing firewalld can be a tricky. Especially if you have many servers to manage. Ansible can help manage firewalld rules for you!</p>



<span id="more-2180"></span>



<h2 class="wp-block-heading">Background on firewalld</h2>



<p><a rel="noreferrer noopener" href="https://firewalld.org/" target="_blank">Firewalld</a> is a firewall which runs on many Linux distributions. It is software which runs on a server, and is used to locally secure the server. For example, it can restrict which ports are available for all source IPs, or it can further restrict access by allowing only certain IPs to a specific port (and zone). Check out the <a rel="noreferrer noopener" href="https://firewalld.org/documentation/" target="_blank">documentation</a> to read more about the features of firewalld.</p>



<p>Everything is blocked when firewalld starts! The only exception is for ssh on port 22. This is normally what you want on a new server. </p>



<h2 class="wp-block-heading">Problem</h2>



<p>However, firewalld isn&#8217;t with out it&#8217;s limitations. To run commands to configure which ports you want to allow through firewalld, you need to have the firewalld service running. But, what if you are adding firewalld to a server that has an application which is already in use? As soon as you start firewalld, it will be blocked!</p>



<p>There are two ways around this. </p>



<ol class="wp-block-list"><li>Copy your firewalld config files in the right place, with all the right ports, zones, etc. And then start firewalld. This can work. But having Ansible copy files around and deal with all that is a challenge since firewalld behaves a certain way.</li><li>Use the &#8220;offline&#8221; firewalld commands!</li></ol>



<p>Let&#8217;s explore options 2. And lucky for us, we want to use Ansible to help us manage this configuration. And, Ansible can make use of &#8220;offline&#8221; mode.<br>But, unlucky for us, the Ansible module which handles firewalld can&#8217;t do everything. (At least not everything that I want it to do).</p>



<p>I want the configuration for firewalld to be as simple as possible. I don&#8217;t want the configuration for services in one place, and the configuration for ports in another.<br>But more importantly, I don&#8217;t want any service interruption.</p>



<h2 class="wp-block-heading">Solution</h2>



<p>Create my own Ansible role that does what I want.</p>



<p>If you&#8217;re new to Ansible, check out my <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">Ansible Getting Started Guide</a>.</p>



<p>I want firewalld to behave in a certain way. Meaning if I have an application already running, and I want firewalld to start restricting access, I don&#8217;t want an outage on that application as soon as I start up the firewalld service on the server.</p>



<h2 class="wp-block-heading">Firewalld Limitations</h2>



<p>Firewalld does have some limitations. You should be aware of this before using it.<br>Anything firewalld is not aware of in the back-end (for example if using iptables), will be removed since firewalld wants to be the single source of truth for firewall rules.<br>This is why firewalld and Docker do not get along.<br>See details from: <a rel="noreferrer noopener" href="https://success.docker.com/article/why-am-i-having-network-problems-after-firewalld-is-restarted" target="_blank">here</a>, <a rel="noreferrer noopener" href="https://www.tripwire.com/state-of-security/devops/psa-beware-exposing-ports-docker/" target="_blank">here</a>, and <a rel="noreferrer noopener" href="https://docs.docker.com/network/iptables/" target="_blank">here</a>.</p>



<p>In case you missed that..<br><strong>Do not use firewalld and Docker.</strong><br><strong>Update</strong>: Instead, if you need a solution to work with Docker try using iptables directly. See my post about <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">securing Docker with iptables and Ansible</a>.</p>



<h2 class="wp-block-heading">Firewalld Ansible Role</h2>



<div class="wp-block-image"><figure class="alignright size-medium"><img loading="lazy" decoding="async" width="244" height="300" src="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-244x300.png" alt="Ansible manage firewalld" class="wp-image-1170" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo-244x300.png 244w, https://ryandaniels.ca/wp-content/uploads/2018/02/Ansible_logo.png 256w" sizes="auto, (max-width: 244px) 100vw, 244px" /></figure></div>



<p>You can find my <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-firewalld" target="_blank">firewalld Ansible Role on GitHub</a> or in <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/firewalld" target="_blank">Ansible Galaxy</a>.</p>



<p>This Ansible Role manages firewalld in offline and persistent mode only. I don&#8217;t want to mess around with non-persistent changes. And using online mode is not an option.</p>



<p>It uses the <a rel="noreferrer noopener" href="https://docs.ansible.com/ansible/latest/modules/firewalld_module.html" target="_blank">Ansible module for firewalld</a> for a few things, but most changes have to be done using the command module. Specifically: &#8220;firewall-offline-cmd&#8221;.</p>



<p>Why? What&#8217;s the benefit doing it this way? It let&#8217;s you create your own custom <a rel="noreferrer noopener" href="https://firewalld.org/documentation/service/" target="_blank">service</a> in firewalld. Even built-in firewalld services can be used, and easily modified. For example, moving the ssh port from 22 to something else. (Warning, be careful changing your SSH port. You could lock yourself out!)</p>



<p>Here&#8217;s a short example of the configuration:</p>



<pre class="wp-block-code"><code>rhel_firewalld_zone_source:
  - zone: internal
    state: enabled
    source:
      - "192.168.22.64/26"
      - "192.168.23.64/26"

rhel_firewalld_custom_service:
  - name: zabbix-agent
    zone: public
    state: enabled
    port_protocol:
    # - 10050/tcp
      - 3333/tcp
  - name: openvpn
    zone: public
    state: enabled
  - name: app123-public
    zone: public
    state: enabled
    description: app123 firewall rules for public zone
    port_protocol:
      - 5000/tcp
  - name: app123-internal
    zone: internal
    state: enabled
    description: app123 firewall rules for internal zone
    port_protocol:
      - 8080/tcp
      - 9000/tcp</code></pre>



<p>In the variable <code>rhel_firewalld_zone_source</code>:<br>This will configure the Zone named <code>internal</code> to only allow IP ranges that are in <code>source</code>.</p>



<p>In the variable <code>rhel_firewalld_custom_service</code>:<br>This will configure the <code>zabbix-agent</code> service (which is actually built-in) for the zone <code>public</code>, but not use the default port (of 10050, commented out for demonstration). Instead it&#8217;s using port 3333.<br>The <code>openvpn</code> service is added to the zone <code>public</code>, and will just use the default configuration (since this is also a built-in firewalld service). You need to know it&#8217;s built-in, if you don&#8217;t specify a port. So it&#8217;s usually better to just specify a port all the time!<br>Last, there are two custom services, <code>app123-public</code> and <code>app123-internal</code>, which are added to their defined zones. They are also adding port 5000 using tcp (attached to the public zone), and adding ports 8080 and 9000 both using tcp (attached to the internal zone).</p>



<p>If you decide you want to change a port, just remove it from the configuration.</p>



<p><a href="https://github.com/ryandaniels/ansible-role-firewalld" target="_blank" rel="noreferrer noopener">More details are on GitHub. Be sure to read the README!</a></p>



<h2 class="wp-block-heading">Getting Started &#8211; Ansible firewalld</h2>



<p>Install from Ansible Galaxy:</p>



<pre class="wp-block-code"><code>ansible-galaxy install ryandaniels.firewalld</code></pre>



<p>Or, clone the GitHub project:</p>



<pre class="wp-block-code"><code>git clone https://github.com/ryandaniels/ansible-role-firewalld.git roles/firewalld</code></pre>



<p>Create the Ansible Playbook, called firewalld.yml:</p>



<pre class="wp-block-preformatted">---
- hosts: '{{ inventory }}'
  become: yes
  vars:
    # Use this role
    rhel_firewalld_managed: true
  roles:
  - firewalld</pre>



<p>Make configuration changes add desired firewalld services and ports. </p>



<p><strong>Warning: Be sure you have everything needed in your configuration. Once firewalld is started it blocks anything that wasn&#8217;t added!</strong></p>



<p><strong>Disclaimer: Keep in mind, you should test all of this in your lab or staging environments. I can&#8217;t guarantee this will be 100% safe and can&#8217;t be held responsible for anything going wrong!</strong></p>



<p>Then run the playbook:</p>



<pre class="wp-block-code"><code>ansible-playbook firewalld.yml --extra-vars "inventory=centos7" -i hosts-dev</code></pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In conclusion, Ansible is now being used to manage firewalld rules! We have a custom firewalld service created using two different zones. The built-in firewalld services are also enabled, but we don&#8217;t really care they are built-in, since we can change the port they use if we want.<br>We have a nice and simple configuration, and this was all done in &#8220;offline&#8221; mode so there was no impact to any existing services using the ports.</p>



<p>Again, your mileage may vary. Always test in your lab or staging environment first! I&#8217;m not responsible for anything you break. </p>



<p>Stay safe!</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">Manage firewalld with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2180</post-id>	</item>
		<item>
		<title>5 Reasons Why You Should Upgrade Windows to Linux</title>
		<link>https://ryandaniels.ca/blog/5-reasons-windows-upgrade-to-linux/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 24 Dec 2019 03:27:34 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Linux Mint]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2042</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/no-windows-upgrade-to-linux/"></p>
<figure class="alignleft size-thumbnail"><img src="https://ryandaniels.ca/wp-content/uploads/2019/12/tux-254x300.png" alt="Tux" class="wp-image-2052"/></figure>
<p></a>It's time. Windows users, Upgrade to Linux. Windows 7 is reaching the end. You must upgrade. Do not replace Windows 7 with Windows 10. That is not an upgrade! Upgrade Windows to Linux Mint. It's so much better!<br />
&#160;<br />
&#160;</p>
<p>The post <a href="https://ryandaniels.ca/blog/5-reasons-windows-upgrade-to-linux/">5 Reasons Why You Should Upgrade Windows to Linux</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="alignright size-thumbnail"><img loading="lazy" decoding="async" width="254" height="300" src="https://ryandaniels.ca/wp-content/uploads/2019/12/tux-254x300.png" alt="Tux" class="wp-image-2052" srcset="https://ryandaniels.ca/wp-content/uploads/2019/12/tux-254x300.png 254w, https://ryandaniels.ca/wp-content/uploads/2019/12/tux-509x600.png 509w, https://ryandaniels.ca/wp-content/uploads/2019/12/tux-611x720.png 611w, https://ryandaniels.ca/wp-content/uploads/2019/12/tux-768x905.png 768w, https://ryandaniels.ca/wp-content/uploads/2019/12/tux.png 933w" sizes="auto, (max-width: 254px) 100vw, 254px" /></figure></div>



<p>It&#8217;s time. Windows users, Upgrade to Linux. Windows 7 is reaching the <a rel="noreferrer noopener" aria-label=" (opens in a new tab)" href="https://support.microsoft.com/en-us/help/4057281/windows-7-support-will-end-on-january-14-2020" target="_blank">end of the line</a> after January 14, 2020. Users must upgrade to something else. Do not replace Windows 7 with Windows 10. That is not an upgrade! How else can I say this? Do not downgrade from Windows 7 to Windows 10. Instead, upgrade Windows 7 to Linux!</p>



<p>In case you haven&#8217;t heard, do not use Windows 10, <a rel="noreferrer noopener" aria-label="for many reasons (opens in a new tab)" href="https://www.privacytools.io/operating-systems/#win10" target="_blank">for many reasons</a>. It&#8217;s a &#8220;Privacy Nightmare&#8221;!<br>Also, it&#8217;s actually really bad to use. They add junk into your Desktop menu at random. And it will come back even if you delete it. <br>Do you like ads? <a rel="noreferrer noopener" aria-label="Microsoft is infesting Windows 10 with annoying ads (opens in a new tab)" href="https://www.theverge.com/2017/3/17/14956540/microsoft-windows-10-ads-taskbar-file-explorer" target="_blank">Microsoft is infesting Windows 10 with annoying ads</a>. <br><strong>You are not in control</strong>.</p>



<p>And then there&#8217;s the many problems with Windows 10 updates. <a rel="noreferrer noopener" aria-label="So (opens in a new tab)" href="https://www.forbes.com/sites/gordonkelly/2019/04/17/microsoft-windows-10-problem-update-warning-upgrade-cost/" target="_blank">So</a> <a rel="noreferrer noopener" aria-label="many (opens in a new tab)" href="https://www.computerworld.com/article/3407712/microsoft-s-windows-update-system-is-broken-will-it-ever-be-fixed.html" target="_blank">many</a> <a rel="noreferrer noopener" aria-label="crazy (opens in a new tab)" href="https://www.techradar.com/news/microsoft-once-again-sends-out-the-wrong-windows-10-update-to-users" target="_blank">crazy</a> <a rel="noreferrer noopener" aria-label="problems (opens in a new tab)" href="https://www.bleepingcomputer.com/news/microsoft/windows-10-1909-kb4517245-update-causes-file-explorer-issues/" target="_blank">problems</a>! It&#8217;s just plain bad. <a rel="noreferrer noopener" aria-label="Did you know Windows 10 deleted user's personal data! (opens in a new tab)" href="https://www.forbes.com/sites/gordonkelly/2018/10/06/microsoft-windows-10-update-lost-data-upgrade-windows-7-windows-xp-free-upgrade/" target="_blank">Did you know Windows 10 deleted user&#8217;s personal data</a>! Also there are <a href="https://www.techradar.com/news/windows-10s-latest-troublesome-update-is-now-reportedly-causing-boot-failures" target="_blank" rel="noreferrer noopener" aria-label="problems with Windows 10 booting after updating (opens in a new tab)">problems with Windows 10 booting after updating</a>.</p>



<h2 class="wp-block-heading">Linux, Everybody&#8217;s doing it!</h2>



<p>There are <a rel="noreferrer noopener" aria-label="so (opens in a new tab)" href="https://www.forbes.com/sites/jasonevangelho/2018/07/23/5-reasons-you-should-switch-from-windows-to-linux-right-now/" target="_blank">so</a> <a rel="noreferrer noopener" aria-label="many (opens in a new tab)" href="https://www.lifewire.com/reasons-to-switch-to-linux-4583960" target="_blank">many</a> <a rel="noreferrer noopener" aria-label="reason (opens in a new tab)" href="https://www.forbes.com/sites/jasonevangelho/2019/03/29/shadowhammer-asus-1-million-reasons-switch-from-windows-to-linux/" target="_blank">reason</a> to upgrade to Linux. If all you do on your computer is use a web browser, occasionally open pictures, sometimes open a spreadsheet or text document then you should definitely upgrade to Linux.</p>



<p>Even if you are a power user, there&#8217;s probably a Linux application that will replace that Windows app. But, even if there isn&#8217;t, you can use software like <a rel="noreferrer noopener" aria-label="Wine (opens in a new tab)" href="https://www.winehq.org/" target="_blank">Wine</a> to run Windows apps on Linux!</p>



<p>Do you game? <a rel="noreferrer noopener" aria-label="Steam (opens in a new tab)" href="https://store.steampowered.com/linux" target="_blank">Steam</a> is an easy way to game on Linux! And it&#8217;s <a rel="noreferrer noopener" aria-label="easy to install (opens in a new tab)" href="https://itsfoss.com/install-steam-ubuntu-linux/" target="_blank">easy to install</a>.</p>



<p>And then there&#8217;s the Linux community. It is absolutely amazing. When you do have an issue, there is so much help available by just searching.</p>



<h2 class="wp-block-heading">Top 5 Reasons to switch to Linux</h2>



<ol class="wp-block-list"><li>Linux just works</li><li>Linux is more secure</li><li>Surprise, Linux is easy to upgrade</li><li>Linux works on old hardware</li><li>Linux is easy to customize</li><li>Bonus Reason: Amazing community for help</li></ol>



<h2 class="wp-block-heading">Which Linux Desktop to Choose?</h2>



<p>Linux on the Desktop has many distributions to choose from. There&#8217;s no single company to dictate what you can do!</p>



<p>With so many options to choose from, how do you pick? If it&#8217;s your first time using a Linux Desktop, try a distro that&#8217;s easy to get up and running. <br>&#8220;<a rel="noreferrer noopener" aria-label="Linux Mint (opens in a new tab)" href="https://linuxmint.com/" target="_blank">Linux Mint</a> Cinnamon Edition&#8221; is a great choice to get started!</p>



<p>Why? Linux Mint is based on Ubuntu which is very popular and easy to use. If you need help, you will be able to find an answer since Ubuntu is so popular. And Linux Mint uses a nice desktop environment by default, called Cinnamon.</p>



<figure class="wp-block-image size-medium is-style-default"><a href="https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon.png" rel="lightbox[2042]"><img loading="lazy" decoding="async" width="800" height="500" src="https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-800x500.png" alt="Linux Mint Cinnamon - No Windows Upgrade Linux" class="wp-image-2049" srcset="https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-800x500.png 800w, https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-1152x720.png 1152w, https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-300x188.png 300w, https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-768x480.png 768w, https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-1536x960.png 1536w, https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon-1200x750.png 1200w, https://ryandaniels.ca/wp-content/uploads/2019/12/linux_mint_cinnamon.png 1920w" sizes="auto, (max-width: 800px) 100vw, 800px" /></a><figcaption>Image Credit: Linux Mint</figcaption></figure>



<p>More screenshot can be found on the <a href="https://linuxmint.com/screenshots.php" target="_blank" rel="noreferrer noopener" aria-label="Linux Mint website (opens in a new tab)">Linux Mint website</a>.</p>



<p>Don&#8217;t want to use Linux Mint Cinnamon? Try Ubuntu instead. That&#8217;s what Linux Mint is based on after all! <a rel="noreferrer noopener" aria-label="Kubuntu (opens in a new tab)" href="https://kubuntu.org/getkubuntu/" target="_blank">Kubuntu</a> has a very nice desktop environment similar to Windows.</p>



<h2 class="wp-block-heading">How to Upgrade from Windows to Linux Mint</h2>



<h3 class="wp-block-heading">Test it out before Installing</h3>



<p>You can even try out Linux Mint before you install it to your hard drive. Actually most Linux distros can do this! Just download the ISO image and add it to a USB stick using <a rel="noreferrer noopener" aria-label="LinuxLive USB Creator (opens in a new tab)" href="https://www.linuxliveusb.com/" target="_blank">LinuxLive USB Creator</a>. Then reboot your computer and boot from the USB stick. Now you are test driving Linux Mint on your computer! Need a step by step guide? Check out their <a rel="noreferrer noopener" aria-label="documentation (opens in a new tab)" href="https://linuxmint-installation-guide.readthedocs.io/en/latest/install.html" target="_blank">documentation</a>.</p>



<h3 class="wp-block-heading">Backup Windows</h3>



<p>Before you install, be sure to backup your existing installation. A great tool for this is called <a rel="noreferrer noopener" aria-label="Macrium Reflect (opens in a new tab)" href="https://www.macrium.com/reflectfree" target="_blank">Macrium Reflect</a>. This can save an &#8220;image&#8221; of Windows to a file. Then later when running Linux Mint, you can start up your old Windows image as a virtual machine using <a rel="noreferrer noopener" aria-label="VirtualBox (opens in a new tab)" href="https://www.virtualbox.org/" target="_blank">VirtualBox</a>! </p>



<h2 class="wp-block-heading">Install Linux Mint</h2>



<p>There are many guides online if you do a search. One thorough guide can be found <a rel="noreferrer noopener" aria-label="here (opens in a new tab)" href="https://www.zdnet.com/article/how-to-replace-windows-7-with-linux-mint/" target="_blank">here</a>.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>After you have upgraded to Linux, you are now free from Windows! No more worrying. You are free to enjoy Linux and all it has to offer. Next maybe you want to customize a few things. Linux (and Linux Mint) make that so easy.</p>



<p>Goodbye Windows, Hello Linux Mint!</p>
<p>The post <a href="https://ryandaniels.ca/blog/5-reasons-windows-upgrade-to-linux/">5 Reasons Why You Should Upgrade Windows to Linux</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2042</post-id>	</item>
		<item>
		<title>Malicious code and abandoned websites</title>
		<link>https://ryandaniels.ca/blog/malicious-code-abandoned-websites/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sat, 27 Oct 2018 21:57:44 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Privacy]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1338</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/malicious-code-abandoned-websites/"><img src="https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js-150x146.png" alt="" width="150" height="146" class="alignleft size-thumbnail wp-image-1359" /></a> Malicious code and abandoned websites are increasingly becoming more of a problem. It's a serious issue in terms of privacy and security.<br />
TL;DR: Website owners: Be careful when using third-party code that you don't control.<br />
Users: Hope for the best! Use a content blocker browser add-on like uBlock Origin. On your mobile device use Firefox with uBlock Origin.</p>
<p>The post <a href="https://ryandaniels.ca/blog/malicious-code-abandoned-websites/">Malicious code and abandoned websites</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Malicious code and abandoned websites are increasingly becoming more of a problem. It&#8217;s a serious issue in terms of privacy and security.</p>
<p>TL;DR:<br />
<strong>Website owners</strong>: Be careful when using third-party code that you don&#8217;t control.<br />
<strong>Users</strong>: Hope for the best! Use a content blocker browser add-on like uBlock Origin. On your mobile device use Firefox with uBlock Origin.</p>
<p><span id="more-1338"></span></p>
<h2>What&#8217;s the problem?</h2>
<p>Abandoned or unmaintained websites can be re-registered by malicious people. Any website using third-party code could be a victim.</p>
<p>To highlight the issue, let&#8217;s look at a specific example. This example luckily wasn&#8217;t extremely malicious. It could have been much worse! But it still highlights the current state of the web.</p>
<p>Recently there was an issue where 800+ websites were using javascript from an abandoned free service called &#8220;New Share Counts&#8221; which counted the number of Twitter shares.</p>
<p>Image of malicious code:</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1359 size-full" src="https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js.png" alt="nsc.js malicious source code" width="897" height="146" srcset="https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js.png 897w, https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js-300x49.png 300w, https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js-768x125.png 768w" sizes="auto, (max-width: 897px) 100vw, 897px" /></p>
<p><a href="https://blog.sucuri.net/2018/10/malicious-redirects-from-newsharecounts-com-tweet-counter.html" target="_blank" rel="noopener noreferrer">Securi</a> and <a href="https://www.bleepingcomputer.com/news/security/abandoned-tweet-counter-hijacked-with-malicious-script/" target="_blank" rel="noopener noreferrer">BleepingComputer</a> have great write-ups on the details.</p>
<p>The problem is this third party website stopped offering their free service. They notified users via their website and eventually the resources they used for counting Tweets were abandoned. This included the Amazon S3 bucket they used. Unfortunately many website owners didn&#8217;t get the notice, or ignored it.</p>
<p>Image of a website including the malicious code in their source code:</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1360 size-full" src="https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js.png" alt="website including malicious code nsc.js" width="877" height="192" srcset="https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js.png 877w, https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js-300x66.png 300w, https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js-768x168.png 768w" sizes="auto, (max-width: 877px) 100vw, 877px" /></p>
<p>According the research from BleepingComputer, on October 3rd the AWS S3 bucket was cancelled and on October 4th a &#8220;bad actor&#8221; registered a new AWS S3 bucket under the same name. Up until October 23rd, all 800+ websites that didn&#8217;t remove this javascript file were serving all of their visitors with a malicious script which redirected mobile users to a scam website.</p>
<p><strong>As of October 23, 2018: </strong>the malicious javascript (newsharecounts.s3-us-west-2.amazonaws.com/nsc.js) has been blocked on the AWS S3 bucket. It is returning the error: Access Denied</p>
<p><strong>Update October 28, 2018</strong>: AWS will not confirm the S3 bucket was banned on their side. The malicious code could return at any time, and possibly be worse next time. According to AWS they need other people to alert them if the malicious content re-appears! From AWS: &#8220;<strong>Should you see the content return or similar appear, please report it immediately.</strong>&#8221;</p>
<p><strong>Update October 31, 2018</strong>: Malicious javascript is back online.</p>
<p><strong>Update November 9, 2018</strong>: From AWS: &#8220;Content in question is not currently accessible&#8221;.</p>
<p><strong>Update January 9, 2019</strong>: Malicious javascript is back online, again.</p>
<p><strong>Update January 14, 2019</strong>: From AWS: &#8220;We have again blocked the content.&#8221;</p>
<h2>Who can fix this?</h2>
<ul>
<li>Individual website(s) that include the third-party malicious code</li>
<li>Hosting provider where the malicious code resides</li>
<li>Web browser blocks malicious code</li>
<li>Web browser add-on blocks malicious code</li>
<li>You and me? Social media? News outlets?</li>
</ul>
<p>Unfortunately it&#8217;s hard to get all 800+ websites to fix this on their sites. So ultimately we need the company hosting the malicious content to step in.</p>
<p>It seems having this issue in the news and social media definitely helps put pressure on those who can take the malicious content down. In this case it was an Amazon S3 bucket hosting the malicious javascript.</p>
<p>But why is this so hard? Just take down the malicious code!</p>
<h3>What about the hosting provider?</h3>
<p>In this case, I submitted an abuse report to AWS the night of October 15th. It was only after Securi and BleepingComputer published news articles on October 16th/17th and some <a href="https://twitter.com/BleepinComputer/status/1052454195444555776" target="_blank" rel="noopener noreferrer">pressure on social media</a> did AWS acknowledge the issue (to me at least). Then it took AWS over a week to take the resource down*. And that was only after countless back and forth emails with them. Thankfully, at least for now, the malicious javascript has been removed.</p>
<p>At first they said this malicious script didn&#8217;t violate their terms of service! I had to read through their terms of service (TOS) and provided them with exact details of how this malicious script actually does violate their TOS.<br />
Such a painful process!</p>
<ul>
<li>At the time of publishing this post, AWS has <strong>not</strong> confirmed they took the malicious script down due to a violation of the terms of service. So hopefully this malicious script won&#8217;t come back online in the future at the same location!</li>
</ul>
<h3>A browser add-on can also help</h3>
<p>I had a feeling it was going to take the hosting provider a while to respond, since these things take time. As a work-around, a browser add-on to the rescue!<br />
uBlock Origin added this malicious javascript to their content filtering add-on <a href="https://github.com/uBlockOrigin/uAssets/issues/3730" target="_blank" rel="noopener noreferrer"><strong>25 minutes</strong> after I opened an issue with them</a>! Now that&#8217;s fast! So at least anyone using this popular browser add-on would be protected (well that is if they use Firefox on their mobile device, which actually isn&#8217;t the dominant browser).</p>
<h3>What about the browser itself?</h3>
<p>The most recent version of Firefox 63 now has <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Privacy/Storage_access_policy#Tracking_protection_explained">Tracking Protection</a>. But this can only block entire domains and not specific files. So that can&#8217;t help in this case.<br />
Directly in the Chrome browser? Not currently an option either.</p>
<h3>You and me? Social media? News outlets?</h3>
<p>Unfortunately that seems to be what it&#8217;s come to. More on that below.</p>
<p>Luckily this example wasn&#8217;t worse. The malicious code only redirected a mobile user to a scam website when they pressed their back button on one of the <a href="https://publicwww.com/websites/%22newsharecounts.s3-us-west-2.amazonaws.com%2Fnsc.js%22/" target="_blank" rel="noopener noreferrer">800 affected websites</a>. It could have been cryptocurrency mining malware, or code to exploit some bug in Android or iOS. Who knows, maybe the hosting provider would respond much faster if it was more serious? Or the website owners? Maybe.. Maybe not.</p>
<h2>Solution for users</h2>
<p>Unfortunately web users have little control over what a website is serving their browser. One thing that can help is using a content filter add-on for your browser like <a href="https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/" target="_blank" rel="noopener noreferrer">uBlock Origin for Firefox</a> or for <a href="https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm?hl=en" target="_blank" rel="noopener noreferrer">Chrome</a>. In the above case the malicious code was only affecting mobile users. Only Firefox supports add-ons for their mobile browser. This is another reason to use Firefox on your mobile devices! In a related post, check out how easy it is to <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/">upgrade your privacy using Firefox</a>.</p>
<h2>Long term solution for website owners</h2>
<p>Website owners need to be careful when adding third-party code to their websites. However, this is extremely difficult in today&#8217;s modern web. Often websites use many, many different third-party services.</p>
<p>One solution is to host all third party code locally on your web server. Unfortunately, this has it&#8217;s own issues since there would no longer updates to the code by the developer unless the website owner manually updates their site.</p>
<p>Another solution is to use <a href="https://en.wikipedia.org/wiki/Subresource_Integrity" target="_blank" rel="noopener noreferrer">Subresource Integrity (SRI)</a>. Unfortunately this can be tedious to implement for a website owner. And even worse, if you use a CMS like WordPress, you rely on the plugin developer to implement SRI into their plugin or theme. There is a WordPress plugin called <a href="https://wordpress.org/plugins/wp-sri/" target="_blank" rel="noopener noreferrer">(SRI) Manager</a> which can help add SRI to all plugins, but your mileage may vary with getting it to work.</p>
<h2>Conclusion &#8211; Who <span style="text-decoration: underline;">should</span> fix this?</h2>
<p>Who can fix this versus who should fix this is a good question. In my opinion, this should be the responsibility of the individual website. However, getting 800+ websites to fix this in a timely manner.. not going to happen (and it didn&#8217;t in this example!). As of the time of this post, most websites still include a link to the malicious code on their sites! Thankfully now it does nothing since it no longer exists.<br />
It really needs to be easier for website owners to have secure third-party code on their website, otherwise we continue down this path.</p>
<h3>Who needs to drive this change?</h3>
<p>Specifically in the above example of &#8220;New Share Counts,&#8221; was it only a concerned internet user (myself) that made this happen?<br />
Probably not, since it was in the news. That&#8217;s probably the only reason there was any traction. But regardless, I contacted an infected website (which I randomly found while surfing the net. Mind you, only one website of 800+), initiated an abuse case with the hosting provider (AWS) where the malicious code was, and lastly, initiated a support ticket for a work-around using a popular browser add-on.</p>
<p>Maybe other people also contacted the hosting provider. Maybe I should have contacted more content filtering browser add-ons? More pressure on social media? Or something else in addition?</p>
<p>Maybe more people need to take action against these issues after they happen.</p>
<p>The next question is, who should be driving this overall change to make it easier to secure third-party code on websites? That&#8217;s also a great question..</p>
<p>However, until that&#8217;s figured out we need individuals and news outlets to raise these issues when they happen.<br />
For instance, open abuse reports with the hosting provider, try to inform the websites impacted, find work-arounds when it&#8217;s taking too long. Raise awareness on social media platforms.</p>
<p>Currently, that&#8217;s all we can do. That is, if the issue is even <strong>detected</strong> in the first place.</p>
<p>&nbsp;</p>
<h2>Timeline</h2>
<p>For anyone interested, here&#8217;s a timeline of events for the &#8220;New Share Counts&#8221; issue from what  I observed. This isn&#8217;t meant to single out the hosting provider (AWS) in particular, they are probably flooded with abuse reports. But still, their generic responses are pretty funny. <strong>Bold</strong> used for emphasis.</p>
<p>2018/10/14 23:13 EST &#8211; Randomly found issue on one specific website (Latest Hacking News) while surfing the net on my couch (on my phone) and informed them about malicious javascript on their site.<br />
<a href="https://i.imgur.com/4E6uSx5.png" target="_blank" rel="noopener noreferrer" rel="lightbox[1338]">https://i.imgur.com/4E6uSx5.png</a></p>
<p>2018/10/15 17:19 EST &#8211; Emailed &#8220;Latest Hacking News&#8221; with more details. Including script where the malicious javascript is located.</p>
<p>2018/10/15 17:47 EST &#8211; Abuse report submitted to the hosting provider (AWS). ( where malicious javascript is hosted: newsharecounts.s3-us-west-2.amazonaws.com/nsc.js ). Gave details on what this malicious javascript is doing and how to reproduce malicious behaviour.</p>
<p>2018/10/15 17:55 EST &#8211; Response from hosting provider: Generic response asking for logs.</p>
<p>2018/10/15 18:04 EST &#8211; Replied to hosting provider: Gave info where they can find a site infected with the malicious javascript. Also, exact steps to reproduce malicious behaviour.</p>
<p>2018/10/16 06:56 EST &#8211; <a href="https://blog.sucuri.net/2018/10/malicious-redirects-from-newsharecounts-com-tweet-counter.html" target="_blank" rel="noopener noreferrer">Securi publishes article about malicious redirects from newsharecount</a>.</p>
<p>2018/10/16 11:06 EST &#8211; &#8220;Latest Hacking News&#8221; removed the malicious javascript from their website.</p>
<p>2018/10/17 03:00 EST &#8211; <a href="https://www.bleepingcomputer.com/news/security/abandoned-tweet-counter-hijacked-with-malicious-script/" target="_blank" rel="noopener noreferrer">BleepingComputer publishes article</a>.</p>
<p>2018/10/17 18:22 EST &#8211; Replied to hosting provider via email: No response from hosting provider (AWS) since 15th. Asked for abuse case to be expedited and if they can shutdown this AWS S3 bucket / javascript file. Also mentioned to AWS this was now in the news via Securi and BleepingComputer.</p>
<p>2018/10/17 18:33 EST &#8211; <a href="https://twitter.com/BleepinComputer/status/1052454195444555776" target="_blank" rel="noopener noreferrer">Reply to BleepingComputer&#8217;s tweet</a>, including AWS twitter handle to highlight lack of response from AWS.</p>
<p>2018/10/17 18:39 EST &#8211; Hosting provider responded via email: &#8220;This case has been investigated and being resolved by the appropriate team.&#8221;</p>
<p>2018/10/17 19:15 EST &#8211; Submitted issue with uBlock Origin (browser add-on to filter content) via their <a href="https://github.com/uBlockOrigin/uAssets/issues/3730" target="_blank" rel="noopener noreferrer">Github issue tracker</a>.</p>
<p>2018/10/17 19:40 EST &#8211; <a href="https://github.com/uBlockOrigin/uAssets/commit/c126e1e6a05072c53d5ab8836c160dc1a7b56fdb" target="_blank" rel="noopener noreferrer">uBlock Origin now blocks this malicious code</a>. Only took 25 minutes! Anyone using the uBlock Origin browser addon (on mobile device) will not be affected by the malicious javascript.</p>
<p>2018/10/18 03:48 EST &#8211; <a href="https://twitter.com/AWSSupport/status/1052828747618033664" target="_blank" rel="noopener noreferrer">Hosting provider responds via twitter</a> that they are investigating.</p>
<p>2018/10/18 04:46 EST &#8211; &#8220;Latest Hacking News&#8221; <a href="https://twitter.com/7H3Wh173R4bb17/status/1052843254121713665" target="_blank" rel="noopener noreferrer">responded</a> via twitter, with thanks for finding the malicious javascript on their website.</p>
<p>2018/10/19 09:41 EST &#8211; Hosting provider responded via email:<br />
&#8220;We understand your concern regarding the continued availability of the content you have reported. As noted previously, AWS customers are responsible for their activity on AWS. As a courtesy we notified our customer of your request to have the content removed or access disabled, however, as we do not consider this content to be in violation of our terms, we are not able to take additional action. We strongly encourage you to continue to work with our customer directly to address the concerns that you may have.&#8221;</p>
<p>2018/10/19 10:12 EST &#8211; Replied to hosting provider via email:<br />
&#8220;It&#8217;s unfortunate that this bad actor&#8217;s malicious script/bucket can&#8217;t be removed since it is clearly hijacking users mobile browsers to serve them ads/malware/malicious script. I suspect that notifying the current AWS customer which owns this bucket will have no result, since they are responsible for this malicious script in the first place.&#8221;</p>
<p>2018/10/19 10:29 EST &#8211; Hosting provider responded, via email, stating the same thing again and the case was closed:<br />
&#8220;As noted previously, AWS customers are responsible for their activity on AWS. <strong>As a courtesy we notified our customer of your request to have the content removed or access disabled, however, as we do not consider this content to be in violation of our terms, we are not able to take additional action. We strongly encourage you to continue to work with our customer directly to address the concerns that you may have. This case has been resolved by the appropriate team.</strong>&#8221;</p>
<p>2018/10/19 18:26 EST &#8211; Replied to hosting provider via email. I read through all of their Terms of Service and found where this malicious javascript violated their terms in two places. Provided details about how this malicious javascript was breaking their TOS in those two places.</p>
<p>2018/10/19 19:08 EST &#8211; Hosting provider responded via email:<br />
&#8220;Thank you for your reply. We are looking into this issue further and passed it on to our customer.&#8221;</p>
<p>2018/10/23 16:30 EST &#8211; &#8220;Abandoned Tweet Counter Hijacked With Malicious Script&#8221; Podcast from <a href="https://www.grc.com/securitynow.htm" target="_blank" rel="noopener noreferrer">Security Now!</a> about this issue. <a href="https://www.grc.com/sn/sn-686-notes.pdf" target="_blank" rel="noopener noreferrer">Episode #686</a> Audio &amp; <a href="https://twit.tv/shows/security-now/episodes/686?autostart=false" target="_blank" rel="noopener noreferrer">Video</a>.</p>
<p>2018/10/23 19:45 EST &#8211; Noticed http://newsharecounts.s3-us-west-2.amazonaws.com/nsc.js is down. Returning error: &#8220;Access Denied&#8221;.</p>
<p>2018/10/23 19:48 EST &#8211; <a href="https://twitter.com/ryan_daniels/status/1054882214889078785" target="_blank" rel="noopener noreferrer">Replied to hosting provider via twitter</a>: Asking hosting provider to confirm they took down the javascript due to violation of their terms.</p>
<p>2018/10/25 16:53 EST &#8211; Replied to hosting provider via email:<br />
&#8220;Can you confirm this S3 bucket is now suspended and can&#8217;t be used again?&#8221;</p>
<p>2018/10/27 &#8211; No response from the hosting provider at time of this post.</p>
<p>2018/10/28 09:19 EST &#8211; Hosting provider responded, via email:<br />
&#8220;<strong>At this time the content appears to be no longer active or available. If you have any evidence otherwise, please let us know.</strong>&#8221;</p>
<p>2018/10/28 09:27 EST &#8211; Replied to hosting provider via email, asking for confirmation the S3 bucket is suspended and if not, to do so.</p>
<p>2018/10/28 09:39 EST &#8211; Hosting provider responded, via email. Due to privacy policies they cannot discuss what actions have been taken, and:<br />
&#8220;<strong>Should you see the content return or similar appear, please report it immediately.</strong>&#8221;</p>
<p>2018/10/31 17:42 EST &#8211; Replied to hosting provider via email. Malicious content is back online.</p>
<p>2018/11/06 11:05 EST &#8211; Hosting provider responded via email.<br />
&#8220;We have begun our investigation into the source of the activity or content you reported.&#8221;</p>
<p>2018/11/09 04:28 EST &#8211; Hosting provider responded via email.<br />
&#8220;Content in question is not currently accessible.. If you believe this content is still live, please provide additional evidence and we will be sure to investigate further. At this time please consider this case as resolved.&#8221;</p>
<p>2019/01/09 05:42 EST &#8211; Emailed hosting provider. Malicious content is live, again.</p>
<p>2019/01/14 08:55 EST &#8211; Hosting provider responded via email.<br />
&#8220;Thank you for advising us that the content has been uploaded again. We have again blocked the content.&#8221;</p>
<p>The post <a href="https://ryandaniels.ca/blog/malicious-code-abandoned-websites/">Malicious code and abandoned websites</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1338</post-id>	</item>
		<item>
		<title>User Management with Ansible</title>
		<link>https://ryandaniels.ca/blog/ansible-user-management/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 13:03:28 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1251</guid>

					<description><![CDATA[<p>Ansible is a great tool to automate all the things. Another task it can help to automate is user management.  This guide will be talking specifically about user management on Linux servers like Red Hat Enterprise Linux (RHEL), CentOS, or Ubuntu. Ansible can handle this task!</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-user-management/">User Management with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Ansible is a great tool to automate all the things. Another task it can help to automate is user management.  This guide will be talking specifically about user management on Linux servers like Red Hat Enterprise Linux (RHEL), CentOS, or Ubuntu.</p>
<p><span id="more-1251"></span></p>
<h2>What&#8217;s the problem?</h2>
<p>If you have multiple servers to manage, it can be a pain to manually add a new user, change a password, or lock an old account. Manually logging into all of your servers and performing these tasks is a real pain, and a huge waste of time.</p>
<p>Luckily there are several solutions.</p>
<h2>Solution: Red Hat IDM</h2>
<p>There are many different solutions for user management. <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/linux_domain_identity_authentication_and_policy_guide/index" target="_blank" rel="noopener noreferrer">Red Hat Identity Management</a> (IDM) is a very good solution that works with many Linux servers. IDM is a central location that holds all the user configuration. And it can even connect to Windows Active Directory.</p>
<p>However, if you don&#8217;t have a subscription to Red Hat Enterprise Linux there are other options.</p>
<h2>Solution: FreeIPA</h2>
<p><a href="https://www.freeipa.org/page/About" target="_blank" rel="noopener noreferrer">FreeIPA</a> is the upstream open source project for Red Hat Identify Management. So you can download the FreeIPA package and follow one of many available tutorials for setting up a <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-centralized-linux-authentication-with-freeipa-on-centos-7" target="_blank" rel="noopener noreferrer">server</a> and <a href="https://www.digitalocean.com/community/tutorials/how-to-configure-a-freeipa-client-on-centos-7" target="_blank" rel="noopener noreferrer">client</a>.</p>
<h2>Solution: Ansible for user management</h2>
<p>If the above solutions seem too complicated there&#8217;s another option. However, you should really take some time to setup user management properly. Use FreeIPA. It&#8217;s free!</p>
<p>But, if you want to use another solution while you are setting up FreeIPA, and you already have Ansible as part of your environment then you have another option. Ansible can do this of course!</p>
<p>The reason Ansible is a decent option for user management is because it is idempotent. This means, Ansible will only make a change if the change is needed to get to the desired state. So you can run the same Ansible Playbook multiple times, and if the Ansible tasks are written properly Ansible will only make a change the first time.</p>
<p>Just keep in mind, I warned you to use FreeIPA. This solution is not &#8220;enterprise&#8221; grade. But it certainly works for certain scenarios, like in a lab environment. And if you want to use Ansible for something new, there is a user management <a href="https://github.com/ryandaniels/ansible-role-create-users" target="_blank" rel="noopener noreferrer">role available on GitHub</a> or on <a href="https://galaxy.ansible.com/ryandaniels/create_users" target="_blank" rel="noopener noreferrer">Ansible Galaxy</a>.</p>
<p>If you aren&#8217;t familiar with Ansible, check out my <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">Getting Started with Ansible guide</a>.</p>
<p>This Ansible role is tested on:</p>
<ul>
<li>Ubuntu</li>
<li>Red Hat Enterprise Linux (RHEL) 7.x, 6.5, 5.9</li>
<li>CentOS 7.x, 6.5, 5.9</li>
</ul>
<h3>What this user management Ansible role does</h3>
<p><a href="https://github.com/ryandaniels/ansible-role-create-users" target="_blank" rel="noopener noreferrer">This role</a> will manage users in the user list configuration file (list is in the file vars/lab_users.secret in the example below).<br />
It can add users, change passwords, lock/unlock user accounts, manage sudo access (per user), add ssh key(s) for ssh key based authentication.<br />
This is done on a per &#8220;group&#8221; basis (using Ansible group variables), as set in the configuration file. The group comes from the Ansible group as set for a server in the inventory file.</p>
<p>Note: Deleting users is not done on purpose.</p>
<p>The great thing about Ansible Playbooks, if you don&#8217;t like something it&#8217;s easy enough to modify.</p>
<h3>Install the Ansible user management role</h3>
<p>First let&#8217;s install the Ansible role to manage users into your Ansible control server:</p>
<pre><code>$ su - ansible
$ cd ~/ansible
$ git clone https://github.com/ryandaniels/ansible-role-create-users.git roles/create-users</code></pre>
<p>Or, you can use Ansible Galaxy to install this role:</p>
<pre><code>$ su - ansible
$ ansible-galaxy install ryandaniels.create_users</code></pre>
<h3>Setup Ansible Vault</h3>
<p>If you don&#8217;t already have <a href="https://docs.ansible.com/ansible/latest/vault.html" target="_blank" rel="noopener noreferrer">Ansible Vault</a> configured, you will need to set it up now. Vault uses AES encryption to store your sensitive information. And we need Ansible Vault to encrypt our user configuration file since we don&#8217;t want to be exposing even a hashed password into source control.</p>
<p>First, (if using git), make sure to update your .gitignore file so your Vault password isn&#8217;t saved to your source control. And also add the secret file we will be creating later:</p>
<pre><code>$ vi .gitignore
.vaultpass
secret
*.secret</code></pre>
<p>Next, create a password for your Ansible Vault and save it in your Password Manager (like <a href="https://keepassxc.org/" target="_blank" rel="noopener noreferrer">KeePassXC</a>). Then create the .vaultpass file, add the Vault password, and fix the permissions:</p>
<pre><code>$ vi .vaultpass
#Enter password here

$ chmod 600 .vaultpass</code></pre>
<p>Also you need to update the Ansible config file to reference where the Vault file is located:</p>
<pre><code>$ vi ansible.cfg
[defaults]
vault_password_file = ./.vaultpass
</code></pre>
<h3>Create Ansible Playbook</h3>
<p>Next, create the Playbook file:</p>
<pre><code>$ vi create-users.yml
---
- hosts: '{{inventory}}'
  vars_files:
    - vars/lab_users.secret
  become: yes
  roles:
  - create-users</code></pre>
<h3>Create configuration for user management</h3>
<p>Next, add your users into a configuration file. The below is only an example, don&#8217;t use it in your user management configuration file. Also, make sure the filename matches a .gitignore entry. In this case it will match &#8220;*.secret&#8221;.<br />
Use the special Ansible command to create the encrypted Ansible Vault file:</p>
<pre><code>$ mkdir -p vars
$ ansible-vault create vars/lab_users.secret
---
users:
  - username: alice
    password: $6$/y5RGZnFaD3f$96xVdOAnldEtSxivDY02h.DwPTrJgGQl8/MTRRrFAwKTYbFymeKH/1Rxd3k.RQfpgebM6amLK3xAaycybdc.60
    update_password: on_create
    comment: Test User 100
    shell: /bin/bash
    ssh_key: |
      ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8crAHG/a9QBD4zO0ZHIjdRXy+ySKviXVCMIJ3/NMIAAzDyIsPKToUJmIApHHHF1/hBllqzBSkPEMwgFbXjyqTeVPHF8V0iq41n0kgbulJG alice@laptop
      ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8crAHG/a9QBD4zO0ZHIjdRXy+ySKviXVCMIxxxxxxxxxxxxxxxxxxJmIApHHHF1/hBllqzBSkPEMwgFbXjyqTeVPHF8V0iq41n0kgbulJG alice@server1
    exclusive_ssh_key: yes
    use_sudo: no
    use_sudo_nopass: no
    user_state: present
    servers:
      - webserver
      - database
      - monitoring

  - username: bob
    password: $6$XEnyI5UYSw$Rlc6tXtECtqdJ3uFitrbBlec1/8Fx2obfgFST419ntJqaX8sfPQ9xR7vj7dGhQsfX8zcSX3tumzR7/vwlIH6p/
    ssh_key: AAAAB3NzaC1yc2EAAAADAQABAAACAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8crAHG/a9QBD4zO0ZHIjdRXy+ySKviXVCMIxxxxxxxxxxxxxxxxxxJmIApHHHF1/hBllqbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbulJG bob@laptop
    use_sudo: no
    user_state: lock
    servers:
      - webserver
      - database</code></pre>
<p>In the above example, there are two users. Users: alice and bob. If you are familiar with user management on Linux, then most of these settings are self explanatory. For example, both Alice and Bob have a hashed password and ssh keys. Alice actually has two ssh keys configured. But Bob&#8217;s account is locked so he can&#8217;t log in.</p>
<p>The interesting part is the list of &#8220;servers&#8221; in the configuration. These are groups defined in your Ansible hosts file. So you can give certain users access to a specific group of servers, depending on the user&#8217;s role.</p>
<p>Important note: Be careful with the <code>update_password</code> setting. When set to <code>always</code>, the user&#8217;s password will be changed to what is defined in <code>password</code>. This might not be what they wanted if they&#8217;ve manually changed their password so it&#8217;s usually safer to use <code>on_create</code>.</p>
<p>For details about all the different settings, see the <a href="https://github.com/ryandaniels/ansible-role-create-users/blob/master/README.md#user-settings" target="_blank" rel="noopener noreferrer">README</a> on GitHub.</p>
<p>Going forward, to update the file, instead of the &#8220;create&#8221; command line option, use &#8220;edit&#8221;:</p>
<pre><code>$ ansible-vault edit vars/lab_users.secret</code></pre>
<p>And don&#8217;t forget to save this into your source control (git).</p>
<h3>Run the Ansible Playbook</h3>
<pre><code>$ ansible-playbook create-users.yml --extra-vars "inventory=all-dev" -i hosts-dev</code></pre>
<p>Marvel at the output generated by Ansible. All these users are created, updated, or locked, but only if something needed to change since Ansible is idempotent.</p>
<h3>Bonus: Add this in Jenkins</h3>
<p>If you also use Jenkins for your CI/CD pipeline, you can add this Ansible Playbook into Jenkins.</p>
<p>You just need to setup Jenkins to use Ansible and Ansible Vault. And there is a great Jenkins Plugin to help. Just follow this guide to use <a href="https://ryandaniels.ca/blog/ansible-vault-jenkins/">Ansible Vault with Jenkins</a>. Keep in mind that updating the user configuration file is only possible from the command line, since it&#8217;s encrypted using Ansible Vault.</p>
<h2>Conclusion</h2>
<p>In conclusion, there are many options for user management on Linux servers. From enterprise solutions like Red Hat IDM. Or, using the upstream open source software IDM uses directly, FreeIPA. If you decide to use Ansible, then the above Ansible role will get the job done. And you can also add it into Jenkins.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-user-management/">User Management with Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1251</post-id>	</item>
		<item>
		<title>Ansible Vault with Jenkins</title>
		<link>https://ryandaniels.ca/blog/ansible-vault-jenkins/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 13 Feb 2018 13:26:59 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Security]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1253</guid>

					<description><![CDATA[<p>Ansible can use encrypted files, using a feature called Ansible Vault. This is great for sensitive information that you don't want to store as a normal text file since you are able to encrypt this data in your souce control.</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-vault-jenkins/">Ansible Vault with Jenkins</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Ansible can use encrypted files, using a feature called Ansible Vault. This is great for sensitive information that you don&#8217;t want to store as a normal text file since you are able to encrypt this data in your source control.</p>
<p><span id="more-1253"></span></p>
<p>If you are new to Ansible, read the <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/" target="_blank" rel="noopener noreferrer">getting started with Ansible</a> post first.</p>
<h2>Why use Ansible Vault?</h2>
<p>You want to use Ansible Vault when you need to use sensitive data with Ansible, like a login and password, or SSH keys. Instead of storing this sensitive information in plain text, where anyone can read it when you save your <a href="http://docs.ansible.com/ansible/latest/playbooks_vault.html" target="_blank" rel="noopener noreferrer">Ansible Playbooks</a> to your source control (like git), Vault uses an AES cypher to encrypt your data.</p>
<p>For more details, read the <a href="http://docs.ansible.com/ansible/latest/vault.html" target="_blank" rel="noopener noreferrer">documentation</a>.</p>
<h2>Ansible Vault with Jenkins</h2>
<p><a href="https://jenkins.io/" target="_blank" rel="noopener noreferrer">Jenkins</a> is software for Continuous Integration and Continuous Delivery. You can add plugins to Jenkins to extend its base features. And one handy plugin allows you to use Ansible with Jenkins.</p>
<p>Recently, the Ansible Plugin for Jenkins was updated to version 0.8.0, and as a result it now works seamlessly with Ansible Vault.</p>
<h2>Install Ansible plugins for Jenkins</h2>
<p>The first thing you need to install is the <a href="https://plugins.jenkins.io/ansible" target="_blank" rel="noopener noreferrer">Ansible plugin</a> for Jenkins.<br />
Also, install the dependent plugin called <a href="https://plugins.jenkins.io/credentials-binding" target="_blank" rel="noopener noreferrer">Credentials Binding</a>.</p>
<p>One thing to note is you can only read from encrypted Ansible Vault encrypted files. You cannot create or modify them using the Jenkins Ansible plugin. So you will still need to use the CLI to modify your encrypted files.</p>
<h2>Add Vault password to Jenkins</h2>
<p>The simplest way to use Ansible Vault with Jenkins is to add your Vault password into a Jenkins Credential. Then you can bind the credential to an environment variable, or use it directly as a &#8220;Vault Credential&#8221;.</p>
<p>Configure your Jenkins freestyle project that uses an Ansible Playbook. If you have the newest version of the Ansible plugin, under the &#8220;Build&#8221; section you will now see an option for &#8220;Vault Credentials&#8221; since this is a new feature.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1280" src="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials.png" alt="ansible vault jenkins credentials" width="643" height="289" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials.png 643w, https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials-300x135.png 300w" sizes="auto, (max-width: 643px) 100vw, 643px" /></p>
<p>Add a new Jenkins Credential as &#8220;Secret text&#8221;, and enter your Ansible Vault encryption password.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1281" src="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials_new.png" alt="ansible vault jenkins new credentials" width="515" height="428" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials_new.png 515w, https://ryandaniels.ca/wp-content/uploads/2018/02/ansible_vault_jenkins_credentials_new-300x249.png 300w" sizes="auto, (max-width: 515px) 100vw, 515px" /></p>
<p>Next, select the new Vault Credentials and you are ready to use your encrypted files in your Jenkins build job from your Ansible Playbooks.</p>
<h2>Conclusion</h2>
<p>In conclusion, you are now using Ansible Vault encrypted files automatically inside of your Jenkins build jobs. This helps you to keep your sensitive data secured in your source control. And Jenkins is helping you to deploy your Ansible Playbooks, while seamlessly decrypting your files.</p>
<p>Next, you can add a job to Jenkins that requires Ansible Vault. If you want to use Ansible for user management on Linux servers, check out the guide for <a href="https://ryandaniels.ca/blog/ansible-user-management/">User Management with Ansible</a>.</p>
<p>&nbsp;</p>
<p>The post <a href="https://ryandaniels.ca/blog/ansible-vault-jenkins/">Ansible Vault with Jenkins</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1253</post-id>	</item>
		<item>
		<title>Upgrade SSH keys and use gpg-agent with Ed25519 keys</title>
		<link>https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 11 Feb 2018 16:30:46 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1245</guid>

					<description><![CDATA[<p>SSH keys are convenient and more secure than using a password to authenticate. If you created your SSH key a while ago, it's probably time to generate new RSA 4096 and Ed25519 keys. SSH keys like DSA and RSA 1024 are very old and now insecure. You should even upgrade ssh keys that are RSA 2048.</p>
<p>The post <a href="https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/">Upgrade SSH keys and use gpg-agent with Ed25519 keys</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SSH keys are very convenient and more secure than using only a password to authenticate. If you created your SSH key a while ago, it&#8217;s probably time to generate new keys. SSH keys like DSA and RSA 1024 are very old and now insecure. You should even upgrade ssh keys that are RSA 2048. But really, it&#8217;s time to start using RSA 4096 for legacy servers, and Ed25519 for servers with modern ssh key support.</p>
<p><span id="more-1245"></span></p>
<p>The below commands are based on the post <a href="https://blog.g3rt.nl/upgrade-your-ssh-keys.html" target="_blank" rel="noopener noreferrer">Upgrade your SSH keys.</a> Check that out for more details.</p>
<h2>Identify and rename old ssh keys</h2>
<p>First, identify your old ssh keys:</p>
<pre>$ cd ~/.ssh
$ for sshkey in $(ls *.pub);do echo $sshkey;ssh-keygen -lf $sshkey;done
/home/ryan/.ssh/id_rsa.pub
2048 SHA256:gIDkzI98pEna3j9+2Ja5di0+k2dCaXtCtx6k71dskA1 ryan@home (RSA)</pre>
<p>From the output, this is showing it is an RSA 2048 key.</p>
<p>Next rename your old public and private ssh keys:</p>
<pre>$ mv id_rsa.pub id_rsa_legacy.pub
$ mv id_rsa id_rsa_legacy</pre>
<h2>Stop using insecure keys</h2>
<p>Use only keys that are greater than RSA 2048, or Ed25519.<br />
Specifically, remove:</p>
<ul>
<li>DSA</li>
<li>RSA 1024 and 2048</li>
<li>ECDSA</li>
</ul>
<p>Just be sure you aren&#8217;t using these ssh keys. Only remove them when you no longer need them and have the new keys setup and working.</p>
<h2>Create or Change your existing password</h2>
<p>If you old RSA ssh key didn&#8217;t use a password, now is the time to set a password. You can upgrade ssh keys that previously existed and didn&#8217;t use a password, without breaking anything. Also adding 100 rounds helps make your old key more secure when at rest if you need to continue using it.</p>
<pre>$ ssh-keygen -f ~/.ssh/id_rsa_legacy -p -o -a 100</pre>
<h2>Upgrade ssh keys &#8211; Generate RSA 4096 ssh keys</h2>
<p>RSA 4096 is good to use for legacy systems which do not yet support the new Ed25519 key.</p>
<p>Generate the RSA 4096 keys, and make sure to use a strong password:</p>
<pre>$ ssh-keygen -t rsa -b 4096 -o -a 100
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ryan/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ryan/.ssh/id_rsa.
Your public key has been saved in /home/ryan/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:732MQCPPaMS815Y7MFXl4n2WXuawR1Zsat+PEG1TnPA ryan@home
The key's randomart image is:
+---[RSA 4096]----+
|         +. o+.oo|
|        o * .+*..|
|         B oo=Eo.|
|          =o=..oo|
|        S .BoBo+=|
|         .  *.Ooo|
|          .  B =.|
|        .   B * .|
|          .... . |
+----[SHA256]-----+</pre>
<p>The &#8220;<code>-o -a 100</code>&#8221; means it is harder to crack the private key&#8217;s password using brute-force attacks. If your legacy system doesn&#8217;t support this, remove this option.</p>
<h2>Upgrade ssh keys &#8211; Generate Ed25519 ssh keys</h2>
<p><a href="https://en.wikipedia.org/wiki/EdDSA#Ed25519" target="_blank" rel="noopener noreferrer">Ed25519</a> ssh keys work on modern systems (OpenSSH 6.7+) and are much shorter than RSA keys. Note, the &#8220;<code>-o -a 100</code>&#8221; option is implied with Ed25519 key generation.<br />
Generate your new Ed25519 key and use a strong password:</p>
<pre>$ ssh-keygen -t ed25519
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ryan/.ssh/id_ed25519.
Your public key has been saved in /home/ryan/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:oU44/TftLl2/d4IKQla36Z1TMqrcdK1xBcerye78fxM ryan@home
The key's randomart image is:
+--[ED25519 256]--+
|        . .      |
|     . . . . .   |
|    . o .   o o .|
|   .   + . o o = |
|    . + S * + +  |
|     = . = B  .E |
|      + B.=.oo ..|
|       =.=o.o ..=|
|      ..oo=+o..+=|
+----[SHA256]-----+</pre>
<p>Now you have both RSA 4096 and Ed25519 ssh keys ready to go.</p>
<p>Next, add the keys to your ssh agent so it will remember the keys for you.</p>
<h2>Install and configure ssh agent</h2>
<p>Using an ssh agent allows you to type in a password once, and then the agent remembers the ssh keys.</p>
<p>On Ubuntu 16.04 there is one problem though. The built-in Gnome-keyring doesn&#8217;t support Ed25519. To work-around this, you could use the normal ssh-agent. But, I suggest instead to use gpg-agent and disable the gnome-keyring.</p>
<p>The below commands are based on the <a href="https://wiki.archlinux.org/index.php/GnuPG#SSH_agent" target="_blank" rel="noopener noreferrer">Arch wiki</a> and an answer from the <a href="https://askubuntu.com/questions/732581/gpg-agent-and-ssh-no-keys/930105#930105" target="_blank" rel="noopener noreferrer">Ask Ubuntu Forum</a>.</p>
<p>Disable Gnome ssh keyring daemon (<a href="https://wiki.archlinux.org/index.php/GNOME/Keyring#Disable_keyring_daemon_components" target="_blank" rel="noopener noreferrer">reference</a>):</p>
<pre>$ cp -rp /etc/xdg/autostart/gnome-keyring-ssh.desktop ~/.config/autostart
$ echo "Hidden=true" &gt;&gt; ~/.config/autostart/gnome-keyring-ssh.desktop</pre>
<p>Install gpg-agent:</p>
<pre>$ sudo apt-get install gpa gnupg-curl</pre>
<p>Enable ssh support in gpg-agent, and set a timeout to remember the key and password for 1 hour, since this adds some convenience:</p>
<pre>$ echo "enable-ssh-support" &gt;&gt; ~/.gnupg/gpg-agent.conf
$ echo "default-cache-ttl-ssh 3600" &gt;&gt; ~/.gnupg/gpg-agent.conf
$ echo "max-cache-ttl-ssh 3600" &gt;&gt; ~/.gnupg/gpg-agent.conf</pre>
<p>Edit your .bashrc to automatically load gpg-agent when you log in.</p>
<pre>$ vi ~/.bashrc
# Set SSH to use gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="~/.gnupg/S.gpg-agent.ssh"
fi</pre>
<p>Reload gpg-agent:</p>
<pre>$ gpg-connect-agent reloadagent /bye</pre>
<p>Next, add your new ssh keys to the gpg-agent:</p>
<pre>$ ssh-add ~/.ssh/id_ed25519 ~/.ssh/id_rsa ~/.ssh/id_rsa_legacy</pre>
<p>You will be prompted to enter your ssh key password. And after you enter that, another prompt will pop-up, from the gpg-agent. It will be used to unlock the gpg-agent&#8217;s key storage. This should be a different password than the password for your ssh keys. You will be prompted to enter this password every time you log in, or after the 1 hour timeout.</p>
<p>Enter the password that you want to use to unlock the gpg-agent key storage. And if you use the same password here for all your ssh keys, you only have to unlock it once:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1270" src="https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt.png" alt="gpg-agent password prompt upgrade ssh keys" width="477" height="277" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt.png 477w, https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt-300x174.png 300w" sizes="auto, (max-width: 477px) 100vw, 477px" /></p>
<p>And now you can list your keys stored in the gpg-agent:</p>
<pre>$ ssh-add -l -E md5 # list fingerprint using md5 hash
$ ssh-add -l        # list fingerprint using sha256 hash
$ ssh-add -L        # list public key parameters</pre>
<h2>Re-deploy the new public keys</h2>
<p>Lastly, you need to add your new public keys to your servers. This command will ssh to your server and add your new public keys to the authorized_keys file.<br />
Change <code>1.2.3.4</code> to your server&#8217;s IP:</p>
<pre>$ ssh 1.2.3.4 "mkdir -p .ssh;echo $(cat ~/.ssh/id_ed25519.pub) &gt;&gt; .ssh/authorized_keys;echo $(cat ~/.ssh/id_rsa.pub) &gt;&gt; .ssh/authorized_keys;chmod 700 .ssh;chmod 640 .ssh/authorized_keys"</pre>
<p>Be sure to do this for ever server you connect to.</p>
<p><strong>Important</strong>: Be sure you <strong>don&#8217;t lock yourself out</strong> of your servers. Have another session open and test to make sure you can log in again after making this change.</p>
<p>Now you can remove your old ssh key from the ssh agent and only use the secure ssh keys:</p>
<pre>$ ssh-add -d 2&gt;/dev/null;ssh-add ~/.ssh/id_ed25519;ssh-add ~/.ssh/id_rsa</pre>
<p>Be sure to add the Ed25519 key first, like above. Since it seems to be a feature that prioritizes RSA keys first. So add the Ed25519 key first.</p>
<p>SSH to your servers to test the new key is working. You can also see in the logs the type of ssh key being used.</p>
<p>Confirm using the new Ed25519 ssh key, on Ubuntu 16.04:</p>
<pre>$ grep " sshd\[" /var/log/auth.log|grep "Accepted publickey"|tail
Feb 11 10:00:00 home sshd[1802]: Accepted publickey for ryan from 192.168.1.100 port 60708 ssh2: ED25519 SHA256:oU44/TftLl2/d4IKQla36Z1TMqrcdK1xBcerye78fxM</pre>
<h2>Conclusion</h2>
<p>Now you have more secure ssh keys since you are using Ed25519 and RSA 4096 keys. You have been able to upgrade ssh keys that are insecure! Next, you should look into updating your ssh server and client settings to use better encryption settings, using <a href="https://stribika.github.io/2015/01/04/secure-secure-shell.html" target="_blank" rel="noopener noreferrer">these</a> <a href="https://wiki.mozilla.org/Security/Guidelines/OpenSSH" target="_blank" rel="noopener noreferrer">references</a>.</p>
<p>And if you don&#8217;t want to manually deploy the new ssh keys to all of your servers, instead you can use <a href="https://ryandaniels.ca/blog/ansible-user-management/">Ansible for user management</a>.</p>
<p>The post <a href="https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/">Upgrade SSH keys and use gpg-agent with Ed25519 keys</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1245</post-id>	</item>
		<item>
		<title>How to setup OpenVPN with ad blocking on Raspberry Pi or a VPS</title>
		<link>https://ryandaniels.ca/blog/openvpn-ad-blocking/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 04 Feb 2018 14:18:33 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1117</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/"><img src="https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload-300x144.jpg" alt="Ad Overload happens.. Is Ad Blocking possible in NYC?" width="300" height="144" class="alignleft size-medium wp-image-1174" /></a> Using a VPN can help to protect your privacy. You can use a VPN to appear like you are in another country to reach a website that was previously blocked, to stop your ISP from restricting you to certain websites, and when travelling to protect your data while using insecure WiFi. There's another: ad blocking.</p>
<p>The post <a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/">How to setup OpenVPN with ad blocking on Raspberry Pi or a VPS</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1174" src="https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload.jpg" alt="Ad Overload happens.. Is Ad Blocking possible in NYC?" width="800" height="383" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload.jpg 800w, https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload-300x144.jpg 300w, https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload-768x368.jpg 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /></p>
<p>Using a VPN (Virtual Private Network) can help to protect your privacy. You can use a VPN to appear like you are in another country so you can reach a website that was previously blocked. You can also use a VPN to stop your ISP from restricting you to certain websites, and when travelling to protect your data while using insecure WiFi. There are many many more reason. However, there can be an extra benefit to using a VPN that people don&#8217;t usually think about: Automatic content blocking (also known as ad blocking).</p>
<p><span id="more-1117"></span></p>
<h2>Why?</h2>
<p>Ad <a href="https://en.wikipedia.org/wiki/Ad_blocking" target="_blank" rel="noopener noreferrer">blocking</a> is now a necessity because of dangerous ads. Some ad networks have had problems with ads containing malicious JavaScript which is actually malware. Even recently <a href="https://arstechnica.com/information-technology/2018/01/now-even-youtube-serves-ads-with-cpu-draining-cryptocurrency-miners/" target="_blank" rel="noopener noreferrer">YouTube was showing ads that contained a cryptocurrency miner</a>. An add-on like <a href="https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/" target="_blank" rel="noopener noreferrer">uBlock Origin for Firefox</a> or <a href="https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm?hl=en" target="_blank" rel="noopener noreferrer">Chrome</a> can help. And customizing your <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/">Firefox privacy settings</a> will also help. But what if apps on your phone are showing dangerous ads? Or, what if you have an old phone that&#8217;s no longer getting updates and you want better protection from the recent Meltdown vulnerability? A browser add-on alone will not help you.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1179" src="https://ryandaniels.ca/wp-content/uploads/2018/02/openvpn.png" alt="OpenVPN with ad blocking" width="208" height="54" /></p>
<p>Now, combine the benefits of a VPN, and ad blocking into one solution. This is where OpenVPN with ad blocking using dnsmasq comes in. For this to work you need control of the OpenVPN server configuration. So using a VPN provider is not an option. But, this way is cheaper! Plus you get the satisfaction of setting up your own VPN!</p>
<h2>Setup a Raspberry Pi with OpenVPN</h2>
<p>You can create your own VPN with a <a href="https://www.raspberrypi.org/products/" target="_blank" rel="noopener noreferrer">Raspberry Pi</a>. If you live in Canada, a good way to get started is with the <a href="http://amzn.to/2FI0IuW" target="_blank" rel="nofollow noopener noreferrer">Raspberry Pi 3 CanaKit</a>. There are many <a href="https://github.com/pivpn/pivpn" target="_blank" rel="noopener noreferrer">guides</a> for setting up a Raspberry Pi with OpenVPN.</p>
<p>However, this method won&#8217;t help if a website restricts your country, or if your ISP blocks you from certain content, since you will have the Raspberry Pi at home. But, you can still use this method to protect you when using open WiFi while travelling, or when at home to get the benefit of ad blocking on your mobile devices.</p>
<h2>Setup a VPS with OpenVPN</h2>
<p>If using a Raspberry Pi isn&#8217;t your thing, you can buy an inexpensive VPS (Virtual Private Server) and host your VPN from there. This may seem like more work, but it&#8217;s pretty easy. And with a VPS you don&#8217;t need to worry about exposing your home network to the public internet. Also, when using a VPS that is only for OpenVPN, you can use common ports to have a better chance of being able to connect to your VPN.</p>
<p><a href="https://ryandaniels.ca/go/linode/" target="_blank" rel="nofollow noopener noreferrer">Linode</a> is a great VPS provider for $5 per month. Or, <a href="https://ryandaniels.ca/go/vultr/" target="_blank" rel="nofollow noopener noreferrer">Vultr</a> offers a VPS for $2.50 per month! (For IPv6 only, IPv4 is $3.50). Whichever VPS provider you choose, make sure to create your VPS in a country that&#8217;s right for you. For example, if you need to access a website usually only available to a certain country. Also make sure you obey their TOS.  I&#8217;m not responsible for anything you do from following this guide!</p>
<p>When using your own VPS, I suggest setting it up with OpenVPN using the <a href="https://github.com/StreisandEffect/streisand" target="_blank" rel="noopener noreferrer">Streisand</a> project. It has many options to bypass blocking if you live in an oppressive country. Note that the commands below will only install OpenVPN (with stunnel) if using Streisand. Plus, Streisand does a good job at protecting your VPS with security tweaks and automatically updating packages.</p>
<h2>Install OpenVPN</h2>
<p>You can install OpenVPN many different ways. Here are two ways I recommend:</p>
<p>To install OpenVPN via PiVPN, follow these <a href="https://github.com/pivpn/pivpn#installation" target="_blank" rel="noopener noreferrer">steps</a>.</p>
<p>To install (only) OpenVPN (also with stunnel) via Streisand, follow the <a href="https://github.com/StreisandEffect/streisand#prerequisites" target="_blank" rel="noopener noreferrer">prerequisites</a> steps, and then run:</p>
<pre><code>$ remote_server_IP=1.2.3.4  # Change IP to your VPS/remote server IP
$ git clone https://github.com/ryandaniels/ansible-role-dnsmasq-adblock.git ~/ansible/roles/dnsmasq-adblock
$ git clone https://github.com/StreisandEffect/streisand.git &amp;&amp; cd streisand
$ ~/streisand/deploy/streisand-existing-cloud-server.sh --ip-address $remote_server_IP --ssh-user username123 --site-config ~/ansible/roles/dnsmasq-adblock/files/streisand-local-site.yml</code></pre>
<p>Change &#8220;remote_server_IP&#8221; to your server&#8217;s IP.<br />
This will use the user &#8220;username123&#8221; with ssh keys for a <a href="https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/" target="_blank" rel="noopener noreferrer">passwordless ssh connection</a>. Be sure to use a use that you&#8217;ve setup with ssh keys.</p>
<h2>Setup ad blocking for OpenVPN using dnsmasq</h2>
<p>Now that you have OpenVPN setup on a RaspberryPi or your own VPS you are ready for the last step, ad blocking. For this you can use a program called dnsmasq. It performs DNS lookups and you can modify the dnsmasq behaviour to block certain domains.</p>
<h3>Manually install and configure dnsmasq on Ubuntu</h3>
<p>These steps were modified from <a href="https://github.com/BobNisco/adblocking-vpn" target="_blank" rel="noopener noreferrer">this github project by Bob Nisco</a> and also uses <a href="https://github.com/StevenBlack/hosts" target="_blank" rel="noopener noreferrer">Steve Black&#8217;s host project</a>.</p>
<p>Install and configure dnsmasq using the DNS servers from OpenDNS:</p>
<pre><code>$ sudo apt-get -y install dnsmasq
$ sudo wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -O /etc/hosts_blocked

$ sudo cat &gt; /etc/dnsmasq.conf &lt;&lt; 'EOF'
domain-needed
bogus-priv
no-resolv
server=208.67.222.222
server=208.67.220.220
listen-address=127.0.0.1
listen-address=10.8.0.1
addn-hosts=/etc/hosts_blocked
EOF</code></pre>
<p>Configure OpenVPN:</p>
<pre><code>$ sudo vi /etc/openvpn/server.conf</code></pre>
<p>Add below, and make sure no other lines have &#8220;dhcp-option DNS&#8221;:</p>
<pre><code>push "dhcp-option DNS 10.8.0.1"</code></pre>
<p>Create a script to update the domains being blocked. And have it run every week:</p>
<pre><code>$ sudo cat &gt; /etc/cron.weekly/adblock_dl_hosts &lt;&lt; 'EOF'
#!/bin/bash
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -O /etc/hosts_blocked &amp;&amp; systemctl restart dnsmasq.service
EOF

$ sudo chmod +x /etc/cron.weekly/adblock_dl_hosts</code></pre>
<p>Restart dnsmasq and OpenVPN:</p>
<pre><code>$ sudo systemctl restart dnsmasq.service 
$ sudo systemctl restart openvpn.service</code></pre>
<h3>Using Ansible to automatically install and configure dnsmasq on Ubuntu</h3>
<p>If you are familiar with Ansible, then you can add a new role to handle the installation and configuration of dnsmasq for ad blocking automatically. If you are not familiar with Ansible but want to know more, check out my post explaining <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">what is Ansible</a>.</p>
<p>I&#8217;ve created this <a href="https://github.com/ryandaniels/ansible-role-dnsmasq-adblock" target="_blank" rel="noopener noreferrer">Ansible role</a> to configure dnsmasq on Ubuntu or Raspbian.</p>
<p>Create the Ansible Playbook:</p>
<pre><code>$ cat &gt; ~/ansible/install-dnsmasq-adblock.yml &lt;&lt; 'EOF'
---
- hosts: '{{inventory}}'
  become: yes
  roles:
  - dnsmasq-adblock
EOF</code></pre>
<p>If using PiVPN or a normal OpenVPN installation (and not Streisand), clone the git repository and run the Ansible Playbook:</p>
<pre><code>$ git clone https://github.com/ryandaniels/ansible-role-dnsmasq-adblock.git ~/ansible/roles/dnsmasq-adblock
$ ansible-playbook install-dnsmasq-adblock.yml --extra-vars "inventory=openvpn-server" -i hosts</code></pre>
<p>If you are using Streisand, then you already cloned the git repositories. Just run the Ansible Playbook:</p>
<pre><code>$ ansible-playbook install-dnsmasq-adblock.yml --extra-vars "inventory=streisand-host adblock_manage_openvpn=false" -i ~/streisand/inventories/inventory-existing</code></pre>
<h2>Conclusion</h2>
<p>In conclusion, now you are more secure by using OpenVPN with ad blocking on your own Raspberry Pi or VPS. And if you are using your own VPS you can use the Streisand project to secure your installation and also to expose common ports to have a higher chance of being able to connect to your VPN from anywhere.</p>
<p>The post <a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/">How to setup OpenVPN with ad blocking on Raspberry Pi or a VPS</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1117</post-id>	</item>
	</channel>
</rss>
