Skip to content

Commit

Permalink
Implement privileged support
Browse files Browse the repository at this point in the history
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
  • Loading branch information
olljanat committed Aug 2, 2022
1 parent 7db07d0 commit af189fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions agent/exec/dockerapi/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func (c *containerConfig) hostConfig() *enginecontainer.HostConfig {
Isolation: c.isolation(),
CapAdd: c.spec().CapabilityAdd,
CapDrop: c.spec().CapabilityDrop,
Privileged: c.spec().Privileged,
}

// The format of extra hosts on swarmkit is specified in:
Expand Down
20 changes: 20 additions & 0 deletions agent/exec/dockerapi/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,26 @@ func TestCapabilityDrop(t *testing.T) {
}
}

func TestPrivileged(t *testing.T) {
c := containerConfig{
task: &api.Task{
Spec: api.TaskSpec{
Runtime: &api.TaskSpec_Container{
Container: &api.ContainerSpec{
Privileged: true,
},
},
},
},
}

expected := true
actual := c.hostConfig().Privileged
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("expected %s, got %s", expected, actual)
}
}

func TestUlimits(t *testing.T) {
c := containerConfig{
task: &api.Task{
Expand Down
8 changes: 8 additions & 0 deletions cmd/swarmctl/service/flagparser/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,13 @@ func parseContainer(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
}
}

if flags.Changed("privileged") {
privileged, err := flags.GetBool("privileged")
if err != nil {
return err
}
spec.Task.GetContainer().Privileged = privileged
}

return nil
}
1 change: 1 addition & 0 deletions cmd/swarmctl/service/flagparser/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func AddServiceFlags(flags *pflag.FlagSet) {
flags.StringSlice("env", nil, "container env")
flags.Bool("tty", false, "open a tty on standard streams")
flags.Bool("open-stdin", false, "open standard input")
flags.Bool("privileged", false, "give extended privileges to container (default false)")

flags.StringSlice("ports", nil, "ports")
flags.String("network", "", "network name")
Expand Down

0 comments on commit af189fa

Please sign in to comment.