Commit 18a102a5 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 1adb4373
# Tell the Rack::Attack Rack middleware to maintain an IP blacklist. # Tell the Rack::Attack Rack middleware to maintain an IP blacklist.
# We update the blacklist in Gitlab::Auth::IpRateLimiter. # We update the blacklist in Gitlab::Auth::IpRateLimiter.
Rack::Attack.blocklist('Git HTTP Basic Auth') do |req| Rack::Attack.blocklist('Git HTTP Basic Auth') do |req|
next false unless Gitlab.config.rack_attack.git_basic_auth.enabled rate_limiter = Gitlab::Auth::IpRateLimiter.new(req.ip)
next false if !rate_limiter.enabled? || rate_limiter.trusted_ip?
Rack::Attack::Allow2Ban.filter(req.ip, Gitlab.config.rack_attack.git_basic_auth) do Rack::Attack::Allow2Ban.filter(req.ip, Gitlab.config.rack_attack.git_basic_auth) do
# This block only gets run if the IP was not already banned. # This block only gets run if the IP was not already banned.
......
...@@ -119,6 +119,8 @@ GitLab supports: ...@@ -119,6 +119,8 @@ GitLab supports:
- Creating a new GKE cluster using the GitLab UI. - Creating a new GKE cluster using the GitLab UI.
- Providing credentials to add an [existing Kubernetes cluster](#add-existing-cluster). - Providing credentials to add an [existing Kubernetes cluster](#add-existing-cluster).
Starting from [GitLab 12.4](https://gitlab.com/gitlab-org/gitlab/issues/25925), all the GKE clusters provisioned by GitLab are [VPC-Native](https://cloud.google.com/kubernetes-engine/docs/how-to/alias-ips).
NOTE: **Note:** NOTE: **Note:**
The [Google authentication integration](../../../integration/google.md) must The [Google authentication integration](../../../integration/google.md) must
be enabled in GitLab at the instance level. If that's not the case, ask your be enabled in GitLab at the instance level. If that's not the case, ask your
......
...@@ -21,11 +21,12 @@ module Gitlab ...@@ -21,11 +21,12 @@ module Gitlab
end end
def register_fail! def register_fail!
return false if trusted_ip?
# Allow2Ban.filter will return false if this IP has not failed too often yet # Allow2Ban.filter will return false if this IP has not failed too often yet
@banned = Rack::Attack::Allow2Ban.filter(ip, config) do @banned = Rack::Attack::Allow2Ban.filter(ip, config) do
# If we return false here, the failure for this IP is ignored by Allow2Ban # We return true to increment the count for this IP
# If we return true here, the count for the IP is incremented. true
ip_can_be_banned?
end end
end end
...@@ -33,20 +34,16 @@ module Gitlab ...@@ -33,20 +34,16 @@ module Gitlab
@banned @banned
end end
def trusted_ip?
trusted_ips.any? { |netmask| netmask.include?(ip) }
end
private private
def config def config
Gitlab.config.rack_attack.git_basic_auth Gitlab.config.rack_attack.git_basic_auth
end end
def ip_can_be_banned?
!trusted_ip?
end
def trusted_ip?
trusted_ips.any? { |netmask| netmask.include?(ip) }
end
def trusted_ips def trusted_ips
strong_memoize(:trusted_ips) do strong_memoize(:trusted_ips) do
config.ip_whitelist.map do |proxy| config.ip_whitelist.map do |proxy|
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::ExclusiveLease, :clean_gitlab_redis_shared_state do describe Gitlab::ExclusiveLease, :clean_gitlab_redis_shared_state do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::ExternalAuthorization, :request_store do describe Gitlab::ExternalAuthorization, :request_store do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::FakeApplicationSettings do describe Gitlab::FakeApplicationSettings do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Favicon, :request_store do RSpec.describe Gitlab::Favicon, :request_store do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::FileDetector do describe Gitlab::FileDetector do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::FileFinder do describe Gitlab::FileFinder do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::GitAccess do describe Gitlab::GitAccess do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::GitAccessWiki do describe Gitlab::GitAccessWiki do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::GitRefValidator do describe Gitlab::GitRefValidator do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::Git do describe Gitlab::Git do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
# We stub Gitaly in `spec/support/gitaly.rb` for other tests. We don't want # We stub Gitaly in `spec/support/gitaly.rb` for other tests. We don't want
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::GithubImport do describe Gitlab::GithubImport do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe ::Gitlab::GlRepository do describe ::Gitlab::GlRepository do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::Gpg do describe Gitlab::Gpg do
...@@ -63,7 +65,7 @@ describe Gitlab::Gpg do ...@@ -63,7 +65,7 @@ describe Gitlab::Gpg do
it 'downcases the email' do it 'downcases the email' do
public_key = double(:key) public_key = double(:key)
fingerprints = double(:fingerprints) fingerprints = double(:fingerprints)
uid = double(:uid, name: 'Nannie Bernhard', email: 'NANNIE.BERNHARD@EXAMPLE.COM') uid = double(:uid, name: +'Nannie Bernhard', email: +'NANNIE.BERNHARD@EXAMPLE.COM')
raw_key = double(:raw_key, uids: [uid]) raw_key = double(:raw_key, uids: [uid])
allow(Gitlab::Gpg::CurrentKeyChain).to receive(:fingerprints_from_key).with(public_key).and_return(fingerprints) allow(Gitlab::Gpg::CurrentKeyChain).to receive(:fingerprints_from_key).with(public_key).and_return(fingerprints)
allow(GPGME::Key).to receive(:find).with(:public, anything).and_return([raw_key]) allow(GPGME::Key).to receive(:find).with(:public, anything).and_return([raw_key])
...@@ -78,8 +80,8 @@ describe Gitlab::Gpg do ...@@ -78,8 +80,8 @@ describe Gitlab::Gpg do
it 'rejects non UTF-8 names and addresses' do it 'rejects non UTF-8 names and addresses' do
public_key = double(:key) public_key = double(:key)
fingerprints = double(:fingerprints) fingerprints = double(:fingerprints)
email = "\xEEch@test.com".force_encoding('ASCII-8BIT') email = (+"\xEEch@test.com").force_encoding('ASCII-8BIT')
uid = double(:uid, name: 'Test User', email: email) uid = double(:uid, name: +'Test User', email: email)
raw_key = double(:raw_key, uids: [uid]) raw_key = double(:raw_key, uids: [uid])
allow(Gitlab::Gpg::CurrentKeyChain).to receive(:fingerprints_from_key).with(public_key).and_return(fingerprints) allow(Gitlab::Gpg::CurrentKeyChain).to receive(:fingerprints_from_key).with(public_key).and_return(fingerprints)
allow(GPGME::Key).to receive(:find).with(:public, anything).and_return([raw_key]) allow(GPGME::Key).to receive(:find).with(:public, anything).and_return([raw_key])
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::GroupSearchResults do describe Gitlab::GroupSearchResults do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::Highlight do describe Gitlab::Highlight do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::HttpIO do describe Gitlab::HttpIO do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::HTTP do describe Gitlab::HTTP do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::I18n do describe Gitlab::I18n do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::Identifier do describe Gitlab::Identifier do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::ImportSources do describe Gitlab::ImportSources do
......
# frozen_string_literal: true
require "spec_helper" require "spec_helper"
describe Gitlab::IncomingEmail do describe Gitlab::IncomingEmail do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::InsecureKeyFingerprint do describe Gitlab::InsecureKeyFingerprint do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::IssuableMetadata do describe Gitlab::IssuableMetadata do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::IssuableSorter do describe Gitlab::IssuableSorter do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::IssuablesCountForState do describe Gitlab::IssuablesCountForState do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::JobWaiter do describe Gitlab::JobWaiter do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::JsonLogger do describe Gitlab::JsonLogger do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::Kubernetes do describe Gitlab::Kubernetes do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::LanguageDetection do describe Gitlab::LanguageDetection do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::Lazy do describe Gitlab::Lazy do
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Gitlab::VisibilityLevelChecker do describe Gitlab::VisibilityLevelChecker do
......
...@@ -452,7 +452,7 @@ describe 'Git HTTP requests' do ...@@ -452,7 +452,7 @@ describe 'Git HTTP requests' do
context "when authentication fails" do context "when authentication fails" do
context "when the user is IP banned" do context "when the user is IP banned" do
before do before do
stub_rack_attack_setting(enabled: true) stub_rack_attack_setting(enabled: true, ip_whitelist: [])
end end
it "responds with status 403" do it "responds with status 403" do
......
...@@ -83,7 +83,7 @@ describe 'Rack Attack global throttles' do ...@@ -83,7 +83,7 @@ describe 'Rack Attack global throttles' do
expect(response).to have_http_status 200 expect(response).to have_http_status 200
end end
expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return('1.2.3.4') expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
# would be over limit for the same IP # would be over limit for the same IP
get url_that_does_not_require_authentication get url_that_does_not_require_authentication
......
...@@ -74,7 +74,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -74,7 +74,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
expect(response).to have_http_status 200 expect(response).to have_http_status 200
end end
expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return('1.2.3.4') expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
expect_rejection { get(*get_args) } expect_rejection { get(*get_args) }
end end
...@@ -194,7 +194,7 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -194,7 +194,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
expect(response).to have_http_status 200 expect(response).to have_http_status 200
end end
expect_any_instance_of(Rack::Attack::Request).to receive(:ip).and_return('1.2.3.4') expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
expect_rejection { get url_that_requires_authentication } expect_rejection { get url_that_requires_authentication }
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment