JOJ0 / synadm

Command line admin tool for Synapse (the Matrix reference homeserver)
https://synadm.readthedocs.io
GNU General Public License v3.0
186 stars 25 forks source link

Synapse returned status code 400 - Can only delete local media #142

Closed ZhenyaPav closed 7 months ago

ZhenyaPav commented 8 months ago

I'm unable to use synadm media delete, as it returns this, without deleting anything:

WARNING Synapse returned status code 400
errcode  M_UNKNOWN
error    Can only delete local media

The synapse server was installed using matrix-docker-ansible-deploy.

JacksonChen666 commented 8 months ago

What's the full synadm command that you ran?

ZhenyaPav commented 8 months ago

What's the full synadm command that you ran?

synadm media delete -d 3

JOJ0 commented 8 months ago

Can you show us a

synadm -vv media delete -d 3

maybe remove secrets before posting

ZhenyaPav commented 8 months ago

synadm -vv media delete -d 3

DEBUG Config entry read. user: (username)
DEBUG Config entry read. token: REDACTED
DEBUG Config entry read. base_url: http://192.168.(local ip):8008
DEBUG Config entry read. admin_path: /_synapse/admin
DEBUG Config entry read. matrix_path: /_matrix
DEBUG Config entry read. timeout: 30
DEBUG Config entry read. server_discovery: well-known
DEBUG Config entry read. homeserver: matrix.(domain name)
DEBUG Config entry read. ssl_verify: True
DEBUG Config entry read. format: human
DEBUG Formatter in use: human - <function humanize at 0x7fad27985b20>
DEBUG Received --before-days: 3
INFO  Deleting local media older than timestamp: 1709750339095,
INFO  which is the date: 2024-03-06 20:38:59.095000
INFO  Querying post on http://192.168.(local ip):8008/_synapse/admin/v1/media/matrix.(domain name)/delete
WARNING Synapse returned status code 400
errcode  M_UNKNOWN
error    Can only delete local media

I think it might be caused by the fact that the server is running on a local machine, with a VPS being used as a proxy. I left the Admin API accessible only through local network intentionally.

JacksonChen666 commented 8 months ago

Possible workaround: Run synadm config, and when you see this:

Homeserver name (auto-retrieval or matrix.DOMAIN):

Enter just the domain name without the matrix. part. Then use synadm media purge if you want to delete old remote media, or use synadm media delete for deleting local media.

(I'll write a full explanation of the issue later. It seems to be with synadm config being confusing for the user, and apparently a deprecation we seemed missed on the synapse admin local media delete API)

JacksonChen666 commented 8 months ago

I happened to have the exact same issue. I think I know what's happening, so here's the explanation of the issue:

synadm config asks you for the homeserver name like this:

Homeserver name (auto-retrieval or matrix.DOMAIN):

The user (probably, and in this case) follows the suggestion of matrix.DOMAIN and inputs, for example, matrix.example.com. That configuration value is passed into the API for deleting local media[^naming], as seen before:

INFO  Querying post on http://192.168.(local ip):8008/_synapse/admin/v1/media/matrix.(domain name)/delete

However, with delegation, Synapse only treats example.com as itself, even if hosted on matrix.example.com.

So the "homeserver name" should've been inputted as example.com, not matrix.example.com. If auto-retrieval was used instead, that would mean the homeserver name is set to example.com, not matrix.example.com.

Basically, synadm config tells you to write the wrong thing.

We can do any of these to fix the issue:

[^naming]: The synadm command for deleting local media is somewhat confusingly named as synadm media delete (used in this issue), while for remote media it's named synadm media purge. The help text in synadm media delete does not make the distinction clear between deleting local media and remote cached media.

ZhenyaPav commented 7 months ago

Possible workaround: Run synadm config, and when you see this:

Homeserver name (auto-retrieval or matrix.DOMAIN):

Enter just the domain name without the matrix. part. Then use synadm media purge if you want to delete old remote media, or use synadm media delete for deleting local media.

(I'll write a full explanation of the issue later. It seems to be with synadm config being confusing for the user, and apparently a deprecation we seemed missed on the synapse admin local media delete API)

This seems to fix the issue

JacksonChen666 commented 7 months ago

Keeping this issue open because the problem (a confusing synadm config) is still there.