Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    SSL certs handling and HAproxy

    Scheduled Pinned Locked Moved General pfSense Questions
    136 Posts 3 Posters 28.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      lewis
      last edited by

      Yes, I think we're getting somewhere.
      This is what I'm seeing about the certificate;

      ---
      Server certificate
      subject=CN = domain.com
      
      issuer=C = US, O = (STAGING) Let's Encrypt, CN = (STAGING) Artificial Apricot R3
      
      ---
      No client certificate CA names sent
      Peer signing digest: SHA256
      Peer signature type: RSA-PSS
      Server Temp Key: X25519, 253 bits
      ---
      SSL handshake has read 4661 bytes and written 409 bytes
      Verification error: unable to get local issuer certificate
      ---
      New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
      Server public key is 2048 bit
      Secure Renegotiation IS NOT supported
      Compression: NONE
      Expansion: NONE
      No ALPN negotiated
      Early data was not sent
      Verify return code: 20 (unable to get local issuer certificate)
      
      1 Reply Last reply Reply Quote 0
      • stephenw10S
        stephenw10 Netgate Administrator
        last edited by

        Aha! OK then that's the first hurdle. The client is connecting to HAProxy at least.

        So you need to renew the cert now it's set to the production server.

        Then see what is broken next. 😉

        1 Reply Last reply Reply Quote 0
        • L
          lewis
          last edited by lewis

          Ok, I've renewed it and no change. Still shows as staging even though I've changed it to production.
          The one difference however is now I'm seeing connections to the web server but all of them are getting a 301.

          The bad thing about doing this is if all I'm going to see are connections from the pfsense device IP, that's going to remove all logging data that is always needed to better understand traffic and so on.

          TOR still gets an HSTS error and firefox is still complaining "Warning: Potential Security Risk Ahead".

          SSL test still shows;

          New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
          Server public key is 2048 bit
          Secure Renegotiation IS NOT supported
          Compression: NONE
          Expansion: NONE
          No ALPN negotiated
          Early data was not sent
          Verify return code: 20 (unable to get local issuer certificate)
          

          I'm not convinced the problem is with the web server because if I set up a NAT rule again, then it works fine.
          This implies there is still something on ACME or haproxy that is not allowing the SSL cert to be used properly.

          Could it have something to do with how the cert is being generated by ACME since there seems to be some small mismatch between the host/hostname/domain or something and the ACME cert being generated.

          There are no errors when ACME renews the cert, all green, all confirmed, looks correct.

          1 Reply Last reply Reply Quote 0
          • L
            lewis
            last edited by

            I wonder if it has something to do with the fact that the cert is being handled by ACME but once the browser hits the web server, that has it's own self signed cert so maybe a mismatch?

            However, I cannot fire up the service without a cert if I allow https connections so added teh self signed cert.
            Why is this so complicated? No wonder I wasn't able to follow any article I could find to get this working.

            1 Reply Last reply Reply Quote 0
            • L
              lewis
              last edited by

              Weird, searching online for help on this leads to so many things but mostly, our own thread now.
              I cannot find anything that helps me to solve this.

              1 Reply Last reply Reply Quote 0
              • L
                lewis
                last edited by

                One thing I notice is that even with the 'production' setting, the re-generated cert always shows staging;
                issuer=C = US, O = (STAGING) Let's Encrypt, CN = (STAGING) Artificial Apricot R3

                When I re-issue and it shows the green page, there is no mention of staging anywhere.

                It's nuts how many articles contradict each other when trying to find anything on this.

                kiokomanK 1 Reply Last reply Reply Quote 0
                • kiokomanK
                  kiokoman LAYER 8 @lewis
                  last edited by

                  @lewis
                  7bacddb7-ecdf-4af5-8c9c-21989cd0e535-image.png

                  so you have registered for production

                  now you should see something with Issuer

                  Acmecert: O=Let's Encrypt, CN=R3, C=US

                  under system / certificates /certificates

                  if you see it than you need to go to haproxy and change, under ssl offloading , the certificate

                  bdfab39a-df00-4fa2-982d-7857d337b6c6-image.png

                  ̿' ̿'\̵͇̿̿\з=(◕_◕)=ε/̵͇̿̿/'̿'̿ ̿
                  Please do not use chat/PM to ask for help
                  we must focus on silencing this @guest character. we must make up lies and alter the copyrights !
                  Don't forget to Upvote with the 👍 button for any post you find to be helpful.

                  1 Reply Last reply Reply Quote 1
                  • L
                    lewis
                    last edited by lewis

                    Holy crap, I finally got it working.
                    I don't even know where to start to show what I did because I tried so many things.
                    The last thing I did was in the backend, changing the server list Table from port 80 to port 443 and enabling Encrypt(SSL).

                    The main problem I have now is still not knowing what the correct configuration of the web server should be.
                    It's using a self signed cert now but this is a stand alone web server. Some of them have lots of virtualhosts.

                    And, what SSL options will be used? The ones on ACME/haproxy or the ones set in ssl.conf/httpd.conf on the web server?

                    Plus, now I'd like to fix the 'load balanced' server that never actually worked.

                    And, how can I forward the visiting IPs? I only see the firewall's IP in the logs which is not useful.
                    I found this but it doesn't send the visiting IP;
                    a1f97c18-6897-4202-9161-8026cb873c6c-image.png

                    kiokomanK 1 Reply Last reply Reply Quote 0
                    • kiokomanK
                      kiokoman LAYER 8 @lewis
                      last edited by kiokoman

                      @lewis
                      if you can, don't use cert on web server just point to port 80
                      people will connect to haproxy and use the cert from ACME/haproxy but haproxy will speak to the web server with the self signed cert

                      on the backend add all the server that will do balance under "server list", set a Weight (10 / 20 /30 etc etc) and select round robin under load balancing

                      backend but carefully read the warning

                      567cc5b8-af5b-4e43-a2e2-4db5f33801bf-image.png

                      ̿' ̿'\̵͇̿̿\з=(◕_◕)=ε/̵͇̿̿/'̿'̿ ̿
                      Please do not use chat/PM to ask for help
                      we must focus on silencing this @guest character. we must make up lies and alter the copyrights !
                      Don't forget to Upvote with the 👍 button for any post you find to be helpful.

                      1 Reply Last reply Reply Quote 0
                      • L
                        lewis
                        last edited by

                        I can't point to port 80 because all of the sites are built using https only.
                        Any sites I'd like to add would be https.

                        kiokomanK 1 Reply Last reply Reply Quote 0
                        • kiokomanK
                          kiokoman LAYER 8 @lewis
                          last edited by

                          @lewis
                          not a big problem, it's just for convenience, create a self signed cert with all the domains you have

                          ̿' ̿'\̵͇̿̿\з=(◕_◕)=ε/̵͇̿̿/'̿'̿ ̿
                          Please do not use chat/PM to ask for help
                          we must focus on silencing this @guest character. we must make up lies and alter the copyrights !
                          Don't forget to Upvote with the 👍 button for any post you find to be helpful.

                          L 1 Reply Last reply Reply Quote 0
                          • L
                            lewis @kiokoman
                            last edited by

                            @kiokoman said in SSL certs handling and HAproxy:

                            @lewis
                            not a big problem, it's just for convenience, create a self signed cert with all the domains you have

                            What does that mean, 'with all of the domains'?
                            Do you mean you have to generate a self signed cert for each domain or there's a way to do one that has all of the names?

                            And more importantly, will https use the always updates SSL options that LE offers or will visitors end up using what ever the Apache server is configured with?

                            kiokomanK 1 Reply Last reply Reply Quote 0
                            • kiokomanK
                              kiokoman LAYER 8 @lewis
                              last edited by kiokoman

                              @lewis
                              visitors will use and see only the ACME cert

                              with openssl you can create 1 cert with all domains name

                              make a copy and edit openssl.cfg

                              Under the [ CA_default ] section, change the line (uncomment the line) # copy_extensions = copy to copy_extensions = copy

                              Under the [ v3_ca ] section,

                              change the line # subjectAltName=email:copy to subjectAltName=@alt_names

                              add a new line with extendedKeyUsage = serverAuth

                              Go to the end of the file and add
                              [ alt_names ]

                              if the server has multiple address expected to be used for connection, you should add multiple entries under [ alt_names ]. For example,

                              [ alt_names ]

                              DNS.1 = app.example.com

                              DNS.2 = app2.example.com

                              DNS.3 = app3.example.com

                              IP.1 = 192.168.1.1

                              IP.2 = 10.10.10.10

                              under cmd if you use windows:

                              set OPENSSL_CONF=C:\OpenSSL-Win64\bin\openssl.cfg (change the directory to where you have your modified copy of openssl.cfg)
                              openssl genrsa -out ServerKey.key 2048
                              openssl req -x509 -new -key ServerKey.key -sha256 -days 825 -out myCA.cer
                              

                              if you need pkcs12

                              openssl pkcs12 -export -out keystore.p12 -inkey ServerKey.key -in myCA.cer
                              

                              These are notes I have and they should still work... probably ...

                              ̿' ̿'\̵͇̿̿\з=(◕_◕)=ε/̵͇̿̿/'̿'̿ ̿
                              Please do not use chat/PM to ask for help
                              we must focus on silencing this @guest character. we must make up lies and alter the copyrights !
                              Don't forget to Upvote with the 👍 button for any post you find to be helpful.

                              L 1 Reply Last reply Reply Quote 0
                              • L
                                lewis
                                last edited by lewis

                                Getting the visitor IP is simple enough.
                                In httpd.conf, I changed;

                                LogFormat "%v %h %l %u %t "%r" %>s %b %D %^FB "%{Referer}i" "%{User-Agent}i"" combined
                                to
                                LogFormat "%v %a %l %u %t "%r" %>s %b %D %^FB "%{Referer}i" "%{User-Agent}i"" combined
                                (%h to %a)

                                And added this directive;
                                RemoteIPHeader X-Forwarded-For

                                In haproxy, Frontend, Advanced, I enabled;
                                6d37c7a4-b559-48e7-8736-80c7cb756995-image.png

                                Now I see the actual visitor IP.

                                1 Reply Last reply Reply Quote 2
                                • L
                                  lewis @kiokoman
                                  last edited by

                                  @kiokoman said in SSL certs handling and HAproxy:

                                  visitors will use and see only the ACME cert

                                  Not sure I understand this. One cert can handle one or more virtual hosts on one web server?

                                  The web servers do not have more than one IP, just one but some have lots of virtualhosts, so, different domain names.
                                  And of course, since I have to use port 80/443 for many of those domains, I have a bunch of VIPs on pfsense.

                                  if you need pkcs12

                                  Don't even know what that is unless I look it up so probably not :).

                                  1 Reply Last reply Reply Quote 0
                                  • kiokomanK
                                    kiokoman LAYER 8
                                    last edited by kiokoman

                                    yes, both ACME and your self signed cert can handle more virtual hosts/domain names with only 1 cert, it's one of the reason why people use haproxy on the first place, 1 ip > many domains

                                    ̿' ̿'\̵͇̿̿\з=(◕_◕)=ε/̵͇̿̿/'̿'̿ ̿
                                    Please do not use chat/PM to ask for help
                                    we must focus on silencing this @guest character. we must make up lies and alter the copyrights !
                                    Don't forget to Upvote with the 👍 button for any post you find to be helpful.

                                    1 Reply Last reply Reply Quote 1
                                    • L
                                      lewis
                                      last edited by

                                      In the case that we've been working on, it's one domain on one web server.
                                      There is another that should be redirected (301) to the main domain in the httpd.conf but I commented that out while working on this.
                                      So maybe that's a good test to try and understand what this new thing (to me) is about.

                                      I definitely don't understand how I can use just one LE cert on pfsense/acme to do this but I kind of understand doing it on the web servers.
                                      On the web servers, I could also just create a self singed cert for every domain that's very long lasting. That I understand.

                                      Getting into editing openssl and other things like that, I don't and could easily lose track of stuff like that. I'm looking for the easiest way that is a no brainer to maintain as I jump from one location to another so have a hard time keeping track of highly nuanced configs.

                                      When you say using one certificate, and let's say we're talking about LE, I've created certs where you use '-d domain1.com -d domain2.com' etc. So I understand that any number of domains can be inserted into one cert. Is this what you mean? I assume so.

                                      1 Reply Last reply Reply Quote 0
                                      • stephenw10S
                                        stephenw10 Netgate Administrator
                                        last edited by

                                        Yes the LE cert used by the HAProxy front end has to be valid for all hosts/domains it is accepting traffic for.

                                        1 Reply Last reply Reply Quote 0
                                        • L
                                          lewis
                                          last edited by

                                          Since I have the single server working, now, moving on to the load balanced servers.

                                          Those web servers are using a san share to get their certificates.
                                          They don't have any self signed cert of course so what would the first step be?

                                          Since they were not going through the haproxy, should I address that first or just do it all at once?

                                          1 Reply Last reply Reply Quote 0
                                          • L
                                            lewis
                                            last edited by

                                            My original plan was to have pfsense handle the cert encryption so that it could send all of the traffic to a varnish server on the LAN.
                                            I guess that means that no matter what, I would have to remove all ssl from each site/server so that pfsense could handle it then send traffic to varnish using port 80.

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.