Object storage provider for Mastodon instance

Hey friends! I finally sat down today to figure out how to set up Mastodon with Storj. I tested the following instructions with Mastodon 4.0.2.

The summary is it works with the following config! It appears the missing trick from prior attempts is the S3_ALIAS_HOST field.

S3_ENABLED=true
S3_PROTOCOL=https
S3_REGION=us-east-1
S3_ENDPOINT=https://gateway.storjshare.io
S3_HOSTNAME=gateway.storjshare.io
S3_BUCKET=BUCKET
S3_ALIAS_HOST=link.storjshare.io/raw/LINKSHARINGKEY/BUCKET
AWS_ACCESS_KEY_ID=GATEWAYKEY
AWS_SECRET_ACCESS_KEY=GATEWAYSECRET

Okay, so the things you need here are:

  • A Storj bucket
  • Gateway credentials (access key and secret key)
  • Linksharing credentials for public access

Because of the linksharing credentials bit, the easiest way to generate all of the things you need is through our uplink CLI.

Assuming you have an uplink CLI set up (so that ls, mb, cp, etc work), the following should work for you:

To make a bucket, you can choose the bucketname, like mastodon, and do

uplink mb sj://mastodon

I’m going to keep calling it BUCKET for subsequent steps though.

To generate the GATEWAYKEY and GATEWAYSECRET, run

uplink share --readonly=false --register sj://BUCKET

This will make an access key and an access secret.

Finally, Storj doesn’t have the same sort of concept of public buckets that S3 has. We support public access, but it’s able to be more fine-grained than at the bucket level. So, we’re going to tell Mastodon about it with the S3_ALIAS_HOST setting, which seems to support path prefixes crammed in there as well.

To generate LINKSHARINGKEY you can do

uplink share --url --readonly --disallow-lists --not-after=none sj://BUCKET

You’ll get a URL, but the URL is not quite right. It will be of the form https://link.storjshare.io/s/LINKSHARINGKEY/BUCKET/, but the Mastodon S3_ALIAS_HOST should be link.storjshare.io/raw/LINKSHARINGKEY/BUCKET. Note the lack of https://, the swap of /s/ for /raw/, and the lack of trailing slash.

Once you have these things, you should be able to plop this configuration in to your Mastodon’s .env.production configuration and you should be all set to “boost” some media “toots”.

S3_ENABLED=true
S3_PROTOCOL=https
S3_REGION=us-east-1
S3_ENDPOINT=https://gateway.storjshare.io
S3_HOSTNAME=gateway.storjshare.io
S3_BUCKET=BUCKET
S3_ALIAS_HOST=link.storjshare.io/raw/LINKSHARINGKEY/BUCKET
AWS_ACCESS_KEY_ID=GATEWAYKEY
AWS_SECRET_ACCESS_KEY=GATEWAYSECRET

If you’re doing the rake mastodon:setup wizard, choosing Minio as your object storage provider and telling it you do want to access the uploaded files from your own domain should allow you to set the same settings in the setup wizard.

Of course, these instructions mean all your media will be served from link.storjshare.io, and maybe you don’t like that. You can always follow our instructions for sharing a bucket via DNS settings for your own domain name. If you do that, you’d replace S3_ALIAS_HOST with your domain name backed by Storj.

If you want a video walkthrough, while it’s not for Mastodon, the same problems are solved for Pixelfed in this Webinar: How to set up Pixelfed on Ubuntu 22.04 connected to Storj DCS - YouTube. Note that in the video, I stumbled over the gateway registration command, which should have been uplink share --readonly=false --register sj://pixelfed. We’re working to make that more intuitive.

17 Likes