conjur-cli 4.9.3 → 4.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,14 +18,12 @@
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
20
  #
21
- require 'conjur/command'
22
-
23
21
  class Conjur::Command::Field < Conjur::Command
24
22
  self.prefix = :field
25
23
 
26
24
  desc "(Deprecated. See standalone jsonfield command instead.)"
27
25
  command :select do |c|
28
- def c.nodoc; true end
26
+ hide_docs(c)
29
27
 
30
28
  c.action do |global_options,options,args|
31
29
  pattern = require_arg(args, 'pattern')
@@ -18,97 +18,110 @@
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
20
  #
21
- require 'conjur/authn'
22
- require 'conjur/command'
23
21
 
24
22
  class Conjur::Command::Groups < Conjur::Command
25
- self.prefix = :group
26
-
27
- desc "Create a new group"
28
- arg_name "id"
29
- command :create do |c|
30
- acting_as_option(c)
31
-
32
- c.action do |global_options,options,args|
33
- id = require_arg(args, 'id')
34
-
35
- group = api.create_group(id, options)
36
- display(group, options)
23
+ def self.assume_user_kind(role)
24
+ if role.split(':').length == 1
25
+ role = [ "user", role ].join(':')
37
26
  end
27
+ role
38
28
  end
29
+
30
+ desc "Manage groups"
31
+ command :group do |group|
32
+ group.desc "Create a new group"
33
+ group.arg_name "id"
34
+ group.command :create do |c|
35
+ acting_as_option(c)
39
36
 
40
- desc "List groups"
41
- command :list do |c|
42
- command_options_for_list c
43
-
44
- c.action do |global_options, options, args|
45
- command_impl_for_list global_options, options.merge(kind: "group"), args
46
- end
47
- end
37
+ c.action do |global_options,options,args|
38
+ id = require_arg(args, 'id')
48
39
 
49
- desc "Show a group"
50
- arg_name "id"
51
- command :show do |c|
52
- c.action do |global_options,options,args|
53
- id = require_arg(args, 'id')
54
- display(api.group(id), options)
40
+ group = api.create_group(id, options)
41
+ display(group, options)
42
+ end
55
43
  end
56
- end
57
44
 
58
- desc "Lists all direct members of the group. The membership list is not recursively expanded."
59
- arg_name "group"
60
- command "members" do |c|
61
- c.desc "Verbose output"
62
- c.switch [:V,:verbose]
45
+ group.desc "List groups"
46
+ group.command :list do |c|
47
+ command_options_for_list c
63
48
 
64
- c.action do |global_options,options,args|
65
- group = require_arg(args, 'group')
66
-
67
- display_members api.group(group).role.members, options
49
+ c.action do |global_options, options, args|
50
+ command_impl_for_list global_options, options.merge(kind: "group"), args
51
+ end
68
52
  end
69
- end
70
53
 
71
- desc "Add a new group member"
72
- arg_name "group member"
73
- command :"members:add" do |c|
74
- c.desc "Also grant the admin option"
75
- c.switch [:a, :admin]
76
-
77
- # perhaps this belongs to member:remove, but then either
78
- # it would be possible to grant membership with member:revoke,
79
- # or we would need two round-trips to authz
80
- c.desc "Revoke the grant option if it's granted"
81
- c.switch [:r, :'revoke-admin']
82
-
83
- c.action do |global_options,options,args|
84
- group = require_arg(args, 'group')
85
- member = require_arg(args, 'member')
86
-
87
- group = api.group(group)
88
- opts = nil
89
- message = "Membership granted"
90
- if options[:admin] then
91
- opts = { admin_option: true }
92
- message = "Adminship granted"
93
- elsif options[:'revoke-admin'] then
94
- opts = { admin_option: false }
95
- message = "Adminship revoked"
54
+ group.desc "Show a group"
55
+ group.arg_name "id"
56
+ group.command :show do |c|
57
+ c.action do |global_options,options,args|
58
+ id = require_arg(args, 'id')
59
+ display(api.group(id), options)
96
60
  end
97
-
98
- group.add_member member, opts
99
- puts message
100
61
  end
101
- end
102
62
 
103
- desc "Remove a group member"
104
- arg_name "group member"
105
- command :"members:remove" do |c|
106
- c.action do |global_options,options,args|
107
- group = require_arg(args, 'group')
108
- member = require_arg(args, 'member')
109
-
110
- api.group(group).remove_member member
111
- puts "Membership revoked"
63
+ group.desc "Show and manage group members"
64
+ group.command :members do |members|
65
+
66
+ members.desc "Lists all direct members of the group. The membership list is not recursively expanded."
67
+ members.arg_name "group"
68
+ members.command :list do |c|
69
+ c.desc "Verbose output"
70
+ c.switch [:V,:verbose]
71
+ c.action do |global_options,options,args|
72
+ group = require_arg(args, 'group')
73
+ display_members api.group(group).role.members, options
74
+ end
75
+ end
76
+
77
+ members.desc "Add a new group member"
78
+ members.arg_name "group member"
79
+ members.command :add do |c|
80
+ c.desc "Also grant the admin option"
81
+ c.switch [:a, :admin]
82
+
83
+ # perhaps this belongs to member:remove, but then either
84
+ # it would be possible to grant membership with member:revoke,
85
+ # or we would need two round-trips to authz
86
+ c.desc "Revoke the grant option if it's granted"
87
+ c.switch [:r, :'revoke-admin']
88
+
89
+ c.action do |global_options,options,args|
90
+ group = require_arg(args, 'group')
91
+ member = require_arg(args, 'member')
92
+ member = assume_user_kind(member)
93
+
94
+ group = api.group(group)
95
+ opts = nil
96
+ message = "Membership granted"
97
+ if options[:admin] then
98
+ opts = { admin_option: true }
99
+ message = "Adminship granted"
100
+ elsif options[:'revoke-admin'] then
101
+ opts = { admin_option: false }
102
+ message = "Adminship revoked"
103
+ end
104
+
105
+ group.add_member member, opts
106
+ puts message
107
+ end
108
+ end
109
+
110
+ members.desc "Remove a group member"
111
+ members.arg_name "group member"
112
+ members.command :remove do |c|
113
+ c.action do |global_options,options,args|
114
+ group = require_arg(args, 'group')
115
+ member = require_arg(args, 'member')
116
+ member = assume_user_kind(member)
117
+
118
+ api.group(group).remove_member member
119
+ puts "Membership revoked"
120
+ end
121
+ end
122
+
112
123
  end
124
+
113
125
  end
114
- end
126
+ end
127
+
@@ -18,68 +18,68 @@
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
20
  #
21
- require 'conjur/authn'
22
- require 'conjur/command'
23
21
 
24
22
  class Conjur::Command::Hosts < Conjur::Command
25
- self.prefix = :host
23
+ desc "Manage hosts"
24
+ command :host do |hosts|
25
+ hosts.desc "Create a new host"
26
+ hosts.arg_name "id"
27
+ hosts.command :create do |c|
28
+ c.arg_name "password"
29
+ c.flag [:p,:password]
26
30
 
27
- desc "Create a new host"
28
- arg_name "id"
29
- command :create do |c|
30
- c.arg_name "password"
31
- c.flag [:p,:password]
32
-
33
- acting_as_option(c)
31
+ acting_as_option(c)
34
32
 
35
- c.action do |global_options,options,args|
36
- id = args.shift
37
- options[:id] = id if id
33
+ c.action do |global_options,options,args|
34
+ id = args.shift
35
+ options[:id] = id if id
38
36
 
39
- unless id
40
- ActiveSupport::Deprecation.warn "id argument will be required in future releases"
37
+ unless id
38
+ ActiveSupport::Deprecation.warn "id argument will be required in future releases"
39
+ end
40
+
41
+ display api.create_host(options), options
41
42
  end
42
-
43
- display api.create_host(options), options
44
43
  end
45
- end
46
-
47
- desc "Show a host"
48
- arg_name "id"
49
- command :show do |c|
50
- c.action do |global_options,options,args|
51
- id = require_arg(args, 'id')
52
- display(api.host(id), options)
44
+
45
+ hosts.desc "Show a host"
46
+ hosts.arg_name "id"
47
+ hosts.command :show do |c|
48
+ c.action do |global_options,options,args|
49
+ id = require_arg(args, 'id')
50
+ display(api.host(id), options)
51
+ end
53
52
  end
54
- end
55
53
 
56
- desc "List hosts"
57
- command :list do |c|
58
- command_options_for_list c
59
54
 
60
- c.action do |global_options, options, args|
61
- command_impl_for_list global_options, options.merge(kind: "host"), args
55
+
56
+ hosts.desc "List hosts"
57
+ hosts.command :list do |c|
58
+ command_options_for_list c
59
+ c.action do |global_options, options, args|
60
+ command_impl_for_list global_options, options.merge(kind: "host"), args
61
+ end
62
62
  end
63
- end
64
-
65
- desc "List the layers to which the host belongs"
66
- arg_name "id"
67
- command :layers do |c|
68
- c.action do |global_options, options, args|
69
- id = require_arg(args, 'id')
70
- display api.host(id).role.all.select{|r| r.kind == "layer"}.map(&:identifier), options
63
+
64
+ hosts.desc "Enroll a new host into conjur"
65
+ hosts.arg_name "host"
66
+ hosts.command :enroll do |c|
67
+ c.action do |global_options, options, args|
68
+ id = require_arg(args, 'host')
69
+ enrollment_url = api.host(id).enrollment_url
70
+ puts enrollment_url
71
+ $stderr.puts "On the target host, please execute the following command:"
72
+ $stderr.puts "curl -L #{enrollment_url} | bash"
73
+ end
71
74
  end
72
- end
73
-
74
- desc "Enroll a new host into conjur"
75
- arg_name "host"
76
- command :enroll do |c|
77
- c.action do |global_options, options, args|
78
- id = require_arg(args, 'host')
79
- enrollment_url = api.host(id).enrollment_url
80
- puts enrollment_url
81
- $stderr.puts "On the target host, please execute the following command:"
82
- $stderr.puts "curl -L #{enrollment_url} | bash"
75
+
76
+ hosts.desc "List the layers to which the host belongs"
77
+ hosts.arg_name "id"
78
+ hosts.command :layers do |c|
79
+ c.action do |global_options, options, args|
80
+ id = require_arg(args, 'id')
81
+ display api.host(id).role.all.select{|r| r.kind == "layer"}.map(&:identifier), options
82
+ end
83
83
  end
84
84
  end
85
85
  end
@@ -18,16 +18,17 @@
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
20
  #
21
- require 'conjur/command'
22
21
 
23
22
  class Conjur::Command::Id < Conjur::Command
24
- self.prefix = :id
25
-
26
- desc "Creates a new unique id"
27
- command :create do |c|
28
- c.action do |global_options,options,args|
29
- var = api.create_variable("text/plain", "unique-id", {})
30
- puts var.id
23
+ desc "Manage ids"
24
+ command :id do |id|
25
+ id.desc "Creates a new unique id"
26
+ id.command :create do |c|
27
+ c.action do |global_options,options,args|
28
+ var = api.create_variable("text/plain", "unique-id", {})
29
+ puts var.id
30
+ end
31
31
  end
32
+
32
33
  end
33
34
  end
@@ -18,6 +18,7 @@
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
20
  #
21
+ require 'highline'
21
22
  require 'conjur/command'
22
23
  require 'openssl'
23
24
  require 'socket'
@@ -0,0 +1,171 @@
1
+ require 'conjur/command'
2
+
3
+ class Conjur::Command::Layers < Conjur::Command
4
+
5
+
6
+ # Form an account:kind:hostid from the host argument
7
+ # Or interpret a fully-qualified role id
8
+ def self.require_hostid_arg(args)
9
+ hostid = require_arg(args, 'host')
10
+ unless hostid.index(':')
11
+ hostid = [ Conjur::Core::API.conjur_account, 'host', hostid ].join(':')
12
+ end
13
+ hostid
14
+ end
15
+
16
+ def self.interpret_layer_privilege(privilege)
17
+ case privilege
18
+ when 'execute'
19
+ 'use_host'
20
+ when 'update'
21
+ 'admin_host'
22
+ else
23
+ exit_now! "Invalid privilege '#{privilege}'. Acceptable values are : execute, update"
24
+ end
25
+ end
26
+
27
+ def self.parse_layer_permission_args(global_options, options, args)
28
+ id = require_arg(args, "layer")
29
+ role = require_arg(args, "role")
30
+ privilege = require_arg(args, "privilege")
31
+ role_name = interpret_layer_privilege privilege
32
+ [ id, role_name, role ]
33
+ end
34
+
35
+ desc "Operations on layers"
36
+ command :layer do |layer|
37
+
38
+ layer.desc "Create a new layer"
39
+ layer.arg_name "id"
40
+ layer.command :create do |c|
41
+ acting_as_option(c)
42
+
43
+ c.action do |global_options,options,args|
44
+ id = require_arg(args, 'id')
45
+
46
+ layer = api.create_layer(id, options)
47
+ display(layer, options)
48
+ end
49
+ end
50
+
51
+ layer.desc "List layers"
52
+ layer.command :list do |c|
53
+ command_options_for_list c
54
+
55
+ c.action do |global_options, options, args|
56
+ command_impl_for_list global_options, options.merge(kind: "layer"), args
57
+ end
58
+ end
59
+
60
+ layer.desc "Show a layer"
61
+ layer.arg_name "id"
62
+ layer.command :show do |c|
63
+ c.action do |global_options,options,args|
64
+ id = require_arg(args, 'id')
65
+ display(api.layer(id), options)
66
+ end
67
+ end
68
+
69
+ layer.desc "Provision a layer by creating backing resources in an IaaS / PaaS system"
70
+ layer.arg_name "layer"
71
+ layer.command :provision do |c|
72
+ hide_docs(c)
73
+
74
+ c.desc "Provisioner to use (aws)"
75
+ c.arg_name "provisioner"
76
+ c.flag [ :provisioner ]
77
+
78
+ c.desc "Variable holding a credential used to connect to the provisioner"
79
+ c.arg_name "variableid"
80
+ c.flag [ :credential ]
81
+
82
+ c.desc "AWS bucket to contain the bootstrap credentials (will be created if missing)"
83
+ c.arg_name "bucket"
84
+ c.flag [ :bucket ]
85
+
86
+ c.action do |global_options, options, args|
87
+ id = require_arg(args, 'layer')
88
+ provisioner = options[:provisioner] or exit_now!("Missing argument: provisioner")
89
+ credential = options[:credential] or exit_now!("Missing argument: credential")
90
+ bucket = options[:bucket] or exit_now!("Missing argument: bucket")
91
+ raise "Supported provisioners: aws" unless provisioner == "aws"
92
+
93
+ require "conjur/provisioner/layer/aws"
94
+
95
+ layer = api.layer(id)
96
+ class << layer
97
+ include Conjur::Provisioner::Layer::AWS
98
+ end
99
+ layer.aws_bucket_name = bucket
100
+ layer.aws_credentialid = credential
101
+ layer.provision
102
+
103
+ puts "Layer provisioned by #{provisioner}"
104
+ end
105
+ end
106
+
107
+ layer.desc "Operations on hosts"
108
+ layer.command :hosts do |hosts|
109
+ hosts.desc "Permit a privilege on hosts in the layer"
110
+ hosts.long_desc <<-DESC
111
+ Privilege may be : execute, update
112
+ DESC
113
+ hosts.arg_name "layer role privilege"
114
+ hosts.command :permit do |c|
115
+ c.action do |global_options,options,args|
116
+ id, role_name, role = parse_layer_permission_args(global_options, options, args)
117
+ api.layer(id).add_member role_name, role
118
+ puts "Permission granted"
119
+ end
120
+ end
121
+
122
+ hosts.desc "Remove a privilege on hosts in the layer"
123
+ hosts.arg_name "layer role privilege"
124
+ hosts.command :deny do |c|
125
+ c.action do |global_options,options,args|
126
+ id, role_name, role = parse_layer_permission_args(global_options, options, args)
127
+ api.layer(id).remove_member role_name, role
128
+ puts "Permission removed"
129
+ end
130
+ end
131
+
132
+ hosts.desc "List roles that have permission on the hosts"
133
+ hosts.arg_name "layer privilege"
134
+ hosts.command :permitted_roles do |c|
135
+ c.action do |global_options,options,args|
136
+ id = require_arg(args, "layer")
137
+ role_name = interpret_layer_privilege require_arg(args, "privilege")
138
+
139
+ members = api.layer(id).hosts_members(role_name).map(&:member).select do |m|
140
+ m.kind != "@"
141
+ end
142
+ display members.map(&:roleid)
143
+ end
144
+ end
145
+
146
+ hosts.desc "Add a host to an layer"
147
+ hosts.arg_name "layer host"
148
+ hosts.command :add do |c|
149
+ c.action do |global_options, options, args|
150
+ id = require_arg(args, 'layer')
151
+ hostid = require_hostid_arg(args)
152
+
153
+ api.layer(id).add_host hostid
154
+ puts "Host added"
155
+ end
156
+ end
157
+
158
+ hosts.desc "Remove a host from an layer"
159
+ hosts.arg_name "layer host"
160
+ hosts.command :remove do |c|
161
+ c.action do |global_options, options, args|
162
+ id = require_arg(args, 'layer')
163
+ hostid = require_hostid_arg(args)
164
+
165
+ api.layer(id).remove_host hostid
166
+ puts "Host removed"
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end