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

Add "ssl_ca_file" in config for self-signed certs #329

Merged
merged 2 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ This provider exposes quite a few provider-specific configuration options:
* `openstack_image_url` - The image URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint.
* `endpoint_type` - The endpoint type to use : publicURL, adminURL, internalURL. If not provided, vagrant will use publicURL by default.
* `interface_type` - The endpoint type to use for identity v3: public, admin, internal. If not provided, vagrant will use public by default.
* `ssl_ca_file` - The location of CA certificate file.
* `ssl_verify_peer` - Verify peer certificate when connecting to endpoint. Defaults to true. Set to false to disable check (beware this is not secure!)

### VM Configuration
Expand Down
2 changes: 1 addition & 1 deletion source/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Metrics/CyclomaticComplexity:
Max: 15

Metrics/MethodLength:
Max: 60
Max: 65

Metrics/LineLength:
Max: 150
Expand Down
6 changes: 3 additions & 3 deletions source/lib/vagrant-openstack-provider/client/rest_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ def self.get(env, url, headers = {}, &block)
config = env[:machine].provider_config
RestClient::Request.execute(method: :get, url: url, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
verify_ssl: config.ssl_verify_peer, &block)
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end

def self.post(env, url, payload, headers = {}, &block)
config = env[:machine].provider_config
RestClient::Request.execute(method: :post, url: url, payload: payload, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
verify_ssl: config.ssl_verify_peer, &block)
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end

def self.delete(env, url, headers = {}, &block)
config = env[:machine].provider_config
RestClient::Request.execute(method: :delete, url: url, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
verify_ssl: config.ssl_verify_peer, &block)
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions source/lib/vagrant-openstack-provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ class Config < Vagrant.plugin('2', :config)
# @return [Boolean]
attr_accessor :use_legacy_synced_folders

# Specify the certificate to use.
#
# @return [String]
attr_accessor :ssl_ca_file

# Verify ssl peer certificate when connecting. Set to false (! unsecure) to disable
#
# @return [Boolean]
Expand Down Expand Up @@ -295,6 +300,7 @@ def initialize
@meta_args_support = UNSET_VALUE
@http = HttpConfig.new
@use_legacy_synced_folders = UNSET_VALUE
@ssl_ca_file = UNSET_VALUE
@ssl_verify_peer = UNSET_VALUE
end

Expand Down Expand Up @@ -407,6 +413,7 @@ def finalize!
@volumes = nil if @volumes.empty?
@stacks = nil if @stacks.empty?
@http.finalize!
@ssl_ca_file = nil if @ssl_ca_file == UNSET_VALUE
@ssl_verify_peer = true if @ssl_verify_peer == UNSET_VALUE
end
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let(:config) do
double('config').tap do |config|
config.stub(:http) { http }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let(:config) do
double('config').tap do |config|
config.stub(:http) { http }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
end
end
Expand Down
1 change: 1 addition & 0 deletions source/spec/vagrant-openstack-provider/client/heat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
config.stub(:username) { 'username' }
config.stub(:password) { 'password' }
config.stub(:http) { http }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
config.stub(:interface_type) { 'public' }
config.stub(:identity_api_version) { '2' }
config.stub(:project_name) { 'testTenant' }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let(:config) do
double('config').tap do |config|
config.stub(:http) { http }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
end
end
Expand Down
1 change: 1 addition & 0 deletions source/spec/vagrant-openstack-provider/client/nova_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
config.stub(:username) { 'username' }
config.stub(:password) { 'password' }
config.stub(:http) { http }
config.stub(:ssl_ca_file) { nil }
config.stub(:ssl_verify_peer) { true }
end
end
Expand Down
4 changes: 3 additions & 1 deletion source/spec/vagrant-openstack-provider/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
its(:security_groups) { should be_nil }
its(:user_data) { should be_nil }
its(:metadata) { should be_nil }
its(:ssl_ca_file) { should eq nil }
end

describe 'overriding defaults' do
Expand All @@ -50,7 +51,8 @@
:user_data,
:metadata,
:availability_zone,
:public_key_path].each do |attribute|
:public_key_path,
:ssl_ca_file].each do |attribute|
it "should not default #{attribute} if overridden" do
subject.send("#{attribute}=".to_sym, 'foo')
subject.finalize!
Expand Down