runner icon indicating copy to clipboard operation
runner copied to clipboard

When using custom container hooks in self-hosted runners, docker args is not passed correctly

Open EttoreFoti opened this issue 1 year ago • 2 comments

Describe the bug When using custom container hooks, using a docker step with multiline args is being forwarded with the wrong formatting, it's removing newlines (/n) and tabs/indent (/t) or any sort of trailing space.

To Reproduce

  1. Use the base build of runner-container-hooks when using github-runner-scale-set on k8s to have self-hosted runners.
  2. Run a workflow like the following:
runs:
  using: "docker"
  image: "ubuntu:latest"
  entrypoint: "/bin/bash"
  args:
    - "-c"
    - |
      cd /github/workspace

      if [[ ! -z true ]]; then
        package_overrides="a b c"
        for package_override in $package_overrides; do
          echo "package_override: $package_override"
        done
      fi

      exit $exit_code
  1. run the action, and it will show how the multiline argument has been converted into a single line, respecting only /n/n not \n ot \t or trailing spaces

  2. by adding logs to runner-container-hooks, we prove that the input being sent to the container has been converted to a list of strings and has already trimmed newlines, tabs and spaces

"entryPointArgs":["\"-c\"","\"cd","/github/workspace\n\nif","[[","!","-z","true","]];","then","echo","\\\"abdcs\\\"\nfi\n\nif","[[","!","-z","false","]];","then","echo","\\\"false\\\"\nfi\n\nif","[[","!","-z","true","]];","then","test=\\\"a","b","c\\\"","for","package_override","in","$package_overrides;","do","echo","\\\"package_override:","$package_override\\\"","done\nfi\n\nexit","$exit_code\""],

Expected behavior The hook should receive the text with the right format, not a splitted list of strings that loses spaces/newlines on merging it back.

It looks like this handler line could be causing the issue:

EntryPointArgs = container.ContainerEntryPointArgs?.Split(' ').Select(arg => arg.Trim()).Where(arg => !string.IsNullOrEmpty(arg)) ?? new List<string>();

Runner Version and Platform

2.321.0

OS of the machine running the runner? Linux

What's not working?

Hook input not correctly shipped.

Job Log Output

Not applicable

Runner and Worker's Diagnostic Logs

Not applicable

EttoreFoti avatar Nov 28 '24 11:11 EttoreFoti

@EttoreFoti - Please provide any other information that will help. We have an internal Issue pointing here for reproduction steps or any other additional information you can provide. Thank you.

theRealMarkCastillo avatar Feb 18 '25 15:02 theRealMarkCastillo

@EttoreFoti - Please provide any other information that will help. We have an internal Issue pointing here for reproduction steps or any other additional information you can provide. Thank you.

Hi! The issue can be replicated by using the latest version of gha-runner-scale-set and enabling the docker custom hooks from runner-container-hooks. In this way you will see how it behaves different when the hooks are enabled compared to the default behavior, and it breaks multiline formatting as written in the main issue.

EttoreFoti avatar Feb 19 '25 13:02 EttoreFoti