chef-vault 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +97 -0
  4. data/Changelog.md +34 -0
  5. data/DEMO.md +13 -6
  6. data/README.md +9 -4
  7. data/Rakefile +47 -10
  8. data/THEORY.md +361 -0
  9. data/bin/chef-vault +5 -5
  10. data/chef-vault.gemspec +11 -2
  11. data/features/clean_unknown_clients.feature +28 -3
  12. data/features/step_definitions/chef-databag.rb +5 -0
  13. data/features/step_definitions/chef-repo.rb +46 -8
  14. data/features/step_definitions/chef-vault.rb +69 -15
  15. data/features/support/env.rb +2 -2
  16. data/features/vault_create.feature +54 -0
  17. data/features/vault_list.feature +26 -0
  18. data/features/vault_show.feature +46 -0
  19. data/features/vault_update.feature +17 -0
  20. data/features/wrong_private_key.feature +14 -0
  21. data/lib/chef-vault.rb +0 -1
  22. data/lib/chef-vault/certificate.rb +1 -1
  23. data/lib/chef-vault/chef_patch/api_client.rb +1 -1
  24. data/lib/chef-vault/chef_patch/user.rb +1 -1
  25. data/lib/chef-vault/exceptions.rb +33 -12
  26. data/lib/chef-vault/item.rb +262 -209
  27. data/lib/chef-vault/item_keys.rb +90 -88
  28. data/lib/chef-vault/user.rb +1 -1
  29. data/lib/chef-vault/version.rb +2 -2
  30. data/lib/chef/knife/decrypt.rb +1 -2
  31. data/lib/chef/knife/encrypt_create.rb +1 -2
  32. data/lib/chef/knife/encrypt_delete.rb +1 -2
  33. data/lib/chef/knife/encrypt_remove.rb +1 -2
  34. data/lib/chef/knife/encrypt_rotate_keys.rb +1 -2
  35. data/lib/chef/knife/encrypt_update.rb +1 -2
  36. data/lib/chef/knife/mixin/compat.rb +3 -3
  37. data/lib/chef/knife/mixin/helper.rb +6 -8
  38. data/lib/chef/knife/vault_admins.rb +1 -2
  39. data/lib/chef/knife/vault_base.rb +2 -2
  40. data/lib/chef/knife/vault_create.rb +3 -4
  41. data/lib/chef/knife/vault_decrypt.rb +3 -4
  42. data/lib/chef/knife/vault_delete.rb +2 -4
  43. data/lib/chef/knife/vault_download.rb +1 -2
  44. data/lib/chef/knife/vault_edit.rb +3 -6
  45. data/lib/chef/knife/vault_list.rb +53 -0
  46. data/lib/chef/knife/vault_refresh.rb +1 -2
  47. data/lib/chef/knife/vault_remove.rb +3 -7
  48. data/lib/chef/knife/vault_rotate_all_keys.rb +2 -4
  49. data/lib/chef/knife/vault_rotate_keys.rb +2 -4
  50. data/lib/chef/knife/vault_show.rb +4 -5
  51. data/lib/chef/knife/vault_update.rb +7 -9
  52. data/spec/chef-vault/certificate_spec.rb +0 -2
  53. data/spec/chef-vault/item_spec.rb +77 -1
  54. data/spec/chef-vault/user_spec.rb +0 -2
  55. data/spec/chef-vault_spec.rb +1 -1
  56. data/spec/spec_helper.rb +1 -3
  57. metadata +38 -14
@@ -1,5 +1,5 @@
1
1
  # Author:: Kevin Moser <kevin.moser@nordstrom.com>
2
- # Copyright:: Copyright 2013, Nordstrom, Inc.
2
+ # Copyright:: Copyright 2013-15, Nordstrom, Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
 
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,117 +14,119 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- class ChefVault::ItemKeys < Chef::DataBagItem
18
- def initialize(vault, name)
19
- super() # parenthesis required to strip off parameters
20
- @data_bag = vault
21
- @raw_data["id"] = name
22
- @raw_data["admins"] = []
23
- @raw_data["clients"] = []
24
- @raw_data["search_query"] = []
25
- end
17
+ class ChefVault
18
+ class ItemKeys < Chef::DataBagItem
19
+ def initialize(vault, name)
20
+ super() # parenthesis required to strip off parameters
21
+ @data_bag = vault
22
+ @raw_data["id"] = name
23
+ @raw_data["admins"] = []
24
+ @raw_data["clients"] = []
25
+ @raw_data["search_query"] = []
26
+ end
26
27
 
27
- def include?(key)
28
- @raw_data.keys.include?(key)
29
- end
28
+ def include?(key)
29
+ @raw_data.keys.include?(key)
30
+ end
30
31
 
31
- def add(chef_client, data_bag_shared_secret, type)
32
- public_key = OpenSSL::PKey::RSA.new chef_client.public_key
33
- self[chef_client.name] =
34
- Base64.encode64(public_key.public_encrypt(data_bag_shared_secret))
32
+ def add(chef_client, data_bag_shared_secret, type)
33
+ public_key = OpenSSL::PKey::RSA.new chef_client.public_key
34
+ self[chef_client.name] =
35
+ Base64.encode64(public_key.public_encrypt(data_bag_shared_secret))
35
36
 
36
- @raw_data[type] << chef_client.name unless @raw_data[type].include?(chef_client.name)
37
- @raw_data[type]
38
- end
37
+ @raw_data[type] << chef_client.name unless @raw_data[type].include?(chef_client.name)
38
+ @raw_data[type]
39
+ end
39
40
 
40
- def delete(chef_client, type)
41
- raw_data.delete(chef_client)
42
- raw_data[type].delete(chef_client)
43
- end
41
+ def delete(chef_client, type)
42
+ raw_data.delete(chef_client)
43
+ raw_data[type].delete(chef_client)
44
+ end
44
45
 
45
- def search_query(search_query=nil)
46
- if search_query
47
- @raw_data["search_query"] = search_query
48
- else
49
- @raw_data["search_query"]
46
+ def search_query(search_query=nil)
47
+ if search_query
48
+ @raw_data["search_query"] = search_query
49
+ else
50
+ @raw_data["search_query"]
51
+ end
50
52
  end
51
- end
52
53
 
53
- def clients
54
- @raw_data["clients"]
55
- end
54
+ def clients
55
+ @raw_data["clients"]
56
+ end
56
57
 
57
- def admins
58
- @raw_data["admins"]
59
- end
58
+ def admins
59
+ @raw_data["admins"]
60
+ end
60
61
 
61
- def save(item_id=@raw_data['id'])
62
- if Chef::Config[:solo]
63
- data_bag_path = File.join(Chef::Config[:data_bag_path],
64
- data_bag)
65
- data_bag_item_path = File.join(data_bag_path, item_id)
62
+ def save(item_id=@raw_data['id'])
63
+ if Chef::Config[:solo]
64
+ data_bag_path = File.join(Chef::Config[:data_bag_path],
65
+ data_bag)
66
+ data_bag_item_path = File.join(data_bag_path, item_id)
66
67
 
67
- FileUtils.mkdir(data_bag_path) unless File.exists?(data_bag_path)
68
- File.open("#{data_bag_item_path}.json",'w') do |file|
69
- file.write(JSON.pretty_generate(self.raw_data))
70
- end
68
+ FileUtils.mkdir(data_bag_path) unless File.exist?(data_bag_path)
69
+ File.open("#{data_bag_item_path}.json", 'w') do |file|
70
+ file.write(JSON.pretty_generate(raw_data))
71
+ end
71
72
 
72
- self.raw_data
73
- else
74
- begin
75
- chef_data_bag = Chef::DataBag.load(data_bag)
76
- rescue Net::HTTPServerException => http_error
77
- if http_error.response.code == "404"
78
- chef_data_bag = Chef::DataBag.new
79
- chef_data_bag.name data_bag
80
- chef_data_bag.create
73
+ raw_data
74
+ else
75
+ begin
76
+ Chef::DataBag.load(data_bag)
77
+ rescue Net::HTTPServerException => http_error
78
+ if http_error.response.code == "404"
79
+ chef_data_bag = Chef::DataBag.new
80
+ chef_data_bag.name data_bag
81
+ chef_data_bag.create
82
+ end
81
83
  end
82
- end
83
84
 
84
- super
85
+ super
86
+ end
85
87
  end
86
- end
87
88
 
88
- def destroy
89
- if Chef::Config[:solo]
90
- data_bag_path = File.join(Chef::Config[:data_bag_path],
91
- data_bag)
92
- data_bag_item_path = File.join(data_bag_path, @raw_data["id"])
89
+ def destroy
90
+ if Chef::Config[:solo]
91
+ data_bag_path = File.join(Chef::Config[:data_bag_path],
92
+ data_bag)
93
+ data_bag_item_path = File.join(data_bag_path, @raw_data["id"])
93
94
 
94
- FileUtils.rm("#{data_bag_item_path}.json")
95
+ FileUtils.rm("#{data_bag_item_path}.json")
95
96
 
96
- nil
97
- else
98
- super(data_bag, id)
97
+ nil
98
+ else
99
+ super(data_bag, id)
100
+ end
99
101
  end
100
- end
101
102
 
102
- def to_json(*a)
103
- json = super
104
- json.gsub(self.class.name, self.class.superclass.name)
105
- end
103
+ def to_json(*a)
104
+ json = super
105
+ json.gsub(self.class.name, self.class.superclass.name)
106
+ end
106
107
 
107
- def self.from_data_bag_item(data_bag_item)
108
- item = new(data_bag_item.data_bag, data_bag_item.name)
109
- item.raw_data = data_bag_item.raw_data
110
- item
111
- end
108
+ def self.from_data_bag_item(data_bag_item)
109
+ item = new(data_bag_item.data_bag, data_bag_item.name)
110
+ item.raw_data = data_bag_item.raw_data
111
+ item
112
+ end
112
113
 
113
- def self.load(vault, name)
114
- begin
115
- data_bag_item = Chef::DataBagItem.load(vault, name)
116
- rescue Net::HTTPServerException => http_error
117
- if http_error.response.code == "404"
114
+ def self.load(vault, name)
115
+ begin
116
+ data_bag_item = Chef::DataBagItem.load(vault, name)
117
+ rescue Net::HTTPServerException => http_error
118
+ if http_error.response.code == "404"
119
+ raise ChefVault::Exceptions::KeysNotFound,
120
+ "#{vault}/#{name} could not be found"
121
+ else
122
+ raise http_error
123
+ end
124
+ rescue Chef::Exceptions::ValidationFailed
118
125
  raise ChefVault::Exceptions::KeysNotFound,
119
126
  "#{vault}/#{name} could not be found"
120
- else
121
- raise http_error
122
127
  end
123
- rescue Chef::Exceptions::ValidationFailed
124
- raise ChefVault::Exceptions::KeysNotFound,
125
- "#{vault}/#{name} could not be found"
126
- end
127
128
 
128
- from_data_bag_item(data_bag_item)
129
+ from_data_bag_item(data_bag_item)
130
+ end
129
131
  end
130
132
  end
@@ -1,5 +1,5 @@
1
1
  # Description: ChefVault::User class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  # Description: ChefVault VERSION file
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -14,6 +14,6 @@
14
14
  # limitations under the License.
15
15
 
16
16
  class ChefVault
17
- VERSION = "2.4.0"
17
+ VERSION = "2.5.0"
18
18
  MAJOR, MINOR, TINY = VERSION.split('.')
19
19
  end
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault Decrypt class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_decrypt'
19
19
  class Chef
20
20
  class Knife
21
21
  class Decrypt < VaultDecrypt
22
-
23
22
  include Knife::VaultBase
24
23
 
25
24
  banner "knife decrypt VAULT ITEM [VALUES] (options)"
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault EncryptCreate class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_create'
19
19
  class Chef
20
20
  class Knife
21
21
  class EncryptCreate < VaultCreate
22
-
23
22
  include Knife::VaultBase
24
23
 
25
24
  banner "knife encrypt create VAULT ITEM VALUES (options)"
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault EncryptDelete class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_delete'
19
19
  class Chef
20
20
  class Knife
21
21
  class EncryptDelete < VaultDelete
22
-
23
22
  include Knife::VaultBase
24
23
 
25
24
  banner "knife encrypt delete VAULT ITEM (options)"
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault EncryptRemove class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_remove'
19
19
  class Chef
20
20
  class Knife
21
21
  class EncryptRemove < VaultRemove
22
-
23
22
  include Knife::VaultBase
24
23
 
25
24
  banner "knife encrypt remove VAULT ITEM VALUES (options)"
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault EncryptRotateKeys class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_rotate_keys'
19
19
  class Chef
20
20
  class Knife
21
21
  class EncryptRotateKeys < VaultRotateKeys
22
-
23
22
  include Knife::VaultBase
24
23
 
25
24
  banner "knife encrypt rotate keys VAULT ITEM (options)"
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault EncryptUpdate class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_update'
19
19
  class Chef
20
20
  class Knife
21
21
  class EncryptUpdate < VaultUpdate
22
-
23
22
  include Knife::VaultBase
24
23
 
25
24
  option :search,
@@ -13,17 +13,17 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- # Make a wraper to chef10/11 "shef/shell" changes
16
+ # Make a wraper to chef10/11 "shef/shell" changes
17
17
 
18
18
  class ChefVault
19
19
  module Mixin
20
20
  module KnifeCompat
21
21
  require 'chef/version'
22
22
  def extend_context_object(obj)
23
- if Chef::VERSION.to_i >= 11
23
+ if Chef::VERSION.to_i >= 11
24
24
  require "chef/shell/ext"
25
25
  Shell::Extensions.extend_context_object(obj)
26
- else
26
+ else
27
27
  require 'chef/shef/ext'
28
28
  Shef::Extensions.extend_context_object(obj)
29
29
  end
@@ -28,23 +28,21 @@ class ChefVault
28
28
  values = {}
29
29
  values.merge!(values_from_file(file)) if file
30
30
  values.merge!(values_from_json(json)) if json
31
-
31
+
32
32
  values
33
33
  end
34
34
 
35
35
  def values_from_file(file)
36
- json = File.open(file){ |file| file.read() }
36
+ json = File.open(file){ |fh| fh.read() }
37
37
 
38
38
  values_from_json(json)
39
39
  end
40
40
 
41
41
  def values_from_json(json)
42
- begin
43
- JSON.parse(json)
44
- rescue JSON::ParserError
45
- raise JSON::ParserError, "#{json} is not valid JSON!"
46
- end
42
+ JSON.parse(json)
43
+ rescue JSON::ParserError
44
+ raise JSON::ParserError, "#{json} is not valid JSON!"
47
45
  end
48
46
  end
49
47
  end
50
- end
48
+ end
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault VaultAdmins module
2
- # Copyright 2014, Nordstrom, Inc.
2
+ # Copyright 2014-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef-vault'
19
19
  class Chef
20
20
  class Knife
21
21
  module VaultAdmins
22
-
23
22
  private
24
23
 
25
24
  def admins
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault VaultBase module
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ class Chef
33
33
  :short => '-M MODE',
34
34
  :long => '--mode MODE',
35
35
  :description => 'Chef mode to run in default - solo',
36
- :proc => Proc.new { |i| Chef::Config[:knife][:vault_mode] = i }
36
+ :proc => proc { |i| Chef::Config[:knife][:vault_mode] = i }
37
37
  end
38
38
  end
39
39
 
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault VaultCreate class
2
- # Copyright 2014, Nordstrom, Inc.
2
+ # Copyright 2014-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ require 'chef/knife/vault_admins'
19
19
  class Chef
20
20
  class Knife
21
21
  class VaultCreate < Knife
22
-
23
22
  include Chef::Knife::VaultBase
24
23
  include Chef::Knife::VaultAdmins
25
24
 
@@ -62,7 +61,7 @@ class Chef
62
61
  "use 'knife vault remove' 'knife vault update' "\
63
62
  "or 'knife vault edit' to make changes."
64
63
  rescue ChefVault::Exceptions::KeysNotFound,
65
- ChefVault::Exceptions::ItemNotFound
64
+ ChefVault::Exceptions::ItemNotFound
66
65
  vault_item = ChefVault::Item.new(vault, item)
67
66
 
68
67
  if values || json_file || file
@@ -75,7 +74,7 @@ class Chef
75
74
  vault_item["file-content"] = File.open(file) { |f| f.read() }
76
75
  end
77
76
  else
78
- vault_json = edit_data(Hash.new)
77
+ vault_json = edit_data({})
79
78
  vault_json.each do |key, value|
80
79
  vault_item[key] = value
81
80
  end
@@ -1,5 +1,5 @@
1
1
  # Description: Chef-Vault VaultDecrypt class
2
- # Copyright 2013, Nordstrom, Inc.
2
+ # Copyright 2013-15, Nordstrom, Inc.
3
3
 
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ require 'chef/knife/vault_base'
18
18
  class Chef
19
19
  class Knife
20
20
  class VaultDecrypt < Knife
21
-
22
21
  include Chef::Knife::VaultBase
23
22
 
24
23
  banner "knife vault decrypt VAULT ITEM [VALUES] (options)"
@@ -42,14 +41,14 @@ class Chef
42
41
  vault_item = ChefVault::Item.load(vault, item).raw_data
43
42
 
44
43
  if values
45
- included_values = %W( id )
44
+ included_values = %w(id)
46
45
 
47
46
  values.split(",").each do |value|
48
47
  value.strip! # remove white space
49
48
  included_values << value
50
49
  end
51
50
 
52
- output(Hash[vault_item.find_all{|k,v| included_values.include?(k)}])
51
+ output(Hash[vault_item.find_all{|k, _| included_values.include?(k)}])
53
52
  else
54
53
  output(vault_item)
55
54
  end