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

create support user #4141

Merged
merged 67 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
a481435
WIP creating and filtering support user
neilisfragile Oct 13, 2018
0bfd8ee
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Oct 23, 2018
c8e1bb6
move to using config.support_user_id
neilisfragile Oct 23, 2018
e9dbd02
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Oct 24, 2018
32b8971
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Oct 25, 2018
0ee8d1b
wip tests to filter out support user
neilisfragile Oct 29, 2018
1d0a5ab
Merge branch 'neilj/create_support_user' of github.com:matrix-org/syn…
neilisfragile Nov 2, 2018
cdb3aae
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Nov 2, 2018
158eccd
test suppoer user filtering
neilisfragile Nov 2, 2018
9d045fe
tc
neilisfragile Nov 2, 2018
76081eb
ensure support user created if does not exist
neilisfragile Nov 2, 2018
8964009
remove unused variable localpart
neilisfragile Nov 5, 2018
5032076
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Nov 5, 2018
0e962f5
fix py2/3 incompatibility
neilisfragile Nov 5, 2018
373a461
remove need to create support user in homeserver
neilisfragile Nov 6, 2018
6f19edb
fix misnamed var
neilisfragile Nov 6, 2018
bccbdb8
replace is with ==
neilisfragile Nov 6, 2018
d8b1f51
remove unused dependency
neilisfragile Nov 6, 2018
b7d1f0d
remove unused import
neilisfragile Nov 6, 2018
4254033
update description due to change in desired behaviour
neilisfragile Nov 6, 2018
06a3ec8
replace filter with list comp to aid py2 py3 compat, make test more p…
neilisfragile Nov 7, 2018
f217b5f
fix case where auto creation of rooms should never auto create for su…
neilisfragile Nov 7, 2018
12d09ac
tiday up cruft
neilisfragile Nov 8, 2018
7430a87
remove white space
neilisfragile Nov 8, 2018
eaac29f
move to db backed support user
neilisfragile Nov 12, 2018
eae8d4a
add db support for support user
neilisfragile Nov 13, 2018
45e0b9d
implementation and tests for db backed support user
neilisfragile Nov 13, 2018
cf10ca9
remove errant prints
neilisfragile Nov 13, 2018
a54aaf4
fix boolean typing
neilisfragile Nov 13, 2018
22418bc
remove unneeded sql
neilisfragile Nov 13, 2018
3121f04
wip - move support user logic into handler from storage
neilisfragile Nov 13, 2018
c708296
fix unit tests
neilisfragile Nov 13, 2018
b01271a
tweak tests and tidy
neilisfragile Nov 13, 2018
add1488
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Nov 14, 2018
b58bf8d
tests for support user behaviour
neilisfragile Nov 14, 2018
3f5fe16
test support user behaviour
neilisfragile Nov 14, 2018
ce27b1c
clean up
neilisfragile Nov 14, 2018
eab8843
improve docstring
neilisfragile Nov 14, 2018
ded5774
fix py2 Mock dep
neilisfragile Nov 14, 2018
44539df
Merge branch 'develop' into neilj/create_support_user
neilisfragile Nov 22, 2018
255515b
isort
neilisfragile Nov 27, 2018
65b4a21
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Nov 27, 2018
40771ff
remove line
neilisfragile Nov 27, 2018
6ae725a
fix race condition
neilisfragile Nov 27, 2018
430ea68
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Nov 28, 2018
b620f0a
fix reference to unused config.support_user_id
neilisfragile Nov 28, 2018
628c96e
Merge branch 'develop' into neilj/create_support_user
neilisfragile Nov 28, 2018
6574fdd
add in missing @defer.inlineCallbacks to test_auto_create_auto_join_w…
neilisfragile Nov 28, 2018
0dae671
allow creation of support users via the admin register api
neilisfragile Dec 11, 2018
33dfdd1
improved comments
neilisfragile Dec 11, 2018
868a72b
check for support users in _initialise_reserved_users. Remove unneces…
neilisfragile Dec 11, 2018
77a4163
Merge branch 'develop' into neilj/create_support_user
neilisfragile Dec 11, 2018
04f197d
fix merge conflict
neilisfragile Dec 11, 2018
1f0075e
linting
neilisfragile Dec 11, 2018
179ad1e
Merge branch 'develop' of github.com:matrix-org/synapse into neilj/cr…
neilisfragile Dec 11, 2018
936b554
change logic to be more explicit in _handle_deltas since order of che…
neilisfragile Dec 11, 2018
da3b125
fix log context leak
neilisfragile Dec 12, 2018
87cd017
add user_type validation and hmac support to admin registraion api
neilisfragile Dec 13, 2018
868cb6b
missing yield in test_is_support_user
neilisfragile Dec 14, 2018
d6d0401
style
neilisfragile Dec 14, 2018
b7c35d9
make user_type arg in admin registration api backward compatible
neilisfragile Dec 14, 2018
151d5c5
Update synapse/handlers/register.py
richvdh Dec 14, 2018
3ddd991
Update synapse/rest/client/v1/admin.py
richvdh Dec 14, 2018
d09cc1d
Update synapse/storage/registration.py
richvdh Dec 14, 2018
a7bb9bc
pep8
neilisfragile Dec 14, 2018
2adb5fc
fix doc typo
neilisfragile Dec 14, 2018
26a5c5f
remove trailing white space
neilisfragile Dec 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/admin_api/register_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ As an example::
}

The MAC is the hex digest output of the HMAC-SHA1 algorithm, with the key being
the shared secret and the content being the nonce, user, password, user_type
(or string "no_user_type" if None) and either the string "admin" or "notadmin",
the shared secret and the content being the nonce, user, password, either the
string "admin" or "notadmin", and optionally the user_type
each separated by NULs. For an example of generation in Python::

import hmac, hashlib
Expand All @@ -60,6 +60,7 @@ each separated by NULs. For an example of generation in Python::
mac.update(b"\x00")
mac.update(b"admin" if admin else b"notadmin")
mac.update(b"\x00")
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be conditional :/

mac.update(user_type.encode('utf8') if user_type else b"no_user_type")
if user_type:
mac.update(user_type.encode('utf8'))

return mac.hexdigest()
5 changes: 3 additions & 2 deletions synapse/_scripts/register_new_matrix_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def request_registration(
mac.update(password.encode('utf8'))
mac.update(b"\x00")
mac.update(b"admin" if admin else b"notadmin")
mac.update(b"\x00")
mac.update(user_type.encode('utf8') if user_type else b"no_user_type")
if user_type:
mac.update(b"\x00")
mac.update(user_type.encode('utf8'))

mac = mac.hexdigest()

Expand Down
3 changes: 2 additions & 1 deletion synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def register(
since it offers no means of associating a device_id with the
access_token. Instead you should call auth_handler.issue_access_token
after registration.
user_type (api.constants.UserTypes) - type of user
user_type (str|None): type of user. One of the values from
api.constants.UserTypes, or None for a normal user.
default_display_name (unicode|None): if set, the new user's displayname
will be set to this. Defaults to 'localpart'.
Returns:
Expand Down
7 changes: 4 additions & 3 deletions synapse/rest/client/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def on_POST(self, request):
admin = body.get("admin", None)
user_type = body.get("user_type", None)
richvdh marked this conversation as resolved.
Show resolved Hide resolved

if user_type and user_type not in UserTypes.ALL_USER_TYPES:
if user_type is not None and user_type not in UserTypes.ALL_USER_TYPES:
raise SynapseError(400, "Invalid user type")

got_mac = body["mac"]
Expand All @@ -176,8 +176,9 @@ def on_POST(self, request):
want_mac.update(password)
want_mac.update(b"\x00")
want_mac.update(b"admin" if admin else b"notadmin")
want_mac.update(b"\x00")
want_mac.update(user_type.encode('utf8') if user_type else b"no_user_type")
if user_type:
want_mac.update(b"\x00")
want_mac.update(user_type.encode('utf8'))
want_mac = want_mac.hexdigest()

if not hmac.compare_digest(
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/monthly_active_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def upsert_monthly_active_user_txn(self, txn, user_id):
for cases where upsert_monthly_active_user_txn is called directly,
like _initialise_reserved_users

In short, don't call this method with support users. (Support users
In short, don't call this method with support users. (Support users
should not appear in the MAU stats).

Args:
Expand Down
3 changes: 2 additions & 1 deletion synapse/storage/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def register(self, user_id, token=None, password_hash=None,
create_profile_with_displayname (unicode): Optionally create a profile for
the user, setting their displayname to the given value
admin (boolean): is an admin user?
user_type (synapse.api.constants.UserTypes): type of user
user_type (str|None): type of user. One of the values from
api.constants.UserTypes, or None for a normal user.

Raises:
StoreError if the user_id could not be registered.
Expand Down
4 changes: 2 additions & 2 deletions tests/rest/client/v1/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_register_incorrect_nonce(self):
nonce = channel.json_body["nonce"]

want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
want_mac.update(b"notthenonce\x00bob\x00abc123\x00admin\x00no_user_type")
want_mac.update(b"notthenonce\x00bob\x00abc123\x00admin")
want_mac = want_mac.hexdigest()

body = json.dumps(
Expand Down Expand Up @@ -179,7 +179,7 @@ def test_nonce_reuse(self):

want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
want_mac.update(
nonce.encode('ascii') + b"\x00bob\x00abc123\x00admin\x00no_user_type"
nonce.encode('ascii') + b"\x00bob\x00abc123\x00admin"
)
want_mac = want_mac.hexdigest()

Expand Down
2 changes: 1 addition & 1 deletion tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def register_user(self, username, password, admin=False):
nonce_str += b"\x00admin"
else:
nonce_str += b"\x00notadmin"
nonce_str += b"\00no_user_type"

want_mac.update(nonce.encode('ascii') + b"\x00" + nonce_str)
want_mac = want_mac.hexdigest()

Expand Down