standard_id-void_which_binds 0.1.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 +7 -0
- data/CHANGELOG.md +79 -0
- data/LICENSE +22 -0
- data/README.md +128 -0
- data/Rakefile +12 -0
- data/app/models/standard_id/void_which_binds/login.rb +14 -0
- data/app/models/standard_id/void_which_binds/received_event.rb +26 -0
- data/app/models/standard_id/void_which_binds/subject.rb +48 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20261005000000_create_standard_id_void_which_binds_tables.rb +64 -0
- data/lib/generators/standard_id/void_which_binds/install/install_generator.rb +81 -0
- data/lib/generators/standard_id/void_which_binds/install/templates/initializer.rb.erb +28 -0
- data/lib/standard_id/void_which_binds/configuration.rb +275 -0
- data/lib/standard_id/void_which_binds/current.rb +18 -0
- data/lib/standard_id/void_which_binds/engine.rb +44 -0
- data/lib/standard_id/void_which_binds/errors.rb +48 -0
- data/lib/standard_id/void_which_binds/events_endpoint.rb +92 -0
- data/lib/standard_id/void_which_binds/id_token.rb +178 -0
- data/lib/standard_id/void_which_binds/jose.rb +258 -0
- data/lib/standard_id/void_which_binds/logins.rb +54 -0
- data/lib/standard_id/void_which_binds/providers/void_which_binds.rb +243 -0
- data/lib/standard_id/void_which_binds/receiver.rb +192 -0
- data/lib/standard_id/void_which_binds/security_event.rb +270 -0
- data/lib/standard_id/void_which_binds/staff_policy.rb +72 -0
- data/lib/standard_id/void_which_binds/testing.rb +65 -0
- data/lib/standard_id/void_which_binds/validators.rb +128 -0
- data/lib/standard_id/void_which_binds/version.rb +7 -0
- data/lib/standard_id/void_which_binds.rb +25 -0
- metadata +131 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7c4ca3cfd0bcc41671df6b1b7111c11809b980b38a2727373eed9aa513fb1f03
|
|
4
|
+
data.tar.gz: 609865c1ec30ded67ab01965edb5e925fe5c50df750a6826c2ea2207fa31a6e2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 00f4d1d658c20414416cd2f20f3613215da6d2e8995ec112275c936fcfcbe10f2b864a2d54113cd6ff926aa57a75ca72a713271adcccc996b5fbf1038db930ea
|
|
7
|
+
data.tar.gz: c8a3c613b8b0fc5110f68fc6bf4b1368156e40b9f285ee9a01ca994507bf3165ffca6d139d425fbb4d343836f07b8cab2143e4b2fbb741025af7ebeb0383915e
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **Broker requests honour the host's `StandardId.config.network_wrapper`** (standard_id releases
|
|
15
|
+
after 0.60.0), given `provider: :void_which_binds`: discovery, the JWKS and the token exchange,
|
|
16
|
+
so a circuit breaker or tracing span covers them as it covers the other providers. The gem keeps
|
|
17
|
+
its own HTTP client (the broker may sit on a private address that `StandardId::HttpClient`
|
|
18
|
+
refuses). A transport error raised inside the wrapper still becomes `BrokerUnavailable`; an
|
|
19
|
+
error the wrapper raises itself propagates as is. On older standard_id releases there is no such
|
|
20
|
+
setting, so nothing changes and the `~> 0.46` requirement stays.
|
|
21
|
+
- **`StandardId::Providers::VoidWhichBinds`** (`void_which_binds`): sign-in with
|
|
22
|
+
an organisation's Void-Which-Binds broker (moneta), per ADR-0023. It uses the
|
|
23
|
+
authorization code flow with PKCE S256, a nonce, `client_secret_basic`, and
|
|
24
|
+
the callback's RFC 9207 `iss` checked before the code is exchanged. The
|
|
25
|
+
EdDSA ID token is verified only under pinned RFC 7638 thumbprints, with
|
|
26
|
+
void-which-binds-go's `oidc.VerifyIDToken` rules. `trusted_for_linking?` is
|
|
27
|
+
`true` (see the README's warning). Requires standard_id 0.46.
|
|
28
|
+
- **`StandardId::VoidWhichBinds.staff_policy`**: a `login_method_policy` that
|
|
29
|
+
admits staff accounts only through `void_which_binds`, gated by
|
|
30
|
+
`void_which_binds_require_for_staff` (default `true`). A staff lock the
|
|
31
|
+
account class cannot perform (no `StandardId::AccountLocking`) is refused at
|
|
32
|
+
boot.
|
|
33
|
+
- **SET receiver** at `POST /auth/void_which_binds/events` (RFC 8935). It
|
|
34
|
+
verifies the SET with void-which-binds-go's `secevent.Verify` rules, answers
|
|
35
|
+
with `secevent.Response`'s codes, deduplicates the `jti`, and applies the
|
|
36
|
+
event by watermark in one transaction before the `202`. It is a bare Rack
|
|
37
|
+
endpoint that reads at most 16 KiB + 1 of the body, also for a chunked
|
|
38
|
+
request with no Content-Length.
|
|
39
|
+
- A session-revoked SET revokes sessions with `login_iat <= toe` and records
|
|
40
|
+
the per-subject revocation watermark (#135), even for unknown subjects.
|
|
41
|
+
- An account-disabled SET applies when `toe >= last_login_iat`. It disables
|
|
42
|
+
the link, revokes the account's sessions and refresh tokens, and locks a
|
|
43
|
+
staff account.
|
|
44
|
+
- Session creation refuses an ID token with `iat <=` the watermark or the
|
|
45
|
+
disabled `toe`.
|
|
46
|
+
- **Failure attribution at the SET endpoint**: only a defect in the SET is
|
|
47
|
+
answered 400. An unusable inline or fetched JWKS, an unreachable broker, a
|
|
48
|
+
database error or any unexpected error on the receiving side is a 500, which
|
|
49
|
+
moneta retries instead of dead-lettering.
|
|
50
|
+
- **Install generator** `standard_id:void_which_binds:install`: initializer,
|
|
51
|
+
migration (subjects, logins and received-events tables) and the engine mount.
|
|
52
|
+
- **`StandardId::VoidWhichBinds::Testing`**: mints ID tokens and SETs under
|
|
53
|
+
test-only keys, for host request specs.
|
|
54
|
+
- **Golden vectors**: every case of void-which-binds-go's
|
|
55
|
+
`testvectors/vectors/oidc` (26 files) and `secevent` (25 files) is replayed.
|
|
56
|
+
Tokens are re-signed and re-minted byte for byte. The copies are pinned to
|
|
57
|
+
void-which-binds-go **v0.24.0** (`3f97570`) by
|
|
58
|
+
`spec/vectors/VOID_WHICH_BINDS_GO_REF` and checked by
|
|
59
|
+
`scripts/check-vector-drift.sh` (CI job `vector-drift`).
|
|
60
|
+
|
|
61
|
+
### Changed
|
|
62
|
+
|
|
63
|
+
- **The PKCE verifier and the callback `iss` now come from standard_id core**
|
|
64
|
+
(0.46's core hook, standard_id#369). The provider declares
|
|
65
|
+
`supports_pkce? = true`, so core generates a fresh verifier for every
|
|
66
|
+
sign-in, keeps it in the encrypted pending-requests cookie, and sends the
|
|
67
|
+
S256 challenge, which `authorization_url` now uses (and refuses to build a
|
|
68
|
+
URL without). `get_user_info` takes `callback_iss:` and `code_verifier:`:
|
|
69
|
+
it refuses a callback whose `iss` is missing or is not
|
|
70
|
+
`void_which_binds_issuer`, refuses a call with no verifier (only the web
|
|
71
|
+
callback passes one, so the native/API callback stays refused), and sends
|
|
72
|
+
the verifier in the token request. Removed: the `CallbackIssuerCheck`
|
|
73
|
+
`before_action` the engine included into the web callback controller,
|
|
74
|
+
`Current.callback_iss` / `Current.callback_checked`,
|
|
75
|
+
`Providers::VoidWhichBinds.code_verifier_for` (the nonce-derived HMAC
|
|
76
|
+
verifier) and `PKCE_KEY_PURPOSE`. Requires standard_id `>= 0.46.0`.
|
|
77
|
+
**Deploy note:** a sign-in in flight at deploy time was started with the
|
|
78
|
+
old derived challenge and has no stored verifier, so it fails once and the
|
|
79
|
+
person needs to retry.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rarebit One
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# standard_id-void_which_binds
|
|
2
|
+
|
|
3
|
+
StandardId provider plugin for an organisation's Void-Which-Binds broker (moneta): OIDC login with pinned EdDSA ID tokens and Security Event Token deprovisioning, per [ADR-0023](https://github.com/rarebit-one/void-which-binds-go/blob/main/docs/adr/0023-broker-oidc-login-and-set-deprovisioning.md).
|
|
4
|
+
|
|
5
|
+
- **Sign-in:** authorization code + PKCE S256 + nonce, `client_secret_basic`. The Ed25519 ID token is verified only under **pinned** key thumbprints, with the same rules as void-which-binds-go's `oidc.VerifyIDToken`. The callback's RFC 9207 `iss` is checked before the code is exchanged. Both the PKCE verifier and the callback `iss` come from standard_id core (0.46+); see [How the sign-in uses standard_id core](#how-the-sign-in-uses-standard_id-core).
|
|
6
|
+
- **Linking:** by `sub` (standard_id's `(provider, sub)` row), or by email only when moneta says `email_verified: true`.
|
|
7
|
+
- **Staff policy:** a `login_method_policy` that lets staff accounts in only through Void-Which-Binds.
|
|
8
|
+
- **Deprovisioning:** `POST /auth/void_which_binds/events` receives moneta's RFC 8935 SET push. It verifies the SET (`secevent.Verify`), deduplicates the `jti`, and applies it by watermark. All of that commits in one transaction before the `202`.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
# Gemfile
|
|
14
|
+
gem "standard_id-void_which_binds"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bin/rails g standard_id:void_which_binds:install # initializer, migration, route
|
|
19
|
+
bin/rails db:migrate
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The generator writes `config/initializers/standard_id_void_which_binds.rb`, copies the migration, and adds this mount:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
mount StandardId::VoidWhichBinds::Engine => "/auth/void_which_binds"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Register both URLs with moneta for **every** origin you serve: the redirect URI `<origin>/auth/callback/void_which_binds` and the SET push endpoint `<origin>/auth/void_which_binds/events`.
|
|
29
|
+
|
|
30
|
+
### How the sign-in uses standard_id core
|
|
31
|
+
|
|
32
|
+
The plugin needs standard_id 0.46 or later. It uses the core hook described in standard_id's README under "Callback `iss` and core-managed PKCE (0.46+)":
|
|
33
|
+
|
|
34
|
+
- **PKCE.** The provider declares `supports_pkce? = true`. On every `/login?connection=void_which_binds`, core generates a fresh verifier and stores it with the state and nonce in the encrypted pending-requests cookie. The authorization URL carries only its S256 challenge. At the web callback, core hands the stored verifier back, and the provider sends it in the token request. A callback whose stored flow has no verifier is refused by core before the provider runs.
|
|
35
|
+
- **Callback `iss` (RFC 9207).** Core passes the redirect's `iss` as `callback_iss:`. The provider refuses the callback unless it equals `void_which_binds_issuer`, including when it is missing, and it checks this before the code is exchanged.
|
|
36
|
+
|
|
37
|
+
**Upgrading from a pre-0.46 build.** Earlier builds derived the verifier from the nonce and captured `iss` in their own `before_action`. A sign-in that was already in flight when you deploy has no stored verifier, so it fails once. The person signs in again.
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
Every field lives in the `social` scope. A field the initializer does not assign falls back to the ENV variable named after it, upper-cased.
|
|
42
|
+
|
|
43
|
+
| Field | ENV | |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `void_which_binds_client_id` | `VOID_WHICH_BINDS_CLIENT_ID` | Switches the provider on |
|
|
46
|
+
| `void_which_binds_client_secret` | `VOID_WHICH_BINDS_CLIENT_SECRET` | Required |
|
|
47
|
+
| `void_which_binds_issuer` | `VOID_WHICH_BINDS_ISSUER` | Required. moneta's https origin, byte for byte (no path, no trailing slash) |
|
|
48
|
+
| `void_which_binds_org` | `VOID_WHICH_BINDS_ORG` | Required. The org id, `ed25519:<64 hex>` |
|
|
49
|
+
| `void_which_binds_jwks_pins` | `VOID_WHICH_BINDS_JWKS_PINS` | Required. RFC 7638 thumbprints of moneta's `assert` key, as an Array or a comma-separated String |
|
|
50
|
+
| `void_which_binds_jwks` | `VOID_WHICH_BINDS_JWKS` | Optional JWKS inline. Otherwise it is fetched from `issuer/.well-known/jwks.json` |
|
|
51
|
+
| `void_which_binds_authorization_endpoint`, `void_which_binds_token_endpoint` | (same names) | Optional. Otherwise read from discovery, whose `issuer` must equal the configured one. Either way both must be on the issuer's origin |
|
|
52
|
+
| `void_which_binds_require_for_staff` | `VOID_WHICH_BINDS_REQUIRE_FOR_STAFF` | Default `true`. Enforces the staff policy and the staff lock |
|
|
53
|
+
| `void_which_binds_staff_predicate` | (none, it is a callable) | `->(account) { account.staff? }` |
|
|
54
|
+
|
|
55
|
+
**Pinning.** The JWKS distributes keys, but it is never a trust root. A token verifies only under a key whose recomputed thumbprint is pinned and equals its `kid`. A published key that is not pinned is ignored. To rotate the key, pin moneta's `next` thumbprint alongside the current one, and drop the old pin once moneta has cut over. When a pinned key is missing from the cached JWKS, the gem refetches it, at most every 30 s.
|
|
56
|
+
|
|
57
|
+
### Staff accounts
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
StandardId.configure do |c|
|
|
61
|
+
c.social.void_which_binds_staff_predicate = ->(account) { account.staff? }
|
|
62
|
+
c.login_method_policy = StandardId::VoidWhichBinds.staff_policy
|
|
63
|
+
# or: StandardId::VoidWhichBinds.staff_policy(staff_predicate: ..., fallback: other_policy)
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
standard_id 0.45 consults the policy before any session or token exists. That covers every flow, including each refresh, which is checked against the original sign-in's method. A staff account may sign in only with `auth_method: :social` and provider `void_which_binds`. When an `account-disabled` SET is applied to a staff account, the account is also locked (`lock!`, if it includes `StandardId::AccountLocking`). The lock stays until someone unlocks it. If a staff lock is configured but the account class does not include `StandardId::AccountLocking`, the app refuses to boot. If it somehow runs anyway, the revocations still commit and the missing lock is logged and reported to `Rails.error`. Without a predicate, the policy raises and fails closed.
|
|
68
|
+
|
|
69
|
+
## ⚠️ `trusted_for_linking?` is true, and must stay limited to an org's own IdP
|
|
70
|
+
|
|
71
|
+
This provider returns `true` from `trusted_for_linking?`. Under `link_strategy: :strict`, a Void-Which-Binds login with `email_verified: true` may therefore link to an **existing, verified** account that was created another way (password, Google, ...).
|
|
72
|
+
|
|
73
|
+
That is safe **only** because moneta is the organisation's **own** broker. Its `email_verified` is true only when the org itself vouches for the address: a link moneta mailed to that address, or an address in a domain the org administers (ADR-0023, D7). Nobody can self-assert an address there.
|
|
74
|
+
|
|
75
|
+
Never copy this setting to a provider where anyone can register an address (Google, Apple, GitHub, a shared or multi-tenant IdP). Trusting such a provider lets whoever controls an address *at that IdP* take over the account that holds the same address *here*. Every other guard still applies: the provider must report `email_verified`, the existing identifier must itself be verified, and a different `sub` for the same identifier is refused.
|
|
76
|
+
|
|
77
|
+
## Deprovisioning (RFC 8935 SET push)
|
|
78
|
+
|
|
79
|
+
moneta pushes one SET per cause (`Content-Type: application/secevent+jwt`). The endpoint answers exactly as `secevent.Response` does:
|
|
80
|
+
|
|
81
|
+
| Outcome | Answer |
|
|
82
|
+
|---|---|
|
|
83
|
+
| Applied; a duplicate `jti`; an unknown subject; an event acknowledged without being applied | `202`, empty body |
|
|
84
|
+
| Refused key, algorithm or signature (for example a pin gap during a rotation) | `400 {"err":"invalid_key"}`. moneta retries |
|
|
85
|
+
| Wrong `iss` / `aud` | `400 invalid_issuer` / `invalid_audience`. moneta retries |
|
|
86
|
+
| Anything else (wrong `typ`, a stale `iat`, a malformed claim, ...) | `400 invalid_request`. moneta dead-letters |
|
|
87
|
+
| Anything on this side: misconfiguration, an unusable inline or fetched JWKS, moneta unreachable, a database failure, an unexpected error | `500`. moneta retries; nothing was committed |
|
|
88
|
+
|
|
89
|
+
The gem applies an event by watermark. Every comparison is between stamps from moneta's monotonic clock, and a tie revokes.
|
|
90
|
+
|
|
91
|
+
- **session-revoked** raises the subject's revocation watermark, even for a subject this app has never seen. It never lowers the watermark. It revokes the browser sessions whose ID token was issued at or before `toe`, along with their refresh tokens, plus any `void_which_binds` refresh token that has no session. Newer sessions are untouched.
|
|
92
|
+
- **account-disabled** applies only when `toe >=` the subject's newest login. It disables the link at `toe`, revokes every session and refresh token of the linked account, and locks a staff account.
|
|
93
|
+
- **Session creation:** the gem refuses an ID token whose `iat <=` the watermark, or `<=` the disabled `toe`. It checks once when the token verifies, and again under the subject's row lock when the session is created. A later login with `iat >` the disabled `toe` re-enables the link.
|
|
94
|
+
|
|
95
|
+
`StandardId::VoidWhichBinds::ReceivedEvent.prune!` deletes `jti` rows older than the 7-day window. Schedule it daily.
|
|
96
|
+
|
|
97
|
+
## Scope (v1)
|
|
98
|
+
|
|
99
|
+
- **Web sign-in only.** The native/API callback (`/api/oauth/callback/void_which_binds`) is refused, because it holds no server-side flow state: core never passes it a PKCE verifier (a client-supplied `code_verifier` is not forwarded) or a nonce. Core's API social login grant (`/authorize?connection=void_which_binds`) also refuses a PKCE provider before it starts.
|
|
100
|
+
- **One issuer per app.** standard_id keys the account link by provider name.
|
|
101
|
+
- An ID token without `email` cannot create an account, because standard_id needs an email address. moneta includes `email` with the `email` scope when its directory has one.
|
|
102
|
+
|
|
103
|
+
## Testing
|
|
104
|
+
|
|
105
|
+
```ruby
|
|
106
|
+
require "standard_id/void_which_binds/testing"
|
|
107
|
+
|
|
108
|
+
key = StandardId::VoidWhichBinds::Testing.key("current") # test-only seed
|
|
109
|
+
StandardId.config.social.void_which_binds_jwks = StandardId::VoidWhichBinds::Testing.jwks(key)
|
|
110
|
+
StandardId.config.social.void_which_binds_jwks_pins = [StandardId::VoidWhichBinds::Testing.thumbprint(key)]
|
|
111
|
+
token = StandardId::VoidWhichBinds::Testing.id_token(key, iss:, sub:, aud:, iat: Time.now.to_i, nonce:, org:, email:, email_verified: true)
|
|
112
|
+
set = StandardId::VoidWhichBinds::Testing.security_event(key, iss:, aud:, iat:, toe:, sub:, event: StandardId::VoidWhichBinds::SecurityEvent::SESSION_REVOKED, reason: "role_changed", initiating_entity: "admin")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
bundle install
|
|
119
|
+
bundle exec rspec # includes every golden vector
|
|
120
|
+
bundle exec rubocop --config .rubocop.yml
|
|
121
|
+
scripts/check-vector-drift.sh # spec/vectors vs void-which-binds-go at the pinned ref
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`spec/vectors/oidc` and `spec/vectors/secevent` are verbatim copies of void-which-binds-go's `testvectors/vectors/`, pinned by `spec/vectors/VOID_WHICH_BINDS_GO_REF` (currently the signed tag v0.24.0, `3f97570`). Never edit them by hand: copy them again and bump the pin in the same change.
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT. See [LICENSE](LICENSE).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StandardId
|
|
4
|
+
module VoidWhichBinds
|
|
5
|
+
# The ID token behind one browser session: its subject and its iat
|
|
6
|
+
# (login_iat), so a session-revoked SET revokes exactly the sessions with
|
|
7
|
+
# login_iat <= toe and spares newer ones.
|
|
8
|
+
class Login < StandardId::ApplicationRecord
|
|
9
|
+
self.table_name = "standard_id_void_which_binds_logins"
|
|
10
|
+
|
|
11
|
+
validates :session_id, :iss, :sub, :login_iat, presence: true
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StandardId
|
|
4
|
+
module VoidWhichBinds
|
|
5
|
+
# A SET this relying party has applied (or acknowledged), keyed by
|
|
6
|
+
# (iss, jti), so a redelivered, retried or reconciled copy is answered 202
|
|
7
|
+
# and does nothing (ADR-0023, the RP's contract, step 2). Written in the
|
|
8
|
+
# same transaction as the event's effects.
|
|
9
|
+
class ReceivedEvent < StandardId::ApplicationRecord
|
|
10
|
+
self.table_name = "standard_id_void_which_binds_received_events"
|
|
11
|
+
|
|
12
|
+
OUTCOMES = %w[applied acknowledged].freeze
|
|
13
|
+
|
|
14
|
+
validates :iss, :jti, :sub, :event_type, :iat, :toe, presence: true
|
|
15
|
+
validates :outcome, inclusion: { in: OUTCOMES }
|
|
16
|
+
|
|
17
|
+
# Deletes rows whose SET is older than the verifier's window: a copy of
|
|
18
|
+
# such a SET is refused on its iat (iat_too_old) before the jti is ever
|
|
19
|
+
# consulted, so its row no longer protects anything. Keeps a day's
|
|
20
|
+
# margin past the 7-day window.
|
|
21
|
+
def self.prune!(now: Time.now.to_i)
|
|
22
|
+
where(iat: ...(now - SecurityEvent::MAX_AGE - 86_400)).delete_all
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module StandardId
|
|
4
|
+
module VoidWhichBinds
|
|
5
|
+
# One (iss, sub) subject named by moneta's ID tokens and SETs, and the
|
|
6
|
+
# relying party's durable state about it (ADR-0023, the RP's contract,
|
|
7
|
+
# step 3):
|
|
8
|
+
#
|
|
9
|
+
# - revoked_toe: the revocation watermark (#135), the latest
|
|
10
|
+
# session-revoked toe applied, for unknown subjects too; never lowered.
|
|
11
|
+
# - last_login_iat: the largest ID-token iat a session was created from.
|
|
12
|
+
# - disabled_toe: the toe of an applied account-disabled, until a login
|
|
13
|
+
# whose iat is greater re-enables the link.
|
|
14
|
+
#
|
|
15
|
+
# Keyed by the full iss_sub subject, not sub alone: another issuer's toe
|
|
16
|
+
# values come from another clock and do not order against these.
|
|
17
|
+
class Subject < StandardId::ApplicationRecord
|
|
18
|
+
self.table_name = "standard_id_void_which_binds_subjects"
|
|
19
|
+
|
|
20
|
+
validates :iss, :sub, presence: true
|
|
21
|
+
|
|
22
|
+
# The row for (iss, sub), created if absent, locked FOR UPDATE for the
|
|
23
|
+
# rest of the caller's transaction, so a SET and a login for the same
|
|
24
|
+
# subject serialise. Must be called inside a transaction.
|
|
25
|
+
def self.lock_for!(iss, sub)
|
|
26
|
+
create_or_find_by!(iss: iss, sub: sub)
|
|
27
|
+
lock.find_by!(iss: iss, sub: sub)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Raises the watermark to toe if toe is greater (or none is stored).
|
|
31
|
+
def advance_watermark!(toe)
|
|
32
|
+
return if revoked_toe && revoked_toe >= toe
|
|
33
|
+
|
|
34
|
+
update!(revoked_toe: toe)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Why a session may not be created from an ID token issued at login_iat,
|
|
38
|
+
# or nil: the watermark refuses login_iat <= revoked_toe (a tie
|
|
39
|
+
# included), and a disabled link refuses login_iat <= disabled_toe.
|
|
40
|
+
def refusal_for(login_iat)
|
|
41
|
+
return "session_revoked" if revoked_toe && SecurityEvent.revokes_session?(revoked_toe, login_iat)
|
|
42
|
+
return "link_disabled" if disabled_toe && !SecurityEvent.reenables_link?(disabled_toe, login_iat)
|
|
43
|
+
|
|
44
|
+
nil
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Mounted by the host at /auth/void_which_binds (the install generator adds
|
|
4
|
+
# mount StandardId::VoidWhichBinds::Engine => "/auth/void_which_binds"
|
|
5
|
+
# to config/routes.rb), so moneta's SET push endpoint is
|
|
6
|
+
# POST /auth/void_which_binds/events.
|
|
7
|
+
StandardId::VoidWhichBinds::Engine.routes.draw do
|
|
8
|
+
post "events", to: StandardId::VoidWhichBinds::EventsEndpoint, as: :events
|
|
9
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# The relying-party state ADR-0023's contract needs (standard_id-void_which_binds).
|
|
2
|
+
#
|
|
3
|
+
# - standard_id_void_which_binds_subjects: one row per (iss, sub), the
|
|
4
|
+
# subject moneta's SETs and ID tokens name. `revoked_toe` is the revocation
|
|
5
|
+
# watermark (#135): the latest session-revoked toe applied, raised and never
|
|
6
|
+
# lowered, recorded for unknown subjects too. `last_login_iat` is the largest
|
|
7
|
+
# ID-token iat a session was created from; `disabled_toe` the toe of an
|
|
8
|
+
# applied account-disabled, cleared by a later login with iat > it.
|
|
9
|
+
# - standard_id_void_which_binds_logins: the iat of the ID token that created
|
|
10
|
+
# each browser session (login_iat), so a session-revoked SET revokes exactly
|
|
11
|
+
# the sessions with login_iat <= toe. The link to the account stays
|
|
12
|
+
# standard_id's own (provider, sub) row in standard_id_social_identities.
|
|
13
|
+
# - standard_id_void_which_binds_received_events: every applied SET's jti, so a
|
|
14
|
+
# redelivery is answered 202 and does nothing. Rows whose iat is older than
|
|
15
|
+
# 7 days may be pruned (an older SET is refused on its iat anyway).
|
|
16
|
+
#
|
|
17
|
+
# New, empty tables: nothing existing is rewritten or backfilled.
|
|
18
|
+
class CreateStandardIdVoidWhichBindsTables < ActiveRecord::Migration[8.0]
|
|
19
|
+
include StandardId::MigrationHelpers
|
|
20
|
+
|
|
21
|
+
def change
|
|
22
|
+
create_table :standard_id_void_which_binds_subjects, id: primary_key_type do |t|
|
|
23
|
+
t.string :iss, null: false
|
|
24
|
+
t.string :sub, null: false
|
|
25
|
+
t.bigint :revoked_toe
|
|
26
|
+
t.bigint :last_login_iat
|
|
27
|
+
t.bigint :disabled_toe
|
|
28
|
+
|
|
29
|
+
t.timestamps
|
|
30
|
+
end
|
|
31
|
+
add_index :standard_id_void_which_binds_subjects, [:iss, :sub], unique: true,
|
|
32
|
+
name: "index_standard_id_vwb_subjects_on_iss_and_sub"
|
|
33
|
+
|
|
34
|
+
create_table :standard_id_void_which_binds_logins, id: primary_key_type do |t|
|
|
35
|
+
t.references :session, type: foreign_key_type, null: false, index: { unique: true, name: "index_standard_id_vwb_logins_on_session_id" },
|
|
36
|
+
foreign_key: { to_table: :standard_id_sessions, on_delete: :cascade }
|
|
37
|
+
t.string :iss, null: false
|
|
38
|
+
t.string :sub, null: false
|
|
39
|
+
t.bigint :login_iat, null: false
|
|
40
|
+
|
|
41
|
+
t.timestamps
|
|
42
|
+
end
|
|
43
|
+
add_index :standard_id_void_which_binds_logins, [:iss, :sub, :login_iat],
|
|
44
|
+
name: "index_standard_id_vwb_logins_on_subject_and_login_iat"
|
|
45
|
+
|
|
46
|
+
create_table :standard_id_void_which_binds_received_events, id: primary_key_type do |t|
|
|
47
|
+
t.string :iss, null: false
|
|
48
|
+
t.string :jti, null: false
|
|
49
|
+
t.string :sub, null: false
|
|
50
|
+
t.string :event_type, null: false
|
|
51
|
+
t.bigint :iat, null: false
|
|
52
|
+
t.bigint :toe, null: false
|
|
53
|
+
t.string :txn
|
|
54
|
+
# applied | acknowledged (applied by watermark, or an unknown subject)
|
|
55
|
+
t.string :outcome, null: false
|
|
56
|
+
|
|
57
|
+
t.timestamps
|
|
58
|
+
end
|
|
59
|
+
add_index :standard_id_void_which_binds_received_events, [:iss, :jti], unique: true,
|
|
60
|
+
name: "index_standard_id_vwb_received_events_on_iss_and_jti"
|
|
61
|
+
add_index :standard_id_void_which_binds_received_events, :iat,
|
|
62
|
+
name: "index_standard_id_vwb_received_events_on_iat"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators"
|
|
4
|
+
|
|
5
|
+
module StandardId
|
|
6
|
+
module VoidWhichBinds
|
|
7
|
+
module Generators
|
|
8
|
+
# Installs Void-Which-Binds sign-in in a host Rails app:
|
|
9
|
+
#
|
|
10
|
+
# - config/initializers/standard_id_void_which_binds.rb, the
|
|
11
|
+
# social.void_which_binds_* fields wired to ENV (a separate file from
|
|
12
|
+
# standard_id.rb, so removing the provider is deleting one file);
|
|
13
|
+
# - the migration for the watermark, login and jti tables;
|
|
14
|
+
# - the SET push endpoint's mount in config/routes.rb.
|
|
15
|
+
#
|
|
16
|
+
# Idempotent: an existing initializer, migration or mount is skipped.
|
|
17
|
+
class InstallGenerator < Rails::Generators::Base
|
|
18
|
+
source_root File.expand_path("templates", __dir__)
|
|
19
|
+
|
|
20
|
+
INITIALIZER_PATH = "config/initializers/standard_id_void_which_binds.rb"
|
|
21
|
+
MIGRATION_NAME = "create_standard_id_void_which_binds_tables"
|
|
22
|
+
MOUNT = %(mount StandardId::VoidWhichBinds::Engine => "/auth/void_which_binds")
|
|
23
|
+
|
|
24
|
+
desc "Installs StandardId Void-Which-Binds: initializer, migration and the SET endpoint mount."
|
|
25
|
+
|
|
26
|
+
class_option :skip_initializer, type: :boolean, default: false, desc: "Do not write #{INITIALIZER_PATH}"
|
|
27
|
+
class_option :skip_migration, type: :boolean, default: false, desc: "Do not copy the migration"
|
|
28
|
+
class_option :skip_route, type: :boolean, default: false, desc: "Do not mount the SET endpoint"
|
|
29
|
+
class_option :force, type: :boolean, default: false, desc: "Overwrite #{INITIALIZER_PATH} if it already exists"
|
|
30
|
+
|
|
31
|
+
def copy_initializer
|
|
32
|
+
return say_status("skip", "#{INITIALIZER_PATH} (--skip-initializer)", :yellow) if options[:skip_initializer]
|
|
33
|
+
|
|
34
|
+
if File.exist?(File.join(destination_root, INITIALIZER_PATH)) && !options[:force]
|
|
35
|
+
return say_status("identical", "#{INITIALIZER_PATH} (already exists; pass --force to overwrite)", :blue)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
template "initializer.rb.erb", INITIALIZER_PATH, force: options[:force]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def copy_migration
|
|
42
|
+
return say_status("skip", "migration (--skip-migration)", :yellow) if options[:skip_migration]
|
|
43
|
+
|
|
44
|
+
existing = Dir[File.join(destination_root, "db/migrate/*_#{MIGRATION_NAME}*.rb")]
|
|
45
|
+
return say_status("identical", "db/migrate/*_#{MIGRATION_NAME}.rb (already installed)", :blue) if existing.any?
|
|
46
|
+
|
|
47
|
+
source = File.expand_path("../../../../../db/migrate/20261005000000_#{MIGRATION_NAME}.rb", __dir__)
|
|
48
|
+
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
49
|
+
copy_file source, "db/migrate/#{timestamp}_#{MIGRATION_NAME}.standard_id_void_which_binds.rb"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def mount_engine
|
|
53
|
+
return say_status("skip", "route (--skip-route)", :yellow) if options[:skip_route]
|
|
54
|
+
|
|
55
|
+
routes = File.join(destination_root, "config/routes.rb")
|
|
56
|
+
return say_status("skip", "config/routes.rb not found; add: #{MOUNT}", :yellow) unless File.exist?(routes)
|
|
57
|
+
return say_status("identical", "SET endpoint mount (already in config/routes.rb)", :blue) if File.read(routes).include?("StandardId::VoidWhichBinds::Engine")
|
|
58
|
+
|
|
59
|
+
route MOUNT
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def print_hints
|
|
63
|
+
say ""
|
|
64
|
+
say "=" * 79
|
|
65
|
+
say "StandardId Void-Which-Binds installed. Run bin/rails db:migrate, then set:"
|
|
66
|
+
say ""
|
|
67
|
+
say " VOID_WHICH_BINDS_CLIENT_ID this app's client_id in the org's moneta"
|
|
68
|
+
say " VOID_WHICH_BINDS_CLIENT_SECRET its client secret (client_secret_basic)"
|
|
69
|
+
say " VOID_WHICH_BINDS_ISSUER moneta's https origin, no trailing slash"
|
|
70
|
+
say " VOID_WHICH_BINDS_ORG the org id, ed25519:<64 hex>"
|
|
71
|
+
say " VOID_WHICH_BINDS_JWKS_PINS pinned assert-key thumbprints, comma-separated"
|
|
72
|
+
say ""
|
|
73
|
+
say "Register with moneta: redirect URI <origin>/auth/callback/void_which_binds"
|
|
74
|
+
say "and SET push endpoint <origin>/auth/void_which_binds/events, for EVERY origin."
|
|
75
|
+
say "=" * 79
|
|
76
|
+
say ""
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Void-Which-Binds (moneta) sign-in for StandardId (ADR-0023).
|
|
4
|
+
#
|
|
5
|
+
# These fields are declared by the standard_id-void_which_binds gem; they do
|
|
6
|
+
# not exist without it in the Gemfile. A field this file does not assign falls
|
|
7
|
+
# back to the ENV variable named after it, upper-cased (standard_id >= 0.42).
|
|
8
|
+
#
|
|
9
|
+
# void_which_binds_client_id switches the provider on; while it is set, the
|
|
10
|
+
# client secret, issuer, org and pins are required (StandardId's boot check).
|
|
11
|
+
StandardId.configure do |config|
|
|
12
|
+
config.social.void_which_binds_client_id = ENV.fetch("VOID_WHICH_BINDS_CLIENT_ID", nil)
|
|
13
|
+
config.social.void_which_binds_client_secret = ENV.fetch("VOID_WHICH_BINDS_CLIENT_SECRET", nil)
|
|
14
|
+
# moneta's public https origin, byte for byte as its tokens spell it.
|
|
15
|
+
config.social.void_which_binds_issuer = ENV.fetch("VOID_WHICH_BINDS_ISSUER", nil)
|
|
16
|
+
# The org id ("ed25519:<64 hex>") every ID token's `org` must equal.
|
|
17
|
+
config.social.void_which_binds_org = ENV.fetch("VOID_WHICH_BINDS_ORG", nil)
|
|
18
|
+
# RFC 7638 thumbprints of moneta's `assert` key (and `next`, during a
|
|
19
|
+
# rotation). The JWKS is fetched from the issuer but is never a trust root:
|
|
20
|
+
# only pinned keys verify.
|
|
21
|
+
config.social.void_which_binds_jwks_pins = ENV.fetch("VOID_WHICH_BINDS_JWKS_PINS", "").split(",")
|
|
22
|
+
|
|
23
|
+
# Staff accounts may sign in ONLY with Void-Which-Binds, and a roster removal
|
|
24
|
+
# locks them. Uncomment and adapt the predicate to switch it on:
|
|
25
|
+
#
|
|
26
|
+
# config.social.void_which_binds_staff_predicate = ->(account) { account.staff? }
|
|
27
|
+
# config.login_method_policy = StandardId::VoidWhichBinds.staff_policy
|
|
28
|
+
end
|