Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-08-25 16:08:48 +0300
committerNick Thomas <nick@gitlab.com>2017-08-30 22:50:44 +0300
commit6847060266792471c9c14518a5106e0f622cd6c5 (patch)
tree291238748abd929e77aaf462b8833bd336e39f5d /lib
parentb49b7bc147955df6589b13942d0437a3b4518c7b (diff)
Rework the permissions model for SSH key restrictions
`allowed_key_types` is removed and the `minimum_<type>_bits` fields are renamed to `<tech>_key_restriction`. A special sentinel value (`-1`) signifies that the key type is disabled. This also feeds through to the UI - checkboxes per key type are out, inline selection of "forbidden" and "allowed" (i.e., no restrictions) are in. As with the previous model, unknown key types are disallowed, even if the underlying ssh daemon happens to support them. The defaults have also been changed from the lowest known bit size to "no restriction". So if someone does happen to have a 768-bit RSA key, it will continue to work on upgrade, at least until the administrator restricts them.
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb1
-rw-r--r--lib/api/settings.rb11
-rw-r--r--lib/gitlab/ssh_public_key.rb52
3 files changed, 27 insertions, 37 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8f766ba4f8d..803b48dd88a 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -744,7 +744,6 @@ module API
expose(:default_snippet_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_snippet_visibility) }
expose(:default_group_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_group_visibility) }
expose :password_authentication_enabled, as: :signin_enabled
- expose :allowed_key_types
end
class Release < Grape::Entity
diff --git a/lib/api/settings.rb b/lib/api/settings.rb
index 6ace0e1e390..01123e45ee0 100644
--- a/lib/api/settings.rb
+++ b/lib/api/settings.rb
@@ -122,11 +122,12 @@ module API
optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.'
- optional :minimum_rsa_bits, type: Integer, values: Gitlab::SSHPublicKey.allowed_sizes('rsa'), desc: 'The minimum allowed bit length of an uploaded RSA key.'
- optional :minimum_dsa_bits, type: Integer, values: Gitlab::SSHPublicKey.allowed_sizes('dsa'), desc: 'The minimum allowed bit length of an uploaded DSA key.'
- optional :minimum_ecdsa_bits, type: Integer, values: Gitlab::SSHPublicKey.allowed_sizes('ecdsa'), desc: 'The minimum allowed curve size (in bits) of an uploaded ECDSA key.'
- optional :minimum_ed25519_bits, type: Integer, values: Gitlab::SSHPublicKey.allowed_sizes('ed25519'), desc: 'The minimum allowed curve size (in bits) of an uploaded ED25519 key.'
- optional :allowed_key_types, type: Array[String], values: Gitlab::SSHPublicKey.technology_names, desc: 'The SSH key types accepted by the application (`rsa`, `dsa`, `ecdsa` or `ed25519`).'
+ ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type|
+ optional :"#{type}_key_restriction",
+ type: Integer,
+ values: ApplicationSetting.supported_key_restrictions(type),
+ desc: "Restrictions on the complexity of uploaded #{type.upcase} keys. A value of #{ApplicationSetting::FORBIDDEN_KEY_VALUE} disables all #{type.upcase} keys."
+ end
optional(*::ApplicationSettingsHelper.visible_attributes)
at_least_one_of(*::ApplicationSettingsHelper.visible_attributes)
diff --git a/lib/gitlab/ssh_public_key.rb b/lib/gitlab/ssh_public_key.rb
index 2df31bcc246..a3f8730fb04 100644
--- a/lib/gitlab/ssh_public_key.rb
+++ b/lib/gitlab/ssh_public_key.rb
@@ -1,31 +1,20 @@
module Gitlab
class SSHPublicKey
- TYPES = %w[rsa dsa ecdsa ed25519].freeze
-
- Technology = Struct.new(:name, :allowed_sizes)
+ Technology = Struct.new(:name, :key_class, :supported_sizes)
Technologies = [
- Technology.new('rsa', [1024, 2048, 3072, 4096]),
- Technology.new('dsa', [1024, 2048, 3072]),
- Technology.new('ecdsa', [256, 384, 521]),
- Technology.new('ed25519', [256])
+ Technology.new(:rsa, OpenSSL::PKey::RSA, [1024, 2048, 3072, 4096]),
+ Technology.new(:dsa, OpenSSL::PKey::DSA, [1024, 2048, 3072]),
+ Technology.new(:ecdsa, OpenSSL::PKey::EC, [256, 384, 521]),
+ Technology.new(:ed25519, Net::SSH::Authentication::ED25519::PubKey, [256])
].freeze
- def self.technology_names
- Technologies.map(&:name)
- end
-
def self.technology(name)
- Technologies.find { |ssh_key_technology| ssh_key_technology.name == name }
+ Technologies.find { |tech| tech.name.to_s == name.to_s }
end
- private_class_method :technology
- def self.allowed_sizes(name)
- technology(name).allowed_sizes
- end
-
- def self.allowed_type?(type)
- technology_names.include?(type.to_s)
+ def self.supported_sizes(name)
+ technology(name)&.supported_sizes
end
attr_reader :key_text, :key
@@ -50,18 +39,7 @@ module Gitlab
def type
return unless valid?
- case key
- when OpenSSL::PKey::EC
- :ecdsa
- when OpenSSL::PKey::RSA
- :rsa
- when OpenSSL::PKey::DSA
- :dsa
- when Net::SSH::Authentication::ED25519::PubKey
- :ed25519
- else
- raise "Unsupported key type: #{key.class}"
- end
+ technology.name
end
def bits
@@ -80,5 +58,17 @@ module Gitlab
raise "Unsupported key type: #{type}"
end
end
+
+ private
+
+ def technology
+ @technology ||=
+ begin
+ tech = Technologies.find { |tech| key.is_a?(tech.key_class) }
+ raise "Unsupported key type: #{key.class}" unless tech
+
+ tech
+ end
+ end
end
end