-
Notifications
You must be signed in to change notification settings - Fork 25
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 ssl_verify to manage selfsigned certificate #88
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.
Hi @heurtematte, thanks for the submission, I'm sure this is a very useful features for a lot of other synadm users as well! Nice!
One thing that comes up in a first and unthorough review is that you define boolean as for the new verify flag on cli level but at some point in the code it is changed / has a default value of None which not really is boolean. Is there a reason for that or could we change it to stay True/False everywhere?
Also, some tiny formatting issues are detected by our linter (flake8) in the CI.
Thanks again and speak soon!
I wanted to keep the method
Tell me if you want me to change this behavior. I'll check the linter. |
Signed-off-by: sebastien.heurtematte <sebastien.heurtematte@eclipse-foundation.org>
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.
Sorry for being picky but we are partly changing something very fundamental here and need to make sure synadm behaves correctly in all use cases. Thanks for your patience and further refinement.
In the end these things count most IMO:
- What will happen if a user updates synadm to this new version and thus, does not have this new option in the config already? I guess the configurator will pop up automatically on any run AFAIR . That still the case?
- The default for new synadm users in the auto-configurator should still be "SSL verification is enabled."
- It should be clear to the user on installation and upgrade what the state of the setting SSL verification currently is.
It would help me reviewing if you post some cli outputs of the configurator and other related cli calls. I'm always concerened with the user experience and --help the most :-)))
synadm/cli/__init__.py
Outdated
@@ -451,6 +462,11 @@ def get_redacted_token_prompt(cli_token): | |||
"Homeserver name (auto-retrieval or matrix.DOMAIN)", | |||
default=homeserver if homeserver else helper.config.get( | |||
"homeserver", homeserver)), | |||
"ssl_verify": click.prompt( | |||
"Verify certificate (Default True, False allow to manage \ | |||
selfsigned certificate)", |
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.
The backslash and the indentation is not required in Python. See other help variables using triple double quotes a little further above. Thanks :-)
Although I feel it's sufficient here to leave the False... part out entirely. Most people/admins will be aware of what ssl_verify option means. It's kind of self-descriptive int that context.
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.
Please note that we have currently not defined the default values of the other config variables explicitly in the help string. Because if you run the configurator the current value (by default is set to the values defined in APIHelper.CONFIG
) is presented behind each prompt within brackets, so the user exactly knows which value the corresponding config variable is currently set to. For example it looks like Synapse base URL [http://localhost:8008]
.
Therefore I don't think that there is a need to explicitly state the default value within the help string
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.
sounds good!
synadm/api.py
Outdated
@@ -375,11 +388,13 @@ def __init__(self, log, user, token, base_url, admin_path, timeout, debug): | |||
timeout (int): Requests module timeout used in ApiRequest.query | |||
method | |||
debug (bool): enable/disable debugging in requests module | |||
verify(bool): SSL verification is turned on by default | |||
and can be turned off using this method. |
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.
I'd prefer the wording: ....using this argument.
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.
ok
if not value: | ||
self.log.error("Config entry missing: %s", key) | ||
if value is None: | ||
self.log.error("Config entry missing: %s, %s", key, value) |
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.
Youwould like to see whatexactly is wrong? Value missing or empty string for example? Or other reason why you added value to be displayed?
You are now only checking for None. The if not value
would have also catched empty strings which also often would cause errors. Not sure but did you test thorougly with setting other values in the config to weird things and made sure things will be catched?
Also note: The usual default of things we get from a Click-defined options is actually None if not specified otherwise. But please doublecheck all possible things that might go wrong here even if a user edits config.yaml manually (without the configurator)
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.
Good catch. I roll back my modification.
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.
I remember why now.
If I set false to the ssl_verify configuration. I have this message
ERROR Config entry missing: ssl_verify, False
So I must deal with string value and boolean value.
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.
I understand!
synadm/api.py
Outdated
@@ -55,6 +56,8 @@ def __init__(self, log, user, token, base_url, path, timeout, debug): | |||
base_url to form the basis for all API endpoint paths | |||
timeout (int): requests module timeout used in query method | |||
debug (bool): enable/disable debugging in requests module | |||
verify(bool): SSL verification is turned on by default | |||
and can be turned off using this method. |
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.
I'd prefer the wording: ....using this argument.
Also, is the type now still bool?
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.
Good question! I'll check
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.
We can keep bool type
"--ssl_verify", "-n", default=True, | ||
help="""Verify certificate (Default True, False allow to manage \ | ||
selfsigned certificate).""" | ||
) |
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.
Default true can be specified by Click's show_default=True flag. Use that and I think we could then rephares this help text to something like: "Whether or not SSL certificates should be verified. Set to False to allow self-signed certifcates." or maybe even shorter because ssl_verify tells it all to a regular Matrix user/admin already:
Set to False to allow self-signed certifcates. Also of I recall correctly, in yaml true
needs to be spelled in non capital letters! Other than in Python! I wonder if that example should already use that spelling? Oooor - I didn't check - if the configurator would handle this lower-casing automatically.... Please doulbe check!
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.
Yaml seems to support different case: |true|True|TRUE|false|False|FALSE
According to https://yaml.org/type/bool.html
Hi @heurtematte can I assist with anything else? There are some things to fix. No hurry in doing that right away. Take your time, the merge of this new feature can wait. I just would like to know if you're still on it. In the meantime I did some testing and another thing comes up. It seems the actual value set in the config is not displayed in the interactive configurator. This is misleading. Have a look how other config settings do it. Any non-sensitive information should be printed while the user reconfigures.
Also we see that the (text in brackets) is rather long and contains a line break. I've mentionend that above already but now I'm sure that it would be sufficient here to make this prompt look like this:
Cert verification (or not) is a logical thing for any admin, no further visual distraction required. |
sorry a bit busy! I'll take a look by the end of the week. |
Signed-off-by: sebastien.heurtematte <sebastien.heurtematte@eclipse-foundation.org>
…text option Signed-off-by: sebastien.heurtematte <sebastien.heurtematte@eclipse-foundation.org>
Hi @heurtematte, thanks for your changes last week. We've been busy with other things in the project but I think around next week might be able to conintue work here. We'd like to do some testing and tiny changes to finalize this. Do you mind if we take over your branch to incorporate said finalization? Thanks! |
Remove redundant backslash and fix indentation.
- Fix long option: - Dashes instead of underscores. - Make sure it is boolean: Set is_flag. - Fix short option: -n is in use already, let's call it -i ("insecure", like other tools use it, eg. curl)
We need to make sure click.prompt saves the value as a boolean, i.e false instead of 'false', true instead of 'true'. Lower-case true/false is valid yaml syntax for boolean values.
Hi @JacksonChen666, I've added a couple of formatting but also functional fixes to make a real boolean value in the config work. Please could you possibly try this in your testing environment:
Thanks a lot! |
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.
Please could you possibly try this in your testing environment:
* What happens if rubbish is written into the config? E.gssl_verify: bollocks text
default value is used regardless of config values, even if configured with False
in synadm config
it will default to True
(very likely not intended behavior).
I have made a comment in the place where I think the issue is, plus something else I noticed.
synadm/cli/__init__.py
Outdated
output, timeout, server_discovery, homeserver): | ||
""" Modify synadm's configuration. | ||
output, timeout, server_discovery, homeserver, ssl_verify): | ||
""" Modify test synadm's configuration. |
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.
test? "Modify test synadm's configuration" doesn't make sense language-wise
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.
Oh, that seems to be a leftover of some debugging by the OP or something. Corrected.
synadm/cli/__init__.py
Outdated
@@ -376,10 +385,15 @@ def root(ctx, verbose, batch, output, config_file): | |||
default value 'auto-retrieval' will try to discover the name using the | |||
method set by --server-discovery.""" | |||
) | |||
@click.option( | |||
"--ssl-verify", "-i", is_flag=True, default=True, show_default=True, |
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.
default=True
is odd in this case, as defaults aren't set in any options above but instead below in the click.prompt
things.
this makes for a UI inconsistency where all other configs use the default value of whatever is set (in synadm config
) in the options except for --ssl-verify
.
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.
Yes! You are absolutely right, we don't handle defaults that way! Defaults should always be handled via APIHelper.CONFIG and the click.prompt things as you noticed! Good catch! I fixed this.
I think now the behaviour is quite fine. Can you please give it another testrun?
To me it looks like this:
- We silently default to true if the option is missing.
- We display an error when the option is manually set wrongly to some non-boolean string.
but we don't quit synadm and continue with subsequent errors. This is good, since otherwhise the configurator could not be run. For example:
(synadm38) ~/git/heurtematte_synadm (master) $ synadm -vv user details testuser2
DEBUG Config entry read. user: admin
DEBUG Config entry read. token: REDACTED
DEBUG Config entry read. base_url: https://peek-a-boo.at
DEBUG Config entry read. admin_path: /_synapse/admin
DEBUG Config entry read. matrix_path: /_matrix
DEBUG Config entry read. timeout: 3600
DEBUG Config entry read. server_discovery: well-known
DEBUG Config entry read. homeserver: peek-a-boo.at
ERROR Config value error: ssl_verify, crap must be boolean
DEBUG Config entry read. ssl_verify: crap
DEBUG Config entry read. format: yaml
DEBUG Formatter in use: yaml - <function dump at 0x7f69b9e70e18>
DEBUG A proper localpart was passed, generating MXID for local homeserver.
INFO Querying get on https://peek-a-boo.at/_synapse/admin/v2/users/@testuser2:peek-a-boo.at
ERROR OSError while querying Synapse: Could not find a suitable TLS CA certificate bundle, invalid path: crap
User details could not be fetched.
(synadm38) ~/git/heurtematte_synadm (master) $
- A configurator run would still display the current value crap, and the user intentionally has to set
1
ortrue
orTrue
to fix it. I think that is ok:
(synadm38) ~/git/heurtematte_synadm (master) $ synadm config
ERROR Config value error: ssl_verify, crap must be boolean
Running configurator...
Synapse admin user name [admin]:
Synapse admin user token [REDACTED]:
Synapse base URL [https://peek-a-boo.at]:
Synapse admin API path [/_synapse/admin]:
Matrix API path [/_matrix]:
Default output format (yaml, json, human, pprint) [yaml]:
Default http timeout [3600]:
Homeserver name (auto-retrieval or matrix.DOMAIN) [peek-a-boo.at]:
Verify certificate [crap]: 1
Server discovery mode (used with homeserver name auto-retrieval) (well-known, dns) [well-known]:
Restricting access to config file to user only.
- They could still leave
crap
but then would get displayed an error again:
$ synadm config
ERROR Config value error: ssl_verify, crap must be boolean
Running configurator...
Synapse admin user name [admin]:
Synapse admin user token [REDACTED]:
Synapse base URL [https://peek-a-boo.at]:
Synapse admin API path [/_synapse/admin]:
Matrix API path [/_matrix]:
Default output format (yaml, json, human, pprint) [yaml]:
Default http timeout [3600]:
Homeserver name (auto-retrieval or matrix.DOMAIN) [peek-a-boo.at]:
Verify certificate [crap]:
Server discovery mode (used with homeserver name auto-retrieval) (well-known, dns) [well-known]:
Restricting access to config file to user only.
ERROR Config value error: ssl_verify, crap must be boolean
We don't set defaults while initially setting up with the @click.option decorator. We handle defaults via the APIHelper.CONFIG dict and some magic in the configurators cli code.
Allow to param ssl_verify in configuration, allow to request https localhost homeserver with self signed certificate.
~/.config/synadm.yaml
Signed-off-by: sebastien.heurtematte sebastien.heurtematte@eclipse-foundation.org