nonnative 3.46.0 → 3.48.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 +1 -2
- data/lib/nonnative/ed25519_key.rb +1 -2
- data/lib/nonnative/token.rb +6 -13
- data/lib/nonnative/version.rb +1 -1
- data/lib/nonnative.rb +2 -7
- metadata +1 -62
- data/lib/nonnative/paseto_token.rb +0 -64
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e59f2997dfa42a55dbacef25dd6b40f37af09601f4d9ed2efd4ee28264f47b8
|
|
4
|
+
data.tar.gz: 7363fd58bdce452cd2a8135d7ce593a1d229aba7326dcc5a5a0330f886b56f9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 460b3aff7f6a73f33e17dd98543989141c84ffe5d1659706bd9fe19c6079efbeb52daae29c20e9e4e7b5e886e5d29dc60c32b8532f89cb2837cfbced92db8cf8
|
|
7
|
+
data.tar.gz: 81a3fc160e5bca6c41885168a6112d3b3d1daa92035dab1606222f9d38673875c6ff68dc2dd602ad36191777910d3fb0327d2877d5c5177aa13c32d04db8ab04
|
data/README.md
CHANGED
|
@@ -221,10 +221,9 @@ headers = Nonnative::Header.auth_bearer(
|
|
|
221
221
|
)
|
|
222
222
|
```
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
The supported `kind` is Ed25519 JWT generation only:
|
|
225
225
|
|
|
226
226
|
- `jwt`: EdDSA JWT with the key id in the `kid` header. `private_key` is a PKCS#8 PEM file.
|
|
227
|
-
- `paseto`: PASETO v4.public with the key id in a `{"kid":"..."}` footer. `private_key` is a PKCS#8 PEM file. Requires system **libsodium** (via `rbnacl`); it loads lazily, so `require 'nonnative'` works without libsodium until you generate a PASETO token.
|
|
228
227
|
|
|
229
228
|
The audience is endpoint-scoped; build it with the helpers:
|
|
230
229
|
|
|
@@ -4,8 +4,7 @@ module Nonnative
|
|
|
4
4
|
# Loads an Ed25519 private key from a PEM file for signing tokens.
|
|
5
5
|
#
|
|
6
6
|
# Verifiers such as go-service use Ed25519 keys encoded as PKCS#8 PEM. This reads the PEM once and
|
|
7
|
-
# exposes
|
|
8
|
-
# 32-byte seed for {Nonnative::JwtToken}.
|
|
7
|
+
# exposes the 32-byte seed required by {Nonnative::JwtToken}.
|
|
9
8
|
#
|
|
10
9
|
# @example
|
|
11
10
|
# key = Nonnative::Ed25519Key.new('config/ed25519.pem')
|
data/lib/nonnative/token.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Nonnative
|
|
4
|
-
# Builds signed JWT
|
|
4
|
+
# Builds signed JWT tokens for authenticating against services under test.
|
|
5
5
|
#
|
|
6
6
|
# The consumer passes in the signing parameters they parsed from their own configuration; this class
|
|
7
7
|
# is not coupled to any particular service's configuration format. The generated token string is
|
|
@@ -12,16 +12,8 @@ module Nonnative
|
|
|
12
12
|
# private_key: 'config/ed25519.pem', expiration: 3600)
|
|
13
13
|
# header = Nonnative::Header.auth_bearer(token.generate(aud: 'GET /v1/things', sub: 'user-1'))
|
|
14
14
|
#
|
|
15
|
-
# @example PASETO
|
|
16
|
-
# token = Nonnative::Token.new(kind: 'paseto', issuer: 'iss', key: 'key-1',
|
|
17
|
-
# private_key: 'config/ed25519.pem', expiration: 3600)
|
|
18
|
-
# token.generate(aud: Nonnative::Token.grpc_audience('/health.v1.Health/Check'), sub: 'user-1')
|
|
19
|
-
#
|
|
20
15
|
# @see Nonnative::Header.auth_bearer
|
|
21
16
|
class Token
|
|
22
|
-
# Supported token kinds mapped to their implementation.
|
|
23
|
-
KINDS = { 'jwt' => Nonnative::JwtToken, 'paseto' => Nonnative::PasetoToken }.freeze
|
|
24
|
-
|
|
25
17
|
class << self
|
|
26
18
|
# Builds the audience string for an HTTP endpoint.
|
|
27
19
|
#
|
|
@@ -41,15 +33,16 @@ module Nonnative
|
|
|
41
33
|
end
|
|
42
34
|
end
|
|
43
35
|
|
|
44
|
-
# @param kind [String] token kind,
|
|
36
|
+
# @param kind [String] token kind, `"jwt"`
|
|
45
37
|
# @param issuer [String] the `iss` claim
|
|
46
|
-
# @param key [String] the key id (JWT `kid` header
|
|
38
|
+
# @param key [String] the key id (JWT `kid` header)
|
|
47
39
|
# @param private_key [String] path to a PKCS#8 Ed25519 private key PEM file
|
|
48
40
|
# @param expiration [Integer] token lifetime in seconds (drives `exp`)
|
|
49
41
|
# @raise [ArgumentError] if the kind is not supported
|
|
50
42
|
def initialize(kind:, issuer:, key:, private_key:, expiration:)
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
raise ArgumentError, "Unsupported token kind '#{kind}'" unless kind == 'jwt'
|
|
44
|
+
|
|
45
|
+
@token = Nonnative::JwtToken.new(issuer: issuer, key: key, private_key: private_key, expiration: expiration)
|
|
53
46
|
end
|
|
54
47
|
|
|
55
48
|
# Generates a signed token.
|
data/lib/nonnative/version.rb
CHANGED
data/lib/nonnative.rb
CHANGED
|
@@ -50,9 +50,7 @@ require 'securerandom'
|
|
|
50
50
|
require 'shellwords'
|
|
51
51
|
require 'uri'
|
|
52
52
|
require 'openssl'
|
|
53
|
-
require 'json'
|
|
54
53
|
require 'time'
|
|
55
|
-
require 'singleton' # ruby-paseto depends on this stdlib, which Ruby no longer auto-loads
|
|
56
54
|
|
|
57
55
|
require 'grpc'
|
|
58
56
|
require 'grpc/health/v1/health_services_pb'
|
|
@@ -68,8 +66,6 @@ require 'rspec/wait'
|
|
|
68
66
|
require 'puma'
|
|
69
67
|
require 'puma/server'
|
|
70
68
|
|
|
71
|
-
# jwt-eddsa (with the ed25519 gem) is pure Ruby and needs no system library, so it loads here.
|
|
72
|
-
# PASETO's rbnacl needs system libsodium, so Nonnative::PasetoToken requires it lazily instead.
|
|
73
69
|
require 'jwt/eddsa'
|
|
74
70
|
|
|
75
71
|
require 'nonnative/version'
|
|
@@ -124,7 +120,6 @@ require 'nonnative/cucumber'
|
|
|
124
120
|
require 'nonnative/header'
|
|
125
121
|
require 'nonnative/ed25519_key'
|
|
126
122
|
require 'nonnative/jwt_token'
|
|
127
|
-
require 'nonnative/paseto_token'
|
|
128
123
|
require 'nonnative/token'
|
|
129
124
|
|
|
130
125
|
# The main namespace for the gem.
|
|
@@ -216,9 +211,9 @@ module Nonnative
|
|
|
216
211
|
# The signing parameters are passed in directly; this is not coupled to any service's
|
|
217
212
|
# configuration format. The generated token string is ready for {Nonnative::Header.auth_bearer}.
|
|
218
213
|
#
|
|
219
|
-
# @param kind [String] token kind,
|
|
214
|
+
# @param kind [String] token kind, `"jwt"`
|
|
220
215
|
# @param issuer [String] the `iss` claim
|
|
221
|
-
# @param key [String] the key id (JWT `kid` header
|
|
216
|
+
# @param key [String] the key id (JWT `kid` header)
|
|
222
217
|
# @param private_key [String] path to a PKCS#8 Ed25519 private key PEM file
|
|
223
218
|
# @param expiration [Integer] token lifetime in seconds (drives `exp`)
|
|
224
219
|
# @return [Nonnative::Token]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nonnative
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.48.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alejandro Falkowski
|
|
@@ -143,26 +143,6 @@ dependencies:
|
|
|
143
143
|
- - "<"
|
|
144
144
|
- !ruby/object:Gem::Version
|
|
145
145
|
version: '2'
|
|
146
|
-
- !ruby/object:Gem::Dependency
|
|
147
|
-
name: json
|
|
148
|
-
requirement: !ruby/object:Gem::Requirement
|
|
149
|
-
requirements:
|
|
150
|
-
- - ">="
|
|
151
|
-
- !ruby/object:Gem::Version
|
|
152
|
-
version: '2'
|
|
153
|
-
- - "<"
|
|
154
|
-
- !ruby/object:Gem::Version
|
|
155
|
-
version: '3'
|
|
156
|
-
type: :runtime
|
|
157
|
-
prerelease: false
|
|
158
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
159
|
-
requirements:
|
|
160
|
-
- - ">="
|
|
161
|
-
- !ruby/object:Gem::Version
|
|
162
|
-
version: '2'
|
|
163
|
-
- - "<"
|
|
164
|
-
- !ruby/object:Gem::Version
|
|
165
|
-
version: '3'
|
|
166
146
|
- !ruby/object:Gem::Dependency
|
|
167
147
|
name: jwt
|
|
168
148
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -223,26 +203,6 @@ dependencies:
|
|
|
223
203
|
- - "<"
|
|
224
204
|
- !ruby/object:Gem::Version
|
|
225
205
|
version: '9'
|
|
226
|
-
- !ruby/object:Gem::Dependency
|
|
227
|
-
name: rbnacl
|
|
228
|
-
requirement: !ruby/object:Gem::Requirement
|
|
229
|
-
requirements:
|
|
230
|
-
- - ">="
|
|
231
|
-
- !ruby/object:Gem::Version
|
|
232
|
-
version: '7'
|
|
233
|
-
- - "<"
|
|
234
|
-
- !ruby/object:Gem::Version
|
|
235
|
-
version: '8'
|
|
236
|
-
type: :runtime
|
|
237
|
-
prerelease: false
|
|
238
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
239
|
-
requirements:
|
|
240
|
-
- - ">="
|
|
241
|
-
- !ruby/object:Gem::Version
|
|
242
|
-
version: '7'
|
|
243
|
-
- - "<"
|
|
244
|
-
- !ruby/object:Gem::Version
|
|
245
|
-
version: '8'
|
|
246
206
|
- !ruby/object:Gem::Dependency
|
|
247
207
|
name: rest-client
|
|
248
208
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -343,26 +303,6 @@ dependencies:
|
|
|
343
303
|
- - "<"
|
|
344
304
|
- !ruby/object:Gem::Version
|
|
345
305
|
version: '2'
|
|
346
|
-
- !ruby/object:Gem::Dependency
|
|
347
|
-
name: ruby-paseto
|
|
348
|
-
requirement: !ruby/object:Gem::Requirement
|
|
349
|
-
requirements:
|
|
350
|
-
- - ">="
|
|
351
|
-
- !ruby/object:Gem::Version
|
|
352
|
-
version: '0'
|
|
353
|
-
- - "<"
|
|
354
|
-
- !ruby/object:Gem::Version
|
|
355
|
-
version: '1'
|
|
356
|
-
type: :runtime
|
|
357
|
-
prerelease: false
|
|
358
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
359
|
-
requirements:
|
|
360
|
-
- - ">="
|
|
361
|
-
- !ruby/object:Gem::Version
|
|
362
|
-
version: '0'
|
|
363
|
-
- - "<"
|
|
364
|
-
- !ruby/object:Gem::Version
|
|
365
|
-
version: '1'
|
|
366
306
|
- !ruby/object:Gem::Dependency
|
|
367
307
|
name: sinatra
|
|
368
308
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -427,7 +367,6 @@ files:
|
|
|
427
367
|
- lib/nonnative/no_proxy.rb
|
|
428
368
|
- lib/nonnative/not_found_error.rb
|
|
429
369
|
- lib/nonnative/observability.rb
|
|
430
|
-
- lib/nonnative/paseto_token.rb
|
|
431
370
|
- lib/nonnative/pool.rb
|
|
432
371
|
- lib/nonnative/port.rb
|
|
433
372
|
- lib/nonnative/ports.rb
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Nonnative
|
|
4
|
-
# Generates Ed25519 PASETO v4.public tokens for authenticating against services under test.
|
|
5
|
-
#
|
|
6
|
-
# The key id is carried in a JSON footer (`{"kid":"..."}`), and the claims match the common
|
|
7
|
-
# iss/aud/sub/iat/nbf/exp/jti set expected by verifiers such as go-service. The signing library is
|
|
8
|
-
# required lazily so that requiring `nonnative` does not depend on `rbnacl`/libsodium being present.
|
|
9
|
-
#
|
|
10
|
-
# @example
|
|
11
|
-
# paseto = Nonnative::PasetoToken.new(issuer: 'iss', key: 'key-1', private_key: 'config/ed25519.pem', expiration: 3600)
|
|
12
|
-
# paseto.generate(aud: 'GET /v1/things', sub: 'user-1')
|
|
13
|
-
#
|
|
14
|
-
# @see https://github.com/bannable/paseto ruby-paseto
|
|
15
|
-
class PasetoToken
|
|
16
|
-
# @param issuer [String] the `iss` claim
|
|
17
|
-
# @param key [String] the key id carried in the `kid` footer
|
|
18
|
-
# @param private_key [String] path to a PKCS#8 Ed25519 private key PEM file
|
|
19
|
-
# @param expiration [Integer] token lifetime in seconds (drives `exp`)
|
|
20
|
-
def initialize(issuer:, key:, private_key:, expiration:)
|
|
21
|
-
@issuer = issuer
|
|
22
|
-
@key = key
|
|
23
|
-
@ed25519 = Nonnative::Ed25519Key.new(private_key)
|
|
24
|
-
@expiration = expiration
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Generates a signed PASETO v4.public token.
|
|
28
|
-
#
|
|
29
|
-
# @param aud [String] the `aud` claim (for example `"GET /v1/things"` or a gRPC full method)
|
|
30
|
-
# @param sub [String] the `sub` claim
|
|
31
|
-
# @param issued_at [Time, nil] overrides the `iat` claim (default: now)
|
|
32
|
-
# @param not_before [Time, nil] overrides the `nbf` claim (default: `issued_at`)
|
|
33
|
-
# @param expires_at [Time, nil] overrides the `exp` claim (default: `issued_at` plus `expiration`)
|
|
34
|
-
# @return [String] the signed PASETO token
|
|
35
|
-
def generate(aud:, sub:, issued_at: nil, not_before: nil, expires_at: nil)
|
|
36
|
-
load_dependencies!
|
|
37
|
-
|
|
38
|
-
now = (issued_at || Time.now).utc
|
|
39
|
-
claims = {
|
|
40
|
-
'iss' => @issuer,
|
|
41
|
-
'aud' => aud,
|
|
42
|
-
'sub' => sub,
|
|
43
|
-
'iat' => now.iso8601,
|
|
44
|
-
'nbf' => (not_before || now).utc.iso8601,
|
|
45
|
-
'exp' => (expires_at || (now + @expiration)).utc.iso8601,
|
|
46
|
-
'jti' => SecureRandom.uuid
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
Paseto::V4::Public.new(@ed25519.pem).encode!(claims, footer: { 'kid' => @key }.to_json)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
# Loads the PASETO signing libraries lazily and raises a clear error if they are unavailable.
|
|
55
|
-
# rbnacl loads system libsodium at runtime, which the gemspec cannot guarantee, so requiring it
|
|
56
|
-
# here keeps `require 'nonnative'` working without libsodium for consumers that do not use PASETO.
|
|
57
|
-
def load_dependencies!
|
|
58
|
-
require 'rbnacl'
|
|
59
|
-
require 'paseto'
|
|
60
|
-
rescue LoadError => e
|
|
61
|
-
raise Nonnative::Error, "PASETO token generation requires libsodium and the rbnacl and ruby-paseto gems (#{e.message})"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|