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

Authorization alpha version #3439

Closed
wants to merge 46 commits into from
Closed

Authorization alpha version #3439

wants to merge 46 commits into from

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Jul 13, 2023

DO NOT MERGE

This contains the following PR for an alpha version of the authorization feature:

Geal and others added 30 commits July 7, 2023 17:31
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

directive @requiresScopes(scopes: [String!]!) 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
Definition:

```graphql
directive @Policy(policy: String!) on OBJECT | FIELD_DEFINITION | INTERFACE | SCALAR | ENUM
```

`@policy` is designed for usage with coprocessors:
- extract the list of policies relevant to the query, store them in the
  context
- the coprocessor (or a rhai or native plugin) goes through the list of
  policies and marks them as successful or not
- the router then filters fields from the query according to which
  policies were successful

the `policy` argument could be the actual authorization policy to
execute, in text form, or an index into a list of policies that the
coprocessor knows how to execute.
This will allow router authorization to leverage existing authorization
systems, with custom policy languages, or ones that call into central
state like a roles database.

Field filtering and null propagation happens in exactly the same way as
the other authorization directives, and can be used with them in the
same schema
this uncovers an issue with type condition on fragments, fragment
spreads and inline fragments: we should check if the type is authorized
there
if we want rhai or a (future) coprocessor to modify the authorization status at
the supergraph level, then the cache key metadata for authorization
should be set up after those plugins have run
@Geal Geal changed the title Authorization alpha Authorization alpha version Jul 13, 2023
@router-perf
Copy link

router-perf bot commented Jul 13, 2023

CI performance tests

  • reload - Reload test over a long period of time at a constant rate of users
  • no-graphos - Basic stress test, no GraphOS.
  • step - Basic stress test that steps up the number of users over time
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • const - Basic stress test that runs with a constant number of users
  • large-request - Stress test with a 1 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • xlarge-request - Stress test with 10 MB request payload

@Geal Geal closed this Aug 9, 2023
@abernix abernix deleted the authorization-alpha branch May 3, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant