Skip to content

mixed auto and manual TLS#81

Open
cuchaz wants to merge 1 commit intoferronweb:developfrom
cuchaz:mixed-auto-tls
Open

mixed auto and manual TLS#81
cuchaz wants to merge 1 commit intoferronweb:developfrom
cuchaz:mixed-auto-tls

Conversation

@cuchaz
Copy link
Contributor

@cuchaz cuchaz commented May 26, 2025

This is another PR that's meant to start a discussion, rather than accept the code as-is.

Basically, I found it really helpful to exclude some domains from auto-TLS while testing apps before they were ready for deployment.

In this case, I was migrating an app from one server to another, so it was impossible to get TLS certs for the app on the destination server since DNS hadn't been updated yet. But I still wanted to be able to test the app on the target server before finalizing the migration, but Ferron kept trying to get the TLS certs for every domain its hosts have and failing on the one domain with old DNS settings. It's common to edit your /etc/hosts file in these cases so you can test deployments locally without making them public yet, which gives you the effect of bypassing public DNS for a bit. So this patch allows configuring each domain to be included in auto-TLS, or not.

But, the reason why I think this might not be a good PR as-is is because it only solves part of the problem. Once you skip some domains during auto-TLS, you still want to be able to access them through Ferron. Either over regular HTTP without a cert, or over HTTPs with a local self-signed cert.

If you've generally configured Ferron to use HTTPs, then that basically rules out regular HTTP since the configuration isn't granular enough to be per-host. So one possible improvement would be to add per-host HTTPs settings.

If you still want to use HTTPs for all your hosts, even in local testing, then ideally you could attach a self-signed cert to the host and use than instead of the auto-TLS one. However, editing the sni configuration to add a self-signed cert to the host seemed to be ignored by Ferron in this case, possibly because auto-TLS was enabled. So another possible improvement here would be to allow Ferron to use the sni certs in cases when auto-TLS has been disabled for a host.

Hopefully that makes sense, and hopefully I've motivated the use case enough here. Let me know what you think, and if you have any questions.

"Invalid automatic TLS enabling option value"
))?
}
if used_properties.contains("enableAutomaticTLS")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical Code - Priority: Medium
The condition checking for enableAutomaticTLS is identical in functionality between ferron/src/server.rs and ferron/src/util/validate_config.rs. This could be refactored to avoid redundancy.

if let Some(domain) = domain_yaml.as_str() {
if !domain.contains("*") {
// check if we even want auto-TLS for this domain
let want_auto_tls = host
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code - Priority: High
The logic for handling enableAutomaticTLS is duplicated between ferron/src/server.rs and ferron/src/util/validate_config.rs. Consider extracting this logic into a shared utility function.

@hikaflow
Copy link

hikaflow bot commented May 26, 2025

PR Summary

Changes Overview

  • No changes were identified in the provided file change summaries.

Identified Issues

  • No issues were found.

Recommendations

  • None.

@DorianNiemiecSVRJS DorianNiemiecSVRJS added the rust Pull requests that update rust code label May 26, 2025
@DorianNiemiecSVRJS
Copy link
Member

I'm rewriting Ferron, and added support for mixed automatic and manual TLS in the rewrite (Ferron 2.x, which is now in beta).
The configuration for Ferron 2.x demonstrating mixed automatic and manual TLS would look like this:

// This is just an example

example.com {
  // Automatic TLS (it's enabled by default)
  root "/var/www/example"
}

manual.example.com {
  // Manual TLS
  tls "/etc/certs/example.crt" "/etc/certs/example.key"
  root "/var/www/example"
}

@cuchaz
Copy link
Contributor Author

cuchaz commented Jul 13, 2025

Looks nice!

@DorianNiemiecSVRJS
Copy link
Member

I have marked Ferron 1.x as "in maintenance mode" in the f3de200 commit, so I'm not sure if I'm going to merge your pull request, as it's against the development branch for Ferron 1.x...

The functionality discussed about in the pull request is already supported in Ferron 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants