Skip to content

Commit d4ec5b8

Browse files
authored
Merge pull request #682 from q384566678/add-selinux
Add SELinux Check
2 parents f611b4e + 743b0b3 commit d4ec5b8

File tree

10 files changed

+1676
-0
lines changed

10 files changed

+1676
-0
lines changed

Godeps/Godeps.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/runtimetest/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/opencontainers/runtime-tools/cmd/runtimetest/mount"
2525
rfc2119 "github.com/opencontainers/runtime-tools/error"
2626
"github.com/opencontainers/runtime-tools/specerror"
27+
"github.com/opencontainers/selinux/go-selinux/label"
2728

2829
"golang.org/x/sys/unix"
2930
)
@@ -1196,6 +1197,27 @@ func (c *complianceTester) validatePosixMounts(spec *rspec.Spec) error {
11961197
return mountErrs
11971198
}
11981199

1200+
func (c *complianceTester) validateMountLabel(spec *rspec.Spec) error {
1201+
if spec.Linux == nil || spec.Linux.MountLabel == "" {
1202+
c.harness.Skip(1, "linux.mountlabel not set")
1203+
return nil
1204+
}
1205+
1206+
for _, mount := range spec.Mounts {
1207+
fileLabel, err := label.FileLabel(mount.Destination)
1208+
if err != nil {
1209+
return fmt.Errorf("Failed to get mountLabel of %v", mount.Destination)
1210+
}
1211+
c.harness.Ok(spec.Linux.MountLabel == fileLabel, "has expected mountlabel")
1212+
c.harness.YAML(map[string]string{
1213+
"expected": spec.Linux.MountLabel,
1214+
"actual": fileLabel,
1215+
})
1216+
}
1217+
1218+
return nil
1219+
}
1220+
11991221
func run(context *cli.Context) error {
12001222
logLevelString := context.String("log-level")
12011223
logLevel, err := logrus.ParseLevel(logLevelString)
@@ -1256,6 +1278,7 @@ func run(context *cli.Context) error {
12561278
c.validateSysctls,
12571279
c.validateUIDMappings,
12581280
c.validateGIDMappings,
1281+
c.validateMountLabel,
12591282
}
12601283

12611284
validations := defaultValidations

validate/validate_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
rspec "github.com/opencontainers/runtime-spec/specs-go"
1717
osFilepath "github.com/opencontainers/runtime-tools/filepath"
1818
"github.com/opencontainers/runtime-tools/specerror"
19+
"github.com/opencontainers/selinux/go-selinux/label"
1920
"github.com/sirupsen/logrus"
2021
)
2122

@@ -226,5 +227,11 @@ func (v *Validator) CheckLinux() (errs error) {
226227
}
227228
}
228229

230+
if v.spec.Linux.MountLabel != "" {
231+
if err := label.Validate(v.spec.Linux.MountLabel); err != nil {
232+
errs = multierror.Append(errs, fmt.Errorf("mountLabel %v is invalid", v.spec.Linux.MountLabel))
233+
}
234+
}
235+
229236
return
230237
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"github.com/opencontainers/runtime-tools/validation/util"
5+
)
6+
7+
func main() {
8+
g, err := util.GetDefaultGenerator()
9+
if err != nil {
10+
util.Fatal(err)
11+
}
12+
g.SetLinuxMountLabel("system_u:object_r:svirt_sandbox_file_t:s0:c715,c811")
13+
err = util.RuntimeInsideValidate(g, nil, nil)
14+
if err != nil {
15+
util.Fatal(err)
16+
}
17+
}

vendor/github.com/opencontainers/selinux/LICENSE

Lines changed: 201 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)