vagrant-box-s3 0.1.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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/lib/vagrant-box-s3/downloader.rb +46 -0
- data/lib/vagrant-box-s3/utils.rb +66 -0
- data/lib/vagrant-box-s3/version.rb +5 -0
- data/lib/vagrant-box-s3.rb +14 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d81dbf3d8b32768cfc022e376cfc5426bf6f84048e51788244ec03bf092cc827
|
4
|
+
data.tar.gz: 7d4edce6804ea7df82cbc6dd4faf781b486e8eec61979e595b45a321a000bf27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 22d63d9785c64664cdd552f4486870711caa7f6141a11756505d92c44ff7a140922fe7158708a2992e03cbfaade073a9782de46296b4462eedcf977d193439bb
|
7
|
+
data.tar.gz: bac015704c14167f29339d1390cd4458c732d945d02075201024f50ad5e72d0a2196a115ae8f1975b0c0ef6df0e13b8348f30a372754804089aff0f4e2e433b5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Steve Whiteley
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Vagrant Box S3
|
2
|
+
|
3
|
+
Use Vagrant boxes stored in Amazon S3 private buckets.
|
4
|
+
|
5
|
+
### Requirements
|
6
|
+
|
7
|
+
- [vagrant](https://developer.hashicorp.com/vagrant/install?product_intent=vagrant) (2.4.x)
|
8
|
+
- [aws-sdk-s3](https://rubygems.org/gems/aws-sdk-s3/versions/1.143.0) (1.x)
|
9
|
+
|
10
|
+
## Features
|
11
|
+
|
12
|
+
This plugin works by monkey patching `Vagrant::Util::Downloader`, extending the core Downloader class in Vagrant to
|
13
|
+
override the `execute_curl` method to replace S3 box URLs with pre-signed S3 URLs.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
vagrant plugin install ../vagrant-box-s3/pkg/vagrant-box-s3-0.1.2.gem
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The plugin with automatically sign requests to AWS S3 URLs with your AWS credentials, allowing you to store private
|
22
|
+
boxes on S3 with your own bucket policies in place.
|
23
|
+
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
AWS credentials are read from the standard environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
|
27
|
+
|
28
|
+
You can also use your credentials file to create a profile. Select the appropriate profile using the `AWS_PROFILE` environment variable. For example:
|
29
|
+
|
30
|
+
#### ~/.aws/credentials
|
31
|
+
|
32
|
+
[vagrant-s3auth]
|
33
|
+
aws_access_key_id = AKIA...
|
34
|
+
aws_secret_access_key = ...
|
35
|
+
|
36
|
+
#### Vagrantfile
|
37
|
+
|
38
|
+
ENV.delete_if { |name| name.start_with?('AWS_') } # Filter out rogue env vars.
|
39
|
+
ENV['AWS_PROFILE'] = 'vagrant-s3auth'
|
40
|
+
|
41
|
+
Vagrant.configure("2") { |config| ... }
|
42
|
+
|
43
|
+
### S3 URLs
|
44
|
+
|
45
|
+
You can use any valid HTTP(S) URL for your box URL:
|
46
|
+
|
47
|
+
#### Path-Style URLs
|
48
|
+
|
49
|
+
Specify the bucket name in the path of the URL. AWS has deprecated path-style URLs, but they might still be seen or used in legacy systems.
|
50
|
+
|
51
|
+
- Format: https://s3.Region.amazonaws.com/bucket-name/key-name
|
52
|
+
Example: https://s3.eu-west-1.amazonaws.com/mybucket/mybox.box
|
53
|
+
|
54
|
+
- Format: https://s3-Region.amazonaws.com/bucket-name/keyname
|
55
|
+
Example: https://s3-eu-west-1.amazonaws.com/bucket-name/mybox.box
|
56
|
+
|
57
|
+
#### Virtual-Hosted-Style URLs
|
58
|
+
Virtual-hosted-style URLs use the bucket name as a subdomain. This is the recommended and most commonly used format.
|
59
|
+
|
60
|
+
- Format: https://bucket-name.s3.Region.amazonaws.com/key-name
|
61
|
+
- Example: https://mybucket.s3.eu-west-1.amazonaws.com/mybox.box
|
62
|
+
|
63
|
+
### IAM configuration
|
64
|
+
|
65
|
+
IAM accounts will need at least the following policy, replacing `BUCKET` with your bucket name.
|
66
|
+
|
67
|
+
{
|
68
|
+
"Version": "2012-10-17",
|
69
|
+
"Statement": [
|
70
|
+
{
|
71
|
+
"Effect": "Allow",
|
72
|
+
"Action": "s3:GetObject",
|
73
|
+
"Resource": "arn:aws:s3:::BUCKET/*"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"Effect": "Allow",
|
77
|
+
"Action": ["s3:GetBucketLocation", "s3:ListBucket"],
|
78
|
+
"Resource": "arn:aws:s3:::BUCKET"
|
79
|
+
}
|
80
|
+
]
|
81
|
+
}
|
82
|
+
|
83
|
+
## Development
|
84
|
+
|
85
|
+
### Requirements
|
86
|
+
|
87
|
+
- [Ruby](https://www.ruby-lang.org/en/downloads/) (3.2.x)
|
88
|
+
|
89
|
+
A specific version of ruby can be installed on macOS via rbenv:
|
90
|
+
|
91
|
+
brew install rbenv
|
92
|
+
|
93
|
+
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
|
94
|
+
|
95
|
+
rbenv install 3.2.2
|
96
|
+
|
97
|
+
cd /path/to/vagrant-box-s3
|
98
|
+
|
99
|
+
rbenv local 3.2.2
|
100
|
+
|
101
|
+
ruby -v
|
102
|
+
|
103
|
+
If bundled packages / dependencies have changed, run bundle install:
|
104
|
+
|
105
|
+
bundle install --path vendor/bundle
|
106
|
+
|
107
|
+
To build the plugin, use `rake build`, this will create a file with the current version number, e.g. `pkg/vagrant-box-s3-0.1.2.gem`.
|
108
|
+
|
109
|
+
Update the current version in `lib/vagrant-box-s3/version.rb`.
|
110
|
+
|
111
|
+
Testing the plugin requires installing into vagrant from the build:
|
112
|
+
|
113
|
+
vagrant plugin install ../vagrant-box-s3/pkg/vagrant-box-s3-0.1.2.gem
|
114
|
+
|
115
|
+
Then running a command that will trigger box URL related actions, such as `vagrant up`, `vagrant box update` etc. with the `--debug` flag.
|
116
|
+
|
117
|
+
## Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrant-box-s3.
|
120
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'vagrant-box-s3/utils'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Util
|
5
|
+
class Downloader
|
6
|
+
|
7
|
+
def aws_auth_download(options, subprocess_options, &data_proc)
|
8
|
+
# Get URL from options, which is the last option in the list.
|
9
|
+
url = options.last
|
10
|
+
|
11
|
+
# Determine method from curl command -I flag existence.
|
12
|
+
method = options.any? { |o| o == '-I' } ? :head_object : :get_object
|
13
|
+
|
14
|
+
# Generate pre-signed URL from S3 URL.
|
15
|
+
presigned_url = VagrantPlugins::BoxS3::Utils.presign_url(method, url, @logger)
|
16
|
+
|
17
|
+
# Update URL in options.
|
18
|
+
url.replace(presigned_url.to_s)
|
19
|
+
|
20
|
+
# Call original execute_curl (aliased).
|
21
|
+
execute_curl_without_aws_auth(options, subprocess_options, &data_proc)
|
22
|
+
|
23
|
+
rescue Aws::S3::Errors::Forbidden => e
|
24
|
+
message = "403 Forbidden: #{e.message}"
|
25
|
+
raise Errors::DownloaderError, message: message
|
26
|
+
rescue Seahorse::Client::NetworkingError => e
|
27
|
+
raise Errors::DownloaderError, message: e
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute_curl_with_aws_auth(options, subprocess_options, &data_proc)
|
31
|
+
options = options.dup
|
32
|
+
url = options.find { |o| o =~ /^http/ }
|
33
|
+
|
34
|
+
if url && url.include?('amazonaws.com')
|
35
|
+
aws_auth_download(options, subprocess_options, &data_proc)
|
36
|
+
else
|
37
|
+
execute_curl_without_aws_auth(options, subprocess_options, &data_proc)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
alias execute_curl_without_aws_auth execute_curl
|
42
|
+
alias execute_curl execute_curl_with_aws_auth
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'aws-sdk-s3'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module BoxS3
|
6
|
+
class Utils
|
7
|
+
|
8
|
+
# Match host style URLs, e.g.
|
9
|
+
# https://bucket-name.s3.Region.amazonaws.com/key-name
|
10
|
+
S3_URL_HOST_REGEX = %r{^https?://([\w\-\.]+)\.s3\.([\w\-]+)\.amazonaws\.com/([^?]+)}
|
11
|
+
|
12
|
+
# Match path style URLs e.g.
|
13
|
+
# https://s3.Region.amazonaws.com/bucket-name/key-name
|
14
|
+
# https://s3-Region.amazonaws.com/bucket-name/keyname
|
15
|
+
S3_URL_PATH_REGEX = %r{^https?://s3[-\.]([\w\-]+)\.amazonaws\.com/([^/]+)/([^?]+)}
|
16
|
+
|
17
|
+
# Parse an s3 URL.
|
18
|
+
def self.parse_s3_url(s3_url)
|
19
|
+
region = bucket = key = nil
|
20
|
+
if s3_url =~ S3_URL_HOST_REGEX
|
21
|
+
match = S3_URL_HOST_REGEX.match(s3_url)
|
22
|
+
region = match[2]
|
23
|
+
bucket = match[1]
|
24
|
+
key = match[3]
|
25
|
+
elsif s3_url =~ S3_URL_PATH_REGEX
|
26
|
+
match = S3_URL_PATH_REGEX.match(s3_url)
|
27
|
+
region = match[1]
|
28
|
+
bucket = match[2]
|
29
|
+
key = match[3]
|
30
|
+
end
|
31
|
+
|
32
|
+
return region, bucket, key
|
33
|
+
end
|
34
|
+
|
35
|
+
# Pre-sign an s3 URL, with given method.
|
36
|
+
def self.presign_url(method, url, logger)
|
37
|
+
logger.info("BoxS3: Generating signed URL for #{method.upcase}")
|
38
|
+
logger.info("BoxS3: Discovered S3 URL: #{url}")
|
39
|
+
|
40
|
+
region, bucket, key = parse_s3_url(url)
|
41
|
+
|
42
|
+
logger.debug("BoxS3: Region: #{region}")
|
43
|
+
logger.debug("BoxS3: Bucket: #{bucket}")
|
44
|
+
logger.debug("BoxS3: Key: #{key}")
|
45
|
+
|
46
|
+
client = Aws::S3::Client.new(
|
47
|
+
profile: ENV['AWS_PROFILE'],
|
48
|
+
region: region
|
49
|
+
)
|
50
|
+
presigner = Aws::S3::Presigner.new(client: client)
|
51
|
+
|
52
|
+
presigned_url = presigner.presigned_url(
|
53
|
+
method,
|
54
|
+
bucket: bucket,
|
55
|
+
key: key,
|
56
|
+
expires_in: 3600
|
57
|
+
).to_s
|
58
|
+
|
59
|
+
logger.debug("BoxS3: Pre-signed URL: #{presigned_url}")
|
60
|
+
|
61
|
+
return presigned_url
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-box-s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Whiteley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-02-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-s3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.143.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.143.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Private, versioned Vagrant boxes hosted on Amazon S3.
|
56
|
+
email:
|
57
|
+
- steve@memiah.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- lib/vagrant-box-s3.rb
|
65
|
+
- lib/vagrant-box-s3/downloader.rb
|
66
|
+
- lib/vagrant-box-s3/utils.rb
|
67
|
+
- lib/vagrant-box-s3/version.rb
|
68
|
+
homepage: https://github.com/memiah/vagrant-box-s3
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.0.3.1
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Amazon AWS S3 Auth.
|
91
|
+
test_files: []
|