Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
| ... | ... |
@@ -783,6 +783,36 @@ func TestUnPrivilegedCanMknod(t *testing.T) {
|
| 783 | 783 |
logDone("run - test un-privileged can mknod")
|
| 784 | 784 |
} |
| 785 | 785 |
|
| 786 |
+func TestCapDropCannotMknod(t *testing.T) {
|
|
| 787 |
+ cmd := exec.Command(dockerBinary, "run", "--cap-drop=MKNOD", "busybox", "sh", "-c", "mknod /tmp/sda b 8 0 && echo ok") |
|
| 788 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 789 |
+ if err == nil {
|
|
| 790 |
+ t.Fatal(err, out) |
|
| 791 |
+ } |
|
| 792 |
+ |
|
| 793 |
+ if actual := strings.Trim(out, "\r\n"); actual == "ok" {
|
|
| 794 |
+ t.Fatalf("expected output not ok received %s", actual)
|
|
| 795 |
+ } |
|
| 796 |
+ deleteAllContainers() |
|
| 797 |
+ |
|
| 798 |
+ logDone("run - test --cap-drop=MKNOD cannot mknod")
|
|
| 799 |
+} |
|
| 800 |
+ |
|
| 801 |
+func TestCapAddCanDownInterface(t *testing.T) {
|
|
| 802 |
+ cmd := exec.Command(dockerBinary, "run", "--cap-add=NET_ADMIN", "busybox", "sh", "-c", "ip link set eth0 down && echo ok") |
|
| 803 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 804 |
+ if err != nil {
|
|
| 805 |
+ t.Fatal(err, out) |
|
| 806 |
+ } |
|
| 807 |
+ |
|
| 808 |
+ if actual := strings.Trim(out, "\r\n"); actual != "ok" {
|
|
| 809 |
+ t.Fatalf("expected output ok received %s", actual)
|
|
| 810 |
+ } |
|
| 811 |
+ deleteAllContainers() |
|
| 812 |
+ |
|
| 813 |
+ logDone("run - test --cap-add=NET_ADMIN can set eth0 down")
|
|
| 814 |
+} |
|
| 815 |
+ |
|
| 786 | 816 |
func TestPrivilegedCanMount(t *testing.T) {
|
| 787 | 817 |
cmd := exec.Command(dockerBinary, "run", "--privileged", "busybox", "sh", "-c", "mount -t tmpfs none /tmp && echo ok") |
| 788 | 818 |
|
| ... | ... |
@@ -67,5 +67,11 @@ func ContainerHostConfigFromJob(job *engine.Job) *HostConfig {
|
| 67 | 67 |
if VolumesFrom := job.GetenvList("VolumesFrom"); VolumesFrom != nil {
|
| 68 | 68 |
hostConfig.VolumesFrom = VolumesFrom |
| 69 | 69 |
} |
| 70 |
+ if CapAdd := job.GetenvList("CapAdd"); CapAdd != nil {
|
|
| 71 |
+ hostConfig.CapAdd = CapAdd |
|
| 72 |
+ } |
|
| 73 |
+ if CapDrop := job.GetenvList("CapDrop"); CapDrop != nil {
|
|
| 74 |
+ hostConfig.CapDrop = CapDrop |
|
| 75 |
+ } |
|
| 70 | 76 |
return hostConfig |
| 71 | 77 |
} |