Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow admin to register a new user #5742

Conversation

awesome-manuel
Copy link
Contributor

@awesome-manuel awesome-manuel commented Jul 23, 2019

This implements #5741.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file
  • Pull request includes a sign off

@richvdh
Copy link
Member

richvdh commented Jul 23, 2019

hrm, what do other ppl on the dev team think about this? In particular:

  • is removing shared-secret support from /client/r0/register going to break things for people? It's worth noting that the docs don't say anything about it being available on the /client/r0/register endpoint.
  • if we add an admin API for registering users as an admin user rather than via a shared secret, should it go on a different endpoint to the existing api or is it ok to share?

@awesome-manuel: note that the admin api endpoints are documented at https://github.com/matrix-org/synapse/blob/master/docs/admin_api/ so as part of this change, that documentation will need updating.

@richvdh richvdh requested a review from a team July 23, 2019 12:30
@awesome-manuel
Copy link
Contributor Author

awesome-manuel commented Jul 23, 2019

@richvdh also note that the checks in _synapse/admin/v1/register are more strict than in /client/r0/register, e.g. no space allowed in username or password and max length must be lower than 512 characters.

@awesome-manuel awesome-manuel force-pushed the admin_registration branch 3 times, most recently from 0bc34d5 to fb56022 Compare July 25, 2019 09:24
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

@awesome-manuel: thanks for this. I think our position on this is:

  • removing support for shared-secret registration from /client/r0/register is fine, but needs calling out as a specific point in the changelog (so it needs a .removal file in changelog.d). Ideally it would be a separate PR, but I won't insist on that.

  • We'd rather support for registration-as-admin ended up on a separate REST endpoint in /admin to shared-secret-registration.

@awesome-manuel
Copy link
Contributor Author

@richvdh any suggestion how this new endpoint should be called?

@richvdh
Copy link
Member

richvdh commented Jul 30, 2019

I suggest something like create_user. The existing register name is poor, but that is something to fix another time.

@awesome-manuel
Copy link
Contributor Author

@richvdh see #5877

@awesome-manuel awesome-manuel force-pushed the admin_registration branch 2 times, most recently from 1c332b2 to a7e735f Compare August 19, 2019 15:09
@awesome-manuel awesome-manuel force-pushed the admin_registration branch 3 times, most recently from ec46859 to 5e9bb20 Compare August 27, 2019 13:52
@awesome-manuel
Copy link
Contributor Author

I suggest something like create_user. The existing register name is poor, but that is something to fix another time.

What do you think of a POST on _synapse/admin/v1/users? Seems to be more REST-like.

@richvdh
Copy link
Member

richvdh commented Aug 27, 2019

What do you think of a POST on _synapse/admin/v1/users? Seems to be more REST-like.

Sure, that could work.

This parameter was used to test if the homeserver belongs to this user_id.
Now the requesting user is tested instead. Not sure if this is required,
since the request must be an admin anyway.
Signed-off-by: Manuel Stahl <manuel.stahl@awesome-technologies.de>
@awesome-manuel
Copy link
Contributor Author

Partly fixes #2522, but should be done in a separate PR.

@richvdh richvdh self-assigned this Oct 3, 2019
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Looks like a great improvement, thanks! A few comments though...

@@ -52,25 +52,98 @@


class UsersRestServlet(RestServlet):
PATTERNS = historical_admin_path_patterns("/users/(?P<user_id>[^/]*)")
PATTERNS = historical_admin_path_patterns("/users")
Copy link
Member

Choose a reason for hiding this comment

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

Hrm. Can you make this continue to accept (but ignore) a /user_id, for compatibility with applications which have hacked around the existing broken API?


if not self.hs.is_mine(target_user):
raise SynapseError(400, "Can only users a local user")
if not self.hs.is_mine(requester.user):
Copy link
Member

Choose a reason for hiding this comment

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

This is redundant. The requester is a local user by definition.


body = parse_json_object_from_request(request)

if "username" not in body:
Copy link
Member

Choose a reason for hiding this comment

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

@@ -1,3 +1,60 @@
Create Account
Copy link
Member

Choose a reason for hiding this comment

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

could you document the response format?

}

returns:
200 OK with empty object if success otherwise an error.
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't be an empty object afaict. (Indeed, your test even asserts that.)

user_type=user_type,
)

result = yield register._create_registration_details(user_id, body)
Copy link
Member

Choose a reason for hiding this comment

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

this will issue an access token for the user, which I'm not sure is the right thing to do. (even if you do want to end up with an access token for the new user, I think that might be better served via a different API per #6054).

In short, I don't think you need to call _create_registration_details here, which is good since it's meant to be a private method and instantiating a RegisterRestServlet here is ugly.


register = RegisterRestServlet(self.hs)

user_id = yield register.registration_handler.register_user(
Copy link
Member

Choose a reason for hiding this comment

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

there are better ways of getting hold of the registration_handler than via the RegisterRestServlet. Just stick
self.registration_handler = hs.get_registration_handler() in the constructor.

@awesome-manuel awesome-manuel deleted the admin_registration branch December 3, 2019 13:54
@awesome-manuel awesome-manuel restored the admin_registration branch December 3, 2019 13:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants