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.
# We update the blacklist in Gitlab::Auth::IpRateLimiter.
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
# This block only gets run if the IP was not already banned.
......
......@@ -119,6 +119,8 @@ GitLab supports:
- Creating a new GKE cluster using the GitLab UI.
- 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:**
The [Google authentication integration](../../../integration/google.md) must
be enabled in GitLab at the instance level. If that's not the case, ask your
......
......@@ -21,11 +21,12 @@ module Gitlab
end
def register_fail!
return false if trusted_ip?
# Allow2Ban.filter will return false if this IP has not failed too often yet
@banned = Rack::Attack::Allow2Ban.filter(ip, config) do
# If we return false here, the failure for this IP is ignored by Allow2Ban
# If we return true here, the count for the IP is incremented.
ip_can_be_banned?
# We return true to increment the count for this IP
true
end
end
......@@ -33,20 +34,16 @@ module Gitlab
@banned
end
def trusted_ip?
trusted_ips.any? { |netmask| netmask.include?(ip) }
end
private
def config
Gitlab.config.rack_attack.git_basic_auth
end
def ip_can_be_banned?
!trusted_ip?
end
def trusted_ip?
trusted_ips.any? { |netmask| netmask.include?(ip) }
end
def trusted_ips
strong_memoize(:trusted_ips) do
config.ip_whitelist.map do |proxy|
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ExclusiveLeaseHelpers, :clean_gitlab_redis_shared_state do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ExclusiveLease, :clean_gitlab_redis_shared_state do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ExternalAuthorization, :request_store do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::FakeApplicationSettings do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Favicon, :request_store do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::FileDetector do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::FileFinder do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GitAccess do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GitAccessWiki do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GitRefValidator do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Git do
......
# frozen_string_literal: true
require 'spec_helper'
# We stub Gitaly in `spec/support/gitaly.rb` for other tests. We don't want
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GithubImport do
......
# frozen_string_literal: true
require 'spec_helper'
describe ::Gitlab::GlRepository do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Gpg do
......@@ -63,7 +65,7 @@ describe Gitlab::Gpg do
it 'downcases the email' do
public_key = double(:key)
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])
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])
......@@ -78,8 +80,8 @@ describe Gitlab::Gpg do
it 'rejects non UTF-8 names and addresses' do
public_key = double(:key)
fingerprints = double(:fingerprints)
email = "\xEEch@test.com".force_encoding('ASCII-8BIT')
uid = double(:uid, name: 'Test User', email: email)
email = (+"\xEEch@test.com").force_encoding('ASCII-8BIT')
uid = double(:uid, name: +'Test User', email: email)
raw_key = double(:raw_key, uids: [uid])
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])
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::GroupSearchResults do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Highlight do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::HttpIO do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::HTTP do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::I18n do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Identifier do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ImportSources do
......
# frozen_string_literal: true
require "spec_helper"
describe Gitlab::IncomingEmail do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::InsecureKeyFingerprint do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::IssuableMetadata do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::IssuableSorter do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::IssuablesCountForState do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::JobWaiter do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::JsonLogger do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Kubernetes do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::LanguageDetection do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Lazy do
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::VisibilityLevelChecker do
......
......@@ -452,7 +452,7 @@ describe 'Git HTTP requests' do
context "when authentication fails" do
context "when the user is IP banned" do
before do
stub_rack_attack_setting(enabled: true)
stub_rack_attack_setting(enabled: true, ip_whitelist: [])
end
it "responds with status 403" do
......
......@@ -83,7 +83,7 @@ describe 'Rack Attack global throttles' do
expect(response).to have_http_status 200
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
get url_that_does_not_require_authentication
......
......@@ -74,7 +74,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
expect(response).to have_http_status 200
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) }
end
......@@ -194,7 +194,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
expect(response).to have_http_status 200
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 }
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