Commit e36cf16a authored by James Fargher's avatar James Fargher

Fix gitaly-backup TLS connections

Omnibus configures OpenSSL to use custom cert directories, but since
gitaly-backup is written in go which does not use OpenSSL we need to
pass these defaults through.

Changelog: fixed
parent e00b70fc
...@@ -25,7 +25,7 @@ module Backup ...@@ -25,7 +25,7 @@ module Backup
args += ['-parallel', @parallel.to_s] if @parallel args += ['-parallel', @parallel.to_s] if @parallel
args += ['-parallel-storage', @parallel_storage.to_s] if @parallel_storage args += ['-parallel-storage', @parallel_storage.to_s] if @parallel_storage
@stdin, stdout, @thread = Open3.popen2(ENV, bin_path, command, '-path', backup_repos_path, *args) @stdin, stdout, @thread = Open3.popen2(build_env, bin_path, command, '-path', backup_repos_path, *args)
@out_reader = Thread.new do @out_reader = Thread.new do
IO.copy_stream(stdout, @progress) IO.copy_stream(stdout, @progress)
...@@ -63,6 +63,13 @@ module Backup ...@@ -63,6 +63,13 @@ module Backup
private private
def build_env
{
'SSL_CERT_FILE' => OpenSSL::X509::DEFAULT_CERT_FILE,
'SSL_CERT_DIR' => OpenSSL::X509::DEFAULT_CERT_DIR
}.merge(ENV)
end
def started? def started?
@thread.present? @thread.present?
end end
......
...@@ -5,12 +5,20 @@ require 'spec_helper' ...@@ -5,12 +5,20 @@ require 'spec_helper'
RSpec.describe Backup::GitalyBackup do RSpec.describe Backup::GitalyBackup do
let(:parallel) { nil } let(:parallel) { nil }
let(:parallel_storage) { nil } let(:parallel_storage) { nil }
let(:progress) do let(:progress) do
Tempfile.new('progress').tap do |progress| Tempfile.new('progress').tap do |progress|
progress.unlink progress.unlink
end end
end end
let(:expected_env) do
{
'SSL_CERT_FILE' => OpenSSL::X509::DEFAULT_CERT_FILE,
'SSL_CERT_DIR' => OpenSSL::X509::DEFAULT_CERT_DIR
}.merge(ENV)
end
after do after do
progress.close progress.close
end end
...@@ -32,7 +40,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -32,7 +40,7 @@ RSpec.describe Backup::GitalyBackup do
project_snippet = create(:project_snippet, :repository, project: project) project_snippet = create(:project_snippet, :repository, project: project)
personal_snippet = create(:personal_snippet, :repository, author: project.owner) personal_snippet = create(:personal_snippet, :repository, author: project.owner)
expect(Open3).to receive(:popen2).with(ENV, anything, 'create', '-path', anything).and_call_original expect(Open3).to receive(:popen2).with(expected_env, anything, 'create', '-path', anything).and_call_original
subject.start(:create) subject.start(:create)
subject.enqueue(project, Gitlab::GlRepository::PROJECT) subject.enqueue(project, Gitlab::GlRepository::PROJECT)
...@@ -53,7 +61,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -53,7 +61,7 @@ RSpec.describe Backup::GitalyBackup do
let(:parallel) { 3 } let(:parallel) { 3 }
it 'passes parallel option through' do it 'passes parallel option through' do
expect(Open3).to receive(:popen2).with(ENV, anything, 'create', '-path', anything, '-parallel', '3').and_call_original expect(Open3).to receive(:popen2).with(expected_env, anything, 'create', '-path', anything, '-parallel', '3').and_call_original
subject.start(:create) subject.start(:create)
subject.wait subject.wait
...@@ -64,7 +72,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -64,7 +72,7 @@ RSpec.describe Backup::GitalyBackup do
let(:parallel_storage) { 3 } let(:parallel_storage) { 3 }
it 'passes parallel option through' do it 'passes parallel option through' do
expect(Open3).to receive(:popen2).with(ENV, anything, 'create', '-path', anything, '-parallel-storage', '3').and_call_original expect(Open3).to receive(:popen2).with(expected_env, anything, 'create', '-path', anything, '-parallel-storage', '3').and_call_original
subject.start(:create) subject.start(:create)
subject.wait subject.wait
...@@ -90,6 +98,26 @@ RSpec.describe Backup::GitalyBackup do ...@@ -90,6 +98,26 @@ RSpec.describe Backup::GitalyBackup do
it_behaves_like 'creates a repository backup' it_behaves_like 'creates a repository backup'
end end
context 'custom SSL envs set' do
let(:ssl_env) do
{
'SSL_CERT_FILE' => '/some/cert/file',
'SSL_CERT_DIR' => '/some/cert'
}
end
before do
stub_const('ENV', ssl_env)
end
it 'passes through SSL envs' do
expect(Open3).to receive(:popen2).with(ssl_env, anything, 'create', '-path', anything).and_call_original
subject.start(:create)
subject.wait
end
end
end end
context 'restore' do context 'restore' do
...@@ -109,7 +137,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -109,7 +137,7 @@ RSpec.describe Backup::GitalyBackup do
copy_bundle_to_backup_path('personal_snippet_repo.bundle', personal_snippet.disk_path + '.bundle') copy_bundle_to_backup_path('personal_snippet_repo.bundle', personal_snippet.disk_path + '.bundle')
copy_bundle_to_backup_path('project_snippet_repo.bundle', project_snippet.disk_path + '.bundle') copy_bundle_to_backup_path('project_snippet_repo.bundle', project_snippet.disk_path + '.bundle')
expect(Open3).to receive(:popen2).with(ENV, anything, 'restore', '-path', anything).and_call_original expect(Open3).to receive(:popen2).with(expected_env, anything, 'restore', '-path', anything).and_call_original
subject.start(:restore) subject.start(:restore)
subject.enqueue(project, Gitlab::GlRepository::PROJECT) subject.enqueue(project, Gitlab::GlRepository::PROJECT)
...@@ -132,7 +160,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -132,7 +160,7 @@ RSpec.describe Backup::GitalyBackup do
let(:parallel) { 3 } let(:parallel) { 3 }
it 'passes parallel option through' do it 'passes parallel option through' do
expect(Open3).to receive(:popen2).with(ENV, anything, 'restore', '-path', anything, '-parallel', '3').and_call_original expect(Open3).to receive(:popen2).with(expected_env, anything, 'restore', '-path', anything, '-parallel', '3').and_call_original
subject.start(:restore) subject.start(:restore)
subject.wait subject.wait
...@@ -143,7 +171,7 @@ RSpec.describe Backup::GitalyBackup do ...@@ -143,7 +171,7 @@ RSpec.describe Backup::GitalyBackup do
let(:parallel_storage) { 3 } let(:parallel_storage) { 3 }
it 'passes parallel option through' do it 'passes parallel option through' do
expect(Open3).to receive(:popen2).with(ENV, anything, 'restore', '-path', anything, '-parallel-storage', '3').and_call_original expect(Open3).to receive(:popen2).with(expected_env, anything, 'restore', '-path', anything, '-parallel-storage', '3').and_call_original
subject.start(:restore) subject.start(:restore)
subject.wait subject.wait
......
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