Add debug log when HMAC incorrect#18474
Conversation
| user_registration_debug_logger.debug( | ||
| "UserRegisterServlet: Incorrect HMAC digest: actual=%s, expected=%s, registration_shared_secret=%s, body=%s", | ||
| got_mac, | ||
| want_mac, | ||
| self.hs.config.registration.registration_shared_secret, | ||
| body, | ||
| ) |
There was a problem hiding this comment.
As an update on the root cause on why we were seeing of HMAC incorrect error, @devonh found that the file for the registration_shared_secret_path itself had an incorrect/unexpected value.
Basically, we're running into the default Synapse behavior (of creating the file and secret if it doesn't exist) masking our deployment race condition where we would start up Synapse before the registration_shared_secret_path file was put in place:
registration_shared_secret_path[...]
If this file does not exist, Synapse will create a new shared secret on startup and store it in this file.
|
I'm taking this off the general review queue while #18474 (comment) is explored. |
| # XXX: We have to set this again because of a Python bug: | ||
| # https://github.com/python/cpython/issues/136958 (feel free to remove once | ||
| # that is resolved and we update to a newer Python version that includes the | ||
| # fix) | ||
| logger.setLevel(logging.NOTSET) |
There was a problem hiding this comment.
Ran into a bug with the built-in unittest Python library so we have this workaround for now, see python/cpython#136958
anoadragon453
left a comment
There was a problem hiding this comment.
This now LGTM!
Thanks for adding tests for the new logger class ✨
|
Thanks for the review and pushing the ball forward @devonh, @reivilibre, @erikjohnston, @anoadragon453 🦏 |
Spawning from getting
HMAC incorrecterrors that seem unexplainable except for theregistration_shared_secretbeing misconfigured. It's also possible my HMAC calculation is incorrect but every time I double-check the result with the known-good Python example (which matches Synapse's source), it's as expected.With these logs, we can actually debug whether
registration_shared_secretis being configured correctly or not.It also helps specifically when using
registration_shared_secret_pathsince the default Synapse behavior (of creating the file and secret if it doesn't exist) can mask deployment race condition where we would start up Synapse before theregistration_shared_secret_pathfile was put in place:This only applies to the
POST /_synapse/admin/v1/registerendpoint but does log very sensitive information so we've made it so you have to explicitly enable the logs by configuringsynapse.rest.admin.users.registration_debug(does not inherit root log level) (via our newExplicitlyConfiguredLogger)homeserver.yamlmyserver.log.config.yamlDev notes
Python bug with
logging.NOTSETandassertLogsandassertNoLogs: python/cpython#136958ExplicitlyConfiguredLoggerLog setup:
synapse/config/logger.pyLog setup in tests:
tests/test_utils/logging_setup.pyPull Request Checklist
EventStoretoEventWorkerStore.".code blocks.