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

Don't pass empty lists of certificates to the oVirt SDK #14160

Merged
merged 1 commit into from
Mar 14, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ def raw_connect_v4(options = {})
# Get the timeout from the configuration:
timeout, = ems_timeouts(:ems_redhat, options[:service])

# The constructor of the SDK expects a list of certificates, but that list can't be empty, or contain only 'nil'
# values, so we need to check the value passed and make a list only if it won't be empty. If it will be empty then
# we should just pass 'nil'.
ca_certs = options[:ca_certs]
ca_certs = [ca_certs] if ca_certs
Copy link
Member

@durandom durandom Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so options[:ca_certs] is not an array already? Just read the code and it seems to be a concatenated String of certs... well :)

:ca_certs => options[:ca_certs].present? ? Array(options[:ca_certs]) : nil

because

[8] pry(main)> Array(nil)
=> []
[9] pry(main)> Array([])
=> []
[10] pry(main)> [].present?
=> false
[11] pry(main)> ''.present?
=> false
[12] pry(main)> nil.present?
=> false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options[:ca_certs] is the content of the endpoints.certificate_authority column, and that can be nil or a string containing one or multiple concatenated certificates. The SDK accepts a list, to makes things simple for users that may have those multiple certificates already split into multiple strings. Each item of that list can also contain multiple certificates concatenated in a single string. The only problem is that when the list [] or [nil] the behaviour of the SDK is to trust no certificate, which is not what we want, what we want in that case is to trust the default system certificates. The way to achieve that in hte SDK is to pass nil.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhernand can options[:ca_certs] have more than one cert? It is plural so it sounds like it :)
In that case you'd end up with [[cert1, cert2]], how about ca_certs = Array(ca_certs) if ca_certs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

options[:ca_certs] is the content of the endpoints.certificate_authority column. That is a single string that may contain multiple concatenated certificates, that is why the name is plural, but the content is either nil or one string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if you've already covered this but if it is a comma separated string should you split it up here? It looks like OvirtSDK4::Connection is expecting an array of strings https://github.com/oVirt/ovirt-engine-sdk-ruby/blob/master/sdk/lib/ovirtsdk4/connection.rb#L132-L136

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. The content of that database is one string contaning one ore more certificates, in PEM format. For example:

-----BEGIN CERTIFICATE----
The first certificate.
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
The second certificate.
-----END CERTIFICATE-----
...

For user convenience, the oVirt SDK accepts them in separate strings, which would require us to split them here, but not using command but the BEGIN/END marks. Fortunately, also for user conveninence, the oVirt SDK also accepts multiple certificates in the same string, so we don't need to split anything here. The only thing that the SDK doesn't accept is [nil] (well, it accepts it, but it doesn't have the meaning that we need: it trusts no CA instead of trusting any CA), so that is the only case that we need to check here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it thanks :)


url = URI::Generic.build(
:scheme => options[:scheme],
:host => options[:server],
Expand All @@ -277,7 +283,7 @@ def raw_connect_v4(options = {})
:password => options[:password],
:timeout => timeout,
:insecure => options[:verify_ssl] == OpenSSL::SSL::VERIFY_NONE,
:ca_certs => [options[:ca_certs]],
:ca_certs => ca_certs,
:log => $rhevm_log,
)
end
Expand Down