unit tests to check privileged mode

This commit is contained in:
Brad Rydzewski
2020-08-17 22:54:55 -04:00
parent e2dada588c
commit 8a8164e2de
2 changed files with 51 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ package compiler
import (
"context"
"path/filepath"
"strings"
"github.com/drone-runners/drone-runner-docker/engine"
@@ -462,6 +463,18 @@ func (c *Compiler) isPrivileged(step *resource.Step) bool {
if len(step.Entrypoint) > 0 {
return false
}
for _, mount := range step.Volumes {
path, _ := filepath.Abs(mount.MountPath)
path = strings.ToLower(path)
switch {
case path == "/":
return false
case path == "/var":
return false
case strings.Contains(path, "/var/run"):
return false
}
}
// if the container image matches any image
// in the whitelist, return true.
for _, img := range c.Privileged {