Jump to content

HOW TO: Emby remote SSL with PFSense, auto cert renewal no private domain required.


Recommended Posts

Posted (edited)

I am currently just starting out with Emby, but this is my initial solution for setting up external SSL at low or no cost and no domain ownership required.  The only cost to this solution would be hardware to run PFSense on if you don't already have something.

It's 10 "easy" steps, so lets get started.

PFSENSE: (highly recommended)

PFSense is a Commercial grade firewall with all the features and capabilities you would expect.  It is a free network firewall distribution, based on the FreeBSD operating system with a custom kernel and including third party free software packages for additional functionality.

PFSense is a Software firewall that can be deployed on a wide range of hardware solutions. You can buy an appliance directly from netgate https://pfsense.org/products/ (I run a NetGate 4200+) or you can build your own firewall utilizing hardware you have laying around or purchase: https://pfsense.org/products/#requirements

Please familiarize yourself with the setup of your Firewall and validate that the configuration is secure.  Don’t assume, PFSense will allow you to do things that typical residential firewall will not.

If you are not familiar with setting up a firewall, I would recommend you get PFSense running and build out a configuration that works for you base needs prior to doing a full switch over. This will give you some time to learn how things work and get comfortable with the interface.  PFSense has an awesome community should you need help with this step.

Prerequisites:

1)      A working PFSense Firewall configuration.    

note: You should either replace your ISP’s Router with PFSENSE or put the ISP’s Router in bridge mode to pass all traffic directly to PFSense. (this will eliminates double NAT configuration bs)

2)      A DDNS account. (this can be any free DDNS service)

3)      A DDNS domain name.  I use (xyz.DDNS.NET free domain currently)

 

The setup for Emby Hosting:

Step 0: setup dyndns  go to Services -> Dynamic DNS

 

image.thumb.png.ebb34bbc16d7d30a6c96db57a2167c4c.png

Step 1: go to Firewall -> NAT -> Port Forwarding and Add a new rule. To forward port 8080 to your internal network firewall Address. 

image.png.6d0af4176c909d5e8aac6e66825726fc.png

Step 2: go to System -> Package Manager and install 2 package “acme” and “haproxy

 

image.png.0c1334cbc7e2b81e8bffbdceefe4d343.png

 

Step 3: go to Services -> Acme Certificates first “Create a new Account Key” then “Register ACME account key” then click save.image.png.7185d91b11a45164164313f894d9107b.png

 

go to certificates tab

 image.png.cc049bd7fa7be6210643031939ea398d.png

For domain name put in your domain name ex xyz.ddns.net

For method use “Standalone HTTP Server” the set port to 8080.

 image.png.9e70ecbb07830028a67d17871cd8ea92.png

For action set it to restart haproxy on cert renewal.  Then save.

Step 4:  issue a cert

 image.png.7996f16561bde7a85f7a4c51d04aca70.png

You can verify your cert by going to System -> Certificates.

You should see the root cert:

 image.png.5d2d4575ed05ce0f75432d24e15129e5.png

And the certificate:

 image.png.1a8cc3c31dc2d0cd7376f5c3b96fbf9d.png

 

Step 5: re-secure port 80 since it points back into your farwall.

Go to Firewall -> Schedules  and create a schedule for mon-sun 3:15-3:30

 image.png.958ac557539ec440a55b45fd921d8c6b.png

 

Go to Firewall -> Rules -> wan

Find the rule created when you made the NAT rule and apply the Schedule to that rule in advanced options.

 image.png.6c042a09873da79ca2ebd1f10ee95d8e.png

(note: with this schedule applied the cert can only be renewed between 3:15am and 3:30 am when the auto renew job goes off.  If you attempt to renew outside that time the firewall blocks the validation requests from letsencrypt)

 

Step 6: go to Services -> haproxy -> settings

Enable haproxy

 image.png.0f08e20517de9470851f68190d262523.png

Make sure dns is set further down:

 image.png.aa1b9ff4aeeeb38635060dafe74809a4.png

Step 7: go to Backend and add an entry

Set to address and port of your internal Emby server.

 image.png.038f892c930956054b2500be817d04ec.png

Save

Step 8: go to frontend and add an entry

Port should be the external port you want to use for emby access.  I used 6701

Set type to http/https offloading

 image.png.a7fc208a90a2f9cc383cafb409611eda.png

Set the host expression to starts with and the value to your dns name  xyz.ddns.net

 image.png.02e86c0f8f68bad5277c11800335efba.png

For action set it to use backend and pick the backend you created in the previous step

 image.png.ef8696fb47b780e719227413493ec7bb.png

Further down in the ssl offloading section pick the certificate you created earlier

 image.png.ecae751e044af869dbe8dd9ac7770318.png

Step 9 go to Firewall -> Rules -> Wan   

Add a rule to allow traffic to the haproxy front end I used port 6701 for access.

 image.png.572048c65a284a09540497a398aacb80.png

 

Step 10 open a browser on a device not connected to your network and go to: https://xyz.ddns.net:6700  (replace xyz.ddns.net with your domain name.)

You should get the Emby login page via a SSL connection.   I am sure there are additional step you can perform to increase security on this. but the goal is a working configuration.

done go watch a movie!

 

 

Edited by rookies
remove attachments again
  • Thanks 1
Posted

Seems a lot more complicated than using Caddy!

Paul

Posted (edited)

Never used Caddy, but after taking a quick look at it.  Likely what I am doing is in fact more complicated to setup. 

The original 10 steps took me about 20 minutes to figure out and accomplish, it's not as complicated as it may appear, and since I have PFSense and it provides so much capability, why not use it.

1) I have WG tunnels so all devices(phones, IPads and laptops) automatically connect to my network as soon as they make an external connection to the internet. so all my devices have full protection and filtering at all times. 

2) I have DNS filtering capability to keep my devices clean of ADs and prevent access to malware sites etc. (and beyond that capability I also run Pi-hole)

3) I have selective outbound traffic routing through VPN tunnels for internet browsing. 

4) Probably more important, I have a lot of control over who can see that I even have open ports.

The ability to block all request to the server based on almost any criteria you can think of.  For instance I block all request that do not originate from north America. Then if they make it past that I block any request that initiates from Azure, AWS or GCP. Then if they make it past that I have multiple ANS's blocked to get rid of the pesky scanners and bad actors .

I get maybe 2 or 3 connection attempts a day not related to my traffic that actually make it to a backend port successfully.

5) I have control over what leaves my network as well, what devices can talk to on a device by device basis.

 

So yes, I agree!  It is absolutely more complicated than using Caddy! 

 

 

 

 

Edited by rookies
  • Like 1
Posted (edited)

@rookiesI also use HAProxy on PFSense as my first reverse proxy (although I have a dedicated VM setup for it and it's only acting as a HAProxy appliance) I do have a couple of extra tips that I didn't see mentioned in your write-up though.

1. In the frontend configuration for HAProxy you'll want to make sure you check the box for "Use "forwardfor" option". This will add the X-Forwarded-For header to packets before sending them to emby. This makes it so that Emby will see the real client IP that is making the connection rather than the IP of PFSense/HAProxy. This is needed if you expect bandwidth limits and whatnot to work for remote connections.

2. Also in the frontend configuration you can add the following in the field next to the "Advanced certificate specific ssl options":  alpn h2,http/1.1

This will enable HTTP/2 on the frontend, so all  connections should use HTTP/2 between the client and HAProxy. It will fall back to http/1.1 if for whatever reason HTTP/2 isn't supported by the client. Also worth noting that if you enabled HTTPS within emby as well, the HAProxy backend can communicate with emby via HTTP/2 so the connection will be HTTP/2 throughout. Most other reverse proxies only support http/1.1 when making backend connections to servers. 

 

Edited by Clackdor
Posted
57 minutes ago, Clackdor said:

@rookiesI also use HAProxy on PFSense as my first reverse proxy (although I have a dedicated VM setup for it and it's only acting as a HAProxy appliance) I do have a couple of extra tips that I didn't see mentioned in your write-up though.

1. In the frontend configuration for HAProxy you'll want to make sure you check the box for "Use "forwardfor" option". This will add the X-Forwarded-For header to packets before sending them to emby. This makes it so that Emby will see the real client IP that is making the connection rather than the IP of PFSense/HAProxy. This is needed if you expect bandwidth limits and whatnot to work for remote connections.

2. Also in the frontend configuration you can add the following in the field next to the "Advanced certificate specific ssl options":  alpn h2,http/1.1

This will enable HTTP/2 on the frontend, so all  connections should use HTTP/2 between the client and HAProxy. It will fall back to http/1.1 if for whatever reason HTTP/2 isn't supported by the client. Also worth noting that if you enabled HTTPS within emby as well, the HAProxy backend can communicate with emby via HTTP/2 so the connection will be HTTP/2 throughout. Most other reverse proxies only support http/1.1 when making backend connections to servers. 

 

That is awesome, thanks for the heads up.  I haven't actually put this into use in any real way.  would have definitely hit the x-forward snag and had to figure it out and fix it.

Posted
12 minutes ago, rookies said:

That is awesome, thanks for the heads up.  I haven't actually put this into use in any real way.  would have definitely hit the x-forward snag and had to figure it out and fix it.

Glad to help. HAProxy is very powerful and kind of pupose-built for proxying and load balancing. I've been using PFSense for over 15 years on and off at this point. Even though I'm currently using Sophos instead of PFSense as my main router/firewall I opted to setup the PFSense VM just for HAProxy since I was already comfortable with it. As far as I'm aware the HAProxy package in PFsense (maybe OPNSense too?) is the only way to get a webgui for HAProxy configuration that isn't tied to some expensive enterprise tool. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...