strongroom-rails 0.4.0 → 0.5.1
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/CHANGELOG.md +14 -0
- data/README.md +23 -3
- data/lib/strongroom/client.rb +20 -1
- data/lib/strongroom/rails/authentication.rb +7 -1
- data/lib/strongroom/rails/version.rb +1 -1
- data/lib/strongroom/session.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b88bdc97033bd0b6f93bbe7cdadc65d7f5874d405dd01cc777a44c21c7887913
|
|
4
|
+
data.tar.gz: c19bf601209285252a93fce614c3c1d21d9c75ab440113dc392495a3b0aa180d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad054bbcc04975ba97dee7585dfffe1aaae660090b25e953bbe3e86ee6240244b2afe8bb0dad7401ecac15b21e680c30638d9dfb5fd336cf0585645ff922593e
|
|
7
|
+
data.tar.gz: 578c236380ea2ab5a5cef2bcc82c26ac2c6dc8b7579a083cd67be6c8e44cc5fc107dabfe121f356fa00164de8ce32ecc3cb745ab91c957b8ea457147044a9ac8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.1](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.5.0...strongroom-rails-v0.5.1) (2026-11-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* **strongroom-rails:** raise InvalidCrossOriginRequest where Rails deprecates InvalidAuthenticityToken ([#8](https://github.com/seuros/strongroom/issues/8)) ([626015d](https://github.com/seuros/strongroom/commit/626015d484b05767f41129b1600e317631b4c130))
|
|
9
|
+
|
|
10
|
+
## [0.5.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.4.0...strongroom-rails-v0.5.0) (2026-11-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* Client#audience_token relays a session to the kernel's token route; token issuers may be any URI ([670dc51](https://github.com/seuros/strongroom/commit/670dc51b289c79f907214213a88f5fae85bb3bdf))
|
|
16
|
+
|
|
3
17
|
## [0.4.0](https://github.com/seuros/strongroom/compare/strongroom-rails-v0.3.0...strongroom-rails-v0.4.0) (2026-10-26)
|
|
4
18
|
|
|
5
19
|
|
data/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Rails adapter for [Strongroom](https://github.com/seuros/strongroom), a Postgres-first authentication kernel
|
|
4
4
|
that acts as your application's security coprocessor: Rails never sees password
|
|
5
5
|
hashes or session secrets. Registration and recovery links go through the
|
|
6
|
-
kernel's service API from your server; MFA,
|
|
7
|
-
|
|
6
|
+
kernel's service API from your server; MFA, mail and automatic routes are
|
|
7
|
+
deliberately absent, and the only JWTs are the kernel's own audience tokens.
|
|
8
8
|
|
|
9
9
|
> **Status: pre-production.** Strongroom has not been audited and is not approved
|
|
10
10
|
> for production traffic or real credential imports.
|
|
@@ -198,7 +198,9 @@ wildcards. An API-mode app must also provide:
|
|
|
198
198
|
- HTTPS and a cookie scope that fits the deployment (Secure, SameSite=Lax:
|
|
199
199
|
same-site subdomains work, cross-site frontends do not).
|
|
200
200
|
|
|
201
|
-
Refusals raise `ActionController::InvalidAuthenticityToken` (422) on both paths
|
|
201
|
+
Refusals raise `ActionController::InvalidAuthenticityToken` (422) on both paths;
|
|
202
|
+
on Rails versions that deprecate it, `ActionController::InvalidCrossOriginRequest`
|
|
203
|
+
(also 422). `Strongroom::Rails::Authentication::MUTATION_REFUSED` names the one in use.
|
|
202
204
|
The Railtie maps `Strongroom::InvalidRequest` to 400, `Unauthorized` to 401,
|
|
203
205
|
`RateLimited` to 429 and `Busy`/`ProtocolError`/`Unavailable` to 503 for
|
|
204
206
|
controllers that do not `rescue_from` them.
|
|
@@ -521,6 +523,24 @@ for that `external_id`). On `Strongroom::IdentityUnverified`, cancel that
|
|
|
521
523
|
registration and let the owner register afresh; do not send a verification
|
|
522
524
|
link instead, which would let the owner verify that account and recover it.
|
|
523
525
|
|
|
526
|
+
## Audience tokens
|
|
527
|
+
|
|
528
|
+
When the daemon has `[tokens]` configured, it signs short-lived tokens that
|
|
529
|
+
let another service verify a session offline against
|
|
530
|
+
`/.well-known/jwks.json`. Your server holds the session, so it asks for them:
|
|
531
|
+
|
|
532
|
+
```ruby
|
|
533
|
+
minted = client.audience_token(token: session_token, audience: "maps")
|
|
534
|
+
render json: {token: minted.reveal, expires_at: minted.expires_at}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
- An audience the kernel does not serve for this namespace raises
|
|
538
|
+
`Strongroom::InvalidRequest`; an ended session raises `Strongroom::Unauthorized`.
|
|
539
|
+
- The token never outlives the session, and nothing is stored: a logged-out
|
|
540
|
+
session mints no more.
|
|
541
|
+
- `Strongroom::AudienceToken` is redacted in `inspect`, YAML and JSON; only
|
|
542
|
+
`reveal` returns the bearer value.
|
|
543
|
+
|
|
524
544
|
## Running the daemon
|
|
525
545
|
|
|
526
546
|
This gem is only the client: it ships no binary and needs none to install. The
|
data/lib/strongroom/client.rb
CHANGED
|
@@ -16,6 +16,10 @@ module Strongroom
|
|
|
16
16
|
"identity_verified" => :boolean}.freeze
|
|
17
17
|
METADATA = LOGIN.merge("org_id" => :uuid, "app_id" => :uuid).freeze
|
|
18
18
|
SERVICE_KEY_HEADER = "X-Strongroom-Service-Key"
|
|
19
|
+
AUDIENCE = /\A[a-z][a-z0-9._-]{0,63}\z/
|
|
20
|
+
COMPACT_JWS = /\A[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\z/
|
|
21
|
+
AUDIENCE_TOKEN = {"token" => :string, "token_type" => :string, "audience" => :string,
|
|
22
|
+
"expires_at" => :timestamp}.freeze
|
|
19
23
|
attr_reader :endpoint, :issuer, :namespace, :org_id, :app_id, :cookie_name, :service_endpoint
|
|
20
24
|
|
|
21
25
|
def initialize(endpoint:, issuer:, namespace:, org_id:, app_id:, cookie_base: "__Host-strongroom_session",
|
|
@@ -120,6 +124,20 @@ module Strongroom
|
|
|
120
124
|
nil
|
|
121
125
|
end
|
|
122
126
|
|
|
127
|
+
def audience_token(token:, audience:)
|
|
128
|
+
raise InvalidRequest, "invalid audience" unless audience.is_a?(String) && audience.match?(AUDIENCE)
|
|
129
|
+
response = request(:post, "token", token: Token.coerce(token), body: JSON.generate(audience: audience),
|
|
130
|
+
refusable: true)
|
|
131
|
+
values = object(response, AUDIENCE_TOKEN)
|
|
132
|
+
minted = values["token"]
|
|
133
|
+
unless values["token_type"] == "Bearer" && values["audience"] == audience &&
|
|
134
|
+
minted.bytesize <= 8192 && minted.match?(COMPACT_JWS)
|
|
135
|
+
raise ProtocolError, "invalid token response"
|
|
136
|
+
end
|
|
137
|
+
raise Unauthorized, "session expired" unless values["expires_at"] > Time.now
|
|
138
|
+
AudienceToken.new(value: minted, audience: audience, expires_at: values["expires_at"])
|
|
139
|
+
end
|
|
140
|
+
|
|
123
141
|
def discard(token:)
|
|
124
142
|
logout(token: token)
|
|
125
143
|
true
|
|
@@ -361,7 +379,7 @@ module Strongroom
|
|
|
361
379
|
value.is_a?(String) && value.match?(UUID) && value != "00000000-0000-0000-0000-000000000000"
|
|
362
380
|
end
|
|
363
381
|
|
|
364
|
-
def request(method, suffix, token: nil, body: nil, status: 200)
|
|
382
|
+
def request(method, suffix, token: nil, body: nil, status: 200, refusable: false)
|
|
365
383
|
headers = {"Accept" => "application/json", "Accept-Encoding" => "identity",
|
|
366
384
|
"Cache-Control" => "no-store", "X-Strongroom-Request" => "1"}
|
|
367
385
|
headers["Content-Type"] = "application/json" if body
|
|
@@ -369,6 +387,7 @@ module Strongroom
|
|
|
369
387
|
response = @transport.call(method, "/accounts/#{namespace}/#{suffix}", headers: headers, body: body)
|
|
370
388
|
bounded!(response)
|
|
371
389
|
case response.status
|
|
390
|
+
when 400 then raise InvalidRequest, "request refused" if refusable
|
|
372
391
|
when 401 then raise Unauthorized, "authentication failed"
|
|
373
392
|
when 403 then raise ProtocolError, "authentication request refused by service policy"
|
|
374
393
|
when 409 then conflict!(response)
|
|
@@ -9,6 +9,12 @@ module Strongroom
|
|
|
9
9
|
extend ActiveSupport::Concern
|
|
10
10
|
|
|
11
11
|
INTENT_HEADER = "HTTP_X_STRONGROOM_REQUEST"
|
|
12
|
+
# Rails main deprecates InvalidAuthenticityToken (no longer defined, only proxied) for InvalidCrossOriginRequest.
|
|
13
|
+
MUTATION_REFUSED = if ::ActionController.const_defined?(:InvalidAuthenticityToken, false)
|
|
14
|
+
::ActionController::InvalidAuthenticityToken
|
|
15
|
+
else
|
|
16
|
+
::ActionController::InvalidCrossOriginRequest
|
|
17
|
+
end
|
|
12
18
|
|
|
13
19
|
def self.origin(value)
|
|
14
20
|
NetHTTPTransport.endpoint(value)
|
|
@@ -93,7 +99,7 @@ module Strongroom
|
|
|
93
99
|
|
|
94
100
|
def strongroom_verify_mutation!(verb)
|
|
95
101
|
unless request.request_method == verb.to_s.upcase && strongroom_mutation_intended?
|
|
96
|
-
raise
|
|
102
|
+
raise MUTATION_REFUSED, "verified mutation intent required"
|
|
97
103
|
end
|
|
98
104
|
end
|
|
99
105
|
|
data/lib/strongroom/session.rb
CHANGED
|
@@ -51,6 +51,32 @@ module Strongroom
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
class AudienceToken
|
|
55
|
+
attr_reader :audience, :expires_at
|
|
56
|
+
|
|
57
|
+
def initialize(value:, audience:, expires_at:)
|
|
58
|
+
@value, @audience, @expires_at = value.dup.freeze, audience.dup.freeze, expires_at
|
|
59
|
+
freeze
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def reveal = @value
|
|
63
|
+
def inspect = "#<Strongroom::AudienceToken audience=#{audience} expires_at=#{expires_at.iso8601} token=[FILTERED]>"
|
|
64
|
+
alias to_s inspect
|
|
65
|
+
def pretty_print(printer) = printer.text(inspect)
|
|
66
|
+
|
|
67
|
+
def as_json(*)
|
|
68
|
+
raise TypeError, "audience tokens must not be serialized"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def marshal_dump
|
|
72
|
+
raise TypeError, "audience tokens must not be serialized"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def encode_with(coder)
|
|
76
|
+
coder.map = {"audience" => audience, "token" => "[FILTERED]"}
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
54
80
|
# A link's secret and its expiry. Put the token in the URL fragment of a link
|
|
55
81
|
# to your own page, which posts it to the kernel; nothing here is safe to log
|
|
56
82
|
# or serialize.
|