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

[Merged by Bors] - Add TLS capability to the beacon node HTTP API #2668

Closed
wants to merge 2 commits into from

Conversation

macladson
Copy link
Member

Currently, the beacon node has no ability to serve the HTTP API over TLS.
Adding this functionality would be helpful for certain use cases, such as when you need a validator client to connect to a backup beacon node which is outside your local network, and the use of an SSH tunnel or reverse proxy would be inappropriate.

Proposed Changes

  • Add three new CLI flags to the beacon node
    • --http-enable-tls: enables TLS
    • --http-tls-cert: to specify the path to the certificate file
    • --http-tls-key: to specify the path to the key file
  • Update the HTTP API to optionally use warp's TlsServer depending on the presence of the --http-enable-tls flag
  • Update tests and docs
  • Use a custom branch for warp to ensure proper error handling

Additional Info

Serving the API over TLS should currently be considered experimental. The reason for this is that it uses code from an unmerged PR. This commit provides the try_bind_with_graceful_shutdown method to warp, which is helpful for controlling error flow when the TLS configuration is invalid (cert/key files don't exist, incorrect permissions, etc).
I've implemented the same code in my branch here.

Once the code has been reviewed and merged upstream into warp, we can remove the dependency on my branch and the feature can be considered more stable.

Currently, the private key file must not be password-protected in order to be read into Lighthouse.

@macladson macladson added work-in-progress PR is a work-in-progress ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Oct 4, 2021
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Nice one! Very neat solution.

I had just a couple of small suggestions :)

beacon_node/http_api/src/lib.rs Outdated Show resolved Hide resolved
beacon_node/http_api/src/lib.rs Outdated Show resolved Hide resolved
@paulhauner paulhauner added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Oct 8, 2021
@macladson macladson added ready-for-review The code is ready for review and removed waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Oct 10, 2021
Copy link
Member

@paulhauner paulhauner left a comment

Choose a reason for hiding this comment

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

Great stuff!

bors r+

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Oct 12, 2021
bors bot pushed a commit that referenced this pull request Oct 12, 2021
Currently, the beacon node has no ability to serve the HTTP API over TLS.
Adding this functionality would be helpful for certain use cases, such as when you need a validator client to connect to a backup beacon node which is outside your local network, and the use of an SSH tunnel or reverse proxy would be inappropriate.

## Proposed Changes

- Add three new CLI flags to the beacon node
  - `--http-enable-tls`: enables TLS
  - `--http-tls-cert`: to specify the path to the certificate file
  - `--http-tls-key`: to specify the path to the key file
- Update the HTTP API to optionally use `warp`'s [`TlsServer`](https://docs.rs/warp/0.3.1/warp/struct.TlsServer.html) depending on the presence of the `--http-enable-tls` flag
- Update tests and docs
- Use a custom branch for `warp` to ensure proper error handling

## Additional Info

Serving the API over TLS should currently be considered experimental. The reason for this is that it uses code from an [unmerged PR](seanmonstar/warp#717). This commit provides the `try_bind_with_graceful_shutdown` method to `warp`, which is helpful for controlling error flow when the TLS configuration is invalid (cert/key files don't exist, incorrect permissions, etc). 
I've implemented the same code in my [branch here](https://github.com/macladson/warp/tree/tls).

Once the code has been reviewed and merged upstream into `warp`, we can remove the dependency on my branch and the feature can be considered more stable.

Currently, the private key file must not be password-protected in order to be read into Lighthouse.
@bors bors bot changed the title Add TLS capability to the beacon node HTTP API [Merged by Bors] - Add TLS capability to the beacon node HTTP API Oct 12, 2021
@bors bors bot closed this Oct 12, 2021
@macladson macladson deleted the bn-https branch October 12, 2021 06:32
@tashian
Copy link

tashian commented Oct 18, 2021

Hi @macladson! I work on the step-ca Certificate Authority. Thanks for adding this PR, we love seeing TLS support being added to more services.

One question. Is there any support for online rotation of the certificate and key?

@macladson
Copy link
Member Author

Hi @tashian, good question! Currently, a cert/key rotation would require a restart of the beacon node.
We use warp as our HTTP server which currently does not support online cert/key rotation. I suspect we will wait until it is supported by warp, then revisit it for Lighthouse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants