haproxy-with-client-certs.cfg.example 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. # This example config is designed for HAProxy. It allows MeshCentral to use and validate Client Certificates.
  2. # Usernames/Passwords are still required. This will provide a layer for authorization.
  3. #
  4. # The MeshID enviorment variable is used for the binary paths. Simply put your MeshID for an incoming group
  5. # into this variable and the binary paths will use the ID for downloading the agent directly to the client.
  6. # Simply type in your specific url (https://reallycoolmeshsystem.com/win10full) and the agent will download
  7. # with the proper meshid for the specified group. In my usage, I have an incoming group assigned.
  8. #
  9. # The config also ensures a split between IPv4 and IPv6. Thus if a client attempts to connect on IPv4,
  10. # it will connect to Meshcentral with IPv4. And if IPv6 is used, IPv6 connection to Meshcentral will be used.
  11. # This config is written in *long* form, it is written for simplicity and clarity. I'm confident that someone
  12. # can shorten the script size easily.
  13. #
  14. # Please examine the MeshID, location of the certificates, certificate names and OU test for the certificates.
  15. # CRL and guest connections are not integrated yet.
  16. #
  17. #
  18. # The following specific path names do not require a validated client certificate:
  19. #
  20. # /win10background - Windows 10 Background Binary Installer
  21. # /win10full - Windows 10 Binary Interactive and Background Installer
  22. # /macosxfull - MacOS 10 Binary Interactive and Background Installer
  23. # /linuxscript - Linux Script ( See Docs)
  24. # /linux64full - Linux AMD64 Binary Interactive and Background Installer
  25. # /linux64background - Linux AMD64 Binary Background Installer
  26. # /linuxarmfull - Linux ARMhf Binary Interactive and Background Installer
  27. # /linuxarmbackground - Linux ARMhf Binary Background Installer
  28. #
  29. # /agent.ashx - Agent to server connection (Websockets)
  30. # /meshrelay.ashx - Agent to server relay
  31. # /meshagents - Default agent download path
  32. # /meshosxagent - Default agent download path for Mac OS X
  33. global
  34. log /dev/log local0
  35. log /dev/log local1 info
  36. chroot /var/lib/haproxy
  37. stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
  38. stats timeout 30s
  39. user haproxy
  40. group haproxy
  41. daemon
  42. # Set the meshID to the incoming group ID
  43. setenv meshID {{really long mesh group ID}}
  44. # Default SSL material locations
  45. # Probably needs a more secure location
  46. ca-base /etc/haproxy/
  47. crt-base /etc/haproxy/
  48. # Default ciphers to use on SSL-enabled listening sockets.
  49. # For more information, see ciphers(1SSL). This list is from:
  50. # https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
  51. # An alternative list with additional directives can be obtained from
  52. # https://mozilla.github.io/server-side-tls/ssl-config-generator/?server=haproxy
  53. ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
  54. ssl-default-bind-options no-sslv3
  55. defaults
  56. log global
  57. mode http
  58. option httplog
  59. option dontlognull
  60. timeout connect 5000
  61. timeout client 50000
  62. timeout server 50000
  63. errorfile 400 /etc/haproxy/errors/400.http
  64. errorfile 403 /etc/haproxy/errors/403.http
  65. errorfile 408 /etc/haproxy/errors/408.http
  66. errorfile 500 /etc/haproxy/errors/500.http
  67. errorfile 502 /etc/haproxy/errors/502.http
  68. errorfile 503 /etc/haproxy/errors/503.http
  69. errorfile 504 /etc/haproxy/errors/504.http
  70. frontend http
  71. bind :::80 v4v6
  72. redirect scheme http code 301 if !{ ssl_fc }
  73. frontend https
  74. # Replace Root-ca.pem and mesh.pem with proper certs
  75. bind :::443 v4v6 ssl crt mesh.pem ca-file Root-ca.pem verify optional crt-ignore-err all ca-ignore-err all
  76. http-request add-header X-Forwarded-Proto https
  77. # Testing for Client Certificate used
  78. acl clientssl ssl_c_used
  79. # Set SSL Cert OU here to verify a proper user
  80. acl clientssl ssl_c_s_dn(OU) "Bad Ass Mesh Services Inc"
  81. # Agents for download
  82. acl meshagent path_beg /meshagents
  83. acl macmeshagent path_beg /meshosxagent
  84. # IPV4 vs IPV6 test
  85. acl meshipv4 src 0.0.0.0/0
  86. acl meshipv6 src ::/0
  87. # Websockets ACL
  88. acl host_ws path_beg /agent.ashx
  89. # MeshRelay
  90. acl meshrelay path_beg /meshrelay.ashx
  91. # Specific Agent installers for each platform
  92. acl winback path_beg /win10background
  93. acl winfull path_beg /win10full
  94. acl macosx path_beg /macosxfull
  95. acl linuxscript path_beg /linuxscript
  96. acl linux64full path_beg /linux64full
  97. acl linux64back path_beg /linux64background
  98. acl linuxarmfull path_beg /linuxarmfull
  99. acl linuxarmback path_beg /linuxarmbackground
  100. # WebSockets
  101. use_backend meshWebSocket4 if host_ws meshipv4 !clientssl
  102. use_backend meshWebSocket6 if host_ws meshipv6 !clientssl
  103. # Mesh Relay
  104. use_backend meshcentralv4 if meshrelay meshipv4
  105. use_backend meshcentralv6 if meshrelay meshipv6
  106. # Client SSL Specific
  107. use_backend meshcentralv4 if meshipv4 !meshagent !macmeshagent clientssl
  108. use_backend meshcentralv6 if meshipv6 !meshagent !macmeshagent clientssl
  109. # Direct Mesh Agent download
  110. use_backend meshcentralv4 if meshipv4 meshagent
  111. use_backend meshcentralv6 if meshipv6 meshagent
  112. use_backend meshcentralv4 if meshipv4 macmeshagent
  113. use_backend meshcentralv6 if meshipv6 macmeshagent
  114. # Windows Custom Download
  115. use_backend Win10full4 if meshipv4 winfull
  116. use_backend Win10full6 if meshipv6 winfull
  117. use_backend Win10back4 if meshipv4 winback
  118. use_backend Win10back6 if meshipv6 winback
  119. # Mac CUstom Download
  120. use_backend macosx4 if meshipv4 macosx
  121. use_backend macosx6 if meshipv6 macosx
  122. # Linux Script Custom Download
  123. use_backend linuxSCRIPT4 if meshipv4 linuxscript
  124. use_backend linuxSCRIPT6 if meshipv6 linuxscript
  125. # Linux Script Custom Download
  126. use_backend linux64-bin-full4 if meshipv4 linux64full
  127. use_backend linux64-bin-full6 if meshipv6 linux64full
  128. use_backend linux64-bin-back4 if meshipv4 linux64back
  129. use_backend linux64-bin-back6 if meshipv6 linux64back
  130. use_backend linuxarm-bin-full4 if meshipv4 linuxarmfull
  131. use_backend linuxarm-bin-full6 if meshipv6 linuxarmfull
  132. use_backend linuxarm-bin-back4 if meshipv4 linuxarmback
  133. use_backend linuxarm-bin-back6 if meshipv6 linuxarmback
  134. # Fail if none of the above
  135. http-request deny if !macmeshagent !meshagent !clientssl !host_ws !winback !winfull !macosx !linuxscript !linux64full !linux64back !linuxarmfull !linuxarmback !meshrelay
  136. # Websockets
  137. backend meshWebSocket4
  138. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  139. server ipv4 127.0.0.1:444
  140. backend meshWebSocket6
  141. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  142. server ipv6 [::1]:444
  143. # Standard Interface
  144. backend meshcentralv4
  145. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  146. server ipv4 127.0.0.1:444
  147. backend meshcentralv6
  148. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  149. server ipv6 [::1]:444
  150. # Windows Agent Download
  151. backend Win10back4
  152. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  153. http-request set-path /meshagents
  154. http-request set-query id=4&meshid=%[env(meshID)]&installflags=2
  155. server ipv4 127.0.0.1:444
  156. backend Win10back6
  157. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  158. http-request set-path /meshagents
  159. http-request set-query id=4&meshid=%[env(meshID)]&installflags=2
  160. server ipv6 [::1]:444
  161. backend Win10full4
  162. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  163. http-request set-path /meshagents
  164. http-request set-query id=4&meshid=%[env(meshdID)]&installflags=0
  165. server ipv4 127.0.0.1:444
  166. backend Win10full6
  167. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  168. http-request set-path /meshagents
  169. http-request set-query id=4&meshid=%[env(meshID)]&installflags=0
  170. server ipv6 [::1]:444
  171. # MacOS Agent Download
  172. backend macosx6
  173. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  174. http-request set-path /meshosxagents
  175. http-request set-query id=100054&meshid=%[env(meshID)]
  176. server ipv6 [::1]:444
  177. backend macosx4
  178. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  179. http-request set-path /meshosxagents
  180. http-request set-query id=100054&meshid=%[env(meshID)]
  181. server ipv4 127.0.0.1:444
  182. # Linux Script Downloads
  183. backend linuxSCRIPT6
  184. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  185. http-request set-path /meshagents
  186. http-request set-query scrpot=1
  187. server ipv6 [::1]:444
  188. backend linuxSCRIPT4
  189. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  190. http-request set-path /meshagents
  191. http-request set-query scrpot=1
  192. server ipv4 127.0.0.1:444
  193. # Linux Binary Downloads
  194. backend linux64-bin-full6
  195. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  196. http-request set-path /meshagents
  197. http-request set-query id=%[env(meshID)]&installflags=0&meshinstall=6
  198. server ipv6 [::1]:444
  199. backend linux64-bin-full4
  200. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  201. http-request set-path /meshagents
  202. http-request set-query id=%[env(meshID)]&installflags=0&meshinstall=6
  203. server ipv4 127.0.0.1:444
  204. backend linux64-bin-back6
  205. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  206. http-request set-path /meshagents
  207. http-request set-query id=%[env(meshID)]&installflags=2&meshinstall=6
  208. server ipv6 [::1]:444
  209. backend linux64-bin-back4
  210. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  211. http-request set-path /meshagents
  212. http-request set-query id=%[env(meshID)]&installflags=2&meshinstall=6
  213. server ipv4 127.0.0.1:444
  214. backend linuxarm-bin-full6
  215. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  216. http-request set-path /meshagents
  217. http-request set-query id=%[env(meshID)]&installflags=0&meshinstall=25
  218. server ipv6 [::1]:444
  219. backend linuxarm-bin-full4
  220. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  221. http-request set-path /meshagents
  222. http-request set-query id=%[env(meshID)]&installflags=0&meshinstall=25
  223. server ipv4 127.0.0.1:444
  224. backend linuxarm-bin-back6
  225. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  226. http-request set-path /meshagents
  227. http-request set-query id=%[env(meshID)]&installflags=2&meshinstall=25`
  228. server ipv6 [::1]:444
  229. backend linuxarm-bin-back4
  230. http-request add-header X-Forwarded-Host %[req.hdr(Host)]
  231. http-request set-path /meshagents
  232. http-request set-query id=%[env(meshID)]&installflags=2&meshinstall=25
  233. server ipv4 127.0.0.1:444