Skip to content
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

validate: allow unset "type" fields in resource devices whitelist #491

Merged
merged 3 commits into from
Oct 24, 2017

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Sep 30, 2017

According to the spec, an unset .Type field in the
.Linux.Resources.Devices list is permitted (and it maps to "all").
This was broken recently, making our own default profile (as well as
umoci's and runc's) not pass validation anymore.

Signed-off-by: Aleksa Sarai asarai@suse.de

@cyphar
Copy link
Member Author

cyphar commented Sep 30, 2017

CI failure is caused by a build failure I cannot reproduce on my local machine.

@wking
Copy link
Contributor

wking commented Oct 1, 2017

Build failures were fixed by #490.

The check you're patching is from #374, and I think we can drop at least the Type check in favor of JSON Schema (with opencontainers/runtime-spec#690 hopefully landing soon ;). But if we want local code until that lands, this change looks fine to me.

@cyphar
Copy link
Member Author

cyphar commented Oct 1, 2017

I've commented on opencontainers/runtime-spec#690, which currently has the same bug as the one I'm fixing here. But since it might take a while to land in runtime-spec, we should fix this bug as currently our validation isn't even consistent with our own defaults (which really shouldn't have happened in the first place -- don't we test that our own default configuration is compliant?).

@wking
Copy link
Contributor

wking commented Oct 1, 2017

... don't we test that our own default configuration is compliant?

+1 to unit tests for this code, runtime-tools is currently sparsely-tested.

I'm fine with either this PR or dropping the local Type check with the expection that opencontainers/runtime-spec#690 will land soon. I don't think anyone is in favor of keeping the overly-strict local test we have in master now.

@cyphar
Copy link
Member Author

cyphar commented Oct 2, 2017

Rebased, added the smoke test, and corrected another bug in our default configuration.

@@ -206,11 +206,6 @@ func (v *Validator) CheckRoot() (errs error) {
return
}

if filepath.Base(v.spec.Root.Path) != "rootfs" {
errs = multierror.Append(errs,
specerror.NewError(specerror.PathName, fmt.Errorf("path name should be the conventional 'rootfs'"), rspec.Version))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a spec SHOULD, and removing it is why your Travis tests fail. I think we need to keep this check, and users that don't care about SHOULD-level violations can ignore those errors like this.

Copy link
Member Author

@cyphar cyphar Oct 2, 2017

Choose a reason for hiding this comment

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

I know it's a SHOULD. But CheckAll doesn't appear to understand that SHOULD doesn't mean MUST. The following error happens:

=== RUN   TestGenerateValid
--- FAIL: TestGenerateValid (0.52s)
        generate_test.go:42: unexpected error(s) validating default: 1 error occurred:

                * path name should be the conventional 'rootfs'
                Refer to: https://github.com/opencontainers/runtime-spec/blob/v1.0.0/config.md#root

And this means that oci-runtime-tool validate returns a non-zero error code.

Copy link
Contributor

Choose a reason for hiding this comment

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

But CheckAll doesn't appear to understand that SHOULD doesn't mean MUST.

CheckAll shouldn't care; it's up to the caller to decide what is fatal or not. Using rootfs in the default config should be enough for your TestGenerateValid. cmd/oci-runtime-tool/validate.go needs a --compliance-level like runtimetest (which may be in flight somewhere, I don't have my dev box handy to grep open PRs).

Copy link
Contributor

Choose a reason for hiding this comment

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

cmd/oci-runtime-tool/validate.go needs a --compliance-level like runtimetest (which may be in flight somewhere, I don't have my dev box handy to grep open PRs).

I couldn't find this in flight, so I filed it as #492.

@cyphar cyphar force-pushed the validate-fix-type-whitelist branch from f9de4c6 to 4d6860d Compare October 10, 2017 12:23
@cyphar
Copy link
Member Author

cyphar commented Oct 10, 2017

Rebased off #492.

levelErrors, err2 := specerror.SplitLevel(err, rfc2119.Must)
if err2 != nil {
t.Errorf("unexpected error(s) filtering errors default: %+v", err2)
t.Errorf("unexpected error(s): %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

What you call err2 will only ever be non-nil if it exactly matches the input error. So I think you want to drop the previous line and keep only this one to avoid redundancy. Perhaps the SplitLevel comment can also be improved to make this more clear?

@cyphar cyphar force-pushed the validate-fix-type-whitelist branch from 4d6860d to 27ad856 Compare October 14, 2017 03:34
Copy link
Contributor

@wking wking left a comment

Choose a reason for hiding this comment

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

One long-term concern, but I don't see anything that would hold back merging.

}

// Validate the bundle.
v, err := validate.NewValidatorFromPath(bundle, true, runtime.GOOS)
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 excited about the asymmetry between unparmeterized generation and host-specific validation. This will cerainly die if runtime.GOOS is not Linux. It may die even on Linux if the host system is sufficiently ancient or the stock config becomes sufficiently demanding. But I'm ok crossing those bridges later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want me to set the OS explicitly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want me to set the OS explicitly?

I'm fine leaving it as it stands, as a reminder that New will need similar options when we get our first non-Linux user and/or stabilize the API.

According to the spec, an unset .Type field in the
.Linux.Resources.Devices list is permitted (and it maps to "all").
This was broken recently, making our own default profile (as well as
umoci's and runc's) not pass validation anymore.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
It doesn't make sense for us to not include a rootfs in
our default configuration -- as it means that we're providing an
invalid configuration.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
To avoid cases where our own validation code would consider our defaults
unsafe (which has happened in the past several times), add a smoke-test
to ensure that this won't happen. Our defaults should not be
intentionally invalid, as that confuses downstreams like umoci which use
runtime-tools for the default as well as for validation of the generated
configuration.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
@cyphar cyphar force-pushed the validate-fix-type-whitelist branch from 27ad856 to 6df06d9 Compare October 23, 2017 22:35
@cyphar
Copy link
Member Author

cyphar commented Oct 23, 2017

/ping @opencontainers/runtime-tools-maintainers

@Mashimiao
Copy link

Mashimiao commented Oct 24, 2017

LGTM

Approved with PullApprove

1 similar comment
@hqhq
Copy link
Contributor

hqhq commented Oct 24, 2017

LGTM

Approved with PullApprove

@hqhq hqhq merged commit e0df0fd into opencontainers:master Oct 24, 2017
@cyphar cyphar deleted the validate-fix-type-whitelist branch October 24, 2017 03:26
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