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

Use trusted clients for inference auth #2278

Merged
merged 8 commits into from
Apr 2, 2023
Merged

Use trusted clients for inference auth #2278

merged 8 commits into from
Apr 2, 2023

Conversation

AbdBarho
Copy link
Collaborator

@AbdBarho AbdBarho commented Mar 31, 2023

Fixes #2285

Changes in the PR:

  • revert auth callbacks to refer back to the inference server (same as it was before), the callback urls in the corresponding apps must be updated.
  • Added trusted clients which can communicate with API keys, these keys need to be added to the github env / secrets, I don't have the access rights to do that
  • Drop all auth code from website

Changes here conflict with #2221, although not significantly, only the urls, maybe this could be addressed as part of #2286

@LAION-AI LAION-AI deleted a comment from github-actions bot Mar 31, 2023
@LAION-AI LAION-AI deleted a comment from github-actions bot Mar 31, 2023
@LAION-AI LAION-AI deleted a comment from github-actions bot Mar 31, 2023
Copy link
Collaborator

@notmd notmd left a comment

Choose a reason for hiding this comment

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

Nice. I will have to look into it again tomorrow!

// TODO: use api key from env
api_key: "0000",
client: "website",
user_id: jwt.sub,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the correct uuid in the data collection backend?

Copy link
Collaborator Author

@AbdBarho AbdBarho Apr 2, 2023

Choose a reason for hiding this comment

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

No, this is the id of the user in the frontend db.

After thinking about this, using the data backend id would introduce a lot of coupling between the services, we can still aggregate information in the website if needed

Copy link
Collaborator

@notmd notmd Apr 2, 2023

Choose a reason for hiding this comment

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

No, this is the id of the user in the frontend db.

After thinking about this, using the data backend id would introduce a lot of coupling between the services, we can still aggregate information in the website if needed

Sure it's up to you. But I think having the data backend would allow the inference to communicate the data backend directly if needed Also using frontend id is kind of useless I think. It only avoids we have to call the data backend to get the id before we call the inference (which we can avoid by attaching it to the session or the JWT). Or maybe we can store both frontend and data backend id. IMO we have made a mistake by having the frontend DB. We use it because we are too lazy to reimplement all the NextAuth stuff but the trade-off is our infas is very complicated and fragmented. Every app has a custom user management system.

Also after this, I think we can deprecate all other sign methods of the inference (or just disable them for now) and use the frontend auth for other methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated to use the backend user id!

@AbdBarho AbdBarho marked this pull request as ready for review April 2, 2023 08:27
Copy link
Collaborator

@yk yk left a comment

Choose a reason for hiding this comment

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

amazing, thank you!

Comment on lines 41 to 48
} catch (err) {
// if we get an error here, the user might not yet exist in the inference database, which is why we try to create
// user once (it won't do anything if the user already exists) and then retry the chat creation again.
// this is maybe not the cleanest solution, but otherwise we would have to sign up all users of the website
// to inference automatically, which is maybe an overkill
await this.inference_login();
return create();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we check for the http status here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@notmd notmd left a comment

Choose a reason for hiding this comment

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

Nice

@@ -6,7 +6,7 @@ const handler = withoutRole("banned", async (req, res, token) => {
const user = await getBackendUserCore(token.sub);
const oasstApiClient = createApiClientFromUser(user);
if (req.method === "GET") {
const tos_acceptance_date = await oasstApiClient.fetch_tos_acceptance(user);
const tos_acceptance_date = (await oasstApiClient.fetch_frontend_user(user)).tos_acceptance_date;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can deconstruct the result here

@AbdBarho AbdBarho merged commit dcc4f25 into main Apr 2, 2023
@AbdBarho AbdBarho deleted the trusted-client-auth branch April 2, 2023 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "trusted" clients to the inference backend
3 participants