Permissions denied issues with custom builds_dir

Summary

When using executor of type instance (googlecompute) and a custom builds_dir, the first job that runs on newly spawned VM gets permissions denied error when trying to create job folder with `mkdir -p` of the full absolute path. Starting from the 2nd job, the error does not happen

Steps to reproduce

  • Deploy a runner of type "instance" and use custom builds_dir : /datas/gitlab-runner
  • In VMs instance template startup-script
    • Mount `/datas` from some local ssd disk
    • mkdir `/datas/gitlab-runner`
    • Grant permissions and ownership as follows :
      • sudo chown -R gitlab-runner:gitlab-runner /datas
      • sudo chmod -R 777 /datas
.gitlab-ci.yml
Add the job definition that is failing here

Actual behavior

When i enable `CI_DEBUG_TRACE=true`, i see that runner tries to create the folder with `mkdir -p` on the full absolute path and the job fails

Getting source from Git repository
mkdir -p /builds/gitlab-runner/xx_YYYYY/0/XXXXX/XXXXXX/XXX/XXXXX/XXXXX.tmp
mkdir: cannot create directory ‘/builds’: Permission denied

I dont understand why the runner tries to create /builds folder . Also, why even with defined permissions i have had permissions issues.

What's strange, is that starting from the 2nd execution of the pipeline, the error does not happen

Expected behavior

Since the permissions and ownership are defined correctly, the job should work correctly.

If the builds_dir is custom, maybe the runner should not try to create the job folder with the full path but start from inside the builds_dir.

Relevant logs and/or screenshots

job log
Add the job log

Environment description

config.toml contents
[[runners]]
  builds_dir = "/builds/gitlab-runner"
  [runners.autoscaler]
    plugin = "fleeting-plugin-googlecompute-linux-amd64"

    [runners.autoscaler.plugin_config]

    [runners.autoscaler.connector_config]
      protocol          = "ssh"
      username          = "gitlab-runner"

    [[runners.autoscaler.policy]]

Used GitLab Runner version

arch=amd64 os=linux revision= fe451d5a version=17.1.0

Possible fixes

Edited by Nabil ZOUABI