feat(rpc): network verification via commitment header#1084
feat(rpc): network verification via commitment header#1084Mirko-von-Leipzig merged 21 commits intonextfrom
Conversation
37be2c3 to
55a9e6a
Compare
55a9e6a to
61fb917
Compare
ce9ba13 to
b1324ec
Compare
| }; | ||
| assert_eq!(AcceptHeaderValue::try_from(input), Ok(expected)); | ||
| let uut = HeaderVerificationLayer::for_tests(); | ||
| uut.verify(&headers).unwrap_err(); |
There was a problem hiding this comment.
Could we test the exact error variants coming out? Given you have created the error enums now.
There was a problem hiding this comment.
We can; but I'm not sure that adds any specific value?
For example, in the case where both mismatch, which error should it be? Could be either..
There was a problem hiding this comment.
For example, in the case where both mismatch, which error should it be? Could be either..
It would be well defined which error would be returned if both mismatched. Checking the error proves our logic is working precisely as expected. We could erroneously return invalid semver variant for an input with a correct semver for example. Unless I'm missing something.
There was a problem hiding this comment.
I had a crack at adding the expected error variants into the cases but I think its blocked on variants like
VersionParsing(#[source] semver::Error, String),Because semver::Error and its constructors etc are not public so we can't recreate them for the tests.
bobbinth
left a comment
There was a problem hiding this comment.
Thank you! Looks good! Not a review but I did leave a couple of questions/comments inline.
This does add an additional header, and maybe instead we should add it to the
acceptheader? I'm just unsure what this format should look like; and we probably want to do additional parsing instead.
I haven't thought about it too much, but it does feel like maybe handling everything through the accept header is a bit more "natural" - i.e., we have a single header which tells us if the request should be accepted or rejected.
On the other hand, this probably complicates parsing a bit and makes it more difficult to handle partial scenarios (e.g., missing version info but present genesis commitment or vise-versa). But it is also not clear if we should care about partial scenarios - and in that case, maybe channeling everything through the accept header is a better option.
7325d95 to
1a25c73
Compare
|
I'm most of the way there, but I'm converting to draft until its done properly to spare you looking at it for no reason. As a short summary of my intentions:
|
1a25c73 to
bee1a0f
Compare
86f569a to
bbe039e
Compare
|
I've refactored this to use an external crate and revert the version requirements to what they were before. I've also updated the description to match the current reality. If you could re-review please :) |
bbe039e to
e654322
Compare
| let supported_versions = VersionReq { | ||
| comparators: vec![Comparator { | ||
| op: semver::Op::Exact, | ||
| major: rpc_version.major, | ||
| minor: rpc_version.minor.into(), | ||
| patch: None, | ||
| pre: semver::Prerelease::default(), | ||
| }], | ||
| }; |
There was a problem hiding this comment.
I'm a bit on the fence about this; but I've left the current behavior as is.
The issue is that its a bit back-to-front. The client should be indicating which versions they're compatible with. For example, their RPC version might be patch compatible with our server's but they may require a new feature or addition that we introduced.
Its easy to do by swapping the client and server types around. The downside is that client's need to think a bit more about what they want.
There was a problem hiding this comment.
I think this is fine for now, but I would create an issue to revisit this in the future because in principle I agree: the client should be specifying the version that it is compatible with and if the node is within this specifications, the request should be accepted.
e654322 to
61aca21
Compare
bobbinth
left a comment
There was a problem hiding this comment.
Looks good! Thank you! I left a couple of small comments inline.
5157d20 to
cf11dfd
Compare
bobbinth
left a comment
There was a problem hiding this comment.
All looks good! Thank you!
This PR adds support for verifying the network identity for RPC clients.
This PR also changes the existing format for the version checking:
The now obsolete format gets rejected now which I think is okay. The new format still allows for an optional
+grpcsuffix.The original version checking behavior is retained, though we may want to consider switching to
Caretinstead ofExactbut that's separate from this addition.This PR also improves the correctness of the accept header verification by:
*/*andapplication/*media-typesq=0Similar to the RPC version check added in #844, we now check the network the client thinks its on. The client can now set the genesis block's commitment in themiden-networkheader, and the RPC service will reject the request if there is a mismatch.This does add an additional header, and maybe instead we should add it to theacceptheader? I'm just unsure what this format should look like; and we probably want to do additional parsing instead.Closes #1066.