Skip to content

Keep recordings in your own bucket

Your organisation can keep its recordings in a bucket at its own site, in storage that speaks the S3 protocol. People upload to the bucket and view from it in their browsers, the runner reads from it and deletes from it, and youSleep's servers do not reach it. youSleep holds the bucket's key, encrypted, and signs each request when it is needed; the browser or the runner sends it to the bucket directly.

Analyses of the recordings in the bucket run at your site, so your organisation sets up on-site compute first (Set up a site). From each recording youSleep receives its header, cleaned by the project's rule, its annotation events without their free text, and the analyses' results.

Who does what

Step Who Where
1. Request on-site storage The organisation's owner The platform
2. Accept the site agreement The organisation's owner The platform
3. Turn on on-site storage youSleep
4. Create the bucket, its key and its CORS rule Your IT Your storage
5. Register the bucket An owner or admin, with your IT The platform
6. Check it from the browser An owner or admin A computer on your network
7. Confirm youSleep's servers cannot reach it An owner or admin The platform
8. Let the runner reach the bucket Your IT The runner's computer
9. Store projects in it Whoever creates a project; owners and admins may require it The platform

The steps on the platform are on the Storage page of your organisation (Organisation → Storage), which its owner and admins see, with each step's state. An acceptance of the site agreement's latest version serves on-site compute and storage alike. Your IT can prepare the bucket while steps 1 to 3 are under way.

4: the bucket

What the storage must do

Storage that does the following works, whoever makes it:

  • HTTPS, with a certificate your browsers trust.
  • Path-style addresses, with the bucket's name after the endpoint: https://<endpoint>/<bucket>/<key>, where the endpoint and the bucket are the ones you register in step 5.
  • Requests signed with AWS Signature Version 4 in the query string, in the region you register.
  • GET, with Range, and with If-Match on an object's ETag.
  • PUT of a whole recording in one request, up to 5 GB, with If-None-Match: * so that an upload never replaces a file. Storage that ignores If-None-Match passes the check with a warning. youSleep writes only under youSleep/.
  • DELETE, from the runner, of files under youSleep/: youSleep deletes only what it wrote, never a file you registered where it was (its key can be confined to this). Browsers delete nothing.
  • ListObjectsV2, with a prefix, the / delimiter and continuation tokens.
  • An ETag on every object, or a Last-Modified that changes when the file does. youSleep compares both, with the size, to tell that a registered file is unchanged: a gateway that serves files on disk may give a file written there no ETag, or keep an old one, while its modification time changes with it.
  • A CORS rule for the browsers (below).

The browser check in step 6 tries these from where people will use the bucket.

Its key

The key youSleep holds may:

  • list the bucket and read any object in it, so that files already in the bucket can be registered where they are;
  • write and delete objects under youSleep/, where youSleep writes everything it writes: uploads and the checks' test files. Only the runner deletes.

A key confined to this passes the check. On AWS S3, and on storage that takes AWS-style policies, such as MinIO, this policy confines it, with your bucket's name in place of <bucket>:

{
  "Version": "2012-10-17",
  "Statement": [
    {"Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::<bucket>"},
    {"Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<bucket>/*"},
    {"Effect": "Allow", "Action": ["s3:PutObject", "s3:DeleteObject"],
     "Resource": "arn:aws:s3:::<bucket>/youSleep/*"}
  ]
}

Cloudflare R2 scopes a token to buckets, not to prefixes: give it Object Read & Write on this bucket alone.

Its CORS rule

Browsers reach the bucket only if its CORS rule allows youSleep's address. The Storage page shows the rule, with that address, when you register the bucket and when a check fails:

[
  {
    "AllowedOrigins": ["https://portal.yousleep.ai"],
    "AllowedMethods": ["GET", "HEAD", "PUT"],
    "AllowedHeaders": ["Content-Type", "Range", "If-Match", "If-None-Match"],
    "ExposeHeaders": ["ETag", "Content-Range", "Content-Length", "Accept-Ranges"],
    "MaxAgeSeconds": 3600
  }
]

Browsers use GET and HEAD to view and register recordings and PUT to upload them. They delete nothing: recordings are deleted by the runner, and a browser can send only the requests youSleep has signed for it.

  • AWS S3: the bucket's Permissions, Cross-origin resource sharing (CORS): paste the rule.
  • Cloudflare R2: the bucket's Settings, CORS policy: paste the rule.
  • Other S3 storage takes the same rule through the S3 API. Under Other S3 storage, the Storage page gives the aws s3api put-bucket-cors command that sets it, with your bucket filled in. Some storage sets CORS for the whole server rather than for each bucket; its documentation says how, with the same origin, methods and headers.

Its network

People's browsers and the runner reach the bucket; youSleep's servers should not. Keep it on your network, where its key is of no use to anyone else. Someone off your network still sees a project's studies and results, but not its recordings: where the bucket gives no answer, youSleep tells them to connect to your network, or to its VPN.

Recordings on a file share

youSleep reaches storage only through S3. If your recordings are on a file share (NFS, SMB), an S3 gateway in front of it can serve its files as objects: Versity S3 Gateway and SeaweedFS are two. youSleep neither supplies nor supports a gateway; yours must do what the storage must do above, and the browser check tries it. To youSleep, a file renamed or moved on the share is a new object (What youSleep does in the bucket).

5 to 7: on the platform

  1. Register the bucket on the Storage page: its endpoint (https://, a host and an optional port), its region (auto on Cloudflare R2), its name, and the key's ID and secret. youSleep keeps the secret encrypted and never shows it again.
  2. Check it from the browser, on a computer on the network where people will use youSleep. The browser writes a test file under youSleep/checks/, reads part of it back, lists it and tries to write it again. The file stays as a record of the check, with its time and ID; you can delete the folder's files or let a lifecycle rule expire them. A request that gets no answer is most often the CORS rule, the certificate or the network.
  3. youSleep's servers try to reach the bucket, and should fail. They open only a TCP connection, and only to a public address. If they reach it, restrict the bucket to your network and try again, or acknowledge on the page that it is reachable.

The bucket is ready once the check has passed and youSleep's servers could not reach it, or you acknowledged that they could.

8: let the runner reach the bucket

The runner sends requests only to the storage addresses its configuration names (policy.storage_origins). The bucket's address is its endpoint. Once the bucket is registered, the install command on Add a runner names it. For a runner installed before, run its install script again with --storage-origin for every address, the bucket's included (Configuration): a repeated option replaces the whole list. The Storage page shows the command with every address, and whether each runner names the bucket's and takes ingest and delete jobs, as it reports. Allow the runner's computer to reach the bucket through your firewall too.

Then run doctor on the runner's computer (Check the runner). It runs the browser check's steps from there, on a test file under youSleep/checks/, and then deletes the file, as the runner deletes recordings; the Storage page shows the runner's check beside the browser's. A bucket address the configuration does not name fails it without a request sent.

9: store projects in it

Once the bucket is ready, a new project is stored in it unless whoever creates the project chooses youSleep's storage. A project's place is fixed when it is created: projects created before stay where they are.

Your organisation's owners and admins can keep every recording at your site, on the Storage page, once your analyses run there. New projects are then stored only in the bucket, and projects in youSleep's storage take no new recordings.

Every member of your organisation can list the bucket and read the files in it through youSleep, and youSleep records each listing and read in your organisation's audit trail. Keep files that only some members may see in another bucket.

What youSleep does in the bucket

  • Uploads go under youSleep/projects/, in a folder per project and a file per recording, named by their IDs, each written once. When someone deletes the recording in youSleep, the runner deletes the upload.
  • Files already in the bucket are registered where they are, from Add studies, Files in your bucket. Nothing is copied, and youSleep never writes or deletes them: deleting such a recording in youSleep only unregisters it.
  • A registered file is the file at its path. Look for new files lists the project's folders again, and also finds the registered files that are no longer there as they were: renamed, moved, deleted, or changed in size, ETag or modification time. Such a recording is missing at your site. Its results are kept, and it cannot be analysed until the file is back in place, unchanged. A file renamed or moved can be registered again, as a new recording.
  • A file put back as it was is there again. Moved back, or restored by a copy that keeps its dates (cp -p, rsync -a, most backup tools), it has its old size, ETag and modification time, and the next Look for new files finds it so.
  • A file written over with the same bytes counts as changed, for example a plain copy over itself or a save without edits: its modification time is new, and youSleep cannot see that its contents are not. Remove the recording and register the file again.
  • youSleep keeps no copy of the recordings in the bucket. The bucket's availability and backups are your site's.
  • If youSleep turns on-site storage off, keeping recordings at your site goes off with it, and new projects keep their recordings on youSleep's servers. Projects already in the bucket stay there and can still be viewed, analysed and deleted, but take no new recordings. If on-site compute goes off, your runners still delete files from the bucket and read the recordings already uploaded to it, and do nothing else.

Change the key or the bucket

  • Replace the key on the Storage page, and the browser check runs again with the new key. Revoke the key, and nothing is signed for the bucket until it has a new one: uploads, the viewer and the runner's reads stop.
  • Change the bucket while no project keeps its recordings in it. Once one does, register another bucket: new projects use it, and existing projects keep theirs.