legion-crypt 1.5.38 → 1.6.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/.github/workflows/ci.yml +30 -3
- data/.rspec +2 -0
- data/AGENTS.md +2 -0
- data/CHANGELOG.md +99 -0
- data/CLAUDE.md +65 -192
- data/CODEOWNERS +4 -4
- data/Gemfile +4 -1
- data/README.md +60 -16
- data/legion-crypt.gemspec +1 -0
- data/lib/legion/crypt/cert_rotation.rb +7 -21
- data/lib/legion/crypt/cluster_secret.rb +3 -14
- data/lib/legion/crypt/ed25519.rb +2 -10
- data/lib/legion/crypt/erasure.rb +3 -13
- data/lib/legion/crypt/jwks_client.rb +4 -4
- data/lib/legion/crypt/lease_manager.rb +5 -831
- data/lib/legion/crypt/mtls.rb +8 -46
- data/lib/legion/crypt/partition_keys.rb +2 -6
- data/lib/legion/crypt/settings.rb +31 -21
- data/lib/legion/crypt/spiffe/svid_rotation.rb +6 -9
- data/lib/legion/crypt/spiffe.rb +14 -39
- data/lib/legion/crypt/vault/auth/jwt.rb +28 -0
- data/lib/legion/crypt/vault/auth/kerberos.rb +60 -0
- data/lib/legion/crypt/vault/auth/ldap.rb +29 -0
- data/lib/legion/crypt/vault/auth.rb +50 -0
- data/lib/legion/crypt/vault/client.rb +362 -0
- data/lib/legion/crypt/vault/cluster.rb +262 -0
- data/lib/legion/crypt/vault/entity.rb +79 -0
- data/lib/legion/crypt/vault/leases.rb +871 -0
- data/lib/legion/crypt/vault/operation.rb +29 -0
- data/lib/legion/crypt/vault/session.rb +405 -0
- data/lib/legion/crypt/vault.rb +21 -31
- data/lib/legion/crypt/version.rb +1 -1
- data/lib/legion/crypt.rb +152 -177
- metadata +27 -11
- data/lib/legion/crypt/kerberos_auth.rb +0 -119
- data/lib/legion/crypt/ldap_auth.rb +0 -48
- data/lib/legion/crypt/token_renewer.rb +0 -318
- data/lib/legion/crypt/vault_client.rb +0 -355
- data/lib/legion/crypt/vault_cluster.rb +0 -331
- data/lib/legion/crypt/vault_entity.rb +0 -78
- data/lib/legion/crypt/vault_jwt_auth.rb +0 -97
- data/lib/legion/crypt/vault_kerberos_auth.rb +0 -51
- data/lib/legion/crypt/vault_operation.rb +0 -27
- /data/lib/legion/crypt/{vault_renewer.rb → vault/renewer.rb} +0 -0
data/README.md
CHANGED
|
@@ -26,6 +26,10 @@ Legion::Crypt.decrypt(encrypted[:enciphered_message], encrypted[:iv])
|
|
|
26
26
|
|
|
27
27
|
Authenticated ciphertext requires a full 16-byte GCM tag. Saved RSA private keys are created with `0600` permissions; existing files are restricted before writing.
|
|
28
28
|
|
|
29
|
+
`Legion::Crypt.start(mode: nil, **)` accepts extra keyword context. With `mode: :infra`, an existing PostgreSQL lease uses `postgresql/creds/infra` without mutating its configured path; other modes preserve the configured path. The mode-to-role mapping is a fixed framework convention, not an operator setting.
|
|
30
|
+
|
|
31
|
+
Vault connectivity inspection propagates errors rather than reporting broken configuration as disconnected. Startup orchestration and bootstrap credential handling recover only from their declared operational failures, using `handle_exception` at warning level; programming errors propagate to callers.
|
|
32
|
+
|
|
29
33
|
### Cluster secret readiness
|
|
30
34
|
|
|
31
35
|
Discovery checks settings, Vault, and then peers. Random generation requires confirmed empty-cluster membership, the lite transport adapter, or standalone operation (no transport loaded or transport explicitly disabled). Disconnected or unknown cluster membership does not authorize a competing key.
|
|
@@ -72,10 +76,16 @@ Public keys are cached for 1 hour. Concurrent misses for one URL share a refresh
|
|
|
72
76
|
|
|
73
77
|
## Configuration
|
|
74
78
|
|
|
79
|
+
Crypt requires `legion-settings` >= 1.4.2. Requiring `legion/crypt` registers its defaults once; runtime reads use the live `Legion::Settings[:crypt]` tree, including replacement trees and request overlays. The partial configuration example below shows the `crypt` section; `lib/legion/crypt/settings.rb` is the authoritative source for all defaults. Configure it through `Legion::Settings`, not the removed `Legion::Crypt.settings`, `.vault_settings`, or `.jwt_settings` accessors. `VAULT_DEV_ROOT_TOKEN_ID` and `VAULT_TOKEN_ID` provide boot defaults; they do not overwrite an explicit live Vault token.
|
|
80
|
+
|
|
81
|
+
`crypt.mtls` owns the mTLS defaults registered by this gem. Certificate issuance reads `Legion::Settings[:crypt][:mtls][:vault_pki_path]` directly; the `Legion::Crypt::Mtls.pki_path` accessor is removed. `security.spiffe` remains Core-owned optional configuration with its existing absent-field defaults. Explicit false policy is never replaced by a truthy fallback. Renewal windows must be finite numbers from zero (inclusive) to one (exclusive).
|
|
82
|
+
|
|
83
|
+
After an explicit full `Legion::Settings.reset!`, standalone callers and tests must bootstrap again with `Legion::Settings.register_library(:crypt, Legion::Crypt::Settings.default)` before using configured crypto APIs. Runtime reads do not repair missing registration. Lease binding transactions and credential publication continue to mutate their intended raw settings roots, not request-overlay copies.
|
|
84
|
+
|
|
75
85
|
```json
|
|
76
86
|
{
|
|
77
87
|
"vault": {
|
|
78
|
-
"enabled":
|
|
88
|
+
"enabled": true,
|
|
79
89
|
"protocol": "http",
|
|
80
90
|
"address": "localhost",
|
|
81
91
|
"port": 8200,
|
|
@@ -84,8 +94,8 @@ Public keys are cached for 1 hour. Concurrent misses for one URL share a refresh
|
|
|
84
94
|
"renewer_time": 5,
|
|
85
95
|
"renewer": true,
|
|
86
96
|
"operation_timeout": 5,
|
|
87
|
-
"push_cluster_secret":
|
|
88
|
-
"read_cluster_secret":
|
|
97
|
+
"push_cluster_secret": false,
|
|
98
|
+
"read_cluster_secret": false,
|
|
89
99
|
"kv_path": "legion",
|
|
90
100
|
"leases": {}
|
|
91
101
|
},
|
|
@@ -97,6 +107,12 @@ Public keys are cached for 1 hour. Concurrent misses for one URL share a refresh
|
|
|
97
107
|
"verify_expiration": true,
|
|
98
108
|
"verify_issuer": true
|
|
99
109
|
},
|
|
110
|
+
"mtls": {
|
|
111
|
+
"enabled": false,
|
|
112
|
+
"vault_pki_path": "pki/issue/legion-internal",
|
|
113
|
+
"cert_ttl": "24h",
|
|
114
|
+
"renewal_window": 0.5
|
|
115
|
+
},
|
|
100
116
|
"cs_encrypt_ready": false,
|
|
101
117
|
"dynamic_keys": true,
|
|
102
118
|
"cluster_secret": null,
|
|
@@ -114,9 +130,9 @@ Public keys are cached for 1 hour. Concurrent misses for one URL share a refresh
|
|
|
114
130
|
|
|
115
131
|
### Vault Integration
|
|
116
132
|
|
|
117
|
-
When `vault.token` is set (or via `VAULT_TOKEN_ID` env var), Crypt connects to Vault on `start`. Vault requests use the core-owned `Legion::Crypt::
|
|
133
|
+
When `vault.token` is set (or via `VAULT_TOKEN_ID` env var), Crypt connects to Vault on `start`. Vault requests use the core-owned `Legion::Crypt::Vault::Client`, built on Faraday and `Legion::JSON`; neither vault-ruby nor a LEX extension is required. Responses have symbol keys, including with JSON 3.
|
|
118
134
|
|
|
119
|
-
`Legion::Crypt.vault_client` returns the cached default client; pass a cluster name for an explicit client. Its logical, KV, and lease endpoints use keyword arguments and ignore extra keywords while still enforcing required arguments
|
|
135
|
+
`Legion::Crypt.vault_client` returns the cached default client; pass a cluster name for an explicit client. Its logical, KV, and lease endpoints use keyword arguments and ignore extra keywords while still enforcing required arguments:
|
|
120
136
|
|
|
121
137
|
```ruby
|
|
122
138
|
client = Legion::Crypt.vault_client
|
|
@@ -143,15 +159,17 @@ The `LeaseManager` handles dynamic secrets from any Vault secrets engine (databa
|
|
|
143
159
|
"crypt": {
|
|
144
160
|
"vault": {
|
|
145
161
|
"leases": {
|
|
146
|
-
"rabbitmq":
|
|
147
|
-
"bedrock":
|
|
148
|
-
"
|
|
162
|
+
"rabbitmq": { "path": "rabbitmq/creds/legion-role" },
|
|
163
|
+
"bedrock": { "path": "aws/creds/bedrock-role" },
|
|
164
|
+
"postgresql": { "path": "postgresql/creds/node" }
|
|
149
165
|
}
|
|
150
166
|
}
|
|
151
167
|
}
|
|
152
168
|
}
|
|
153
169
|
```
|
|
154
170
|
|
|
171
|
+
`postgresql` is the lease name recognized by `Legion::Crypt.start(mode: :infra)` for role selection. Other lease names retain their configured paths.
|
|
172
|
+
|
|
155
173
|
Other settings files reference lease data using `lease://name#key`:
|
|
156
174
|
|
|
157
175
|
```json
|
|
@@ -193,7 +211,7 @@ Release Crypt before Settings. Older `register_ref` callers remain supported, bu
|
|
|
193
211
|
|
|
194
212
|
## Multi-Cluster Vault
|
|
195
213
|
|
|
196
|
-
`
|
|
214
|
+
`Legion::Crypt::Vault::Cluster` supports connecting to multiple Vault clusters simultaneously. Each cluster has its own `Legion::Crypt::Vault::Client` instance.
|
|
197
215
|
|
|
198
216
|
Clients are reused only while their endpoint, namespace, TLS verification, and token match the current configuration. Connection changes replace the cached client without disabling lease or token owners retaining its predecessor. Displaced clients are weakly tracked, so the cache does not keep unused clients alive; shutdown permanently closes all surviving clients after owner cleanup. In-place authentication token refreshes preserve the current client.
|
|
199
217
|
|
|
@@ -245,8 +263,7 @@ JWT and Kerberos `login!` use the same grant lifecycle: token, TTL, expiry, rene
|
|
|
245
263
|
|
|
246
264
|
When `crypt.vault.auth_method` is set to `kerberos`, `Crypt.start` performs Kerberos auto-auth to Vault using `KerberosAuth`:
|
|
247
265
|
|
|
248
|
-
```
|
|
249
|
-
# Settings
|
|
266
|
+
```json
|
|
250
267
|
{
|
|
251
268
|
"crypt": {
|
|
252
269
|
"vault": {
|
|
@@ -262,29 +279,56 @@ When `crypt.vault.auth_method` is set to `kerberos`, `Crypt.start` performs Kerb
|
|
|
262
279
|
|
|
263
280
|
The SPNEGO token is sent as an HTTP `Authorization` header (not JSON body). Kerberos auth uses the configured namespace, where the auth mount resides; configure the cluster with `"namespace": null` for a root-mounted auth method. The client namespace is not cleared or temporarily changed during authentication. Requires Homebrew MIT Kerberos (`brew install krb5`) on macOS — the system Heimdal library is not compatible.
|
|
264
281
|
|
|
265
|
-
`TokenRenewer`
|
|
282
|
+
`Legion::Crypt::TokenRenewer` renews renewable tokens at 75% TTL and retries transient failures with backoff. Only Kerberos-authenticated grants can reauthenticate through Kerberos. JWT and LDAP grants require another login after expiry or terminal rejection.
|
|
266
283
|
|
|
267
284
|
## SPIFFE Workload API
|
|
268
285
|
|
|
269
286
|
The local Unix-socket Workload API exchange has a shared 10-second monotonic deadline. Connection, HTTP/2 handshake, request writes, and flushes additionally share a 5-second setup budget; response reads use the remaining operation time. Availability probes are bounded to 5 seconds, and failed exchanges close acquired sockets.
|
|
270
287
|
|
|
271
|
-
Responses may split the gRPC prefix or body across HTTP/2 DATA frames and socket reads. JWT-SVID audiences use protobuf varint lengths, including audiences of 128 bytes or longer. X.509 fallback remains opt-in; JWT-SVID failures raise `Spiffe::SvidError`.
|
|
288
|
+
Responses may split the gRPC prefix or body across HTTP/2 DATA frames and socket reads. JWT-SVID audiences use protobuf varint lengths, including audiences of 128 bytes or longer. X.509 fallback remains opt-in; JWT-SVID failures raise `Legion::Crypt::Spiffe::SvidError`.
|
|
272
289
|
|
|
273
290
|
## mTLS
|
|
274
291
|
|
|
275
|
-
`Crypt::Mtls` issues mTLS certificates from Vault PKI
|
|
292
|
+
`Legion::Crypt::Mtls` issues mTLS certificates from Vault PKI using `crypt.mtls` configuration. `issue_cert(common_name:, alt_names: '', ttl: nil, **)` preserves caller-supplied SANs and TTL overrides while accepting extra keyword context. `Legion::Crypt::CertRotation` renews at expiry minus the certificate lifetime multiplied by `crypt.mtls.renewal_window` (default `0.5`), rather than waiting for a fixed polling interval. Initial issuance and renewal failures retry with exponential backoff from 1 to 60 seconds; a failed renewal retains the last installed certificate. Shutdown interrupts scheduled waits, bounds in-flight issuance with the Vault operation timeout, and prevents late results from replacing the certificate.
|
|
276
293
|
|
|
277
|
-
`Transport::Connection::Vault` independently acquires and applies tempfile-based Bunny mTLS credentials. Certificate rotation does not itself close transport connections when a certificate expires. mTLS is disabled by default.
|
|
294
|
+
`Legion::Transport::Connection::Vault` independently acquires and applies tempfile-based Bunny mTLS credentials. Certificate rotation does not itself close transport connections when a certificate expires. mTLS is disabled by default.
|
|
278
295
|
|
|
279
296
|
## Requirements
|
|
280
297
|
|
|
281
298
|
- Ruby >= 3.4
|
|
299
|
+
- `concurrent-ruby` (~> 1.3)
|
|
282
300
|
- `ed25519` (~> 1.3)
|
|
283
301
|
- `jwt` gem (>= 2.7)
|
|
284
302
|
- `faraday` gem (~> 2.0)
|
|
285
303
|
- `legion-json` gem (>= 1.2.0; JSON 3 supported)
|
|
304
|
+
- `legion-logging` (>= 1.5.0)
|
|
305
|
+
- `legion-settings` (>= 1.4.2)
|
|
286
306
|
- HashiCorp Vault (optional, for secrets management)
|
|
287
|
-
- `
|
|
307
|
+
- `lex-kerberos` (optional, supplies the SPNEGO helper for Kerberos auth)
|
|
308
|
+
|
|
309
|
+
## Development
|
|
310
|
+
|
|
311
|
+
Use the existing checkout and the full repository checks:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
bundle install
|
|
315
|
+
bundle exec rubocop -A
|
|
316
|
+
bundle exec rspec --format json --out tmp/rspec_results.json --format progress --out tmp/rspec_progress.txt
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Run specs against the corrected code if RuboCop changes files. On failure, inspect the failing examples in `tmp/rspec_results.json`; do not substitute a narrower suite for the full check.
|
|
320
|
+
|
|
321
|
+
Specs mirror implementation paths and filenames exactly: `lib/legion/crypt/vault/client.rb` is covered by `spec/legion/crypt/vault/client.rb`, without an `_spec` suffix. Keep each spec focused on its corresponding implementation; startup, JWT convenience, and credential-scoping groups belong in `spec/legion/crypt.rb`.
|
|
322
|
+
|
|
323
|
+
`.rspec` explicitly loads `spec/spec_helper.rb` and discovers `spec/legion/**/*.rb`. The helper puts `lib/` ahead of `spec/` on Ruby's load path so production requires cannot resolve to mirrored spec files. Keep support files outside the discovered implementation-spec tree.
|
|
324
|
+
|
|
325
|
+
Require and use real gemspec dependencies rather than mocking them. `spec/spec_helper.rb` requires `legion-settings` and its resolver, isolates the settings root, and installs complete Crypt defaults for each example. The original settings state is restored afterward, including when an example replaces the loader root.
|
|
326
|
+
|
|
327
|
+
The test bundle also declares `legionio` for the legacy `Vault::Renewer` specs. Isolated Ruby subprocesses exercise the real periodic actor, cancellation lifecycle, and Vault HTTP client against a local service fixture without loading optional Core/transport components into unrelated examples. This is a development/test dependency only; Crypt's runtime gemspec does not depend on Core, and no running Vault service is required.
|
|
328
|
+
|
|
329
|
+
Set individual properties through `Legion::Settings[:crypt][...]`. For replacement-tree scenarios, start from `Legion::Crypt::Settings.default`, modify the needed nested properties, then install it with `Legion::Settings.set_prop(:crypt, configuration)`. Do not replace nested defaults with partial hashes, or stub Settings, its loader, resolver, or returned settings hashes. Keep settings changes within the example lifecycle.
|
|
330
|
+
|
|
331
|
+
Use real libraries with local service fixtures or supported test adapters for external I/O. Preserve security-sensitive behavior: test failure propagation and lifecycle transitions, never expose secrets in test output.
|
|
288
332
|
|
|
289
333
|
## License
|
|
290
334
|
|
data/legion-crypt.gemspec
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'legion/logging/helper'
|
|
4
|
-
require 'legion/crypt/
|
|
4
|
+
require 'legion/crypt/vault/operation'
|
|
5
5
|
|
|
6
6
|
module Legion
|
|
7
7
|
module Crypt
|
|
@@ -53,8 +53,8 @@ module Legion
|
|
|
53
53
|
@wake.broadcast
|
|
54
54
|
@thread
|
|
55
55
|
end
|
|
56
|
-
deadline ||= ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) + Legion::Crypt::
|
|
57
|
-
Legion::Crypt::
|
|
56
|
+
deadline ||= ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) + Legion::Crypt::Vault::Operation::SHUTDOWN_TIMEOUT
|
|
57
|
+
Legion::Crypt::Vault::Operation.with_timeout(deadline: deadline) { thread.join } if thread && thread != Thread.current
|
|
58
58
|
@mutex.synchronize { @thread = nil if @thread.equal?(thread) && !thread&.alive? }
|
|
59
59
|
log.info('[mTLS] CertRotation stopped')
|
|
60
60
|
rescue StandardError => e
|
|
@@ -67,7 +67,7 @@ module Legion
|
|
|
67
67
|
|
|
68
68
|
def rotate!(generation: nil)
|
|
69
69
|
generation ||= @mutex.synchronize { @generation }
|
|
70
|
-
new_cert = Legion::Crypt::
|
|
70
|
+
new_cert = Legion::Crypt::Vault::Operation.with_timeout { Legion::Crypt::Mtls.issue_cert(common_name: node_common_name) }
|
|
71
71
|
issued_at = Time.now
|
|
72
72
|
raise 'Vault PKI returned an expired certificate' unless new_cert[:expiry] > issued_at
|
|
73
73
|
|
|
@@ -133,31 +133,17 @@ module Legion
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
def renewal_window
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
security = Legion::Settings[:security]
|
|
139
|
-
return 0.5 if security.nil?
|
|
140
|
-
|
|
141
|
-
mtls = security[:mtls] || security['mtls'] || {}
|
|
142
|
-
window = mtls[:renewal_window] || mtls['renewal_window'] || 0.5
|
|
136
|
+
window = Legion::Settings[:crypt][:mtls][:renewal_window]
|
|
143
137
|
unless window.is_a?(Numeric) && window.finite? && window >= 0 && window < 1
|
|
144
138
|
raise ArgumentError, 'Certificate renewal window must be finite and between zero and one (exclusive)'
|
|
145
139
|
end
|
|
146
140
|
|
|
147
141
|
window
|
|
148
|
-
rescue StandardError => e
|
|
149
|
-
handle_exception(e, level: :debug, operation: 'crypt.cert_rotation.renewal_window')
|
|
150
|
-
0.5
|
|
151
142
|
end
|
|
152
143
|
|
|
153
144
|
def node_common_name
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
name = Legion::Settings[:client]&.dig(:name) || Legion::Settings[:client]&.dig('name')
|
|
157
|
-
name || 'legion.internal'
|
|
158
|
-
rescue StandardError => e
|
|
159
|
-
handle_exception(e, level: :debug, operation: 'crypt.cert_rotation.node_common_name')
|
|
160
|
-
'legion.internal'
|
|
145
|
+
name = Legion::Settings.dig(:client, :name)
|
|
146
|
+
name.nil? ? 'legion.internal' : name
|
|
161
147
|
end
|
|
162
148
|
|
|
163
149
|
def emit_rotated_event(cert)
|
|
@@ -97,17 +97,6 @@ module Legion
|
|
|
97
97
|
nil
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
def force_cluster_secret
|
|
101
|
-
Legion::Settings[:crypt].fetch(:force_cluster_secret, false)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def settings_push_vault
|
|
105
|
-
vault_settings = Legion::Settings[:crypt][:vault]
|
|
106
|
-
return vault_settings[:push_cluster_secret] unless vault_settings[:push_cluster_secret].nil?
|
|
107
|
-
|
|
108
|
-
vault_settings.fetch(:push_cs_to_vault, false)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
100
|
def only_member?
|
|
112
101
|
return true if defined?(Legion::Transport::TYPE) && Legion::Transport::TYPE == 'local'
|
|
113
102
|
|
|
@@ -130,7 +119,7 @@ module Legion
|
|
|
130
119
|
Legion::Settings[:crypt][:cluster_secret] = value.dup.freeze
|
|
131
120
|
@cluster_secret_cache = nil
|
|
132
121
|
Legion::Settings[:crypt][:cs_encrypt_ready] = true
|
|
133
|
-
push_cs_to_vault if push_to_vault &&
|
|
122
|
+
push_cs_to_vault if push_to_vault && Legion::Settings[:crypt][:vault][:push_cluster_secret]
|
|
134
123
|
log.info "Cluster secret loaded into settings push_to_vault=#{push_to_vault}"
|
|
135
124
|
end
|
|
136
125
|
|
|
@@ -145,7 +134,7 @@ module Legion
|
|
|
145
134
|
end
|
|
146
135
|
|
|
147
136
|
def cluster_secret_timeout
|
|
148
|
-
timeout = Legion::Settings[:crypt]
|
|
137
|
+
timeout = Legion::Settings[:crypt][:cluster_secret_timeout]
|
|
149
138
|
unless timeout.is_a?(Numeric) && timeout.finite? && timeout.positive?
|
|
150
139
|
raise InitializationError, 'cluster_secret_timeout must be a finite positive number'
|
|
151
140
|
end
|
|
@@ -154,7 +143,7 @@ module Legion
|
|
|
154
143
|
end
|
|
155
144
|
|
|
156
145
|
def secret_length
|
|
157
|
-
length = Legion::Settings[:crypt][:cluster_length]
|
|
146
|
+
length = Legion::Settings[:crypt][:cluster_length]
|
|
158
147
|
raise InitializationError, 'cluster_length must be a positive integer' unless length.is_a?(Integer) && length.positive?
|
|
159
148
|
|
|
160
149
|
length
|
data/lib/legion/crypt/ed25519.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'ed25519'
|
|
4
4
|
require 'legion/logging/helper'
|
|
5
|
+
require 'legion/crypt/settings'
|
|
5
6
|
|
|
6
7
|
module Legion
|
|
7
8
|
module Crypt
|
|
@@ -83,17 +84,8 @@ module Legion
|
|
|
83
84
|
|
|
84
85
|
private
|
|
85
86
|
|
|
86
|
-
def key_prefix
|
|
87
|
-
begin
|
|
88
|
-
Legion::Settings[:crypt][:ed25519][:vault_key_prefix]
|
|
89
|
-
rescue StandardError => e
|
|
90
|
-
handle_exception(e, level: :debug, operation: 'crypt.ed25519.key_prefix')
|
|
91
|
-
nil
|
|
92
|
-
end || 'keys'
|
|
93
|
-
end
|
|
94
|
-
|
|
95
87
|
def vault_key_path(agent_id)
|
|
96
|
-
normalize_kv_path("#{
|
|
88
|
+
normalize_kv_path("#{Legion::Settings[:crypt][:ed25519][:vault_key_prefix]}/#{agent_id}")
|
|
97
89
|
end
|
|
98
90
|
|
|
99
91
|
def normalize_kv_path(path)
|
data/lib/legion/crypt/erasure.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'legion/logging/helper'
|
|
4
|
+
require 'legion/crypt/settings'
|
|
4
5
|
|
|
5
6
|
module Legion
|
|
6
7
|
module Crypt
|
|
@@ -9,7 +10,7 @@ module Legion
|
|
|
9
10
|
|
|
10
11
|
class << self
|
|
11
12
|
def erase_tenant(tenant_id:)
|
|
12
|
-
key_path = "#{
|
|
13
|
+
key_path = "#{Legion::Settings[:crypt][:partition_keys][:vault_tenant_prefix]}/#{tenant_id}/master_key"
|
|
13
14
|
|
|
14
15
|
log.info "[crypt] Erasing tenant #{tenant_id}"
|
|
15
16
|
result = Legion::Crypt.delete(key_path)
|
|
@@ -25,7 +26,7 @@ module Legion
|
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
def verify_erasure(tenant_id:)
|
|
28
|
-
key_path = "#{
|
|
29
|
+
key_path = "#{Legion::Settings[:crypt][:partition_keys][:vault_tenant_prefix]}/#{tenant_id}/master_key"
|
|
29
30
|
|
|
30
31
|
data = Legion::Crypt.read(key_path, nil)
|
|
31
32
|
erased = data.nil?
|
|
@@ -35,17 +36,6 @@ module Legion
|
|
|
35
36
|
handle_exception(e, level: :warn, operation: 'crypt.erasure.verify_erasure', tenant_id: tenant_id)
|
|
36
37
|
{ erased: false, tenant_id: tenant_id, error: e.message }
|
|
37
38
|
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def tenant_prefix
|
|
42
|
-
begin
|
|
43
|
-
Legion::Settings[:crypt][:partition_keys][:vault_tenant_prefix]
|
|
44
|
-
rescue StandardError => e
|
|
45
|
-
handle_exception(e, level: :debug, operation: 'crypt.erasure.tenant_prefix')
|
|
46
|
-
nil
|
|
47
|
-
end || 'secret/data/legion/tenants'
|
|
48
|
-
end
|
|
49
39
|
end
|
|
50
40
|
end
|
|
51
41
|
end
|
|
@@ -6,6 +6,7 @@ require 'json'
|
|
|
6
6
|
require 'openssl'
|
|
7
7
|
require 'jwt'
|
|
8
8
|
require 'legion/logging/helper'
|
|
9
|
+
require 'legion/crypt/settings'
|
|
9
10
|
require 'concurrent'
|
|
10
11
|
|
|
11
12
|
module Legion
|
|
@@ -172,12 +173,11 @@ module Legion
|
|
|
172
173
|
end
|
|
173
174
|
|
|
174
175
|
def jwks_ssl_verify_mode
|
|
175
|
-
return OpenSSL::SSL::VERIFY_PEER unless defined?(Legion::Settings)
|
|
176
|
-
|
|
177
176
|
verify = Legion::Settings[:crypt][:jwt][:jwks_tls_verify]&.to_s
|
|
178
177
|
verify == 'none' ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
|
|
179
|
-
rescue StandardError
|
|
180
|
-
|
|
178
|
+
rescue StandardError => e
|
|
179
|
+
handle_exception(e, level: :warn, operation: 'crypt.jwks.ssl_verify_mode')
|
|
180
|
+
raise
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
def with_url_lock(jwks_url, &)
|