ohai 7.2.0.rc.1 → 7.2.0.rc.2

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
  SHA1:
3
- metadata.gz: e696d6497786e063bbcc85830a45813a0b744847
4
- data.tar.gz: f2c84d8af20573e108ba3f2401a50d87a3df4258
3
+ metadata.gz: 9d1436bcd73ef60c3c794bdf276c0b572e757455
4
+ data.tar.gz: b767aa0d9791d62f002005b904c2115585ce4139
5
5
  SHA512:
6
- metadata.gz: 70175ff249bb15b9bf961fc2040cfed5da50f6f3fc28b44c519e07615d550f050d6e7f002ddb7c0a51c35feb3fb43a21fe2fde754d65be2f9cbc6a628859831a
7
- data.tar.gz: deb3e278ce5af36eb12080d9bbfa836a44bad719a7af7ba91ca0b1b6a664876a8508e3b1b37902703e93715984be8f08d7a2b9b0e062c230392a9b00d5228655
6
+ metadata.gz: aced95949e6cb8df985e11c345dfba4a73f30a222fd06be5d250bcb36d69fa96c9566394a2bf3b4d6379ff765d307888d5765a61aaf648864af593f181ef7ef8
7
+ data.tar.gz: 82b6fa1453d0352261468a31e23af6a5a047ef681da5db209c4b49bbf87dcf3f5e17a352d9bf5308d67e1e207797bb60b8b3e8be386db482b2bef592e3373fd3
@@ -122,6 +122,7 @@ module Ohai
122
122
  def fetch_metadata(id='', api_version=nil)
123
123
  api_version ||= best_api_version
124
124
  return Hash.new if api_version.nil?
125
+
125
126
  metadata = Hash.new
126
127
  retrieved_metadata = metadata_get(id, api_version)
127
128
  if retrieved_metadata
@@ -40,7 +40,7 @@ Ohai.plugin(:EC2) do
40
40
  end
41
41
 
42
42
  def looks_like_ec2?
43
- # Try non-blocking connect so we don't "block" if
43
+ # Try non-blocking connect so we don't "block" if
44
44
  # the Xen environment is *not* EC2
45
45
  hint?('ec2') || has_ec2_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80)
46
46
  end
@@ -49,7 +49,14 @@ Ohai.plugin(:EC2) do
49
49
  if looks_like_ec2?
50
50
  Ohai::Log.debug("looks_like_ec2? == true")
51
51
  ec2 Mash.new
52
- fetch_metadata.each {|k, v| ec2[k] = v }
52
+ fetch_metadata.each do |k, v|
53
+ # fetch_metadata returns IAM security credentials, including the IAM user's
54
+ # secret access key. We'd rather not have ohai send this information
55
+ # to the server.
56
+ # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
57
+ next if k == 'iam' && !hint?('iam')
58
+ ec2[k] = v
59
+ end
53
60
  ec2[:userdata] = self.fetch_userdata
54
61
  else
55
62
  Ohai::Log.debug("looks_like_ec2? == false")
@@ -47,7 +47,7 @@ Ohai.plugin(:Eucalyptus) do
47
47
  end
48
48
 
49
49
  def looks_like_euca?
50
- # Try non-blocking connect so we don't "block" if
50
+ # Try non-blocking connect so we don't "block" if
51
51
  # the Xen environment is *not* EC2
52
52
  hint?('eucalyptus') || has_euca_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80)
53
53
  end
@@ -56,7 +56,17 @@ Ohai.plugin(:Eucalyptus) do
56
56
  if looks_like_euca?
57
57
  Ohai::Log.debug("looks_like_euca? == true")
58
58
  eucalyptus Mash.new
59
- self.fetch_metadata.each {|k, v| eucalyptus[k] = v }
59
+ self.fetch_metadata.each do |k, v|
60
+ # Eucalyptus 3.4+ supports IAM roles and Instance Profiles much like AWS
61
+ # https://www.eucalyptus.com/blog/2013/10/15/iam-roles-and-instance-profiles-eucalyptus-34
62
+ #
63
+ # fetch_metadata returns IAM security credentials, including the IAM user's
64
+ # secret access key. We'd rather not have ohai send this information
65
+ # to the server.
66
+ # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
67
+ next if k == 'iam' && !hint?('iam')
68
+ eucalyptus[k] = v
69
+ end
60
70
  eucalyptus[:userdata] = self.fetch_userdata
61
71
  else
62
72
  Ohai::Log.debug("looks_like_euca? == false")
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '7.2.0.rc.1'
21
+ VERSION = '7.2.0.rc.2'
22
22
  end
@@ -44,6 +44,7 @@ describe Ohai::System, "plugin ec2" do
44
44
  @http_client.should_receive(:get).
45
45
  with("/").twice.
46
46
  and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
47
+ File.stub(:exist?).and_return(false)
47
48
  end
48
49
 
49
50
  it "should recursively fetch all the ec2 metadata" do
@@ -64,6 +65,7 @@ describe Ohai::System, "plugin ec2" do
64
65
  and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
65
66
 
66
67
  @plugin.run
68
+
67
69
  @plugin[:ec2].should_not be_nil
68
70
  @plugin[:ec2]['instance_type'].should == "c1.medium"
69
71
  @plugin[:ec2]['ami_id'].should == "ami-5d2dc934"
@@ -92,33 +94,80 @@ describe Ohai::System, "plugin ec2" do
92
94
  @http_client.should_receive(:get).
93
95
  with("/2012-01-12/user-data/").
94
96
  and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
97
+
95
98
  @plugin.run
96
99
 
97
100
  @plugin[:ec2].should_not be_nil
98
101
  @plugin[:ec2]['network_interfaces_macs']['12:34:56:78:9a:bc']['public_hostname'].should eql('server17.opscode.com')
99
102
  end
100
103
 
101
- it "should parse ec2 iam/ directory and its JSON files properly" do
102
- @http_client.should_receive(:get).
103
- with("/2012-01-12/meta-data/").
104
- and_return(double("Net::HTTP Response", :body => "iam/", :code => "200"))
105
- @http_client.should_receive(:get).
106
- with("/2012-01-12/meta-data/iam/").
107
- and_return(double("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
108
- @http_client.should_receive(:get).
109
- with("/2012-01-12/meta-data/iam/security-credentials/").
110
- and_return(double("Net::HTTP Response", :body => "MyRole", :code => "200"))
111
- @http_client.should_receive(:get).
112
- with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
113
- and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
114
- @http_client.should_receive(:get).
115
- with("/2012-01-12/user-data/").
116
- and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
117
- @plugin.run
104
+ context "with ec2_iam cloud file" do
105
+ before do
106
+ if windows?
107
+ File.stub(:exist?).with('C:\chef\ohai\hints/iam.json').and_return(true)
108
+ File.stub(:read).with('C:\chef\ohai\hints/iam.json').and_return('')
109
+ else
110
+ File.stub(:exist?).with('/etc/chef/ohai/hints/iam.json').and_return(true)
111
+ File.stub(:read).with('/etc/chef/ohai/hints/iam.json').and_return('')
112
+ end
113
+ end
118
114
 
119
- @plugin[:ec2].should_not be_nil
120
- @plugin[:ec2]['iam']['security-credentials']['MyRole']['Code'].should eql 'Success'
121
- @plugin[:ec2]['iam']['security-credentials']['MyRole']['Token'].should eql '12345678'
115
+ it "should parse ec2 iam/ directory and collect iam/security-credentials/" do
116
+ @http_client.should_receive(:get).
117
+ with("/2012-01-12/meta-data/").
118
+ and_return(double("Net::HTTP Response", :body => "iam/", :code => "200"))
119
+ @http_client.should_receive(:get).
120
+ with("/2012-01-12/meta-data/iam/").
121
+ and_return(double("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
122
+ @http_client.should_receive(:get).
123
+ with("/2012-01-12/meta-data/iam/security-credentials/").
124
+ and_return(double("Net::HTTP Response", :body => "MyRole", :code => "200"))
125
+ @http_client.should_receive(:get).
126
+ with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
127
+ and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
128
+ @http_client.should_receive(:get).
129
+ with("/2012-01-12/user-data/").
130
+ and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
131
+
132
+ @plugin.run
133
+
134
+ @plugin[:ec2].should_not be_nil
135
+ @plugin[:ec2]['iam']['security-credentials']['MyRole']['Code'].should eql 'Success'
136
+ @plugin[:ec2]['iam']['security-credentials']['MyRole']['Token'].should eql '12345678'
137
+ end
138
+ end
139
+
140
+ context "without ec2_iam cloud file" do
141
+ before do
142
+ if windows?
143
+ File.stub(:exist?).with('C:\chef\ohai\hints/iam.json').and_return(false)
144
+ else
145
+ File.stub(:exist?).with('/etc/chef/ohai/hints/iam.json').and_return(false)
146
+ end
147
+ end
148
+
149
+ it "should parse ec2 iam/ directory and NOT collect iam/security-credentials/" do
150
+ @http_client.should_receive(:get).
151
+ with("/2012-01-12/meta-data/").
152
+ and_return(double("Net::HTTP Response", :body => "iam/", :code => "200"))
153
+ @http_client.should_receive(:get).
154
+ with("/2012-01-12/meta-data/iam/").
155
+ and_return(double("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
156
+ @http_client.should_receive(:get).
157
+ with("/2012-01-12/meta-data/iam/security-credentials/").
158
+ and_return(double("Net::HTTP Response", :body => "MyRole", :code => "200"))
159
+ @http_client.should_receive(:get).
160
+ with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
161
+ and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
162
+ @http_client.should_receive(:get).
163
+ with("/2012-01-12/user-data/").
164
+ and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
165
+
166
+ @plugin.run
167
+
168
+ @plugin[:ec2].should_not be_nil
169
+ @plugin[:ec2]['iam'].should be_nil
170
+ end
122
171
  end
123
172
 
124
173
  it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do
@@ -201,10 +250,13 @@ describe Ohai::System, "plugin ec2" do
201
250
  it_should_behave_like "ec2"
202
251
 
203
252
  before(:each) do
204
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
205
- File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
206
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
207
- File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
253
+ if windows?
254
+ File.should_receive(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
255
+ File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
256
+ else
257
+ File.should_receive(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
258
+ File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
259
+ end
208
260
  end
209
261
  end
210
262
 
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: 7.2.0.rc.1
4
+ version: 7.2.0.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-27 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types