Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/opencontainers/runtime-tools/cmd/runtimetest/mount"
rfc2119 "github.com/opencontainers/runtime-tools/error"
"github.com/opencontainers/runtime-tools/specerror"
"github.com/opencontainers/selinux/go-selinux/label"

"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -1196,6 +1197,27 @@ func (c *complianceTester) validatePosixMounts(spec *rspec.Spec) error {
return mountErrs
}

func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error {
if spec.Linux == nil || spec.Linux.MountLabel == "" {
c.harness.Skip(1, "linux.mountlabel not set")
return nil
}

for _, mount := range spec.Mounts {
fileLabel, err := label.FileLabel(mount.Destination)
if err != nil {
return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination)
}
c.harness.Ok(spec.Linux.MountLabel == fileLabel, "has expected mountlabel")
c.harness.YAML(map[string]string{
"expected": spec.Linux.MountLabel,
"actual": fileLabel,
})
}

return nil
}

func run(context *cli.Context) error {
logLevelString := context.String("log-level")
logLevel, err := logrus.ParseLevel(logLevelString)
Expand Down Expand Up @@ -1256,6 +1278,7 @@ func run(context *cli.Context) error {
c.validateSysctls,
c.validateUIDMappings,
c.validateGIDMappings,
c.validateMountLabel,
}

validations := defaultValidations
Expand Down
7 changes: 7 additions & 0 deletions validate/validate_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
rspec "github.com/opencontainers/runtime-spec/specs-go"
osFilepath "github.com/opencontainers/runtime-tools/filepath"
"github.com/opencontainers/runtime-tools/specerror"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -226,5 +227,11 @@ func (v *Validator) CheckLinux() (errs error) {
}
}

if v.spec.Linux.MountLabel != "" {
if err := label.Validate(v.spec.Linux.MountLabel); err != nil {
errs = multierror.Append(errs, fmt.Errorf("mountLabel %v is invalid", v.spec.Linux.MountLabel))
}
}

return
}
17 changes: 17 additions & 0 deletions validation/linux_mount_label/linux_mount_label.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"github.com/opencontainers/runtime-tools/validation/util"
)

func main() {
g, err := util.GetDefaultGenerator()
if err != nil {
util.Fatal(err)
}
g.SetLinuxMountLabel("system_u:object_r:svirt_sandbox_file_t:s0:c715,c811")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need an 'invalid mount label' test case as well.

err = util.RuntimeInsideValidate(g, nil, nil)
if err != nil {
util.Fatal(err)
}
}
201 changes: 201 additions & 0 deletions vendor/github.com/opencontainers/selinux/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading