diff --git a/command/daemon/config.go b/command/daemon/config.go index f2d4a35..2d34df5 100644 --- a/command/daemon/config.go +++ b/command/daemon/config.go @@ -41,11 +41,6 @@ type Config struct { Acme bool `envconfig:"DRONE_HTTP_ACME"` } - Keypair struct { - Public string `envconfig:"DRONE_PUBLIC_KEY_FILE"` - Private string `envconfig:"DRONE_PRIVATE_KEY_FILE"` - } - Runner struct { Name string `envconfig:"DRONE_RUNNER_NAME"` Capacity int `envconfig:"DRONE_RUNNER_CAPACITY" default:"2"` diff --git a/engine/compiler/compiler.go b/engine/compiler/compiler.go index 14e630c..bc189ba 100644 --- a/engine/compiler/compiler.go +++ b/engine/compiler/compiler.go @@ -310,7 +310,7 @@ func (c *Compiler) Compile(ctx context.Context, args Args) *engine.Spec { dst.Envs = environ.Combine(envs, dst.Envs) dst.Volumes = append(dst.Volumes, mount) dst.Labels = labels - setupScript(src, dst, full) + setupScript(src, dst, os) setupWorkdir(src, dst, full) spec.Steps = append(spec.Steps, dst) diff --git a/engine/compiler/script.go b/engine/compiler/script.go index b4a5331..5b39440 100644 --- a/engine/compiler/script.go +++ b/engine/compiler/script.go @@ -28,8 +28,9 @@ func setupScript(src *resource.Step, dst *engine.Step, os string) { // windows operating system. func setupScriptWindows(src *resource.Step, dst *engine.Step) { dst.Entrypoint = []string{"powershell", "-noprofile", "-noninteractive", "-command"} - dst.Command = []string{"echo $DRONE_SCRIPT | iex"} + dst.Command = []string{"echo $Env:DRONE_SCRIPT | iex"} dst.Envs["DRONE_SCRIPT"] = powershell.Script(src.Commands) + dst.Envs["SHELL"] = "powershell.exe" } // helper function configures the pipeline script for the diff --git a/engine/engine_impl.go b/engine/engine_impl.go index aa11467..e97a27a 100644 --- a/engine/engine_impl.go +++ b/engine/engine_impl.go @@ -9,6 +9,7 @@ import ( "io" "io/ioutil" + "github.com/drone-runners/drone-runner-docker/internal/docker/errors" "github.com/drone-runners/drone-runner-docker/internal/docker/image" "github.com/drone-runners/drone-runner-docker/internal/docker/jsonmessage" "github.com/drone-runners/drone-runner-docker/internal/docker/stdcopy" @@ -68,7 +69,7 @@ func (e *Docker) Setup(ctx context.Context, spec *Spec) error { Labels: vol.EmptyDir.Labels, }) if err != nil { - return err + return errors.TrimExtraInfo(err) } } @@ -83,7 +84,7 @@ func (e *Docker) Setup(ctx context.Context, spec *Spec) error { Labels: spec.Network.Labels, }) - return err + return errors.TrimExtraInfo(err) } // Destroy the pipeline environment. @@ -132,17 +133,17 @@ func (e *Docker) Run(ctx context.Context, spec *Spec, step *Step, output io.Writ // create the container err := e.create(ctx, spec, step, output) if err != nil { - return nil, err + return nil, errors.TrimExtraInfo(err) } // start the container err = e.start(ctx, step.ID) if err != nil { - return nil, err + return nil, errors.TrimExtraInfo(err) } // tail the container err = e.tail(ctx, step.ID, output) if err != nil { - return nil, err + return nil, errors.TrimExtraInfo(err) } // wait for the response return e.wait(ctx, step.ID) diff --git a/internal/docker/errors/errors.go b/internal/docker/errors/errors.go new file mode 100644 index 0000000..2c278fa --- /dev/null +++ b/internal/docker/errors/errors.go @@ -0,0 +1,26 @@ +// Copyright 2019 Drone.IO Inc. All rights reserved. +// Use of this source code is governed by the Polyform License +// that can be found in the LICENSE file. + +package errors + +import ( + "errors" + "strings" +) + +// TrimExtraInfo is a helper function that trims extra information +// from a Docker error. Specifically, on Windows, this can expose +// environment variables and other sensitive data. +func TrimExtraInfo(err error) error { + s := err.Error() + i := strings.Index(s, "extra info:") + if i > 0 { + s = s[:i] + s = strings.TrimSpace(s) + s = strings.TrimSuffix(s, "(0x2)") + s = strings.TrimSpace(s) + return errors.New(s) + } + return err +} diff --git a/internal/docker/errors/errors_test.go b/internal/docker/errors/errors_test.go new file mode 100644 index 0000000..c64f188 --- /dev/null +++ b/internal/docker/errors/errors_test.go @@ -0,0 +1,22 @@ +// Copyright 2019 Drone.IO Inc. All rights reserved. +// Use of this source code is governed by the Polyform License +// that can be found in the LICENSE file. + +package errors + +import ( + "errors" + "testing" +) + +func TestTrimExtraInfo(t *testing.T) { + const ( + before = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified. (0x2) extra info: { "User":"ContainerUser" }` + after = `Error response from daemon: container encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified.` + ) + errBefore := errors.New(before) + errAfter := TrimExtraInfo(errBefore) + if errAfter.Error() != after { + t.Errorf("Expect trimmed image") + } +}