<?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>Coherent Ramblings &#187; sudo</title>
	<atom:link href="http://plathrop.tertiusfamily.net/blog/tag/sudo/feed/" rel="self" type="application/rss+xml" />
	<link>http://plathrop.tertiusfamily.net/blog</link>
	<description>My thoughts on everything from Operations through Parenting and beyond.</description>
	<lastBuildDate>Thu, 03 Jun 2010 17:12:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Managing sudoers With Puppet</title>
		<link>http://plathrop.tertiusfamily.net/blog/2007/12/15/managing-sudoers-with-puppet/</link>
		<comments>http://plathrop.tertiusfamily.net/blog/2007/12/15/managing-sudoers-with-puppet/#comments</comments>
		<pubDate>Sun, 16 Dec 2007 05:45:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Puppet]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[sudo]]></category>

		<guid isPermaLink="false">http://plathrop.tertiusfamily.net/blog/?p=13</guid>
		<description><![CDATA[In my last post, I described how to distribute an SSH authorized_keys file using Puppet. My reasoning for this was to help us utilize our existing set of home-grown scripts to administer machines &#8211; with Puppet we don&#8217;t have to wonder if our keys are set up on every host. Well, I&#8217;m sure a few [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I described how to distribute an SSH authorized_keys file using Puppet. My reasoning for this was to help us utilize our existing set of home-grown scripts to administer machines &#8211; with Puppet we don&#8217;t have to wonder if our keys are set up on every host. Well, I&#8217;m sure a few of you spotted the flaw in this. Most of us have learned not to run scripts as root when it isn&#8217;t necessary. Instead we use sudo to grant limited root powers for specific commands. Sudo is a well-designed piece of software; it&#8217;s configuration file, the sudoers file, is setup in such a way that the same sudoers file may be used on many machines. This makes it ripe for management in Puppet.</p>
<p>Building on top of the configuration we created in my last post, here is the <samp>site.pp</samp> manifest after adding sudo to the mix:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">node default <span style="color:#006600; font-weight:bold;">&#123;</span>
  file <span style="color:#006600; font-weight:bold;">&#123;</span> ‘<span style="color:#006600; font-weight:bold;">/</span>root<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">ssh</span><span style="color:#006600; font-weight:bold;">/</span>authorized_keys’:
    owner <span style="color:#006600; font-weight:bold;">=&gt;</span> root,
    group <span style="color:#006600; font-weight:bold;">=&gt;</span> root,
    mode <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">644</span>,
    source <span style="color:#006600; font-weight:bold;">=&gt;</span> ‘puppet:<span style="color:#006600; font-weight:bold;">///</span>root<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">ssh</span><span style="color:#006600; font-weight:bold;">/</span>authorized_keys’
  <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
  file <span style="color:#006600; font-weight:bold;">&#123;</span> ‘<span style="color:#006600; font-weight:bold;">/</span>etc<span style="color:#006600; font-weight:bold;">/</span>sudoers’:
    owner <span style="color:#006600; font-weight:bold;">=&gt;</span> root,
    group <span style="color:#006600; font-weight:bold;">=&gt;</span> root,
    mode <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">440</span>,
    source <span style="color:#006600; font-weight:bold;">=&gt;</span> ‘puppet:<span style="color:#006600; font-weight:bold;">///</span>etc<span style="color:#006600; font-weight:bold;">/</span>sudoers’
    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Package<span style="color:#006600; font-weight:bold;">&#91;</span>“sudo”<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
  package <span style="color:#006600; font-weight:bold;">&#123;</span> sudo: <span style="color:#9966CC; font-weight:bold;">ensure</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> installed <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>The first definition is mostly familiar; we defined a file resource like it last time. There is something new here, however:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> Package<span style="color:#006600; font-weight:bold;">&#91;</span>“sudo”<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<p>The <samp>require</samp> parameter describes a dependency. Before this resource is applied, Puppet will look for a <a href="http://reductivelabs.com/trac/puppet/wiki/TypeReference#package">package resource</a> with the name &#8220;sudo&#8221; and apply that resource first. Next we define that package resource:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>17
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">  package <span style="color:#006600; font-weight:bold;">&#123;</span> sudo: <span style="color:#9966CC; font-weight:bold;">ensure</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> installed <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>All we want is to make sure that sudo is installed. Perhaps the coolest part of this is that it doesn&#8217;t matter that I am using Debian here, Puppet supports a wide range of package systems under the hood, and it will choose the one most appropriate for the system it is configuring. If I add a FreeBSD machine to my network, I should not have to make any changes to my Puppet configuration &#8211; I can still depend on sudo getting installed!</p>
<p>Next, we need to add an <samp>etc</samp> mount to our Puppet fileserver. Here is the resulting <samp>fileserver.conf</samp>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">[root]
  path /etc/puppet/files/root
  allow 10.0.0.0/8
&nbsp;
[etc]
  path /etc/puppet/files/etc
  allow 10.0.0.0/8</pre></td></tr></table></div>

<p>Put your sudoers file in <samp>/etc/puppet/files/etc</samp> and wait for your clients to check in with <samp>puppetmasterd</samp>. Alternately, you can log in to a client and run <samp>puppetd &#8211;test</samp> to pull down the new configuration. If sudo was not installed, it should be, and <samp>/etc/sudoers</samp> will be downloaded as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://plathrop.tertiusfamily.net/blog/2007/12/15/managing-sudoers-with-puppet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
