Add a feature flag for the x-gitlab-namespace response header

What does this MR do and why?

This is based on an idea from @bbondalapati: What if we propagate attribution data to Cloudflare?

We want the root namespace of each request in the Cloudflare request logs for GitLab.com. Those logs already record the x-gitlab-namespace response header, but Rails does not send it today. The header is behind request_cost_headers, which is off on GitLab.com, and it is only set for requests with a Gitaly cost above zero.

This MR adds the ops flag root_namespace_response_header, off by default. With the flag on, every response with a root namespace in the application context has the header, including requests that never call Gitaly.

request_cost_headers now only controls x-gitlab-score-gitaly, under the same conditions as before.

The flag type is ops because the header is only useful where a proxy in front of GitLab logs it. A derisk flag would be removed after rollout, and that would turn the header on for every self-managed instance.

The middleware currently sets no header

Since a change to the request context middleware, the project and namespace that controllers and the API add to the application context are removed before RequestCost reads them. It finds no root namespace and sets neither header. On staging, where request_cost_headers is on, requests with a Gitaly cost and a root namespace in the Rails log have neither header.

This MR moves RequestCost inside the request context middleware and adds a request spec for the header. The existing spec stubs the context lookup.

Case where the header names a namespace the caller cannot read

Warning

Do not enable root_namespace_response_header on GitLab.com until a Cloudflare rule removes x-gitlab-namespace from client responses.

The API adds a group to the application context before it checks access. With the flag on, a 404 for GET /api/v4/groups/:id on a private group would include that group's root namespace path. API project lookups by ID add the project only after the permission check.

This MR does not change that.

References

  • Rollout issue for root_namespace_response_header: #639906
  • First version of the header: !230708 (merged)
  • Rollout issue for request_cost_headers: #601092
  • Related: !270365 (merged) stops the application context from caching a nil project or namespace. With it, more responses have a root namespace in the context and therefore the header.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Igor

Merge request reports

Loading
Loading