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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +2 -1
- data/Rakefile +32 -1
- data/bin/_conjur_completions +48 -0
- data/bin/_conjur_completions.yaml +96 -0
- data/conjur.gemspec +2 -2
- data/lib/conjur/authn.rb +14 -4
- data/lib/conjur/cli.rb +54 -18
- data/lib/conjur/command.rb +23 -11
- data/lib/conjur/command/assets.rb +85 -84
- data/lib/conjur/command/audit.rb +25 -26
- data/lib/conjur/command/authn.rb +60 -48
- data/lib/conjur/command/dsl_command.rb +0 -1
- data/lib/conjur/command/env.rb +68 -65
- data/lib/conjur/command/field.rb +1 -3
- data/lib/conjur/command/groups.rb +91 -78
- data/lib/conjur/command/hosts.rb +50 -50
- data/lib/conjur/command/ids.rb +9 -8
- data/lib/conjur/command/init.rb +1 -0
- data/lib/conjur/command/layers.rb +171 -0
- data/lib/conjur/command/policy.rb +27 -26
- data/lib/conjur/command/pubkeys.rb +77 -0
- data/lib/conjur/command/resources.rb +129 -130
- data/lib/conjur/command/roles.rb +97 -69
- data/lib/conjur/command/script.rb +13 -14
- data/lib/conjur/command/secrets.rb +18 -21
- data/lib/conjur/command/users.rb +46 -45
- data/lib/conjur/command/variables.rb +72 -85
- data/lib/conjur/config.rb +3 -0
- data/lib/conjur/dsl/runner.rb +0 -1
- data/lib/conjur/version.rb +1 -1
- data/profile.rb +19 -0
- data/spec/command/authn_spec.rb +37 -1
- data/spec/command/groups_spec.rb +18 -7
- data/spec/command/layers_spec.rb +35 -0
- data/spec/command/pubkeys_spec.rb +75 -0
- data/spec/command/users_spec.rb +25 -0
- metadata +50 -67
@@ -18,23 +18,22 @@
|
|
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/dsl_command'
|
23
21
|
|
24
22
|
class Conjur::Command::Script < Conjur::DSLCommand
|
25
|
-
|
23
|
+
desc "Execute Conjur DSL scripts"
|
24
|
+
command :script do |script|
|
25
|
+
script.desc "Run a Conjur DSL script"
|
26
|
+
script.arg_name "script"
|
27
|
+
script.command :execute do |c|
|
28
|
+
acting_as_option(c)
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
c.flag [:c, :context]
|
35
|
-
|
36
|
-
c.action do |global_options,options,args|
|
37
|
-
run_script args, options
|
30
|
+
c.desc "Load context from this config file, and save it when finished. The file permissions will be 0600 by default."
|
31
|
+
c.arg_name "context"
|
32
|
+
c.flag [:c, :context]
|
33
|
+
|
34
|
+
c.action do |global_options,options,args|
|
35
|
+
run_script args, options
|
36
|
+
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -18,32 +18,29 @@
|
|
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::Secrets < Conjur::Command
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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)
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
display api.create_secret(secret, options), options
|
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
|
37
35
|
end
|
38
|
-
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
37
|
+
secret.desc "Retrieve a secret"
|
38
|
+
secret.arg_name "id"
|
39
|
+
secret.command :value do |c|
|
40
|
+
c.action do |global_options,options,args|
|
41
|
+
id = args.shift or raise "Missing parameter: id"
|
42
|
+
puts api.secret(id).value
|
43
|
+
end
|
47
44
|
end
|
48
45
|
end
|
49
46
|
end
|
data/lib/conjur/command/users.rb
CHANGED
@@ -18,13 +18,9 @@
|
|
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/api/authn'
|
22
|
-
require 'conjur/authn'
|
23
|
-
require 'conjur/command'
|
24
21
|
|
25
22
|
class Conjur::Command::Users < Conjur::Command
|
26
|
-
|
27
|
-
|
23
|
+
|
28
24
|
def self.prompt_for_password
|
29
25
|
# use stderr to allow output redirection, e.g.
|
30
26
|
# conjur user:create -p username > user.json
|
@@ -37,56 +33,61 @@ class Conjur::Command::Users < Conjur::Command
|
|
37
33
|
|
38
34
|
password
|
39
35
|
end
|
40
|
-
|
41
|
-
desc "Create a new user"
|
42
|
-
arg_name "login"
|
43
|
-
command :create do |c|
|
44
|
-
c.desc "Prompt for a password for the user (default: --no-password)"
|
45
|
-
c.switch [:p,:password]
|
46
|
-
|
47
|
-
acting_as_option(c)
|
48
|
-
|
49
|
-
c.action do |global_options,options,args|
|
50
|
-
login = require_arg(args, 'login')
|
51
|
-
|
52
|
-
opts = options.slice(:ownerid)
|
53
36
|
|
54
|
-
|
55
|
-
|
37
|
+
desc "Manage users"
|
38
|
+
command :user do |user|
|
39
|
+
|
40
|
+
user.desc "Create a new user"
|
41
|
+
user.arg_name "login"
|
42
|
+
user.command :create do |c|
|
43
|
+
c.desc "Prompt for a password for the user (default: --no-password)"
|
44
|
+
c.switch [:p,:password]
|
45
|
+
|
46
|
+
acting_as_option(c)
|
47
|
+
|
48
|
+
c.action do |global_options,options,args|
|
49
|
+
login = require_arg(args, 'login')
|
50
|
+
|
51
|
+
opts = options.slice(:ownerid)
|
52
|
+
|
53
|
+
if options[:p]
|
54
|
+
opts[:password] = prompt_for_password
|
55
|
+
end
|
56
|
+
|
57
|
+
display api.create_user(login, opts)
|
56
58
|
end
|
57
|
-
|
58
|
-
display api.create_user(login, opts)
|
59
59
|
end
|
60
|
-
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
user.desc "Show a user"
|
62
|
+
user.arg_name "id"
|
63
|
+
user.command :show do |c|
|
64
|
+
c.action do |global_options,options,args|
|
65
|
+
id = require_arg(args, 'id')
|
66
|
+
display(api.user(id), options)
|
67
|
+
end
|
68
68
|
end
|
69
|
-
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
user.desc "List users"
|
71
|
+
user.command :list do |c|
|
72
|
+
command_options_for_list c
|
74
73
|
|
75
|
-
|
76
|
-
|
74
|
+
c.action do |global_options, options, args|
|
75
|
+
command_impl_for_list global_options, options.merge(kind: "user"), args
|
76
|
+
end
|
77
77
|
end
|
78
|
-
end
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
user.desc "Update the password of the logged-in user"
|
80
|
+
user.command :update_password do |c|
|
81
|
+
c.desc "Password to use, otherwise you will be prompted"
|
82
|
+
c.flag [:p,:password]
|
84
83
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
c.action do |global_options,options,args|
|
85
|
+
username, password = Conjur::Authn.read_credentials
|
86
|
+
new_password = options[:password] || prompt_for_password
|
87
|
+
|
88
|
+
Conjur::API.update_password username, password, new_password
|
89
|
+
end
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
92
93
|
end
|
@@ -17,102 +17,89 @@
|
|
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
|
-
require 'conjur/authn'
|
22
|
-
require 'conjur/command'
|
20
|
+
|
23
21
|
|
24
22
|
class Conjur::Command::Variables < Conjur::Command
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
23
|
+
desc "Manage variables"
|
24
|
+
command :variable do |var|
|
25
|
+
var.desc "Create and store a variable"
|
26
|
+
var.arg_name "id"
|
27
|
+
var.command :create do |c|
|
28
|
+
c.arg_name "mime_type"
|
29
|
+
c.flag [:m, :"mime-type"], default_value: "text/plain"
|
30
|
+
|
31
|
+
c.arg_name "kind"
|
32
|
+
c.flag [:k, :"kind"], default_value: "secret"
|
33
|
+
|
34
|
+
c.arg_name "value"
|
35
|
+
c.desc "Initial value"
|
36
|
+
c.flag [:v, :"value"]
|
37
|
+
|
38
|
+
acting_as_option(c)
|
39
|
+
|
40
|
+
c.action do |global_options,options,args|
|
41
|
+
id = args.shift
|
42
|
+
options[:id] = id if id
|
43
|
+
|
44
|
+
unless id
|
45
|
+
ActiveSupport::Deprecation.warn "id argument will be required in future releases"
|
46
|
+
end
|
47
|
+
|
48
|
+
mime_type = options.delete(:m)
|
49
|
+
kind = options.delete(:k)
|
50
|
+
|
51
|
+
options.delete(:"mime-type")
|
52
|
+
options.delete(:"kind")
|
53
|
+
|
54
|
+
var = api.create_variable(mime_type, kind, options)
|
55
|
+
display(var, options)
|
48
56
|
end
|
49
|
-
|
50
|
-
mime_type = options.delete(:m)
|
51
|
-
kind = options.delete(:k)
|
52
|
-
|
53
|
-
options.delete(:"mime-type")
|
54
|
-
options.delete(:"kind")
|
55
|
-
|
56
|
-
var = api.create_variable(mime_type, kind, options)
|
57
|
-
display(var, options)
|
58
57
|
end
|
59
|
-
end
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
var.desc "Show a variable"
|
60
|
+
var.arg_name "id"
|
61
|
+
var.command :show do |c|
|
62
|
+
c.action do |global_options,options,args|
|
63
|
+
id = require_arg(args, 'id')
|
64
|
+
display(api.variable(id), options)
|
65
|
+
end
|
67
66
|
end
|
68
|
-
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
var.desc "List variables"
|
69
|
+
var.command :list do |c|
|
70
|
+
command_options_for_list c
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "Add a value"
|
80
|
-
arg_name "variable ( value | STDIN )"
|
81
|
-
command :"values:add" do |c|
|
82
|
-
c.action do |global_options,options,args|
|
83
|
-
id = require_arg(args, 'variable')
|
84
|
-
value = args.shift || STDIN.read
|
85
|
-
|
86
|
-
api.variable(id).add_value(value)
|
87
|
-
puts "Value added"
|
72
|
+
c.action do |global_options, options, args|
|
73
|
+
command_impl_for_list global_options, options.merge(kind: "variable"), args
|
74
|
+
end
|
88
75
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
76
|
+
|
77
|
+
var.desc "Access varialbe values"
|
78
|
+
var.command :values do |values|
|
79
|
+
values.desc "Add a value"
|
80
|
+
values.arg_name "variable ( value | STDIN )"
|
81
|
+
values.command :add do |c|
|
82
|
+
c.action do |global_options,options,args|
|
83
|
+
id = require_arg(args, 'variable')
|
84
|
+
value = args.shift || STDIN.read
|
85
|
+
|
86
|
+
api.variable(id).add_value(value)
|
87
|
+
puts "Value added"
|
88
|
+
end
|
89
|
+
end
|
101
90
|
end
|
102
|
-
end
|
103
91
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
puts tempfile
|
92
|
+
var.desc "Get a value"
|
93
|
+
var.arg_name "variable"
|
94
|
+
var.command :value do |c|
|
95
|
+
c.desc "Version number"
|
96
|
+
c.flag [:v, :version]
|
97
|
+
|
98
|
+
c.action do |global_options,options,args|
|
99
|
+
id = require_arg(args, 'variable')
|
100
|
+
$stdout.write api.variable(id).value(options[:version])
|
101
|
+
end
|
115
102
|
end
|
116
|
-
|
103
|
+
|
117
104
|
end
|
118
105
|
end
|
data/lib/conjur/config.rb
CHANGED
@@ -36,6 +36,7 @@ module Conjur
|
|
36
36
|
|
37
37
|
def load(config_files = default_config_files)
|
38
38
|
require 'yaml'
|
39
|
+
require 'conjur/log'
|
39
40
|
config_files.each do |f|
|
40
41
|
if File.file?(f)
|
41
42
|
if Conjur.log
|
@@ -51,6 +52,7 @@ module Conjur
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def apply
|
55
|
+
require 'conjur/configuration'
|
54
56
|
keys = Config.keys.dup
|
55
57
|
keys.delete(:plugins)
|
56
58
|
keys.each do |k|
|
@@ -59,6 +61,7 @@ module Conjur
|
|
59
61
|
end
|
60
62
|
|
61
63
|
if Conjur.log
|
64
|
+
require 'conjur/api'
|
62
65
|
Conjur.log << "Using authn host #{Conjur::Authn::API.host}\n"
|
63
66
|
end
|
64
67
|
if Config[:cert_file]
|
data/lib/conjur/dsl/runner.rb
CHANGED
data/lib/conjur/version.rb
CHANGED
data/profile.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'ruby-prof'
|
3
|
+
|
4
|
+
result = RubyProf.profile do
|
5
|
+
require 'conjur/cli'
|
6
|
+
Conjur::CLI.run(ARGV)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
`mkdir -p #{File.dirname(__FILE__)}/profile`
|
11
|
+
File.open("profile/graph.html", "w") do |io|
|
12
|
+
grapher = RubyProf::GraphHtmlPrinter.new(result)
|
13
|
+
grapher.print(io)
|
14
|
+
end
|
15
|
+
File.open("profile/stack.html", "w") do |io|
|
16
|
+
printer = RubyProf::CallStackPrinter.new(result)
|
17
|
+
printer.print(io)
|
18
|
+
end
|
19
|
+
|
data/spec/command/authn_spec.rb
CHANGED
@@ -2,6 +2,42 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Conjur::Command::Authn do
|
4
4
|
context logged_in: false do
|
5
|
+
context "logging in" do
|
6
|
+
[ "authn:login", "authn login" ].each do |cmd|
|
7
|
+
before do
|
8
|
+
Conjur::Authn.stub(:write_credentials)
|
9
|
+
end
|
10
|
+
describe_command "#{cmd}" do
|
11
|
+
it "prompts for username and password and logs in the user" do
|
12
|
+
Conjur::Authn.should_receive(:ask_for_credentials).with({}).and_return [ "the-user", "the-api-key" ]
|
13
|
+
|
14
|
+
expect { invoke }.to write("Logged in")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
describe_command "#{cmd} -u the-user" do
|
18
|
+
it "prompts for password and logs in the user" do
|
19
|
+
Conjur::Authn.should_receive(:ask_for_credentials).with({username: 'the-user'}).and_return [ "the-user", "the-api-key" ]
|
20
|
+
|
21
|
+
expect { invoke }.to write("Logged in")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe_command "#{cmd} -u the-user -p the-password" do
|
25
|
+
it "logs in the user" do
|
26
|
+
Conjur::Authn.should_receive(:ask_for_credentials).with({username: 'the-user', password: 'the-password'}).and_return [ "the-user", "the-api-key" ]
|
27
|
+
|
28
|
+
expect { invoke }.to write("Logged in")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
describe_command "#{cmd} -p the-password the-user" do
|
32
|
+
it "logs in the user" do
|
33
|
+
Conjur::Authn.should_receive(:ask_for_credentials).with({username: 'the-user', password: 'the-password'}).and_return [ "the-user", "the-api-key" ]
|
34
|
+
|
35
|
+
expect { invoke }.to write("Logged in")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
5
41
|
describe_command 'authn:whoami' do
|
6
42
|
it "errors out" do
|
7
43
|
expect { invoke }.to raise_error(GLI::CustomExit, /not logged in/i)
|
@@ -12,7 +48,7 @@ describe Conjur::Command::Authn do
|
|
12
48
|
context logged_in: true do
|
13
49
|
describe_command 'authn:logout' do
|
14
50
|
it "deletes credentials" do
|
15
|
-
invoke
|
51
|
+
expect { invoke }.to write("Logged out")
|
16
52
|
netrc[authn_host].should_not be
|
17
53
|
end
|
18
54
|
end
|