graphql-armory 0.1.0.pre2 → 0.1.0.pre4
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 +17 -0
- data/MIGRATING.md +1 -1
- data/README.md +21 -274
- data/docs/authorization.md +264 -0
- data/docs/encrypted-ids.md +136 -0
- data/docs/persisted-queries.md +184 -0
- data/lib/graphql/armory/authorization/integration.rb +3 -2
- data/lib/graphql/armory/encoder/default.rb +59 -0
- data/lib/graphql/armory/encoder/legacy.rb +34 -0
- data/lib/graphql/armory/encoder/versioned.rb +67 -0
- data/lib/graphql/armory/encoder.rb +137 -0
- data/lib/graphql/armory/ids.rb +76 -0
- data/lib/graphql/armory/persisted_queries/manifest.rb +109 -0
- data/lib/graphql/armory/persisted_queries.rb +144 -0
- data/lib/graphql/armory/version.rb +1 -1
- data/lib/graphql/armory.rb +3 -0
- metadata +11 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5f463135c3578c6248c02f5610cb6bd1bc3f88fe9c26867e8cbd5164c84be408
|
|
4
|
+
data.tar.gz: 0344af8ea82c901fb5ad36cd1d236039f30afe3969142305b3e9b48d0890e5ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 171b49d43c89c1c306949b7e30c56aa71687ccff9f3028f99e8b5f181f4a80b650d8a58e996090013bfa8e800632848109e557842f8ee78aecffbf0893d8d14a
|
|
7
|
+
data.tar.gz: 477b8904c178b41c690f2c308004f0d0a8f441d4df144e4ff2cb4e1a06babe6a33c401728edfcc7ebfd0a14c8ae336c8d7ce12bf4de0944b11e2171cdc02c0c8
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.0.pre4 (2026-10-29)
|
|
6
|
+
|
|
7
|
+
Persisted queries / operation allowlist (roadmap module 3). Docs: `docs/persisted-queries.md`.
|
|
8
|
+
|
|
9
|
+
- Persisted queries, part 1: `GraphQL::Armory::PersistedQueries::Manifest` loads Apollo's persisted query manifest or Relay's persisted output, checks every id is the digest of its query (sha256, md5 or sha1) and parses each query once; any problem raises at boot.
|
|
10
|
+
- Persisted queries, part 2: `use GraphQL::Armory::PersistedQueries, store:, strict:` runs the stored operation a request names by id (`context[:operation_id]`; `PersistedQueries.operation_id(params)` reads it from `operationId`, `extensions.operationId` or `extensions.persistedQuery.sha256Hash`). Unknown ids and mismatched queries are refused; strict mode refuses raw queries unless the context holds `armory_allow_raw_query: true`. Docs: `docs/persisted-queries.md`.
|
|
11
|
+
|
|
12
|
+
## 0.1.0.pre3 (2026-10-29)
|
|
13
|
+
|
|
14
|
+
Encrypted, versioned IDs and cursors (roadmap module 2), and a docs page per module.
|
|
15
|
+
|
|
16
|
+
- Encrypted IDs and cursors, part 4: `use GraphQL::Armory::IDs` defines `id_from_object` and `object_from_id` with encrypted IDs (default encoder unless `encoder:`); Base types are looked up inside the user's scope, other types through `find:`; every ID it cannot honour answers `null`.
|
|
17
|
+
- Encrypted IDs and cursors, part 3: `Encoder.default`, keyed by `GRAPHQL_ARMORY_KEY` or, in Rails, by a key derived with HKDF from `secret_key_base` (not from `Rails.application.key_generator`, whose digest changes during boot); it raises when the schema loads without either.
|
|
18
|
+
- Encrypted IDs and cursors, part 2: `Encoder.versioned(newest, ..., oldest)` and `decode_versioned` to rotate keys without breaking clients; `Encoder::Legacy` reads graphql-ruby's default base64 to add encryption to an existing API.
|
|
19
|
+
- Encrypted IDs and cursors, part 1: `GraphQL::Armory::Encoder` (AES-256-GCM, HKDF subkeys, stable IDs, random-nonce cursors, `key`, `tag`, `codec`). Works as `cursor_encoder` and inside `object_from_id`; an ID it refuses in `loads:` is answered like a missing record. See `docs/encrypted-ids.md`.
|
|
20
|
+
- Docs: each module has its own page in `docs/` (the problem, the solution, how to use it, guarantees and limits). The authorization guide moved from the README to `docs/authorization.md`; the README now lists the modules.
|
|
21
|
+
|
|
5
22
|
## 0.1.0.pre2 (2026-10-29)
|
|
6
23
|
|
|
7
24
|
Closes the known gaps of the authorization module.
|
data/MIGRATING.md
CHANGED
|
@@ -10,7 +10,7 @@ class AppSchema < GraphQL::Schema
|
|
|
10
10
|
end
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Make your base classes include `GraphQL::Armory::Authorization::Base` (see
|
|
13
|
+
Make your base classes include `GraphQL::Armory::Authorization::Base` (see "How to use it" in [docs/authorization.md](docs/authorization.md)). Types that inherit from them are now covered; run the audit to see the rest.
|
|
14
14
|
|
|
15
15
|
## 2. Replace `authorized?` with a rule
|
|
16
16
|
|
data/README.md
CHANGED
|
@@ -4,273 +4,39 @@
|
|
|
4
4
|
|
|
5
5
|
# graphql-armory
|
|
6
6
|
|
|
7
|
-
Open-source extensions for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), built on its public extension points: no fork, no monkey patching.
|
|
7
|
+
Open-source extensions for [graphql-ruby](https://github.com/rmosolgo/graphql-ruby), built on its public extension points: no fork, no monkey patching. One gem, one module at a time; each module has its own page in [`docs/`](docs) with the problem it solves, how to use it, and its limits.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **Nothing is open by default.** A type or field no rule covers answers `null` (or an error), never data.
|
|
12
|
-
- **Lists only contain what the user may see**, including connections: the scope runs before pagination and counting.
|
|
13
|
-
- **Lookups by ID cannot leak** (IDOR). A record you may not read and a record that does not exist look identical.
|
|
14
|
-
- **An audit tells you what you forgot**, from a rake task or an RSpec matcher, so CI fails instead of production leaking.
|
|
15
|
-
|
|
16
|
-
> **Status: early development (0.1, unreleased).** Pundit and CanCanCan adapters. Not published yet.
|
|
9
|
+
> **Status: early development.** Prereleases on RubyGems (`0.1.0.pre4`). The API may change before 1.0.
|
|
17
10
|
|
|
18
11
|
## Install
|
|
19
12
|
|
|
20
13
|
```ruby
|
|
21
|
-
gem "graphql-armory", "~> 0.1.0.
|
|
22
|
-
gem "pundit" # or "cancancan",
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Requires Ruby >= 3.1 and graphql >= 2.4. `GraphQL::Execution::Next` is supported from graphql 2.6.2 (see [Engines](#engines)).
|
|
26
|
-
|
|
27
|
-
## Quick start
|
|
28
|
-
|
|
29
|
-
Your policies stay plain Pundit. The only new thing is where the rules are declared:
|
|
30
|
-
|
|
31
|
-
```ruby
|
|
32
|
-
class BaseField < GraphQL::Schema::Field
|
|
33
|
-
include GraphQL::Armory::Authorization::Base
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class BaseObject < GraphQL::Schema::Object
|
|
37
|
-
include GraphQL::Armory::Authorization::Base
|
|
38
|
-
field_class BaseField
|
|
39
|
-
default_action :read # every type is checked with InvoicePolicy#read?, AccountPolicy#read?...
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
class InvoiceType < BaseObject
|
|
43
|
-
field :number, String, null: false
|
|
44
|
-
field :internal_notes, String, authorize: :manage # this field asks InvoicePolicy#manage?
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
class QueryType < BaseObject
|
|
48
|
-
authorize :none, reason: "root type; each field declares its own rule"
|
|
49
|
-
field :invoices, [InvoiceType], null: false, authorize: :none, reason: "narrowed by InvoicePolicy::Scope"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
class AppSchema < GraphQL::Schema
|
|
53
|
-
query QueryType
|
|
54
|
-
use GraphQL::Armory::Authorization, adapter: :pundit
|
|
55
|
-
end
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
The actor is `context[:current_user]`. A complete, tested version lives in [`examples/invoices.rb`](examples/invoices.rb).
|
|
59
|
-
|
|
60
|
-
### Rules
|
|
61
|
-
|
|
62
|
-
| Declaration | Meaning |
|
|
63
|
-
|---|---|
|
|
64
|
-
| `default_action :read` | Default rule for every type below this base class. |
|
|
65
|
-
| `authorize :manage` | This type is checked with `manage?` instead. |
|
|
66
|
-
| `authorize :read, model: Invoice` | The model when it is not named like the type. |
|
|
67
|
-
| `field ..., authorize: :manage` | The field asks another question of the same policy. |
|
|
68
|
-
| `authorize :none, reason: "..."` | Explicit bypass. A reason is required and appears in the audit. |
|
|
69
|
-
|
|
70
|
-
A bypass does not propagate: a field of a bypassed type still needs its own rule, or it is denied.
|
|
71
|
-
|
|
72
|
-
### What happens on denial
|
|
73
|
-
|
|
74
|
-
```ruby
|
|
75
|
-
use GraphQL::Armory::Authorization, adapter: :pundit, on_unauthorized: :null # default
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
| Mode | Client sees | Use |
|
|
79
|
-
|---|---|---|
|
|
80
|
-
| `:null` | `null`, no error | Default. Reveals nothing. |
|
|
81
|
-
| `:error` | `"Not found"`, code `NOT_FOUND`, identical on every path | When clients need to tell. |
|
|
82
|
-
| `:raise` | `NotAuthorizedError` naming only the type | When your app rescues it. |
|
|
83
|
-
|
|
84
|
-
Denied non-null fields raise the generic "Not found" error, because GraphQL cannot return `null` there (on Execution::Next a denied object in a non-null position answers graphql-ruby's own "Cannot return null for non-nullable field", and `:raise` messages are prefixed with the field path). `find_by:` lookups always answer `null` in every mode: a missing ID cannot raise, and a foreign ID must look the same.
|
|
85
|
-
|
|
86
|
-
### Lists, connections and lookups
|
|
87
|
-
|
|
88
|
-
Lists of a type are narrowed through `InvoicePolicy::Scope` (relations) or by calling the policy per item (arrays). Return a relation when you can: SQL filters before Ruby sees anything.
|
|
89
|
-
|
|
90
|
-
```ruby
|
|
91
|
-
field :invoice, InvoiceType, authorize: :none, reason: "looked up through the scope", find_by: :id do
|
|
92
|
-
argument :id, ID
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
field :invoice_via_ref, InvoiceType, authorize: :none, reason: "loaded through the scope" do
|
|
96
|
-
argument :invoice_id, ID, loads: InvoiceType
|
|
97
|
-
end
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
`find_by:` and `loads:` (also inside input objects whose base class includes `Base`) look the record up **inside the user's scope**, so another tenant's ID answers exactly like a missing one. Opt out of the scope for a field's `loads:` only on purpose, with `load_through_scope: false`; the audit lists it. On `Execution::Next` the opt-out also reaches `loads:` nested in that field's input objects (the interpreter keeps those scoped), and the audit lists them too (`Query.field(filter.invoice_id)`). An input object that overrides `object_from_id` or defines `load_<argument>` itself is honoured on the interpreter and not seen by the audit.
|
|
101
|
-
|
|
102
|
-
**Global IDs.** When your schema defines `object_from_id` (Relay global IDs), `loads:` decodes the id with it, refuses a record of another model, and looks the record up again inside the scope (one extra query per load). Without `object_from_id`, the id is the primary key. `object_from_id` must return the record itself, not a lazy value: a lazy value is denied. A decoder that raises `ActiveRecord::RecordNotFound` (like `GlobalID.find`) or `ArgumentError` (a malformed id) is answered like a missing record; other errors propagate. `loads:` of an interface or union (for example `Types::Node`) raises `ConfigurationError`: load a concrete type. Composite primary keys are not supported.
|
|
103
|
-
|
|
104
|
-
## The audit
|
|
105
|
-
|
|
106
|
-
```ruby
|
|
107
|
-
GraphQL::Armory::Authorization::Audit.(AppSchema) # => report with problems
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
```ruby
|
|
111
|
-
# spec/schema_spec.rb
|
|
112
|
-
require "graphql/armory/authorization/rspec"
|
|
113
|
-
expect(AppSchema).to be_fully_authorized
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
```ruby
|
|
117
|
-
# Rakefile (or a Rails task file): exits 1 when anything is uncovered
|
|
118
|
-
load "tasks/graphql_armory.rake"
|
|
119
|
-
# bundle exec rake "graphql_armory:audit[AppSchema]"
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
It reports types nobody protects (a base class that never included `Base`), types and fields with no rule, policies missing the method or `Scope`, `loads:` that skip the scope, and lists every declared bypass with its reason.
|
|
123
|
-
|
|
124
|
-
## CanCanCan
|
|
125
|
-
|
|
126
|
-
Same schema, different adapter. Your types and fields do not change:
|
|
127
|
-
|
|
128
|
-
```ruby
|
|
129
|
-
use GraphQL::Armory::Authorization, adapter: :cancan
|
|
14
|
+
gem "graphql-armory", "~> 0.1.0.pre4" # a prerelease: `gem install graphql-armory --pre`
|
|
15
|
+
gem "pundit" # or "cancancan", for the authorization module
|
|
130
16
|
```
|
|
131
17
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
| Question | CanCanCan call |
|
|
135
|
-
|---|---|
|
|
136
|
-
| Can this object be seen? | `ability.can?(:read, object)` |
|
|
137
|
-
| Can this field be seen? | `ability.can?(:manage, object, :internal_notes)` for a field that declares `authorize: :manage`: the attribute is passed, because `can :read, User, [:username]` makes `can?(:read, user)` true for the whole object |
|
|
138
|
-
| Which items of a list? | `Model.accessible_by(ability, :read)`, still a paginable relation; Arrays are filtered with `can?` |
|
|
139
|
-
|
|
140
|
-
**Block-only rules.** `can(:read, Invoice) { |i| ... }` cannot be turned into SQL, so `accessible_by` fails. The adapter raises `MissingScopeError` instead of guessing. To accept the cost, declare it on the type: `authorize :read, scope: :in_memory`. Lists are then filtered with `can?` one by one and efficient pagination is lost; `find_by:` and `loads:` find the record and then ask `can?`. Fields covered by the type's rule are not asked about their attribute: give the ones an attribute rule must hide their own `authorize: :action`. Options the adapter does not understand (`policy:`, another `scope:`) raise `ConfigurationError`.
|
|
18
|
+
Requires Ruby >= 3.1 and graphql >= 2.4.
|
|
141
19
|
|
|
142
|
-
|
|
20
|
+
## Modules
|
|
143
21
|
|
|
144
|
-
|
|
22
|
+
Status: ✅ released, 🚧 in progress, ⬜ not started. Update this table in the same PR that changes a module.
|
|
145
23
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Hide a type or a field from users who may not use it, in introspection and in "did you mean" suggestions:
|
|
149
|
-
|
|
150
|
-
```ruby
|
|
151
|
-
class InvoiceExportType < BaseObject
|
|
152
|
-
authorize :read, model: Invoice, visible_when: :export # InvoicePolicy#export? / can?(:export, Invoice)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
field :internal_notes, String, authorize: :manage, visible_when: :export
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
`visible_when:` is an action like any other, but it is asked **of the model's class, with no record**: `InvoicePolicy.new(user, Invoice).export?` with Pundit, `can?(:export, Invoice)` with CanCanCan. Write a method that decides from the user (`user.admin?`), not from the record. Nothing is hidden unless you declare it, and the audit reports a `visible_when:` action the policy does not define.
|
|
159
|
-
|
|
160
|
-
A hidden member also hides what leads only to it: a root field that returns a hidden type disappears with it.
|
|
161
|
-
|
|
162
|
-
**Schema dumps.** graphql 2.6 builds an ordinary context for `to_definition`, which cannot be told apart from an anonymous request, and an anonymous request must never see hidden members. Ask for the full schema explicitly:
|
|
163
|
-
|
|
164
|
-
```ruby
|
|
165
|
-
AppSchema.to_definition(context: { armory_full_schema: true })
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
Things to know:
|
|
169
|
-
|
|
170
|
-
- **Hiding is not authorization.** A hidden field is absent from the schema, so a query for it fails like a field that never existed. What the user may *read* is still decided by `authorize`.
|
|
171
|
-
- **The policy receives the class.** A policy that reads the record (`record.account_id`) raises `NoMethodError` for a `visible_when:` action; write that action from the user. The error propagates out of `execute`, so make sure your error handler does not echo it.
|
|
172
|
-
- **CanCanCan conditions are not applied to a class.** `can :export, Invoice, account_id: 1` makes the member visible to anyone who holds the rule. For a field, the attribute is passed: `can?(:export, Invoice, :internal_notes)`.
|
|
173
|
-
- **A subclass that redeclares `authorize` replaces the rule**, `visible_when:` included: repeat it.
|
|
174
|
-
- **`visible_when:` on a field needs a type that includes `Base`** (not an interface or a plain type); otherwise it raises `ConfigurationError` when a query selects it.
|
|
175
|
-
- **Static `Schema::Visibility` profiles are not supported** and raise `ConfigurationError`; plain `use Schema::Visibility`, `dynamic: true` and the default warden work.
|
|
176
|
-
|
|
177
|
-
Visibility is computed per query (and memoized inside it). Role-based profile caching across requests is graphql-ruby's `Schema::Visibility` feature and is not wrapped here.
|
|
178
|
-
|
|
179
|
-
## Arguments
|
|
180
|
-
|
|
181
|
-
An argument with no rule is **covered by its field**: the field already decides whether the user may call it. Declare a rule on the arguments that must be stricter, and they are checked when the client sends them:
|
|
182
|
-
|
|
183
|
-
```ruby
|
|
184
|
-
class BaseArgument < GraphQL::Schema::Argument
|
|
185
|
-
include GraphQL::Armory::Authorization::Base
|
|
186
|
-
end
|
|
187
|
-
# in your base field: argument_class BaseArgument
|
|
188
|
-
|
|
189
|
-
field :invoices, [InvoiceType], authorize: :none, reason: "narrowed by the scope" do
|
|
190
|
-
argument :include_internal, Boolean, required: false, authorize: :manage, model: Invoice
|
|
191
|
-
argument :tag, String, required: false, visible_when: :export, model: Invoice
|
|
192
|
-
argument :status, String, required: false, authorize: :none, reason: "public filter"
|
|
193
|
-
end
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
- **`authorize: :manage`** asks the policy about the parent object when it is an instance of the model, otherwise about the model's class (a root field has no record, so write the action from the user). The model is the one the field's type wraps, or `model:` when it wraps none, as on a root field. A denial denies the whole field, with the usual null or error.
|
|
197
|
-
- **Defaults.** graphql-ruby does not check an argument the client left at its default, and the two engines disagree about it (the interpreter skips the check, `Execution::Next` applies the default), so a restricted argument with a `default_value:` is refused with an `ArgumentError`. Sending `false` explicitly counts as using the argument.
|
|
198
|
-
- **Every argument class needs `Base`.** `argument_class` is not inherited: set it on your base field, and also on resolvers, input objects (for restricted arguments nested in a filter) and directives that need it.
|
|
199
|
-
- **`visible_when:`** hides the argument like it hides a field: it is absent from introspection and from suggestions, and a query that uses it fails like an argument that never existed.
|
|
200
|
-
- **`authorize: :none, reason:`** only declares and documents: the audit lists it with its reason.
|
|
201
|
-
- `authorize: true` is refused on an argument, and an argument with no model to ask about raises `ConfigurationError`.
|
|
202
|
-
|
|
203
|
-
## Mutations and resolvers
|
|
204
|
-
|
|
205
|
-
Include `Base` in your base mutation (or resolver) and declare what each one needs. A mutation is an action, not a read, so `default_action` does not apply and **a mutation with no `authorize` is denied**.
|
|
206
|
-
|
|
207
|
-
```ruby
|
|
208
|
-
class Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation
|
|
209
|
-
include GraphQL::Armory::Authorization::Base
|
|
210
|
-
argument_class Types::BaseArgument
|
|
211
|
-
field_class Types::BaseField
|
|
212
|
-
object_class Types::BaseObject
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
class Mutations::ApproveInvoice < Mutations::BaseMutation
|
|
216
|
-
authorize :approve, model: Invoice # InvoicePolicy#approve?(invoice) / can?(:approve, invoice)
|
|
217
|
-
argument :invoice_id, ID, loads: Types::Invoice
|
|
218
|
-
field :invoice, Types::Invoice, null: true
|
|
219
|
-
end
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
- **The record is the loaded one.** The rule runs after `loads:`, once per loaded record of the model (with none loaded, the model's class is asked). `loads:` goes through the user's scope, so a foreign id answers like a missing one.
|
|
223
|
-
- **Denial** follows the schema's `on_unauthorized` mode, like a field (`null`, `"Not found"`, or raise). With `on_denied: :errors` the mutation does not run and answers `{ errors: [{ message: "Not allowed", code: "FORBIDDEN" }] }` as data, so the payload needs an `errors` field.
|
|
224
|
-
- **Payload types** are ordinary objects: declare `authorize :none, reason: "...", covers_fields: true` so their fields are covered by the mutation instead of denied.
|
|
225
|
-
- **`authorize :none, reason:`** documents a mutation anyone may call; the audit lists it with its reason. A mutation with no rule appears as `:no_rule` (for example `Mutation.forgotten`), and a rule the policy does not define as `:adapter`.
|
|
226
|
-
- An unknown `on_denied:` raises `ArgumentError`; a mutation with a rule but no model raises `ConfigurationError`.
|
|
227
|
-
- **Class-level answers are weak.** With no loaded record of the model (no `loads:`, an empty `loads: [ID]`, or a `loads:` of another type) the rule is asked about the model's class: CanCan answers true for anyone holding the right, and a Pundit policy that reads `record` attributes raises. Load the record you are authorizing.
|
|
228
|
-
- **`ready?` runs before authorization** (and, on the interpreter, before a failing `loads:`). Keep it free of side effects.
|
|
229
|
-
- **`loads:` inside an input object** goes through the scope only when your base input object includes `Base` (`class Types::BaseInputObject < GraphQL::Schema::InputObject; include GraphQL::Armory::Authorization::Base; end`); otherwise the audit reports it as `:unscoped_load`.
|
|
230
|
-
- **Do not put `authorize:` on a mutation field or on payload fields**; the mutation's own rule is the one that counts. A subclass that redeclares `authorize :none` is open to everyone, on purpose.
|
|
231
|
-
|
|
232
|
-
## Interfaces and unions
|
|
233
|
-
|
|
234
|
-
They are never authorized themselves: graphql-ruby only runs `authorized?` on the concrete type, and every path ends there (root field, association, each list item, `loads:`, union and interface resolution). A foreign object in a list of a union or an interface comes back `null`, like in any other list. So `include Base` in an interface or a union is refused with a message pointing to the possible types; declare the rule on each concrete type.
|
|
235
|
-
|
|
236
|
-
What an interface adds is its fields, declared once and resolved on many types:
|
|
237
|
-
|
|
238
|
-
- A field with no rule is **covered** by the rule of the Base types that implement the interface (a plain implementer runs no check at all), unless one of them is a bypass (`authorize :none`). Then the field is **denied for every implementer**, because it cannot tell which type it runs on, and the audit reports it (`:field_without_rule`, for example `Document.number`). Declare it (`authorize: :none, reason:` or an action) to fix it.
|
|
239
|
-
- `visible_when:` is not supported on an interface field; put it on the concrete types' fields.
|
|
240
|
-
- `authorize: true` is not valid on an interface field: it is always denied, and the audit reports it. Use an action or `:none`.
|
|
241
|
-
- An interface whose field class does not include `Base`, such as graphql-ruby's built-in Relay `Node`, runs no field check, so its `id` stays readable on a bypassed implementer. The audit reports it (`:unprotected`, `Node.id`); give your own `Node` interface a Base field class if that matters.
|
|
242
|
-
- The audit reports an interface field once, on the interface that declares it, not again on each implementer.
|
|
243
|
-
|
|
244
|
-
## Telemetry
|
|
245
|
-
|
|
246
|
-
Pass `sinks: [->(signal, data) {}]`. Signals are `:allowed`, `:denied`, `:bypassed`; data holds only `type`, `action` and `reason`, never record attributes.
|
|
247
|
-
|
|
248
|
-
## Guarantees and limits
|
|
249
|
-
|
|
250
|
-
Covered by the black-box suite in `spec/security`, on both engines: user A cannot read user B's objects by root field, nested association or `loads:`; lists never contain foreign objects; uncovered types fail closed and show in the audit; a field hidden with `visible?` is absent from introspection and error suggestions (that is graphql-ruby's behaviour, pinned by a test).
|
|
251
|
-
|
|
252
|
-
Policies must return `true`/`false`/`nil`; anything else raises `AdapterError`. Do not use `dataloader.request` inside policies; use `dataloader.with(...).load`.
|
|
253
|
-
|
|
254
|
-
## Engines
|
|
255
|
-
|
|
256
|
-
Both execution engines are tested: the default interpreter and `Execution::Next`. In graphql 2.5.26 to 2.6.1, Next crashes on denied fields, so the gem refuses to run on Next there (`ConfigurationError`). Everything else works from graphql 2.4.
|
|
257
|
-
|
|
258
|
-
## Performance
|
|
259
|
-
|
|
260
|
-
`benchmark/authorization.rb`, 1000 invoices, graphql 2.6.2, Ruby 3.2, Docker on Windows:
|
|
261
|
-
|
|
262
|
-
| Engine | Query | plain | armory (array) | armory (relation) |
|
|
24
|
+
| Order | Module | Status | Docs | Current limits |
|
|
263
25
|
|---|---|---|---|---|
|
|
264
|
-
|
|
|
265
|
-
|
|
|
266
|
-
|
|
|
267
|
-
|
|
|
26
|
+
| 1 | Authorization (Pundit, CanCanCan) | ✅ | [docs/authorization.md](docs/authorization.md) | Released in 0.1.0.pre2 (prerelease). Pundit and CanCanCan (the audit checks less with CanCanCan). Global IDs in `loads:` decoded through `object_from_id`; `loads:` inside input objects scoped with `include Base`. `Execution::Next` needs graphql >= 2.6.2. |
|
|
27
|
+
| 2 | Encrypted, versioned IDs and cursors | ✅ | [docs/encrypted-ids.md](docs/encrypted-ids.md) | Released in 0.1.0.pre4 (prerelease). `Encoder` (AES-256-GCM), versioned chains and `Legacy`, `Encoder.default` (ENV or Rails), `use GraphQL::Armory::IDs`. Composite primary keys not supported. |
|
|
28
|
+
| 3 | Persisted queries / operation allowlist | ✅ | [docs/persisted-queries.md](docs/persisted-queries.md) | Released in 0.1.0.pre4 (prerelease). Allowlist from a build manifest (Apollo, Relay), `use GraphQL::Armory::PersistedQueries` with strict mode. A runtime store (database, sync endpoint) is planned for later. |
|
|
29
|
+
| 4 | Rate limiting | ⬜ | | Research not started. |
|
|
30
|
+
| 5 | Stable (keyset) connections | ⬜ | | Research not started. |
|
|
31
|
+
| 6 | Subscriptions over Pusher / Ably | ⬜ | | Research not started. |
|
|
32
|
+
| 7 | Response caching | ⬜ | | Research not started. |
|
|
33
|
+
| 8 | API versioning (changesets) | ⬜ | | Research not started. |
|
|
34
|
+
| 9 | `@defer` / `@stream` | ⬜ | | Research not started. |
|
|
35
|
+
| 10 | Dashboard | ⬜ | | Research not started. |
|
|
268
36
|
|
|
269
|
-
|
|
37
|
+
Each module starts with its own research before design. A module is ✅ only when it is released and its page documents its limits.
|
|
270
38
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
Coming from hand-written `authorized?` and `scope_items`? See [MIGRATING.md](MIGRATING.md).
|
|
39
|
+
Every module page follows the same outline: **The problem**, **The solution**, **How to use it**, reference sections, **Guarantees and limits**.
|
|
274
40
|
|
|
275
41
|
## Development
|
|
276
42
|
|
|
@@ -287,30 +53,11 @@ GRAPHQL_VERSION="~> 2.4.0" docker compose run --rm test # another graphq
|
|
|
287
53
|
Releases are published from GitHub Actions with RubyGems Trusted Publishing (`.github/workflows/release.yml`): no API key is stored and no OTP is asked. Bump `GraphQL::Armory::VERSION` and the CHANGELOG on `main`, then push the matching tag:
|
|
288
54
|
|
|
289
55
|
```
|
|
290
|
-
git tag v0.1.0.
|
|
56
|
+
git tag v0.1.0.pre4 && git push origin v0.1.0.pre4
|
|
291
57
|
```
|
|
292
58
|
|
|
293
59
|
The workflow checks that the tag matches the version, runs the specs and pushes the gem. It only publishes a tag on a commit of `main`. The `release` environment can require a maintainer's approval first (on a public repository, or a private one on a paid GitHub plan).
|
|
294
60
|
|
|
295
|
-
## Roadmap
|
|
296
|
-
|
|
297
|
-
Status: ✅ done, 🚧 in progress, ⬜ not started. Update this table in the same PR that changes a module.
|
|
298
|
-
|
|
299
|
-
| Order | Module | Status | Current limits |
|
|
300
|
-
|---|---|---|---|
|
|
301
|
-
| 1 | Authorization (Pundit, CanCanCan) | ✅ | Released in 0.1.0.pre2 (prerelease). Pundit and CanCanCan (the audit checks less with CanCanCan). Global IDs in `loads:` decoded through `object_from_id`; `loads:` inside input objects scoped with `include Base`. `Execution::Next` needs graphql >= 2.6.2. |
|
|
302
|
-
| 2 | Encrypted, versioned IDs and cursors | ⬜ | Research not started. |
|
|
303
|
-
| 3 | Persisted queries / operation whitelisting | ⬜ | Research not started. |
|
|
304
|
-
| 4 | Rate limiting | ⬜ | Research not started. |
|
|
305
|
-
| 5 | Stable (keyset) connections | ⬜ | Research not started. |
|
|
306
|
-
| 6 | Subscriptions over Pusher / Ably | ⬜ | Research not started. |
|
|
307
|
-
| 7 | Response caching | ⬜ | Research not started. |
|
|
308
|
-
| 8 | API versioning (changesets) | ⬜ | Research not started. |
|
|
309
|
-
| 9 | `@defer` / `@stream` | ⬜ | Research not started. |
|
|
310
|
-
| 10 | Dashboard | ⬜ | Research not started. |
|
|
311
|
-
|
|
312
|
-
Each module starts with its own research before design. A module is ✅ only when it is released and its limits are documented here.
|
|
313
|
-
|
|
314
61
|
## Related gems
|
|
315
62
|
|
|
316
63
|
- [graphql-armory-rust_parser](https://github.com/israelb/graphql-armory-rust_parser): a GraphQL parser written in Rust, installable as graphql-ruby's default parser.
|