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

Support SELinux Check #386

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

19 changes: 19 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 @@ -778,6 +779,20 @@ func validatePosixMounts(spec *rspec.Spec) error {
return mountErrs
}

func validateMountLabel(spec *rspec.Spec) error {
for _, mount := range spec.Mounts {
fileLabel, err := label.GetFileLabel(mount.Destination)
if err != nil {
return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination)
}
if spec.Linux != nil && fileLabel != spec.Linux.MountLabel {
return fmt.Errorf("Expected mountLabel %v, actual %v", spec.Linux.MountLabel, fileLabel)
}
}

return nil
}

func run(context *cli.Context) error {
logLevelString := context.String("log-level")
logLevel, err := logrus.ParseLevel(logLevelString)
Expand Down Expand Up @@ -880,6 +895,10 @@ func run(context *cli.Context) error {
test: validateGIDMappings,
description: "gid mappings",
},
{
test: validateMountLabel,
description: "mountLabel",
},
}

t := tap.New()
Expand Down
7 changes: 7 additions & 0 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/go-multierror"
rspec "github.com/opencontainers/runtime-spec/specs-go"
osFilepath "github.com/opencontainers/runtime-tools/filepath"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/sirupsen/logrus"
"github.com/syndtr/gocapability/capability"

Expand Down Expand Up @@ -762,6 +763,12 @@ func (v *Validator) CheckLinux() (errs error) {
}
}

if v.spec.Linux.MountLabel != "" {
if err := label.Validate(v.spec.Linux.MountLabel); 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 sure what label.Validate is checking, but the spec places no limits on the linux.mountLabel value. If we want to validate it (against a particular kernel API?), then I think we probably need clarity in the spec about what API the value will be passed to, and the check here should probably only happen when HostSpecific is set.

Copy link
Author

Choose a reason for hiding this comment

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

The validation of mountLabel is not host-specific. It just checks whether label contains unexpected options. Please refer to label.Validate()

Copy link
Contributor

Choose a reason for hiding this comment

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

It just checks whether label contains unexpected options.

But there is nothing in the spec about “MUST be a valid SELinux label according to [some SELinux spec]” or “MUST NOT contain z or Z” or anything like that. Currently spec-readers have to make that jump on their own.

And I was suggesting host-specific because even if z and Z are not legal labels for today's kernel, are we sure that they will be illegal labels for all kernels? Maybe someone compiles a Linux kernel where they are legal, and the spec's kernel-punt-where-possible approach is designed to support that sort of thing.

Copy link
Contributor

@wking wking Sep 28, 2017

Choose a reason for hiding this comment

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

I still don't see spec grounds for this check, but if the runtime-tools maintainers feel like it's grounded (or if they just want “unlikely to be supported by the kernel” warnings), then the validate/ changes from this PR belong in v0.3.0. That could either happen by spinning them out into a new PR, or by reviewing them here in the context of the runtimetest changes.

errs = multierror.Append(errs, fmt.Errorf("mountLabel %v is invalid", v.spec.Linux.MountLabel))
}
}

return
}

Expand Down
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.

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

Loading