Skip to content

Commit

Permalink
Merge pull request #3612 from hashicorp/docker-rkt-user
Browse files Browse the repository at this point in the history
Set user for rkt tasks
  • Loading branch information
chelseakomlo committed Dec 5, 2017
2 parents f27d0dd + c4e1dc3 commit fef15f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ IMPROVEMENTS:
* driver/docker: Adds support for `ulimit` and `sysctl` options [GH-3568]
* driver/docker: Adds support for StopTimeout (set to the same value as
kill_timeout [GH-3601]
* driver/rkt: Add support for passing through user [GH-3612]
* driver/qemu: Support graceful shutdowns on unix platforms [GH-3411]
* template: Updated to consul template 0.19.4 [GH-3543]
* core/enterprise: Return 501 status code in Nomad Pro for Premium end points
Expand Down
6 changes: 5 additions & 1 deletion client/driver/rkt.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse,

}

// If a user has been specified for the task, pass it through to the user
if task.User != "" {
prepareArgs = append(prepareArgs, fmt.Sprintf("--user=%s", task.User))
}

// Add user passed arguments.
if len(driverConfig.Args) != 0 {
parsed := ctx.TaskEnv.ParseAndReplace(driverConfig.Args)
Expand Down Expand Up @@ -635,7 +640,6 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse,
execCmd := &executor.ExecCommand{
Cmd: absPath,
Args: runArgs,
User: task.User,
}
ps, err := execIntf.LaunchCmd(execCmd)
if err != nil {
Expand Down
23 changes: 13 additions & 10 deletions client/driver/rkt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/assert"

ctestutils "github.com/hashicorp/nomad/client/testutil"
)
Expand Down Expand Up @@ -334,6 +335,7 @@ func TestRktDriver_Start_Wait_AllocDir(t *testing.T) {
}

func TestRktDriverUser(t *testing.T) {
assert := assert.New(t)
if !testutil.IsTravis() {
t.Parallel()
}
Expand Down Expand Up @@ -366,18 +368,19 @@ func TestRktDriverUser(t *testing.T) {
defer ctx.AllocDir.Destroy()
d := NewRktDriver(ctx.DriverCtx)

if _, err := d.Prestart(ctx.ExecCtx, task); err != nil {
t.Fatalf("error in prestart: %v", err)
}
_, err := d.Prestart(ctx.ExecCtx, task)
assert.Nil(err)
resp, err := d.Start(ctx.ExecCtx, task)
if err == nil {
resp.Handle.Kill()
t.Fatalf("Should've failed")
}
msg := "unknown user alice"
if !strings.Contains(err.Error(), msg) {
t.Fatalf("Expecting '%v' in '%v'", msg, err)
assert.Nil(err)
defer resp.Handle.Kill()

select {
case res := <-resp.Handle.WaitCh():
assert.False(res.Successful())
case <-time.After(time.Duration(testutil.TestMultiplier()*15) * time.Second):
t.Fatalf("timeout")
}

}

func TestRktTrustPrefix(t *testing.T) {
Expand Down

0 comments on commit fef15f4

Please sign in to comment.