Skip to content

Commit

Permalink
Merge pull request #682 from q384566678/add-selinux
Browse files Browse the repository at this point in the history
Add SELinux Check
  • Loading branch information
liangchenye authored Feb 18, 2019
2 parents f611b4e + 743b0b3 commit d4ec5b8
Show file tree
Hide file tree
Showing 10 changed files with 1,676 additions and 0 deletions.
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")
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

0 comments on commit d4ec5b8

Please sign in to comment.