-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add support for master key clients to create user sessions #7406
Add support for master key clients to create user sessions #7406
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is awesome!
I suggest the REST endpoint to be renamed to impersonateUser
I don't think a security check is needed here. You are not adding a configurable feature / new option to Parse Server. Security checks evaluate options that the developer has configured and that may create points of attacks if not configured properly. If you agree that no security check is needed, you may well delete the TODO from the template.
This should be a TODO in the related issue, not in this PR. Since the issue has not been created by you (and is using an old template), you could just add it as a comment or create a new issue and reference the existing issue. The issue itself should contain all TODOs that are necessary for this feature, such as:
Any implementation in the Parse JS SDK (or any other Parse client SDK) could be regarded as a separate undertaking, each with its own required TODO in the respective SDK guide.
The REST response should be the same response as for the |
I've created a pull request to the docs repo covering the new endpoint. |
What's the appropriate way to handle locking out a user from the Should |
I hope I understand your question correctly. Security of a custom API endpoint is up to the developer, whatever their use case requires. Which account do you mean would be locked - the user who invokes |
Should I could go either way - I just need to know whether I should make a code change to this PR to allow supplying a parameter to |
The master key always trumps any restriction and ACL.
|
Got it. I've updated my REST docs PR with that information. This PR still has two outstanding questions:
Other than that, are there any outstanding concerns before this PR could be considered for merge? |
I think we can introduce a new one, otherwise we cannot differentiate the session origin. Any suggestions? |
If the master key isn't supplied, If the REST call doesn't supply the If there isn't a user with the supplied
How about:
|
Looking at the current auth provider terms for an indication, I think However, So for lack of a better term ( |
I've pushed a change setting the value to |
Let's give the auth provider naming some more thought, since this is unlikely because difficult to change in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌 for cleaning up and code documentation
Just some corrections for the error codes and testing.
Codecov Report
@@ Coverage Diff @@
## master #7406 +/- ##
==========================================
- Coverage 93.95% 93.93% -0.02%
==========================================
Files 181 181
Lines 13228 13245 +17
==========================================
+ Hits 12428 12442 +14
- Misses 800 803 +3
Continue to review full report at Codecov.
|
Could you take a look at the coverage report to see whether this PR requires more tests? |
The coverage report seems off to me. Codecov thinks all coverage for the Redis adapter has been removed, as well as some cases for the Mongo adapter (e.g., handling DB connection/auth errors) and some RestWrite cases (username taken, email taken). Reviewing the PR diff, I don't see how it could be affecting coverage for those subsystems. Coverage for UsersRouter is up 0.59%. But the CI checks don't mark the coverage as a requirement. It looks like CI failed on the self-check with this error:
|
Could be false positives.
I'll submit a PR to fix this. |
If you rebase on master, the CI tests should pass. |
8924dff
to
783681b
Compare
…n log in as any user, without access to the user's credentials, and without presuming the user already has a session
I've rebased onto |
Can you please delete the package-lock file and rebuild it? It's out of sync with package.json. |
783681b
to
303c58d
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for this great feature!
Thanks so much for all your help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert the package-lock file? Otherwise this looks good to me!
Why revert? I rebuilt it from package json. |
It doesn't have anything to do with the PR and we don't know what those dozens of dependencies updates will cause. |
I see, I agree it makes sense to do this in a separate PR. What is our current practice for this? I can't remember an explicit PR where we only updated package-lock in the past. I do remember PRs however were we regenerated the package-lock as a side effect, even though it had nothing to do with the PR. |
This usually happens because a user deleted the package-lock file then regenerated it, thats my issue. In this PR rearranging the package.json (npm install) shouldn't have caused a change in the lock file (I just tried it locally and no change). |
makes sense, reverted package-lock So should I regenerate the package-lock file in a dedicated PR or how to we rebuild the package-lock file? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Let Synx manage the package-lock file or if someone installs a new package the lock file will update without regenerating. |
Add support for master key clients to create user sessions (parse-community#7406)
I am not sure about that approach. I opened #7417 to discuss that. |
Cool PR! But
But we would use this to login users with our own login provider, so for us it's a real login. So, wouldn't it be better if it's optional to call the triggers? |
@vince1995 If you want to use a custom login provider, you would create a custom auth adapter. Please feel free to open a new issue where you explain what you suggest to change. This PR is closed. |
@vince1995 @mtrezza This is related : #6641 |
Hi, any chances of this PR being released? I'm using the currently using master branch to use this feature. |
@tehsunnliu the next major release will be V5, available in the coming months. See: #7492 |
Thank you for the info. |
🎉 This change has been released in version 5.0.0-beta.1 |
🎉 This change has been released in version 5.0.0 |
New Pull Request Checklist
Issue Description
This PR proposes an implementation for #6641: a way for Cloud Code (or any master key client) to create user sessions without access to the user's credentials, and without presumption of an existing user session. This is useful for user impersonation (customer support), or for creating a standalone API that can act with a user's authority after validating the user's identity some other way (e.g., API key).
Related issue: #6641
Approach
I've created a new REST endpoint that creates a new session for the given user ID if the master key is supplied. I elided the before/after login triggers since it's not really a login - I assume we want a clear semantic distinction between normal user activity and e.g., a user making an API call against their account that creates a session, or a customer support representative logging in as the user to investigate a ticket. Maybe a parameter in the API call should toggle hooks on/off?
TODOs before merging
Still needs docs updates, and I'll submit a PR for the JS SDK, both after I'm given the thumbs-up on the new API.
authProvider
should the session be flagged with? Ispassword
okay, or do we need a new value?