TExcelTAD
Home › CI/CD Pipelines & Pipeline Security › GitLab Runners & Executors

GitLab Runners & Executors

GitLab itself only schedules jobs. GitLab Runner, a separate Go program, polls GitLab for jobs and runs them with an executor. On GitLab.com you can use the hosted runners; on a self-managed GitLab (or for private networks, GPUs, or cost reasons) you run your own.

Executors

Executor Each job runs Isolation Typical use
shell directly on the runner host, as the runner's user none between jobs simple hosts, special hardware; what gitlab-ci-local uses in this course
docker in a new container from the job's image:, with services: as sidecar containers container the default choice for most self-managed runners
kubernetes in a new pod in a cluster (job container, helper, services as containers in the pod) pod autoscaling on an existing cluster
docker-autoscaler / instance on VMs created and destroyed on demand by a fleeting plugin (AWS, GCP, Azure) VM hosted-runner-like autoscaling in your cloud account (replaces the older docker+machine)
ssh, virtualbox, parallels, custom on a remote host, in a VM, or by your own scripts varies special platforms (macOS builds, legacy systems)

The shell executor runs every job as the same user on the same machine: a job can read what an earlier job left behind (credentials included). Use it only for trusted projects, or with ephemeral hosts.

Registering a runner

Runners are created in the GitLab UI (Settings → CI/CD → Runners → New project runner, or at group or instance level). Creating one shows a runner authentication token (glrt-…) that the runner host uses to register. The older registration-token workflow is deprecated. A sample session on a Linux host with GitLab Runner installed from GitLab's package repository:

bash
sudo gitlab-runner register --non-interactive \
  --url https://gitlab.example.com \
  --token "$RUNNER_TOKEN" \
  --executor docker \
  --docker-image alpine:3.22 \
  --description "shop-docker-01"
sudo gitlab-runner list
Runtime platform                                    arch=amd64 os=linux pid=4121 revision=6c1e6f4a version=18.5.0
Running in system-mode.

Verifying runner... is valid                        correlation_id=01JB9K2M3XQ7 runner=glrt-t8Q
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
Listing configured runners                          ConfigFile=/etc/gitlab-runner/config.toml
shop-docker-01                                      Executor=docker Token=glrt-t8Q URL=https://gitlab.example.com

Tags, the protected flag and "run untagged jobs" are set on the runner in the UI when you create it. The resulting config.toml:

toml
concurrent = 4                       # jobs this host runs at once, across all runners in the file

[[runners]]
  name = "shop-docker-01"
  url = "https://gitlab.example.com"
  token = "glrt-t8Q..."              # keep this file readable by root only
  executor = "docker"
  [runners.docker]
    image = "alpine:3.22"            # default when a job has no image:
    privileged = false               # true is needed for Docker-in-Docker; avoid it
    pull_policy = ["if-not-present"]
    volumes = ["/cache"]
  [runners.cache]
    Type = "s3"                      # shared cache for all runners of the fleet
    Shared = true
    [runners.cache.s3]
      ServerAddress = "s3.amazonaws.com"
      BucketName = "acme-runner-cache"
      BucketLocation = "eu-central-1"

Picking runners from a job

yaml
build-arm:
  tags: [arm64, docker]          # only runners with ALL these tags
  script: make build

deploy-production:
  tags: [prod-network]           # a runner inside the production network...
  environment: production        # ...that is marked "protected", so only protected branches can use it

A protected runner only takes jobs from protected branches and tags. Combine that with protected variables, and a feature-branch pipeline can neither reach the deployment network nor read its credentials.

Building images without privileged containers

Pipelines that build container images often use Docker-in-Docker (services: [docker:dind]), which requires privileged = true: a job then has root-equivalent access to the runner host. Safer options:

Option How
BuildKit rootless the moby/buildkit:rootless image with buildctl-daemonless.sh
Buildah / Podman rootless builds from a Dockerfile
Kaniko-style builders build in user space without a daemon (Google archived Kaniko in 2025; community forks and alternatives continue)
a remote builder a dedicated BuildKit service the runners talk to
crane append / ko / Jib assemble images without a Dockerfile (Go: ko; JVM: Jib), as in the build → scan → push rehearsal

Test yourself

Which executor gives each job a fresh container from its image:?

  1. shell
  2. docker
  3. ssh
  4. custom

What does marking a runner as protected achieve?

  1. It can't be deleted
  2. It only runs jobs from protected branches and tags
  3. It runs jobs faster
  4. It encrypts logs

Why avoid privileged = true for Docker-in-Docker builds?

  1. It's slower
  2. A privileged job container effectively has root on the runner host
  3. It doesn't support caching
  4. It's deprecated