Skip to content

Conversation

n-thumann
Copy link
Contributor

This PR adds support for ZeroMQ to listen on multiple interfaces, just like the RPC server.
Currently, if you specify more than one e.g. zmqpubhashblock paramter, only the first one will be used. Therefore a user may be forced to listen on all interfaces (e.g. zmqpubhashblock=0.0.0.0:28332), which can result in an increased attack surface.
With this PR a user can specify multiple interfaces to listen on, e.g.
-zmqpubhashblock=tcp://127.0.0.1:28332 -zmqpubhashblock=tcp://192.168.1.123:28332.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 10, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Concept ACK.

Maybe use a minimal diff

     for (const auto& entry : factories)
     {
         std::string arg("-zmq" + entry.first);
-        if (gArgs.IsArgSet(arg))
-        {
-            CZMQNotifierFactory factory = entry.second;
-            std::string address = gArgs.GetArg(arg, "");
+        CZMQNotifierFactory factory = entry.second;
+        for (const std::string& address : gArgs.GetArgs(arg)) {
             CZMQAbstractNotifier *notifier = factory();
             notifier->SetType(entry.first);
             notifier->SetAddress(address);

Also:

  • update the doc/zmq.md with this change
  • add release note too
  • update some test in test/functional/interface_zmq.py with multiple interfaces.

Welcome!

@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch from 582d81e to 2dcb4df Compare March 10, 2020 22:51
@promag
Copy link
Contributor

promag commented Mar 11, 2020

  • update some test in test/functional/interface_zmq.py with multiple interfaces.

@n-thumann don't forget about this.

@n-thumann
Copy link
Contributor Author

  • update some test in test/functional/interface_zmq.py with multiple interfaces.

@n-thumann don't forget about this.

Thank you for your feedback! The test is already in the works :)

@n-thumann
Copy link
Contributor Author

Currently the debug.log prints
2020-03-11T17:52:01.715152Z [scheduler] zmq: Publish hashblock <blockhash> 2020-03-11T17:52:01.715248Z [scheduler] zmq: Publish hashblock <blockhash>, when hashblock is triggered and ZeroMQ is listening on two interfaces.
Do you think it´s useful to append something like to tcp://127.0.0.1:28332 to each log entry, so that a user knows why there is an apparently duplicate entry?

@promag
Copy link
Contributor

promag commented Mar 11, 2020

Do you think it´s useful to append something like to tcp://127.0.0.1:28332 to each log entry, so that a user knows why there is an apparently duplicate entry?

Yes, makes sense in this change. Alternatively it could avoid printing the duplicate messages but not worth it.

@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch 2 times, most recently from d6f80e8 to 751a5c5 Compare March 11, 2020 18:52
@n-thumann n-thumann requested a review from promag March 16, 2020 16:26
@laanwj laanwj added the Feature label Mar 19, 2020
@mruddy
Copy link
Contributor

mruddy commented Apr 21, 2020

Tested ACK

I tested on Ubuntu 19.10 x86_64 with zmq version 4.3.2.

I verified that the node starts when not specifying any of the zmq flags, when starting with between 1 and 3 -zmqpubhashblock on different addresses and/or ports, with and without -zmqpubhashblockhwm=10000. I verified log entries, and I also verified receiving messages with the contrib/zmq/zmq_sub.py subscriber.

@n-thumann side note, you might have the right skill set to review my #14687 related to zmq, if you have some spare cycles. that's a small change that the lightning guys have been requesting for a while. thanks!

@instagibbs
Copy link
Member

concept ACK, will review

Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

utACK 6b8d300

Small, straight forward change. We can clean up log messages later if they're confusing.

@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch from 6b8d300 to ab996c2 Compare September 2, 2020 08:14
@instagibbs
Copy link
Member

re-utACK ab996c2

@jonatack
Copy link
Member

jonatack commented Sep 4, 2020

Concept ACK

@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch from ab996c2 to d8ecf73 Compare September 20, 2020 12:38
@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch from d8ecf73 to f50cd3c Compare September 23, 2020 21:23
@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch from f50cd3c to d39d889 Compare September 30, 2020 22:03
@n-thumann
Copy link
Contributor Author

n-thumann commented Sep 30, 2020

Adjusted log output to new notification types of #19572.

@n-thumann n-thumann force-pushed the zmq-listen-multiple-interfaces branch from d39d889 to e66870c Compare September 30, 2020 22:34
Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

utACK

@laanwj
Copy link
Member

laanwj commented Oct 1, 2020

Code review ACK e66870c

@instagibbs
Copy link
Member

reACK e66870c

@laanwj laanwj merged commit a0185d9 into bitcoin:master Oct 1, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 4, 2020
e66870c zmq: Append address to notify log output (nthumann)
241803d test: Add zmq test to support multiple interfaces (nthumann)
a0b2e5c doc: Add release notes to support multiple interfaces (nthumann)
b1c3f18 doc: Adjust ZMQ usage to support multiple interfaces (nthumann)
347c94f zmq: Add support to listen on multiple interfaces (Nicolas Thumann)

Pull request description:

  This PR adds support for ZeroMQ to listen on multiple interfaces, just like the RPC server.
  Currently, if you specify more than one e.g. `zmqpubhashblock` paramter, only the first one will be used. Therefore a user may be forced to listen on all interfaces (e.g. `zmqpubhashblock=0.0.0.0:28332`), which can result in an increased attack surface.
  With this PR a user can specify multiple interfaces to listen on, e.g.
  `-zmqpubhashblock=tcp://127.0.0.1:28332 -zmqpubhashblock=tcp://192.168.1.123:28332`.

ACKs for top commit:
  laanwj:
    Code review ACK e66870c
  instagibbs:
    reACK bitcoin@e66870c

Tree-SHA512: f38ab4a6ff00dc821e5f4842508cefadb701e70bb3893992c1b32049be20247c8aa9476a1f886050c5f17fe7f2ce99ee30193ce2c81a7482a5a51f8fc22300c7
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 14, 2021
Summary:
> This PR adds support for ZeroMQ to listen on multiple interfaces, just like the RPC server.
> Currently, if you specify more than one e.g. zmqpubhashblock paramter, only the first one will be used. Therefore a user may be forced to listen on all interfaces (e.g. zmqpubhashblock=0.0.0.0:28332), which can result in an increased attack surface.
> With this PR a user can specify multiple interfaces to listen on, e.g.
> -zmqpubhashblock=tcp://127.0.0.1:28332 -zmqpubhashblock=tcp://192.168.1.123:28332.

This is a backport of [[bitcoin/bitcoin#18309 | core#18309]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10339
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants