chef-vault 3.4.0.pre.pre419 → 3.4.0.pre.pre420

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. metadata +1 -45
  3. data/.github/CODEOWNERS +0 -2
  4. data/.gitignore +0 -33
  5. data/.rspec +0 -2
  6. data/.rubocop.yml +0 -6
  7. data/.simplecov +0 -6
  8. data/.travis.yml +0 -19
  9. data/Changelog.md +0 -141
  10. data/DEMO.md +0 -60
  11. data/Gemfile +0 -12
  12. data/KNIFE_EXAMPLES.md +0 -256
  13. data/README.md +0 -333
  14. data/Rakefile +0 -50
  15. data/THEORY.md +0 -363
  16. data/UPGRADE.md +0 -55
  17. data/appveyor.yml +0 -32
  18. data/chef-vault.gemspec +0 -54
  19. data/features/clean.feature +0 -23
  20. data/features/clean_on_refresh.feature +0 -27
  21. data/features/clean_unknown_clients.feature +0 -45
  22. data/features/detect_and_warn_v1_vault.feature +0 -14
  23. data/features/isvault.feature +0 -29
  24. data/features/itemtype.feature +0 -24
  25. data/features/step_definitions/chef-databag.rb +0 -9
  26. data/features/step_definitions/chef-repo.rb +0 -72
  27. data/features/step_definitions/chef-vault.rb +0 -151
  28. data/features/step_definitions/chef_databagitem.rb +0 -9
  29. data/features/support/env.rb +0 -14
  30. data/features/vault_create.feature +0 -63
  31. data/features/vault_list.feature +0 -31
  32. data/features/vault_show.feature +0 -45
  33. data/features/vault_show_vaultname.feature +0 -21
  34. data/features/vault_update.feature +0 -18
  35. data/features/verify_id_matches.feature +0 -10
  36. data/features/wrong_private_key.feature +0 -13
  37. data/hooks/pre-commit +0 -43
  38. data/spec/chef-vault/actor_spec.rb +0 -247
  39. data/spec/chef-vault/certificate_spec.rb +0 -37
  40. data/spec/chef-vault/chef_api_spec.rb +0 -39
  41. data/spec/chef-vault/item_keys_spec.rb +0 -263
  42. data/spec/chef-vault/item_spec.rb +0 -360
  43. data/spec/chef-vault/user_spec.rb +0 -36
  44. data/spec/chef-vault_spec.rb +0 -65
  45. data/spec/spec_helper.rb +0 -91
  46. data/tasks/github_changelog_generator.rb +0 -30
data/UPGRADE.md DELETED
@@ -1,55 +0,0 @@
1
- # UPGRADING A v1 VAULT to v2
2
-
3
- chef-vault v2 added metadata to the vault to keep track of
4
- which secrets belong to clients and which belong to admins,
5
- as well as the search query to use during a `knife vault refresh`
6
- operation.
7
-
8
- You can use chef-vault v2 to decrypt v1 vaults, but the management
9
- operations are unable to intuit which of the secrets belong to
10
- clients and which belong to admins. Fixing this error thus requires
11
- some manual intervention.
12
-
13
- If you attempt to use the management operations (refresh, update, etc.)
14
- on a v1 vault, you will get this error:
15
-
16
- ChefVault::Exceptions::V1Format: cannot manage a v1 vault. See UPGRADE.md for help
17
-
18
- To fix this, you need to edit the data bag item by hand. Assuming a
19
- vault 'foo' with an item 'bar', run:
20
-
21
- knife data bag edit foo bar_keys
22
-
23
- This will present you with a JSON representation of the extra data
24
- bag item managed by chef-vault. It will have an id key as well as a key
25
- for every user for whom the vault item is encrypted:
26
-
27
- {
28
- "id" : "bar_keys",
29
- "james" : "iWdGgm...\n",
30
- "one" : "RjJ4rlh....\n",
31
- "two" : "NHJlqnfd9...\n",
32
- "three" : "GjXkrxq...\n"
33
- }
34
-
35
- Add keys for 'admins', 'clients' and 'search_query':
36
-
37
- {
38
- "id" : "bar_keys",
39
- "james" : "iWdGgm...\n",
40
- "one" : "RjJ4rlh....\n",
41
- "two" : "NHJlqnfd9...\n",
42
- "three" : "GjXkrxq...\n",
43
- "admins": [],
44
- "clients": [],
45
- "search_query": ""
46
- }
47
-
48
- Save the edited data bag and run knife vault update with the appropriate values to populate those keys:
49
-
50
- knife vault update foo bar -S 'name:*' -A james
51
-
52
- (set your search query to something appropriate for your environment)
53
-
54
- v2.7.0 of chef-vault may add some automation to this step, but for now this
55
- provides a way to upgrade without breaking your ability to manage things.
@@ -1,32 +0,0 @@
1
- version: "master-{build}"
2
-
3
- os: Windows Server 2012 R2
4
- platform:
5
- - x64
6
-
7
- clone_depth: 1
8
- skip_tags: true
9
- skip_branch_with_pr: true
10
- branches:
11
- only:
12
- - master
13
-
14
- # caching vendor/bundle appears to break horribly in the face of gems checked out of git
15
- # cache:
16
- # - vendor/bundle
17
-
18
- install:
19
- - ps: iex (irm https://omnitruck.chef.io/install.ps1); Install-Project -Project chefdk -channel stable
20
- - bundle config --local path vendor/bundle
21
- - SET CI=true
22
- - SET BUNDLE_WITHOUT=changelog:style
23
-
24
- build_script:
25
- - ps: c:\opscode\chefdk\bin\chef.bat shell-init powershell | iex
26
- - bundle install || bundle install || bundle install
27
-
28
- test_script:
29
- - SET SPEC_OPTS=--format progress
30
- - c:\opscode\chefdk\bin\chef.bat exec bundle exec rake spec
31
- # aruba on windows seems pretty terribadly broken: https://github.com/cucumber/aruba/pull/422
32
- # - c:\opscode\chefdk\bin\chef.bat exec bundle exec cucumber
@@ -1,54 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # Chef-Vault Gemspec file
3
- # Copyright 2013-15, Nordstrom, Inc.
4
-
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
-
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
-
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
-
17
- $:.push File.expand_path("../lib", __FILE__)
18
- require "chef-vault/version"
19
-
20
- def self.prerelease?
21
- !ENV["TRAVIS_TAG"] || ENV["TRAVIS_TAG"].empty?
22
- end
23
-
24
- Gem::Specification.new do |s|
25
- s.name = "chef-vault"
26
- s.version = ChefVault::VERSION
27
- s.version = "#{s.version}-pre#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV["TRAVIS"]
28
- s.has_rdoc = true
29
- s.authors = ["Thom May"]
30
- s.email = ["thom@chef.io"]
31
- s.summary = "Data encryption support for Chef using data bags"
32
- s.description = s.summary
33
- s.homepage = "https://github.com/chef/chef-vault"
34
- s.license = "Apache License, v2.0"
35
- s.files = `git ls-files`.split("\n")
36
- s.require_paths = ["lib"]
37
- s.bindir = "bin"
38
- s.executables = %w{ chef-vault }
39
-
40
- s.required_ruby_version = ">= 2.2.0"
41
-
42
- s.add_development_dependency "rake", "~> 11.0"
43
- s.add_development_dependency "rspec", "~> 3.4"
44
- s.add_development_dependency "aruba", "~> 0.6"
45
- s.add_development_dependency "simplecov", "~> 0.9"
46
- s.add_development_dependency "simplecov-console", "~> 0.2"
47
- if ENV.key?("TRAVIS_BUILD") && RUBY_VERSION == "2.1.9"
48
- # Test version of Chef with Chef Zero before
49
- # /orgs/org/users/user/keys endpoint was added.
50
- s.add_development_dependency "chef", "12.8.1"
51
- else # Test most current version of Chef on 2.2.2
52
- s.add_development_dependency :chef
53
- end
54
- end
@@ -1,23 +0,0 @@
1
- Feature: clean client keys
2
- When updating a vault item, chef-vault normally performs the
3
- saved or specified query and encrypts the item for all nodes
4
- returned. It does not remove old client keys from the vault
5
- item keys data bag, which will grow over time. Using the
6
- --clean switch will cause all client keys to be removed from
7
- the data bag before encrypting the item for all clients
8
- returned by the query
9
-
10
- Scenario: Do not clean client keys on update
11
- Given a local mode chef repo with nodes 'one,two,three'
12
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two'
13
- Then the vault item 'test/item' should be encrypted for 'one,two'
14
- And I update the vault item 'test/item' to be encrypted for 'two,three'
15
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
16
-
17
- Scenario: Clean client keys on update
18
- Given a local mode chef repo with nodes 'one,two,three'
19
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two'
20
- Then the vault item 'test/item' should be encrypted for 'one,two'
21
- And I update the vault item 'test/item' to be encrypted for 'two,three' with the clean option
22
- Then the vault item 'test/item' should be encrypted for 'two,three'
23
- And the vault item 'test/item' should not be encrypted for 'one'
@@ -1,27 +0,0 @@
1
- Feature: clean unknown clients on vault refresh
2
- When refreshing a vault, new clients may be added if they match
3
- the search query or client list, but old clients that no longer
4
- exist will never be removed. The --clean-unknown-clients switch
5
- will cause cause any unknown clients to be removed from the vault
6
- item's access list as well
7
-
8
- Scenario: Refresh without clean option
9
- Given a local mode chef repo with nodes 'one,two,three'
10
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
11
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
12
- And I delete node 'one' from the Chef server
13
- And I refresh the vault item 'test/item'
14
- And the vault item 'test/item' should be encrypted for 'one,two,three'
15
- And 'one,two,three' should be a client for the vault item 'test/item'
16
-
17
- Scenario: Refresh with clean option
18
- Given a local mode chef repo with nodes 'one,two,three'
19
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
20
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
21
- And I delete node 'one' from the Chef server
22
- And I refresh the vault item 'test/item' with the 'clean-unknown-clients' option
23
- Then the output should contain "Removing unknown client 'one'"
24
- And the vault item 'test/item' should be encrypted for 'two,three'
25
- And the vault item 'test/item' should not be encrypted for 'one'
26
- And 'two,three' should be a client for the vault item 'test/item'
27
- And 'one' should not be a client for the vault item 'test/item'
@@ -1,45 +0,0 @@
1
- Feature: clean unknown clients on key rotation
2
- When removing a client from a vault item, chef-vault normally
3
- removes the key and then rotates the key. If a node has been
4
- deleted in the meantime from the Chef server but not the vault,
5
- the rotation will fail due to that client's public key missing.
6
- Using the --clean-unknown-clients switch will cause any clients
7
- that have been removed to be removed from the vault item's
8
- access list as well
9
-
10
- Scenario: Prune clients when rotating keys
11
- Given a local mode chef repo with nodes 'one,two,three'
12
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
13
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
14
- And I delete node 'one' from the Chef server
15
- And I rotate the keys for vault item 'test/item' with the 'clean-unknown-clients' option
16
- Then the output should contain "Removing unknown client 'one'"
17
- And the vault item 'test/item' should be encrypted for 'two,three'
18
- And the vault item 'test/item' should not be encrypted for 'one'
19
- And 'two,three' should be a client for the vault item 'test/item'
20
- And 'one' should not be a client for the vault item 'test/item'
21
-
22
- Scenario: Prune clients when rotating all keys
23
- Given a local mode chef repo with nodes 'one,two,three'
24
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
25
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
26
- And I delete nodes 'one,two' from the Chef server
27
- And I rotate all keys with the 'clean-unknown-clients' option
28
- Then the output should contain "Removing unknown client 'one'"
29
- And the output should contain "Removing unknown client 'two'"
30
- And the vault item 'test/item' should be encrypted for 'three'
31
- And the vault item 'test/item' should not be encrypted for 'one,two'
32
- And 'three' should be a client for the vault item 'test/item'
33
- And 'one,two' should not be a client for the vault item 'test/item'
34
-
35
- Scenario: Prune clients when node gone but client exists
36
- Given a local mode chef repo with nodes 'one,two,three'
37
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
38
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
39
- And I delete node 'one' from the Chef server
40
- And I rotate the keys for vault item 'test/item' with the 'clean-unknown-clients' option
41
- Then the output should contain "Removing unknown client 'one'"
42
- And the vault item 'test/item' should be encrypted for 'two,three'
43
- And the vault item 'test/item' should not be encrypted for 'one'
44
- And 'two,three' should be a client for the vault item 'test/item'
45
- And 'one' should not be a client for the vault item 'test/item'
@@ -1,14 +0,0 @@
1
- Feature: Detect and Warn for v1 Vaults
2
- chef-vault can read a v1 vault, but the management commands
3
- tend to break when they try to reference v2 fields like
4
- clients and admins. They should detect and warn when trying
5
- to access a v1 vault
6
-
7
- Scenario: Add search query to v1 vault
8
- Given a local mode chef repo with nodes 'one,two,three' with admins 'bob'
9
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
10
- Then the vault item 'test/item' should be encrypted for 'one,two,three'
11
- And 'one,two,three' should be a client for the vault item 'test/item'
12
- And I downgrade the vault item 'test/item' to v1 syntax
13
- And I try to add 'bob' as an admin for the vault item 'test/item'
14
- Then the output should match /cannot manage a v1 vault. See UPGRADE.md for help/
@@ -1,29 +0,0 @@
1
- Feature: determine if a data bag item is a vault
2
- If a data bag item is a vault, 'knife vault isvault VAULTNAME ITEMNAME'
3
- should exit 0. Otherwise it should exit 1.
4
-
5
- Scenario: detect vault item
6
- Given a local mode chef repo with nodes 'one,two,three'
7
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
8
- And I check if the data bag item 'test/item' is a vault
9
- Then the exit status should be 0
10
-
11
- Scenario: detect vault item with keys in sparse mode
12
- Given a local mode chef repo with nodes 'one,two,three'
13
- And I create a vault item 'test/item' with keys in sparse mode containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
14
- And I check if the data bag item 'test/item' is a vault
15
- Then the exit status should be 0
16
-
17
- Scenario: detect non-vault item (encrypted data bag)
18
- Given a local mode chef repo with nodes 'one,two,three'
19
- And I create an empty data bag 'test'
20
- And I create an encrypted data bag item 'test/item' containing the JSON '{"id": "item", "foo": "bar"}' with the secret 'sekrit'
21
- And I check if the data bag item 'test/item' is a vault
22
- Then the exit status should not be 0
23
-
24
- Scenario: detect non-vault item (normal data bag)
25
- Given a local mode chef repo with nodes 'one,two,three'
26
- And I create an empty data bag 'test'
27
- And I create a data bag item 'test/item' containing the JSON '{"id": "item", "foo": "bar"}'
28
- And I check if the data bag item 'test/item' is a vault
29
- Then the exit status should not be 0
@@ -1,24 +0,0 @@
1
- Feature: determine the type of a data bag item
2
- 'knife vault itemtype VAULTNAME ITEMNAME' should output one of
3
- 'normal', 'encrypted', or 'vault' depending on what type of item
4
- it detects
5
-
6
- Scenario: detect vault item
7
- Given a local mode chef repo with nodes 'one,two,three'
8
- And I create a vault item 'test/item' containing the JSON '{"foo": "bar"}' encrypted for 'one,two,three'
9
- And I check the type of the data bag item 'test/item'
10
- Then the output should match /^vault$/
11
-
12
- Scenario: detect non-vault item (encrypted data bag)
13
- Given a local mode chef repo with nodes 'one,two,three'
14
- And I create an empty data bag 'test'
15
- And I create an encrypted data bag item 'test/item' containing the JSON '{"id": "item", "foo": "bar"}' with the secret 'sekrit'
16
- And I check the type of the data bag item 'test/item'
17
- Then the output should match /^encrypted$/
18
-
19
- Scenario: detect non-vault item (normal data bag)
20
- Given a local mode chef repo with nodes 'one,two,three'
21
- And I create an empty data bag 'test'
22
- And I create a data bag item 'test/item' containing the JSON '{"id": "item", "foo": "bar"}'
23
- And I check the type of the data bag item 'test/item'
24
- Then the output should match /^normal$/
@@ -1,9 +0,0 @@
1
- When(/^I create a data bag '(.+)' containing the JSON '(.+)'$/) do |bag, json|
2
- write_file "item.json", json
3
- run_simple "knife data bag create #{bag} -z -c knife.rb -d"
4
- run_simple "knife data bag from_file #{bag} -z -c knife.rb item.json"
5
- end
6
-
7
- Given(/^I create an empty data bag '(.+)'$/) do |databag|
8
- run_simple "knife data bag create #{databag} -z -c knife.rb", false
9
- end
@@ -1,72 +0,0 @@
1
- Given(/^a local mode chef repo with nodes '(.+?)'(?: with admins '(.+?)')?$/) do |nodelist, adminlist|
2
- # create the repo directory hierarchy
3
- %w{cookbooks clients nodes data_bags}.each do |dir|
4
- create_directory dir
5
- end
6
- # create a basic knife.rb
7
- write_file "knife.rb", <<EOF
8
- local_mode true
9
- chef_repo_path '.'
10
- chef_zero.enabled true
11
- knife[:vault_mode] = 'client'
12
- EOF
13
- # create the admin users and capture their private key we
14
- # always create an admin called 'admin' because otherwise subsequent
15
- # steps become annoying to determine who the admin is
16
- admins = %w{admin}
17
- admins.push(adminlist.split(/,/)) if adminlist
18
- admins.flatten.each do |admin|
19
- create_admin(admin)
20
- end
21
- # add the admin key to the knife configuration
22
- append_to_file "knife.rb", <<EOF
23
- node_name 'admin'
24
- client_key 'admin.pem'
25
- EOF
26
- # create the requested nodes
27
- nodelist.split(/,/).each do |node|
28
- create_client(node)
29
- create_node(node)
30
- end
31
- end
32
-
33
- Given(/^I create an admin named '(.+)'$/) do |admin|
34
- create_admin(admin)
35
- end
36
-
37
- Given(/^I delete clients? '(.+)' from the Chef server$/) do |nodelist|
38
- nodelist.split(/,/).each do |node|
39
- delete_client(node)
40
- end
41
- end
42
-
43
- Given(/^I regenerate the client key for the node '(.+)'$/) do |node|
44
- delete_client(node)
45
- create_client(node)
46
- end
47
-
48
- Given(/^I delete nodes? '(.+)' from the Chef server$/) do |nodelist|
49
- nodelist.split(/,/).each { |node| delete_node(node) }
50
- end
51
-
52
- def create_node(name)
53
- run_simple "knife node create #{name} -z -d -c knife.rb"
54
- end
55
-
56
- def create_admin(admin)
57
- create_client(admin, "-a")
58
- end
59
-
60
- def create_client(name, args = nil)
61
- command = "knife client create #{name} -z -d -c knife.rb #{args} >#{name}.pem"
62
- run_simple command
63
- write_file("#{name}.pem", last_command_started.stdout)
64
- end
65
-
66
- def delete_client(name)
67
- run_simple "knife client delete #{name} -y -z -c knife.rb"
68
- end
69
-
70
- def delete_node(name)
71
- run_simple "knife node delete #{name} -y -z -c knife.rb"
72
- end
@@ -1,151 +0,0 @@
1
- require "json"
2
-
3
- Given(/^I create a vault item '(.+)\/(.+)'( with keys in sparse mode)? containing the JSON '(.+)' encrypted for '(.+)'(?: with '(.+)' as admins?)?$/) do |vault, item, sparse, json, nodelist, admins|
4
- write_file "item.json", json
5
- query = nodelist.split(/,/).map { |e| "name:#{e}" }.join(" OR ")
6
- adminarg = admins.nil? ? "-A admin" : "-A #{admins}"
7
- sparseopt = sparse.nil? ? "" : "-K sparse"
8
- run_simple "knife vault create #{vault} #{item} -z -c knife.rb #{adminarg} #{sparseopt} -S '#{query}' -J item.json", false
9
- end
10
-
11
- Given(/^I update the vault item '(.+)\/(.+)' to be encrypted for '(.+)'( with the clean option)?$/) do |vault, item, nodelist, cleanopt|
12
- query = nodelist.split(/,/).map { |e| "name:#{e}" }.join(" OR ")
13
- run_simple "knife vault update #{vault} #{item} -z -c knife.rb -S '#{query}' #{cleanopt ? '--clean' : ''}"
14
- end
15
-
16
- Given(/^I remove clients? '(.+)' from vault item '(.+)\/(.+)' with the '(.+)' options?$/) do |nodelist, vault, item, optionlist|
17
- query = nodelist.split(/,/).map { |e| "name:#{e}" }.join(" OR ")
18
- options = optionlist.split(/,/).map { |o| "--#{o}" }.join(" ")
19
- run_simple "knife vault remove #{vault} #{item} -z -c knife.rb -S '#{query}' #{options}"
20
- end
21
-
22
- Given(/^I rotate the keys for vault item '(.+)\/(.+)' with the '(.+)' options?$/) do |vault, item, optionlist|
23
- options = optionlist.split(/,/).map { |o| "--#{o}" }.join(" ")
24
- run_simple "knife vault rotate keys #{vault} #{item} -c knife.rb -z #{options}"
25
- end
26
-
27
- Given(/^I rotate all keys with the '(.+)' options?$/) do |optionlist|
28
- options = optionlist.split(/,/).map { |o| "--#{o}" }.join(" ")
29
- run_simple "knife vault rotate all keys -z -c knife.rb #{options}"
30
- end
31
-
32
- Given(/^I refresh the vault item '(.+)\/(.+)'$/) do |vault, item|
33
- run_simple "knife vault refresh #{vault} #{item} -c knife.rb -z"
34
- end
35
-
36
- Given(/^I refresh the vault item '(.+)\/(.+)' with the '(.+)' options?$/) do |vault, item, optionlist|
37
- options = optionlist.split(/,/).map { |o| "--#{o}" }.join(" ")
38
- run_simple "knife vault refresh #{vault} #{item} -c knife.rb -z #{options}"
39
- end
40
-
41
- Given(/^I try to decrypt the vault item '(.+)\/(.+)' as '(.+)'$/) do |vault, item, node|
42
- run_simple "knife vault show #{vault} #{item} -z -c knife.rb -u #{node} -k #{node}.pem", false
43
- end
44
-
45
- Then(/^the vault item '(.+)\/(.+)' should( not)? be encrypted for '(.+)'( with keys in sparse mode)?$/) do |vault, item, neg, nodelist, sparse|
46
- nodes = nodelist.split(/,/)
47
- command = "knife data bag show #{vault} #{item}_keys -z -c knife.rb -F json"
48
- run_simple(command)
49
- output = last_command_started.stdout
50
- data = JSON.parse(output)
51
- if sparse
52
- expect(data).to include("mode" => "sparse")
53
- nodes.each do |node|
54
- command = "knife data bag show #{vault} #{item}_key_#{node} -z -c knife.rb -F json"
55
- run_simple(command, fail_on_error: false)
56
- if neg
57
- error = last_command_started.stderr
58
- expect(error).to include("ERROR: The object you are looking for could not be found")
59
- else
60
- data = JSON.parse(last_command_started.stdout)
61
- expect(data).to include("id" => "#{item}_key_#{node}")
62
- end
63
- end
64
- else
65
- expect(data).to include("mode" => "default")
66
- nodes.each { |node| neg ? (expect(data).not_to include(node)) : (expect(data).to include(node)) }
67
- end
68
- end
69
-
70
- Given(/^'(.+)' should( not)? be a client for the vault item '(.+)\/(.+)'$/) do |nodelist, neg, vault, item|
71
- nodes = nodelist.split(/,/)
72
- command = "knife data bag show #{vault} #{item}_keys -z -c knife.rb -F json"
73
- run_simple(command)
74
- output = last_command_started.stdout
75
- data = JSON.parse(output)
76
- nodes.each do |node|
77
- if neg
78
- expect(data["clients"]).not_to include(node)
79
- else
80
- expect(data["clients"]).to include(node)
81
- end
82
- end
83
- end
84
-
85
- Given(/^'(.+)' should( not)? be an admin for the vault item '(.+)\/(.+)'$/) do |nodelist, neg, vault, item|
86
- nodes = nodelist.split(/,/)
87
- command = "knife data bag show #{vault} #{item}_keys -z -c knife.rb -F json"
88
- run_simple(command)
89
- output = last_command_started.stdout
90
- data = JSON.parse(output)
91
- nodes.each do |node|
92
- if neg
93
- expect(data["admins"]).not_to include(node)
94
- else
95
- expect(data["admins"]).to include(node)
96
- end
97
- end
98
- end
99
-
100
- Given(/^I list the vaults$/) do
101
- run_simple("knife vault list")
102
- end
103
-
104
- Given(/^I can('t)? decrypt the vault item '(.+)\/(.+)' as '(.+)'$/) do |neg, vault, item, client|
105
- run_simple "knife vault show #{vault} #{item} -c knife.rb -z -u #{client} -k #{client}.pem", false
106
- if neg
107
- expect(last_command_started).not_to have_exit_status(0)
108
- else
109
- expect(last_command_started).to have_exit_status(0)
110
- end
111
- end
112
-
113
- Given(/^I (try to )?add '(.+)' as an admin for the vault item '(.+)\/(.+)'$/) do |try, newadmin, vault, item|
114
- run_simple "knife vault update #{vault} #{item} -c knife.rb -z -A #{newadmin}", !try
115
- end
116
-
117
- Given(/^I show the keys of the vault '(.+)'$/) do |vault|
118
- run_simple "knife vault show #{vault} -c knife.rb -z"
119
- end
120
-
121
- Given(/^I check if the data bag item '(.+)\/(.+)' is a vault$/) do |vault, item|
122
- run_simple "knife vault isvault #{vault} #{item} -c knife.rb -z", false
123
- end
124
-
125
- Given(/^I check the type of the data bag item '(.+)\/(.+)'$/) do |vault, item|
126
- run_simple "knife vault itemtype #{vault} #{item} -c knife.rb -z"
127
- end
128
-
129
- Given(/^I downgrade the vault item '(.+)\/(.+)' to v1 syntax/) do |vault, item|
130
- # v1 syntax doesn't have the admins, clients and search_query keys
131
- keysfile = "tmp/aruba/data_bags/#{vault}/#{item}_keys.json"
132
- data = JSON.parse(IO.read(keysfile))
133
- %w{admins clients search_query}.each { |k| data.key?("raw_data") ? data["raw_data"].delete(k) : data.delete(k) }
134
- IO.write(keysfile, JSON.generate(data))
135
- end
136
-
137
- Given(/^I can save the JSON object of the encrypted data bag for the vault item '(.+)\/(.+)'$/) do |vault, item|
138
- command = "knife data bag show #{vault} #{item} -z -c knife.rb -F json"
139
- run_simple(command)
140
- output = last_command_started.stdout
141
- @saved_encrypted_vault_item = JSON.parse(output)
142
- end
143
-
144
- Given(/^the data bag of the vault item '(.+)\/(.+)' has not been re-encrypted$/) do |vault, item|
145
- command = "knife data bag show #{vault} #{item} -z -c knife.rb -F json"
146
- run_simple(command)
147
- output = last_command_started.stdout
148
- encrypted_vault_item = JSON.parse(output)
149
-
150
- expect(encrypted_vault_item).to eq(@saved_encrypted_vault_item)
151
- end