Commit 6c519b7a authored by Douwe Maan's avatar Douwe Maan

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
parents b69cc523 b371d751
...@@ -23,6 +23,7 @@ v 8.11.0 (unreleased) ...@@ -23,6 +23,7 @@ v 8.11.0 (unreleased)
- Fix renaming repository when name contains invalid chararacters under project settings - 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 - Optimize checking if a user has read access to a list of issues !5370
- Nokogiri's various parsing methods are now instrumented - 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 - 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) - Include old revision in merge request update hooks (Ben Boeckel)
- Add build event color in HipChat messages (David Eisner) - Add build event color in HipChat messages (David Eisner)
......
...@@ -26,8 +26,9 @@ class Key < ActiveRecord::Base ...@@ -26,8 +26,9 @@ class Key < ActiveRecord::Base
end end
def publishable_key def publishable_key
# Removes anything beyond the keytype and key itself # Strip out the keys comment so we don't leak email addresses
self.key.split[0..1].join(' ') # Replace with simple ident of user_name (hostname)
self.key.split[0..1].push("#{self.user_name} (#{Gitlab.config.gitlab.host})").join(' ')
end end
# projects that has this key # projects that has this key
......
...@@ -16,12 +16,13 @@ describe Key, models: true do ...@@ -16,12 +16,13 @@ describe Key, models: true do
end end
describe "Methods" do describe "Methods" do
let(:user) { create(:user) }
it { is_expected.to respond_to :projects } it { is_expected.to respond_to :projects }
it { is_expected.to respond_to :publishable_key } it { is_expected.to respond_to :publishable_key }
describe "#publishable_keys" do describe "#publishable_keys" do
it 'strips all personal information' do it 'replaces SSH key comment with simple identifier of username + hostname' do
expect(build(:key).publishable_key).not_to match(/dummy@gitlab/) expect(build(:key, user: user).publishable_key).to include("#{user.name} (localhost)")
end end
end end
end end
......
...@@ -643,7 +643,7 @@ describe User, models: true do ...@@ -643,7 +643,7 @@ describe User, models: true do
user = create :user user = create :user
key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id 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
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