dockercmakegitlab-runner

Operation not permitted on gitlab-runner


I'm trying to run a gitlab ci on my own server. I registered gitlab-runner in a separated machine using privileges

sudo gitlab-runner -n \
  --url https://git.myServer.com/ \
  --registration-token TOKEN \
  --executor docker \
  --description "Docker runner" \
  --docker-image "myImage:version" \
  --docker-privileged

Then I created a simple .gitlab-ci.yml configuration

stages:
  - build

default:
  image: myImage:version

build-os:
  stage: build
  script: ./build

My build script builds some cpp files and triggers some cmake files. However, one of those cmake files fails when trying to execute configure_file command

CMake Error at CMakeLists.txt:80 (configure_file):
  Operation not permitted

I think it's a problem of privileges of my gitlab-runner but I registered it with sudo privileges.

Any idea of what I'm missing? thank you!

edit: Here's my config.toml file

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Description"
  url = "https://git.myServer.com/"
  token = "TOKEN"
  executor = "docker"
  environment = [
      "DOCKER_AUTH_CONFIG={config}",
      "GIT_STRATEGY=clone",
  ]
  clone_url = "https://git.myServer.com"
  builds_dir = "/home/gitlab-runner/build"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "myImage:version"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = [
        "/tmp/.X11-unix:/tmp/.X11-unix",
        "/dev:/dev",
        "/run/user/1000/gdm/Xauthority:/home/gitlab-runner/.Xauthority",
    ]
    memory = "8g"
    memory_swap = "8g"
    ulimit = ["core=0", "memlock=-1", "rtprio=99"]
    shm_size = 0
    pull_policy = ["if-not-present"]
    network_mode = "host"

I have also tried changing the user from gitlab-runner to my host user following this but it didn't work.

This is the line which makes my build fail.


Solution

  • I entered the container from the runner machine while the ci was running and I noticed that the repository was cloned as root but the build directories were created under a user. The cofigure_file command is trying to modify a file from the repository, so it's like user is trying to modify a file created as root (when cloned). I didn't manage to make the gitlab-runner software clone the repository as user. Instead, my workaround was to change the permissions of the folder before building. My .gitlab-ci.yml looks like this now

    stages:
      - build
    
    default:
      image: myImage:version
    
    build-os:
      stage: build
      script: 
        - cd ../ && sudo chown -R user:sudo my-repo/ && cd my-repo/
        - ./build