ohai 16.7.37 → 16.12.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39d6064d1c93ab4dac377f1883213fad35872ee08ac0c2b97801b5d96da1a1df
4
- data.tar.gz: 5837422d08995fd7057e84d496d85b11514bd51b6b0d391b282fb3612fb083bc
3
+ metadata.gz: a3157ed0544a09a2be70af496e0b3f36fa538a82b1186555f8380c42ba38bcc6
4
+ data.tar.gz: 433621ca5500cff124015f57d6ba2e4a7479579b44f18918961eb04bec8300c2
5
5
  SHA512:
6
- metadata.gz: d58037d84d3f6066b86561940dffe8b812d89ef6e75a7a0a8a843affccb7b6fc98e29795d2bd62ce48b396eefc71901423e198274d5474c95e1fb189101f4992
7
- data.tar.gz: cc8c6cbd38084685fe8cb8dccdc3f5c469829b0798c562fb8803dc37d0c3aacf2a844781689ef0f3a5796929f43951d59b083531fea4ed08a46a07395bb8a06d
6
+ metadata.gz: d2eba25677fc4cbdeb090f7c05d86ddd240f02513d24b07204e5a6ffa79560125e8bf444f1ce8622bbac337076db4b3c6cf9e90ef58318ca49debfe829d35c73
7
+ data.tar.gz: 6e304286a016ae9d23467ab158f4bcf512e993e0e466124909d57fdc509a1c553ab8241b24f5a63f7347e954c1b5b3fa03d040003ede9586c45fdaaecb042067
data/Gemfile CHANGED
@@ -4,19 +4,19 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  # pull these gems from master of chef/chef so that we're testing against what we will release
7
- gem "chef-config", git: "https://github.com/chef/chef", glob: "chef-config/chef-config.gemspec"
8
- gem "chef-utils", git: "https://github.com/chef/chef", glob: "chef-utils/chef-utils.gemspec"
7
+ gem "chef-config", git: "https://github.com/chef/chef", branch: "chef-16", glob: "chef-config/chef-config.gemspec"
8
+ gem "chef-utils", git: "https://github.com/chef/chef", branch: "chef-16", glob: "chef-utils/chef-utils.gemspec"
9
9
 
10
10
  # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
11
11
  group :development do
12
- gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
12
+ gem "chefstyle", "1.6.2"
13
13
  gem "ipaddr_extensions"
14
14
  gem "rake", ">= 10.1.0"
15
15
  gem "rspec-collection_matchers", "~> 1.0"
16
16
  gem "rspec-core", "~> 3.0"
17
17
  gem "rspec-expectations", "~> 3.0"
18
18
  gem "rspec-mocks", "~> 3.0"
19
- gem "rubocop-performance", "1.9.0"
19
+ gem "rubocop-performance", "1.9.2"
20
20
  gem "rubocop-rspec"
21
21
  end
22
22
 
@@ -43,15 +43,23 @@ module Ohai
43
43
  EC2_METADATA_ADDR ||= "169.254.169.254"
44
44
  EC2_SUPPORTED_VERSIONS ||= %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15
45
45
  2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
46
- 2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 }.freeze
46
+ 2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02
47
+ 2016-11-30 2018-08-17 2018-11-29 2019-10-01 2020-08-24 2020-11-01 }.freeze
47
48
  EC2_ARRAY_VALUES ||= %w{security-groups local_ipv4s}.freeze
48
49
  EC2_ARRAY_DIR ||= %w{network/interfaces/macs}.freeze
49
50
  EC2_JSON_DIR ||= %w{iam}.freeze
50
51
 
52
+ #
53
+ # The latest metadata version in EC2_SUPPORTED_VERSIONS that this instance supports
54
+ # in AWS supported metadata versions are determined at instance start so we need to be
55
+ # cautious here in case an instance has been running for a long time
56
+ #
57
+ # @return [String] the version
58
+ #
51
59
  def best_api_version
52
60
  @api_version ||= begin
53
61
  logger.trace("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release")
54
- response = http_client.get("/")
62
+ response = http_client.get("/", { 'X-aws-ec2-metadata-token': v2_token })
55
63
  if response.code == "404"
56
64
  logger.trace("Mixin EC2: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
57
65
  return "latest"
@@ -84,6 +92,23 @@ module Ohai
84
92
  end
85
93
  end
86
94
 
95
+ #
96
+ # Fetch an API token for use querying AWS IMDSv2 or return nil if no token if found
97
+ # AWS like systems (think OpenStack) will not respond with a token here
98
+ #
99
+ # @return [NilClass, String] API token or nil
100
+ #
101
+ def v2_token
102
+ @v2_token ||= begin
103
+ request = http_client.put("/latest/api/token", nil, { 'X-aws-ec2-metadata-token-ttl-seconds': "60" })
104
+ if request.code == "404" # not on AWS
105
+ nil
106
+ else
107
+ request.body
108
+ end
109
+ end
110
+ end
111
+
87
112
  # Get metadata for a given path and API version
88
113
  #
89
114
  # Typically, a 200 response is expected for valid metadata.
@@ -93,7 +118,7 @@ module Ohai
93
118
  def metadata_get(id, api_version)
94
119
  path = "/#{api_version}/meta-data/#{id}"
95
120
  logger.trace("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}#{path}")
96
- response = http_client.get(path)
121
+ response = http_client.get(path, { 'X-aws-ec2-metadata-token': v2_token })
97
122
  case response.code
98
123
  when "200"
99
124
  response.body
@@ -174,13 +199,13 @@ module Ohai
174
199
 
175
200
  def fetch_userdata
176
201
  logger.trace("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/")
177
- response = http_client.get("/#{best_api_version}/user-data/")
202
+ response = http_client.get("/#{best_api_version}/user-data/", { 'X-aws-ec2-metadata-token': v2_token })
178
203
  response.code == "200" ? response.body : nil
179
204
  end
180
205
 
181
206
  def fetch_dynamic_data
182
207
  @fetch_dynamic_data ||= begin
183
- response = http_client.get("/#{best_api_version}/dynamic/instance-identity/document/")
208
+ response = http_client.get("/#{best_api_version}/dynamic/instance-identity/document/", { 'X-aws-ec2-metadata-token': v2_token })
184
209
 
185
210
  if json?(response.body) && response.code == "200"
186
211
  FFI_Yajl::Parser.parse(response.body)
@@ -20,9 +20,19 @@
20
20
  Ohai.plugin(:Chef) do
21
21
  provides "chef_packages/chef"
22
22
 
23
+ def chef_effortless?
24
+ # Determine if client is being run as a Habitat package.
25
+ if Chef::CHEF_ROOT.include?("hab/pkgs/chef/chef")
26
+ # Determine if client is running in zero mode which would show it is using the Effortless pattern.
27
+ # Explicitly set response to true or nil, not false
28
+ ChefConfig::Config["chef_server_url"].include?("chefzero://")
29
+ end
30
+ end
31
+
23
32
  collect_data(:default, :target) do
24
33
  begin
25
34
  require "chef/version"
35
+ require "chef-config/config" unless defined?(ChefConfig::Config)
26
36
  rescue Gem::LoadError
27
37
  logger.trace("Plugin Chef: Unable to load the chef gem to determine the version")
28
38
  # this catches when you've done a major version bump of ohai, but
@@ -35,5 +45,6 @@ Ohai.plugin(:Chef) do
35
45
  chef_packages[:chef] = Mash.new
36
46
  chef_packages[:chef][:version] = Chef::VERSION
37
47
  chef_packages[:chef][:chef_root] = Chef::CHEF_ROOT
48
+ chef_packages[:chef][:chef_effortless] = chef_effortless?
38
49
  end
39
50
  end
@@ -121,6 +121,9 @@ Ohai.plugin(:EC2) do
121
121
  logger.trace("Plugin EC2: looks_like_ec2? == true")
122
122
  ec2 Mash.new
123
123
  fetch_metadata.each do |k, v|
124
+ # this includes sensitive data we don't want to store on the node
125
+ next if k == "identity_credentials_ec2_security_credentials_ec2_instance"
126
+
124
127
  # fetch_metadata returns IAM security credentials, including the IAM user's
125
128
  # secret access key. We'd rather not have ohai send this information
126
129
  # to the server. If the instance is associated with an IAM role we grab
@@ -29,7 +29,7 @@ Ohai.plugin(:Eucalyptus) do
29
29
  provides "eucalyptus"
30
30
  depends "network/interfaces"
31
31
 
32
- MAC_MATCH = /^[dD]0:0[dD]:/.freeze
32
+ MAC_MATCH = /^[dD]0:0[dD]:/.freeze unless defined?(MAC_MATCH)
33
33
 
34
34
  # returns the mac address from the collection of all address types
35
35
  def get_mac_address(addresses)
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Davide Cavalca <dcavalca@fb.com>
4
+ # Copyright:: Copyright (c) 2020 Facebook
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ Ohai.plugin(:Grub2) do
21
+ provides "grub2/environment"
22
+ optional true
23
+
24
+ collect_data(:dragonflybsd, :freebsd, :linux, :netbsd) do
25
+ editenv_path = which("grub2-editenv")
26
+ if editenv_path
27
+ editenv_out = shell_out("#{editenv_path} list")
28
+
29
+ grub2 Mash.new unless grub2
30
+ grub2[:environment] ||= Mash.new
31
+
32
+ editenv_out.stdout.each_line do |line|
33
+ key, val = line.split("=", 2)
34
+ grub2[:environment][key] = val.strip
35
+ end
36
+ else
37
+ logger.trace("Plugin Grub2: Could not find grub2-editenv. Skipping plugin.")
38
+ end
39
+ end
40
+ end
@@ -18,31 +18,38 @@
18
18
  Ohai.plugin(:Linode) do
19
19
  provides "linode"
20
20
 
21
- depends "kernel"
21
+ depends "domain"
22
22
  depends "network/interfaces"
23
23
 
24
- # Checks for matching linode kernel name
24
+ # Checks to see if the node is in the members.linode.com domain
25
25
  #
26
- # Returns true or false
27
- def has_linode_kernel?
28
- if ( kernel_data = kernel )
29
- kernel_data[:release].split("-").last.include?("linode")
30
- end
26
+ # @return [Boolean]
27
+ #
28
+ def has_linode_domain?
29
+ domain&.include?("linode")
30
+ end
31
+
32
+ # Checks for linode mirrors in the apt sources.list file
33
+ #
34
+ # @return [Boolean]
35
+ #
36
+ def has_linode_apt_repos?
37
+ file_exist?("/etc/apt/sources.list") && file_read("/etc/apt/sources.list").include?("linode")
31
38
  end
32
39
 
33
40
  # Identifies the linode cloud by preferring the hint, then
34
41
  #
35
- # Returns true or false
42
+ # @return [Boolean]
43
+ #
36
44
  def looks_like_linode?
37
- hint?("linode") || has_linode_kernel?
45
+ hint?("linode") || has_linode_domain? || has_linode_apt_repos?
38
46
  end
39
47
 
40
- # Names linode ip address
48
+ # Alters linode mash with new interface based on name parameter
41
49
  #
42
- # name - symbol of ohai name (e.g. :public_ip)
43
- # eth - Interface name (e.g. :eth0)
50
+ # @param [Symbol] name Ohai name (e.g. :public_ip)
51
+ # @param [Symbol] eth Interface name (e.g. :eth0)
44
52
  #
45
- # Alters linode mash with new interface based on name parameter
46
53
  def get_ip_address(name, eth)
47
54
  if ( eth_iface = network[:interfaces][eth] )
48
55
  eth_iface[:addresses].each do |key, info|
@@ -19,7 +19,6 @@
19
19
  # limitations under the License.
20
20
 
21
21
  Ohai.plugin(:Lspci) do
22
- depends "platform"
23
22
  provides "pci"
24
23
  optional true
25
24
 
@@ -273,6 +273,30 @@ Ohai.plugin(:Network) do
273
273
  iface
274
274
  end
275
275
 
276
+ # determine pause parameters for the interface using ethtool
277
+ def ethernet_pause_parameters(iface)
278
+ return iface unless ethtool_binary_path
279
+
280
+ iface.each_key do |tmp_int|
281
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
282
+
283
+ so = shell_out("#{ethtool_binary_path} -a #{tmp_int}")
284
+ logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
285
+ iface[tmp_int]["pause_params"] = {}
286
+ so.stdout.lines.each do |line|
287
+ next if line.start_with?("Pause parameters for")
288
+ next if line.strip.nil?
289
+
290
+ key, val = line.split(/:\s+/)
291
+ if val
292
+ pause_key = "#{key.downcase.tr(" ", "_")}"
293
+ iface[tmp_int]["pause_params"][pause_key] = val.strip.eql? "on"
294
+ end
295
+ end
296
+ end
297
+ iface
298
+ end
299
+
276
300
  # determine driver info for the interface using ethtool
277
301
  def ethernet_driver_info(iface)
278
302
  return iface unless ethtool_binary_path
@@ -385,7 +409,7 @@ Ohai.plugin(:Network) do
385
409
  if line =~ IPROUTE_INT_REGEX
386
410
  cint = $2
387
411
  iface[cint] = Mash.new
388
- if cint =~ /^(\w+)(\d+.*)/
412
+ if cint =~ /^(\w+?)(\d+.*)/
389
413
  iface[cint][:type] = $1
390
414
  iface[cint][:number] = $2
391
415
  end
@@ -696,7 +720,7 @@ Ohai.plugin(:Network) do
696
720
  if line =~ /^([0-9a-zA-Z@\.\:\-_]+)\s+/
697
721
  cint = $1
698
722
  iface[cint] = Mash.new
699
- if cint =~ /^(\w+)(\d+.*)/
723
+ if cint =~ /^(\w+?)(\d+.*)/
700
724
  iface[cint][:type] = $1
701
725
  iface[cint][:number] = $2
702
726
  end
@@ -770,6 +794,7 @@ Ohai.plugin(:Network) do
770
794
  iface = ethernet_channel_parameters(iface)
771
795
  iface = ethernet_coalesce_parameters(iface)
772
796
  iface = ethernet_driver_info(iface)
797
+ iface = ethernet_pause_parameters(iface)
773
798
  counters[:network][:interfaces] = net_counters
774
799
  network["interfaces"] = iface
775
800
  end
@@ -112,15 +112,16 @@ Ohai.plugin(:Platform) do
112
112
  # ohai uses. If you're adding a new platform here and you want to change the name
113
113
  # you'll want to add it here and then add a spec for the platform_id_remap method
114
114
  {
115
- "rhel" => "redhat",
115
+ "alinux" => "alibabalinux",
116
116
  "amzn" => "amazon",
117
+ "archarm" => "arch",
118
+ "cumulus-linux" => "cumulus",
117
119
  "ol" => "oracle",
118
- "sles" => "suse",
119
- "sles_sap" => "suse",
120
120
  "opensuse-leap" => "opensuseleap",
121
+ "rhel" => "redhat",
122
+ "sles_sap" => "suse",
123
+ "sles" => "suse",
121
124
  "xenenterprise" => "xenserver",
122
- "cumulus-linux" => "cumulus",
123
- "archarm" => "arch",
124
125
  }[id] || id
125
126
  end
126
127
 
@@ -136,7 +137,7 @@ Ohai.plugin(:Platform) do
136
137
  when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /cumulus/, /kali/, /pop/
137
138
  # apt-get+dpkg almost certainly goes here
138
139
  "debian"
139
- when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /xcp/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/, /clearos/, /bigip/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
140
+ when /oracle/, /centos/, /redhat/, /almalinux/, /scientific/, /enterpriseenterprise/, /xcp/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/, /clearos/, /bigip/, /alibabalinux/, /sangoma/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
140
141
  # NOTE: "rhel" should be reserved exclusively for recompiled rhel versions that are nearly perfectly compatible down to the platform_version.
141
142
  # The operating systems that are "rhel" should all be as compatible as rhel7 = centos7 = oracle7 = scientific7 (98%-ish core RPM version compatibility
142
143
  # and the version numbers MUST track the upstream). The appropriate EPEL version repo should work nearly perfectly. Some variation like the
@@ -287,6 +288,9 @@ Ohai.plugin(:Platform) do
287
288
  # centos only includes the major version in os-release for some reason
288
289
  if os_release_info["ID"] == "centos"
289
290
  get_redhatish_version(file_read("/etc/redhat-release").chomp)
291
+ # debian testing and unstable don't have VERSION_ID set
292
+ elsif os_release_info["ID"] == "debian"
293
+ os_release_info["VERSION_ID"] || file_read("/etc/debian_version").chomp
290
294
  else
291
295
  os_release_info["VERSION_ID"] || shell_out("/bin/uname -r").stdout.strip
292
296
  end
@@ -225,7 +225,11 @@ Ohai.plugin(:Virtualization) do
225
225
  # If so, we may need to look further for a differentiator (OHAI-573)
226
226
  virtualization[:systems][:lxc] = "host"
227
227
  end
228
- elsif file_exist?("/.dockerenv") || file_exist?("/.dockerinit")
228
+ end
229
+
230
+ # regardless of what we found above, if we're a docker container inside
231
+ # of the above, lets report as a docker container
232
+ if file_exist?("/.dockerenv") || file_exist?("/.dockerinit")
229
233
  logger.trace("Plugin Virtualization: .dockerenv or .dockerinit exist. Detecting as docker guest")
230
234
  virtualization[:system] = "docker"
231
235
  virtualization[:role] = "guest"
@@ -106,7 +106,7 @@ Ohai.plugin(:Packages) do
106
106
  end
107
107
  end
108
108
 
109
- def collect_programs_from_registry_key(key_path)
109
+ def collect_programs_from_registry_key(repo, key_path)
110
110
  # from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
111
111
  if ::RbConfig::CONFIG["target_cpu"] == "i386"
112
112
  reg_type = Win32::Registry::KEY_READ | 0x100
@@ -115,7 +115,7 @@ Ohai.plugin(:Packages) do
115
115
  else
116
116
  reg_type = Win32::Registry::KEY_READ
117
117
  end
118
- Win32::Registry::HKEY_LOCAL_MACHINE.open(key_path, reg_type) do |reg|
118
+ repo.open(key_path, reg_type) do |reg|
119
119
  reg.each_key do |key, _wtime|
120
120
  pkg = reg.open(key)
121
121
  name = pkg["DisplayName"] rescue nil
@@ -133,9 +133,10 @@ Ohai.plugin(:Packages) do
133
133
  collect_data(:windows) do
134
134
  require "win32/registry" unless defined?(Win32::Registry)
135
135
  packages Mash.new
136
- collect_programs_from_registry_key('Software\Microsoft\Windows\CurrentVersion\Uninstall')
136
+ collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
137
+ collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
138
+ collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
137
139
  # on 64 bit systems, 32 bit programs are stored here
138
- collect_programs_from_registry_key('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
139
140
  end
140
141
 
141
142
  collect_data(:aix) do
@@ -162,8 +162,8 @@ Ohai.plugin(:Rackspace) do
162
162
  unless rackspace[:public_ip].nil?
163
163
  rackspace[:public_hostname] = begin
164
164
  Resolv.getname(rackspace[:public_ip])
165
- rescue Resolv::ResolvError, Resolv::ResolvTimeout
166
- rackspace[:public_ip]
165
+ rescue Resolv::ResolvError, Resolv::ResolvTimeout
166
+ rackspace[:public_ip]
167
167
  end
168
168
  end
169
169
  rackspace[:local_ipv4] = rackspace[:private_ip]
@@ -18,7 +18,6 @@
18
18
  #
19
19
 
20
20
  Ohai.plugin(:Lsscsi) do
21
- depends "platform"
22
21
  provides "scsi"
23
22
  optional true
24
23
 
data/lib/ohai/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
 
20
20
  module Ohai
21
21
  OHAI_ROOT = File.expand_path(__dir__)
22
- VERSION = "16.7.37"
22
+ VERSION = "16.12.3"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.7.37
4
+ version: 16.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -285,6 +285,7 @@ files:
285
285
  - lib/ohai/plugins/gce.rb
286
286
  - lib/ohai/plugins/go.rb
287
287
  - lib/ohai/plugins/groovy.rb
288
+ - lib/ohai/plugins/grub2.rb
288
289
  - lib/ohai/plugins/haskell.rb
289
290
  - lib/ohai/plugins/hostname.rb
290
291
  - lib/ohai/plugins/init_package.rb
@@ -390,7 +391,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
391
  - !ruby/object:Gem::Version
391
392
  version: '0'
392
393
  requirements: []
393
- rubygems_version: 3.0.3
394
+ rubygems_version: 3.1.4
394
395
  signing_key:
395
396
  specification_version: 4
396
397
  summary: Ohai profiles your system and emits JSON