-
Notifications
You must be signed in to change notification settings - Fork 496
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
Ignore proxy for cloud metadata retrieval #2700
Conversation
fb1a025
to
46e45e7
Compare
e33a9bc
to
3922edc
Compare
This commit updates method documentation into YARD formatting.
Prior to this commit when a user set the http_proxy environment variable, the Net::HTTP#new in the HTTP resolver would use it when establishing new connections. While this is the desired behavior in most cases, this also interfered with fetching cloud metadata for services like AWS, GCP, and Azure. Facter had previously dealt with this behavior in earlier versions (2.x) starting with 23bf7e5, but that was lost during Facter's transition to C++ then back to Ruby. This commit exposes Net::HTTP#new's p_addr (proxy address) argument and, by necessity, the preceding port positional argument, and configures the AWS, GCE, and Azure resolvers to always pass nil as the proxy address.
3922edc
to
fe36fc2
Compare
I think this is introducing some unwanted behavior related to positional and keyword arguments. Some of the methods being called here use a hash as what's intended to be a positional argument but, with the addition of keyword arguments in this PR, older Rubies seem to now misinterpret the keys in that hash as individual keyword arguments. For example in the ec2 resolver, the headers and timeouts arguments now seem to get wrongly interpreted as keyword arguments: facter/lib/facter/resolvers/ec2.rb Lines 52 to 56 in dbfb450
I think we can resolve this by using strings instead of symbols in these positional hash arguments and being explicit about the hash syntax( |
When attempting to add new keyword arguments to the get_request and put_request methods, I'm running into issues with different versions of Ruby and how they deal with the separation of positional and keyword arguments. The last argument of these methods (timeouts) is an optional hash that uses symbols as keys. In Ruby < 3.0, Ruby interprets the keys in the timeouts hash as keyword arguments if we add any keyword arguments to the get_request/put_request methods. For example, running this rspec test on Ruby 2.7.8:
Ruby >= 3.0 properly separates positional and keyword arguments:
But because we still support Facter on Ruby >= 2.5, we need to account for Ruby < 3.0. We could solve this issue by making sure that the keys in the timeouts hash are strings intead of symbols. However, other parts of the code access values in the hash by looking for symbol keys specifically (like in here) and get_request/put_request are public methods. The fact that those methods are public mean that while I think additive changes like new keyword arguments are probably okay, changes or removals risk breaking things for any users who may rely on those methods. I'm going to instead try to implement this with a boolean positional argument instead which, while isn't as clean, seems easier to implement across Ruby versions and retains compatibility with these public methods. See also: https://www.fastruby.io/blog/fix-sneaky-argument-error-when-upgrading-ruby.html |
Closing in favor of #2704 |
Prior to this commit when a user set the http_proxy environment variable, the Net::HTTP#new in the HTTP resolver would use it when establishing new connections. While this is the desired behavior in most cases, this also interfered with fetching cloud metadata for services like AWS and GCP.
Facter had previously dealt with this behavior in earlier versions (2.x) starting with 23bf7e5, but that was lost during Facter's transition from C++ back to Ruby.
This commit sets Net::HTTP#new's p_addr (proxy address) argument to nil when Facter detects that the http_proxy environment variable is present when attempting to resolve cloud service metadata.