Workhorse configuration
For historical reasons, Workhorse uses:
- Command line flags.
- A configuration file.
- Environment variables.
Add any new Workhorse configuration options into the configuration file.
CLI options
gitlab-workhorse [OPTIONS]
Options:
-apiCiLongPollingDuration duration
Long polling duration for job requesting for runners (default 50ns)
-apiLimit uint
Number of API requests allowed at single time
-apiQueueDuration duration
Maximum queueing duration of requests (default 30s)
-apiQueueLimit uint
Number of API requests allowed to be queued
-authBackend string
Authentication/authorization backend (default "http://localhost:8080")
-authSocket string
Optional: Unix domain socket to dial authBackend at
-cableBackend string
ActionCable backend
-cableSocket string
Optional: Unix domain socket to dial cableBackend at
-config string
TOML file to load config from
-developmentMode
Allow the assets to be served from Rails app
-documentRoot string
Path to static files content (default "public")
-listenAddr string
Listen address for HTTP server (default "localhost:8181")
-listenNetwork string
Listen 'network' (tcp, tcp4, tcp6, unix) (default "tcp")
-listenUmask int
Umask for Unix socket
-logFile string
Log file location
-logFormat string
Log format to use defaults to text (text, json, structured, none) (default "text")
-pprofListenAddr string
pprof listening address, for example, 'localhost:6060'
-prometheusListenAddr string
Prometheus listening address, for example, 'localhost:9229'
-propagateCorrelationID X-Request-ID
Reuse existing Correlation-ID from the incoming request header X-Request-ID if present
-proxyHeadersTimeout duration
How long to wait for response headers when proxying the request (default 5m0s)
-secretPath string
File with secret key to authenticate with authBackend (default "./.gitlab_workhorse_secret")
-version
Print version and exitThe ‘auth backend’ refers to the GitLab Rails application. The name is
a holdover from when GitLab Workhorse only handled git push and git pull over
HTTP.
GitLab Workhorse can listen on either a TCP or a Unix domain socket. It
can also open a second listening TCP listening socket with the Go
net/http/pprof profiler server.
GitLab Workhorse can listen on Redis build and runner registration events if you
pass a valid TOML configuration file through the -config flag.
A regular setup only requires the following (replacing the string
with the actual socket)
Redis
GitLab Workhorse integrates with Redis to do long polling for CI build requests. To configure it:
- Configure Redis settings in the TOML configuration file.
- Control polling behavior for CI build requests with the
-apiCiLongPollingDurationcommand-line flag.
You can enable Redis in the configuration file while leaving CI polling disabled. This configuration results in an idle Redis Pub/Sub connection. The opposite is not possible: CI long polling requires a correct Redis configuration.
For example, the [redis] section in the configuration file could contain:
[redis]
URL = "unix:///var/run/gitlab/redis.sock"
Password = "my_awesome_password"URL- A string in the formatunix://path/to/redis.sockorredis://host:port.Password- Required only if your Redis instance is password-protected.Sentinel- Required if you use Sentinel.
If both Sentinel and URL are given, only Sentinel is used.
Optional fields:
[redis]
DB = 0
MaxIdle = 1
MaxActive = 1DB- The database to connect to. Defaults to0.MaxIdle- How many idle connections can be in the Redis pool at once. Defaults to1.MaxActive- How many connections the pool can keep. Defaults to1.
Relative URL support
If you mount GitLab at a relative URL, like example.com/gitlab, use this
relative URL in the authBackend setting:
gitlab-workhorse -authBackend http://localhost:8080/gitlabTLS support
A listener with TLS can be configured to be used for incoming requests. Paths to the files containing a certificate and matching private key for the server must be provided:
[[listeners]]
network = "tcp"
addr = "localhost:3443"
[listeners.tls]
certificate = "/path/to/certificate"
key = "/path/to/private/key"
min_version = "tls1.2"
max_version = "tls1.3"The certificate file should contain the concatenation
of the server’s certificate, any intermediates, and the certificate authority’s certificate.
Metrics endpoints can be configured similarly:
[metrics_listener]
network = "tcp"
addr = "localhost:9229"
[metrics_listener.tls]
certificate = "/path/to/certificate"
key = "/path/to/private/key"
min_version = "tls1.2"
max_version = "tls1.3"Sentinel support
[redis]
Sentinel = [ "redis://sentinel1:23456", "redis://sentinel2:23456" ]
SentinelMaster = "mymaster"Sentinel TLS support
[redis]
Sentinel = [ "rediss://sentinel1:23456", "rediss://sentinel2:23456" ]
SentinelMaster = "mymaster"
[Sentinel.tls]
certificate = "/path/to/certificate" # optional
key = "/path/to/private/key" # optional
ca_certificate = "/path/to/ca_certificate" # optional
min_version = "tls1.2" # optional
max_version = "tls1.3" # optionalInteraction of authBackend and authSocket
The interaction between authBackend and authSocket can be confusing.
If authSocket is set, it overrides the host portion of authBackend, but not
the relative path.
In table form:
authBackend | authSocket | Workhorse connects to | Rails relative URL |
|---|---|---|---|
| unset | unset | localhost:8080 | / |
http://localhost:3000 | unset | localhost:3000 | / |
http://localhost:3000/gitlab | unset | localhost:3000 | /gitlab |
| unset | /path/to/socket | /path/to/socket | / |
http://localhost:3000 | /path/to/socket | /path/to/socket | / |
http://localhost:3000/gitlab | /path/to/socket | /path/to/socket | /gitlab |
The same applies to cableBackend and cableSocket.
Metadata options
Include the following options in the [metadata] section:
| Setting | Type | Default value | Description |
|---|---|---|---|
zip_reader_limit_bytes | bytes | 104857600 (100 MB) | The optional number of bytes to limit the zip reader to. |
For example:
[metadata]
zip_reader_limit_bytes = 209715200 # 200 MBRequest body size limit
Workhorse can check the size of request bodies that it proxies to the Rails application. Most routes have a limit of 100 MB. Some routes set a lower limit, and some routes always enforce their limit.
To set what Workhorse does with a request body that is larger than the limit,
set the WORKHORSE_REQUEST_LIMIT environment variable to one of these values:
| Value | Description |
|---|---|
disabled | Default. Workhorse does not check the size of request bodies. |
logging | Workhorse counts the size of request bodies, but does not reject requests that are larger than the limit. |
enforced | Workhorse rejects requests with a body larger than the limit with 413 Request Entity Too Large. |
The value is not case-sensitive. If the variable is not set, or is set to any other value,
Workhorse uses disabled.
gitlab_workhorse['env'] = {
'WORKHORSE_REQUEST_LIMIT' => 'enforced'
}export WORKHORSE_REQUEST_LIMIT='enforced'Each access log line has two fields for the route of the request:
body_limit: the limit, in bytes.body_limit_mode: the mode that applies to the request: the route’s own mode, if it sets one, otherwise the global mode. When it isdisabled, Workhorse does not check the request body againstbody_limit.
Error tracking
GitLab-Workhorse supports remote error tracking with Sentry.
To enable this feature, set the GITLAB_WORKHORSE_SENTRY_DSN environment variable.
You can also set the GITLAB_WORKHORSE_SENTRY_ENVIRONMENT environment variable to
use the Sentry environment feature to separate staging, production and
development.
gitlab_workhorse['env'] = {
'GITLAB_WORKHORSE_SENTRY_DSN' => 'https://foobar'
'GITLAB_WORKHORSE_SENTRY_ENVIRONMENT' => 'production'
}export GITLAB_WORKHORSE_SENTRY_DSN='https://foobar'
export GITLAB_WORKHORSE_SENTRY_ENVIRONMENT='production'Distributed tracing
Workhorse supports distributed tracing through LabKit using OpenTracing APIs.
By default, no tracing implementation is linked into the binary. You can link in
different OpenTracing providers with build tags
or build constraints by setting the BUILD_TAGS make variable.
For more details of the supported providers, refer to LabKit. For an example of
Jaeger tracing support, include the tags: BUILD_TAGS="tracer_static tracer_static_jaeger" like this:
make BUILD_TAGS="tracer_static tracer_static_jaeger"After you compile Workhorse with an OpenTracing provider, configure the tracing
configuration with the GITLAB_TRACING environment variable, like this:
GITLAB_TRACING=opentracing://jaeger ./gitlab-workhorsePropagate correlation IDs
When a user makes an HTTP request, such as creating a new project, the
initial request is routed through Workhorse to another service, which
may in turn, make other requests. To help trace the request as it flows
across services, Workhorse generates a random value called a
correlation ID.
Workhorse sends this correlation ID with the X-Request-Id HTTP header.
Some GitLab services, such as GitLab Shell, generate their own
correlation IDs. In addition, other services, such as Gitaly, make
internal API calls that pass along a correlation ID from the original
request. In either case, the correlation ID is also passed with the
X-Request-Id HTTP header.
By default, Workhorse ignores this header and always generates a new correlation ID. This makes debugging harder and prevents distributed tracing from working properly, because the new correlation ID is completely unrelated to the original one.
Workhorse can be configured to propagate an incoming correlation ID with
the -propagateCorrelationID command-line flag. It is highly
recommended that this option be used with an IP allow list to ensure
arbitrary values cannot be generated by untrusted clients.
An IP allow list is specified with the trusted_cidrs_for_propagation
option in the Workhorse configuration file. Specify a list of CIDR blocks
that can be trusted. For example:
trusted_cidrs_for_propagation = ["10.0.0.0/8", "127.0.0.1/32"]In addition to the X-Request-Id header, it is possible to adopt an
incoming Cf-Ray header from Cloudflare, with fallback to X-Request-Id
if not present. This behavior can be enabled via:
adopt_cf_ray_header = trueIt will also respect the trusted CIDR configuration.
The -propagateCorrelationID flag must be used for the trusted_cidrs_for_propagation and adopt_cf_ray_header options to work.
Trusted proxies
If Workhorse is behind a reverse proxy such as NGINX, the
trusted_cidrs_for_x_forwarded_for option is needed to specify which
CIDR blocks can be used to trust to provide the originating IP address
with the X-Forwarded-For HTTP header. For example:
trusted_cidrs_for_x_forwarded_for = ["10.0.0.0/8", "127.0.0.1/32"]Route the repository API to Gitway
Gitway serves the repository API at
/api/repository/, such as /api/repository/files and /api/repository/commits, and
git clone from https://gitlab.example.com/api/repository.git.
Clients authenticate with a gitlab-repositories token from POST /api/v4/token_exchange.
The token names the repository, so the path does not.
Gitway checks the token itself, so Workhorse sends these requests straight to Gitway
without calling Rails.
To route these requests to Gitway, add a [gitway] section with url set to the scheme and host
of the Gitway HTTP listener:
[gitway]
url = "http://gitway.internal:8181"Workhorse rewrites the path of each request to the path Gitway serves:
| Path on the GitLab host | Path on Gitway |
|---|---|
/api/repository.git/<rest> | /v1/repository.git/<rest> |
/api/repository/<name>.git/info/refs | /v1/repository/<name>.git/info/refs |
/api/repository/<name>.git/git-upload-pack | /v1/repository/<name>.git/git-upload-pack |
/api/repository/<name>.git/git-receive-pack | /v1/repository/<name>.git/git-receive-pack |
/api/repository/<operation> | /v1/<operation> |
For example, /api/repository/files goes to /v1/files.
In the named form, <name> is a UUID or a project path, such as group/subgroup/project.
A path such as /api/repository/files/foo.git/raw is an operation, and goes to /v1/files/foo.git/raw.
For these requests, Workhorse:
- Resolves
.and..segments and removes the relative URL root before it rewrites the path, as it does for routing. - Forwards the query string,
Authorizationheader, and request body unchanged. - Sets the
Hostheader to the Gitway host, and the original host inX-Forwarded-Host. - Sets
X-Request-IDto the correlation ID, and appends the client IP address that Workhorse resolved toX-Forwarded-For. - Returns the Gitway response unchanged.
Workhorse does not replace error responses with GitLab error pages,
and does not act on
Gitlab-Workhorse-Send-DataorX-Sendfileheaders in it. - Skips Puma load shedding, because these requests never reach Puma.
On a Geo secondary site that proxies to the primary site, Workhorse sends these requests, including clones, to the primary site.
If you leave out the [gitway] section, Workhorse sends these requests to Rails.
Gitway trusts the X-Request-ID and X-Forwarded-For headers because only Workhorse
can reach its HTTP listener.
Do not expose this listener to any other client.
Workhorse takes the client IP address from the leftmost public address in the incoming
X-Forwarded-For header, whichever peer sent it, and trusted_cidrs_for_x_forwarded_for
does not apply.
The address is only as reliable as the proxy in front of Workhorse that sets this header.
Continuous profiling
Workhorse supports continuous profiling through LabKit using Stackdriver Profiler. By default, the Stackdriver Profiler implementation is linked in the binary using build tags, though it’s not required and can be skipped. For example:
make BUILD_TAGS=""After you compile Workhorse with continuous profiling, set the profiler configuration
with the GITLAB_CONTINUOUS_PROFILING environment variable. For example:
GITLAB_CONTINUOUS_PROFILING="stackdriver?service=workhorse&service_version=1.0.1&project_id=test-123 ./gitlab-workhorse"