ironclad 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/ironclad/cli.rb +13 -0
- data/lib/ironclad/diff.rb +34 -0
- data/lib/ironclad/version.rb +1 -1
- data/lib/ironclad.rb +18 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6819fa2b385f31df19c7479d5ed5a0910ec213cc2c45c6ebc295808f66587a19
|
|
4
|
+
data.tar.gz: 99037f4d626d7801aaa355ef8f4d6f528477e50e4790c4c5128242acfe8af5c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a80bfbba051d04f6723269272610643d29c13dfeaeea811105a4083eea24cbd99bd8d0fb4486610b1614b4d0f38c9b9f640c8d9463df6974e7f0edb72fde5ffe
|
|
7
|
+
data.tar.gz: d5a34169bc5fe30a3866427ea8afdcba6691c0ae3996bf199cea3aeeb43c0b85bf3b659d82e44ca9467c7e77711beb8541b190717bae9131f4a487b6fe75ce61
|
data/README.md
CHANGED
|
@@ -11,7 +11,8 @@ Ironclad reads each environment's key (`master.key`, `production.key`) from
|
|
|
11
11
|
Linux kernel keyring — so repeated use doesn't round-trip to 1Password. It
|
|
12
12
|
ships:
|
|
13
13
|
|
|
14
|
-
- a CLI for printing a key
|
|
14
|
+
- a CLI for printing a key, editing credentials, and keeping `git diff`
|
|
15
|
+
readable,
|
|
15
16
|
- a Railtie that loads the current environment's key into `ENV` at boot,
|
|
16
17
|
- Capistrano helpers so deploys need no key file, and
|
|
17
18
|
- an install generator that wires it all into a Rails app.
|
data/lib/ironclad/cli.rb
CHANGED
|
@@ -8,6 +8,7 @@ module Ironclad
|
|
|
8
8
|
#
|
|
9
9
|
# ironclad [env] [--refresh] print the credentials key (default env)
|
|
10
10
|
# ironclad edit [env] edit Rails credentials for env
|
|
11
|
+
# ironclad diff <file> git textconv: decrypt a credentials file
|
|
11
12
|
class CLI
|
|
12
13
|
def self.start(argv)
|
|
13
14
|
new(argv).run
|
|
@@ -22,6 +23,9 @@ module Ironclad
|
|
|
22
23
|
when 'edit'
|
|
23
24
|
@argv.shift
|
|
24
25
|
edit(@argv.shift || 'default')
|
|
26
|
+
when 'diff'
|
|
27
|
+
@argv.shift
|
|
28
|
+
diff(@argv.shift)
|
|
25
29
|
when '-h', '--help', 'help'
|
|
26
30
|
print_help
|
|
27
31
|
else
|
|
@@ -45,12 +49,20 @@ module Ironclad
|
|
|
45
49
|
def edit(env)
|
|
46
50
|
validate_env!(env)
|
|
47
51
|
ENV['RAILS_MASTER_KEY'] = Ironclad.key(env)
|
|
52
|
+
Ironclad.configure_git_diff!
|
|
48
53
|
|
|
49
54
|
args = ['credentials:edit']
|
|
50
55
|
args.push('-e', env) unless env == 'default'
|
|
51
56
|
exec('bin/rails', *args)
|
|
52
57
|
end
|
|
53
58
|
|
|
59
|
+
def diff(path)
|
|
60
|
+
raise Error, 'Usage: ironclad diff <file>' unless path
|
|
61
|
+
|
|
62
|
+
require_relative 'diff'
|
|
63
|
+
Diff.call(path)
|
|
64
|
+
end
|
|
65
|
+
|
|
54
66
|
def validate_env!(env)
|
|
55
67
|
return if Ironclad.config.environments.include?(env)
|
|
56
68
|
|
|
@@ -65,6 +77,7 @@ module Ironclad
|
|
|
65
77
|
Usage:
|
|
66
78
|
ironclad [env] [--refresh] print the credentials key (env: default)
|
|
67
79
|
ironclad edit [env] edit Rails credentials for env
|
|
80
|
+
ironclad diff <file> git textconv: decrypt a credentials file
|
|
68
81
|
ironclad --help show this help
|
|
69
82
|
|
|
70
83
|
--refresh re-reads from the source after a key rotation.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_support'
|
|
4
|
+
require 'active_support/encrypted_file'
|
|
5
|
+
|
|
6
|
+
module Ironclad
|
|
7
|
+
module Diff
|
|
8
|
+
ENV_KEY = 'IRONCLAD_DIFF_KEY'
|
|
9
|
+
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
def call(path, out = $stdout)
|
|
13
|
+
out.write(decrypt(path) || File.read(path))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def decrypt(path)
|
|
17
|
+
key = Ironclad.key(environment_for(path))
|
|
18
|
+
return unless key
|
|
19
|
+
|
|
20
|
+
ENV[ENV_KEY] = key
|
|
21
|
+
ActiveSupport::EncryptedFile.new(
|
|
22
|
+
content_path: path, key_path: File::NULL,
|
|
23
|
+
env_key: ENV_KEY, raise_if_missing_key: true
|
|
24
|
+
).read
|
|
25
|
+
rescue Ironclad::Error, ActiveSupport::MessageEncryptor::InvalidMessage
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def environment_for(path)
|
|
30
|
+
env = File.basename(path).delete_suffix('.yml.enc')
|
|
31
|
+
Ironclad.config.key?(env) ? env : 'default'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/ironclad/version.rb
CHANGED
data/lib/ironclad.rb
CHANGED
|
@@ -12,6 +12,9 @@ require_relative 'ironclad/key_store'
|
|
|
12
12
|
module Ironclad
|
|
13
13
|
class Error < StandardError; end
|
|
14
14
|
|
|
15
|
+
GIT_DIFF_DRIVER = 'rails_credentials'
|
|
16
|
+
DIFF_COMMAND = 'bin/ironclad diff'
|
|
17
|
+
|
|
15
18
|
class << self
|
|
16
19
|
# Path to the project's ironclad.yml. Override before first use if needed.
|
|
17
20
|
attr_writer :config_path
|
|
@@ -38,11 +41,26 @@ module Ironclad
|
|
|
38
41
|
store.key(environment.to_s, refresh: refresh)
|
|
39
42
|
end
|
|
40
43
|
|
|
44
|
+
def configure_git_diff!(command = DIFF_COMMAND)
|
|
45
|
+
return unless enrolled_in_git_diff?
|
|
46
|
+
|
|
47
|
+
system('git', 'config', "diff.#{GIT_DIFF_DRIVER}.textconv", command,
|
|
48
|
+
%i[out err] => File::NULL)
|
|
49
|
+
end
|
|
50
|
+
|
|
41
51
|
# Reset memoized state (mainly for tests).
|
|
42
52
|
def reset!
|
|
43
53
|
@config = nil
|
|
44
54
|
@store = nil
|
|
45
55
|
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def enrolled_in_git_diff?
|
|
60
|
+
attributes = File.join(Dir.pwd, '.gitattributes')
|
|
61
|
+
File.file?(attributes) &&
|
|
62
|
+
File.read(attributes).include?("diff=#{GIT_DIFF_DRIVER}")
|
|
63
|
+
end
|
|
46
64
|
end
|
|
47
65
|
end
|
|
48
66
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ironclad
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jarrett Lusso
|
|
@@ -104,6 +104,7 @@ files:
|
|
|
104
104
|
- lib/ironclad/capistrano.rb
|
|
105
105
|
- lib/ironclad/cli.rb
|
|
106
106
|
- lib/ironclad/config.rb
|
|
107
|
+
- lib/ironclad/diff.rb
|
|
107
108
|
- lib/ironclad/key_store.rb
|
|
108
109
|
- lib/ironclad/railtie.rb
|
|
109
110
|
- lib/ironclad/source.rb
|