use garage s3 storage #7

Open
opened 2024-05-24 21:22:50 +02:00 by taeer · 10 comments
Owner

Most fediversity apps have options to use s3 storage as a backend.

  • data replication
  • scales better (?)
  • easier to migrate (?)
Most fediversity apps have options to use s3 storage as a backend. - data replication - scales better (?) - easier to migrate (?)
Author
Owner
Resources: - [garage docs for integrating with apps](https://garagehq.deuxfleurs.fr/documentation/connect/apps/) - [mastodon docs for s3 storage](https://docs.joinmastodon.org/admin/optional/object-storage/) - [peertube docs for remote storage](https://docs.joinpeertube.org/maintain/remote-storage)
Author
Owner

Current status:

Mastodon

Successfully uploads images into s3 storage, and tries to display that image from the correct URL. If I copy-paste the URL from the web inspector, the image shows up.

However, on mastodon itself the image does not show up. This might be a CORS issue, though changing those settings didn't help.

PeerTube

Works!

PixelFed

It seems to be storing the uploaded images correctly in s3, but then when it tries to display them it's using a different URL. Going to that url does not display the image. A couple possibilities

  • one part of the app understand it's supposed to be using s3, and another doesn't
  • that URL should be redirecting to the proper place, and we're running into the same issue as Mastodon of not being able to display the image on a different page / at a different URL.
  • the URL should be redirecting to the proper place, but the redirection itself is broken.
# Current status: ## Mastodon Successfully uploads images into s3 storage, and tries to display that image from the correct URL. If I copy-paste the URL from the web inspector, the image shows up. However, on mastodon itself the image does not show up. This might be a CORS issue, though changing those settings didn't help. ## PeerTube Works! ## PixelFed It seems to be storing the uploaded images correctly in s3, but then when it tries to display them it's using a different URL. Going to that url does not display the image. A couple possibilities - one part of the app understand it's supposed to be using s3, and another doesn't - that URL should be redirecting to the proper place, and we're running into the same issue as Mastodon of not being able to display the image on a different page / at a different URL. - the URL should be redirecting to the proper place, but the redirection itself is broken.
Author
Owner

Mastodon update

It's not CORS. I solved the CORS problem already successfuly. Instead, it's security from the other end. Rather than garage refusing to serve the image, mastodon is refusing to display it because of Content-Security-Policy rules.

If I doctor the response headers for the page in the chromium devtools window to remove Content-Security-Policy, it works. The images load.

However, this doesn't immediately suggest a way to solve this in the NixOS configuration. Mastodon is supposed to set the CSP correctly automatically. The code for that is in content_security_policy.rb (among other places). I found a bunch of mastodon issues that had to do with CSP, but none seemed to correspond to this case.

I also tried doctoring the header in the nginx reverse proxy config, but I couldn't get that working. It's not a great long-term solution anyways, so I don't want to put more effort into it.

## Mastodon update It's **not** CORS. I solved the CORS problem already successfuly. Instead, it's security from the other end. Rather than garage refusing to serve the image, mastodon is refusing to display it because of Content-Security-Policy rules. If I doctor the response headers for the page in the chromium devtools window to remove `Content-Security-Policy`, it works. The images load. However, this doesn't immediately suggest a way to solve this in the NixOS configuration. Mastodon is **supposed** to set the CSP correctly automatically. The code for that is in [content_security_policy.rb](https://github.com/mastodon/mastodon/blob/main/app/lib/content_security_policy.rb) (among other places). I found a bunch of mastodon issues that had to do with CSP, but none seemed to correspond to this case. I also tried doctoring the header in the `nginx` reverse proxy config, but I couldn't get that working. It's not a great long-term solution anyways, so I don't want to put more effort into it.
Author
Owner

I'm working towards a minimal reproduction of the mastodon/garage issues using Nixos Tests taeer/simple-nixos-fediverse#9 (comment)

I'm working towards a minimal reproduction of the mastodon/garage issues using Nixos Tests https://git.fediversity.eu/taeer/simple-nixos-fediverse/issues/9#issuecomment-97
Author
Owner

Minimal reproduction is done, and I've submitted an issue upstream with mastodon
https://github.com/mastodon/mastodon/issues/31145

Minimal reproduction is done, and I've submitted an issue upstream with mastodon https://github.com/mastodon/mastodon/issues/31145
Author
Owner

Pixefled update:
There are two issues preventing us from seeing images posted.

  1. Has nothing to do with garage. Even with garage disabled, the same behaviour persists. See this nixpkgs issues: https://github.com/NixOS/nixpkgs/issues/235147
  2. Why are we accessing the filesystem to begin with, rather than garage? Because nginx is configured to do so in the pixelfed module in nixpkgs.
Pixefled update: There are two issues preventing us from seeing images posted. 1. Has nothing to do with garage. Even with garage disabled, the same behaviour persists. See this nixpkgs issues: https://github.com/NixOS/nixpkgs/issues/235147 2. Why are we accessing the filesystem to begin with, rather than garage? Because nginx is configured to do so in the pixelfed module in nixpkgs.
Owner

Pixelfed update

Commit 553a03b971 seems to feature a working Pixelfed+Garage setup. Here are some noteworthy comments:

  • There exists a DANGEROUSLY_SET_FILESYSTEM_DRIVER flag (formerly just FILESYSTEM_DRIVER) that one can put to s3 and that makes all the storage rely on the S3 backend (Garage, in our case). It is not clear whether we actually want this.

  • This flag differs from the FILESYSTEM_CLOUD flag that specifies that medias (but not avatars, for instance) should be uploaded to the cloud (Garage, in our case). It seems to not have much effect when it is s3 and so is DANGEROUSLY_SET_FILESYSTEM_DRIVER. If the later is not set, then the medias are first uploaded on the local storage and then copied to Garage. It is unclear if and when they are removed from the local storage.

  • Pixelfed uses the AWS_URL to which it appends the media's path and shows that on the client path. If requesting this file does not work, a piece of code on the client replaces the src by a “no preview” image. One should look in the developer tools to check the actual request that's being made.

  • In the commit mentioned, we set AWS_URL to "", meaning the src will just be the media's path. This works in the presence of a proxy configuration for Nginx routing the request to the Garage web address internally.

## Pixelfed update Commit 553a03b971d18e5a69e217552c973587b7a0d315 seems to feature a working Pixelfed+Garage setup. Here are some noteworthy comments: - There exists a `DANGEROUSLY_SET_FILESYSTEM_DRIVER` flag (formerly just `FILESYSTEM_DRIVER`) that one can put to `s3` and that makes _all_ the storage rely on the S3 backend (Garage, in our case). It is not clear whether we actually want this. - This flag differs from the `FILESYSTEM_CLOUD` flag that specifies that medias (but not avatars, for instance) should be uploaded to the cloud (Garage, in our case). It seems to not have much effect when it is `s3` and so is `DANGEROUSLY_SET_FILESYSTEM_DRIVER`. If the later is not set, then the medias are first uploaded on the local storage and then copied to Garage. It is unclear if and when they are removed from the local storage. - Pixelfed uses the `AWS_URL` to which it appends the media's path and shows that on the client path. If requesting this file does not work, a piece of code on the client replaces the `src` by a “no preview” image. One should look in the developer tools to check the actual request that's being made. - In the commit mentioned, we set `AWS_URL` to `""`, meaning the `src` will just be the media's path. This works in the presence of a proxy configuration for Nginx routing the request to the Garage web address internally.
Author
Owner

Images not showing up without DANGEROUSLY_SET_FILESYSTEM_DRIVER seems to be a generic issue with pixelfed on nixpkgs. See https://github.com/NixOS/nixpkgs/issues/235147 for discussion.

If we apply the patch someone there came up with, it works. See 1d8f514240 for a working config without DANGEROUSLY_SET_ETC_ETC

Images not showing up without `DANGEROUSLY_SET_FILESYSTEM_DRIVER` seems to be a generic issue with pixelfed on nixpkgs. See https://github.com/NixOS/nixpkgs/issues/235147 for discussion. If we apply the [patch someone there came up with](https://git.hubrecht.ovh/hubrecht/nixos/src/commit/411ce0386c475eb569381b6a9f719ec49e4fc04e/machines/dell-r730/pixelfed/01-local-filesystem.patch), it works. See 1d8f514240cb8982683da9d6bed5af91fe041360 for a working config without `DANGEROUSLY_SET_ETC_ETC`
Author
Owner

In the commit mentioned, we set AWS_URL to "", meaning the src will just be the media's path. This works in the presence of a proxy configuration for Nginx routing the request to the Garage web address internally.

we can also set AWS_URL to the public web endpoint of garage http://pixelfed.web.garage.localhost:3902/. In this case we don't need to set any nginx proxy_pass. This is done in the next commit e7ffd94c5e.

> In the commit mentioned, we set `AWS_URL` to `""`, meaning the `src` will just be the media's path. This works in the presence of a proxy configuration for Nginx routing the request to the Garage web address internally. we can also set `AWS_URL` to the public web endpoint of garage `http://pixelfed.web.garage.localhost:3902/`. In this case we don't need to set any nginx proxy_pass. This is done in the next commit e7ffd94c5e0169dd71afc3e882c335f3abafae1b.
Owner

Found this discussion which links to these two issues. Lots of confusing things, but in particular:

image

Found [this discussion](https://github.com/pixelfed/pixelfed/discussions/5150) which links to [these](https://github.com/pixelfed/pixelfed/issues/4348) [two](https://github.com/pixelfed/pixelfed/issues/4348) issues. Lots of confusing things, but in particular: ![image](/attachments/1637c0c8-152e-470f-a099-cce6fd99792a)
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Fediversity/simple-nixos-fediverse#7
No description provided.