graphql-armory 0.1.0.pre7 → 0.1.0.pre9
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 +81 -0
- data/README.md +6 -5
- data/docs/authorization.md +220 -10
- data/docs/encrypted-ids.md +1 -1
- data/docs/persisted-queries.md +111 -19
- data/docs/rate-limiting.md +32 -11
- data/docs/telemetry.md +31 -8
- data/exe/graphql-armory-publish +6 -0
- data/lib/graphql/armory/authorization/adapters/cancan.rb +17 -4
- data/lib/graphql/armory/authorization/adapters/pundit.rb +79 -14
- data/lib/graphql/armory/authorization/adapters/substitute.rb +4 -1
- data/lib/graphql/armory/authorization/audit/baseline.rb +191 -0
- data/lib/graphql/armory/authorization/audit/command.rb +57 -8
- data/lib/graphql/armory/authorization/audit/denial_hooks.rb +29 -0
- data/lib/graphql/armory/authorization/audit/edge_rules.rb +36 -0
- data/lib/graphql/armory/authorization/audit/findings.rb +35 -0
- data/lib/graphql/armory/authorization/audit/foreign_policies.rb +90 -0
- data/lib/graphql/armory/authorization/audit/input_loads.rb +26 -0
- data/lib/graphql/armory/authorization/audit/interface_rules.rb +42 -0
- data/lib/graphql/armory/authorization/audit/introspection_fields.rb +40 -0
- data/lib/graphql/armory/authorization/audit/library_methods.rb +24 -0
- data/lib/graphql/armory/authorization/audit/observed_rules.rb +58 -0
- data/lib/graphql/armory/authorization/audit/overrides.rb +81 -0
- data/lib/graphql/armory/authorization/audit/own_checks.rb +144 -0
- data/lib/graphql/armory/authorization/audit/payload_reuse.rb +95 -0
- data/lib/graphql/armory/authorization/audit/plain_resolvers.rb +85 -0
- data/lib/graphql/armory/authorization/audit/reach.rb +75 -0
- data/lib/graphql/armory/authorization/audit/report.rb +7 -1
- data/lib/graphql/armory/authorization/audit/type_rules.rb +282 -0
- data/lib/graphql/armory/authorization/audit/visibility_models.rb +83 -0
- data/lib/graphql/armory/authorization/audit.rb +59 -192
- data/lib/graphql/armory/authorization/authorize.rb +35 -9
- data/lib/graphql/armory/authorization/configuration.rb +32 -3
- data/lib/graphql/armory/authorization/definitions.rb +121 -0
- data/lib/graphql/armory/authorization/integration/argument.rb +24 -6
- data/lib/graphql/armory/authorization/integration/field.rb +36 -6
- data/lib/graphql/armory/authorization/integration/object.rb +9 -1
- data/lib/graphql/armory/authorization/integration/resolver.rb +2 -0
- data/lib/graphql/armory/authorization/integration/schema.rb +7 -0
- data/lib/graphql/armory/authorization/integration.rb +36 -4
- data/lib/graphql/armory/authorization/rspec.rb +10 -4
- data/lib/graphql/armory/authorization/rule.rb +24 -3
- data/lib/graphql/armory/authorization/scope.rb +6 -6
- data/lib/graphql/armory/authorization.rb +4 -1
- data/lib/graphql/armory/ids.rb +11 -11
- data/lib/graphql/armory/persisted_queries/manifest.rb +2 -0
- data/lib/graphql/armory/persisted_queries/manifests.rb +69 -0
- data/lib/graphql/armory/persisted_queries/publisher.rb +127 -0
- data/lib/graphql/armory/persisted_queries/redis_store.rb +137 -0
- data/lib/graphql/armory/persisted_queries.rb +55 -16
- data/lib/graphql/armory/railtie.rb +10 -0
- data/lib/graphql/armory/rate_limits/analysis_guard.rb +79 -0
- data/lib/graphql/armory/rate_limits/concurrency.rb +91 -14
- data/lib/graphql/armory/rate_limits/points.rb +91 -14
- data/lib/graphql/armory/rate_limits/time.rb +107 -19
- data/lib/graphql/armory/rate_limits.rb +29 -5
- data/lib/graphql/armory/telemetry.rb +71 -9
- data/lib/graphql/armory/version.rb +1 -1
- data/lib/graphql/armory.rb +1 -0
- data/lib/tasks/graphql_armory.rake +11 -4
- metadata +28 -3
|
@@ -4,16 +4,34 @@ module GraphQL
|
|
|
4
4
|
module Armory
|
|
5
5
|
# Records what a module decided (a request allowed, an ID refused, an operation run) and hands it to its sinks.
|
|
6
6
|
# A sink is anything that responds to `call(signal, data)`: a lambda that logs, a metrics client, or
|
|
7
|
-
# `Telemetry::Notifications`.
|
|
7
|
+
# `Telemetry::Notifications`. A sink that requires a third argument also receives the query's context, to read who
|
|
8
|
+
# asked from it; the context never goes in `data`. Never put record attributes, IDs, keys or queries in `data`: a client chooses
|
|
8
9
|
# those, and they would end up in the app's logs.
|
|
9
10
|
class Telemetry
|
|
10
11
|
class ConfigurationError < Armory::Error; end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
# The class alone: an error's message may quote what the sink was sending, or its credentials.
|
|
14
|
+
DEFAULT_ON_SINK_ERROR = ->(error, signal) { warn("graphql-armory sink failed on #{signal}, request continues: #{error.class}") }
|
|
15
|
+
|
|
16
|
+
def self.build(sinks: [], on_sink_error: nil)
|
|
17
|
+
new(sinks: sinks, on_sink_error: on_sink_error)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# What a sink reads the context through: it decides nothing, so it cannot change who the query runs as. An object in
|
|
21
|
+
# the context is the app's own, and stays as it is. `inspect` stays out of it, so a sink that logs its arguments logs no token.
|
|
22
|
+
class ContextView
|
|
23
|
+
def initialize(context)
|
|
24
|
+
@context = context
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def [](key) = @context[key]
|
|
28
|
+
def fetch(key, *default, &block) = @context.fetch(key, *default, &block)
|
|
29
|
+
def dig(key, *rest) = @context.dig(key, *rest)
|
|
30
|
+
def key?(key) = @context.key?(key)
|
|
31
|
+
def inspect = "#<#{self.class.name}>"
|
|
14
32
|
end
|
|
15
33
|
|
|
16
|
-
def initialize(sinks: [])
|
|
34
|
+
def initialize(sinks: [], on_sink_error: nil)
|
|
17
35
|
# Messages name a class, never `inspect` a value: a metrics client holds its API key.
|
|
18
36
|
raise ConfigurationError, "sinks: must be an Array of callables taking (signal, data), got #{sinks.class}" unless sinks.is_a?(Array)
|
|
19
37
|
|
|
@@ -24,18 +42,56 @@ module GraphQL
|
|
|
24
42
|
raise ConfigurationError, "sink #{sink.is_a?(Module) ? sink.name : sink.class} is not available: the library it reports to is not loaded"
|
|
25
43
|
end
|
|
26
44
|
|
|
27
|
-
|
|
45
|
+
raise ConfigurationError, "on_sink_error: must be a callable taking the error and the signal, found a #{on_sink_error.class}" unless on_sink_error.nil? || on_sink_error.respond_to?(:call)
|
|
46
|
+
|
|
47
|
+
@sinks = sinks.map { |sink| [sink, takes_context?(sink)] }.freeze
|
|
48
|
+
@on_sink_error = on_sink_error || DEFAULT_ON_SINK_ERROR
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Whether anything hears what is recorded.
|
|
52
|
+
def listening?
|
|
53
|
+
!@sinks.empty?
|
|
28
54
|
end
|
|
29
55
|
|
|
30
56
|
# Every sink gets the same frozen data, so one sink (or a subscriber) cannot change what the next one sees.
|
|
31
|
-
def record(signal, **data)
|
|
57
|
+
def record(signal, context: nil, **data)
|
|
32
58
|
return nil if @sinks.empty?
|
|
33
59
|
|
|
34
60
|
data = data.to_h { |key, value| [key, value.is_a?(String) ? value.dup.freeze : value] }.freeze
|
|
35
|
-
@sinks.
|
|
61
|
+
view = ContextView.new(context || {}) if @sinks.any? { |_sink, takes_context| takes_context }
|
|
62
|
+
@sinks.each do |sink, takes_context|
|
|
63
|
+
takes_context ? sink.call(signal, data, view) : sink.call(signal, data)
|
|
64
|
+
rescue StandardError => error
|
|
65
|
+
@on_sink_error.call(error, signal)
|
|
66
|
+
end
|
|
36
67
|
nil
|
|
37
68
|
end
|
|
38
69
|
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
# Only a sink that requires it: one taking `*arguments` or a defaulted third may log whatever it gets. A sink whose
|
|
73
|
+
# `call` cannot be read (a BasicObject, one behind method_missing) takes two.
|
|
74
|
+
def takes_context?(sink)
|
|
75
|
+
callable = Proc === sink || Method === sink ? sink : ::Kernel.instance_method(:method).bind_call(sink, :call)
|
|
76
|
+
return callable.arity == 3 if Proc === callable && !callable.lambda?
|
|
77
|
+
|
|
78
|
+
parameters = callable.parameters
|
|
79
|
+
refuse_uncallable(sink, parameters)
|
|
80
|
+
parameters.count { |type, _| type == :req } == 3
|
|
81
|
+
rescue NameError, TypeError
|
|
82
|
+
false
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# It would raise on every signal, and with sinks that no longer fail the request nobody would notice.
|
|
86
|
+
def refuse_uncallable(sink, parameters)
|
|
87
|
+
required = parameters.count { |type, _| type == :req }
|
|
88
|
+
optional = parameters.count { |type, _| type == :opt }
|
|
89
|
+
rest = parameters.any? { |type, _| type == :rest }
|
|
90
|
+
return unless required > 3 || parameters.any? { |type, _| type == :keyreq } || (required + optional < 2 && !rest)
|
|
91
|
+
|
|
92
|
+
raise ConfigurationError, "sink #{sink.is_a?(Module) ? sink.name : sink.class} must take (signal, data) or (signal, data, context)"
|
|
93
|
+
end
|
|
94
|
+
|
|
39
95
|
# Reports every signal as an ActiveSupport::Notifications event named "<signal>.graphql_armory", with the
|
|
40
96
|
# signal's data as payload: `sinks: [GraphQL::Armory::Telemetry::Notifications]`.
|
|
41
97
|
module Notifications
|
|
@@ -50,10 +106,11 @@ module GraphQL
|
|
|
50
106
|
|
|
51
107
|
# Keeps what was recorded and fails when told, for tests.
|
|
52
108
|
class Substitute
|
|
53
|
-
attr_reader :recorded
|
|
109
|
+
attr_reader :recorded, :contexts
|
|
54
110
|
|
|
55
111
|
def initialize
|
|
56
112
|
@recorded = []
|
|
113
|
+
@contexts = []
|
|
57
114
|
@failure = nil
|
|
58
115
|
end
|
|
59
116
|
|
|
@@ -66,13 +123,18 @@ module GraphQL
|
|
|
66
123
|
@failure = nil
|
|
67
124
|
end
|
|
68
125
|
|
|
69
|
-
def record(signal, **data)
|
|
126
|
+
def record(signal, context: nil, **data)
|
|
127
|
+
@contexts << context
|
|
70
128
|
raise @failure if @failure
|
|
71
129
|
|
|
72
130
|
@recorded << [signal, data]
|
|
73
131
|
nil
|
|
74
132
|
end
|
|
75
133
|
|
|
134
|
+
def listening?
|
|
135
|
+
true
|
|
136
|
+
end
|
|
137
|
+
|
|
76
138
|
def recorded?(signal)
|
|
77
139
|
@recorded.any? { |recorded_signal, _| recorded_signal == signal }
|
|
78
140
|
end
|
data/lib/graphql/armory.rb
CHANGED
|
@@ -3,9 +3,16 @@
|
|
|
3
3
|
require "graphql/armory"
|
|
4
4
|
|
|
5
5
|
namespace :graphql_armory do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exit
|
|
6
|
+
# The Railtie loads this before Rails defines :environment, so the action looks it up when it runs. An app may also load this by hand.
|
|
7
|
+
action = GraphQL::Armory::Authorization::Audit::Command::RAKE_ACTION
|
|
8
|
+
unless Rake::Task.task_defined?("graphql_armory:audit") && Rake::Task["graphql_armory:audit"].actions.include?(action)
|
|
9
|
+
desc "Lists every type, field and argument of a schema that no authorization rule covers (exit 1 if any)"
|
|
10
|
+
task :audit, [:schema, :baseline], &action
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
baseline_action = GraphQL::Armory::Authorization::Audit::Command::BASELINE_ACTION
|
|
14
|
+
unless Rake::Task.task_defined?("graphql_armory:audit_baseline") && Rake::Task["graphql_armory:audit_baseline"].actions.include?(baseline_action)
|
|
15
|
+
desc "Writes the audit's problems to a baseline file, or removes from it what is gone; it never adds to a file that exists"
|
|
16
|
+
task :audit_baseline, [:schema, :baseline], &baseline_action
|
|
10
17
|
end
|
|
11
18
|
end
|
metadata
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: graphql-armory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.0.
|
|
4
|
+
version: 0.1.0.pre9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Israel
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
@@ -33,7 +33,8 @@ description: 'Open-source extensions for graphql-ruby built on its public extens
|
|
|
33
33
|
points. The first module is authorization: deny-by-default coverage, scoped lists
|
|
34
34
|
and connections, IDOR-safe lookups, mutations, interfaces and unions, visibility
|
|
35
35
|
driven by the policy, and a schema audit for CI.'
|
|
36
|
-
executables:
|
|
36
|
+
executables:
|
|
37
|
+
- graphql-armory-publish
|
|
37
38
|
extensions: []
|
|
38
39
|
extra_rdoc_files: []
|
|
39
40
|
files:
|
|
@@ -47,6 +48,7 @@ files:
|
|
|
47
48
|
- docs/persisted-queries.md
|
|
48
49
|
- docs/rate-limiting.md
|
|
49
50
|
- docs/telemetry.md
|
|
51
|
+
- exe/graphql-armory-publish
|
|
50
52
|
- lib/graphql-armory.rb
|
|
51
53
|
- lib/graphql/armory.rb
|
|
52
54
|
- lib/graphql/armory/authorization.rb
|
|
@@ -55,14 +57,32 @@ files:
|
|
|
55
57
|
- lib/graphql/armory/authorization/adapters/pundit.rb
|
|
56
58
|
- lib/graphql/armory/authorization/adapters/substitute.rb
|
|
57
59
|
- lib/graphql/armory/authorization/audit.rb
|
|
60
|
+
- lib/graphql/armory/authorization/audit/baseline.rb
|
|
58
61
|
- lib/graphql/armory/authorization/audit/command.rb
|
|
62
|
+
- lib/graphql/armory/authorization/audit/denial_hooks.rb
|
|
63
|
+
- lib/graphql/armory/authorization/audit/edge_rules.rb
|
|
64
|
+
- lib/graphql/armory/authorization/audit/findings.rb
|
|
65
|
+
- lib/graphql/armory/authorization/audit/foreign_policies.rb
|
|
66
|
+
- lib/graphql/armory/authorization/audit/input_loads.rb
|
|
67
|
+
- lib/graphql/armory/authorization/audit/interface_rules.rb
|
|
68
|
+
- lib/graphql/armory/authorization/audit/introspection_fields.rb
|
|
69
|
+
- lib/graphql/armory/authorization/audit/library_methods.rb
|
|
70
|
+
- lib/graphql/armory/authorization/audit/observed_rules.rb
|
|
71
|
+
- lib/graphql/armory/authorization/audit/overrides.rb
|
|
72
|
+
- lib/graphql/armory/authorization/audit/own_checks.rb
|
|
73
|
+
- lib/graphql/armory/authorization/audit/payload_reuse.rb
|
|
74
|
+
- lib/graphql/armory/authorization/audit/plain_resolvers.rb
|
|
75
|
+
- lib/graphql/armory/authorization/audit/reach.rb
|
|
59
76
|
- lib/graphql/armory/authorization/audit/report.rb
|
|
77
|
+
- lib/graphql/armory/authorization/audit/type_rules.rb
|
|
78
|
+
- lib/graphql/armory/authorization/audit/visibility_models.rb
|
|
60
79
|
- lib/graphql/armory/authorization/authorize.rb
|
|
61
80
|
- lib/graphql/armory/authorization/configuration.rb
|
|
62
81
|
- lib/graphql/armory/authorization/controls/actor.rb
|
|
63
82
|
- lib/graphql/armory/authorization/controls/context.rb
|
|
64
83
|
- lib/graphql/armory/authorization/controls/rule.rb
|
|
65
84
|
- lib/graphql/armory/authorization/controls/subject.rb
|
|
85
|
+
- lib/graphql/armory/authorization/definitions.rb
|
|
66
86
|
- lib/graphql/armory/authorization/errors.rb
|
|
67
87
|
- lib/graphql/armory/authorization/integration.rb
|
|
68
88
|
- lib/graphql/armory/authorization/integration/argument.rb
|
|
@@ -90,8 +110,13 @@ files:
|
|
|
90
110
|
- lib/graphql/armory/persisted_queries.rb
|
|
91
111
|
- lib/graphql/armory/persisted_queries/controls.rb
|
|
92
112
|
- lib/graphql/armory/persisted_queries/manifest.rb
|
|
113
|
+
- lib/graphql/armory/persisted_queries/manifests.rb
|
|
114
|
+
- lib/graphql/armory/persisted_queries/publisher.rb
|
|
115
|
+
- lib/graphql/armory/persisted_queries/redis_store.rb
|
|
93
116
|
- lib/graphql/armory/persisted_queries/store.rb
|
|
117
|
+
- lib/graphql/armory/railtie.rb
|
|
94
118
|
- lib/graphql/armory/rate_limits.rb
|
|
119
|
+
- lib/graphql/armory/rate_limits/analysis_guard.rb
|
|
95
120
|
- lib/graphql/armory/rate_limits/clock.rb
|
|
96
121
|
- lib/graphql/armory/rate_limits/concurrency.rb
|
|
97
122
|
- lib/graphql/armory/rate_limits/controls.rb
|