muchsecrets 0.0.2 → 0.0.3

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: 639350be4d0bce627d623560089b2cc2997657be
4
- data.tar.gz: 523849a5697680c7edf53de4978e52d6bde445de
3
+ metadata.gz: 46a037577a9dd00f6d594cee1d3a7b12f53fd510
4
+ data.tar.gz: fe3f8ca23d1b1dbc6bfaf51ca70c467b5e878a6e
5
5
  SHA512:
6
- metadata.gz: f3a45736a0d5a015e5abc406dae0808f1e0805777509e3c4ec26cbb3ce78778a3626487711c5050c9a11f85dc11eb0661acc0f980bd5dc11881ac922c822d950
7
- data.tar.gz: 55e41eab84259fa263f20a22fc1b8010b8c7a7f78ac5eff811869b39ef0159f20f5aa4e051339c91dfb600e2e23928d7858bf70dc3aefa7248c2f4afb8b2fcf8
6
+ metadata.gz: db9a765ec0505bdf95642762527bc4e7bfcc010106d661e0fd822510eefda6342f40320cd40d894c40fc14d630fbefa925735d7551153b2cb0b13ce83f057e48
7
+ data.tar.gz: 6e4f82f2c02c1567a7fa7897989ae46caf6384131324c4429712346c42f370b818f25be1985688829e65cc637b9fd799bae82cd68feb55550ede64b78cdee649
data/README.md CHANGED
@@ -11,10 +11,46 @@ What's this useful for? Pulling encrypted secrets from [Consul](https://consul.i
11
11
  :$ openssl req -new -newkey rsa:4096 -nodes -x509 -keyout application.pem -out application.pem
12
12
  ````
13
13
 
14
- 2. store your private key some place safe
14
+ 2. store your keypair some place safe.
15
+
15
16
 
16
17
  ## Usage ##
17
18
 
19
+ Use the command line executable to encrypt:
20
+ ```
21
+ :$ muchsecrets --encrypt --publickey shared-production-wc1.pem --string "such_privacy"
22
+
23
+ -----BEGIN PKCS7-----
24
+ MIIDMwYJKoZIhvcNAQcDoIIDJDCCAyACAQAxggLgMIIC3AIBADCBwzCBtTELMAkG
25
+ A1UEBhMCVVMxDzANBgNVBAgTBk9yZWdvbjERMA8GA1UEBxMIUG9yd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+ -----END PKCS7-----
43
+ ```
44
+
45
+ Use the command line to decrypt directly from consul:
46
+ ```
47
+ :$ muchsecrets --decrypt --publickey application.pem --privatekey application.pem --consul secrets/wow
48
+
49
+ foo bar baz
50
+ ```
51
+
52
+ Or you can use it directly from your application.
53
+
18
54
  To encrypt a string:
19
55
  ```ruby
20
56
  require 'muchsecrets'
@@ -41,13 +77,21 @@ ZQMEASwEEMVOg3shVq9U1O7CzSDJfSyADex+cL6h7RnV1tRwDqI=
41
77
  -----END PKCS7-----"
42
78
  ```
43
79
 
44
- Push the encrypted string to consul.
80
+ Push the encrypted string to consul/whatever.
45
81
 
46
- To decrypt a raw key value from consul:
82
+ To decrypt a key value directly from consul:
47
83
  ```ruby
48
84
  require 'muchsecrets'
49
85
  wow = MuchSecrets::Secret.new(:public_key => 'application.pem', :private_key => 'application.pem')
50
- super_secret = wow.get_http_secret('notprod/github_api_key/encrypted?raw')
86
+ super_secret = wow.get_consul_secret('notprod/github_api_key/encrypted') # would fetch http://consul:8500/v1/kv/notprod/github_api_key/encrypted?raw
87
+ # => "such_privacy"
88
+ ```
89
+
90
+ To decrypt a key value directly from a web endpoint:
91
+ ```ruby
92
+ require 'muchsecrets'
93
+ wow = MuchSecrets::Secret.new(:public_key => 'application.pem', :private_key => 'application.pem', :base_url => 'http://service:8080')
94
+ super_secret = wow.get_http_secret('notprod/github_api_key/encrypted') # would fetch http://service:8080/notprod/github_api_key/encrypted
51
95
  # => "such_privacy"
52
96
  ```
53
97
 
data/bin/muchsecrets ADDED
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'muchsecrets'
4
+
5
+ options = {}
6
+
7
+ # Extra options to OptionParser reduce the amount of whitespace it introduces
8
+ # into the help message, making it easier to make the help message fit in a
9
+ # 80x24 window.
10
+ opts = OptionParser.new(nil, 24, ' ')
11
+
12
+ opts.banner = 'Usage: muchsecrets [options] [--file /path/to/file | --consul path/to/consul/key | --string "really private string"]'
13
+
14
+ # actions
15
+ opts.on('--encrypt', 'Encrypt it.') do |opt|
16
+ options[:encrypt] = opt
17
+ end
18
+ opts.on('--decrypt', 'Decrypt it.') do |opt|
19
+ options[:decrypt] = opt
20
+ end
21
+
22
+ # options
23
+ opts.on('--consulserver HOST', 'Consul server http address.') do |opt|
24
+ options[:consulserver] = opt
25
+ end
26
+ opts.on('--privatekey PRIVKEY', 'Location of your private key.') do |opt|
27
+ options[:privatekey] = opt
28
+ end
29
+ opts.on('--publickey PUBKEY', 'Location of your public key.') do |opt|
30
+ options[:publickey] = opt
31
+ end
32
+
33
+ # what to act on
34
+ opts.on('--file FILE', 'File to encrypt.') do |opt|
35
+ options[:file] = opt
36
+ end
37
+ opts.on('--consul KEY', 'Consul key to decrypt.') do |opt|
38
+ options[:consul] = opt
39
+ end
40
+ opts.on('--string "STRING"', 'Quoted string to encrypt.') do |opt|
41
+ options[:string] = opt
42
+ end
43
+
44
+ opts.on_tail('-h', '--help', 'Show this message.') do
45
+ puts opts
46
+ exit
47
+ end
48
+
49
+ opts.parse!
50
+
51
+ # Display a usage message if the user did not specify a valid action to perform.
52
+ if options.empty?
53
+ puts opts
54
+ exit
55
+ end
56
+
57
+ # I refuse to encrypt and decrypt at the same time.
58
+ if options[:encrypt] && options[:decrypt]
59
+ puts "you cannot pass the --encrypt flag at the same time as the --decrypt flag."
60
+ exit
61
+ # likewise, I refuse to do nothing.
62
+ elsif !options[:encrypt] && !options[:decrypt]
63
+ puts "you need to pass either --encrypt or --decrypt."
64
+ exit
65
+ end
66
+
67
+ # if we get here I guess we can do something.
68
+ if options[:encrypt]
69
+ # need the public key for encrypting.
70
+ abort "--encrypt needs the --publickey option passed." if !options[:publickey]
71
+
72
+ string_to_encrypt = ""
73
+
74
+ if options[:file]
75
+ string_to_encrypt = File.read(options[:file])
76
+ elsif options[:string]
77
+ string_to_encrypt = options[:string].to_s
78
+ end
79
+
80
+ # encrypt and print string
81
+ wow = MuchSecrets::Secret.new(:public_key => options[:publickey])
82
+ puts wow.encrypt_string(string_to_encrypt)
83
+
84
+ elsif options[:decrypt]
85
+ # need the public and private keys for decrypting.
86
+ abort "--decrypt needs the --publickey option passed." if !options[:publickey]
87
+ abort "--decrypt needs the --privatekey options passed." if !options[:privatekey]
88
+
89
+ wow = MuchSecrets::Secret.new(:public_key => options[:publickey], :private_key => options[:privatekey])
90
+ puts wow.get_consul_secret(options[:consul])
91
+
92
+ end
93
+
94
+
data/lib/muchsecrets.rb CHANGED
@@ -1,3 +1,2 @@
1
- #require "goldstar/notifications/version"
2
1
  require "muchsecrets/secret"
3
2
 
@@ -15,6 +15,11 @@ module MuchSecrets
15
15
  return decrypt_string(encrypted_secret)
16
16
  end
17
17
 
18
+ def get_consul_secret(uri)
19
+ uri = uri + '?raw'
20
+ return get_http_secret(uri)
21
+ end
22
+
18
23
  def encrypt_string(val)
19
24
  cert = OpenSSL::X509::Certificate.new(File.read(@public_key))
20
25
  return OpenSSL::PKCS7::encrypt([cert], val, @cipher, OpenSSL::PKCS7::BINARY)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muchsecrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat O'Brien
@@ -13,12 +13,14 @@ dependencies: []
13
13
  description: handles encrypting and decrypting secrets to/from consul.
14
14
  email:
15
15
  - muchsecrets@tetrisbocks.net
16
- executables: []
16
+ executables:
17
+ - muchsecrets
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
20
21
  - lib/muchsecrets/secret.rb
21
22
  - lib/muchsecrets.rb
23
+ - bin/muchsecrets
22
24
  - LICENSE
23
25
  - README.md
24
26
  homepage: http://github.com/poblahblahblah/muchsecrets