<?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>Random Things &#187; mysql</title>
	<atom:link href="http://www.edna.narrabilis.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.edna.narrabilis.com</link>
	<description></description>
	<lastBuildDate>Sat, 18 Jul 2009 15:07:36 +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>stunnel for mysql &#8211; server and client</title>
		<link>http://www.edna.narrabilis.com/2006/06/01/stunnel-for-mysql-server-and-client/</link>
		<comments>http://www.edna.narrabilis.com/2006/06/01/stunnel-for-mysql-server-and-client/#comments</comments>
		<pubDate>Thu, 01 Jun 2006 15:34:32 +0000</pubDate>
		<dc:creator>ednawig</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.edna.narrabilis.com/2006/06/01/stunnel-for-mysql-server-and-client/</guid>
		<description><![CDATA[We needed to set up an stunnel to the mysql server (mysql.example.com), 

 so that the client (client.example.com) and the server can communicate over an encrypted tunnel. Stunnel was already installed on both linux machines &#8211; it is avaialble from http://stunnel.org. The steps taken on mysql.example.com were:

cd /etc/stunnel
Create a certificate:
openssl req&#160;&#160; -x509 -nodes -days 365&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>We needed to set up an stunnel to the mysql server (<code>mysql.example.com</code>), <span style="float:left; margin-right: 2em; margin-top: 1em; margin-bottom: 1em;"><script type="text/javascript"><!--
google_ad_client = "pub-8771063603940634";
google_ad_width = 125;
google_ad_height = 125;
google_ad_format = "125x125_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "CCCCCC";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "666666";
google_color_text = "333333";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span> so that the client (<code>client.example.com</code>) and the server can communicate over an encrypted tunnel. <span id="more-48"></span>Stunnel was already installed on both linux machines &#8211; it is avaialble from <a href="http://stunnel.org">http://stunnel.org</a>. The steps taken on <code>mysql.example.com</code> were:</p>
<ol>
<li><code>cd /etc/stunnel</code></li>
<li>Create a certificate:<br />
<code>openssl req&nbsp;&nbsp; -x509 -nodes -days 365&nbsp;&nbsp; -newkey rsa:1024 \<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -keyout stunnel.pem -out stunnel.pem </code></li>
<li>The <code>stunnel.conf</code> file contains the following lines:
<p><code>cert = /etc/stunnel/stunnel.pem<br />
setuid = nobody<br />
setgid = nobody<br />
pid = /tmp/stunnel.pid<br />
debug = 7<br />
output = stunnel.log<br />
[mysqls]<br />
accept&nbsp;&nbsp;= 3309<br />
connect = 3306<br />
</code></p>
</li>
<li><code>stunnel</code>is started</li>
</ol>
<p>The steps taken on <code>client.example.com</code> were:</p>
<ol>
<li>Create a certificate as above (not strictly necessary but otherwise the connection is open to a man in the middle attack)</li>
<li><code>stunnel.conf</code> contains the following lines:
<p><code><br />
cert =/etc/stunnel/stunnel.pem<br />
pid = /tmp/stunnel.pid<br />
setuid = nobody<br />
setgid = nobody<br />
debug=7<br />
output=stunnel.log<br />
client = yes<br />
[3309]<br />
accept&nbsp;&nbsp;= 3309<br />
connect = mysql.example.com:3309<br />
</code></p>
</li>
<li><code>stunnel</code> is started</li>
<li>The <code>mysql</code> client is invoked with the following:<br />
<code>mysql -h mysql.example.com -u mysqluser -p -P 3309</code><br />
The hostname must be specified so that <code>mysql</code> will not attempt to bind with a local <code>mysqld</code> via a local socket.<br />
<code>mysqluser</code> needs to be granted rights on the appropriate databases with the host being <code>localhost.localdomain</code>. Something like<br />
<code>grant all on db.* to mysqluser@&#039;localhost.localdomain&#039; identified by &#039;SecretPw&#039;;</code><br />
(this is done on a mysql client running on <code>mysql.example.com</code> by an administrator).</ol>
<p>We had another requirement: we had to establish tunneled <code>mysql</code> connections from <code>mysql.example.com</code> to <code>topmysql.example.com</code>. So we created on <code>mysql.example.com</code> the directory <code>/etc/stunnel-client</code> with the client configuration as above. We started a second instance of <code>stunnel</code>, specifying the new config:<br />
<code>stunnel /etc/stunnel-client/stunnel-client.conf</code></p>
<p><code>topmysql.example.com</code> was set up as an <code>stunnel</code> server as above, and everything worked as expected.</p>
<p>The only thing left to do is firewall off the unencrypted mysql connections on both servers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.edna.narrabilis.com/2006/06/01/stunnel-for-mysql-server-and-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
