Skip to content

Conversation

@TrumanLing
Copy link
Contributor

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]

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\-\.\_]+?$`)
Copy link
Contributor

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.

Copy link
Contributor Author

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)
}
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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:

  1. If you run your check too early, you might not check anything and have invalid refs injected here slip through without getting caught.
  2. 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.

Copy link
Contributor Author

@TrumanLing TrumanLing Oct 31, 2016

Choose a reason for hiding this comment

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

I agree with you, but I updated it here, because ref is used starting from here.

}

func unpack(w walker, dest, refName string) error {
if err := refsNameRegexpCheck(refName); err != nil {
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 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.

Copy link
Contributor Author

@TrumanLing TrumanLing Oct 31, 2016

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.

Copy link
Contributor

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).

Copy link
Contributor Author

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]>
@vbatts
Copy link
Member

vbatts commented Feb 8, 2017

failures in make lint

@wking
Copy link
Contributor

wking commented Feb 8, 2017 via email

@xiekeyang
Copy link
Contributor

Close for opencontainers/image-spec#533

@xiekeyang xiekeyang closed this Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants