<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>IT notes - haproxy</title>
    <subtitle>DBRE, AWS platform engineering, PostgreSQL, Linux, FreeBSD, and Rust reference notes.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://nbari.com/tags/haproxy/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://nbari.com"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2017-05-30T14:47:06+02:00</updated>
    <id>https://nbari.com/tags/haproxy/atom.xml</id>
    <entry xml:lang="en">
        <title>haproxy ssh</title>
        <published>2017-05-30T14:47:06+02:00</published>
        <updated>2017-05-30T14:47:06+02:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://nbari.com/haproxy-ssh/"/>
        <id>https://nbari.com/haproxy-ssh/</id>
        
        <content type="html" xml:base="https://nbari.com/haproxy-ssh/">&lt;h1 id=&quot;https-and-ssh-on-the-same-port&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#https-and-ssh-on-the-same-port&quot; aria-label=&quot;Anchor link for: https-and-ssh-on-the-same-port&quot;&gt;🔗&lt;/a&gt;HTTPS and SSH on the same port&lt;/h1&gt;
&lt;p&gt;Using HAProxy to server SSH and SSL available on the same port:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;global&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    maxconn 1000000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    spread-checks 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    log /var/run/log local0 notice&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    daemon&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    tune.ssl.default-dh-param 2048&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;defaults&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    mode http&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    balance roundrobin&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option http-server-close&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option abortonclose&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option dontlognull&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option redispatch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout check           3s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout client          30s  # Client and server timeout must match the longest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout connect         5s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout http-keep-alive 5s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout http-request    10s  # A complete request may never take that long.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout queue           1m   # Don&amp;#39;t queue requests too long if saturated.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout server          10s  # Time we may wait for a response from the server.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    retries 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    log global&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# ----------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# stats&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# ----------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;listen stats&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    bind *:81&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stats enable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stats uri /&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stats show-node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stats show-legends&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    stats refresh 5s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# ------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;#  https + ssh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;# ------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;frontend ssl&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    mode tcp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    bind *:443 ssl crt /usr/local/etc/haproxy/your.cert&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option tcplog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    tcp-request inspect-delay 5s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    tcp-request content accept if HTTP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    # 5353482d322e30 is the binary representation of the string &amp;#39;SSH-2.0&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    acl client_attempts_ssh payload(0,7) -m bin 5353482d322e30&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    use_backend ssh if !HTTP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    use_backend ssh if client_attempts_ssh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    use_backend http if HTTP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;backend http&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    mode http&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    http-request set-header X-Forwarded-Port %[dst_port]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    server www 10.10.8.3:8000 maxconn 50 check&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;backend ssh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    mode tcp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option tcplog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    server ssh 10.10.8.4:22&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    timeout server 2h&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;connecting-from-an-ssh-client&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#connecting-from-an-ssh-client&quot; aria-label=&quot;Anchor link for: connecting-from-an-ssh-client&quot;&gt;🔗&lt;/a&gt;Connecting from an SSH client&lt;/h1&gt;
&lt;p&gt;To connect throught the HAProxy on port 443 edit the ~/.ssh/config:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;Host&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; ssh-over-https&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-12&quot;&gt;    ProxyCommand&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt; openssl s_client -connect your.haproxy.com:443 -quiet&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;how-does-this-work&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-does-this-work&quot; aria-label=&quot;Anchor link for: how-does-this-work&quot;&gt;🔗&lt;/a&gt;how does this work ?&lt;/h1&gt;
&lt;p&gt;The &lt;a rel=&quot;external&quot; href=&quot;https://tools.ietf.org/html/rfc4253#section-4.2&quot;&gt;RFC 4253&lt;/a&gt;, section 4.2
states that clients must send a string that starts with &#39;SSH-2.0&#39;:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;4.2.  Protocol Version Exchange&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   When the connection has been established, both sides MUST send an&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   identification string.  This identification string MUST be&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      SSH-protoversion-softwareversion SP comments CR LF&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   Since the protocol being defined in this set of documents is version&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   2.0, the &amp;#39;protoversion&amp;#39; MUST be &amp;quot;2.0&amp;quot;.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;gt;&amp;gt;&amp;gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;5353482d322e30&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;.&lt;/span&gt;&lt;span class=&quot;z-2&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-7&quot;&gt;hex&lt;/span&gt;&lt;span class=&quot;z-3&quot;&gt;&amp;quot;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;z-1 z-i&quot;&gt;SSH-2.0&lt;/span&gt;&lt;span class=&quot;z-3 z-i&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;5353482d322e30&lt;/code&gt; is the binary representation of the string &#39;SSH-2.0&#39;. So
everything boils down to this line:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;acl client_attempts_ssh payload(0,7) -m bin 5353482d322e30&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When a new connection is made on the port 443, HAproxy decrypts the SSL layer,
and checks whether the stream of data sent by the client starts with this string.&lt;/p&gt;
&lt;p&gt;src: http://blog.chmd.fr/ssh-over-ssl-episode-4-a-haproxy-based-configuration.html&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>haproxy</title>
        <published>2017-02-09T13:53:50+01:00</published>
        <updated>2017-02-09T13:53:50+01:00</updated>
        
        <author>
          <name>Unknown</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://nbari.com/haproxy/"/>
        <id>https://nbari.com/haproxy/</id>
        
        <content type="html" xml:base="https://nbari.com/haproxy/">&lt;h1 id=&quot;haproxy-http-auth-ip-src&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#haproxy-http-auth-ip-src&quot; aria-label=&quot;Anchor link for: haproxy-http-auth-ip-src&quot;&gt;🔗&lt;/a&gt;HAproxy + HTTP auth + IP SRC&lt;/h1&gt;
&lt;p&gt;Use HTTP Auth when source IP is not from an allowed source:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;userlist TestUsers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user guest insecure-password secret&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;backend test-node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    acl network_allowed src 10.0.0.1 192.30.252.0/22&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    acl AuthOK http_auth(TempUsers)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    http-request auth realm Test if !network_allowed !AuthOK&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    server test test.server.tld:80 maxconn 50 check&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To only allow specific range, for example only GitHub:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; acl network_allowed src 192.30.252.0/22 185.199.108.0/22&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; http-request deny if !network_allowed&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;haproxy-mysql&quot;&gt;&lt;a class=&quot;zola-anchor&quot; href=&quot;#haproxy-mysql&quot; aria-label=&quot;Anchor link for: haproxy-mysql&quot;&gt;🔗&lt;/a&gt;HAproxy + mysql&lt;/h1&gt;
&lt;p&gt;First setup mysql by creating a HAproxy to do the checks:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;USE mysql;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;INSERT INTO user (Host,User) values(&amp;#39;%&amp;#39;, &amp;#39;haproxy&amp;#39;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;FLUSH PRIVILEGES;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In case you are here because you ran out of connections you can do:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;mysql&amp;gt; FLUSH HOSTS;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then you can use something like:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;backend rds-mysql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    mode tcp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    balance leastconn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option tcpka&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    option mysql-check user haproxy&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    server rds mysql.eu-central-1.rds.amazonaws.com:3306 check&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;https://www.haproxy.com/doc/aloha/7.0/haproxy/healthchecks.html#checking-a-mysql-service&lt;/p&gt;
</content>
        
    </entry>
</feed>
