ohai 16.8.1 → 16.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 168be10defab5e91f8da06ce4d101a461ed13a2051d4b6901c3039571c7a3066
4
- data.tar.gz: 8783ddbdc49208974d09cfc7e708760402248719baaf2a1a8dce28e8a14902bc
3
+ metadata.gz: 67ffbc76e1366d1413aa7f01ac2e8f4ff22b89f8a9fa8568b348a441c284b8f9
4
+ data.tar.gz: 59e0790fc0ee8182982c63f1d495c89a974fec9950a0843ac46d2eeb9dea6baf
5
5
  SHA512:
6
- metadata.gz: 5781908ba60b11f68397c10693d6c084e1eb021dc5a6b1348448b712225322295cc5b510dc41e9feecbf1a463d23f47773428ce540c138b43a2c6fd9ced079a4
7
- data.tar.gz: 50a9ba71dca6681a84536c1f443653dc4d78172ded2fffa9022ad8ed8e577a0dc3e1bc6329b021438fe3ee6d2d62d1154093928fb3fb53957df38363f0bf92c2
6
+ metadata.gz: 867b388ecf15e49431eaea7b315411522d8d57e2e4310cf867048dcadde9832dc94a02710c99ef332b8f51f4e9fe88db0bb00e47ac3505bc911a2ca3763a3a0e
7
+ data.tar.gz: 4c0d991e9d1b3b92f705611f54af8f826ecd866cbc7f8b65d4ad70fb879f4a1501a2e1a38a908e4e6b4c3d0367e4b16167d843ba5840d64f9b41a68aae448f33
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)
@@ -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
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Lance Albertson (lance@osuosl.org>)
4
+ # Copyright:: Copyright (c) 2021 Oregon State University
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(:OsRelease) do
21
+ provides "os_release"
22
+
23
+ collect_data(:linux) do
24
+ os_release Mash.new unless os_release
25
+
26
+ # https://www.freedesktop.org/software/systemd/man/os-release.html
27
+ if file_exist?("/etc/os-release")
28
+ file_read("/etc/os-release").each_line do |line|
29
+ key, value = line.split("=")
30
+ if key == "ID_LIKE"
31
+ os_release[key.downcase] = value.chomp.gsub(/\A"|"\Z/, "").split(" ") if value
32
+ else
33
+ os_release[key.downcase] = value.chomp.gsub(/\A"|"\Z/, "") if value
34
+ end
35
+ end
36
+ end
37
+ end
38
+ 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]
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.8.1"
22
+ VERSION = "16.13.0"
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.8.1
4
+ version: 16.13.0
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-12-04 00:00:00.000000000 Z
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -305,6 +305,7 @@ files:
305
305
  - lib/ohai/plugins/linux/mdadm.rb
306
306
  - lib/ohai/plugins/linux/memory.rb
307
307
  - lib/ohai/plugins/linux/network.rb
308
+ - lib/ohai/plugins/linux/os_release.rb
308
309
  - lib/ohai/plugins/linux/platform.rb
309
310
  - lib/ohai/plugins/linux/selinux.rb
310
311
  - lib/ohai/plugins/linux/sessions.rb
@@ -391,7 +392,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
391
392
  - !ruby/object:Gem::Version
392
393
  version: '0'
393
394
  requirements: []
394
- rubygems_version: 3.0.3
395
+ rubygems_version: 3.1.4
395
396
  signing_key:
396
397
  specification_version: 4
397
398
  summary: Ohai profiles your system and emits JSON