Support redis_username for Workhorse Redis ACL authentication

What does this MR do?

GitLab Workhorse cannot connect to an external Redis that uses Redis 6+ ACL authentication (username + password). The gitlab_workhorse['redis_username'] setting already exists in gitlab.rb, but it has no effect: the username is dropped, so Workhorse authenticates with the password only and fails with WRONGPASS.

This MR makes redis_username work by adding it to the generated Redis URL.

Workhorse (Go) reads the username only from the URL (redis.ParseURL), so it has to be embedded there. The Go code and the config.toml template are unchanged, and the existing Password = ... line stays.

Changes

The Redis URL builder is shared, so most of the change is in shared helpers:

  • redis_uri.rb – add user as a URI component and render user:password (via a shared URI::Redis.build_userinfo helper).
  • redis_helper.rb – add a username: parameter to build_redis_url (percent-encoded, like the password); encode_redis_password is renamed to encode_redis_credential since it now encodes both.
  • base.rb – carry username through redis_credentials / redis_url (TCP and Unix socket).
  • gitlab_workhorse.rb – carry username through the separate Workhorse Redis instance settings.

The change is additive: username defaults to nil, so password-only and no-auth setups are unchanged.

This MR supports gitlab_workhorse['redis_username']. A global gitlab_rails['redis_username'] (overriding the various instance-specific redis_*_username settings, like redis_password does) does not exist yet and is left as a follow-up.

Result

With gitlab_workhorse['redis_username'] set, the generated config.toml now contains the username in the URL:

[redis]
Password = "secret"
URL = "rediss://my-acl-user:secret@my-redis.example.com:6379/"

Specs were added for URL rendering and username propagation. All affected suites pass locally and rubocop is clean.

Fixes #9946 (closed). Same pattern as #8559; also unblocks #9939 (KAS ACL).

Follow-ups raised from review: #9950 (closed) (KAS), #9951 (closed) (Sentinel username), #9952 (Container Registry).

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion.

Required

  • MR title and description are up to date, accurate, and descriptive.
  • MR targeting the appropriate branch.
  • Latest Merge Result pipeline is green.
  • When ready for review, MR is labeled workflowready for review per the Distribution MR workflow.
  • The UBT version and corresponding checksum hash have been updated and referenced in the merge request if applicable. - N/a

For GitLab team members

If you don't have access to this, the reviewer should trigger these jobs for you during the review process.

  • The manual Trigger:ee-package jobs have a green pipeline running against latest commit.
  • If config/software or config/patches directories are changed, make sure the build-package-on-all-os job within the Trigger:ee-package downstream pipeline succeeded. - N/A
  • If you are changing anything SSL related, then the Trigger:package:fips manual job within the Trigger:ee-package downstream pipeline must succeed. - N/A
  • If CI configuration is changed, the branch must be pushed to dev.gitlab.org to confirm regular branch builds aren't broken. - N/A

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes. !9535 (comment 3492834183)
  • Documentation created/updated. - not applicable at the moment, as deployment use case would require have separate Redis for Workhorse => docs should be added when all Redis services support username
  • Tests added.
  • Integration tests added to GitLab QA. - N/A
  • Equivalent MR/issue for the GitLab Chart opened. - N/A
  • Validate potential values for new configuration settings. Formats such as integer 10, duration 10s, URI scheme://user:passwd@host:port may require quotation or other special handling when rendered in a template and written to a configuration file. - N/A
Edited by Nailia Iskhakova

Merge request reports

Loading
Loading