# Files

> Where attachments, avatars and emojis live, why they’re served from their own hostname, what anyone can read, and what’s kept privately for the staff.

## The S3 store

Files live in an S3-compatible store that runs in the kit: **Silo**
(`pgsty/silo`), the community continuation of MinIO, which stopped publishing images and archived
its repository. It speaks the same S3 API as the cloud stores, and keeps everything in the
`s3-data` volume.

Browsers upload straight to it with a short-lived signed URL that the API gives them, sized and
typed for that one file; the API then checks the file’s real type from its first bytes before
accepting it. Uploads that are never finished are deleted after a day.

## Its own hostname

Files are served from `KLANG_FILES_DOMAIN`, never from the app’s hostname, so an uploaded file
can’t run as the app, whatever it contains. Caddy passes that whole hostname to the store, except
its administration, which stays inside.

## Who can read what

Attachments aren’t private. Anyone who has a file’s URL can open it without signing in, as on
Klang Cloud: a file sent in a private channel and then shared outside it can be opened by
whoever gets the link. The URLs carry a long random part, so they can’t be guessed, and nobody
can list the bucket.

| Bucket                   | Who reads it                                                                                                                                                                                                      |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `klang-attachments`      | Anyone who has a file’s address (each one carries a random part), like the attachments of Klang Cloud. **Nobody can list it**: knowing one address doesn’t reveal any other                                       |
| `klang-private-evidence` | Nobody without the API’s key. It keeps what the staff must preserve: a copy of an image before a restricted decision removes it (child safety, terrorism), and the files of a reported message its author deletes |

`s3-init` sets this up at every start, so a change to the policy reaches existing installs when
they update. The API has its own key, limited to these two buckets; the store’s root key is only
used by `s3-init`.

## Another S3 store

The API speaks plain S3, but the kit isn’t built for an outside store: the web and the panel allow
one files hostname in their security policy, for both uploads and reads, and expect the bucket to be
called `klang-attachments` under it. An outside store would need that same hostname in front of it,
CORS for the app’s origin, the policy above and the one-day rule for `pending/`. It isn’t tested:
use the kit’s store, and back it up ([Backups](https://docs.klang.gg/self-hosting/backups/)).

## Disk space

`LIMIT_UPLOAD_MB` and `LIMIT_STORAGE_GB` cap what each person can upload
([Configuration](https://docs.klang.gg/self-hosting/configuration/#limits)). To see how much the store uses:

```bash
docker compose exec s3 du -sh /data
```
