# Data flows

See where the data is, how it moves and how it is protected.

## Where the data is kept

All the data that Platforma stores stays in the corporate infrastructure: in the storage and on the disks of the cloud account of your company or the servers of your company. MiLaboratories does not get any input data or results.

> **Caution:**
>
> The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) does not encrypt the files or the database itself: encryption at rest comes from the corporate storage and the disks that the Backend uses. The Terraform modules (The Terraform code that MiLaboratories provides to install Platforma. The cloud-specific Terraform modules make the cluster and its cloud parts in AWS or Google Cloud; the cloud-agnostic Terraform modules install Platforma into the cluster.) use the default keys of the cloud. The operator (The person who installs and runs Platforma in your company, for example an IT engineer or a bioinformatician.) can set customer-managed keys on the bucket and the disks; the cloud identity (The identity that the cloud gives to the Platforma pod (IAM roles for service accounts on AWS, Workload Identity on Google Cloud). With it, Platforma needs no access keys.) of the Backend then needs the right to use them.

#### Variant: Kubernetes cluster

```mermaid
flowchart LR
  subgraph user["Computer of each user"]
    app["Desktop App"]
  end
  subgraph company["Corporate infrastructure"]
    ep["Entry point"]
    be["Backend"]
    db[("Database disk")]
    logs[("Log disk")]
    ws[("Workspace: working folders of jobs")]
    jobs["Jobs"]
    bucket[("Primary storage")]
    lib[("Data libraries, read-only")]
  end
  app -- "requests, TLS" --> ep --> be
  app -- "files, HTTPS signed links" --> bucket
  be --> db
  be --> logs
  be <--> ws
  jobs <--> ws
  be <--> bucket
  be --> lib
```

**Diagram:** The Desktop App on the computer of each user sends its requests through the entry point to the Backend, over TLS. It exchanges files directly with the primary storage, over HTTPS with signed links. The Backend keeps its database and its logs on their own disks, reads the data libraries, and writes the results to the primary storage. In Kubernetes, jobs work only in the workspace; the Backend copies their input there and moves their results to the primary storage. All of it is in the corporate infrastructure.

| Data                                                                                                                                                                                             | Where it is                                                                                                                                                                                                                                                                      | Encrypted at rest                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| Results of all projects and the files that users upload                                                                                                                                          | Primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.): an Amazon S3 or Google Cloud Storage bucket                                                                                                    | By the bucket: Amazon S3 managed keys, or Google managed keys                                |
| Database: users, projects, permissions                                                                                                                                                           | Disk of the Backend                                                                                                                                                                                                                                                              | By the disk: AWS managed keys, Google managed keys, or the disks of your company             |
| Working folders of jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.)                                                            | Workspace (The storage where the Backend and all jobs keep the working files of running jobs. The Backend and the jobs use it at the same time. In Kubernetes, it is a network file system; in Single Server mode, it is a folder on the server.): Amazon EFS, Filestore, or NFS | By the file system: AWS managed keys, Google managed keys, or the NFS server of your company |
| Log files of the Backend                                                                                                                                                                         | Disk for logs                                                                                                                                                                                                                                                                    | Same as the database                                                                         |
| Backups of the database, made automatically                                                                                                                                                      | Primary storage                                                                                                                                                                                                                                                                  | Same as the primary storage                                                                  |
| Secrets: license key, master secret, sign-in (To show the Backend who you are, with a sign-in provider or a single-user token. The verb is "sign in"; the noun and the adjective are "sign-in".) | Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) Secrets in the namespace of Platforma                                                                                                                    | By the cluster: Amazon EKS and Google Kubernetes Engine encrypt Secrets at rest              |
| Data on screen, downloaded results and the cache of recently used results                                                                                                                        | Computer of each user. The Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.) keeps the cache in its data folder (by default `~/Platforma`), one folder for each server.                             | By the disk encryption of the computer. The cache itself is not encrypted.                   |

#### Variant: Single Server

| Data                                                                      | Where it is                                                                                                                                                                          | Encrypted at rest                                                                                              |
| ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- |
| Results of all projects and the files that users upload                   | Primary storage: a folder on the server, or an Amazon S3 or Google Cloud Storage bucket                                                                                              | By the disk encryption of the server, or by the bucket                                                         |
| Database: users, projects, permissions                                    | The data folder of the Backend on the server (by default `~/.platforma/backend`)                                                                                                     | By the disk encryption of the server                                                                           |
| Working folders of jobs and downloaded tools                              | The data folder of the Backend                                                                                                                                                       | By the disk encryption of the server                                                                           |
| Log files of the Backend                                                  | The data folder of the Backend                                                                                                                                                       | By the disk encryption of the server                                                                           |
| Backups of the database, made automatically                               | Primary storage                                                                                                                                                                      | Same as the primary storage                                                                                    |
| Secrets: license key, master secret, sign-in                              | Files or environment variables that the operator gives the Backend. In the data folder: the single-user token and the key of a self-signed certificate, when the Backend makes them. | By the disk encryption of the server. File rights must let only the system user of the Backend read the files. |
| Data on screen, downloaded results and the cache of recently used results | Computer of each user. The Desktop App keeps the cache in its data folder (by default `~/Platforma`), one folder for each server.                                                    | By the disk encryption of the computer. The cache itself is not encrypted.                                     |

The Backend also encrypts the SSO (Sign-in through the identity service of the company, with the same account as for other company systems.) sessions and the storage keys of the primary storage and the data libraries (A folder or bucket with input data of the company. Users select files from it in the Desktop App. Platforma only reads it.) in its own database, with AES-256-GCM and a key made from the [master secret](/security-secrets/#master-secret).

The cache of the Desktop App has a size limit, and it stays after sign-out. For how long it is kept, see [How long data is kept](/security-data-flows/#how-long-data-is-kept).

## Encryption in transit

Every connection to the services of MiLaboratories uses TLS. Inside the corporate network and the cloud account of your company, some connections do not use TLS: they are marked in the tables. The tables list the connections that carry the data; for all outbound connections, see [Outbound connections](/security-outbound-connections/).

#### Variant: Kubernetes cluster

```mermaid
flowchart LR
  app["Desktop App"] -- "TLS" --> ep["Entry point"]
  ep -- "no TLS by default" --> be["Backend"]
  app -- "HTTPS" --> ps[("Primary storage")]
  be -- "HTTPS" --> ps
  be -- "AWS: TLS, Google Cloud: no TLS" --> fs[("Workspace")]
  jobs["Jobs"] -- "AWS: TLS, Google Cloud: no TLS" --> fs
  be -- "HTTPS; LDAP with or without TLS" --> idp["Corporate identity provider or LDAP"]
  be -- "HTTPS" --> lib[("Data libraries")]
  be -- "HTTPS" --> mil["Services of MiLaboratories"]
  jobs -- "HTTPS, license check" --> mil
```

**Diagram:** The Desktop App connects to the entry point with TLS. From the entry point to the Backend, inside the cluster, there is no TLS by default. The Desktop App and the Backend connect to the primary storage with HTTPS. The Backend and the jobs connect to the workspace with TLS on AWS and without TLS on Google Cloud. The Backend connects to the corporate identity provider with HTTPS. It connects to the corporate LDAP directory with or without TLS, as the operator sets it. It connects to the data libraries and the services of MiLaboratories with HTTPS. Jobs connect to the license service with HTTPS.

| Connection                                                                                                                                                                                        | Protection                                                                                                                                                                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Desktop App to the entry point (The way in to the Backend from outside the cluster, a load balancer or an Ingress with a DNS name. It usually ends TLS and sends the traffic to the Backend pod.) | TLS, always. The certificate must be valid for the address of Platforma and trusted by the computers of users. On AWS it comes from AWS Certificate Manager, on Google Cloud from Certificate Manager.                                               |
| Entry point to the Backend                                                                                                                                                                        | No TLS by default: the requests, with the sessions of users, go unencrypted inside the cluster. The operator can turn on TLS on the Backend: then all ports of the Backend use TLS, the metrics port included, and these requests are encrypted too. |
| Desktop App and Backend to the primary storage                                                                                                                                                    | HTTPS. On AWS, the bucket refuses requests without TLS.                                                                                                                                                                                              |
| Backend and jobs to the workspace                                                                                                                                                                 | On AWS: NFS with TLS. On Google Cloud: NFS without TLS, open only to the nodes and pods of the cluster.                                                                                                                                              |
| Backend to the corporate identity provider or LDAP (The directory of users of a company. The Backend can check logins and passwords in it.) directory                                             | HTTPS. For LDAP, TLS when the operator sets it (an `ldaps://` address, or StartTLS).                                                                                                                                                                 |
| Backend to the data libraries                                                                                                                                                                     | HTTPS                                                                                                                                                                                                                                                |
| Backend to the services of MiLaboratories                                                                                                                                                         | HTTPS                                                                                                                                                                                                                                                |
| Jobs to the license service                                                                                                                                                                       | HTTPS                                                                                                                                                                                                                                                |

#### Variant: Single Server

```mermaid
flowchart LR
  app["Desktop App"] -- "TLS when it is on" --> be["Backend"]
  app -- "HTTPS, bucket only" --> ps[("Primary storage: a folder or a bucket")]
  be -- "disk, or HTTPS to a bucket" --> ps
  be -- "disk, no network" --> wf[("Workspace")]
  jobs["Jobs"] -- "disk, no network" --> wf
  be -- "HTTPS; LDAP with or without TLS" --> idp["Corporate identity provider or LDAP"]
  be -- "HTTPS to a bucket, disk for a folder" --> lib[("Data libraries")]
  be -- "HTTPS" --> mil["Services of MiLaboratories"]
  jobs -- "HTTPS, license check" --> mil
```

**Diagram:** In Single Server mode, the Desktop App connects to the Backend directly, with TLS when TLS is on in the Backend. The files of a folder storage come through the Backend, with the same protection; a bucket is reached with HTTPS. The Backend and the jobs use the workspace on the disk of the server, with no network. The Backend connects to the corporate identity provider with HTTPS, to the corporate LDAP directory with or without TLS, as the operator sets it, and to the services of MiLaboratories with HTTPS. The Backend reads a data library in a bucket with HTTPS, and a data library in a folder on the server from the disk. Jobs connect to the license service with HTTPS.

| Connection                                                   | Protection                                                                                                                                                                                         |
| ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Desktop App to the Backend                                   | TLS when TLS is on in the Backend: the Backend serves it on all its ports, with a corporate or a self-signed certificate. Without TLS, the requests, with the sessions of users, go unencrypted.   |
| Desktop App to the primary storage                           | A folder on the server: the Backend serves the files on its data address, port 6347, with the same protection as the requests (see [Open ports](/security-overview/#open-ports)). A bucket: HTTPS. |
| Backend and jobs to the workspace                            | No network: the workspace is a folder on the disk of the server.                                                                                                                                   |
| Backend to the corporate identity provider or LDAP directory | HTTPS. For LDAP, TLS when the operator sets it (an `ldaps://` address, or StartTLS).                                                                                                               |
| Backend to the data libraries                                | A bucket: HTTPS. A folder on the server: no network.                                                                                                                                               |
| Backend to the services of MiLaboratories                    | HTTPS                                                                                                                                                                                              |
| Jobs to the license service                                  | HTTPS                                                                                                                                                                                              |

## How files move

```mermaid
sequenceDiagram
  participant App as Desktop App
  participant BE as Backend
  participant PS as Primary storage
  App->>BE: Ask for a link to a file
  BE-->>App: Signed link, valid for a short time
  App->>PS: Download or upload the file with the link
  PS-->>App: File
```

**Diagram:** The Desktop App asks the Backend for a link to a file. The Backend answers with a signed link that is valid for a short time. The Desktop App downloads or uploads the file directly with the primary storage, with this link. With a bucket, the file does not go through the Backend.

When the primary storage is a bucket, large files do not slow down the Backend: the computers of users upload and download them directly from the bucket. For each file, the Backend gives a link that it signs with its cloud identity. The link works only for a short time (1 minute on Amazon S3, 1 hour on Google Cloud Storage). Only these links open the files, so the bucket does not need any public access settings.

When the primary storage is a folder on the server in Single Server mode (The mode in which the Backend and all its jobs run on one Linux machine, the server, with no Kubernetes cluster.), the Backend itself serves the files, also with signed links.

In a folder storage, the Backend checks each part of an upload; on Google Cloud Storage, it checks the whole file after the upload.

> **Caution:**
>
> The computers of users must reach the address of the bucket over the network: from the internet, or through the corporate VPN or private connection. A bucket that accepts requests only from the private network of the cluster stops their downloads. The jobs in the cluster then run normally, but the Desktop App cannot show any results of the analysis (tables, charts and so on).

## What jobs can reach

```mermaid
sequenceDiagram
  participant BE as Backend
  participant FS as Workspace
  participant Job
  participant PS as Primary storage
  BE->>FS: Put the input in a working folder
  BE->>Job: Start
  Job->>FS: Read the input, write the results
  BE->>PS: Move the results, remove the working folder
```

**Diagram:** In Kubernetes, the Backend puts the input of a job in a working folder in the workspace and starts the job. The job reads the input and writes its results in this folder. The Backend then moves the results to the primary storage and removes the working folder. The job never connects to the primary storage.

In Kubernetes, a tool in a job cannot read the corporate buckets: jobs do not get any cloud rights, storage keys or access to the data libraries. This is the same on every installation path (A set of tools and steps that installs Platforma. There are five installation paths: the AWS installer, the Google Cloud installer, the Terraform modules, the Helm chart and Single Server mode.), the installers included. On AWS, the jobs have an IAM role without policies: it gets rights only when the operator adds a policy. The Backend copies the input of a job to the workspace, starts the job, and moves the results to the primary storage. With the Terraform modules, the cluster also stops the pods of jobs from using the cloud identity of the nodes. In a cluster that the company provides, this is a requirement of the Kubernetes contract.

In Kubernetes, each job sees only its own working folder: its pod mounts only this folder of the workspace. A job cannot see the working folders of other jobs.

In Kubernetes, a job gets only the secret values that its Block (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) asks for, and only from one Secret that the operator chooses. By default, this is the license Secret, which holds only the license key: every Block that asks gets the license key. The master secret and the storage keys are in other Secrets, so no Block can get them, as long as the operator keeps them out of the Secret for jobs.

> **Caution:**
>
> In Single Server mode, jobs are isolated only when Docker is turned on: then each job runs in a container that sees only its own working folder. Without Docker, a job can read every file that the system user of the Backend can read. See [Single Server mode](/security-overview/#single-server-mode).

> **Why it is so:**
>
> Tools in jobs come from many developers. Because a job cannot reach the storage, each tool gets only the data that the Backend gives to its run.

## How long data is kept

```mermaid
timeline
  title How long data is kept
  Until the job ends : Working folder of a job
  Up to 5 days : Records of finished jobs
  7 days : Uploads that did not finish
  14 days : Backups of the database
  2 weeks after the last use : Installed tools
  3 months : Tool archives
```

**Diagram:** A timeline of how long Platforma keeps temporary data. The working folder of a job stays until the job ends. The records of finished jobs stay for up to 5 days, and uploads that did not finish for 7 days. Backups of the database stay for 14 days. Installed tools stay for 2 weeks after the last use, and tool archives for 3 months.

#### Variant: Kubernetes cluster

| Data                                       | Kept for                                                                                                                                                                                                                             | Removed by                 |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
| Results in the primary storage             | As long as a project uses them                                                                                                                                                                                                       | The Backend                |
| Working folder of a job                    | Until the job ends. In debug mode, 24 hours after the job ends.                                                                                                                                                                      | The Backend                |
| Records of finished jobs in the cluster    | Up to 5 days; they can be removed sooner                                                                                                                                                                                             | A cleanup job, every night |
| Log files                                  | The last 10 files of 1 GiB                                                                                                                                                                                                           | The Backend                |
| Backups of the database                    | The last 14, one every 24 hours                                                                                                                                                                                                      | The Backend                |
| Downloaded tools                           | 3 months for archives, 2 weeks after the last use for installed tools                                                                                                                                                                | The Backend                |
| Uploads that did not finish                | 7 days                                                                                                                                                                                                                               | A rule of the bucket       |
| Cache of results on the computer of a user | Recently used data, within the size limit (up to about 8 GiB for each kind of cache; the oldest files are removed first). The cache stays after sign-out. The folder of a server is removed after 30 days without use of the server. | The Desktop App            |

#### Variant: Single Server

| Data                                       | Kept for                                                                                                                                                                                                                             | Removed by      |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------- |
| Results in the primary storage             | As long as a project uses them                                                                                                                                                                                                       | The Backend     |
| Working folder of a job                    | Until the job ends                                                                                                                                                                                                                   | The Backend     |
| Log files                                  | The last 20 files of 20 MiB, compressed                                                                                                                                                                                              | The Backend     |
| Backups of the database                    | The last 14, one every 24 hours                                                                                                                                                                                                      | The Backend     |
| Downloaded tools                           | 3 months for archives, 2 weeks after the last use for installed tools                                                                                                                                                                | The Backend     |
| Cache of results on the computer of a user | Recently used data, within the size limit (up to about 8 GiB for each kind of cache; the oldest files are removed first). The cache stays after sign-out. The folder of a server is removed after 30 days without use of the server. | The Desktop App |

By default, the backups of the database are in the primary storage, and data that is deleted from the database stays in the backups for up to 14 days.

The records of finished jobs are not an audit record: Platforma does not guarantee to keep them for 5 days.

No rule of the bucket deletes or moves the results: only the Backend deletes files, when no project uses them.

## Backups and recovery

The Backend backs up its database automatically, once every 24 hours, and keeps the last 14 backups. It stores the backups in the primary storage. Thus the primary storage holds all the data that matters: the results, the files of users and the backups of the database. For where each kind of data is and how long it is kept, see [Where the data is kept](/security-data-flows/#where-the-data-is-kept) and [How long data is kept](/security-data-flows/#how-long-data-is-kept).

## The one critical point

The safety of the primary storage is the one critical point. Platforma does not make a copy of the primary storage. The operator protects it with the tools of the storage:

- For a bucket: versioning, soft delete or replication to a different location.
- For a folder on a server: the backup of the server.

## Recovery

To recover, the operator restores the database from a backup. The Backend must start with the same [master secret](/security-secrets/#master-secret): the database holds the stored keys sealed with a key made from the master secret, and only the same secret makes them usable again. For the steps, see [Restore](/maintain-backup-and-restore/#restore).

The newest backup is at most 24 hours old. Thus a restore can lose up to 24 hours of changes to projects, users and permissions. The results in the primary storage are not lost.

> **Caution:**
>
> - If the primary storage is lost and does not have protection of its own, the results and the backups of the database are lost together.
> - A lost master secret makes the stored keys in a restored database unusable.

> **Why it is so:**
>
> One place for all the data that matters makes protection simple: the operator protects one storage with the tools that the storage already has, and does not need a separate backup system for Platforma.

## Uninstall

With the Terraform modules, the Helm chart and the installers, the uninstall keeps the results when the operator follows the procedure. The operator then deletes the data on purpose, with a separate procedure. The teardown of the Google Cloud installer deletes the data only when the operator chooses its mode that deletes all data. See [Uninstall Platforma](/maintain-uninstalling/).

#### Variant: Kubernetes cluster

```mermaid
flowchart LR
  A["Uninstall the Backend"] --> B["Remove the cluster parts"] --> C["Remove the cloud parts"]
  C --> K[("Kept: primary storage, workspace, database disk")]
```

**Diagram:** With the Terraform modules, the operator uninstalls Platforma in three steps, in reverse order of the installation: the Backend, then the parts in the cluster, then the parts in the cloud. The primary storage, the workspace and the disk of the database stay after all three steps, and a new installation can use them again. The logs disk stays only when the operator chooses it.

When the operator uninstalls Platforma with the Terraform modules, the primary storage, the workspace and the disk of the database stay, and a new installation can use them again:

- The Terraform modules protect the bucket and the workspace that they make (on AWS, S3 and EFS; on Google Cloud, Cloud Storage and Filestore). The removal of the cloud parts stops until the operator takes these two out of the control of the modules.
- The database disk stays when the Backend and the cluster are removed.
- The logs disk stays only when the operator chooses this in the settings of the modules. By default, it is deleted: a new installation works the same with a new, empty logs disk.
- To use the kept data again, the operator gives the bucket, the workspace and the database disk to the new installation in an optional input of the modules. Without this input, the modules make new ones.

#### Variant: Single Server

To uninstall Platforma, the operator removes the service of the Backend. The data folder of the Backend, with the database and the logs, stays on the server until the operator deletes it. The primary storage also stays.

## Next

- [Outbound connections](/security-outbound-connections/)
- [Secrets](/security-secrets/)

Source: https://docs.platforma.bio/security-data-flows/
