Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 MSC3861 config options admin_token_path and client_secret_path #18004
Add MSC3861 config options admin_token_path and client_secret_path #18004
Changes from 3 commits
09e7a1e
e46187d
fbebb1d
5da34d5
ebbfcca
87be544
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Is there a different idiomatic pattern with
attrs
where we can just read from the file once?It looks like we just access
config.client_secret()
once in__init__()
in the usage but I don't think we should make downstream consumers think about having to cache this value because of the expensive/slow file read each time.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 context in which I made this design decision is the following: I’ve started thinking about secret rotation in Synapse and would like to have it supported eventually. For that to work, the consumers of secrets have to know about updates to the secret in use (and sometimes previous secrets as well).
I find the small scope of this change (together with the unwieldiness of
attrs
1) a good place to get a first taste of how updating secrets might work.Regarding your concern about performance: I’d expect such a small file to be cached by the OS and very quick to be accessed. If that would not be the case, memory mapping or the use of inotify would be a more full-fledged solution. But does this MR actually cause any performance regression?
Footnotes
I don’t blame you,
attrs
, it’s simply not the task you were made for. ↩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.
This feels like a pre-optimization and something that needs discussion on whether we even want to support it and strategies for how best to tackle.
I don't think it's a performance problem in its current form. I just don't think that downstream consumers using
config.client_secret()
should have to think about it. It should just always be an in-memory thing after startup.For example, if we wanted to support secret rotation, we could have a watcher on the file that would only update when the file changes (not read the file each time). But this is just another example of a strategy that should be discussed in a separate, dedicated secret rotation discussion. And why I don't think we should attempt to figure it out with this PR.
In any case, I think we should figure out how best to read the file once on startup.
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 updated patch set now only reads in the files once at startup.
To allow consumers access to the raw values close to what is written in the config, the attributes
_{client_secret,admin_token}{,_path}
are part of the dataclass – with leading underscore to underline their lower-level nature. The methodsclient_secret
andadmin_token
on the other hand provide convenient access for a consumer to the secret, independently of where it initially came from.You are right, I think those maybe-future plans should not impede the best solution to the problem at hand. It was not my intention to overload the PR with a discussion about secret rotation. In the meantime I had some helpful and structuring conversations about it at FOSDEM, and I will write up an issue to discuss it further.