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

Topic prefix stripping in server-to-server connections #81

Open
smurfix opened this issue Feb 11, 2024 · 26 comments
Open

Topic prefix stripping in server-to-server connections #81

smurfix opened this issue Feb 11, 2024 · 26 comments

Comments

@smurfix
Copy link

smurfix commented Feb 11, 2024

Hi,

While FlashMQ supports prefixing topics on messages it sends and receives, it doesn't seem to be able to remove a prefix from incoming or outgoing topics, at least as far as flashmq.conf manpage is concerned.

This would afford transparently tunneling arbitrary messages through a shared server.

Mosquitto can do it ;-)

@halfgaar
Copy link
Owner

I can see why you would want it. I'd have to spend some time looking at how complex it would be to make, and what the performance implications are (I tend to avoid adding overly heavy features).

@smurfix
Copy link
Author

smurfix commented Feb 12, 2024

I hear you. A "strip the first N components of the incoming / outgoing message" feature would work for most if not all users, if that's easier than a comparison; I didn't yet encounter any such link that needed more complex arrangements.

In any case, on the positive side, at least this feature has no performance impact if it's not used.

@marcelrv
Copy link

This topic mapping would indeed be very appreciated.
@smurfix you indicate topic prefixing when sending, how did you accomplish that as that would already do most of the job in my case, but did not recognise how to do that from the conf file nor from the bridge code

@smurfix
Copy link
Author

smurfix commented Mar 21, 2024

I currently accomplish topic prefixing with RabbitMQ, but I'd rather switch to something faster + more extensible (FlashMQ has this nice plugin architecture …) if at all possible.

@halfgaar
Copy link
Owner

I did some checking for feasibility. One question pops to mind: if there is authentication in place, do you expect that to happen before or after the mangling? Let's say we're talking about messages on topic a/b/c:

  • In incoming publish: do you want the 'write' permission to be checked on prefix/a/b/c or a/b/c?
  • In delivering a publish to a subscriber, same question: do you want that 'read' permission to be checked on prefix/a/b/c or a/b/c?

There are some architectural difficulties if you would want the ACL check to happen with the prefix. Logically, I'd say without the prefix makes most sense.

@smurfix
Copy link
Author

smurfix commented Mar 22, 2024

As long as you're consistent whether the checks are done on the paths as seen by the client or as seen by the server (= every other client that doesn't have mangling applied to it) I can write an ACL to match.

Thus, my answer is "whatever happens to be easier to implement".

@wiebeytec
Copy link
Contributor

OK, then I'll give it a go. Prefix stripping on receive is easy. Adding a prefix on send is a bit more difficult, but if we can do it at the very last step, meaning after authentication on the original topic string, it's probably doable.

Do note that it will incur some extra overhead, because there are certain optimizations it can't do then.

Probably the next feature you want is multiple bridge connections with load balancing. It's on my list...

@halfgaar
Copy link
Owner

I created a branch with a test version: https://github.com/halfgaar/FlashMQ/tree/PREVIEW-bridge-prefixes. If compiling is too hard, I can probably give you a .deb package.

The bridge config sections supports a local_prefix and remote_prefix option. It should act the same as Mosquitto's, in terms of how it subscribes and what it adds and removes.

The prefix options are defined per bridge, not per pattern. There are some conceptual problems with having them per pattern. I'm not sure how Mosquitto does it...

The ACL checking turned out to be the following:

  • Remote prefix is removed and local prefixes is added before ACL write checks. So, the ACL write checking is done after the mangling.
  • The read ACL checks (delivery to subscribers) is done before mangling. So, the ACL is done on the path as it appears locally. Then, after ACL, the local prefix is removed and the remote prefix added.

@halfgaar
Copy link
Owner

Actually, I was a bit premature. There are various issues with that branch still.

@smurfix
Copy link
Author

smurfix commented Mar 25, 2024

Thanks. Looking forward to testing it once you've got the issues ironed out.

Building a .deb is not a problem.

@smurfix
Copy link
Author

smurfix commented Mar 25, 2024

OK, then I'll give it a go.

👍🏼

Probably the next feature you want is multiple bridge connections with load balancing. It's on my list...

Heh. Not really. My volume is high but not that high.

What I do want is redundancy, i.e. connect my MQTT servers in an arbitrary mesh and lose no messages (*) if any one of them hangs / fails / whatever. I'm currently using my own protocol on top of MQTT for this and I'd love to be able to bypass the whole thing.

(*) except exact duplicates of course; when a sensor tells me five times that it's 18° out there I don't care how many of those arrive – as long as the number is greater than zero.

@halfgaar
Copy link
Owner

As an update; I was doing some prep work for this change, which kind of opened up can of worms of things that needed fixing. So, I'm working on a new release, coming in a few days I hope, and then I can continue with this.

@smurfix
Copy link
Author

smurfix commented Mar 29, 2024

Thanks for the update. Not a problem.

@halfgaar
Copy link
Owner

I think I'm close to giving you a .deb to test. For what OS+version do you want it?

@smurfix
Copy link
Author

smurfix commented Apr 14, 2024

Cool.
Standard Debian stable should be fine.

@halfgaar
Copy link
Owner

You can download a test version for Bookwork here. It's a release build, so optimized and no symbols. At this point, I don't expect test scenarios I need debuggers for, just whether it behaves correctly. I can always make a debug build if required.

Install with dpkg -i.

This comment still applies as to how it works.

The more scenarios tested, the better. Like bridges with persistent sessions (non-clean start and non-0 expiry), severed connections, queued messages, using aliases, etc.

@halfgaar
Copy link
Owner

I'm eager to any test results, both positive and negative alike :)

@smurfix
Copy link
Author

smurfix commented Apr 25, 2024

Yeah and I'm eager for some "free" time in which to test the setup I have in mind …

I'll try to shovel some hours free next week.

@halfgaar
Copy link
Owner

Has the shoveling worked ;)?

@smurfix
Copy link
Author

smurfix commented May 28, 2024 via email

@halfgaar
Copy link
Owner

halfgaar commented Jun 27, 2024

I created new test builds, based off 1.15.2:

There were some architectural changes in master, so this branch was adapted to that.

@smurfix
Copy link
Author

smurfix commented Nov 9, 2024

Could you rebase this to the subscription-id branch? That'd let me set up a mostly-integrated test environment which I hopefully can (lightly) torture over the holidays.

@halfgaar
Copy link
Owner

halfgaar commented Nov 9, 2024

It has some merge conflicts, and more with the subscription IDs. I can, but I'd rather first finish the subscription IDs and have that in master.

@smurfix
Copy link
Author

smurfix commented Nov 9, 2024

Thanks. No hurry.

@halfgaar
Copy link
Owner

I tried to rebase, but now the tests fail. I don't know why yet.

I also saw some likely mistakes. So, this still needs some work.

halfgaar added a commit that referenced this issue Dec 3, 2024
@halfgaar
Copy link
Owner

halfgaar commented Dec 3, 2024

I have a new test branch:

https://github.com/halfgaar/FlashMQ/tree/WIP-bridge-prefixes

The prefix is not applied automatically to the bridge's subscribe and publish directives. It felt too magic to do so, plus it would mean the prefixes are applied to all subscribe and publish directives, which is not good.

Let me know how it works out.

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

No branches or pull requests

4 participants