conjur-cli 5.6.6 → 6.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +1 -1
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +1 -1
  5. data/APPLIANCE_VERSION +1 -1
  6. data/CHANGELOG.md +3 -42
  7. data/Gemfile +4 -7
  8. data/Humanfile.md +31 -0
  9. data/Jenkinsfile +34 -63
  10. data/README.md +41 -55
  11. data/Rakefile +5 -1
  12. data/bin/conjur +0 -2
  13. data/build-deb.sh +1 -3
  14. data/ci/cli-test.sh +6 -0
  15. data/ci/package.sh +3 -1
  16. data/ci/publish.sh +2 -2
  17. data/ci/secrets/publish.yml +2 -2
  18. data/ci/wait_for_server.sh +10 -0
  19. data/conjur-cli.gemspec +7 -7
  20. data/dev/docker-compose.yml +24 -0
  21. data/dev/start.sh +15 -0
  22. data/dev/stop.sh +5 -0
  23. data/docker-compose.yml +30 -0
  24. data/features/authentication/authenticate.feature +34 -0
  25. data/features/authentication/login.feature +13 -0
  26. data/features/authentication/logout.feature +15 -0
  27. data/{acceptance-features → features}/authentication/whoami.feature +0 -0
  28. data/features/authorization/resource/annotate.feature +22 -0
  29. data/features/authorization/resource/check.feature +47 -0
  30. data/{acceptance-features → features}/authorization/resource/exists.feature +18 -6
  31. data/features/authorization/resource/permitted_roles.feature +35 -0
  32. data/features/authorization/resource/show.feature +34 -0
  33. data/features/authorization/role/exists.feature +28 -0
  34. data/features/authorization/role/members.feature +45 -0
  35. data/features/authorization/role/memberships.feature +43 -0
  36. data/features/conjurenv/check.feature +34 -0
  37. data/features/conjurenv/run.feature +15 -0
  38. data/{acceptance-features → features}/conjurenv/template.feature +8 -3
  39. data/{acceptance-features → features}/directory/user/update_password.feature +8 -2
  40. data/{acceptance-features → features}/directory/variable/value.feature +9 -5
  41. data/{acceptance-features → features}/directory/variable/values-add.feature +8 -3
  42. data/features/hostfactory/tokens.feature +22 -0
  43. data/features/pubkeys/show.feature +18 -0
  44. data/features/step_definitions/authn_steps.rb +22 -0
  45. data/features/step_definitions/cli_steps.rb +28 -0
  46. data/features/step_definitions/file_steps.rb +12 -0
  47. data/features/step_definitions/flow_control_steps.rb +7 -0
  48. data/features/step_definitions/graph_steps.rb +4 -3
  49. data/{acceptance-features → features}/step_definitions/http_steps.rb +0 -0
  50. data/features/step_definitions/overrides.rb +9 -0
  51. data/features/step_definitions/policy_steps.rb +11 -0
  52. data/{acceptance-features → features}/step_definitions/trusted_proxy_steps.rb +0 -0
  53. data/features/support/blank.yml +1 -0
  54. data/features/support/env.rb +21 -7
  55. data/features/support/hooks.rb +31 -116
  56. data/features/support/world.rb +16 -76
  57. data/jenkins.sh +33 -0
  58. data/lib/conjur/authenticator.rb +83 -0
  59. data/lib/conjur/authn.rb +5 -20
  60. data/lib/conjur/cli.rb +13 -6
  61. data/lib/conjur/command.rb +30 -350
  62. data/lib/conjur/command/authn.rb +23 -15
  63. data/lib/conjur/command/host_factories.rb +2 -74
  64. data/lib/conjur/command/hosts.rb +6 -113
  65. data/lib/conjur/command/init.rb +20 -35
  66. data/lib/conjur/command/{secrets.rb → policies.rb} +33 -22
  67. data/lib/conjur/command/pubkeys.rb +3 -63
  68. data/lib/conjur/command/resources.rb +45 -162
  69. data/lib/conjur/command/roles.rb +11 -181
  70. data/lib/conjur/command/rspec/helpers.rb +0 -1
  71. data/lib/conjur/command/rspec/mock_services.rb +4 -4
  72. data/lib/conjur/command/users.rb +2 -159
  73. data/lib/conjur/command/variables.rb +5 -218
  74. data/lib/conjur/complete.rb +2 -2
  75. data/lib/conjur/config.rb +1 -11
  76. data/lib/conjur/conjurenv.rb +12 -9
  77. data/lib/conjur/identifier_manipulation.rb +3 -5
  78. data/lib/conjur/version.rb +2 -2
  79. data/{publish-rubygem.sh → publish.sh} +0 -4
  80. data/spec/authn_spec.rb +4 -0
  81. data/spec/command/hosts_spec.rb +2 -69
  82. data/spec/command/init_spec.rb +16 -11
  83. data/spec/command/pubkeys_spec.rb +1 -46
  84. data/spec/command/resources_spec.rb +21 -170
  85. data/spec/command/roles_spec.rb +5 -181
  86. data/spec/command/users_spec.rb +3 -79
  87. data/spec/command_spec.rb +1 -20
  88. data/spec/complete_spec.rb +1 -23
  89. data/spec/config_spec.rb +1 -1
  90. data/spec/spec_helper.rb +4 -5
  91. data/test.sh +29 -25
  92. metadata +92 -212
  93. data/.githooks/pre_commit/run_specs.rb +0 -23
  94. data/Dockerfile +0 -15
  95. data/Dockerfile.fpm +0 -18
  96. data/Dockerfile.publish +0 -12
  97. data/Dockerfile.standalone +0 -33
  98. data/Dockerfile.validate-packaging +0 -9
  99. data/VERSION +0 -1
  100. data/acceptance-features/audit/audit_event_send.feature +0 -107
  101. data/acceptance-features/audit/fetch.feature +0 -16
  102. data/acceptance-features/audit/send.feature +0 -51
  103. data/acceptance-features/authentication/authenticate.feature +0 -10
  104. data/acceptance-features/authentication/login.feature +0 -12
  105. data/acceptance-features/authentication/logout.feature +0 -13
  106. data/acceptance-features/authorization/resource/annotate.feature +0 -35
  107. data/acceptance-features/authorization/resource/check.feature +0 -24
  108. data/acceptance-features/authorization/resource/create.feature +0 -21
  109. data/acceptance-features/authorization/resource/deny.feature +0 -12
  110. data/acceptance-features/authorization/resource/give.feature +0 -24
  111. data/acceptance-features/authorization/resource/permit.feature +0 -20
  112. data/acceptance-features/authorization/resource/permitted_roles.feature +0 -16
  113. data/acceptance-features/authorization/resource/show.feature +0 -28
  114. data/acceptance-features/authorization/role/create.feature +0 -13
  115. data/acceptance-features/authorization/role/exists.feature +0 -19
  116. data/acceptance-features/authorization/role/grant_to.feature +0 -21
  117. data/acceptance-features/authorization/role/graph.feature +0 -57
  118. data/acceptance-features/authorization/role/members.feature +0 -23
  119. data/acceptance-features/authorization/role/memberships.feature +0 -27
  120. data/acceptance-features/bootstrap.feature +0 -13
  121. data/acceptance-features/conjurenv/check.feature +0 -21
  122. data/acceptance-features/conjurenv/run.feature +0 -10
  123. data/acceptance-features/directory/group/create.feature +0 -20
  124. data/acceptance-features/directory/group/retire.feature +0 -54
  125. data/acceptance-features/directory/host/create.feature +0 -23
  126. data/acceptance-features/directory/host/retire.feature +0 -6
  127. data/acceptance-features/directory/hostfactory/create.feature +0 -28
  128. data/acceptance-features/directory/hostfactory/tokens.feature +0 -16
  129. data/acceptance-features/directory/layer/create.feature +0 -10
  130. data/acceptance-features/directory/layer/hosts-add.feature +0 -9
  131. data/acceptance-features/directory/layer/hosts-remove.feature +0 -10
  132. data/acceptance-features/directory/layer/retire.feature +0 -43
  133. data/acceptance-features/directory/user/create.feature +0 -23
  134. data/acceptance-features/directory/user/retire.feature +0 -6
  135. data/acceptance-features/directory/variable/create.feature +0 -14
  136. data/acceptance-features/directory/variable/retire.feature +0 -17
  137. data/acceptance-features/dsl/policy_owner.feature +0 -45
  138. data/acceptance-features/dsl/resource_owner.feature +0 -17
  139. data/acceptance-features/dsl/retire.feature +0 -15
  140. data/acceptance-features/global-privilege/elevate.feature +0 -20
  141. data/acceptance-features/global-privilege/reveal.privilege +0 -20
  142. data/acceptance-features/pubkeys/add.feature +0 -22
  143. data/acceptance-features/pubkeys/delete.feature +0 -9
  144. data/acceptance-features/pubkeys/names.feature +0 -26
  145. data/acceptance-features/pubkeys/show.feature +0 -27
  146. data/acceptance-features/step_definitions/cli_steps.rb +0 -57
  147. data/acceptance-features/step_definitions/graph_steps.rb +0 -22
  148. data/acceptance-features/step_definitions/user_steps.rb +0 -51
  149. data/acceptance-features/support/env.rb +0 -23
  150. data/acceptance-features/support/hooks.rb +0 -178
  151. data/acceptance-features/support/world.rb +0 -176
  152. data/acceptance-features/trusted_proxies.feature +0 -82
  153. data/bin/conjurize +0 -26
  154. data/bin/jsonfield +0 -70
  155. data/build-standalone +0 -6
  156. data/deprecations.sh +0 -38
  157. data/features/conjurize.feature +0 -134
  158. data/features/dsl_context.feature +0 -36
  159. data/features/dsl_host_create.feature +0 -11
  160. data/features/dsl_ownership.feature +0 -30
  161. data/features/dsl_permission.feature +0 -45
  162. data/features/dsl_resource_create.feature +0 -23
  163. data/features/dsl_role_create.feature +0 -11
  164. data/features/dsl_user_create.feature +0 -23
  165. data/features/jsonfield.feature +0 -49
  166. data/features/role_graph.feature +0 -58
  167. data/features/step_definitions/conjurize_steps.rb +0 -5
  168. data/features/step_definitions/dsl_steps.rb +0 -52
  169. data/features/support/conjur.conf +0 -6
  170. data/lib/conjur/command/assets.rb +0 -121
  171. data/lib/conjur/command/audit.rb +0 -155
  172. data/lib/conjur/command/bootstrap.rb +0 -129
  173. data/lib/conjur/command/dsl_command.rb +0 -75
  174. data/lib/conjur/command/elevate.rb +0 -76
  175. data/lib/conjur/command/field.rb +0 -45
  176. data/lib/conjur/command/groups.rb +0 -208
  177. data/lib/conjur/command/ids.rb +0 -34
  178. data/lib/conjur/command/layers.rb +0 -211
  179. data/lib/conjur/command/ldapsync.rb +0 -118
  180. data/lib/conjur/command/rspec/audit_helpers.rb +0 -68
  181. data/lib/conjur/command/rubydsl.rb +0 -93
  182. data/lib/conjur/command/script.rb +0 -48
  183. data/lib/conjur/command/server.rb +0 -67
  184. data/lib/conjur/conjurize.rb +0 -71
  185. data/lib/conjur/conjurize/script.rb +0 -150
  186. data/lib/conjur/dsl/runner.rb +0 -273
  187. data/publish-deb.sh +0 -6
  188. data/push-image +0 -29
  189. data/spec/command/assets_spec.rb +0 -115
  190. data/spec/command/audit_spec.rb +0 -376
  191. data/spec/command/elevate_spec.rb +0 -28
  192. data/spec/command/env_spec.rb +0 -168
  193. data/spec/command/groups_spec.rb +0 -77
  194. data/spec/command/host_factories_spec.rb +0 -38
  195. data/spec/command/layers_spec.rb +0 -35
  196. data/spec/command/ldapsync_spec.rb +0 -28
  197. data/spec/command/rubydsl_spec.rb +0 -63
  198. data/spec/command/variable_expiration_spec.rb +0 -164
  199. data/spec/command/variables_spec.rb +0 -192
  200. data/spec/conjurize/script_spec.rb +0 -62
  201. data/spec/conjurize_spec.rb +0 -70
  202. data/spec/dsl/runner_spec.rb +0 -93
  203. data/spec/env_spec.rb +0 -214
@@ -1,51 +0,0 @@
1
- Given(/^I login as a new user$/) do
2
- @username_index ||= 0
3
- username = %w(alice bob charles dave edward)[@username_index]
4
- raise "I'm out of usernames!" unless username
5
- @username_index += 1
6
- @username = "#{username}@$ns"
7
- step %Q(I login as new user "#{@username}")
8
- end
9
-
10
- Given(/^I create a new user named "(.*?)"$/) do |username|
11
- step "I successfully run `conjur user create --as-role user:admin@#{namespace} #{username}`"
12
-
13
- user_info = JSON.parse(last_command_started.stdout)
14
- save_password username, user_info['api_key']
15
- end
16
-
17
- Given(/^I create a new host with id "(.*?)"$/) do |hostid|
18
- step "I successfully run `conjur host create #{namespace}/monitoring/server`"
19
- host = JSON.parse(last_json)
20
- @host_id = host['id']
21
- @host_api_key = host['api_key']
22
- end
23
-
24
- Given(/^I login as the new host/) do
25
- step %Q(I set the environment variable "CONJUR_AUTHN_LOGIN" to "host/#{@host_id}")
26
- step %Q(I set the environment variable "CONJUR_AUTHN_API_KEY" to "#{@host_api_key}")
27
- end
28
-
29
- Given(/^I login as new user "(.*?)"$/) do |username|
30
- step %Q(I create a new user named "#{username}")
31
- step %Q(I login as "#{username}")
32
- end
33
-
34
- Given(/^I login as "(.*?)"$/) do |username|
35
- password = find_password(username)
36
-
37
- step %Q(I set the environment variable "CONJUR_AUTHN_LOGIN" to "#{username}")
38
- step %Q(I set the environment variable "CONJUR_AUTHN_API_KEY" to "#{password}")
39
- end
40
-
41
- Then(/^I(?: can)? type and confirm a new password/) do
42
- @password = SecureRandom.hex(12)
43
- step %Q(I type "#{@password}")
44
- step %Q(I type "#{@password}")
45
- step "the exit status should be 0"
46
- end
47
-
48
- When(/^I enter the password/) do
49
- raise "No current password" unless @password
50
- step %Q(I type "#{@password}")
51
- end
@@ -1,23 +0,0 @@
1
- require "aruba/cucumber"
2
- require "json_spec/cucumber"
3
- require 'cucumber-api'
4
- require 'addressable/uri'
5
-
6
- $LOAD_PATH.unshift File.expand_path('../..', File.dirname(__FILE__))
7
-
8
- # Overwrite cucumber-api's resolve function so it will use the scheme
9
- # and host from ENV['CONJUR_APPLIANCE_URL'] if url doesn't already
10
- # have a host.
11
- $orig_resolve = self.method(:resolve)
12
- def resolve url
13
- # disable cucumber-api's ill-considered cache. Re-authenticate in
14
- # case it (cucumber-api) wiped out the headers
15
- $cache = {}
16
- add_user_auth_header
17
- url = Addressable::URI.parse(url)
18
- unless url.host
19
- conjur_url = Addressable::URI.parse(Conjur.configuration.appliance_url)
20
- url.merge!(:scheme => conjur_url.scheme, :host => conjur_url.host)
21
- end
22
- $orig_resolve.call(url.to_s)
23
- end
@@ -1,178 +0,0 @@
1
-
2
- require 'conjur/api'
3
- require 'conjur/cli'
4
- require 'conjur/authn'
5
-
6
- netrc = Conjur::Authn.netrc
7
- username, password = Conjur::Authn.get_credentials
8
- raise "Not logged in to Conjur" unless username && password
9
- puts "Performing acceptance tests as root-ish user '#{username}'"
10
-
11
- Aruba.configure do |config|
12
- config.exit_timeout = 30
13
- config.io_wait_timeout = 2
14
- end
15
-
16
- Before('@conjurapi-log') do
17
- set_env 'CONJURAPI_LOG', 'stderr'
18
- end
19
-
20
- Before do
21
- step %Q(I set the environment variable "CONJUR_AUTHN_LOGIN" to "#{username}")
22
- step %Q(I set the environment variable "CONJUR_AUTHN_API_KEY" to "#{password}")
23
-
24
- @admin_api = Conjur::Authn.connect
25
- @test_user = admin_api.create_user "admin@#{namespace}", ownerid: "#{Conjur.configuration.account}:user:#{username}"
26
-
27
- @security_admin = admin_api.create_group [ namespace, "security_admin" ].join('/')
28
- @security_admin.add_member test_user, admin_option: true
29
-
30
- JsonSpec.memorize "MY_ROLEID", %Q("#{test_user.roleid}")
31
- JsonSpec.memorize "NAMESPACE", namespace
32
-
33
- admin_api.group("pubkeys-1.0/key-managers").add_member @security_admin
34
- admin_api.resource('!:!:conjur').permit 'elevate', test_user, grant_option: true
35
- admin_api.resource('!:!:conjur').permit 'reveal', test_user, grant_option: true
36
-
37
- admin_api.create_user "attic@#{namespace}"
38
-
39
- # Set up the environment so the CLI will authenticate
40
- # correctly. Note that the API caches credentials, so these
41
- # variables won't have any effect on future calls to
42
- # Conjur::Authn.connect
43
- step %Q(I set the environment variable "CONJUR_AUTHN_LOGIN" to "#{test_user.login}")
44
- step %Q(I set the environment variable "CONJUR_AUTHN_API_KEY" to "#{test_user.api_key}")
45
- end
46
-
47
- After do
48
- if admin_api
49
- admin_api.group("pubkeys-1.0/key-managers").remove_member @security_admin
50
- admin_api = nil
51
- namespace = nil
52
- end
53
- tempfiles.each { |tempfile| File.unlink(tempfile) unless tempfile.nil? }
54
- end
55
-
56
- require 'ostruct'
57
-
58
- class MockAPI
59
- attr_reader :things
60
-
61
- def initialize
62
- @things = {}
63
- end
64
-
65
- def thing(kind, id)
66
- (@things[kind.to_sym] || []).find{|r| r.id == id}
67
- end
68
-
69
- def thing_like(kind, id_pattern)
70
- (@things[kind.to_sym] || []).find{|r| id_pattern.match(r.id)}
71
- end
72
-
73
- def create_host(options = {})
74
- id = options.delete(:id)
75
- if id
76
- host = thing(:host, id)
77
- else
78
- id = SecureRandom.uuid
79
- end
80
- host ||= create_thing(:host, id, options, role: true, api_key: true)
81
- end
82
-
83
- def create_user(id, options = {})
84
- thing(:user, id) || create_thing(:user, id, options, role: true, api_key: true)
85
- end
86
-
87
- def create_variable(mime_type, kind)
88
- create_thing(:user, SecureRandom.uuid, mime_type: mime_type, kind: kind)
89
- end
90
-
91
- def create_resource(id, options = {})
92
- resource(id).tap do |resource|
93
- resource.send(:"exists?=", true)
94
- populate_options resource, options
95
- end
96
- end
97
-
98
- def create_role(id, options = {})
99
- role(id).tap do |role|
100
- role.send(:"exists?=", true)
101
- populate_options role, options
102
- end
103
- end
104
-
105
- [ :user, :host ].each do |kind|
106
- define_method kind do |id|
107
- thing(kind, id)
108
- end
109
- end
110
-
111
- def role(id)
112
- raise "Role id must be a string" unless id.is_a?(String)
113
- thing(:role, id) || create_thing(:role, id, { exists?: false }, role: true)
114
- end
115
-
116
- def resource(id)
117
- raise "Resource id must be a string" unless id.is_a?(String)
118
- thing(:resource, id) || create_thing(:resource, id, exists?: false)
119
- end
120
-
121
- protected
122
-
123
- def create_thing(kind, id, options, kind_options = {})
124
- thing = OpenStruct.new(kind: kind, id: id, exists?: true)
125
-
126
- class << thing
127
- def permit(privilege, role, options = {})
128
- (self.permissions ||= []) << OpenStruct.new(privilege: privilege, role: role.id, grant_option: !!options[:grant_option])
129
- end
130
- end
131
-
132
- if kind_options[:api_key]
133
- thing.api_key = SecureRandom.uuid
134
- end
135
- if kind_options[:role]
136
- thing.roleid = id
137
- class << thing
138
- def can(privilege, resource, options = {})
139
- resource.permit privilege, self, options
140
- end
141
- end
142
- end
143
-
144
- populate_options(thing, options)
145
-
146
- store_thing kind, thing
147
-
148
- thing
149
- end
150
-
151
- def populate_options(thing, options)
152
- options.each do |k,v|
153
- thing.send("#{k}=", v)
154
- end
155
- end
156
-
157
- def store_thing(kind, thing)
158
- (things[kind] ||= []) << thing
159
- end
160
- end
161
-
162
- Before("@dsl") do
163
- puts "Using MockAPI"
164
- puts "Using account 'cucumber'"
165
-
166
- require 'conjur/api'
167
- require 'conjur/config'
168
- require 'conjur/dsl/runner'
169
-
170
- Conjur.stub(:env).and_return "ci"
171
- Conjur.stub(:stack).and_return "ci"
172
- Conjur.stub(:account).and_return "cucumber"
173
-
174
- Conjur::Core::API.stub(:conjur_account).and_return 'cucumber'
175
- @mock_api ||= MockAPI.new
176
- Conjur::DSL::Runner.any_instance.stub(:api).and_return @mock_api
177
- end
178
-
@@ -1,176 +0,0 @@
1
- require 'aruba/api'
2
- require 'conjur/api'
3
-
4
- module ConjurCLIWorld
5
- include Aruba::Api
6
-
7
- attr_accessor :admin_api, :namespace, :test_user, :headers
8
-
9
- def last_json
10
- process_cmd last_command_started.stdout
11
- end
12
-
13
- def passwords
14
- @passwords ||= {}
15
- end
16
-
17
- def save_password username, password
18
- raise "Password for #{username} not found" if password.blank?
19
- raise "Found existing password for user '#{username}'" if passwords[username]
20
- passwords[username] = password
21
- end
22
-
23
- def find_password username
24
- passwords[username] or raise "No password for user '#{username}'"
25
- end
26
-
27
- def find_or_create_password(username)
28
- unless password = passwords[username]
29
- password = passwords[username] = SecureRandom.hex(12)
30
- end
31
- password
32
- end
33
-
34
- def admin_role
35
- admin_api.current_role.role_id
36
- end
37
-
38
- def random_hex nbytes = 12
39
- @random ||= Random.new
40
- @random.bytes(nbytes).unpack('h*').first
41
- end
42
-
43
- def namespace
44
- @namespace ||= random_hex
45
- end
46
-
47
- # Aruba's method
48
- def run(cmd, *args)
49
- # it's a thunk now so it should be returned. puts can be added back as block if we want to
50
- super process_cmd(cmd), *args
51
- end
52
-
53
- # Substitute the namespace for marker $ns
54
- def sanitize_text string
55
- string = super
56
- string.gsub("$ns", namespace)
57
- end
58
-
59
- def get_process(wanted)
60
- super wanted.gsub("$ns", namespace)
61
- end
62
-
63
- def tempfiles
64
- @tempfiles||=[]
65
- end
66
-
67
- def headers
68
- @headers ||= {}
69
- end
70
-
71
- def add_user_auth_header
72
- return if headers['Authorization']
73
-
74
- token = Conjur::API.authenticate(test_user.login, test_user.api_key)
75
- headers.merge!(
76
- 'Authorization' => %Q{Token token="#{Base64.strict_encode64(token.to_json)}"}
77
- )
78
- end
79
-
80
- protected
81
-
82
- def process_cmd(cmd)
83
- cmd = cmd.dup
84
- cmd.gsub!("$ns", namespace)
85
- cmd.gsub!("$pubkeys_url", Conjur.configuration.pubkeys_url)
86
-
87
- JsonSpec.memory.each do |k,v|
88
- cmd.gsub!("%{#{k}}", v)
89
- end
90
- cmd
91
- end
92
- end
93
-
94
- module ConjurWorld
95
- def last_json
96
- last_stdout
97
- end
98
-
99
- def last_stdout
100
- raise "No commands have been run" unless last_cmd
101
- stdout_from last_cmd
102
- end
103
-
104
- attr_accessor :last_cmd
105
-
106
- def account
107
- Conjur::Core::API.conjur_account
108
- end
109
-
110
- def role_kind
111
- @role_kind ||= "cli-cukes"
112
- end
113
-
114
- def role_id_map
115
- @role_id_map ||= {}
116
- end
117
-
118
- def extract_filtered_graph json
119
- graph = JSON.parse(json.to_s)
120
- case graph
121
- when Hash then filter_hash_graph(graph)
122
- when Array then filter_array_graph(graph)
123
- else raise "WTF: graph was #{graph.class}?"
124
- end
125
- end
126
-
127
- def filter_hash_graph graph
128
- allowed = role_id_map.values
129
- edges = graph['graph']
130
- filtered = edges.select do |edge|
131
- allowed.member?(edge['parent']) and allowed.member?(edge['child'])
132
- end
133
- {'graph' => filtered}
134
- end
135
-
136
- def filter_array_graph graph
137
- allowed = role_id_map.values
138
- graph.select do |edge|
139
- edge.all?{|v| allowed.member?(v)}
140
- end
141
- end
142
-
143
- def graph edges
144
- # generate roles
145
- edges.flatten.uniq.each do |role_id|
146
- role_id_map[role_id] = expanded = expand_role_id(role_id)
147
- run_command "conjur role create '#{expanded}'"
148
- end
149
-
150
- # generate memberships
151
- edges.each do |parent, child|
152
- run_command "conjur role grant_to #{expand_role_id(parent)} #{expand_role_id(child)}"
153
- end
154
- end
155
-
156
- def run_command cmd
157
- step "I successfully run " + '`' + cmd + '`'
158
- end
159
-
160
- def expand_role_id role_id
161
- "#{account}:#{role_kind}:#{prepend_namespace role_id}"
162
- end
163
-
164
- def prepend_namespace id
165
- "#{namespace}-#{id}"
166
- end
167
-
168
- def expand_roles string
169
- role_id_map.each do |role, expanded|
170
- string.gsub! role, expanded
171
- end
172
- string
173
- end
174
- end
175
-
176
- World(ConjurWorld, ConjurCLIWorld)
@@ -1,82 +0,0 @@
1
- Feature: Conjur services support trusted proxies
2
-
3
- As an administrator of the Conjur Appliance, I want to be able to
4
- specify CIDRs for machines that should be regarded as trusted
5
- proxies. IP addresses that match those CIDRs can be regarded as
6
- coming from localhost. Other addresses should not be remapped (even
7
- if those addresses are non-routable), and so will appear in audit
8
- events and be used to validate CIDR restrictions (e.g. on
9
- hostfactory tokens).
10
-
11
- Scenario: authn supports trusted proxies for CIDR restrictions
12
- Given I set the JSON request body to:
13
- """
14
- {
15
- "login": "restricted@$ns",
16
- "password": "restricted",
17
- "ownerid": "cucumber:user:admin@$ns",
18
- "cidr": ["192.168.0.0/24"]
19
- }
20
- """
21
- And I send a POST request to "/api/users"
22
- And the response status should be "201"
23
- Given I send "text/plain" and accept JSON
24
- And I set the request body to "restricted"
25
- When I send a POST request forwarded from "192.168.0.1" to "/api/authn/users/restricted@$ns/authenticate"
26
- Then the response status should be "200"
27
-
28
- Scenario: authz supports trusted proxies
29
- Given I send a PUT request forwarded from "192.168.0.1" to "/api/authz/cucumber/resources/test/$ns/resource?acting_as=$user_role"
30
- And the response status should be "204"
31
- When I successfully run `conjur audit resource test:$ns/resource`
32
- Then the JSON response at "request/ip" should be "192.168.0.1"
33
-
34
- Scenario: core supports trusted proxies
35
- Given I set the JSON request body to:
36
- """
37
- {
38
- "id": "$ns/var",
39
- "kind": "password",
40
- "mime_type": "text/plain"
41
- }
42
- """
43
- And I send a POST request forwarded from "192.168.0.1" to "/api/variables"
44
- And the response status should be "201"
45
- When I successfully run `conjur audit resource variable:$ns/var`
46
- Then the JSON response at "request/ip" should be "192.168.0.1"
47
-
48
- Scenario: expiration supports trusted proxies
49
- Given I successfully run `conjur variable create $ns_expiration_var value`
50
- And I send a GET request forwarded from "192.168.0.1" to "/api/variables/$ns_expiration_var/value"
51
- And the response status should be "200"
52
- When I get the audit event for the resource "cucumber:variable:$ns_expiration_var" with action "check"
53
- Then the audit event should show the request from "192.168.0.1"
54
-
55
- Scenario: host-factory supports trusted proxies when creating hostfactories
56
- Given I successfully run `conjur layer create --as-role $user_role $ns/layer`
57
- When I send a POST request forwarded from "192.168.0.1" to "/api/host_factories" with:
58
- | id | roleid | ownerid | layers[] |
59
- | $ns/hf | $user_role | $user_role | $ns/layer |
60
-
61
- And the response status should be "201"
62
- And I successfully run `conjur audit resource host_factory:$ns/hf`
63
- Then the JSON response at "request/ip" should be "192.168.0.1"
64
-
65
- Scenario: hostfactory supports trusted proxies when creating hosts
66
- Given I successfully run `conjur layer create --as-role $user_role $ns/layer`
67
- And I successfully run `conjur hostfactory create --as-role $user_role --layer $ns/layer $ns/hf`
68
- And I create a hostfactory token for "$ns/hf" with CIDR "192.168.0.0/16"
69
- When I use the hostfactory token from "192.168.0.1" to create host "$ns/host"
70
- And I get the audit event for the resource "cucumber:host:$ns/host" with action "create"
71
- Then the audit event should show the request from "192.168.0.1"
72
-
73
- Scenario: hostfactory supports trusted proxies when validating token CIDR restrictions
74
- Given I successfully run `conjur layer create --as-role $user_role $ns/layer`
75
- And I successfully run `conjur hostfactory create --as-role $user_role --layer $ns/layer $ns/hf`
76
- And I create a hostfactory token for "$ns/hf" with CIDR "192.168.0.0/16"
77
- Then I can use the hostfactory token from "192.168.0.1" to create host "$ns/host1"
78
-
79
- Scenario: pubkeys supports trusted proxies
80
- Given I create a pubkey for "pubkeys_user@$ns" from "192.168.0.1" with "ssh-rsa foobar pubkeys_user@host"
81
- When I get the audit event for the pubkey variable with action "create"
82
- Then the audit event should show the request from "192.168.0.1"