s3-secure 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +201 -22
- data/README.md +41 -17
- data/lib/s3_secure.rb +3 -2
- data/lib/s3_secure/access_logs.rb +30 -0
- data/lib/s3_secure/access_logs/base.rb +4 -0
- data/lib/s3_secure/access_logs/disable.rb +37 -0
- data/lib/s3_secure/access_logs/enable.rb +41 -0
- data/lib/s3_secure/access_logs/list.rb +25 -0
- data/lib/s3_secure/access_logs/show.rb +89 -0
- data/lib/s3_secure/aws_services.rb +1 -33
- data/lib/s3_secure/aws_services/s3.rb +54 -0
- data/lib/s3_secure/cli.rb +19 -1
- data/lib/s3_secure/command.rb +7 -0
- data/lib/s3_secure/encryption.rb +2 -0
- data/lib/s3_secure/encryption/disable.rb +4 -8
- data/lib/s3_secure/encryption/enable.rb +4 -8
- data/lib/s3_secure/encryption/list.rb +12 -16
- data/lib/s3_secure/encryption/show.rb +11 -6
- data/lib/s3_secure/help/batch.md +14 -0
- data/lib/s3_secure/help/encryption/list.md +5 -0
- data/lib/s3_secure/help/lifecycle/add.md +13 -0
- data/lib/s3_secure/help/lifecycle/list.md +22 -0
- data/lib/s3_secure/help/lifecycle/remove.md +5 -0
- data/lib/s3_secure/help/lifecycle/show.md +13 -0
- data/lib/s3_secure/help/policy/list.md +5 -0
- data/lib/s3_secure/lifecycle.rb +31 -0
- data/lib/s3_secure/lifecycle/add.rb +33 -0
- data/lib/s3_secure/lifecycle/base.rb +5 -0
- data/lib/s3_secure/lifecycle/builder.rb +47 -0
- data/lib/s3_secure/lifecycle/list.rb +24 -0
- data/lib/s3_secure/lifecycle/remove.rb +28 -0
- data/lib/s3_secure/lifecycle/show.rb +40 -0
- data/lib/s3_secure/policy.rb +2 -0
- data/lib/s3_secure/policy/enforce.rb +3 -6
- data/lib/s3_secure/policy/list.rb +13 -17
- data/lib/s3_secure/policy/show.rb +8 -6
- data/lib/s3_secure/policy/unforce.rb +4 -7
- data/lib/s3_secure/remediate_all.rb +11 -0
- data/lib/s3_secure/summary/items.rb +0 -2
- data/lib/s3_secure/version.rb +1 -1
- data/lib/s3_secure/versioning.rb +29 -0
- data/lib/s3_secure/versioning/base.rb +4 -0
- data/lib/s3_secure/versioning/disable.rb +19 -0
- data/lib/s3_secure/versioning/enable.rb +19 -0
- data/lib/s3_secure/versioning/list.rb +24 -0
- data/lib/s3_secure/versioning/show.rb +27 -0
- data/s3-secure.gemspec +4 -2
- data/spec/lib/lifecycle/builder_spec.rb +85 -0
- metadata +48 -4
@@ -0,0 +1,19 @@
|
|
1
|
+
class S3Secure::Versioning
|
2
|
+
class Disable < Base
|
3
|
+
def run
|
4
|
+
show = Show.new(@options)
|
5
|
+
if show.enabled?
|
6
|
+
s3.put_bucket_versioning(
|
7
|
+
bucket: @bucket,
|
8
|
+
versioning_configuration: {
|
9
|
+
# mfa_delete: "Disabled",
|
10
|
+
status: "Suspended",
|
11
|
+
},
|
12
|
+
)
|
13
|
+
puts "Versioning Suspended on bucket #{@bucket}"
|
14
|
+
else
|
15
|
+
puts "Bucket #{@bucket} is already has versioning already Suspended or not Enabled."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class S3Secure::Versioning
|
2
|
+
class Enable < Base
|
3
|
+
def run
|
4
|
+
show = Show.new(@options)
|
5
|
+
if show.enabled?
|
6
|
+
puts "Bucket #{@bucket} is has versioning already enabled."
|
7
|
+
else
|
8
|
+
s3.put_bucket_versioning(
|
9
|
+
bucket: @bucket,
|
10
|
+
versioning_configuration: {
|
11
|
+
# mfa_delete: "Disabled",
|
12
|
+
status: "Enabled",
|
13
|
+
},
|
14
|
+
)
|
15
|
+
puts "Versioning enabled on bucket #{@bucket}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class S3Secure::Versioning
|
2
|
+
class List < Base
|
3
|
+
def run
|
4
|
+
presenter = CliFormat::Presenter.new(@options)
|
5
|
+
presenter.header = ["Bucket", "Has Versioning?"]
|
6
|
+
|
7
|
+
buckets.each do |bucket|
|
8
|
+
$stderr.puts "Getting versioning for bucket #{bucket.color(:green)}"
|
9
|
+
|
10
|
+
show = Show.new(bucket: bucket)
|
11
|
+
row = [bucket, show.enabled?]
|
12
|
+
if @options[:versioning].nil?
|
13
|
+
presenter.rows << row # always show policy
|
14
|
+
elsif @options[:versioning]
|
15
|
+
presenter.rows << row if show.enabled? # only show if bucket has some encryption rules
|
16
|
+
else
|
17
|
+
presenter.rows << row unless show.enabled? # only show if bucket doesnt have any encryption rules
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
presenter.show
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class S3Secure::Versioning
|
2
|
+
class Show < Base
|
3
|
+
def run
|
4
|
+
if enabled?
|
5
|
+
puts "This S3 bucket has versioning enabled"
|
6
|
+
else
|
7
|
+
puts "This S3 bucket does not have versioning enabled"
|
8
|
+
end
|
9
|
+
details = get_versioning(@bucket).to_h
|
10
|
+
unless details.empty?
|
11
|
+
puts "Bucket versioning details: "
|
12
|
+
pp details
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def enabled?
|
17
|
+
versioning = get_versioning(@bucket)
|
18
|
+
versioning.status == "Enabled" # Can be Enabled, Suspended, or nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_versioning(bucket)
|
22
|
+
s3.get_bucket_versioning(bucket: bucket) # resp
|
23
|
+
rescue Aws::S3::Errors::ServerSideEncryptionConfigurationNotFoundError
|
24
|
+
end
|
25
|
+
memoize :get_versioning
|
26
|
+
end
|
27
|
+
end
|
data/s3-secure.gemspec
CHANGED
@@ -10,9 +10,10 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["tongueroo@gmail.com"]
|
11
11
|
spec.summary = "S3 Bucket security hardening tool"
|
12
12
|
spec.homepage = "https://github.com/tongueroo/s3-secure"
|
13
|
-
spec.license = "
|
13
|
+
spec.license = "Apache2.0"
|
14
14
|
|
15
|
-
|
15
|
+
git_installed = system("type git > /dev/null 2>&1")
|
16
|
+
spec.files = git_installed ? `git ls-files`.split($/) : Dir.glob("**/*")
|
16
17
|
spec.bindir = "exe"
|
17
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
@@ -20,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
20
21
|
|
21
22
|
spec.add_dependency "activesupport"
|
22
23
|
spec.add_dependency "aws-sdk-s3"
|
24
|
+
spec.add_dependency "cli-format"
|
23
25
|
spec.add_dependency "memoist"
|
24
26
|
spec.add_dependency "rainbow"
|
25
27
|
spec.add_dependency "text-table"
|
@@ -0,0 +1,85 @@
|
|
1
|
+
describe S3Secure::Lifecycle::Builder do
|
2
|
+
subject { S3Secure::Lifecycle::Builder.new(rules) }
|
3
|
+
|
4
|
+
describe "already has s3-secure-automated-cleanup rule" do
|
5
|
+
let(:rules) {
|
6
|
+
[{:expiration=>{:expired_object_delete_marker=>true},
|
7
|
+
:id=>"s3-secure-automated-cleanup",
|
8
|
+
:status=>"Enabled",
|
9
|
+
:noncurrent_version_expiration=>{:noncurrent_days=>365},
|
10
|
+
:abort_incomplete_multipart_upload=>{:days_after_initiation=>30}}]
|
11
|
+
}
|
12
|
+
|
13
|
+
it "has?" do
|
14
|
+
result = subject.has?("s3-secure-automated-cleanup")
|
15
|
+
expect(result).to be true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "rules_with_addition" do
|
19
|
+
rules = subject.rules_with_addition
|
20
|
+
expect(rules.size).to eq 1 # no dups
|
21
|
+
result = has_lifecycle?(rules)
|
22
|
+
expect(result).to be true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "rules_with_removal" do
|
26
|
+
rules = subject.rules_with_removal
|
27
|
+
result = has_lifecycle?(rules)
|
28
|
+
expect(result).to be false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "doesnt have s3-secure-automated-cleanup rule" do
|
33
|
+
let(:rules) {
|
34
|
+
[{:rules=>
|
35
|
+
[{:expiration=>{:expired_object_delete_marker=>true},
|
36
|
+
:id=>"someother-policy",
|
37
|
+
:status=>"Enabled",
|
38
|
+
:noncurrent_version_expiration=>{:noncurrent_days=>365},
|
39
|
+
:abort_incomplete_multipart_upload=>{:days_after_initiation=>30}}]}]
|
40
|
+
}
|
41
|
+
|
42
|
+
it "has?" do
|
43
|
+
result = subject.has?("s3-secure-automated-cleanup")
|
44
|
+
expect(result).to be false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "rules_with_addition" do
|
48
|
+
rules = subject.rules_with_addition
|
49
|
+
expect(rules.size).to eq 2 # no dups
|
50
|
+
result = has_lifecycle?(rules)
|
51
|
+
expect(result).to be true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "rules_with_removal" do
|
55
|
+
rules = subject.rules_with_removal
|
56
|
+
result = has_lifecycle?(rules)
|
57
|
+
expect(result).to be false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "empty policy" do
|
62
|
+
let(:rules) { nil }
|
63
|
+
|
64
|
+
it "has?" do
|
65
|
+
result = subject.has?("s3-secure-automated-cleanup")
|
66
|
+
expect(result).to be false
|
67
|
+
end
|
68
|
+
|
69
|
+
it "rules_with_addition" do
|
70
|
+
rules = subject.rules_with_addition
|
71
|
+
result = has_lifecycle?(rules)
|
72
|
+
expect(result).to be true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "rules_with_removal" do
|
76
|
+
rules = subject.rules_with_removal
|
77
|
+
result = has_lifecycle?(rules)
|
78
|
+
expect(result).to be false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def has_lifecycle?(rules)
|
83
|
+
!!rules.detect { |rule| rule[:id] == S3Secure::Lifecycle::Builder::RULE_ID }
|
84
|
+
end
|
85
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3-secure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cli-format
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: memoist
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,8 +212,15 @@ files:
|
|
198
212
|
- lib/s3-secure.rb
|
199
213
|
- lib/s3_secure.rb
|
200
214
|
- lib/s3_secure/abstract_base.rb
|
215
|
+
- lib/s3_secure/access_logs.rb
|
216
|
+
- lib/s3_secure/access_logs/base.rb
|
217
|
+
- lib/s3_secure/access_logs/disable.rb
|
218
|
+
- lib/s3_secure/access_logs/enable.rb
|
219
|
+
- lib/s3_secure/access_logs/list.rb
|
220
|
+
- lib/s3_secure/access_logs/show.rb
|
201
221
|
- lib/s3_secure/autoloader.rb
|
202
222
|
- lib/s3_secure/aws_services.rb
|
223
|
+
- lib/s3_secure/aws_services/s3.rb
|
203
224
|
- lib/s3_secure/batch.rb
|
204
225
|
- lib/s3_secure/cli.rb
|
205
226
|
- lib/s3_secure/command.rb
|
@@ -213,13 +234,27 @@ files:
|
|
213
234
|
- lib/s3_secure/encryption/list.rb
|
214
235
|
- lib/s3_secure/encryption/show.rb
|
215
236
|
- lib/s3_secure/help.rb
|
237
|
+
- lib/s3_secure/help/batch.md
|
216
238
|
- lib/s3_secure/help/completion.md
|
217
239
|
- lib/s3_secure/help/completion_script.md
|
218
240
|
- lib/s3_secure/help/encryption/disable.md
|
219
241
|
- lib/s3_secure/help/encryption/enable.md
|
242
|
+
- lib/s3_secure/help/encryption/list.md
|
243
|
+
- lib/s3_secure/help/lifecycle/add.md
|
244
|
+
- lib/s3_secure/help/lifecycle/list.md
|
245
|
+
- lib/s3_secure/help/lifecycle/remove.md
|
246
|
+
- lib/s3_secure/help/lifecycle/show.md
|
220
247
|
- lib/s3_secure/help/policy/enforce_ssl.md
|
248
|
+
- lib/s3_secure/help/policy/list.md
|
221
249
|
- lib/s3_secure/help/policy/unforce_ssl.md
|
222
250
|
- lib/s3_secure/help/summary.md
|
251
|
+
- lib/s3_secure/lifecycle.rb
|
252
|
+
- lib/s3_secure/lifecycle/add.rb
|
253
|
+
- lib/s3_secure/lifecycle/base.rb
|
254
|
+
- lib/s3_secure/lifecycle/builder.rb
|
255
|
+
- lib/s3_secure/lifecycle/list.rb
|
256
|
+
- lib/s3_secure/lifecycle/remove.rb
|
257
|
+
- lib/s3_secure/lifecycle/show.rb
|
223
258
|
- lib/s3_secure/policy.rb
|
224
259
|
- lib/s3_secure/policy/base.rb
|
225
260
|
- lib/s3_secure/policy/checker.rb
|
@@ -231,20 +266,28 @@ files:
|
|
231
266
|
- lib/s3_secure/policy/list.rb
|
232
267
|
- lib/s3_secure/policy/show.rb
|
233
268
|
- lib/s3_secure/policy/unforce.rb
|
269
|
+
- lib/s3_secure/remediate_all.rb
|
234
270
|
- lib/s3_secure/summary.rb
|
235
271
|
- lib/s3_secure/summary/item.rb
|
236
272
|
- lib/s3_secure/summary/items.rb
|
237
273
|
- lib/s3_secure/table.rb
|
238
274
|
- lib/s3_secure/version.rb
|
275
|
+
- lib/s3_secure/versioning.rb
|
276
|
+
- lib/s3_secure/versioning/base.rb
|
277
|
+
- lib/s3_secure/versioning/disable.rb
|
278
|
+
- lib/s3_secure/versioning/enable.rb
|
279
|
+
- lib/s3_secure/versioning/list.rb
|
280
|
+
- lib/s3_secure/versioning/show.rb
|
239
281
|
- s3-secure.gemspec
|
240
282
|
- spec/lib/cli_spec.rb
|
283
|
+
- spec/lib/lifecycle/builder_spec.rb
|
241
284
|
- spec/lib/policy/checker_spec.rb
|
242
285
|
- spec/lib/policy/document/force_ssl_remove_spec.rb
|
243
286
|
- spec/lib/policy/document_spec.rb
|
244
287
|
- spec/spec_helper.rb
|
245
288
|
homepage: https://github.com/tongueroo/s3-secure
|
246
289
|
licenses:
|
247
|
-
-
|
290
|
+
- Apache2.0
|
248
291
|
metadata: {}
|
249
292
|
post_install_message:
|
250
293
|
rdoc_options: []
|
@@ -261,12 +304,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
304
|
- !ruby/object:Gem::Version
|
262
305
|
version: '0'
|
263
306
|
requirements: []
|
264
|
-
rubygems_version: 3.
|
307
|
+
rubygems_version: 3.1.2
|
265
308
|
signing_key:
|
266
309
|
specification_version: 4
|
267
310
|
summary: S3 Bucket security hardening tool
|
268
311
|
test_files:
|
269
312
|
- spec/lib/cli_spec.rb
|
313
|
+
- spec/lib/lifecycle/builder_spec.rb
|
270
314
|
- spec/lib/policy/checker_spec.rb
|
271
315
|
- spec/lib/policy/document/force_ssl_remove_spec.rb
|
272
316
|
- spec/lib/policy/document_spec.rb
|