Skip to content

Commit 97c3d98

Browse files
Mic92anoadragon453
andauthoredJun 18, 2024
register_new_matrix_user: add password-file flag (#17294)
Co-authored-by: Andrew Morgan <[email protected]> Co-authored-by: Andrew Morgan <[email protected]>
1 parent fa3adc8 commit 97c3d98

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed
 

‎changelog.d/17294.feature

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`register_new_matrix_user` now supports a --password-file flag, which
2+
is useful for scripting.

‎debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
matrix-synapse-py3 (1.109.0+nmu1) UNRELEASED; urgency=medium
2+
3+
* `register_new_matrix_user` now supports a --password-file flag.
4+
5+
-- Synapse Packaging team <packages@matrix.org> Tue, 18 Jun 2024 13:29:36 +0100
6+
17
matrix-synapse-py3 (1.109.0) stable; urgency=medium
28

39
* New synapse release 1.109.0.

‎debian/register_new_matrix_user.ronn

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ A sample YAML file accepted by `register_new_matrix_user` is described below:
3131
Local part of the new user. Will prompt if omitted.
3232

3333
* `-p`, `--password`:
34-
New password for user. Will prompt if omitted. Supplying the password
35-
on the command line is not recommended. Use the STDIN instead.
34+
New password for user. Will prompt if this option and `--password-file` are omitted.
35+
Supplying the password on the command line is not recommended.
36+
37+
* `--password-file`:
38+
File containing the new password for user. If set, overrides `--password`.
39+
This is a more secure alternative to specifying the password on the command line.
3640

3741
* `-a`, `--admin`:
3842
Register new user as an admin. Will prompt if omitted.

‎synapse/_scripts/register_new_matrix_user.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,18 @@ def main() -> None:
173173
default=None,
174174
help="Local part of the new user. Will prompt if omitted.",
175175
)
176-
parser.add_argument(
176+
password_group = parser.add_mutually_exclusive_group()
177+
password_group.add_argument(
177178
"-p",
178179
"--password",
179180
default=None,
180-
help="New password for user. Will prompt if omitted.",
181+
help="New password for user. Will prompt for a password if "
182+
"this flag and `--password-file` are both omitted.",
183+
)
184+
password_group.add_argument(
185+
"--password-file",
186+
default=None,
187+
help="File containing the new password for user. If set, will override `--password`.",
181188
)
182189
parser.add_argument(
183190
"-t",
@@ -247,6 +254,11 @@ def main() -> None:
247254
print(_NO_SHARED_SECRET_OPTS_ERROR, file=sys.stderr)
248255
sys.exit(1)
249256

257+
if args.password_file:
258+
password = _read_file(args.password_file, "password-file").strip()
259+
else:
260+
password = args.password
261+
250262
if args.server_url:
251263
server_url = args.server_url
252264
elif config is not None:
@@ -269,9 +281,7 @@ def main() -> None:
269281
if args.admin or args.no_admin:
270282
admin = args.admin
271283

272-
register_new_user(
273-
args.user, args.password, server_url, secret, admin, args.user_type
274-
)
284+
register_new_user(args.user, password, server_url, secret, admin, args.user_type)
275285

276286

277287
def _read_file(file_path: Any, config_path: str) -> str:

0 commit comments

Comments
 (0)