legion-crypt 0.3.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 265bfefa35f6346031ae28749fa479e511e9f98f5a3c8b5cd3b756e86f6920b4
4
- data.tar.gz: 2fedcd11ffcb04683cdf8c122b721bd30e37b7a73b48f2660237895725045999
3
+ metadata.gz: a7018b9c084879712ba6a2fdf0b64f19b1c78de8cb8b9377063f824a0f43314c
4
+ data.tar.gz: 0d449cbe402ffbe5a45256801ea442ac03d7663f234f4678f52147e55214c0c0
5
5
  SHA512:
6
- metadata.gz: 430546afd08fdddbc359be8dd09a530552a596917943ca7e5c0a9bd7a3064e4c95cbb3ea468faaa62cfe6572577eea3eb60765ebbb68f3a8756a0a491de8c44d
7
- data.tar.gz: 856f677b6201f8052cf6d0a617f56ce893029afc02df2f9490e506bc55034090814f35cf0c98438c66db6c0a728be84f060f72c7319bb20bfd29f0cc1debdc24
6
+ metadata.gz: 64e62d71d928dbd378aa7ce371af98b79c0a70cd6724461db87c7753f073014e8d0973975b947c31cdcda34f138f473afcf11d5026ec5332e7b5d619b91e72f8
7
+ data.tar.gz: 42b44f3d2b203db36197dc399732790fe3e6cc6f9f00b9e3c3660fc1283cf6bbd519fbaab718ddaa44a404f5332e3d8f0eb24120d17ac41f2071df637fc61634
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore CHANGED
@@ -1,11 +1,15 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /Gemfile.lock
3
4
  /_yardoc/
4
5
  /coverage/
5
6
  /doc/
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
9
-
10
+ /legion/.idea/
11
+ /.idea/
12
+ *.key
10
13
  # rspec failure tracking
11
14
  .rspec_status
15
+ legionio.key
data/.rubocop.yml CHANGED
@@ -1,24 +1,53 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
1
6
  Layout/LineLength:
2
- Max: 140
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
3
16
  Metrics/MethodLength:
4
17
  Max: 50
18
+
5
19
  Metrics/ClassLength:
6
20
  Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
7
25
  Metrics/BlockLength:
8
- Max: 50
9
- Metrics/CyclomaticComplexity:
10
- Max: 14
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
11
30
  Metrics/AbcSize:
12
- Max: 17
31
+ Max: 60
32
+
33
+ Metrics/CyclomaticComplexity:
34
+ Max: 15
35
+
13
36
  Metrics/PerceivedComplexity:
14
- Max: 16
15
- Naming/MethodParameterName:
16
- Enabled: false
37
+ Max: 17
38
+
17
39
  Style/Documentation:
18
40
  Enabled: false
19
- AllCops:
20
- TargetRubyVersion: 2.5
21
- NewCops: enable
22
- SuggestExtensions: false
41
+
42
+ Style/SymbolArray:
43
+ Enabled: true
44
+
23
45
  Style/FrozenStringLiteralComment:
46
+ Enabled: true
47
+ EnforcedStyle: always
48
+
49
+ Naming/FileName:
50
+ Enabled: false
51
+
52
+ Naming/PredicateMethod:
24
53
  Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Legion::Crypt
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [1.3.0] - 2026-03-16
6
+
7
+ ### Added
8
+ - `LeaseManager` singleton for dynamic Vault secret lease management
9
+ - Named lease definitions in `crypt.vault.leases` settings
10
+ - Boot-time lease fetch with data caching
11
+ - Background renewal thread with rotation detection
12
+ - Settings push-back on credential rotation via reverse index
13
+ - `lease://name#key` URI references resolved by Settings resolver
14
+
15
+ ## v1.2.1
16
+
17
+ ### Fixed
18
+ - `validate_hex` and `set_cluster_secret` now handle leading zeros correctly by padding the
19
+ base-32 round-trip result back to the original string length. Previously, secrets whose
20
+ hex representation started with one or more zero bytes would fail validation and cause
21
+ `find_cluster_secret` to return nil non-deterministically.
22
+
23
+ ### Added
24
+ - Comprehensive spec coverage for `Legion::Crypt::VaultJwtAuth` (`.login`, `.login!`,
25
+ `.worker_login`, `AuthError`, constants).
26
+ - `after` hook in `cluster_secret_spec` to restore `Legion::Settings[:crypt][:cluster_secret]`
27
+ between examples, eliminating ordering-dependent state pollution.
28
+ - TODO comments in `vault_spec` for tests that require live Vault connectivity.
29
+
30
+ ## v1.2.0
31
+ Moving from BitBucket to GitHub. All git history is reset from this point on
data/CLAUDE.md ADDED
@@ -0,0 +1,149 @@
1
+ # legion-crypt: Encryption and Vault Integration for LegionIO
2
+
3
+ **Repository Level 3 Documentation**
4
+ - **Parent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
5
+
6
+ ## Purpose
7
+
8
+ Handles encryption, decryption, secrets management, JWT token management, and HashiCorp Vault connectivity for the LegionIO framework. Provides AES-256-CBC message encryption, RSA key pair generation, cluster secret management, JWT issue/verify operations, and Vault token lifecycle management.
9
+
10
+ **GitHub**: https://github.com/LegionIO/legion-crypt
11
+ **License**: Apache-2.0
12
+
13
+ ## Architecture
14
+
15
+ ```
16
+ Legion::Crypt (singleton module)
17
+ ├── .start # Initialize: generate keys, connect to Vault
18
+ ├── .encrypt(string) # AES-256-CBC encryption
19
+ ├── .decrypt(message) # AES-256-CBC decryption
20
+ ├── .shutdown # Stop Vault renewer, close sessions
21
+
22
+ ├── Cipher # OpenSSL cipher operations (AES-256-CBC)
23
+ │ ├── .encrypt # Encrypt with cluster secret
24
+ │ ├── .decrypt # Decrypt with cluster secret
25
+ │ ├── .private_key # RSA private key (generated or loaded)
26
+ │ └── .public_key # RSA public key
27
+
28
+ ├── Vault # HashiCorp Vault integration
29
+ │ ├── .connect_vault # Establish Vault session
30
+ │ ├── .read(path) # Read secret from Vault
31
+ │ ├── .write(path) # Write secret to Vault
32
+ │ └── .renew_token # Token renewal
33
+
34
+ ├── JWT # JSON Web Token operations
35
+ │ ├── .issue # Create signed JWT (HS256 or RS256)
36
+ │ ├── .verify # Verify and decode JWT
37
+ │ └── .decode # Decode without verification (inspection)
38
+
39
+ ├── ClusterSecret # Cluster-wide shared secret management
40
+ │ └── .cs # Generate/distribute cluster secret
41
+
42
+ ├── VaultJwtAuth # Vault JWT auth backend integration
43
+ │ ├── .login # Authenticate to Vault using a JWT token, returns Vault token hash
44
+ │ ├── .login! # Authenticate and set ::Vault.token for subsequent operations
45
+ │ └── .worker_login # Issue a Legion JWT and authenticate to Vault in one step
46
+
47
+ ├── VaultRenewer # Background Vault token renewal thread
48
+ ├── LeaseManager # Dynamic Vault lease lifecycle: fetch, cache, renew, rotate, push-back
49
+ ├── Settings # Default crypt config
50
+ └── Version
51
+ ```
52
+
53
+ ### Key Design Patterns
54
+
55
+ - **Dynamic Keys**: By default, generates new RSA key pair per process start (no persistent keys)
56
+ - **Cluster Secret**: Shared AES key distributed across Legion nodes for inter-node encrypted communication
57
+ - **Vault Conditional**: Vault module is only included if the `vault` gem is available
58
+ - **Token Lifecycle**: VaultRenewer runs background thread for automatic token renewal
59
+ - **JWT Dual Algorithm**: HS256 (symmetric, cluster secret) for intra-cluster tokens; RS256 (asymmetric, RSA keypair) for tokens verifiable without sharing the signing key
60
+
61
+ ## Default Settings
62
+
63
+ ```json
64
+ {
65
+ "vault": { "..." : "see vault settings" },
66
+ "jwt": {
67
+ "enabled": true,
68
+ "default_algorithm": "HS256",
69
+ "default_ttl": 3600,
70
+ "issuer": "legion",
71
+ "verify_expiration": true,
72
+ "verify_issuer": true
73
+ },
74
+ "cs_encrypt_ready": false,
75
+ "dynamic_keys": true,
76
+ "cluster_secret": null,
77
+ "save_private_key": true,
78
+ "read_private_key": true
79
+ }
80
+ ```
81
+
82
+ ## Dependencies
83
+
84
+ | Gem | Purpose |
85
+ |-----|---------|
86
+ | `jwt` (>= 2.7) | JSON Web Token encoding/decoding |
87
+ | `vault` (>= 0.17) | HashiCorp Vault Ruby client |
88
+
89
+ Dev dependencies: `legion-logging`, `legion-settings`
90
+
91
+ ## File Map
92
+
93
+ | Path | Purpose |
94
+ |------|---------|
95
+ | `lib/legion/crypt.rb` | Module entry, start/shutdown lifecycle |
96
+ | `lib/legion/crypt/cipher.rb` | AES-256-CBC encrypt/decrypt, RSA key generation |
97
+ | `lib/legion/crypt/jwt.rb` | JWT issue/verify/decode operations |
98
+ | `lib/legion/crypt/vault.rb` | Vault read/write/connect/renew operations |
99
+ | `lib/legion/crypt/cluster_secret.rb` | Cluster-wide shared secret management |
100
+ | `lib/legion/crypt/vault_jwt_auth.rb` | Vault JWT auth backend: `.login`, `.login!`, `.worker_login`; raises `AuthError` on failure |
101
+ | `lib/legion/crypt/vault_renewer.rb` | Background Vault token renewal |
102
+ | `lib/legion/crypt/lease_manager.rb` | Dynamic Vault lease lifecycle management |
103
+ | `lib/legion/crypt/settings.rb` | Default configuration |
104
+ | `lib/legion/crypt/version.rb` | VERSION constant |
105
+
106
+ ## Role in LegionIO
107
+
108
+ First service-level module initialized during `Legion::Service` startup (before transport). Provides:
109
+ 1. Vault token for `legion-transport` to fetch RabbitMQ credentials
110
+ 2. Message encryption for `legion-transport` (optional `transport.messages.encrypt`)
111
+ 3. Cluster secret for inter-node encrypted communication
112
+ 4. JWT tokens for node authentication and task authorization
113
+
114
+ ### Vault JWT Auth Usage
115
+
116
+ ```ruby
117
+ # Authenticate to Vault using a JWT (Vault must have JWT auth method enabled)
118
+ result = Legion::Crypt::VaultJwtAuth.login(jwt: token, role: 'legion-worker')
119
+ # => { token: '...', lease_duration: 3600, renewable: true, policies: [...], metadata: {} }
120
+
121
+ # Authenticate and set Vault client token in one step
122
+ Legion::Crypt::VaultJwtAuth.login!(jwt: token)
123
+
124
+ # Issue a Legion JWT and use it to authenticate to Vault (convenience for workers)
125
+ result = Legion::Crypt::VaultJwtAuth.worker_login(worker_id: 'abc', owner_msid: 'user@example.com')
126
+ ```
127
+
128
+ Vault prerequisites: `vault auth enable jwt` + configure `auth/jwt/config` with JWKS URL or bound issuer.
129
+
130
+ ### JWT Usage
131
+
132
+ ```ruby
133
+ # Convenience methods (auto-selects keys from settings)
134
+ token = Legion::Crypt.issue_token({ node_id: 'abc' }, ttl: 3600)
135
+ claims = Legion::Crypt.verify_token(token)
136
+
137
+ # Direct module usage (explicit keys)
138
+ token = Legion::Crypt::JWT.issue(payload, signing_key: key, algorithm: 'RS256')
139
+ claims = Legion::Crypt::JWT.verify(token, verification_key: pub_key, algorithm: 'RS256')
140
+ decoded = Legion::Crypt::JWT.decode(token) # no verification, inspection only
141
+ ```
142
+
143
+ **Algorithms:**
144
+ - `HS256` (default): Uses cluster secret. All cluster nodes can issue and verify.
145
+ - `RS256`: Uses RSA keypair. Only the issuing node can sign; anyone with the public key can verify.
146
+
147
+ ---
148
+
149
+ **Maintained By**: Matthew Iverson (@Esity)
data/Gemfile CHANGED
@@ -3,3 +3,12 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'simplecov'
12
+ end
13
+ gem 'legion-logging'
14
+ gem 'legion-settings'
data/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ https://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2021 Esity
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ https://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
data/README.md CHANGED
@@ -1,3 +1,97 @@
1
- # Legion::Crypt
1
+ # legion-crypt
2
2
 
3
- The Legion encryption module
3
+ Encryption, secrets management, JWT token management, and HashiCorp Vault integration for the [LegionIO](https://github.com/LegionIO/LegionIO) framework. Provides AES-256-CBC message encryption, RSA key pair generation, cluster secret management, JWT issue/verify operations, and Vault token lifecycle management.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install legion-crypt
9
+ ```
10
+
11
+ Or add to your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'legion-crypt'
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ require 'legion/crypt'
21
+
22
+ Legion::Crypt.start
23
+ Legion::Crypt.encrypt('this is my string')
24
+ Legion::Crypt.decrypt(message)
25
+ ```
26
+
27
+ ### JWT Tokens
28
+
29
+ ```ruby
30
+ # Issue a token (defaults to HS256 using cluster secret)
31
+ token = Legion::Crypt.issue_token({ node_id: 'abc' }, ttl: 3600)
32
+
33
+ # Verify and decode a token
34
+ claims = Legion::Crypt.verify_token(token)
35
+
36
+ # Use RS256 (RSA keypair) instead
37
+ token = Legion::Crypt.issue_token({ node_id: 'abc' }, algorithm: 'RS256')
38
+ claims = Legion::Crypt.verify_token(token, algorithm: 'RS256')
39
+
40
+ # Inspect a token without verification
41
+ decoded = Legion::Crypt::JWT.decode(token)
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ ```json
47
+ {
48
+ "vault": {
49
+ "enabled": false,
50
+ "protocol": "http",
51
+ "address": "localhost",
52
+ "port": 8200,
53
+ "token": null,
54
+ "connected": false,
55
+ "renewer_time": 5,
56
+ "renewer": true,
57
+ "push_cluster_secret": true,
58
+ "read_cluster_secret": true,
59
+ "kv_path": "legion"
60
+ },
61
+ "jwt": {
62
+ "enabled": true,
63
+ "default_algorithm": "HS256",
64
+ "default_ttl": 3600,
65
+ "issuer": "legion",
66
+ "verify_expiration": true,
67
+ "verify_issuer": true
68
+ },
69
+ "cs_encrypt_ready": false,
70
+ "dynamic_keys": true,
71
+ "cluster_secret": null,
72
+ "save_private_key": true,
73
+ "read_private_key": true
74
+ }
75
+ ```
76
+
77
+ ### JWT Algorithms
78
+
79
+ | Algorithm | Key | Use Case |
80
+ |-----------|-----|----------|
81
+ | `HS256` (default) | Cluster secret (symmetric) | Intra-cluster tokens — all nodes can issue and verify |
82
+ | `RS256` | RSA key pair (asymmetric) | Tokens verifiable by external services without sharing the signing key |
83
+
84
+ ### Vault Integration
85
+
86
+ When `vault.token` is set (or via `VAULT_TOKEN_ID` env var), Crypt connects to Vault on `start`. The background `VaultRenewer` thread keeps the token alive. Vault is an optional runtime dependency — the Vault module is only included if the `vault` gem is available.
87
+
88
+ ## Requirements
89
+
90
+ - Ruby >= 3.4
91
+ - `jwt` gem (>= 2.7)
92
+ - `vault` gem (>= 0.17, optional)
93
+ - HashiCorp Vault (optional, for secrets management)
94
+
95
+ ## License
96
+
97
+ Apache-2.0
data/legion-crypt.gemspec CHANGED
@@ -3,37 +3,28 @@
3
3
  require_relative 'lib/legion/crypt/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'legion-crypt'
6
+ spec.name = 'legion-crypt'
7
7
  spec.version = Legion::Crypt::VERSION
8
8
  spec.authors = ['Esity']
9
9
  spec.email = ['matthewdiverson@gmail.com']
10
-
11
- spec.summary = 'Legion::Vault is used to keep things safe'
12
- spec.description = 'Integrates with Hashicorps vault and other encryption type things'
13
- spec.homepage = 'https://bitbucket.org/legion-io/legion-vault/'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
-
17
- spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/legion/'
19
- spec.metadata['changelog_uri'] = 'https://bitbucket.org/legion-io/legion/src/master/CHANGELOG.md'
20
- spec.metadata['wiki_uri'] = 'https://bitbucket.org/legion-io/legion-crypt/wiki'
21
- spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/legion-crypt/issues'
22
-
23
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
10
+ spec.summary = 'Handles requests for encrypt, decrypting, connecting to Vault, among other things'
11
+ spec.description = 'A gem used by the LegionIO framework for encryption'
12
+ spec.homepage = 'https://github.com/LegionIO/legion-crypt'
13
+ spec.license = 'Apache-2.0'
26
14
  spec.require_paths = ['lib']
15
+ spec.required_ruby_version = '>= 3.4'
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.extra_rdoc_files = %w[README.md LICENSE CHANGELOG.md]
18
+ spec.metadata = {
19
+ 'bug_tracker_uri' => 'https://github.com/LegionIO/legion-crypt/issues',
20
+ 'changelog_uri' => 'https://github.com/LegionIO/legion-crypt/blob/main/CHANGELOG.md',
21
+ 'documentation_uri' => 'https://github.com/LegionIO/legion-crypt',
22
+ 'homepage_uri' => 'https://github.com/LegionIO/LegionIO',
23
+ 'source_code_uri' => 'https://github.com/LegionIO/legion-crypt',
24
+ 'wiki_uri' => 'https://github.com/LegionIO/legion-crypt/wiki',
25
+ 'rubygems_mfa_required' => 'true'
26
+ }
27
27
 
28
- spec.add_dependency 'vault', '>= 0.15.0'
29
-
30
- spec.add_development_dependency 'legionio'
31
- spec.add_development_dependency 'legion-logging'
32
- spec.add_development_dependency 'legion-settings'
33
- spec.add_development_dependency 'legion-transport'
34
- spec.add_development_dependency 'rspec'
35
- spec.add_development_dependency 'rspec_junit_formatter'
36
- spec.add_development_dependency 'rubocop'
37
- spec.add_development_dependency 'simplecov', '< 0.18.0'
38
- spec.add_development_dependency 'simplecov_json_formatter'
28
+ spec.add_dependency 'jwt', '>= 2.7'
29
+ spec.add_dependency 'vault', '>= 0.17'
39
30
  end