vagrant-ec2-metadata 0.0.3 → 0.0.5

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
- SHA1:
3
- metadata.gz: b39fa813ecb66b687b5bfdd5be62352fae5e4e0d
4
- data.tar.gz: 2da7b1319f80aecdecf9c6922bde2530aefdfd26
2
+ SHA256:
3
+ metadata.gz: 2e867c6d250971803534937a1a989806fb0a2e65ad650e01fa5770f77ec083f0
4
+ data.tar.gz: 343d5435d23a8a54a9f3936822cb47a3416e43b44b7f15297e1b1e5a54bfb99c
5
5
  SHA512:
6
- metadata.gz: 3772d5c7560a0e4b0e8b27757b2d1faa83dda570626ed1bebe064733fe8fa6688a98113bd76ae5f196c56dff90325971f64dfaa08cb405ad86d7387068b87e0b
7
- data.tar.gz: b0dc167dd1e73d3a0ee1df85dda666f806d3f7e18f4f65519eaa361cef2d26ff7c08324f3bccb5a474c253c21f62f66539c681138caa82d3eac59507b1ec751a
6
+ metadata.gz: d69d13a1f61cb0406324f3c4c90d336172df3ef3f7526a983fd14af28d2aa366ba120ebc127719849bcbc5120bfdb1654ba5870f75f1c81cb5c323f2ca4994f8
7
+ data.tar.gz: 88f574e031baa81c664e876cf73a54968eb7af388d033de0bfcefbdc78325eabe6c31d456c44af688c4f365acc6cbd4c074e94168b9ebfdba0344be866c2fab4
checksums.yaml.gz.sig CHANGED
Binary file
@@ -4,6 +4,15 @@ require "socket"
4
4
 
5
5
  ENV["AWS_DEFAULT_REGION"] ||= "us-west-2"
6
6
 
7
+ # WEBrick doesn't let us use PUT unless we apply this hack first
8
+ module WEBrick
9
+ module HTTPServlet
10
+ class ProcHandler
11
+ alias do_PUT do_GET
12
+ end
13
+ end
14
+ end
15
+
7
16
  module VagrantEc2Metadata
8
17
  class Server
9
18
  def initialize(config, port, options, env)
@@ -11,6 +20,7 @@ module VagrantEc2Metadata
11
20
  @port = port
12
21
  @options = options
13
22
  @env = env
23
+ @imdsv2_token = "supersecrettoken"
14
24
  end
15
25
 
16
26
  def start
@@ -31,10 +41,29 @@ module VagrantEc2Metadata
31
41
  next
32
42
  end
33
43
 
44
+ if req.request_method == "PUT"
45
+ if req.path == "/latest/api/token"
46
+ res.body = @imdsv2_token
47
+ end
48
+ next
49
+ end
50
+
51
+ if @config.require_tokens && (!req.header["x-aws-ec2-metadata-token"] || req.header["x-aws-ec2-metadata-token"][0] != @imdsv2_token)
52
+ res.status = 401 # Unauthorized
53
+ next
54
+ end
55
+
34
56
  # This endpoint is all we handle right now
35
- next if !req.path.start_with?("/latest/meta-data/iam/security-credentials/")
57
+ if !req.path.start_with?("/latest/meta-data/iam/security-credentials")
58
+ res.status = 404
59
+ next
60
+ end
36
61
 
37
- if req.path == "/latest/meta-data/iam/security-credentials/"
62
+ if req.path == "/latest/meta-data/iam/security-credentials"
63
+ # The Go SDK sends the request here first, then gets redirected to the correct path.. https://github.com/aws/aws-sdk-go/pull/2002
64
+ res.status = 301
65
+ res["Location"] = "/latest/meta-data/iam/security-credentials/"
66
+ elsif req.path == "/latest/meta-data/iam/security-credentials/"
38
67
  res.body = "role"
39
68
  else
40
69
  sts = ::Aws::STS::Client.new(profile: @config.profile)
@@ -52,17 +81,17 @@ module VagrantEc2Metadata
52
81
  creds = resp.credentials
53
82
  end
54
83
 
55
- res.body = <<EOF
56
- {
57
- "Code" : "Success",
58
- "LastUpdated" : "#{Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")}",
59
- "Type" : "AWS-HMAC",
60
- "AccessKeyId" : "#{creds.access_key_id}",
61
- "SecretAccessKey" : "#{creds.secret_access_key}",
62
- "Token" : "#{creds.session_token}",
63
- "Expiration" : "#{creds.expiration.strftime("%Y-%m-%dT%H:%M:%SZ")}"
64
- }
65
- EOF
84
+ res.body = <<~EOF
85
+ {
86
+ "Code" : "Success",
87
+ "LastUpdated" : "#{Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")}",
88
+ "Type" : "AWS-HMAC",
89
+ "AccessKeyId" : "#{creds.access_key_id}",
90
+ "SecretAccessKey" : "#{creds.secret_access_key}",
91
+ "Token" : "#{creds.session_token}",
92
+ "Expiration" : "#{creds.expiration.strftime("%Y-%m-%dT%H:%M:%SZ")}"
93
+ }
94
+ EOF
66
95
  end
67
96
  end
68
97
 
@@ -1,3 +1,3 @@
1
1
  module VagrantEc2Metadata
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -7,9 +7,11 @@ module VagrantEc2Metadata
7
7
  attr_accessor :profile
8
8
  attr_accessor :role_arn
9
9
  attr_accessor :port
10
+ attr_accessor :require_tokens
10
11
 
11
12
  def initialize
12
13
  @profile = UNSET_VALUE
14
+ @require_tokens = false
13
15
  end
14
16
 
15
17
  def finalize!
@@ -40,10 +42,9 @@ module VagrantEc2Metadata
40
42
  # If you are having troubles with the iptables rule, you can flush it with:
41
43
  # sudo iptables -t nat -F
42
44
 
43
- cmd = <<EOF
44
- sudo iptables -t nat -A OUTPUT -p tcp -d 169.254.169.254 -j DNAT --to-destination #{host_ip}:#{port} || echo 'Error setting up iptables rule.'
45
- grep -q -F '169.254.169.254 instance-data' /etc/hosts || echo "# Added by vagrant-ec2-metadata:\n169.254.169.254 instance-data" | sudo tee -a /etc/hosts >/dev/null
46
- EOF
45
+ cmd = <<~EOF
46
+ sudo iptables -t nat -A OUTPUT -p tcp -d 169.254.169.254 -j DNAT --to-destination #{host_ip}:#{port} || echo 'Error setting up iptables rule.'
47
+ EOF
47
48
 
48
49
  @machine.ui.info("Setting up an iptables rule for the EC2 metadata server (port #{port}).")
49
50
  @machine.action(:ssh_run,
data.tar.gz.sig CHANGED
@@ -1 +1 @@
1
- ����27h��k���D��\'Mj]E���i��k�<cd&�r����X Z�"���ͧ��j<˾� �I�
1
+ ��3$6��=V��,>s��8ه�H��c蘣
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-ec2-metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Sundin
@@ -31,7 +31,7 @@ cert_chain:
31
31
  E04BZKo2WzOTzSDymo97Yu4YFgyc98umMyeaCvPk4YmdNzqSanAXpY2bnsyu0CF5
32
32
  Td0=
33
33
  -----END CERTIFICATE-----
34
- date: 2017-11-02 00:00:00.000000000 Z
34
+ date: 2022-10-25 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aws-sdk-core
@@ -39,28 +39,28 @@ dependencies:
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '3.6'
42
+ version: '3.164'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '3.6'
49
+ version: '3.164'
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: webrick
52
52
  requirement: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '1.3'
56
+ version: 1.6.1
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '1.3'
63
+ version: 1.6.1
64
64
  description: Easily provide vagrant machines with AWS credentials by faking an EC2
65
65
  metadata server.
66
66
  email:
@@ -91,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.13
94
+ rubygems_version: 3.1.2
96
95
  signing_key:
97
96
  specification_version: 4
98
97
  summary: Easily provide vagrant machines with AWS credentials.
metadata.gz.sig CHANGED
@@ -1 +1,3 @@
1
- ��5z �(6Zs�^�^J=b����4>���gh$L��1E�>�Á��X8)�>"%�48�i����\�eyL>"��
1
+ E>g2T��� �i� ��5����� �Hg`u����+�ү�
2
+ j�Eu �Ƒ����p�
3
+ �䃅�wa�'p��/� *�