<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/on-watering-holes-trust-defensible-systems-and-data-science-community-security/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2017/02/23/on-watering-holes-trust-defensible-systems-and-data-science-community-security/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I’ve been threatening to do a series on “data science community security” for a while and had cause to issue this inaugural post today. It all started with this:</p>
<blockquote data-lang="en" class="twitter-tweet"><p dir="ltr" lang="en">Hey <a target="_blank" rel="nofollow" href="https://twitter.com/hashtag/rstats?src=hash">#rstats</a> folks: don't do this. Srsly. Don't do this. Pls. Will blog why. Just don't do this. <a target="_blank" rel="nofollow" href="https://t.co/qkem5ruEBi">https://t.co/qkem5ruEBi</a></p>
<p>— boB Rudis (<a target="_blank" rel="nofollow" href="http://twitter.com/hrbrmstr">@hrbrmstr</a>) <a target="_blank" rel="nofollow" href="https://twitter.com/hrbrmstr/status/834772651579150336">February 23, 2017</a></p></blockquote>
<p></p>
<p>Let me begin with the following: <a target="_blank" rel="nofollow" href="http://twitter.com/henrikbengtsson">@henrikbengtsson</a> is an <strong>awesome member</strong> of the #rstats community. He makes great things and I trust his code and intentions. This post is not about him, it’s about raising awareness regarding security in the data science community.</p>
<p>I can totally see why folks would like Henrik’s tool. Package dependency management — including installing packages — is not the most beloved of R tasks, especially for new R users or those who prefer performing their respective science or statistical work vs delve deep into the innards of R. The suggestion to use:</p>
<pre><code>source('http://callr.org/install#knitr')</code></pre>
<p>no doubt came from a realization of how cumbersome it can be to deal with said dependency management. You can even ostensibly see what the script does since Henrik provides <a target="_blank" rel="nofollow" href="http://callr.org/install">a link to it</a> right on the page.</p>
<p>So, why the call to not use it?</p>
<p>For starters, if you do want to use this approach, grab his script and make a local copy of it. Read it. Try to grok what it does. Then, use it locally. It will likely be a time-/effort-saver for many R users.</p>
<p>My call was to not source it from the internet. </p>
<p>Why? To answer that I need to talk about trust.</p>
<h3>hrbrmstr’s Hierarchy of Package Trust</h3>
<p>When you install a package on your system you’re bringing someone else’s code into your personal work space. When you try to use said code with a <code>library()</code> call, R has a few mechanisms to run code on package startup. So, when you just install and load a package you’re executing real code in the context of your local user. Some of that code may be interpreted R code. Some may be calling compiled code. Some of it may be trying to execute binaries (apps) that are already on your system.</p>
<p>Stop and think about that for a second. </p>
<p>If you saw a USB stick outside your office with a label <strong>“Cool/Useful R Package”</strong> would you insert it into your system and install the package? (Please tell me you answered “No!” <img alt="🙂" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f642.png"></p>
<p>With that in mind, I have a personal “HieraRchy of Package Trust” that I try to stick by:</p>
<p><img alt="" class="wp-image-5098" src="https://i0.wp.com/rud.is/b/wp-content/uploads/2017/02/hieRarchy.png?resize=713%2C615&ssl=1" data-recalc-dims="1"> </p>
<h4>Tier 1</h4>
<p>This should be a pretty obvious one, but if it’s my own code/server or my org’s code/server there’s inherent trust.</p>
<h4>Tier 2</h4>
<p>When you type <code>install.pacakges()</code> and rely on a known CRAN mirror, MRAN server or Bioconductor download using <code>https</code> you’re getting quite a bit in the exchange.</p>
<p>CRAN GuaRdians at least took some time to review the package. They won’t catch every possible potentially malicious bit and the efficacy of evaluating statistical outcomes is also left to the package user. What you’re getting — at least from the main <code>cran.r-project.org</code> repo and RStudio’s repos — are reviewed packages served from decently secured systems run by organizations with good intentions. Your trust in other mirror servers is up to you but there are no guarantees of security on them. I’ve evaluated the main CRAN and RStudio setups (remotely) and am comfortable with them <strong>but</strong> I also use my own personal, internal CRAN mirror for many reasons, including security. </p>
<p>Revolution-cum-Microsoft MRAN is also pretty trustworthy, especially since Microsoft has quite a bit to lose if there are security issues there.</p>
<p>Bioconductor also has solid package management practices in place, but I don’t use that ecosystem much (at all, really) so can’t speak too much more about it except that I’m comfortable enough with it to put it with the others at that level.</p>
<h4>Tier 3</h4>
<p>If I’m part of a known R cabal in private collaboration, I also trust it, but it’s still raw source and I have to scan through code to ensure the efficacy of it, so it’s a bit further down the list.</p>
<h4>Tier 4</h4>
<p>If I know the contributors to a public source repo, I’ll also consider trusting it, but I will still need to read through the source and doubly-so if there is compiled code involved.</p>
<h4>Tiers 5 &amp; 6</h4>
<p>If the repo source is a new/out-of-the-blue contributor to the R community or hosted personally, it will be relegated to the “check back later” task list and definitely not installed without a thorough reading of the source.</p>
<h4>NOTE</h4>
<p>There are caveats to the list above — like CRAN R packages that download pre-compiled Windows libraries from GitHub — that I’ll go into in other posts, along with a demonstration of the perils of trust that I hope doesn’t get Hadley too upset (you’ll see why in said future post <img alt="😀" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f600.png">).</p>
<p>Also note that there is no place on said hierarchy for the random USB stick of cool/useful R code. #justdontdoit</p>
<h3>Watering Holes</h3>
<p>The places where folks come together to collaborate have a colloquial security name: a “watering hole”. Attackers use these known places to perform — you guessed it — “watering hole” attacks. They figure out where you go, who/what you trust and use that to do bad things. I personally don’t know of any current source-code attacks, but data scientists <a target="_blank" rel="nofollow" href="https://www.bleepingcomputer.com/news/security/cyber-espionage-group-uses-microphones-and-dropbox-to-spy-on-ukrainian-targets/">are being targeted</a> in other ways by attackers. If attackers sense there is a source code soft-spot it will only be a matter of time before they begin to use that vector for attack. The next section mentions one possible attacker that you’re likely not thinking of as an “attacker”.</p>
<p>This isn’t <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Fear,_uncertainty_and_doubt">FUD</a>. </p>
<p>Governments, competitors and criminals know that the keys to the 21st century economy (for a while, anyway) reside in data and with those who can gather, analyze and derive insight from data. Not all of us have to worry about this, but many of us do and you should not dismiss the value of the work you’re doing, especially if you’re not performing open research. Imagine if a tiny bit of data exfiltration code managed to get on your Spark cluster or even your own laptop. This can easily happen with a tampered package (remember the incident a few years ago with usage tracking code in R scripts?).</p>
<h3>A Bit More On https</h3>
<p>I glossed over the <code>https</code> bit above, but by downloading a package over SSL/TLS you’re ensuring that the bits of code aren’t modified in transit from the server to your system and what you’re downloading is also not shown to prying eyes. That’s important since you really want to be sure you’re getting what you think your getting (i.e. no bits are changed) and you may be working in areas your oppressive, authoritarian government doesn’t approve of, such as protecting the environment or tracking global climate change (<img alt="🍊" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f34a.png">).</p>
<p>The use of <code>https</code> also does show — at least in a limited sense — that the maintainers of the server knew enough to actually setup SSL/TLS and thought — at least for a minute or two — about security. The crazy move to “Let’s Encrypt” everything is a topic for another, non-R post, but you can use that service to get free certificates for your own sites with a pretty easy installation mechanism.</p>
<p>I re-mention SSL/TLS as a segue back to the original topic…</p>
<h3>Back to the topic at hand</h3>
<p>So, what’s so bad about:</p>
<pre><code>source('http://callr.org/install#knitr')</code></pre>
<p>On preview: nothing. Henrik’s a good dude and you can ostensibly see what that script is doing.</p>
<p>On review: <em>much</em>.</p>
<p>I won’t go into a great deal of detail, but that server is running a RHEL 5 server with 15 internet services enabled, ranging from FTP to mail to web serving along with two database servers (both older versions) directly exposed to the internet. The default serving mode is <code>http</code> and the SSL certificate it does have is not trusted by any common certificate store. </p>
<p>None of that was found by any super-elite security mechanism. </p>
<p>Point your various clients at those services on that system and you’ll get a response. To put it bluntly, that system is 100% vulnerable to attack. (How to setup a defensible system is a topic for another post.).</p>
<p>In other words, if said mechanism becomes a popular “watering hole” for easy installation of R packages, it’s also a pretty easy target for attackers to take surreptitious control of and then inject whatever they want, along with keeping track of what’s being installed, by whom and from which internet locale.</p>
<p>Plain <code>base::source()</code> does nothing on your end to validate the integrity of that script. It’s like using <code>devtools::source()</code> or <code>devtools::source_gist()</code> without the <code>sha1</code> parameter (which uses a hash to validate the integrity of what you’re sourcing). Plus, it seems you cannot do:</p>
<pre><code>devtools::source_url('http://callr.org/install#knitr', sha1=&quot;2c1c7fe56ea5b5127f0e709db9169691cc50544a&quot;)</code></pre>
<p>since the <code>httr</code> call that lies beneath appears to be stripping away the <code>#…</code> bits. So, there’s no way to run this remotely with any level of integrity or confidentiality.</p>
<h4>TLDR</h4>
<p>If you like this script (it’s pretty handy) put it in a local directory and source it from there.</p>
<h3>Fin</h3>
<p>I can’t promise a frequency for “security in the data science community” posts but will endeavor to crank out a few more before summer. Note also that R is not the only ecosystem with these issues, so Python, Julia, node.js and other communities should not get smug <img alt="🙂" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f642.png"></p>
<p>Our pursuit of open, collaborative work has left us vulnerable to bad intentioned ne’er-do-wells and it’s important to at least be aware of the vulnerabilities in our processes, workflows and practices. I’m not saying you have to be wary of every <code>devtools::instal_github()</code> that you do, but you are now armed with information that might help you think twice about how often you trust calls to do such things.</p>
<p>In the meantime, download <a target="_blank" rel="nofollow" href="http://twitter.com/henrikbengtsson">@henrikbengtsson</a>’s script, thank him for making a very useful tool and run it locally (provided you’re cool with potentially installing things from non-CRAN repos <img alt="🙂" class="wp-smiley" src="https://s.w.org/images/core/emoji/2/72x72/1f642.png"></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rud.is/b/2017/02/23/on-watering-holes-trust-defensible-systems-and-data-science-community-security/"> R – rud.is</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/InXgYzFm6Nw"></a></div>