Commit a450585e authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Redo parsing of nginx proxy headers.

parent 3556fae4
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -435,9 +435,7 @@ default['gitlab']['nginx']['proxy_connect_timeout'] = 300
default['gitlab']['nginx']['proxy_set_headers'] = {
  "Host" => "$http_host",
  "X-Real-IP" => "$remote_addr",
  "X-Forwarded-For" => "$proxy_add_x_forwarded_for",
  "X-Forwarded-Proto" => "http",
  "X-Forwarded-Ssl" => nil
  "X-Forwarded-For" => "$proxy_add_x_forwarded_for"
}


+19 −9
Original line number Diff line number Diff line
@@ -314,19 +314,29 @@ module Gitlab
    end

    def parse_nginx_proxy_headers(https)
      value_from_gitlab_rb = Gitlab['nginx']['proxy_set_headers']
      default_from_attributes = node['gitlab']['nginx']['proxy_set_headers']
      values_from_gitlab_rb = Gitlab['nginx']['proxy_set_headers']
      default_from_attributes = node['gitlab']['nginx']['proxy_set_headers'].to_hash

      default_from_attributes = if https
                                  default_from_attributes.merge({
                                                                 'X-Forwarded-Proto' => "https",
                                                                 'X-Forwarded-Ssl' => "on"
                                                               })
                                else
                                  default_from_attributes.merge({
                                                                 "X-Forwarded-Proto" => "http"
                                                               })
                                end

      if https
        default_from_attributes = default_from_attributes.to_hash.merge('X-Forwarded-Proto' => "https") unless value_from_gitlab_rb && value_from_gitlab_rb['X-Forwarded-Proto']
        default_from_attributes = default_from_attributes.to_hash.merge('X-Forwarded-Ssl' => "on") unless value_from_gitlab_rb && value_from_gitlab_rb['X-Forwarded-Ssl']
      if values_from_gitlab_rb
        values_from_gitlab_rb.each do |key, value|
          default_from_attributes.delete(key) if value.nil?
        end

      Gitlab['nginx']['proxy_set_headers'] = if value_from_gitlab_rb
                                               default_from_attributes.merge(value_from_gitlab_rb.to_hash)
                                             else
                                               default_from_attributes
        default_from_attributes = default_from_attributes.merge(values_from_gitlab_rb.to_hash)
      end

      Gitlab['nginx']['proxy_set_headers'] = default_from_attributes
    end

    def parse_ci_external_url