-
Notifications
You must be signed in to change notification settings - Fork 275
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
Metadata API: make Root roles a Mapping #1668
Metadata API: make Root roles a Mapping #1668
Conversation
Mark roles as a Mapping to indicate that users should not add or remove values from the dictionary during the lifetime of the Root object) Signed-off-by: Martin Vrachev <[email protected]>
@jku your suggestion:
I tried implementing it, but then I realized that If I am given |
Pull Request Test Coverage Report for Build 1472701943Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
METPATHs and TARGETPATHs are not validated that are strings as per specification they can't be anything else but a string. I am still wondering if we should create a sanity check that you can't use |
sorry, I don't understand the connection here. Why do you need to map keys to roles in a constructor? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
METPATHs and TARGETPATHs are not validated that are strings as per specification they can't be anything else but a string.
We're trying to validate that data we got is according to spec, and should not assume that things are strings because spec says so... that said, I too am unsure about type checks: I've been negative about them but am beginning to think we might want to do type checks for dictionary keys as those never get checked by other code (as most other types do). More on that in code comment.
I am still wondering if we should create a sanity check that you can't use
targets
as a TARGETPATH...
Sorry, I don't understand this.
tuf/api/metadata.py
Outdated
if any(meta_path == "" for meta_path in meta): | ||
raise ValueError("All meta paths must be non-empty strings") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you originally suggested checking that "meta_path is a non-empty string": now you check that "metapath is not an empty string". These are subtly different as the former includes type checking and the implemented check is so specific that I don't think it's worth two lines of code.
I'm still not sure how much type checking we actually should do... maybe we should validate the dictionary key types as that doesn't happen "implicitly" like it tends to happen for other data that is wrongly typed. If we don't do that we could deserialize (and then later serialize) data that is not actually valid metadata
I was unclear with my statement. I meant the JSON format spec which doesn't allow non-string keys for dictionaries |
Oh this is a really good point! we're supposedly format-independent so maybe shouldn't trust this ... but it's still a convincing argument |
I think you are correct that if we want to be able to easily switch to a new format it's better if we do the type checks. |
Supporting a new format is not going to be easy whatever we do (with the way the spec is written)... so I'd rather avoid investing any lines of code in that right now. Maybe just fix the bug with meta keys and make sure the check that prevents using toplevel filenames (except targets) is as simple as possible: Could build a private list/set of _invalid_snapshot_meta_keys at metadata.py import time (maybe a snapshot private class variable) and then use that list in snapshot init, for example. Speaking of simplicity I've been thinking about this and I think checking empty string for meta keys (or even checking whether the string ends in ".json") might not be that useful? It does not guarantee the key is a real filename or even that it's a safe filename... In any case meta should only be used like this For target paths the empty string check could make sense, especially if this is mentioned in the spec... I can't find that reference though, is this really in the spec? |
I haven't spent time on this issue for a while, but which bug do you mean?
Will try it, good idea.
I agree. At some point, we would want to open what's inside meta keys and if there is an empty string there will be an OSError.
I don't find it explicitly mentioned either. |
Current PR is, I believe, preventing meta keys from being toplevel rolenames. That is not relevant: meta keys being toplevel role filenames could be a problem. That said, now that I look at this and #1558 together I'm wondering if this PR is worth it overall: meta keys are never meant to be iterated over, client always looks up data from meta with a key constructed with I think I'm fine with closing this (or just doing the Dict->Mapping change) in favor of #1158. What do you think? |
After a discussion with @jku we decided that:
meaning DelegatedRole names are actually used to open files
Because of those reasons, I will drop the other commits which validate TARGETPATH and METAPATH and will leave only the first one. |
8b21020
to
29da5da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for going through the steps so we could figure out what we actually wanted here
Fixes #1356
Description of the changes being introduced by the pull request:
This pr includes a couple of smaller changes:
Mapping
to indicate that users should not add or removevalues from the dictionary during the lifetime of the Root object
EDIT: Those two were included in the initial version of the pr.
Then together with @jku we agreed we don't want to do that.
See my comment #1668 (comment)
Please verify and check that the pull request fulfills the following
requirements: