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
@@ -31,10 +31,6 @@ for the username. Password can be provided as -p, --password, or the command wil
31
31
  On successful login, the password is exchanged for the API key, which is cached in the operating system user's
32
32
  .netrc file. Subsequent "conjur" commands will authenticate with the cached login name and API key. To switch users,
33
33
  login again using the new user credentials. To erase credentials, use the 'authn logout' command.
34
-
35
- If specified, the CAS server URL should be in the form https://<hostname>/v1.
36
- It should be running the CAS RESTful services at the /v1 path
37
- (or other path as specified by this argument).
38
34
  DESC
39
35
  authn.command :login do |c|
40
36
  c.arg_name 'username'
@@ -43,10 +39,6 @@ It should be running the CAS RESTful services at the /v1 path
43
39
  c.arg_name 'password'
44
40
  c.flag [:p,:password]
45
41
 
46
- c.arg_name 'CAS server'
47
- c.desc 'Specifies a CAS server URL to use for login'
48
- c.flag [:"cas-server"]
49
-
50
42
  c.action do |global_options,options,args|
51
43
  if options[:username].blank? && !args.empty?
52
44
  options[:username] = args.pop
@@ -60,16 +52,32 @@ It should be running the CAS RESTful services at the /v1 path
60
52
 
61
53
  authn.desc "Obtains an authentication token using the current logged-in user"
62
54
  authn.command :authenticate do |c|
63
- c.arg_name 'header'
64
55
  c.desc "Base64 encode the result and format as an HTTP Authorization header"
65
56
  c.switch [:H,:header]
66
57
 
58
+ c.arg_name 'filename'
59
+ c.desc 'Keeps a fresh access token in the indicated file. With this argument, the command runs forever.'
60
+ c.flag [ :f, :filename ]
61
+
67
62
  c.action do |global_options,options,args|
68
- token = Conjur::Authn.authenticate(options)
69
- if options[:header]
70
- puts "Authorization: Token token=\"#{Base64.strict_encode64(token.to_json)}\""
63
+ # Authenticate will try and parse the token file to read the expiration time.
64
+ # It only knows how to do that if the token file contains a JSON access token.
65
+ raise "--header option is not supported with --filename option" if options[:header] && options[:filename]
66
+
67
+ authenticate = lambda {
68
+ Conjur::Authn.authenticate
69
+ }
70
+
71
+ if filename = options[:filename]
72
+ Conjur::Authenticator.run authenticate: authenticate, filename: filename
71
73
  else
72
- display token
74
+ formatter = if options[:header]
75
+ lambda {|token| "Authorization: Token token=\"#{Base64.strict_encode64(JSON.generate token)}\"" }
76
+ else
77
+ lambda {|token| JSON.pretty_generate token }
78
+ end
79
+
80
+ puts formatter.call(authenticate.call)
73
81
  end
74
82
  end
75
83
  end
@@ -88,11 +96,11 @@ It should be running the CAS RESTful services at the /v1 path
88
96
  c.action do
89
97
  begin
90
98
  creds = Conjur::Authn.get_credentials(noask: true)
91
- puts({account: Conjur::Core::API.conjur_account, username: creds[0]}.to_json)
99
+ puts({account: Conjur.configuration.account, username: creds[0]}.to_json)
92
100
  rescue Conjur::Authn::NoCredentialsError
93
101
  exit_now! 'Not logged in.', -1
94
102
  end
95
103
  end
96
104
  end
97
105
  end
98
- end
106
+ end
@@ -23,66 +23,6 @@ class Conjur::Command::HostFactories < Conjur::Command
23
23
  desc "Manage host factories"
24
24
 
25
25
  command :hostfactory do |hf|
26
- hf.desc "Create a new host factory [DEPRECATED]"
27
- hf.arg_name "id"
28
- hf.command :create do |c|
29
- acting_as_option(c)
30
-
31
- c.arg_name "layer"
32
- c.desc "A space-delimited list of layers to which new hosts will belong"
33
- c.flag [:l, :layer]
34
-
35
- c.action do |global_options,options,args|
36
- notify_deprecated
37
-
38
- id = require_arg(args, 'hostfactory')
39
-
40
- unless options[:ownerid]
41
- exit_now! "Use --as-group or --as-role to indicate the host factory role"
42
- end
43
-
44
- owner_role = api.role(options[:ownerid])
45
-
46
- layers = (options[:layer] || "").split(/\s/)
47
- exit_now! "Provide at least one layer" unless layers.count > 0
48
-
49
- unless has_admin?(current_role, owner_role)
50
- exit_now! "#{owner_role.id} must be an admin of role '#{owner_role.roleid}' to create a host factory for it"
51
- end
52
- layers.each do |layerid|
53
- layer = api.layer(layerid)
54
- exit_now! "Layer '#{layerid}' does not exist" unless layer.exists?
55
- unless has_admin?(owner_role, layer.role)
56
- exit_now! "#{owner_role.id} must be an admin of layer '#{layerid}' to create a host factory for it"
57
- end
58
- end
59
-
60
- command_options = options.dup
61
- command_options[:layers] = layers
62
- command_options[:roleid] = options[:ownerid]
63
-
64
- host_factory = api.create_host_factory id, command_options
65
- display host_factory
66
- end
67
- end
68
-
69
- hf.desc "Show a host factory"
70
- hf.arg_name "id"
71
- hf.command :show do |c|
72
- c.action do |global_options,options,args|
73
- id = require_arg(args, 'id')
74
- display(api.host_factory(id), options)
75
- end
76
- end
77
-
78
- hf.desc "List host factories"
79
- hf.command :list do |c|
80
- command_options_for_list c
81
- c.action do |global_options, options, args|
82
- command_impl_for_list global_options, options.merge(kind: "host_factory"), args
83
- end
84
- end
85
-
86
26
  hf.desc "Operations on tokens"
87
27
  hf.long_desc <<-DESC
88
28
  This command creates one or more identical tokens. A token is always created with an
@@ -131,12 +71,10 @@ By default, this command creates one token. Optionally, it can be used to create
131
71
  end
132
72
  expiration = Time.now + duration
133
73
  count = (options[:count] || 1).to_i
134
- command_options = {}
135
74
 
136
75
  cidr = format_cidr(options.delete(:cidr))
137
- command_options[:cidr] = cidr unless cidr.nil?
138
76
 
139
- tokens = api.host_factory(id).create_tokens expiration, count, command_options
77
+ tokens = api.resource(full_resource_id("host_factory:#{id}")).create_tokens expiration, count: count, cidr: cidr
140
78
  display tokens.map(&:to_json)
141
79
  end
142
80
  end
@@ -151,16 +89,6 @@ By default, this command creates one token. Optionally, it can be used to create
151
89
  puts "Token revoked"
152
90
  end
153
91
  end
154
-
155
- tokens.desc "Show a token"
156
- tokens.arg_name "token"
157
- tokens.command :show do |c|
158
- c.action do |global_options,options,args|
159
- token = require_arg(args, 'token')
160
-
161
- display api.show_host_factory_token(token), options
162
- end
163
- end
164
92
  end
165
93
 
166
94
  hf.desc "Operations on hosts"
@@ -171,7 +99,7 @@ By default, this command creates one token. Optionally, it can be used to create
171
99
  c.action do |global_options,options,args|
172
100
  token = require_arg(args, 'token')
173
101
  id = require_arg(args, 'host-id')
174
-
102
+
175
103
  host = Conjur::API.host_factory_create_host token, id, options
176
104
  display host
177
105
  end
@@ -21,83 +21,11 @@
21
21
 
22
22
  class Conjur::Command::Hosts < Conjur::Command
23
23
  def self.host_layer_roles host
24
- host.role.all.select{|r| r.kind == "layer"}
24
+ host.memberships.select{|r| r.kind == "layer"}
25
25
  end
26
26
 
27
27
  desc "Manage hosts"
28
28
  command :host do |hosts|
29
- hosts.desc "Create a new host [DEPRECATED]"
30
- hosts.arg_name "NAME"
31
- hosts.command :create do |c|
32
- c.arg_name "password"
33
- c.flag [:p,:password]
34
-
35
- c.desc "A comma-delimited list of CIDR addresses to restrict host to (optional)"
36
- c.flag [:cidr]
37
-
38
- acting_as_option(c)
39
-
40
- c.action do |global_options,options,args|
41
- notify_deprecated
42
-
43
- id = args.shift
44
-
45
- unless id
46
- ActiveSupport::Deprecation.warn "id argument will be required in future releases"
47
- end
48
-
49
- cidr = format_cidr(options.delete(:cidr))
50
- options[:id] = id if id
51
- options[:cidr] = cidr unless cidr.nil?
52
-
53
- display api.create_host(options), options
54
- end
55
- end
56
-
57
- hosts.desc "Show a host"
58
- hosts.arg_name "HOST"
59
- hosts.command :show do |c|
60
- c.action do |global_options,options,args|
61
- id = require_arg(args, 'HOST')
62
- display(api.host(id), options)
63
- end
64
- end
65
-
66
- hosts.desc "Decommission a host [DEPRECATED]"
67
- hosts.arg_name "HOST"
68
- hosts.command :retire do |c|
69
- retire_options c
70
-
71
- c.action do |global_options,options,args|
72
- notify_deprecated
73
-
74
- id = require_arg(args, 'HOST')
75
-
76
- host = api.host(id)
77
-
78
- validate_retire_privileges host, options
79
-
80
- host_layer_roles(host).each do |layer|
81
- puts "Removing from layer #{layer.id}"
82
- api.layer(layer.id).remove_host host
83
- end
84
-
85
- retire_resource host
86
- retire_role host
87
- give_away_resource host, options
88
-
89
- puts "Host retired"
90
- end
91
- end
92
-
93
- hosts.desc "List hosts"
94
- hosts.command :list do |c|
95
- command_options_for_list c
96
- c.action do |global_options, options, args|
97
- command_impl_for_list global_options, options.merge(kind: "host"), args
98
- end
99
- end
100
-
101
29
  hosts.desc "Rotate a host's API key"
102
30
  hosts.command :rotate_api_key do |c|
103
31
  c.desc "Login of host whose API key we want to rotate (default: logged-in host)"
@@ -105,8 +33,9 @@ class Conjur::Command::Hosts < Conjur::Command
105
33
  c.action do |_global, options, _args|
106
34
  if options.include?(:host)
107
35
  host = options[:host]
36
+ host_resourceid = full_resource_id("host:#{host}")
108
37
 
109
- unless api.host(host).exists?
38
+ unless api.resource(host_resourceid).exists?
110
39
  exit_now! "host '#{host}' not found"
111
40
  end
112
41
 
@@ -117,10 +46,10 @@ class Conjur::Command::Hosts < Conjur::Command
117
46
 
118
47
  # Make sure we're not trying to rotate our own key with the user flag.
119
48
  if api.username == host
120
- exit_now! 'To rotate your own API key, use this command without the --host flag'
49
+ exit_now! 'To rotate the API key of the currently logged-in host, use this command without any flags or options'
121
50
  end
122
51
 
123
- puts api.user(host).rotate_api_key
52
+ puts api.resource(host_resourceid).rotate_api_key
124
53
  else
125
54
  username, password = Conjur::Authn.read_credentials
126
55
  # Make sure the current identity is a host
@@ -136,48 +65,12 @@ class Conjur::Command::Hosts < Conjur::Command
136
65
  end
137
66
  end
138
67
 
139
- hosts.desc "Update a hosts's attributes [DEPRECATED]"
140
- hosts.arg_name "HOST"
141
- hosts.command :update do |c|
142
- c.desc "A comma-delimited list of CIDR addresses to restrict host to (optional). Use 'all' to reset"
143
- c.flag [:cidr]
144
-
145
- c.action do |global_options, options, args|
146
- notify_deprecated
147
-
148
- id = require_arg(args, 'HOST')
149
-
150
- host = api.host(id)
151
-
152
- cidr = format_cidr(options[:cidr])
153
-
154
- host_options = { }
155
- host_options[:cidr] = cidr unless cidr.nil?
156
-
157
- host.update(host_options)
158
- puts "Host updated"
159
- end
160
- end
161
-
162
- hosts.desc "Enroll a new host into conjur [DEPRECATED]"
163
- hosts.arg_name "HOST"
164
- hosts.command :enroll do |c|
165
- hide_docs(c)
166
- c.action do |global_options, options, args|
167
- id = require_arg(args, 'HOST')
168
- enrollment_url = api.host(id).enrollment_url
169
- puts enrollment_url
170
- $stderr.puts "On the target host, please execute the following command:"
171
- $stderr.puts "curl -L #{enrollment_url} | bash"
172
- end
173
- end
174
-
175
68
  hosts.desc "List the layers to which the host belongs"
176
69
  hosts.arg_name "HOST"
177
70
  hosts.command :layers do |c|
178
71
  c.action do |global_options, options, args|
179
72
  id = require_arg(args, 'HOST')
180
- host = api.host(id)
73
+ host = api.resource(full_resource_id("host:#{id}"))
181
74
  display host_layer_roles(host).map(&:identifier), options
182
75
  end
183
76
  end
@@ -38,11 +38,11 @@ class Conjur::Command::Init < Conjur::Command
38
38
  end
39
39
 
40
40
  Conjur::CLI.command :init do |c|
41
- c.desc "Hostname of the Conjur endpoint (required for virtual appliance)"
42
- c.arg_name 'HOSTNAME'
43
- c.flag ["h", "hostname"]
41
+ c.desc "URL of the Conjur service"
42
+ c.arg_name 'URL'
43
+ c.flag ["u", "url"]
44
44
 
45
- c.desc "Conjur organization account name (not required for appliance)"
45
+ c.desc "Conjur organization account name"
46
46
  c.flag ["a", "account"]
47
47
 
48
48
  c.desc "Conjur SSL certificate (will be obtained from host unless provided by this option)"
@@ -56,40 +56,26 @@ class Conjur::Command::Init < Conjur::Command
56
56
  c.flag "force"
57
57
 
58
58
  c.action do |global_options,options,args|
59
- hostname = options[:hostname] || highline.ask("Enter the hostname (and optional port) of your Conjur endpoint: ").to_s
60
- protocol, hostname = (hostname.scan %r(^(?:(.*)://)?(.*))).first
61
- exit_now! "only https protocol supported" unless protocol.nil? || protocol == 'https'
62
- if hostname
63
- Conjur.configuration.core_url = "https://#{hostname}/api"
64
- end
59
+ url = options[:url] || highline.ask("Enter the URL of your Conjur service: ").to_s
60
+ url = URI.parse(url)
65
61
 
66
- if (certificate = options[:certificate]).blank?
67
- unless hostname.blank?
68
- connect_hostname = if hostname.include?(':')
69
- hostname
70
- else
71
- hostname + ':443'
72
- end
73
- fingerprint, certificate = get_certificate connect_hostname
74
-
75
- puts
76
- puts fingerprint
77
-
78
- puts "\nPlease verify this certificate on the appliance using command:
79
- openssl x509 -fingerprint -noout -in ~conjur/etc/ssl/conjur.pem\n\n"
80
- exit_now! "You decided not to trust the certificate" unless highline.ask("Trust this certificate (yes/no): ").strip == "yes"
81
- end
62
+ Conjur.configuration.appliance_url = url.to_s
63
+
64
+ if (certificate = options[:certificate]).blank? && url.scheme == "https"
65
+ connect_hostname = [ url.host, url.port ].join(":")
66
+ fingerprint, certificate = get_certificate connect_hostname
67
+
68
+ puts
69
+ puts fingerprint
70
+
71
+ puts "\nPlease verify this certificate on the appliance using command:
72
+ openssl x509 -fingerprint -noout -in ~conjur/etc/ssl/conjur.pem\n\n"
73
+ exit_now! "You decided not to trust the certificate" unless highline.ask("Trust this certificate (yes/no): ").strip == "yes"
82
74
  end
83
75
 
84
76
  configure_cert_store certificate
85
77
 
86
- account = options[:account]
87
- account ||= if hostname
88
- account = Conjur::Core::API.info['account'] or raise "Expecting 'account' in Core info"
89
- else
90
- # using .to_s to overcome https://github.com/JEG2/highline/issues/69
91
- highline.ask("Enter your organization account name: ").to_s
92
- end
78
+ account = options[:account] || highline.ask("Enter your organization account name: ").to_s
93
79
 
94
80
  exit_now! "account is required" if account.blank?
95
81
 
@@ -98,7 +84,7 @@ class Conjur::Command::Init < Conjur::Command
98
84
  plugins: []
99
85
  }
100
86
 
101
- config[:appliance_url] = "https://#{hostname}/api" unless hostname.blank?
87
+ config[:appliance_url] = url.to_s
102
88
 
103
89
  config_file = File.expand_path('~/.conjurrc')
104
90
 
@@ -140,7 +126,6 @@ class Conjur::Command::Init < Conjur::Command
140
126
 
141
127
  sock = TCPSocket.new host, port.to_i
142
128
  ssock = SSLSocket.new sock
143
- ssock.hostname = host
144
129
  ssock.connect
145
130
  chain = ssock.peer_cert_chain
146
131
  cert = chain.first
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright (C) 2013 Conjur Inc
2
+ # Copyright (C) 2017 Conjur Inc
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
5
  # this software and associated documentation files (the "Software"), to deal in
@@ -17,30 +17,41 @@
17
17
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
-
22
- class Conjur::Command::Secrets < Conjur::Command
23
- desc "Manage secrets"
24
- command :secret do |secret|
25
- hide_docs(secret)
26
- secret.desc "Create and store a secret"
27
- secret.arg_name "secret"
28
- secret.command :create do |c|
29
- acting_as_option(c)
30
20
 
31
- c.action do |global_options,options,args|
32
- secret = args.shift or raise "Missing parameter: secret"
33
- display api.create_secret(secret, options), options
34
- end
35
- end
21
+ class Conjur::Command::Policies < Conjur::Command
22
+ desc "Manage policies"
23
+ command :policy do |p|
24
+ p.desc "Load a policy"
25
+ p.arg_name "POLICY FILENAME"
26
+ p.command :load do |c|
27
+ c.desc "Fully replace the existing policy, deleting any data that is not declared in the new policy."
28
+ c.switch :replace
36
29
 
37
- secret.desc "Retrieve a secret"
38
- secret.arg_name "id"
39
- secret.command :value do |c|
30
+ c.desc "Allow explicit deletion statements in the policy."
31
+ c.switch :delete
32
+
40
33
  c.action do |global_options,options,args|
41
- id = args.shift or raise "Missing parameter: id"
42
- puts api.secret(id).value
34
+ policy_id = require_arg(args, 'POLICY')
35
+ filename = require_arg(args, 'FILENAME')
36
+ policy = if filename == '-'
37
+ STDIN.read
38
+ else
39
+ require 'open-uri'
40
+ open(filename).read
41
+ end
42
+
43
+ method = if options[:replace]
44
+ Conjur::API::POLICY_METHOD_PUT
45
+ elsif options[:delete]
46
+ Conjur::API::POLICY_METHOD_PATCH
47
+ else
48
+ Conjur::API::POLICY_METHOD_POST
49
+ end
50
+
51
+ result = api.load_policy policy_id, policy, method: method
52
+ $stderr.puts "Loaded policy '#{policy_id}'"
53
+ puts JSON.pretty_generate(result)
43
54
  end
44
55
  end
45
56
  end
46
- end
57
+ end