secret_server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3809021f55ff721ca61d09dda83b42ee40cdd9f3
4
+ data.tar.gz: a1661e11f67f917c2dba75df4b7a298859985cc3
5
+ SHA512:
6
+ metadata.gz: 48eda31f9aa395ce3e6a908b2072f222ab06e20931380dc938c8c5717c6dc65098ae58911ea67f89241d5cf8664dd00bf4ba4376c712a87acbbc5566857ea72e
7
+ data.tar.gz: 27cec9fb35e6f8f0f6e681cedc1d13ae5f7e4b3fa1e65ed8693bcfaa7d18754d4e07a6932560ba2ff0271c6387297c81ec8392e512bb02987f28f4086df82007
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # tss configs
12
+ cache.config
13
+ credentials.config
14
+ endpoint.config
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - 'spec/**/*'
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in secret_server.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Tony Gambone
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,150 @@
1
+ # secret-server-ruby
2
+
3
+ A gem for using Thycotic Secret Server as a vault for storing secrets and consuming them in Ruby programs.
4
+
5
+ Requires Secret Server 10.4 and higher, and an installation of the Secret Server SDK client tool.
6
+
7
+ This gem is unofficial and not supported by Thycotic.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'secret_server'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install secret_server
24
+
25
+ ## Initial Setup
26
+
27
+ Configure the connection to your Secret Server instance:
28
+
29
+ ```ruby
30
+ SecretServer.configure do |config|
31
+ config.path = "#{ENV['HOME']}/sdkclient"
32
+ config.url = 'https://myserver/SecretServer/'
33
+ config.rule = 'MyOnboardingRule'
34
+ config.key = 'MyOnboardingKey'
35
+ end
36
+ ```
37
+
38
+ * `config.path` is the directory containing the SDK client
39
+ * `config.url` is the URL to your Secret Server instance
40
+ * `config.rule` is the name of an onboarding rule you have created (optional)
41
+ * `config.key` is the onboarding key for that rule, if applicable (optional)
42
+
43
+ Alternatively, you can also pull configuration from the current environment:
44
+
45
+ ```ruby
46
+ SecretServer.env_configure
47
+ ```
48
+
49
+ The gem will configure the connection using the variables `SDK_CLIENT_PATH`,
50
+ `SECRET_SERVER_URL`, `SDK_CLIENT_RULE`, and `SDK_CLIENT_KEY`.
51
+
52
+ Initialize the connection to Secret Server:
53
+
54
+ ```ruby
55
+ SecretServer.init!
56
+ ```
57
+
58
+ The initialization step requires write access to the current directory.
59
+
60
+ Once the configuration and initialization are complete, they do not need to be
61
+ run again. Encrypted configuration files created in the current directory will
62
+ be used to establish the connection to Secret Server.
63
+
64
+ ## Usage
65
+
66
+ Fetch a secret by ID:
67
+
68
+ ```ruby
69
+ # retrieve the full representation of a secret
70
+ secret = SecretServer.secret(1)
71
+
72
+ # retrieve only the secret fields
73
+ secret = SecretServer.secret(1, field: :all)
74
+
75
+ # retrieve only a single secret field value by slug
76
+ password = SecretServer.secret(1, field: 'password')
77
+ ```
78
+
79
+ To acquire an API token to make REST calls as the application account user:
80
+
81
+ ```ruby
82
+ token = SecretServer.token
83
+ ```
84
+
85
+ To remove the connection to Secret Server and delete all configuration:
86
+
87
+ ```ruby
88
+ SecretServer.remove!
89
+ ```
90
+
91
+ ## Cache Settings
92
+
93
+ By default, no secret values are stored on the local machine. As such, every call to `SecretServer.secret` will result in a round-trip to the server. If the server is unavailable, the call will fail.
94
+
95
+ To change this behavior, set the cache strategy:
96
+
97
+ ```ruby
98
+ # The default (never cache secrets)
99
+ SecretServer.cache_strategy = SecretServer::SdkClient::StrategyNever
100
+
101
+ # Set the cache age (the maximum time, in minutes, that a cached value will be usable).
102
+ SecretServer.cache_age = 10
103
+
104
+ # Check the server first; if unavailable, use the return the last retrieved
105
+ # value, if present. Use this strategy for improved fault tolerance.
106
+ SecretServer.cache_strategy = SecretServer::SdkClient::StrategyServerThenCache
107
+
108
+ # Check the cache first; if no value is present, retrieve it from the server.
109
+ # Use this strategy for improved performance.
110
+ SecretServer.cache_strategy = SecretServer::SdkClient::StrategyCacheThenServer
111
+
112
+ # Same as the above mode, but allow an expired cached value to be used if the
113
+ # server is unavailable.
114
+ SecretServer.cache_strategy = SecretServer::SdkClient::StrategyCacheThenServerAllowExpired
115
+
116
+ # It is also possible to set the cache strategy and age at the same time:
117
+ SecretServer.cache_strategy = [SecretServer::SdkClient::StrategyServerThenCache, 20]
118
+
119
+ # Clear all cached values immediately
120
+ SecretServer.cache_clear!
121
+ ```
122
+
123
+ ## Development
124
+
125
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
126
+
127
+ To install this gem onto your local machine, run `bundle exec rake install`.
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tonygambone/secret-server-ruby.
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
136
+
137
+ ## TODO
138
+
139
+ * Automated SDK client installation
140
+ * Check if `tss` is a supported version, if it ever supports versioning
141
+ * Integration testing
142
+ * Add links to SDK client documentation where needed
143
+ * Release to GitHub official
144
+ * Release to Rubygems
145
+
146
+ ## `tss` TODO
147
+
148
+ * Report version
149
+ * Clear up cache.config on remove
150
+
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'secret_server'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # Secret Server SDK client integration for Ruby
2
+ module SecretServer
3
+ require_relative 'secret_server/sdk_client'
4
+ require_relative 'secret_server/version'
5
+
6
+ class << self
7
+ attr_reader :client
8
+
9
+ def module_init!
10
+ @client = SdkClient.new
11
+ self
12
+ end
13
+
14
+ def method_missing(m, *params, &block)
15
+ if @client.respond_to?(m)
16
+ @client.send(m, *params, &block)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def respond_to_missing?(m, p = false)
23
+ @client.respond_to?(m, p) || super
24
+ end
25
+ end
26
+ end
27
+
28
+ SecretServer.module_init!
@@ -0,0 +1,14 @@
1
+ Dir[File.dirname(__FILE__) + '/commands/*.rb'].each do |file|
2
+ require file
3
+ end
4
+
5
+ module SecretServer
6
+ # Wrappers for each command provided by the SDK client tool.
7
+ module Commands
8
+ include SecretServer::Commands::Cache
9
+ include SecretServer::Commands::Init
10
+ include SecretServer::Commands::Remove
11
+ include SecretServer::Commands::Secret
12
+ include SecretServer::Commands::Token
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ module SecretServer
2
+ module Commands
3
+ # Command to control caching of Secret values
4
+ module Cache
5
+ # rubocop:disable Naming/ConstantName
6
+ StrategyNever = 0
7
+ StrategyServerThenCache = 1
8
+ StrategyCacheThenServer = 2
9
+ StrategyCacheThenServerAllowExpired = 3
10
+ # rubocop:enable Naming/ConstantName
11
+
12
+ def cache_strategy
13
+ stdout, * = sdkclient_exec('cache', '-c')
14
+ result = /Strategy : (\w+)(?:, Max Age : (\d+) minutes)?/.match(stdout)
15
+ strategy = SecretServer::SdkClient.const_get("Strategy#{result[1]}")
16
+ [strategy, result[2].to_i]
17
+ end
18
+
19
+ def cache_strategy=(value)
20
+ strategy, age = value.is_a?(Array) ? value : [value, nil]
21
+ validate_cache_strategy_args(strategy, age)
22
+ args = ['cache', '-s', strategy.to_s]
23
+ args += ['-a', age.to_s] unless age.nil?
24
+ sdkclient_exec(*args)
25
+ end
26
+
27
+ def cache_age
28
+ cache_strategy[1]
29
+ end
30
+
31
+ def cache_age=(age)
32
+ unless age.is_a?(Integer) && age >= 0
33
+ raise ArgumentError, 'age must be a nonnegative integer'
34
+ end
35
+ sdkclient_exec('cache', '-a', age.to_s)
36
+ end
37
+
38
+ def cache_clear!
39
+ sdkclient_exec('cache', '-b')
40
+ end
41
+
42
+ private
43
+
44
+ def validate_cache_strategy_args(strategy, age)
45
+ unless strategy.is_a? Integer
46
+ raise ArgumentError, 'strategy must be an integer'
47
+ end
48
+ unless (0..3).cover? strategy
49
+ raise ArgumentError, 'strategy must be in the range 0 to 3 inclusive'
50
+ end
51
+ unless age.nil? || age.is_a?(Integer) && age >= 0
52
+ raise ArgumentError, 'age must be a nonnegative integer'
53
+ end
54
+ true
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,14 @@
1
+ module SecretServer
2
+ module Commands
3
+ # Command to initialize a connection to Secret Server
4
+ module Init
5
+ def init!
6
+ raise 'Secret Server URL is not set' unless valid_url?
7
+ args = ['-e', '-u', url]
8
+ args += ['-r', rule] unless rule.nil?
9
+ args += ['-k', key] unless key.nil?
10
+ sdkclient_exec('init', *args)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module SecretServer
2
+ module Commands
3
+ # Command to remove a connection with Secret Server
4
+ module Remove
5
+ def remove!
6
+ sdkclient_exec('remove', '-c')
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ module SecretServer
2
+ module Commands
3
+ # Command to fetch Secret values
4
+ module Secret
5
+ def secret(id, opts = {})
6
+ unless id.is_a?(Integer) && id > 0
7
+ raise ArgumentError, 'id must be a positive integer'
8
+ end
9
+ args = ['-s', id.to_s]
10
+ if opts.key? :field
11
+ args += opts[:field] == :all ? ['-ad'] : ['-f', opts[:field].to_s]
12
+ end
13
+ secret_exec(*args)
14
+ end
15
+
16
+ private
17
+
18
+ def secret_exec(*args)
19
+ stdout, * = sdkclient_exec('secret', *args)
20
+ stdout.chomp!
21
+ begin
22
+ JSON.parse(stdout)
23
+ rescue JSON::ParserError
24
+ stdout
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module SecretServer
2
+ module Commands
3
+ # Command to fetch an API token
4
+ module Token
5
+ def token
6
+ stdout, * = sdkclient_exec('token')
7
+ stdout
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ module SecretServer
2
+ # Helpers for working with the Secret Server configuration
3
+ module Configuration
4
+ attr_accessor :path, :url, :rule, :key
5
+
6
+ def configure
7
+ yield self
8
+ end
9
+
10
+ def env_configure
11
+ configure do |config|
12
+ config.path = ENV['SDK_CLIENT_PATH'] || nil
13
+ config.url = ENV['SECRET_SERVER_URL'] || nil
14
+ config.rule = ENV['SDK_CLIENT_RULE'] || nil
15
+ config.key = ENV['SDK_CLIENT_KEY'] || nil
16
+ end
17
+ end
18
+
19
+ def valid_path?
20
+ File.exist? tss
21
+ end
22
+
23
+ def valid_url?
24
+ !url.nil?
25
+ end
26
+
27
+ def tss
28
+ return @tss if defined? @tss
29
+ @tss = begin
30
+ bin = File.join(path, 'tss.exe')
31
+ bin = File.join(path, 'tss') unless File.exist? bin
32
+ bin
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+ require 'open3'
3
+ require_relative 'configuration'
4
+ require_relative 'commands'
5
+
6
+ module SecretServer
7
+ # Ruby SDK client for Secret Server
8
+ class SdkClient
9
+ include SecretServer::Configuration
10
+ include SecretServer::Commands
11
+
12
+ private
13
+
14
+ def sdkclient_exec(*args)
15
+ raise 'SDK client path is invalid' unless valid_path?
16
+ stdout, stderr, status = Open3.capture3(tss, *args)
17
+ raise stdout unless status.exitstatus.zero?
18
+ [stdout, stderr, status]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SecretServer
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'secret_server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'secret_server'
8
+ spec.version = SecretServer::VERSION
9
+ spec.authors = ['Tony Gambone']
10
+ spec.email = ['tony.gambone@thycotic.com']
11
+
12
+ spec.summary = 'Retrieve secrets from Secret Server in Ruby programs.'
13
+ spec.homepage = 'https://thycotic.com/'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`
17
+ .split("\x0")
18
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.11'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'rubocop', '~> 0.52.1'
27
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secret_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tony Gambone
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.52.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.52.1
69
+ description:
70
+ email:
71
+ - tony.gambone@thycotic.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/secret_server.rb
87
+ - lib/secret_server/commands.rb
88
+ - lib/secret_server/commands/cache.rb
89
+ - lib/secret_server/commands/init.rb
90
+ - lib/secret_server/commands/remove.rb
91
+ - lib/secret_server/commands/secret.rb
92
+ - lib/secret_server/commands/token.rb
93
+ - lib/secret_server/configuration.rb
94
+ - lib/secret_server/sdk_client.rb
95
+ - lib/secret_server/version.rb
96
+ - secret_server.gemspec
97
+ homepage: https://thycotic.com/
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.2.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Retrieve secrets from Secret Server in Ruby programs.
121
+ test_files: []