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

feat(auth): tenanted grants #3187

Merged
merged 9 commits into from
Feb 11, 2025
Merged

Conversation

njlie
Copy link
Contributor

@njlie njlie commented Dec 18, 2024

Changes proposed in this pull request

  • Adds tenantId to grants
  • Pulls tenant identity provider information when constructing an interaction for a given grant.

Context

Closes #3128.

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. type: source Changes business logic pkg: auth Changes in the GNAP auth package. pkg: mock-ase labels Dec 18, 2024
@njlie njlie force-pushed the nl/3128/tenanted-grants branch from 67f3d21 to 1e383c1 Compare January 8, 2025 18:15
@njlie njlie force-pushed the nl/3128/tenanted-grants branch from 1e383c1 to d1785a2 Compare January 27, 2025 21:37
@njlie njlie marked this pull request as ready for review February 3, 2025 23:34
@njlie njlie force-pushed the nl/3128/tenanted-grants branch from 88cf1f5 to 1410ab0 Compare February 3, 2025 23:35
@njlie njlie linked an issue Feb 4, 2025 that may be closed by this pull request
4 tasks
Copy link
Collaborator

@koekiebox koekiebox left a comment

Choose a reason for hiding this comment

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

The PR looks good to me, I was wondering though, where can I find the most comprehensive documentation for auth?
Do we want to add a sub-section in Integration that talks about how the auth works (not part of this PR)?

https://rafiki.dev/apis/graphql/auth/

* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to backfill old grants w tenantId as well?

Copy link
Contributor

@BlairCurrey BlairCurrey Feb 10, 2025

Choose a reason for hiding this comment

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

Outside the scope of this PR, but we should do some manual testing for the upgrade before merging the multi tenacny branch into main. So we can catch stuff like this.

@@ -179,6 +196,15 @@ async function createPendingGrant(
)
}

const tenant = await deps.tenantService.get(tenantId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we fetch the tenant in the createGrant function, can we avoid this lookup by passing tenant in directly?

await trx.commit()

if (!isTenantWithIdp(grant.tenant)) throw new Error('invalid interaction')
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this to be a GNAPServerRouteError or is this something that shouldn't really happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something that shouldn't really happen - an interactive grant should only be created if the tenant it's for has its IDP configured. If this does happen, this block is wrapped in a try-catch that throws a GNAPServerRouteError in the catch.

getBySession(
id: string,
nonce: string,
tenantId?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this isn't used: getBySession is always called without tenantId. I think you probably wanted to add this because of the interaction finish route?

@@ -328,7 +328,7 @@ describe('Incoming Payment Routes', (): void => {
await expect(incomingPaymentRoutes.get(ctx)).resolves.toBeUndefined()
expect(ctx.response).toSatisfyApiSpec()
expect(ctx.body).toEqual({
authServer: config.authServerGrantUrl,
authServer: config.authServerGrantUrl + '/' + config.operatorTenantId, // TODO: replace with incoming payment tenant id
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI @oana-lolea, this will need to be updated if this PR goes in first

@mkurapov
Copy link
Contributor

mkurapov commented Feb 7, 2025

@koekiebox in the docs there is

https://rafiki.dev/integration/deployment/services/auth-service/
https://openpayments.dev/introduction/idp/ (probably the more helpful diagram to show the grant & interaction process)

we can go over something specific as well if you have other q's, maybe a team wide call would be helpful as well about auth?

@@ -290,7 +290,7 @@ export class App {

// Grant Cancel
router.delete<DefaultState, GrantRevokeContext>(
'/continue/:id',
'/:tenantId/continue/:id',
Copy link
Contributor

@BlairCurrey BlairCurrey Feb 10, 2025

Choose a reason for hiding this comment

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

What are we doing with this tenantId, or why do we need to include it here? I dont see it used in the grantRoutes.revoke method and I dont think it's used by the middleware. Should we be validating it in the revoke method? I do see we're checking it in POST /:tenantId/continue/:id (grantRoutes.continue).

@njlie njlie merged commit f8a61c4 into 2893/multi-tenancy-v1 Feb 11, 2025
37 checks passed
@njlie njlie deleted the nl/3128/tenanted-grants branch February 11, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: auth Changes in the GNAP auth package. pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mulit-Tenant] Tenanted grants
4 participants