Skip to content

tls_manager: let REST proxy skip tls cert verification#8437

Merged
Roasbeef merged 1 commit into
lightningnetwork:masterfrom
ellemouton:v0-17-3-tls-fix
Jan 30, 2024
Merged

tls_manager: let REST proxy skip tls cert verification#8437
Roasbeef merged 1 commit into
lightningnetwork:masterfrom
ellemouton:v0-17-3-tls-fix

Conversation

@ellemouton
Copy link
Copy Markdown
Collaborator

Similarly to what is done in LiT, we let the REST proxy skip TLS
verification when connecting to the gRPC server. This is necessary to fix this bug that appears in LiT that happens when the --tlsencryptkey flag is used. This flag results
in an ephemeral tls key&cert being used which is swapped out with the permanent tls key/cert once LND is unlocked. After a day, the ephemeral cert expires but the client continues trying to use that key.

Since this is just LND connecting to itself, it should be fine to skip TLS verification here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2024

Important

Auto Review Skipped

Auto reviews are limited to the following labels: llm-review. Please add one of these labels to enable auto reviews.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@saubyk saubyk added this to the v0.17.4 milestone Jan 29, 2024
@hieblmi hieblmi self-requested a review January 29, 2024 15:31
Comment thread tls_manager.go Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The comment above should be changed to indicate that we skip tls for REST calls.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

updated! thanks :)

Copy link
Copy Markdown
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

This flag results
in an ephemeral tls key&cert being used which is swapped out with the permanent tls key/cert once LND is unlocked. After a day, the ephemeral cert expires but the client continues trying to use that key.

IIUC, isn't the solution here just that the client should get the updated cert to communicate with the node? Certs eventually expire, which is a fact of life, but the clients should be able to get the updated cert to communicate with the node.

Comment thread tls_manager.go
// certificate (which might be tricky if we're using Let's
// Encrypt or if the ephemeral tls cert is being used), we just
// skip the certificate verification. Injecting a malicious
// hostname into the listener address will result in an error
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you mean by injecting a malicious host name?

I think the attack scenario here is a MiTM (on the same machine), that is then used to obtain the macaroon directly from a request (previously not written to disk), and then can use that to issue direct commands.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm also curious about the implication for a remote signer, I think the signer node needs to open this port for the watch only node?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The REST proxy connects to the host/port configured by -rpclisten. So if you supply anything controlled by an attacker (on the same machine or remote), then lnd will attempt to listen on that host/port. And if it can't (because an attacker is already listening), then it would shut down before the REST proxy is even spun up. Or am I missing a scenario where you could inject a value that would not fail on startup?

@Roasbeef
Copy link
Copy Markdown
Member

Perhaps an alternative solution is: have the REST proxy ensure that it's using the long-lived cert when it goes to make that initial connection. IIUC, as is, this swap over can happen while lnd is still running, yet locked. As a result, any potential solution down this line needs to now insert some additional communication to the REST proxy that the switch over occurred.

Comment thread tls_manager.go
// If we're using the ephemeral certificate, we need to use the
// ephemeral cert path.
certPath := t.cfg.TLSCertPath
if t.ephemeralCertPath != "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Based on the reported scenario, does the issue happen while lnd has been running the entire time (> 24 hrs) after the first unlock, or after? If it's the latter, then we can also insert a check here re if the fresh/new cert is already in place, then we can use that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The proper fix here would indeed be to re-initialize the whole REST server once the long-term certificate is available. But because the call sites are quite in different places, it would mean a big refactor and cleanup. Which we would also want to cover with unit/integration tests. So not something we want to do under time pressure (which is IMO also how the original PR was merged in a state with several bugs).

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

Successfully merging this pull request may close these issues.

Issues connecting to LND's REST Proxy when encrypting LND's TLS Key

6 participants