Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to fix issue 144, check for presence of specifed ca_file (#1) #145

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ It can be used when the certificate of the gitlab server is signed using a CA
and when upon registering a runner the following error is shown:
`certificate verify failed (self signed certificate in certificate chain)`
Using the CA file solves https://github.com/voxpupuli/puppet-gitlab_ci_runner/issues/124.
The ca_file must exist, if it does not. Gitlab runner token generation will be skipped. Gitlab runner will not register until either the file exists or the ca_file parameter is not specified.

Default value: ``undef``

Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/functions/gitlab_ci_runner/register_to_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def register_to_file(url, regtoken, runner_name, additional_options = {}, proxy
return 'DUMMY-NOOP-TOKEN' if Puppet.settings[:noop]

begin
# Confirm the specified ca file exists
if !ca_file.nil? && !File.exist?(ca_file)
puts('Specified CA file doesn\'t exist for gitlab-ci-runner. Did you forget to create it?')
benjamin-robertson marked this conversation as resolved.
Show resolved Hide resolved
return 'Specified CA file doesn\'t exist, not creating authtoken'
end
authtoken = PuppetX::Gitlab::Runner.register(url, additional_options.merge('token' => regtoken), proxy, ca_file)['token']

# If this function is used as a Deferred function the Gitlab Runner config dir
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
# and when upon registering a runner the following error is shown:
# `certificate verify failed (self signed certificate in certificate chain)`
# Using the CA file solves https://github.com/voxpupuli/puppet-gitlab_ci_runner/issues/124.
# The ca_file must exist, if it does not. Gitlab runner token generation will be skipped. Gitlab runner will not register until either the file exists or the ca_file parameter is not specified.
#
class gitlab_ci_runner (
String $xz_package_name, # Defaults in module hieradata
Expand Down
12 changes: 10 additions & 2 deletions spec/functions/register_to_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@

it { is_expected.to run.with_params(url, regtoken, runner_name).and_return(return_hash['token']) }

context 'with ca_file option' do
context 'with existing file ca_file option' do
before do
allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'token' => regtoken }, nil, '/tmp').and_return(return_hash)
end

it { is_expected.to run.with_params(url, regtoken, runner_name, {}, nil, '/tmp').and_return(return_hash['token']) }
end

context 'with non existent ca_file option' do
before do
allow(PuppetX::Gitlab::Runner).to receive(:register).with(url, { 'token' => regtoken }, nil, '/path/to/ca_file').and_return(return_hash)
end

it { is_expected.to run.with_params(url, regtoken, runner_name, {}, nil, '/path/to/ca_file').and_return(return_hash['token']) }
it { is_expected.to run.with_params(url, regtoken, runner_name, {}, nil, '/path/to/ca_file').and_return('Specified CA file doesn\'t exist, not creating authtoken') }
end
end

Expand Down