Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19144.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in 1.142.0rc1 where any attempt to configure `matrix_authentication_service.secret_path` would prevent the homeserver from starting up.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this problem caught?

Can we be sure it doesn't happen elsewhere? (feels like no without manually auditing things or test coverage to stress these pieces)

When having a cursory look, only this stood out to me,

class MatrixRtcConfigModel(ParseModel):
transports: list = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this problem caught?

I raised this after the CI for element-hq/ess-helm#853 started failing on RC3

3 changes: 2 additions & 1 deletion synapse/config/mas.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class MasConfigModel(ParseModel):
enabled: StrictBool = False
endpoint: AnyHttpUrl = AnyHttpUrl("http://localhost:8080")
secret: Optional[StrictStr] = Field(default=None)
secret_path: Optional[FilePath] = Field(default=None)
# We set `strict=False` to allow `str` instances.
secret_path: Optional[FilePath] = Field(default=None, strict=False)

@model_validator(mode="after")
def verify_secret(self) -> Self:
Expand Down
7 changes: 7 additions & 0 deletions synapse/util/pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class ParseModel(BaseModel):

but otherwise uses Pydantic's default behaviour.

Strict mode can adversely affect some types of fields, and should be disabled
for a field if:

- the field's type is a `Path` or `FilePath`. Strict mode will refuse to
coerce from `str` (likely what the yaml parser will produce) to `FilePath`,
raising a `ValidationError`.
Comment on lines +36 to +38
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kinda feels like a bug with the pydantic.FilePath type 🤔. Of course it has to be parsed from a string. Feels like it should act like Annotated[StrictStr, AfterValidator(validate_file_path)]

May be worth finding existing issues tracking this or creating one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see both sides of the argument. On one hand, it would be a bit odd to allow coercion for one specific type (str -> FilePath) in strict mode. On the other, most people will be taking in paths as str types. There should be a simple way to validate that the file exists etc. (which is what people expect to do when setting the type of the field to FilePath).

So I agree that there's something either wrong/missing. I'll raise it as an issue in a bit while waiting for the release assets to build.


For now, ignore unknown fields. In the future, we could change this so that unknown
config values cause a ValidationError, provided the error messages are meaningful to
server operators.
Expand Down
Loading