diff --git a/azure/backend.go b/azure/backend.go index 4268b4f71..372522fc2 100644 --- a/azure/backend.go +++ b/azure/backend.go @@ -193,6 +193,10 @@ func getGroupAndContainerName(containerID string) (groupName string, containerNa } func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error { + err := verifyExecCommand(command) + if err != nil { + return err + } groupName, containerAciName := getGroupAndContainerName(name) containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, groupName, containerAciName) if err != nil { @@ -208,6 +212,15 @@ func (cs *aciContainerService) Exec(ctx context.Context, name string, command st ) } +func verifyExecCommand(command string) error { + tokens := strings.Split(command, " ") + if len(tokens) > 1 { + return errors.New("ACI exec command does not accept arguments to the command. " + + "Only the binary should be specified") + } + return nil +} + func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error { groupName, containerAciName := getGroupAndContainerName(containerName) var tail *int32 diff --git a/azure/backend_test.go b/azure/backend_test.go index 9e4bc2ef6..8092c8c52 100644 --- a/azure/backend_test.go +++ b/azure/backend_test.go @@ -61,6 +61,15 @@ func (suite *BackendSuiteTest) TestErrorMessageRunSingleContainerNameWithCompose Expect(err.Error()).To(Equal("invalid container name. ACI container name cannot include \"_\"")) } +func (suite *BackendSuiteTest) TestVerifyCommand() { + err := verifyExecCommand("command") // Command without an argument + Expect(err).To(BeNil()) + err = verifyExecCommand("command argument") // Command with argument + Expect(err).NotTo(BeNil()) + Expect(err.Error()).To(Equal("ACI exec command does not accept arguments to the command. " + + "Only the binary should be specified")) +} + func TestBackendSuite(t *testing.T) { RegisterTestingT(t) suite.Run(t, new(BackendSuiteTest)) diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index e3f44f70c..04e30a463 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -150,6 +150,15 @@ func (s *E2eACISuite) TestACIBackend() { Expect(output).To(ContainSubstring("GET")) }) + s.T().Run("exec command", func(t *testing.T) { + output := s.NewDockerCommand("exec", testContainerName, "pwd").ExecOrDie() + Expect(output).To(ContainSubstring("/")) + + output = s.NewDockerCommand("exec", testContainerName, "echo", "fail_with_argument").ExecOrDie() + Expect(output).To(ContainSubstring("ACI exec command does not accept arguments to the command. " + + "Only the binary should be specified")) + }) + s.T().Run("follow logs from nginx", func(t *testing.T) { timeChan := make(chan time.Time)