bob's tech ramblings where i ramble about technical things http://tech.randomness.org.uk/ Generating a SSL certificate with Capistrano http://tech.randomness.org.uk/Generating_a_SSL_certificate_with_Capistrano.html http://tech.randomness.org.uk/Generating_a_SSL_certificate_with_Capistrano.html Sun, 30 Aug 2009 17:34:14 GMT <p><a href="http://www.capify.org/index.php/Capistrano">Capistrano</a> is useful for deploying ruby applications. It can also be used to help with configuration and setup of things related to the applications</p> <p> Such as creating the ssl keys and certificates for the demo and staging sites. I've always used an <a href="http://www.exim.org/exim-html-4.00/doc/html/spec_36.html#SECT36.5">openssl one liner</a> to do this but I still needed to fill in the details for the certificate. Which is less that ideal if you want to automate the creation of the keys and certificates. So I dug around and found the right incantation to pass the certificate details to openssl. I then made this into a capistrano recipe.</p> <pre> namespace :sslcert do desc "create a self signed ssl cert" task :create, :roles => :web do sudo "openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/private/#{application}.key -out /etc/ssl/certs/#{application}.crt -days 9999 -nodes -subj \"/C=GB/ST=England/L=London/O=#{application}/OU=IT/CN=#{servername}\"" end end </pre> <p>As you can see the magic happens with the -subj option.</p> <p>This recipe puts the ssl certificate and key in the default location for them on debian. You could of course change this and then not need to use sudo. In my actual work version I also make sure this recipe doesn't run on production deployments since they should be using real ssl certificates.</p> An Apache holding page with mod_rewrite http://tech.randomness.org.uk/An_Apache_holding_page_with_mod_rewrite.html http://tech.randomness.org.uk/An_Apache_holding_page_with_mod_rewrite.html Sun, 16 Aug 2009 17:34:14 GMT <p>On Thursday the <a href="http://london.randomness.org.uk">Randomness Guide to London</a> was probably the target of a <a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">ddos</a> attack. The machine it was hosted on went to load of about 60. Which is fine since its solaris. The main problem was when the machine exhausted its memory and started to swap the machine would become unresponive.. To mitigate this I dropped the number of concurrent connections apache allowed. The machine suffered less but the website was still unusable because you were fighting to get one of the limited number of available connections.</p> <p> Since I was in the <a href="http://london.randomness.org.uk/wiki.cgi?Bricklayer's_Arms,_SW15_1DD">pub</a> the other administrator of the <a href="http://london.randomness.org.uk">Randomness Guide to London</a> was renaming the CGIs so that load would drop and she could get on to it. When I got back I whipped up some mod_rewrite rules such that we could see the site but everyone else got a holding page. 10 minutes after this the ddos stopped. So it was a bit late. However a holding page is still a useful thing to have.</p> <p>The next morning I refined it a bit to be more intelligent and return a 503 which is the correct status code.</p> <pre> RewriteEngine On RewriteCond %{REMOTE_ADDR} !AAA.BBB.CCC.DDD RewriteCond %{DOCUMENT_ROOT}/holding.html -f RewriteCond %{DOCUMENT_ROOT}/holding.enable -f RewriteCond %{SCRIPT_FILENAME} !holding.html RewriteRule ^.*$ /holding.html [R=503,L] ErrorDocument 503 /holding.html </pre> </p>First turn on the rewrite engine. Then the conditions for which the RewriteRule applies <ul> <li>Don't match an IP address. So you can see the site.</li> <li>Make sure holding.html exists</li> <li>Check for the existence of a file called holding.enable. This is the means by which you turn holding page on and off.</li> <li>Don't apply the rule when serving holding.html</li> </ul> Then the rule itself. Which basically redirects anything to the 503 error page. Which you then set as holding.html</p> <p>That's all you really need although at work I add an extra line to help stupid web caches not keep on showing the error page after the site is back. <pre> Header Set Cache-Control "max-age=0, no-store" </pre> </p> Testing perl 5.10.1-RC1 http://tech.randomness.org.uk/Testing_perl_5_10_1_RC1.html http://tech.randomness.org.uk/Testing_perl_5_10_1_RC1.html Mon, 10 Aug 2009 17:37:02 GMT <p>The first <a href="http://use.perl.org/articles/09/08/07/0910246.shtml">perl 5.10.1</a> release candidate was released the other day. As <a href="http://www.shadowcat.co.uk/blog/matt-s-trout/test-the-rc-test-the-rc-test-the-rc/">mst says</a> if you don't test it now and it breaks for you when its released its your fault. As a good <a href="http://www.cpantesters.org/">cpan tester</a> I've added it to my testing <a href="http://svn.randomness.org.uk/trunk/bob/scripts/cpantest.sh">setup</a>.</p> <p>Since I care about <a href="http://openguides.org/">OpenGuides</a> for the <a href="http://london.randomness.org.uk">Randomness Guide to London</a> I made sure to submit a <a href="http://www.nntp.perl.org/group/perl.cpan.testers/2009/08/msg4944870.html">test report</a> for <a href="http://www.cpantesters.org/distro/O/OpenGuides.html">it</a>.</p> <p>While I was doing this I also added perl 5.8.9 to my setup. I also changed my setup slightly by pre-installing <a href="http://www.iinteractive.com/moose/">Moose</a> and <a href="http://www.catalystframework.org/">Catalyst</a> since thats what all the cool perl programmers are using these days. Since installing and testing their dependency chains was burning a lot of cpu, time and bandwidth every time a new module based on them was updated or added to <a href="http://search.cpan.org/">CPAN</a></p> Setting up a Signed apt repo http://tech.randomness.org.uk/Setting_up_a_Signed_apt_repo.html http://tech.randomness.org.uk/Setting_up_a_Signed_apt_repo.html Fri, 7 Aug 2009 17:34:14 GMT <p>So you've set up a apt repository following dean's excellant <a href="http://blog.unixdaemon.net/cgi-bin/blosxom.pl/operatingsystems/linux/debian/personal_apt_repo_initial.html">instructions</a> and youve tried to install a package and got the following warning</p> <pre>WARNING: The following packages cannot be authenticated!</pre> <p>At this point you have several choices:- <ul> <li>press yes and carry on.(not that useful if youre using puppet to install stuff)</li> <li><code>echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth</code></li> <li> Set up a <a href="http://wiki.debian.org/SecureApt">secure repository</a></li> </ul> <p>Lets go with setting up a secure repository. <ul> <li>Make yourself a gpg key - <code>gpg --gen-key</code></li> <li>Export your public key to a file - <code>gpg --armor --export $keyid >public.key</code>. You will need this later</li> <li>Create an apt-release.conf containing <code>APT::FTPArchive::Release::Suite "etch";</code><small>(Im behind and should have written this post a year ago)</small> in your repository base.</li> <li>Generate a release file - <code>apt-ftparchive -c apt-release.conf release dists/etch/ > dists/etch/Release</code></li> <li>Create a signed version - <code>gpg --sign -ba -o dists/etch/Release.gpg dists/etch/Release</code></li> </ul> Your repository is now secure. Now you need to tell your machines about your key or apt-get will emit <pre>W: GPG error: http://debianrepo etch Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY $KEYID</pre> To do this manually you can take the public.key you generated earlier and copy it to your machines and then run <code>apt-key add public.key</code></p> <p> Of course in this day and age doing things like that for all your machines would be tedious so I use <a href="http://reductivelabs.com/products/puppet/">puppet</a> with a class something like the following.</p> <pre> class aptkey { file { "/etc/apt/public.key": mode => 440, owner => root, group => root, source => [ "puppet://puppet/host/public.key", "puppet://puppet/files/public.key" ], } exec { "install-key": command => "/usr/bin/apt-key add /etc/apt/public.key", require => File["/etc/apt/public.key"], unless => "/usr/bin/apt-key list | /bin/grep -q 'firstname.lastname'"; } exec { "key-update": command => "/usr/bin/apt-get update", require => Exec["install-key"], } } </pre> Dean's Cron Commandments http://tech.randomness.org.uk/Dean_s_Cron_Commandments.html http://tech.randomness.org.uk/Dean_s_Cron_Commandments.html Mon, 4 Aug 2008 17:34:14 GMT <p>Dean wrote his <a href="http://blog.unixdaemon.net/cgi-bin/blosxom.pl/sysadmin/cron_commandments.html">Cron Commandments</a> a while back but they got some link loving from <a href="http://simonwillison.net/2008/Jun/27/cron/">Simon Willison </a>relatively recently. The one he misses though is <b>Thou shall not rewrite cron</b>. Im looking at you <a href="http://backgroundrb.rubyforge.org/">backgroundrb</a> and <a href="http://rufus.rubyforge.org/rufus-scheduler/files/README_txt.html">rufus-scheduler</a>.</p> Cisco Routers for the Desperate http://tech.randomness.org.uk/Cisco_Routers_for_the_Desperate.html http://tech.randomness.org.uk/Cisco_Routers_for_the_Desperate.html Sun, 22 Jun 2008 17:34:14 GMT <p>If you dont know much about using and setting up cisco routers I humbly suggest you buy <a href="http://nostarch.com/frameset.php?startat=cisco">Cisco Routers for the Desperate</a>. It was very useful this week when I set up a pair of 2811s with HSRP. I would tell you how but I think you should buy the book instead.</p> Creating an apt repo. http://tech.randomness.org.uk/Creating_an_apt_repo_.html http://tech.randomness.org.uk/Creating_an_apt_repo_.html Thu, 22 May 2008 12:51:09 GMT <p>So recently I've backported[1] a couple of debian packages and needed somewhere to serve them from. The current work apt repo scares me so I followed <a href="http://blog.unixdaemon.net/">Dean's</a> useful <a href="http://blog.unixdaemon.net/cgi-bin/blosxom.pl/operatingsystems/linux/debian/personal_apt_repo_initial.html">guide</a> to setting one up instead. It worked very nicely and wasn't pain.</p> <p><small>[1] post to come hopefully</small></p> Patch accepted to chronicle http://tech.randomness.org.uk/Patch_accepted_to_chronicle.html http://tech.randomness.org.uk/Patch_accepted_to_chronicle.html Mon, 21 Jan 2008 17:34:14 GMT <p>When I was setting up my <a href="http://planet.randomness.org.uk/">Planet</a> I noticed that <a href="http://www.steve.org.uk/Software/chronicle/">Chronicle</a> was outputting less that useful titles for the rss feed. Instead of whining I provided a <a href="http://chronicle.repository.steve.org.uk/?rev/89eef19064e8">patch</a> which <a href="http://www.steve.org.uk/">Steve</a> <a href="http://chronicle.repository.steve.org.uk/?rev/3f0bf6fe2825">accpeted</a>.</p> Hating mailman http://tech.randomness.org.uk/Hating_mailman.html http://tech.randomness.org.uk/Hating_mailman.html Sun, 13 Jan 2008 17:34:14 GMT <p>Today I have mostly been <a href="http://bob.hates-software.com/2008/01/13/e1af6d12.html">hating</a> <a href="http://www.list.org/">mailman</a></p> <p>That's about an hour of my life im never getting back</p> SVN::Web for my repository http://tech.randomness.org.uk/SVN__Web_for_my_repository.html http://tech.randomness.org.uk/SVN__Web_for_my_repository.html Tue, 8 Jan 2008 17:34:14 GMT <p>I've had a <a href="http://svn.randomness.org.uk/">svn repo</a> for a while. Today I installed <a href="http://search.cpan.org/dist/SVN-Web/">SVN::Web</a> which gives a useful web interface to it. For example you can see other revisions than the current one. <a href="http://svnweb.randomness.org.uk/index.cgi/randomness/">My Repository</a> via SVN::Web.</p> <p> One reason why i did this is that it gives a <a href="http://svnweb.randomness.org.uk/index.cgi/randomness/rss">RSS feed</a> of the revision log. This means I can use <a href="http://rssfwd.com/">RSS FWD</a> to get commit messages in my email without having to mess with commit hooks.</p>