<?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/"
	>

<channel>
	<title>NPM &#8211; MeghRaj TechnoSoft &#8211; Web, App, E-commerce Development  Agency In India.</title>
	<atom:link href="https://www.meghrajtechnosoft.com/npm/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.meghrajtechnosoft.com</link>
	<description></description>
	<lastBuildDate>Mon, 07 Dec 2020 10:10:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.15</generator>

<image>
	<url>https://www.meghrajtechnosoft.com/wp-content/uploads/2020/10/fevecon.png</url>
	<title>NPM &#8211; MeghRaj TechnoSoft &#8211; Web, App, E-commerce Development  Agency In India.</title>
	<link>https://www.meghrajtechnosoft.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What does unsafe-perm in npm actually do?</title>
		<link>https://www.meghrajtechnosoft.com/what-does-unsafe-perm-in-npm-actually-do/</link>
					<comments>https://www.meghrajtechnosoft.com/what-does-unsafe-perm-in-npm-actually-do/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 07 Dec 2020 08:20:04 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Node.JS]]></category>
		<category><![CDATA[NPM]]></category>
		<guid isPermaLink="false">https://www.meghrajtechnosoft.com/?p=17487</guid>

					<description><![CDATA[<p>I’ve routinely been directed to what feels like a magic fix to issues when installing items over NPM. The issue that I’ve most recently encountered occurs in two different OS’s; Windows and Elementary. When attempting to install&#160;Sindre Sorhus’ Pure ZSH [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/what-does-unsafe-perm-in-npm-actually-do/">What does unsafe-perm in npm actually do?</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I’ve routinely been directed to what feels like a magic fix to issues when installing items over NPM. The issue that I’ve most recently encountered occurs in two different OS’s; Windows and Elementary. When attempting to install&nbsp;<a href="https://github.com/sindresorhus/pure" target="_blank" rel="noreferrer noopener">Sindre Sorhus’ Pure ZSH theme</a>&nbsp;both in Ubuntu WSL and Elementary Loki, I have issues with not having permissions.</p>



<p>The solution seems to be almost the same in both cases.</p>



<pre><code>npm config set unsafe-perm true</code></pre>



<p>What exactly is this doing? Is it ‘unsafe’?</p>



<p>Let’s start with&nbsp;<a href="https://duckduckgo.com/?q=npm+config+set+unsafe-perm+true&amp;t=canonical&amp;ia=qa" target="_blank" rel="noreferrer noopener">a search</a>. So there is a config setting allowed in the&nbsp;<code>package.json</code>&nbsp;that actually can set this per package. But wait,&nbsp;<a href="https://docs.npmjs.com/misc/config" target="_blank" rel="noreferrer noopener">it’s always true unless using root</a>. I never run as&nbsp;<code>root</code>, or with&nbsp;<code>sudo</code>&nbsp;privileges unless I am forced to. Let’s take a look through the&nbsp;<a href="https://github.com/npm/cli" target="_blank" rel="noreferrer noopener">source code</a></p>



<blockquote class="wp-block-quote"><p>Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.</p></blockquote>



<blockquote class="wp-block-quote"><p>If npm was invoked with root privileges, then it will change the uid to the user account or uid specified by the user config, which defaults to nobody. Set the unsafe-perm flag to run scripts with root privileges.</p></blockquote>



<pre><code>function loadUid(cb) {
  // if we're not in unsafe-perm mode, then figure out who
  // to run stuff as.  Do this first, to support `npm update npm -g`
  if (!this.get('unsafe-perm')) {
    getUid(this.get('user'), this.get('group'), cb);
  } else {
    process.nextTick(cb);
  }
}</code></pre>



<p>In other words, if we set&nbsp;<code>unsafe-perm</code>&nbsp;to always true, we will stop getting the user and the group the command was ran as and we will over-load the defaults.</p>



<pre><code>'unsafe-perm': process.platform === 'win32' ||
                     process.platform === 'cygwin' ||
                     !(process.getuid &amp;&amp; process.setuid &amp;&amp;
                       process.getgid &amp;&amp; process.setgid) ||
process.getuid() !== 0,</code></pre>



<p>It’s starting to make a bit more sense. This issue that I’m facing is that the permissions my current user has are unable to create the symlinks that are being asked by the program. By setting&nbsp;<code>unsafe-perm</code>&nbsp;to&nbsp;<code>true</code>&nbsp;will force&nbsp;<code>NPM</code>&nbsp;to attempt to always run within the context of the running script.</p>



<p>I suppose that this isn’t ‘unsafe’ but it does force the package installer to never drop into user and group switching when installing apps. It’s possible then you may end up having the code run as ‘root’ when installing (which could then be considered ‘unsafe’);</p>



<p>This goes all the way back to&nbsp;<a href="https://github.com/npm/cli/commit/021750a5bf0c1024916c0a497763cb2d2da78e46" target="_blank" rel="noreferrer noopener">February 7th, 2011</a>!<br>Initially this would cause the app to either Error out when&nbsp;<code>false</code>&nbsp;or to&nbsp;<a href="https://github.com/npm/cli/commit/52e3e88feb75c1e4c5e05771e2f4e67be27015ab" target="_blank" rel="noreferrer noopener">toggle the user and group</a>.</p>



<p>But finally,&nbsp;<a href="https://github.com/npm/cli/commit/dae3259fd17866c189c5e8b3a7968f515b1af4ca" target="_blank" rel="noreferrer noopener">we reach the reasoning for this code</a>&nbsp;(and still it’s not what many may expect).</p>



<blockquote class="wp-block-quote"><p>You can’t please everyone.</p></blockquote>



<blockquote class="wp-block-quote"><p>Don’t try to be secure if it’ll fail.&nbsp;</p><p>If someone really wants to encourage this all the time, then they can do<br><code>npm config set unsafe-perm false</code>&nbsp;explicitly.&nbsp;</p><p>In the npm 1.0 future, it will probably require sudo for global<br>installing no matter what, and use this behavior for local installing.<br>Since so many people have npm installing in their home dir, requiring<br>sudo is causing more trouble than it’s worth.</p></blockquote>



<p><em>Boom</em></p>



<p>This was added to help installing files into ‘safe’ locations without&nbsp;<code>sudo</code>.<br>So I think that I may have the answer?</p>



<blockquote class="wp-block-quote"><p>Use this sparingly; probably bad to set globally for all running scripts. If the user is running as&nbsp;<code>root</code>&nbsp;it may cause the app to force changes that could extend beyond what a running script should have. Never run as&nbsp;<code>root</code>&nbsp;and it will be&nbsp;<code>true</code>&nbsp;by default. Use&nbsp;<code>sudo</code>&nbsp;otherwise. It’s not a magic bullet.</p></blockquote>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/what-does-unsafe-perm-in-npm-actually-do/">What does unsafe-perm in npm actually do?</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.meghrajtechnosoft.com/what-does-unsafe-perm-in-npm-actually-do/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
