activestorage-horcrux 0.0.2 → 0.0.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +41 -11
- data/lib/active_storage/service/horcrux_service.rb +32 -10
- data/lib/active_storage/service/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8709676589bd8ed4406d3e0c9ffc2e7beede65830f37c707a2b6c1061bb3f8e3
|
4
|
+
data.tar.gz: 94c9b7508e4c5648bc9a9d2761ea0447c6537d6122aca3aeaeadecb425fd608b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b0831c200ec394f04288cd8d245130de0227d67f7870b6b92ed5f3bbab2c33844cc38c4bb40acdc7a073056b3b4a109009d11f946d845b2c68fe5d89b93aa4
|
7
|
+
data.tar.gz: 1c2569bee9f9f2dac190df90b5777e9a11b831c70ed4ed2a419e4f5d34de384d409e8eb09dafc64e6445672507b4f3fd1a71906b61f2a3f31622388968e5910e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
[](https://travis-ci.org/johncallahan/activestorage-horcrux)
|
2
2
|
|
3
|
-
An ActiveStorage
|
4
|
-
|
5
|
-
gem](https://github.com/grempe/tss-rb)). Use it in your
|
6
|
-
file. It is not a mirror, but can be named as a storage
|
3
|
+
An ActiveStorage service option that uploads shares *across* one or
|
4
|
+
more other storage services using Shamir Secret Sharing (via the
|
5
|
+
[tss-rb gem](https://github.com/grempe/tss-rb)). Use it in your
|
6
|
+
storage.yml file. It is not a mirror, but can be named as a storage
|
7
|
+
service.
|
7
8
|
|
8
9
|
```ruby
|
9
10
|
# in storage.yml
|
@@ -19,17 +20,46 @@ horcrux:
|
|
19
20
|
service: Horcrux
|
20
21
|
shares: 5
|
21
22
|
threshold: 3
|
23
|
+
prefix: true
|
22
24
|
services: [ disk1, disk2 ]
|
23
25
|
```
|
24
26
|
|
25
|
-
Configuration elements:
|
27
|
+
# Configuration elements:
|
26
28
|
|
27
29
|
* service: name of the service
|
28
|
-
* shares: specified the number of shares split across services.
|
29
|
-
* threshold: specifies the _minimum_ number of shares are needed to
|
30
|
-
|
30
|
+
* shares: (integer) specified the number of shares split across services.
|
31
|
+
* threshold: (integer) specifies the _minimum_ number of shares are needed to reconstruct the contents.
|
32
|
+
* prefix: (boolean) prefix the key with the name of the service
|
31
33
|
* services: one or more other ActiveStorage services in storage.yml
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
After upload, the blob key is replaced with a comma-separated list of
|
36
|
+
keys for each shard. You can retrieve the blob key(s) and then
|
37
|
+
replace it to hide the share keys (but remember to save them
|
38
|
+
someplace!). Later, you can change the key(s) back again and download
|
39
|
+
the attachment shares (using at least threshold number of keys).
|
40
|
+
|
41
|
+
# Demo
|
42
|
+
|
43
|
+
Compatible with the [lockbox gem](https://github.com/ankane/lockbox). See this [demo example](https://github.com/johncallahan/activestorage-horcrux-example).
|
44
|
+
|
45
|
+
# Testing
|
46
|
+
|
47
|
+
```shell
|
48
|
+
% rspec
|
49
|
+
```
|
50
|
+
|
51
|
+
# Development
|
52
|
+
|
53
|
+
Bump the version in lib/active_storage/service/version.rb and then
|
54
|
+
|
55
|
+
```shell
|
56
|
+
% bundle
|
57
|
+
% gem build activestorage-horcrux
|
58
|
+
% gem push activestorage-horcrux-0.0.x.gem
|
59
|
+
```
|
60
|
+
|
61
|
+
# To-do/Issues
|
62
|
+
|
63
|
+
* using Tempfile for passing back keys (yuck)
|
64
|
+
* size limitations (by the tss-rb gem)
|
65
|
+
* intercept and convert TSS errors to gem-specific errors
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'tss'
|
4
4
|
require 'base64'
|
5
|
-
require
|
5
|
+
require 'active_support/core_ext/module/delegation'
|
6
6
|
|
7
7
|
# frozen_string_literal: true
|
8
8
|
|
@@ -15,21 +15,31 @@ module ActiveStorage
|
|
15
15
|
base64Data = Base64.encode64(data)
|
16
16
|
shards = TSS.split(secret: base64Data,threshold: @threshold,num_shares: @shares)
|
17
17
|
i = 0
|
18
|
+
main_key = ""
|
18
19
|
servicesamples = []
|
19
|
-
file = Tempfile.new(key,"/tmp")
|
20
20
|
while i < shards.count
|
21
21
|
if servicesamples.empty?
|
22
22
|
servicesamples = services[0..-1]
|
23
23
|
end
|
24
24
|
svc = servicesamples.sample
|
25
25
|
shardkey = SecureRandom.base58(key.length)
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
|
27
|
+
scblob = Class.new Blob
|
28
|
+
scblob.service = svc[:service]
|
29
|
+
iofile = Tempfile.new(shardkey,"/tmp")
|
30
|
+
iofile.write(shards[i])
|
31
|
+
iofile.rewind
|
32
|
+
myblob = scblob.create_and_upload! io:iofile, filename: ""
|
33
|
+
iofile.close
|
34
|
+
iofile.unlink
|
35
|
+
|
36
|
+
main_key = main_key + "#{myblob.reload.key},"
|
29
37
|
servicesamples.delete(svc)
|
30
38
|
i = i + 1
|
31
39
|
end
|
32
|
-
|
40
|
+
main_blob = Blob.find_by_key(key)
|
41
|
+
main_blob.key = main_key
|
42
|
+
main_blob.save!
|
33
43
|
end
|
34
44
|
|
35
45
|
def download(keys,&block)
|
@@ -39,11 +49,23 @@ module ActiveStorage
|
|
39
49
|
while i < shardkeys.count
|
40
50
|
j = 0
|
41
51
|
while j < services.count
|
42
|
-
|
43
|
-
|
52
|
+
begin
|
53
|
+
if services[j][:service].exist?(shardkeys[i])
|
54
|
+
shard = services[j][:service].download(shardkeys[i])
|
55
|
+
shards << shard
|
56
|
+
break
|
57
|
+
end
|
58
|
+
j = j + 1
|
59
|
+
rescue NotImplementedError
|
60
|
+
begin
|
61
|
+
shard = services[j][:service].download(shardkeys[i]).to_s
|
62
|
+
shards << shard
|
63
|
+
break
|
64
|
+
rescue RestClient::BadRequest
|
65
|
+
j = j + 1
|
66
|
+
end
|
44
67
|
end
|
45
|
-
|
46
|
-
end
|
68
|
+
end
|
47
69
|
i = i + 1
|
48
70
|
end
|
49
71
|
secret = TSS.combine(shares: shards)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-horcrux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Callahan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|