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

feat: dos protected topic relay msgs based on meta field #1614

Merged
merged 2 commits into from
Apr 4, 2023

Conversation

alrevuelta
Copy link
Contributor

@alrevuelta alrevuelta commented Mar 17, 2023

Partially addresses #1612

Summary:

  • Add new pubsub validator using the meta field for validation. This field can include an optional signature of the message injected from the application, making the relayer only propagate/accept messages with a valid signature included. Note that this is not part of the protocol and only configured from the application.
  • TODO: Wait for RFC/BCP to merge: feat(rfc): add opt-in signed message dos protection vacp2p/rfc#588

@alrevuelta alrevuelta changed the title feat: dos protected topic poc feat: dos protected topic with optional signed msgs Mar 17, 2023
@LNSD
Copy link
Contributor

LNSD commented Mar 21, 2023

Are you planning to use the meta field for DoS protection? There is a discussion related to that here: vacp2p/rfc#573 (comment)

The idea is to use a generalized version of the proof field for DoS purposes instead of the meta field, which should be an application-specific field.

@LNSD
Copy link
Contributor

LNSD commented Mar 21, 2023

Additionally, the "formalization" of the proof field was also discussed in this PR: waku-org/waku-proto#13 (comment)

In case we should need specific data to be associated with a message for relay layer DoS protections, I'd suggest introducing a new field for this.

This is the case for RLN. The RLN relay validator precise a proof Waku message attribute. Maybe that field could be generalized/standardised in a particular manner so it can be used for different purposes.

@alrevuelta
Copy link
Contributor Author

@LNSD Thanks for the input. I actually haven't thought about it, was using meta since I initially thought it was a good idea, but goes against I would suggest using meta only for data the app layer wants to hand down and I have to do a couple of tricks to make it work (eg removing meta from the hash calculation).

So I was initially using meta because imho this message signing shouldn't be part of the protocol, and I saw it as some kinf of application level thingy (I see the key as an application level thing) but ofc mixed with the message hash, which clearly belong to the protocol.

So I'm fine with both of your suggestions:

  • Using proof or a generalized version of it. A variable size array with a max and just try to decode it into an rlnProof or a a signature. Following this
  • Adding a new field, msgSignature. However I'm not sure having a field for this would be nice, since it kind of expresses an intention, and we don't want messages to be signed.

So perhaps I would lean towards a generalized version of proof, but not 100% sure of the implications. cc @rymnc

@alrevuelta alrevuelta force-pushed the dos-signed-topic branch 2 times, most recently from 9f443f2 to 39359c9 Compare March 22, 2023 14:10
@alrevuelta alrevuelta requested review from LNSD, jm-clius and rymnc and removed request for LNSD and jm-clius March 22, 2023 14:37
@jm-clius
Copy link
Contributor

I think it's important that (apart from the new field) the actual validation functionality gets removed from the protocol itself as much as possible. This imply some mechanism to pass validation-like functionality from the configured app (wakunode2 in this case) down to where relay is mounted, but I don't think the protocol should be aware of how app-level validations work (or even the configured public key). I know there may be some complexities that I'm missing here in getting this concept to work, but I would strive for a simple mechanism that works in this way.

The implementation itself should be much simpler if we don't try to do signing ourselves and don't have to deal with public keys.

@alrevuelta
Copy link
Contributor Author

@jm-clius thanks for the comments, will try to move it to the app layer. Note that I added message signing for completeness, since it feels weird that the node can validate signed messages but not publish them.

@jm-clius
Copy link
Contributor

Note that I added message signing for completeness, since it feels weird that the node can validate signed messages but not publish them.

I think the concept here is that from the nodes perspective it simply receives messages from the app (e.g. via the API) and publishes as-is. I also don't think the "node" should therefore do the validation - just be configurable to accept validation vectors from the app of which it is agnostic, therefore allowing app-defined validation.

@alrevuelta alrevuelta force-pushed the dos-signed-topic branch 4 times, most recently from a5d5c41 to 511c346 Compare March 23, 2023 09:46
@alrevuelta
Copy link
Contributor Author

@jm-clius removed signing of messages and moved everything to the app.

@jm-clius
Copy link
Contributor

Thanks for addressing the app-node separation concerns. I think this will work and keeps the node clean of application-level knowledge. One thing to note is that this still require the inverse (node/protocol-level knowledge on the application, e.g. the app "knowing" about node.wakuRelay and relay validators). This may just be an OK tradeoff to keep things simple for now?

If we need a more general approach I'd suggest something like defining the concept of an app-level validation function, which the node gets constructed with. When relay then gets constructed and mounted, it "translates" these app-defined validations to relay validators and adds them to its set. This would allow the app to remain ignorant of protocol/relay concepts and the protocol/relay to remain ignorant of app concepts (as it is in your implementation).

This idea would require a bit more structure so is perhaps overkill for now, but perhaps useful if we need general app-level validation in future.

The most important concern left then, I think, is to address the naming of the field we add to the WakuMessage. I don't think it should be a signature, as the protocol should be unaware of what this field contains. What do you think about appdata (or any better suggestions)?

@LNSD
Copy link
Contributor

LNSD commented Mar 23, 2023

Please, @alrevuelta, could you answer my questions in the associated issue?

@alrevuelta
Copy link
Contributor Author

The most important concern left then, I think, is to address the naming of the field we add to the WakuMessage. I don't think it should be a signature, as the protocol should be unaware of what this field contains. What do you think about appdata (or any better suggestions)?

Very open for namings. Have the feeling that appdata would be interpreted as the same as the existing meta defined as # Application specific metadata.. Perhaps it can be named validityProof and reused by also rln or future validators.

This idea would require a bit more structure so is perhaps overkill for now, but perhaps useful if we need general app-level validation in future.

Since the future of this feature is not very clear and I'm also figuring things out along the way, I would prefer to prioritize validating it + moving forward with scoring + trimming connections. Actually I wouldn't mind having a dedicated branch for this complete feature, where functionality >> convenctions, processes, patterns, etc. This would allow to iterate faster and first validate the idea before spending time in things that may be discarded. Once the idea is validated with a bunch of learnings along the way, it can be materialized in production ready code. wdyt?

@alrevuelta
Copy link
Contributor Author

As agreed in a meeting, this PR will use the new meta field to store the signuture instead of creating a new field. Once the new meta is in place, this PR will use it.

@alrevuelta alrevuelta marked this pull request as ready for review March 31, 2023 08:32
@alrevuelta alrevuelta changed the title feat: dos protected topic with optional signed msgs feat: dos protected topic relay msgs based on meta field Mar 31, 2023
@alrevuelta
Copy link
Contributor Author

Using now the meta field + new app hash function as discussed, tested and ready to rumble.
can I get a review @jm-clius @LNSD ?
will follow up with metrics + cli config in upcoming PRs.

Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

Approving to not block and require re-review, but comment below should be addressed first - think it's just something that went wrong when merging

waku/v2/node/waku_node.nim Outdated Show resolved Hide resolved
waku/v2/node/waku_node.nim Outdated Show resolved Hide resolved
waku/v2/node/waku_node.nim Outdated Show resolved Hide resolved
waku/v2/protocol/waku_relay/protocol.nim Outdated Show resolved Hide resolved
waku/v2/protocol/waku_message/message.nim Outdated Show resolved Hide resolved
Comment on lines 387 to 396
except CatchableError:

# Get this from cli
var topicsPublicKeys = initTable[string, SkPublicKey]()

# Add validation keys to protected topics
for topic, publicKey in topicsPublicKeys.pairs:
info "routing only signed traffic", topic=topic, publicKey=publicKey
node.wakuRelay.addSignedTopicValidator(Pubsubtopic(topic), publicKey)
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure this is a faulty merge conflict resolution. This should not be part of the except CatchableError block and the error-less except in L396 should be except CatchableError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, very good catch thanks.

@alrevuelta
Copy link
Contributor Author

@jm-clius addressed your last comment thanks!

can see other 5 commnets made at the same time but in old code, weird. i assume you resolved them and there is noting to address there, since it was already addressed before.

image

@alrevuelta alrevuelta merged commit c26dcb2 into master Apr 4, 2023
@alrevuelta alrevuelta deleted the dos-signed-topic branch April 4, 2023 08:58
@fryorcraken fryorcraken added the E:Opt-in message signing See https://github.com/waku-org/pm/issues/20 for details label Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E:Opt-in message signing See https://github.com/waku-org/pm/issues/20 for details
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants