Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why recommending no SSL when behind Cloudflare? #1039

Closed
kirillrogovoy opened this issue Oct 3, 2024 · 13 comments
Closed

Why recommending no SSL when behind Cloudflare? #1039

kirillrogovoy opened this issue Oct 3, 2024 · 13 comments

Comments

@kirillrogovoy
Copy link

I'm sorry if this had been discussed. Couldn't find it anywhere.

This line from the config template got me puzzled:

Set ssl: false if using something like Cloudflare to terminate SSL (but keep host!).

I've always believed that one has to have SSL at the origin server even if behind a public proxy such as Cloudflare.

Because, otherwise, the request between Cloudflare and the origin server will travel through the public internet unencrypted, right? Like this: User <-encrypted-> Cloudflare <-plain-> Origin

Don't we want to have this instead? User <-encrypted-> Cloudflare <-encrypted-> Origin

I understand that the ultimate answer is "well, it's up to you" which is fair. However, I feel like the way this comment is phrased might deceive users into thinking that they have complete User<->Server encryption when they actually don't.

Or am I missing something here?

@tuladhar
Copy link
Contributor

tuladhar commented Oct 3, 2024

I don't think it's deceiving as the comment does say that Cloudflare terminates the SSL, which technically means encryption ends at Cloudflare.

By default, Cloudflare uses Flexible mode, which means that even if you set ssl: true, the connection between Cloudflare and your origin server is still not encrypted. To properly set it up, you need to set SSL mode to Full in Cloudflare. Maybe, that can be mentioned in the comment.

I can create a PR to address this if that would be useful, does that sound good?

@kaka-ruto
Copy link

So for this to work well with Cloudflare we need to set ssl: true and on cloudflare use the Full/Strict ssl mode?

@kaka-ruto
Copy link

Also just to confirm, I and many others had hacked Kamal 1 to work with letsencrypt by running mkdir -p /letsencrypt && touch /letsencrypt/acme.json && chmod 600 /letsencrypt/acme.json on the server as suggested in #112.

We also need to remove that dir for this to work well right?

@tuladhar
Copy link
Contributor

tuladhar commented Oct 3, 2024

So for this to work well with Cloudflare we need to set ssl: true and on cloudflare use the Full/Strict ssl mode?

Yes, otherwise you will get constant redirect, such as these:
Screenshot 2024-10-04 at 1 43 39 AM

And once you have set this, Full should be enough. It will work again.

Screenshot 2024-10-04 at 1 44 35 AM

@tuladhar
Copy link
Contributor

tuladhar commented Oct 3, 2024

Also just to confirm, I and many others had hacked Kamal 1 to work with letsencrypt by running mkdir -p /letsencrypt && touch /letsencrypt/acme.json && chmod 600 /letsencrypt/acme.json on the server as suggested in #112.

We also need to remove that dir for this to work well right?

I started with Kamal 2, so no idea about that. But, I'd suggest, to try without removing first and then remove it and try again.

@cardmagic
Copy link

It would be amazing if kamal-proxy had an easy built-in option to generate self-signed certificates as an option instead of letsencrypt which would allow full (but not strict) end-to-end with cloudflare

@kaka-ruto
Copy link

Thanks @tuladhar , will try that.

@kirillrogovoy
Copy link
Author

In regards to the original issue, my main issue was with the imperative default advice that might be harmful to the security of the origin.

I'll post that line again:

Set ssl: false if using something like Cloudflare to terminate SSL (but keep host!).

As @tuladhar mentioned, the default setting in Cloudflare is Flexible which means "go over unencrypted HTTP". And then the default advice in Kamal is "turn SSL off when using (something like) Cloudflare"

In their docs, Cloudflare clearly recommends using Full:
image

Again, it's probably not Kamal's job to educate people about all this. I'm not sure what is a more idiomatic solution here for Kamal specifically, but I'd either remove that recommendation completely from the config template or spend another line explaining implication of ssl: false + public proxy like Cloudflare.

Or flip the statement and always recommend turning SSL on unless the users are really sure that the server will have a reverse proxy in front of it inside their private network (either physically or via some VPN) and it will be terminating SSL.

@tuladhar
Copy link
Contributor

tuladhar commented Oct 4, 2024

It would be amazing if kamal-proxy had an easy built-in option to generate self-signed certificates as an option instead of letsencrypt which would allow full (but not strict) end-to-end with cloudflare

But why would you need a self-signed certificate when you can get a valid LE certificate for free for your domain?

@tuladhar
Copy link
Contributor

tuladhar commented Oct 4, 2024

@kirillrogovoy PR opened: #1054

@cardmagic
Copy link

It would be amazing if kamal-proxy had an easy built-in option to generate self-signed certificates as an option instead of letsencrypt which would allow full (but not strict) end-to-end with cloudflare

But why would you need a self-signed certificate when you can get a valid LE certificate for free for your domain?

The LE cert only works in situations with a single app server, if you are load balancing a bunch of them it’s easier to do self signed. And I want SSL to the load balancer, even if it is self signed.

@kirillrogovoy
Copy link
Author

Thanks @tuladhar! ❤️

@aguynamedben
Copy link

Does anybody know of a proven guide that works for Rails 8 + Kamal 2 for setting up:

  • SSL and/or DNS with Cloudflare
  • 1 DigitalOcean load balancers
  • 2-3 DigitalOcean droplets

I watched the DHH videos, bought the Kamal handbook, but am still in SSL proxy CDN DNS hell. For Kamal to succeed I feel like it has to provide a lot of documentation on how to set this stuff up. Otherwise people will just keep using the alternatives.

I was able to get a single DigitalOcean droplet to work with Cloudflare DNS set with an A record for the Droplet and Proxy Status set to "Proxied", i.e. terminating HTTPS. But when I added a DigitalOcean load balancer in front of the Droplet (with the health check for /up on port 80) it's always red. When I try to visit the domain for the load balancer, which is setup in Cloudflare DNS as an A record with "DNS only", I get Cloudflare handshake errors.

I feel like I've tried every combination of variables (i.e. editing production.rb in Rails, editing deploy.yml, spinning up new Droplets, toggling Cloudflare Proxy Status) and I'm 12 hours in and can't find the right set of variables. There should just be a cookbook in the Kamal docs for the common setups for Rails 8 + Kamal 2, or else I'm going to go back crying to fly.io 😭

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants