Skip to content

Has permissions - #10

Open
alexanderdomin wants to merge 5 commits into
masterfrom
hasPermissions
Open

alexanderdomin wants to merge 5 commits into
masterfrom
hasPermissions

Conversation

@alexanderdomin

Copy link
Copy Markdown
Collaborator

Adopting the schema and adding permission validation to the GraphQL server implementation.

Pedro Soares and others added 5 commits January 13, 2021 16:57
The `@hasPermissions` directive, enforces the resolution of a field/type
to be guarded by a list of permissions. For more information on how to
use it, refer to:
https://github.com/profusion/apollo-validation-directives#haspermissions

As we are using a mocked environment, we need to apply the
SchemaDirectiveVisitor on top of the schema with the mocked resolvers -
since Apollo replace the resolvers with mocked ones. That's why we are
not using `mock: true` on ApolloServer creation but rather the explicit
function `addMockFunctionsToSchema`.

Change-Id: I30eb09b60866068a6693c1f0c919c8898f06b47e
If we receive a JWT token on the request, the server is going to
verify and decode it to get the incoming list of permissions by the
client. This permissions are attached to the server context so that
they can be validated by the `@hasPermissions` directive.

To decode the token, an cryptographic algorithm key must be given.
For now, this key is being read by one of the two places defined in
the .env file:
- PUBLIC_KEY_FILE: used for RSA asymmetric mechanisms, it is a file
path that contains the contents of the key (loaded dynamically by
the server)
- SECRET_KEY: used for HMAC symmetric mechanism, it is the value of
the key that can be generated using `uuidgen` for example.

Change-Id: Ib56ee3a0a299de46647f8efbdd2fd705cf0f75ab
The .env.example is a reference to .env configuration files used on
this project. This files are used to store environments configuration
that should be changed in different deploys. For now, we are using the
.env to store the keys used to decrypt the JWT token and set the
default port for GraphQL Server.

See README.md for more information on how to setup.

Change-Id: I34e116a93ffabf9d8feb77cd99b934db8419b771
Change-Id: I870feb9680a4d21c27e4ce8944485ce6ebb0297e
On the scalar fields of the schema, create `@hasPermissions` directive
with permissions that needs to be checked when resolving the field. The
schema permissions will be checked against the permissions from the JWT
token sent on the request - if not present, GraphQL will throw an error.

Change-Id: I1d43aff81f6cfdc5c5873d3514c3f658d505fba9

@slawr slawr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for posting the PR. The commits appear to be missing a git signed-off.

See Genivi contribution guidelines:

  1. https://at.projects.genivi.org/wiki/display/PROJ/Code+Quality+and+Maintenance+Policy
  2. https://at.projects.genivi.org/wiki/display/PROJ/How+to+contribute+to+GENIVI

@gunnarx

gunnarx commented Jan 26, 2021

Copy link
Copy Markdown

We merged the PRs in the order they were given, so #7 was merged first. But it also implemented some simple resolvers.
This means that this code now has some conflicts with the existing. We talked about it today and feel that we need a conversation between the programmers to resolve it. Or you could take a look at rebasing this one @hspedro @alexanderdomin, if you think that might be a way forward ?
We could take this PR directly but then the missing functionality (which exists in #7) seems to be the connection to the SQLite database, so one way of resolving the conflict might be to add that functionality to this branch.

@gunnarx gunnarx mentioned this pull request Jan 26, 2021
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.

4 participants