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

HPC-7904: 🛂 Setup authentication for resolvers #21

Merged
merged 27 commits into from
Nov 17, 2021
Merged

HPC-7904: 🛂 Setup authentication for resolvers #21

merged 27 commits into from
Nov 17, 2021

Conversation

Pl217
Copy link
Contributor

@Pl217 Pl217 commented Jun 18, 2021

The main goal of this commit is to allow for usage of @Permission decorator, which allows our permission model to be used with resolver methods.

Also, there are multiple commits which deal with various improvements, not directly affecting auth, but I didn't want to open a lot of PRs, since the project is still in its inception and lots of changes are expected. Some of the notable changes:

  • Update all dependencies to latest version, except graphql, which got released recently, but other dependencies like type-graphql aren't ready for the upgrade. Apollo server sees major version upgrade, going from v2 to v3.
  • knex version is pinned to the same version used in hpc-api-core, because there are type errors otherwise
  • hpc-api-core dependency is added now that new model abstraction lib based on knex is added in 🎨 HPC-7936: Introduce new model abstraction lib hpc-api-core#1 and some basic models defined in there. This PR will need Define models needed for HPC-7904 hpc-api-core#30 merged first, because some more models need to be defined, since I deleted models defined in this repo, because those defined in hpc-api-core will be used instead.
  • Custom auth header parsing is introduced because plugins for Basic and Bearer header parsing will not work together and I haven't found a plugin to support both
  • Debugging is allowed with port forwarding enabled for debugging outside docker container. In order to attach debugger in chrome://inspect, you'll need to add localhost:9339 inside "Configure..." button popup dialog.
  • Local copy of hpc-api-core repo is used, so new yarn install-and-link dev command is introduced that does the necessary linking.

@Pl217 Pl217 assigned s0 and astroash Jun 18, 2021
Copy link
Contributor

@s0 s0 left a comment

Choose a reason for hiding this comment

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

Few comments here.

There is of course quite a lot of duplication here from the old service (which does make it difficult to review exactly how it differs), but I've given that code in particular at least a quick once-over.

I'm wondering now if it makes sense though to move all that code in hpc_service that we want to share into hpc-api-core before merging this PR, and basing this stuff on-top of that, avoiding the duplication in the first place. There will certainly be a bunch of changes that need to be made to make it compatible for both use-cases, but that could then be done in separate PRs that make it clear how this code is changing.

src/data-providers/postgres/models/common/base.ts Outdated Show resolved Hide resolved
config/index.ts Outdated Show resolved Hide resolved
src/common-utils/log.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/common-libs/auth/permissions.ts Outdated Show resolved Hide resolved
src/common-libs/auth/auth-checker.ts Outdated Show resolved Hide resolved
src/common-libs/auth/permission-decorator.ts Outdated Show resolved Hide resolved
src/common-libs/auth/permission-decorator.ts Outdated Show resolved Hide resolved
docs/AUTH.md Outdated Show resolved Hide resolved
@s0 s0 assigned Pl217 and unassigned s0 and astroash Jul 6, 2021
@s0 s0 added the needs minor changes There are review or issue comments to address label Jul 6, 2021
@Pl217 Pl217 force-pushed the HPC-7904 branch 2 times, most recently from 893dfc7 to a687100 Compare August 13, 2021 11:29
@Pl217
Copy link
Contributor Author

Pl217 commented Aug 13, 2021

I'm wondering now if it makes sense though to move all that code in hpc_service that we want to share into hpc-api-core before merging this PR, and basing this stuff on-top of that, avoiding the duplication in the first place. There will certainly be a bunch of changes that need to be made to make it compatible for both use-cases, but that could then be done in separate PRs that make it clear how this code is changing.

I moved the common auth code to UN-OCHA/hpc-api-core#21

@Pl217 Pl217 added ready for review All comments have been addressed, and the Pull Request is ready for review and removed needs minor changes There are review or issue comments to address labels Aug 24, 2021
@Pl217 Pl217 assigned s0 and unassigned Pl217 Aug 24, 2021
@Pl217 Pl217 added pending prior merge Another Pull Request needs to be merged before this one ready for review All comments have been addressed, and the Pull Request is ready for review and removed ready for review All comments have been addressed, and the Pull Request is ready for review labels Nov 2, 2021
@Pl217 Pl217 force-pushed the HPC-7904 branch 3 times, most recently from c13bece to ef126dc Compare November 4, 2021 14:09
New major version 16 is released few days ago, but
other dependencies aren't ready for the upgrade

By the words of a main maintainer of type-graphql package
that we use, support for GraphQL version 16 "won't happen soon,
as all the other GraphQL ecosystem tools need to support v16 too."
MichalLytek/type-graphql#1100
@s0 s0 added the needs minor changes There are review or issue comments to address label Nov 17, 2021
According to release notes for version 7
https://github.com/typicode/husky/releases/tag/v7.0.0
".husky/.gitignore is now unnecessary and can be removed"
Version 12.20 is required for dev dependencies
like eslint and lint-staged to work
Also, pin the version of `prettier` because
according to its docs, even patch versions
can introduce changes to formatting output.
Also, rename knex connection inside `Context` object to `connection`
Model definitions from hpc-api-core will be used instead
This is done because resolver that uses `findById` is not
authenticated and anon users should not see leaked latest version.
Forward ports to allow for debugging outside docker container.

Since this API (v4) is behind a proxy of previous versions of API,
there is a conflict in port numbers, so instead of default Node.js
inspect port (9229), other port number is used - 9339.
This decorator can accept permission conditions required
to access the resource. For example:
```
@Permission(({ args }) =>
  Promise.resolve({
    or: [
      { type: 'global', permission: P.global.VIEW_ANY_PLAN_DATA },
      { type: 'plan', permission: P.plan.VIEW_DATA, id: args.id },
    ],
  })
)
```

If only global permission check is needed, it can be used directly:
```
@Permission({
  type: 'global',
  permission: P.global.VIEW_ALL_JOBS,
})
```
@Pl217 Pl217 added ready for review All comments have been addressed, and the Pull Request is ready for review and removed pending prior merge Another Pull Request needs to be merged before this one needs minor changes There are review or issue comments to address labels Nov 17, 2021
@Pl217 Pl217 assigned s0 and unassigned Pl217 Nov 17, 2021
@s0 s0 merged commit 7b051a9 into develop Nov 17, 2021
@s0 s0 deleted the HPC-7904 branch November 17, 2021 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review All comments have been addressed, and the Pull Request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants