sasa1977 / site_encrypt

Integrated certification via Let's encrypt for Elixir-powered sites
MIT License
470 stars 34 forks source link

Support https-only endpoints #33

Closed axelson closed 3 years ago

axelson commented 3 years ago

An endpoint that is only https will likely have false as the :http configuration, which is the default: https://hexdocs.pm/phoenix/1.5.8/Phoenix.Endpoint.html?#module-adapter-configuration

Without this you get an error like:

11:18:57.256 [error] GenServer GenTrackerWeb.Endpoint terminating
** (FunctionClauseError) no function clause matching in Keyword.fetch!/2
    (elixir 1.12.0-rc.0) lib/keyword.ex:417: Keyword.fetch!(false, :port)
    (site_encrypt 0.4.2) lib/site_encrypt/phoenix.ex:106: SiteEncrypt.Phoenix.start_acme_server/1
    (parent 0.12.0) lib/parent.ex:646: Parent.start_validated_child/2
    (parent 0.12.0) lib/parent.ex:375: Parent.start_child/2
    (parent 0.12.0) lib/parent.ex:396: anonymous fn/1 in Parent.start_all_children!/1
axelson commented 3 years ago

So this probably isn't the best by itself because I later realized that Let's Encrypt's HTTP-01 challenge type (the type used by site_encrypt I think) requires port 80 to be open: https://letsencrypt.org/docs/allow-port-80/

But it would be nice to give a better error in the case of http: false

sasa1977 commented 3 years ago

So this probably isn't the best by itself because I later realized that Let's Encrypt's HTTP-01 challenge type (the type used by site_encrypt I think) requires port 80 to be open

Precisely.

But it would be nice to give a better error in the case of http: false

I agree. I think that raising an error in this case should be the way to go.

axelson commented 3 years ago

Okay, I've changed the code to raise an error instead. This is what it looks like when ran:

[error] GenServer GenTrackerWeb.Endpoint terminating
** (RuntimeError) Unable to retrieve HTTP port from the HTTP configuration. SiteEncrypt relies on the Lets Encrypt HTTP-01 challenge type which requires an HTTP version of the endpoint to be running and the configuration received did not include an http port.
Received: false
    (site_encrypt 0.4.2) lib/site_encrypt/phoenix.ex:132: SiteEncrypt.Phoenix.raise_http_required/1
    (site_encrypt 0.4.2) lib/site_encrypt/phoenix.ex:106: SiteEncrypt.Phoenix.start_acme_server/1
    (parent 0.12.0) lib/parent.ex:646: Parent.start_validated_child/2
    (parent 0.12.0) lib/parent.ex:375: Parent.start_child/2
    (parent 0.12.0) lib/parent.ex:396: anonymous fn/1 in Parent.start_all_children!/1
    (elixir 1.12.0-rc.0) lib/enum.ex:1553: Enum."-map/2-lists^map/1-0-"/2
    (elixir 1.12.0-rc.0) lib/enum.ex:1553: Enum."-map/2-lists^map/1-0-"/2
    (parent 0.12.0) lib/parent/supervisor.ex:51: Parent.Supervisor.init/1
sasa1977 commented 3 years ago

Thank you!