Skip to content

Commit e0df0fd

Browse files
authored
Merge pull request #491 from cyphar/validate-fix-type-whitelist
validate: allow unset "type" fields in resource devices whitelist
2 parents 6554add + 6df06d9 commit e0df0fd

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

generate/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func New() Generator {
4141
spec := rspec.Spec{
4242
Version: rspec.Version,
4343
Root: &rspec.Root{
44-
Path: "",
44+
Path: "rootfs",
4545
Readonly: false,
4646
},
4747
Process: &rspec.Process{

validate/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ func (v *Validator) CheckLinuxResources() (errs error) {
749749
}
750750
for index := 0; index < len(r.Devices); index++ {
751751
switch r.Devices[index].Type {
752-
case "a", "b", "c":
752+
case "a", "b", "c", "":
753753
default:
754754
errs = multierror.Append(errs, fmt.Errorf("type of devices %s is invalid", r.Devices[index].Type))
755755
}

validation/generate_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package validation
2+
3+
import (
4+
"io/ioutil"
5+
"os"
6+
"path/filepath"
7+
"runtime"
8+
"testing"
9+
10+
rfc2119 "github.com/opencontainers/runtime-tools/error"
11+
"github.com/opencontainers/runtime-tools/generate"
12+
"github.com/opencontainers/runtime-tools/specerror"
13+
"github.com/opencontainers/runtime-tools/validate"
14+
)
15+
16+
// Smoke test to ensure that _at the very least_ our default configuration
17+
// passes the validation tests. If this test fails, something is _very_ wrong
18+
// and needs to be fixed immediately (as it will break downstreams that depend
19+
// on us for a "sane default" and do compliance testing -- such as umoci).
20+
func TestGenerateValid(t *testing.T) {
21+
bundle, err := ioutil.TempDir("", "TestGenerateValid_bundle")
22+
if err != nil {
23+
t.Fatal(err)
24+
}
25+
defer os.RemoveAll(bundle)
26+
27+
// Create our toy bundle.
28+
rootfsPath := filepath.Join(bundle, "rootfs")
29+
if err := os.Mkdir(rootfsPath, 0755); err != nil {
30+
t.Fatal(err)
31+
}
32+
configPath := filepath.Join(bundle, "config.json")
33+
g := generate.New()
34+
if err := (&g).SaveToFile(configPath, generate.ExportOptions{Seccomp: false}); err != nil {
35+
t.Fatal(err)
36+
}
37+
38+
// Validate the bundle.
39+
v, err := validate.NewValidatorFromPath(bundle, true, runtime.GOOS)
40+
if err != nil {
41+
t.Errorf("unexpected NewValidatorFromPath error: %+v", err)
42+
}
43+
if err := v.CheckAll(); err != nil {
44+
levelErrors, err := specerror.SplitLevel(err, rfc2119.Must)
45+
if err != nil {
46+
t.Errorf("unexpected non-multierror: %+v", err)
47+
return
48+
}
49+
for _, e := range levelErrors.Warnings {
50+
t.Logf("unexpected warning: %v", e)
51+
}
52+
if err := levelErrors.Error; err != nil {
53+
t.Errorf("unexpected MUST error(s): %+v", err)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)