On the previous post we described HAproxy installation, now configure TCP secure connections with Username and password.  HAProxy provides an Userlists, Group and User options.

userlists can be used to store authentication & authorization data for independent customers.

Example :
    

 userlist ListName


Group to the current userlist. We can add the users to this group by using a comma-separated list of names.

Example :
 

 group GroupName
        users User1,User2....,Usern


User to the current userlist. Both secure (encrypted) and insecure (unencrypted) passwords can be used.  Linux can support method of encrypting passwords MD5, SHA-256, SHA-512 and etc.

Example :
  

    user username1 password $6kfo0440383$#*3643&YR22jd2@!81t())@(1
    user username2 insecure-password password
 


Open your HPAroxy configure file by text editor,
 
# vim /etc/haproxy/haproxy.cfg


global
        log /dev/log    local0 debug
        log /dev/log    local2 info
        log /dev/log    local1 notice
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin
        stats timeout 30s

    userlist list1
    group mygroup
        user username1 password $6kfo0440383$#*3643&YR22jd2@!81t())@(1
          user username2 insecure-password password

frontend haproxymaster
        bind *:1883
        mode tcp

backend infibroker
        mode tcp
        option tcpka
        retries 3
        server hostname 192.168.2.10:1900 check
        timeout connect        10s
        timeout server         1m


Finally, restart the HAProxy service.
 
# service haproxy restart