# The S3 server

CrushMFT speaks the protocol of Amazon S3 as a server. Backup programs, data tools and scripts that can "write to S3" can so write to CrushMFT, and what they write lands in the user's folders, wherever those really are: on a disk, on a file server, in another cloud.

There is no separate port. The S3 server answers on the [web listeners](Ports-HTTP.md): a request that is signed the S3 way is treated as S3, everything else as before.

## Access key and secret key

An S3 tool logs in with an access key and a secret key. For CrushMFT:

| The tool asks for | Enter |
|---|---|
| access key | the user name, a tilde, and the password: `alex~PASSWORD` |
| secret key | the password |

The user is an ordinary user of CrushMFT, with their folders and [permissions](VFS-Permissions.md).

A request is accepted when the password in the access key is right. Its signature is checked against the secret key too; with the server setting `s3_require_valid_signature` on, a request with a wrong signature is refused. On a new server that setting is off, so always enter the password as the secret key: then the signature and the checksums of the content are verified.

## Buckets

S3 has buckets; CrushMFT has a user's folders. How one becomes the other is a setting of the listener, `s3_bucket_mode`:

| Mode | A user sees | A bucket is |
|---|---|---|
| `single`, the default | one bucket, named `bucket` (`s3_bucket_name`) | the user's whole folder tree. Any bucket name a tool uses leads there. |
| `folders` | a bucket for each folder at the top of their tree | that folder |

Tools address a bucket in the path, `https://files.example.com/bucket/key`. With `s3_domain` set to a host name, the bucket can be in the host name instead, `https://bucket.s3.example.com/key`; that needs a wildcard entry in DNS and a certificate to match.

The listener setting `s3_mode` is `auto` (S3 beside everything else), `off` (no S3 on this port) or `only` (nothing but S3).

> [!NOTE]
> These four listener settings have no fields in Preferences yet. They are set in the listener's entry in the server's `prefs.XML`.

## Settings of the server

| Setting | What it does | New server |
|---|---|---|
| `s3_region` | the region the server calls itself. Tools must sign for it. | `us-east-1` |
| `s3_require_valid_signature` | refuse a request whose signature does not fit the secret key | false |
| `s3_require_protocol_permission` | only users with S3 among their allowed protocols may use it. Off: whoever may log in over the web may use S3. | false |
| `s3_signature_skew_minutes` | how far a tool's clock may be off | 15 |
| `s3_upload_staging_dir` | where uploads are collected before they are stored. Empty: the folder `s3_staging` in the server's folder. | empty |
| `s3_upload_expire_days` | after how many days the parts of an upload that was never finished are thrown away | 7 |
| `s3_delete_empty_parents` | a delete that leaves a folder empty removes the folder, as an S3 "prefix" vanishes with its last object | true |
| `s3_min_part_size` | the smallest part of a multipart upload that is accepted. 0: any. | 0 |

## What it can do

Listing of buckets and objects (both listing versions, with prefix, delimiter and paging), get, head, put, delete, delete of many, copy, uploads in parts with all their calls, ranged downloads, conditional requests, presigned links, checksums (MD5, SHA-1, SHA-256, CRC32, CRC32C, CRC64NVME), and the date of the original file from the metadata several tools send.

What S3 has and a file server has not is answered politely and does nothing: versioning (one version per object), access lists (accepted and ignored), tags, bucket policies. There is no answer for browser apps that need CORS, and the multi-region signature "SigV4a" is not supported.

## How an upload is stored

An upload is first collected in the staging folder, checked against its length and checksums, and then written into the user's folder in one piece, through the same path as an upload over any other protocol. So

- [events](Users-Events.md), [quotas](Quota.md), PGP on the folder and [filters](Users-Misc-File-Filters.md) all apply;
- a broken upload never leaves half a file in the user's folder;
- the staging folder needs free space for the largest uploads that are under way at the same time.

## Tried on the test server

With the command-line tool curl, signed for `us-east-1`, as the test user:

| Request | Answer |
|---|---|
| list buckets | one bucket, `bucket`, owner the user |
| list `bucket` with delimiter `/` | the user's top folders as prefixes, the files with size, date and ETag |
| put `bucket/files/s3-hello.txt` | `200`; the folder `files` was made on the way |
| head | `200`, with `ETag`, `Last-Modified`, `x-amz-meta-mtime` |
| get | the content |
| delete | `204`; the folder, now empty, went with it |
| get after the delete | `NoSuchKey`: "The specified key does not exist." |
| a wrong password in the access key | `InvalidAccessKeyId`: "The user name or password in the access key (user~password) is not valid." |
| the right access key, a wrong secret key | accepted, as described above |

For tools and their settings, see [Using S3 tools](Connect-S3.md). CrushMFT as an S3 **client**, with a user's folder in a bucket elsewhere, is [Amazon S3](VFS-S3.md).
