Skip to content

Commit 1e3d15a

Browse files
author
Robert Speicher
committed
Merge branch 'permissions-create-keys' into 'master'
Update the keys permission check to open the file in write mode. That way the file is created if it does not exist. This will help simplify the check being running from omnibus. Currently we create the authorized_keys, file in omnibus. We want to instead have omnibus call check-permissions as the git user, to get around nfs root_squash issues with the authorized_keys file. See merge request !83
2 parents 0b73855 + 6e4ada2 commit 1e3d15a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/gitlab_keys.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def clear
106106
end
107107

108108
def check_permissions
109-
open_auth_file('r+') { true }
109+
open_auth_file(File::RDWR | File::CREAT) { true }
110110
rescue => ex
111111
puts "error: could not open #{auth_file}: #{ex}"
112112
if File.exist?(auth_file)
@@ -132,7 +132,7 @@ def lock(timeout = 10)
132132
def lock_file
133133
@lock_file ||= auth_file + '.lock'
134134
end
135-
135+
136136
def open_auth_file(mode)
137137
open(auth_file, mode, 0600) do |file|
138138
file.chmod(0600)

spec/gitlab_keys_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@
183183
gitlab_keys.should_receive(:open_auth_file).and_raise("imaginary error")
184184
expect(gitlab_keys.exec).to eq(false)
185185
end
186+
187+
it 'creates the keys file if it does not exist' do
188+
create_authorized_keys_fixture
189+
FileUtils.rm(tmp_authorized_keys_path)
190+
expect(gitlab_keys.exec).to eq(true)
191+
expect(File.exist?(tmp_authorized_keys_path)).to eq(true)
192+
end
186193
end
187194

188195
describe :exec do

0 commit comments

Comments
 (0)