-
Notifications
You must be signed in to change notification settings - Fork 85
Add regular expression match for ref string input #61
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
Conversation
| var gitCommit = "" | ||
|
|
||
| // refRegexp for string ref should be complied with description "Object names in the refs subdirectories MUST NOT include characters outside of the set of "A" to "Z", "a" to "z", "0" to "9", the hyphen -, the dot ., and the underscore _." at https://github.com/opencontainers/image-spec/blob/master/image-layout.md. | ||
| var refRegexp = regexp.MustCompile(`^[a-zA-Z0-9\-\.\_]+?$`) |
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.
This constant should probably be provided by image-spec, from which runtime-tools can import and use it.
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.
Thanks for your proposal, I will try to submit it in image-spec.
| if boolRefMatch != true { | ||
| v.stderr.Printf("ref name (%s) is invalid", v.ref) | ||
| os.Exit(1) | ||
| } |
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.
This probably belongs in image-layout validation like image/image.go's validate.
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.
IMHO, parameter ref input should be validated as early as possible, which can reduces unnecessary software execution.
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.
There is already [ref-oriented validation in image/image.go's validate/](https://github.com/TrumanLing/image-tools/blob/adbe39359bf2aac1aa01d3ce376036039c19fe32/image/image.go#L69). Adding that check here saves a few cycles in the oci-create-runtime-bundlecase, but completely misses the validation check in theoci-image-validatecase and the “library call toValidateLayout`” case.
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.
@wking Greate suggestion! But image/image.go's validate is for oci-image-validate, so I think, it is reasonable to add regular expression checks at the beginning of image/image.go's unpack, validate and createRuntimeBundle, which are separately for oci-unpack, oci-image-validate and oci-create-runtime-bundle.
image/image.go
Outdated
| } | ||
|
|
||
| func validate(w walker, refs []string, out *log.Logger) error { | ||
| var tmperr error |
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.
No need for tmperr. I'd rather have:
func validate(w walker, refs []string, out *log.Logger) (err error) {above, use err for refsNameRegexpCheck, and possibly shift an := → = below where we currently setup err.
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.
IMHO, the regular expression check should be at the beginning of the function. As for your recommendation, let the check below line := for err to avoid one more variable. But I think it is a little bit of breaking the logic with handling image validation, that means, the original func validate is for image validation, and not for parameter input check. So, I think the parameter check should be at the beginning, and the rest of code lines does its original operation, no insertion of other operation, even just only one line.
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.
IMHO, the regular expression check should be at the beginning of the function.
I hadn't thought about that, but not that you bring it up… ;). I think it should be here, because:
- If you run your check too early, you might not check anything and have invalid refs injected here slip through without getting caught.
- A ref not existing seems more important than not meeting the regexp.
I feel pretty strongly about (1), but not particularly strongly about (2). Regardless of how (2) goes, the check should be inside that loop. Perhaps the point that the validated refs may not be parameters (when they come from listReferences) is enough to allow closer integration between this regexp validation and the existing logic.
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.
| } | ||
|
|
||
| func unpack(w walker, dest, refName string) error { | ||
| if err := refsNameRegexpCheck(refName); err != nil { |
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.
I'm not convinced that we want to be doing validation as part of unpacking (folks who want it can call the validation code before calling unpack). But if that is not convincing, we can always add this for now, and remove it if/when someone gets around to filing a PR to pull the existing validation logic out of the unpacking code.
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.
I'm not convinced that we want to be doing validation as part of unpacking (folks who want it can call the validation code before calling unpack).
I agree with you, but we can't avoid user's typing error. So I think, it is needed.
But if that is not convincing, we can always add this for now, and remove it if/when someone gets around to filing a PR to pull the existing validation logic out of the unpacking code.
Currently we add it like this, if there is better solution in the future, we will change to the better one.
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.
On Sun, Oct 30, 2016 at 07:11:09PM -0700, TrumanLing wrote:
… but we can't avoid user's typing error…
That's not a problem. If the user typo's the ref name, unpacking will fail because the ref does not exist. Checking against the regexp in that case only “protects” you from the unlikely and presumably intentional case where the user is trying to unpack an illegal ref that already exists in the ref store. If the illegal ref is in the ref store it's not a compliant image, but I still think we should allow the user to unpack the ref (assuming the DAG it points to is unpackable).
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.
OK, I understand your concern. I will change it after PR in image-spec is merged, which leads to CI failure without merging it.
implementation for spec description "Object names in the refs subdirectories MUST NOT include characters outside of the set of "A" to "Z", "a" to "z", "0" to "9", the hyphen -, the dot ., and the underscore _." at https://github.com/opencontainers/image-spec/blob/master/image-layout.md. Signed-off-by: Ling FaKe <[email protected]>
|
failures in |
|
On Wed, Feb 08, 2017 at 11:29:27AM -0800, Vincent Batts wrote:
failures in `make lint`
Is it worth landing this for rc4 support with refs (and this
restriction on their names) now removed from the spec for the next
release [1] and no similar restriction on org.opencontainers.ref.name
values [2]? I think we should just close this PR and wait for someone
to file one with a more comprehensive catch-up to
opencontainers/image-spec#533.
[1]: https://github.com/opencontainers/image-spec/pull/533/files#diff-99bfcb610f238b942638d49d1ff2eaf4L58
[2]: https://github.com/opencontainers/image-spec/pull/533/files#diff-338aacf6337d00fc0cde843c3182c3f8R24
|
|
Close for opencontainers/image-spec#533 |
implementation for spec description "Object names in the refs
subdirectories MUST NOT include characters outside of the set of "A" to
"Z", "a" to "z", "0" to "9", the hyphen -, the dot ., and the underscore
_." at https://github.com/opencontainers/image-spec/blob/master/image-layout.md.
Signed-off-by: Ling FaKe [email protected]