Skip to content

Commit 00c8888

Browse files
Mic92anoadragon453
andcommitted
register_new_matrix_user: add password-file flag
getpass in python exist on stdin to be a tty, hence we cannot just pipe into register_new_matrix_user. --password-file instead works better and it would also allow the use of stdin if /dev/stdin is passed. Co-authored-by: Andrew Morgan <[email protected]> Signed-off-by: Jörg Thalheim <[email protected]>
1 parent 863578b commit 00c8888

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

changelog.d/17294.feature

Lines changed: 2 additions & 0 deletions
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/register_new_matrix_user.ronn

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ 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
36+
on the command line is not recommended. Use `--password-file` if possible.
37+
38+
* `--password-file`:
39+
File containing the new password for user. If set, overrides `--password`.
40+
This is a more secure alternative to specifying the password on the command line.
3641

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

synapse/_scripts/register_new_matrix_user.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,19 @@ 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
188+
override `--password`.",
181189
)
182190
parser.add_argument(
183191
"-t",
@@ -247,6 +255,11 @@ def main() -> None:
247255
print(_NO_SHARED_SECRET_OPTS_ERROR, file=sys.stderr)
248256
sys.exit(1)
249257

258+
if args.password_file:
259+
password = _read_file(args.password_file, "password-file").strip()
260+
else:
261+
password = args.password
262+
250263
if args.server_url:
251264
server_url = args.server_url
252265
elif config is not None:
@@ -270,7 +283,7 @@ def main() -> None:
270283
admin = args.admin
271284

272285
register_new_user(
273-
args.user, args.password, server_url, secret, admin, args.user_type
286+
args.user, password, server_url, secret, admin, args.user_type
274287
)
275288

276289

0 commit comments

Comments
 (0)