summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-08-02 23:23:21 +0000
committerDouwe Maan <douwe@gitlab.com>2016-08-02 23:23:21 +0000
commit6c519b7a7420901a5ec608e9a73786d32bd23407 (patch)
treec9cf9923e88caa728cf81cf38a7d129c78bd13fb
parentb69cc5239d87f5ad14870031147f06ca0ac4f938 (diff)
parentb371d751287fd8a01126c7aa5f156f868d177ef2 (diff)
downloadgitlab-ce-6c519b7a7420901a5ec608e9a73786d32bd23407.tar.gz
Merge branch '18866-add-simple-identifier-to-public-ssh-keys' into 'master'
Add simple identifier to public SSH keys ## What does this MR do? Adds a simple identifier of user_name + hostname to public SSH keys ## Are there points in the code the reviewer needs to double check? ## Why was this MR needed? To help people identify keys when they export them ## What are the relevant issue numbers? #18866 ## Screenshots (if relevant) ## Does this MR meet the acceptance criteria? - [ x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [ -] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - [ -] API support added - Tests - [ x] Added for this feature/bug - [ x] All builds are passing - [ x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [ x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [ x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) Closes #18866 See merge request !5614
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/key.rb5
-rw-r--r--spec/models/key_spec.rb5
-rw-r--r--spec/models/user_spec.rb2
4 files changed, 8 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 31e5d982cdf..55a382b9cd7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -23,6 +23,7 @@ v 8.11.0 (unreleased)
- Fix renaming repository when name contains invalid chararacters under project settings
- Optimize checking if a user has read access to a list of issues !5370
- Nokogiri's various parsing methods are now instrumented
+ - Add simple identifier to public SSH keys (muteor)
- Add a way to send an email and create an issue based on private personal token. Find the email address from issues page. !3363
- Include old revision in merge request update hooks (Ben Boeckel)
- Add build event color in HipChat messages (David Eisner)
diff --git a/app/models/key.rb b/app/models/key.rb
index b9bc38a0436..568a60b8af3 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -26,8 +26,9 @@ class Key < ActiveRecord::Base
end
def publishable_key
- # Removes anything beyond the keytype and key itself
- self.key.split[0..1].join(' ')
+ # Strip out the keys comment so we don't leak email addresses
+ # Replace with simple ident of user_name (hostname)
+ self.key.split[0..1].push("#{self.user_name} (#{Gitlab.config.gitlab.host})").join(' ')
end
# projects that has this key
diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb
index 49cf3d8633a..6d68e52a822 100644
--- a/spec/models/key_spec.rb
+++ b/spec/models/key_spec.rb
@@ -16,12 +16,13 @@ describe Key, models: true do
end
describe "Methods" do
+ let(:user) { create(:user) }
it { is_expected.to respond_to :projects }
it { is_expected.to respond_to :publishable_key }
describe "#publishable_keys" do
- it 'strips all personal information' do
- expect(build(:key).publishable_key).not_to match(/dummy@gitlab/)
+ it 'replaces SSH key comment with simple identifier of username + hostname' do
+ expect(build(:key, user: user).publishable_key).to include("#{user.name} (localhost)")
end
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 2a5a7fb2fc6..9f432501c59 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -643,7 +643,7 @@ describe User, models: true do
user = create :user
key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id
- expect(user.all_ssh_keys).to include(key.key)
+ expect(user.all_ssh_keys).to include(a_string_starting_with(key.key))
end
end