-
Notifications
You must be signed in to change notification settings - Fork 278
Metadata API: Provide a way to validate object when serializing to dictionary #1696
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
Comments
I decided to create one prototype of a possible solution: https://github.com/MVrachev/tuf/tree/serialization-validation. |
I agree with the basic premise: we'll want to re-evaluate whether our validation is appropriate for the serialization as well (while we've been concentrating on the client case, the focus has been on validating deserialized data). some quick comments:
|
I'll rephrase this to be more specific: Ideally we want to guarantee not just that our internal data structures are correct at serialization time, but that our serialization output is valid and that we can succesfully deserialize that output. |
I see many advantages to that approach:
So, I like the idea and I can volunteer for the next sprint to implement it. The only question that remains is do we need to think for an API or a way to do a deeper serialization functionality as this one:
or maybe we don't actually as during an update with |
This is unlikely to get implemented in a single sprint but a design doc or prototype or some infrastructure work might be a good idea (I have no idea how much work there is in adding the eq() implementations as an example).
Loading (deserializing) validation should fail only if the there is a compliance or safety issue... and I think that's a good rule for serialization as well: deciding that implementations aren't allowed to add keys without using them doesn't clearly improve safety but it could be annoying to the repository implementers who want do it for whatever reasons. Checks like that would make definitely make sense in repository implementations... and possibly even in a repository library. |
We should test how much slower it will get when using this kind of validation. |
I created a prototype in my branch here https://github.com/MVrachev/tuf/tree/validation-during-serialization. |
As a prototype that's pretty much what I was imagining: definitely good enough to make some sort of a decision
Overall: looks like a reasonable direction to me but let's discuss with others too. |
Even if we decide to leave it as a separate API call I think it could be useful.
It's becasue the
|
Thinking a bit further: the prototype ends up calling |
Added a validation constructor argument in |
Thanks for working on this, @MVrachev and @jku! I just caught up on your discussion and read through the prototype and I like it! I also think that |
@lukpueh do you think it should be an argument or it's okay to do it during initialization? My question towards both of you @jku and @lukpueh is how do you think we should move forward? |
Initialization of what? Regardless, given the computational cost of the validation, I'd make it optional.
No. I think this is something specific to JSONSerializer.
Yes.
Do you have something on your mind? I think this sounds good for the time being.
It would make 1.0.0 stronger. But I also see no problem in adding this in a subsequent minor release. Let's prioritize things that need to go into 1.0.0. |
There are two options on how to call the validation through the
I think the first option makes more sense as once a
No, I don't have anything else in pat
I think it makes sense to include it in |
Oh right, I remember. The first option is also consistent with how we configure python-tuf/tuf/api/metadata.py Lines 242 to 249 in 059bfda
Given the computational cost of validation I lean towards a default of metadata.to_bytes(JSONSerializer(compact=True, validate=True)) We can discuss this more on the PR. |
Agreed with the discussion above:
|
Add Signature.__eq__() method to support comparison between signature objects. The need for this method came when solving issue #1696 in TUF and more precisely read: theupdateframework/python-tuf#1696 (comment) Issue #1696 in TUF is about adding validation API after metadata object initialization and because signatures in TUF are dictionaries whose values are Signature objects they need for Signature.__eq__() the method became apparent. Signed-off-by: Martin Vrachev <[email protected]>
Add Signature.__eq__() method to support comparison between signature objects. The need for this method came when solving issue #1696 in TUF and more precisely read: theupdateframework/python-tuf#1696 (comment) Issue #1696 in TUF is about adding validation API after metadata object initialization and because signatures in TUF are dictionaries whose values are Signature objects they need for Signature.__eq__() the method became apparent. Signed-off-by: Martin Vrachev <[email protected]>
Add Signature.__eq__() method to support comparison between signature objects. The need for this method came when solving issue #1696 in TUF and more precisely read: theupdateframework/python-tuf#1696 (comment) Issue #1696 in TUF is about adding validation API after metadata object initialization and because signatures in TUF are dictionaries whose values are Signature objects they need for Signature.__eq__() the method became apparent. Signed-off-by: Martin Vrachev <[email protected]>
Description of issue or feature request:
This issue is discussed during a couple of conversations with @jku.
We can say we are almost done with Metadata API validation during the initialization of
Signed
objects as summarized here: #1140 (comment).What we didn't focus on is validation when serializing the
Signed
objects to dictionaries throughSigned.to_dict()
.This could be useful for users of Metadata API that changed the signed portion
I imagine some of the requirements for such validation are:
One thing to consider is doing we want to add a little more complex validation, additional to the one done during initialization.
For example, for Root, it probably could be useful to validate that each of the set of
keyid
s defined in thekeys
dictionary is all used inside a particular role inroles
.Current behavior:
No validation is done when calling
to_dict()
from any of theSigned
child classes.Expected behavior:
Provide a way to validate an object before calling
to_dict()
or when callingto_dict()
with an explicit option set.PS: I didn't include the signatures part from the Metadata objects in this discussion as their validation is a little more complex as you need access to the delegator.
The text was updated successfully, but these errors were encountered: