Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphOS Enterprise: authorization directives #3397

Merged
merged 97 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
522da68
GraphOS Enterprise: authorization directives
Geal Jul 7, 2023
d2c5107
changeset
Geal Jul 7, 2023
19a3325
Apply suggestions from code review
Geal Jul 7, 2023
dfe2c9c
simplify examples
Geal Jul 7, 2023
bbdaef9
Merge branch 'dev' into geal/authorization-directives
Geal Jul 10, 2023
225ebd7
test scope extraction on all test queries
Geal Jul 10, 2023
8f9842f
fix scope extraction from fragments and inline fragments
Geal Jul 10, 2023
c1e82f5
do not forget to set the cache key metadata in warm up
Geal Jul 10, 2023
b64b497
update the query planner cache key after supergraph plugins
Geal Jul 10, 2023
7930a06
lint
Geal Jul 11, 2023
152cfa3
comments from reviews
Geal Jul 12, 2023
413948a
use private entries for the query plan cache metadata
Geal Jul 12, 2023
266d96a
lint
Geal Jul 12, 2023
3293cbb
Merge branch 'dev' into geal/authorization-directives
Geal Jul 12, 2023
13fe51b
fix redis test
Geal Jul 12, 2023
a477937
Merge branch 'dev' into geal/authorization-directives
Geal Jul 13, 2023
c736346
Add sub-header for authentication and authorization
Meschreiber Jul 14, 2023
d537514
Restructure Authorization page
Meschreiber Jul 14, 2023
64e43e8
Copy edit `@authenticated` section
Meschreiber Jul 14, 2023
a92ddae
Copy edit `@requiredScopes` section
Meschreiber Jul 14, 2023
5e2d625
Copy edit "Authorization and `@key` types
Meschreiber Jul 14, 2023
2011701
Copy edit Interfaces
Meschreiber Jul 14, 2023
00f5896
Copy edits
Meschreiber Jul 14, 2023
1ffdfd3
Typo
Meschreiber Jul 15, 2023
03cbade
Add pre-req information
Meschreiber Jul 17, 2023
cc0b141
Remove nested headers
Meschreiber Jul 17, 2023
a7c5949
Remove unnecessary space
Meschreiber Jul 18, 2023
c6f3554
Copy edit
Meschreiber Jul 18, 2023
21f5a21
Apply suggestions from code review
Meschreiber Jul 20, 2023
d5c1b81
Merge branch 'ms/authorization-directives-docs' of https://github.com…
Meschreiber Jul 20, 2023
e006b24
Clarify that `requiredScopes` can also eliminate entire subgraph requ…
Meschreiber Jul 20, 2023
2dc22d2
Add authorization directives to list of router enterprise features
Meschreiber Jul 20, 2023
92a1cc3
Merge branch 'dev' into geal/authorization-directives
Geal Jul 28, 2023
2bd587f
update router-bridge
Geal Jul 28, 2023
765c7f8
Update docs/source/configuration/authorization.mdx
Meschreiber Jul 28, 2023
3b0e94e
Merge branch 'dev' into geal/authorization-directives
Geal Aug 1, 2023
1ff841f
Apply suggestions from code review
Meschreiber Aug 4, 2023
ce51ab0
Copy edits
Meschreiber Jul 21, 2023
d74bd61
Copy edits and add to-do sections
Meschreiber Aug 4, 2023
813e7a8
Copy edits
Meschreiber Aug 6, 2023
497f06b
Add to-dos
Meschreiber Aug 6, 2023
479961b
Update error message for completely filtered query
Meschreiber Aug 7, 2023
94b9282
Typo
Meschreiber Aug 7, 2023
a5ed4ab
Typo
Meschreiber Aug 7, 2023
5e2f3e1
Rewrite intro
Meschreiber Aug 8, 2023
d5ac253
Align code examples to demo
Meschreiber Aug 8, 2023
fa7ff60
Copy edits
Meschreiber Aug 8, 2023
8a3fa58
Remove links to demo
Meschreiber Aug 8, 2023
2ab7433
move the claim augmentation example
Geal Aug 9, 2023
56ef003
Merge branch 'dev' into geal/authorization-directives
Geal Aug 9, 2023
31b22e9
Merge branch 'geal/authorization-directives' into ms/authorization-di…
Geal Aug 10, 2023
2791253
Update docs/source/configuration/authorization.mdx
Geal Aug 10, 2023
19d6c5f
implement the policy directive (#3406)
Geal Aug 11, 2023
c9236e1
Merge branch 'dev' into geal/authorization-directives
Geal Aug 11, 2023
551f139
Merge branch 'geal/authorization-directives' into ms/authorization-di…
Geal Aug 11, 2023
141b84c
add documentation for
Geal Aug 11, 2023
c36fca4
return a proper GraphQL response with authorization errors
Geal Aug 11, 2023
1ccb412
lint
Geal Aug 11, 2023
542fbfb
lint
Geal Aug 11, 2023
2a45290
implement OR for the policy directive
Geal Aug 11, 2023
ed1b8d4
implement OR for the requiresScopes directive
Geal Aug 11, 2023
9a5f0de
WiP: Rhai script to edit the claims
Geal Aug 11, 2023
77f5368
Use content components
Meschreiber Aug 11, 2023
3459afb
Copy edits
Meschreiber Aug 11, 2023
cb2b46f
Copy edit
Meschreiber Aug 11, 2023
84d1054
Update intro
Meschreiber Aug 11, 2023
b9a5116
Authorization directive docs (#3449)
Meschreiber Aug 11, 2023
62f66e3
Fix relative links
Meschreiber Aug 11, 2023
556330b
lint
Geal Aug 14, 2023
204a70f
Remove @policy docs
Meschreiber Aug 14, 2023
94bb17b
Add mermaid diagrams to intro
Meschreiber Aug 14, 2023
6dd06d6
Add coprocessor section
Meschreiber Aug 14, 2023
9e0d867
Copy edit
Meschreiber Aug 14, 2023
1dbdc78
Copy edit
Meschreiber Aug 15, 2023
b1dccdf
Nest coprocessor sections in Expansion blocks
Meschreiber Aug 15, 2023
7ade438
Apply feedback from docs review
Meschreiber Aug 15, 2023
8b44636
Copy edit
Meschreiber Aug 15, 2023
c73b3ca
Merge branch 'dev' into geal/authorization-directives
Geal Aug 16, 2023
ae586bd
More docs edits
Meschreiber Aug 16, 2023
2573b13
More docs feedback applied
Meschreiber Aug 21, 2023
24fcb3d
check the authorization status of implementors of an interface (#3588)
Geal Aug 22, 2023
94aa0eb
Merge branch 'dev' into geal/authorization-directives
Geal Aug 22, 2023
0e775d9
deactivate the policy directive for now
Geal Aug 22, 2023
eb21b27
Add docs for OR logic in @requireScopes
Meschreiber Aug 22, 2023
237a1c3
Merge branch 'dev' into geal/authorization-directives
Geal Aug 23, 2023
c32f84f
refactor tests to reduce the number of snapshots
Geal Aug 23, 2023
c364e63
move the experimental option to a preview option
Geal Aug 23, 2023
89764d4
fix snapshots
Geal Aug 23, 2023
26b1cc4
enable -> enabled
Geal Aug 23, 2023
a21e54d
analytics for authorization configuration
Geal Aug 23, 2023
bc50690
Merge branch 'dev' into geal/authorization-directives
Geal Aug 23, 2023
7d705a7
Apply suggestions from code review
Geal Aug 23, 2023
13ee68b
align requiresScopes tests with the main definition
Geal Aug 23, 2023
b240ea9
remove warnings from diagnostics
Geal Aug 23, 2023
95906f1
Update .changesets/feat_geal_authorization_directives.md
Geal Aug 23, 2023
c78c3cf
Update apollo-router/src/configuration/metrics.rs
Geal Aug 23, 2023
7e845dc
snapshots
Geal Aug 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changesets/feat_geal_authorization_directives.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### GraphOS Enterprise: authorization directives ([PR #3397](https://github.com/apollographql/router/pull/3397))

We introduce two new directives, `@authenticated` and `requiresScopes`, that define authorization policies for field and types in the supergraph schema.

They are defined as follows:

```graphql
directive @authenticated on OBJECT | FIELD_DEFINITION | INTERFACE | SCALAR | ENUM

scalar federation__Scope
directive @requiresScopes(scopes: [[federation__Scope!]!]!) on OBJECT | FIELD_DEFINITION | INTERFACE | SCALAR | ENUM
```

They are implemented by hooking the request lifecycle at multiple steps:
- in query analysis, we extract from the query the list of scopes that would be relevant to authorize the query
- in a supergraph plugin, we calculate the authorization status and put it in the context: `is_authenticated` for `@authenticated`, and the intersection of the query's required scopes and the scopes provided in the token, for `@requiresScopes`
- in the query planning phase, we filter the query to remove the fields that are not authorized, then the filtered query goes through query planning
- at the subgraph level, if query deduplication is active, the authorization status is used to group queries together
- at the execution service level, the response is formatted according to the filtered query first, which will remove any unauthorized information, then to the shape of the original query, which will propagate nulls as needed
- at the execution service level, errors are added to the response indicating which fields were removed because they were not authorized

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/3397
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5183,9 +5183,9 @@ dependencies = [

[[package]]
name = "router-bridge"
version = "0.4.0+v2.4.10"
version = "0.5.1+v2.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca7a000e3c4e1f6539581443354403f50d9a85b22c9a9a5572be0cf581c25df"
checksum = "6b16165d85954933e84512b7c34805d2b876c8ea4e9f206fe0812ad201eefb05"
dependencies = [
"anyhow",
"async-channel",
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ reqwest = { version = "0.11.19", default-features = false, features = [
"stream",
] }
# note: this dependency should _always_ be pinned, prefix the version with an `=`
router-bridge = "=0.4.0+v2.4.10"
router-bridge = "=0.5.1+v2.5.1"
rust-embed="6.8.1"
rustls = "0.21.6"
rustls-pemfile = "1.0.3"
Expand Down
4 changes: 3 additions & 1 deletion apollo-router/feature_discussions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
"experimental_logging": "https://github.com/apollographql/router/discussions/1961",
"experimental_http_max_request_bytes": "https://github.com/apollographql/router/discussions/3220"
},
"preview": {}
"preview": {
"preview_directives": "https://github.com/apollographql/router/discussions/???"
}
}
4 changes: 3 additions & 1 deletion apollo-router/src/configuration/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ impl Metrics {
value.apollo.router.config.authorization,
"$.authorization",
opt.require_authentication,
"$[?(@.require_authentication == true)]"
"$[?(@.require_authentication == true)]",
opt.directives,
"$.preview_directives[?(@.enabled == true)]"
);
log_usage_metrics!(
value.apollo.router.config.coprocessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ expression: "&metrics.metrics"
---
value.apollo.router.config.authorization:
- 1
- opt__require_authentication__: "true"
- opt__directives__: "false"
opt__require_authentication__: "true"

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: apollo-router/src/configuration/metrics.rs
expression: "&metrics.metrics"
---
value.apollo.router.config.authorization:
- 1
- opt__directives__: "true"
opt__require_authentication__: "false"

Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,21 @@ expression: "&schema"
"authorization": {
"description": "Authorization plugin",
"type": "object",
"required": [
"require_authentication"
],
"properties": {
"preview_directives": {
"description": "`@authenticated` and `@requiresScopes` directives",
"type": "object",
"properties": {
"enabled": {
"description": "enables the `@authenticated` and `@requiresScopes` directives",
"default": false,
"type": "boolean"
}
}
},
"require_authentication": {
"description": "Reject unauthenticated requests",
"default": false,
"type": "boolean"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
authorization:
require_authentication: true
require_authentication: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
authorization:
preview_directives:
enabled: true
3 changes: 3 additions & 0 deletions apollo-router/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ pub(crate) enum QueryPlannerError {

/// complexity limit exceeded
LimitExceeded(OperationLimits<bool>),

/// Unauthorized field or type
Unauthorized(Vec<Path>),
}

impl IntoGraphQLErrors for QueryPlannerError {
Expand Down
Loading