# Security overview

See how Platforma is built, where Block code runs and what is open to the network.

#### Variant: Kubernetes cluster

```mermaid
flowchart LR
  subgraph PC["Computer of each user"]
    app["Desktop App"]
  end

  subgraph CO["Corporate infrastructure"]
    direction TB
    entry["Entry point<br/>Ingress or Gateway, TLS"]
    subgraph NS["Namespace of Platforma (all runtime rights are here)"]
      direction TB
      backend["Backend"]
      jobs["Jobs"]
      secrets["Secrets: license, master secret, sign-in"]
      sa["Service account of the Backend"]
    end
    nodes["Cluster nodes"]
    identity["Cloud identity"]
    bucket["Primary storage<br/>(read and write)"]
    libs["Data libraries<br/>(read only)"]
    idp["Sign-in<br/>SSO or LDAP"]
    mirrors["Registry and image mirrors<br/>(optional)"]
  end

  subgraph NET["Outside endpoints"]
    direction TB
    lic["License service<br/>licensing-api.milaboratories.com"]
    assets["Assets registry<br/>bin.pl-open.science"]
    blk["Block registry<br/>blocks.pl-open.science"]
    images["Images of tools and of the Backend: containers.pl-open.science, quay.io, registry.k8s.io"]
    upd["Desktop App updates<br/>cdn-ga.platforma.bio"]
    mon["Monitoring service<br/>mon.pl-open.science"]
  end

  app -->|requests| entry
  entry --> backend
  app <-->|files| bucket
  app -.->|"SSO sign-in"| idp
  backend -.->|checks users| idp
  backend -->|reads| secrets
  backend -->|starts| jobs
  backend --- sa
  sa -->|bound to| identity
  identity -->|read / write| bucket
  identity -.->|read only| libs
  backend -->|required| lic
  jobs -->|"tools that check their license"| lic
  backend -->|"or a mirror"| assets
  backend -->|"or a mirror"| blk
  app -->|"Blocks, or a mirror"| blk
  nodes -->|"pull, or a mirror"| images
  app -.->|"updates, optional"| upd
  backend -.->|not needed to run| mon
  mirrors -.->|copies of| assets
  mirrors -.->|copies of| blk
  mirrors -.->|copies of| images

  classDef nsObj fill:#16a34a,stroke:#14532d,color:#ffffff
  classDef companyObj fill:#64748b,stroke:#334155,color:#ffffff
  classDef companyOpt fill:#cbd5e1,stroke:#334155,color:#0f172a,stroke-dasharray: 4 3
  classDef client fill:#e4f5d8,stroke:#14532d,color:#0f172a
  classDef internet fill:#dc2626,stroke:#7f1d1d,color:#ffffff
  classDef internetOpt fill:#fca5a5,stroke:#7f1d1d,color:#0f172a
  classDef optional fill:#f1f5f9,stroke:#64748b,color:#0f172a,stroke-dasharray: 4 3

  class app client
  class backend,jobs,secrets,sa nsObj
  class entry,nodes,identity,bucket,libs,idp companyObj
  class mirrors companyOpt
  class lic internet
  class assets,blk,images internetOpt
  class mon,upd optional

  style PC fill:#f0fdf4,stroke:#14532d,stroke-width:2px
  style CO fill:#f8fafc,stroke:#334155,stroke-width:2px
  style NS fill:#ecfdf5,stroke:#14532d,stroke-width:2px
  style NET fill:#fef2f2,stroke:#7f1d1d,stroke-width:2px
```

**Diagram:** At runtime, Platforma works inside one namespace of the Kubernetes cluster: the Backend, its jobs, its secrets (license, master secret, sign-in) and the service account of the Backend are there. Platforma does not need any Kubernetes rights outside this namespace, other than to read the state of its two job queues (the queues that decide when jobs start). Wider rights are necessary only to install it. Clients reach the Backend through one entry point (an Ingress or a Gateway, with TLS). The Desktop App on the computer of each user sends requests there, exchanges files with the primary storage, and signs in at the corporate identity provider when users sign in with SSO. The Backend checks the users with the corporate identity provider or the corporate LDAP directory. The service account of the Backend is bound to a cloud identity. Through it, the Backend reads and writes the primary storage and only reads the data libraries. Jobs do not have any cloud rights by default. Outbound connections: the license service of MiLaboratories (licensing-api.milaboratories.com) is required for the Backend, and for jobs with tools that check their license. The Backend reaches the assets registry (bin.pl-open.science), for assets such as reference genomes, and the Block registry (blocks.pl-open.science). The tools come as the images that the cluster nodes pull; the Desktop App reaches only the Block registry. These registries and the images are reached directly or through optional corporate mirrors. The monitoring service (mon.pl-open.science) gets usage records from the Backend when the license allows them (all licenses allow them); Platforma does not depend on them: it works when they cannot be sent. The Desktop App can get its updates from MiLaboratories (cdn-ga.platforma.bio, optional). For each connection and the reason for it, see Outbound connections. Legend: green = in the namespace of Platforma. Grey = a corporate resource (dashed: optional). Red = required outbound connection. Pale red = endpoint of MiLaboratories or a public image registry that can have a mirror in the corporate network. Light grey, dashed = MiLaboratories service that is not needed to run Platforma.

At runtime, Platforma works inside one namespace of the Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) cluster and does not need any Kubernetes rights outside it. The only exception: it reads the state of its two job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) queues, which decide when jobs start. Wider rights are necessary only to install it. Clients reach the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) through one 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.), and users 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".) with SSO (Sign-in through the identity service of the company, with the same account as for other company systems.), LDAP (The directory of users of a company. The Backend can check logins and passwords in it.) or a static list of users (A sign-in provider that is a file with the logins and the password hashes of the users, in the htpasswd format. The Backend reads it again when it changes.). The service account of the Backend uses a 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.) to reach the corporate storage.

#### Variant: Single Server

```mermaid
flowchart LR
  subgraph PC["Computer of each user"]
    app["Desktop App"]
  end

  subgraph CO["Corporate infrastructure"]
    direction TB
    subgraph SRV["Server in Single Server mode (all runtime rights are here)"]
      direction TB
      backend["Backend<br/>accepts clients, TLS optional"]
      jobs["Jobs<br/>processes, or containers with Docker"]
      secrets["License, master secret, sign-in settings"]
      work["Workspace"]
    end
    bucket["Primary storage<br/>folder on the server or a bucket<br/>(read and write)"]
    libs["Data libraries<br/>folders or buckets<br/>(read only)"]
    idp["Sign-in<br/>SSO or LDAP"]
    mirrors["Registry and image mirrors<br/>(optional)"]
  end

  subgraph NET["Outside endpoints"]
    direction TB
    lic["License service<br/>licensing-api.milaboratories.com"]
    soft["Software registry<br/>bin.pl-open.science<br/>(only without Docker)"]
    assets["Assets registry<br/>bin.pl-open.science"]
    blk["Block registry<br/>blocks.pl-open.science"]
    images["Software images<br/>(only with Docker)"]
    upd["Desktop App updates<br/>cdn-ga.platforma.bio"]
  end

  app -->|requests| backend
  app <-->|files| bucket
  app -.->|"SSO sign-in"| idp
  backend -.->|checks users| idp
  backend -->|reads| secrets
  backend -->|starts| jobs
  backend <--> work
  jobs <--> work
  backend <-->|read / write| bucket
  backend -.->|read only| libs
  backend -->|required| lic
  jobs -->|"tools that check their license"| lic
  backend -->|"or a mirror"| soft
  backend -->|"or a mirror"| assets
  backend -->|"or a mirror"| blk
  app -->|"Blocks, or a mirror"| blk
  jobs -->|"pull, or a mirror"| images
  app -.->|"updates, optional"| upd
  mirrors -.->|copies of| soft
  mirrors -.->|copies of| assets
  mirrors -.->|copies of| blk
  mirrors -.->|copies of| images

  classDef nsObj fill:#16a34a,stroke:#14532d,color:#ffffff
  classDef companyObj fill:#64748b,stroke:#334155,color:#ffffff
  classDef companyOpt fill:#cbd5e1,stroke:#334155,color:#0f172a,stroke-dasharray: 4 3
  classDef client fill:#e4f5d8,stroke:#14532d,color:#0f172a
  classDef internet fill:#dc2626,stroke:#7f1d1d,color:#ffffff
  classDef internetOpt fill:#fca5a5,stroke:#7f1d1d,color:#0f172a
  classDef optional fill:#f1f5f9,stroke:#64748b,color:#0f172a,stroke-dasharray: 4 3

  class app client
  class backend,jobs,secrets,work nsObj
  class bucket,libs,idp companyObj
  class mirrors companyOpt
  class lic internet
  class soft,assets,blk,images internetOpt
  class upd optional

  style PC fill:#f0fdf4,stroke:#14532d,stroke-width:2px
  style CO fill:#f8fafc,stroke:#334155,stroke-width:2px
  style SRV fill:#ecfdf5,stroke:#14532d,stroke-width:2px
  style NET fill:#fef2f2,stroke:#7f1d1d,stroke-width:2px
```

**Diagram:** In Single Server mode, the Backend and its jobs run on the server itself. Jobs run as processes, or as containers when Docker is on. The Backend accepts the connections of clients directly, and keeps the license, the master secret and the sign-in settings on the server. TLS is optional: the Backend serves it with a corporate or a self-signed certificate; without it, connections are not encrypted. The Desktop App on the computer of each user sends requests to the Backend, exchanges files with the primary storage, and signs in at the corporate identity provider when users sign in with SSO. The Backend checks the users with the corporate identity provider or the corporate LDAP directory, or with a static list of users in a file on the server, which does not need any network connection. The primary storage is a folder on the server or a bucket; the data libraries are folders or buckets that Platforma only reads. Outbound connections: the license service of MiLaboratories (licensing-api.milaboratories.com) is required for the Backend, and for jobs with tools that check their license. The Backend reaches the assets registry (bin.pl-open.science), for assets such as reference genomes, and the Block registry (blocks.pl-open.science). When the jobs run without Docker, it also reaches the software registry on the same host; the Desktop App reaches only the Block registry. These registries, and the software images (only with Docker), are reached directly or through optional corporate mirrors. In Single Server mode, the Backend does not send usage records to the monitoring service. The Desktop App can get its updates from MiLaboratories (cdn-ga.platforma.bio, optional). For each connection and the reason for it, see Outbound connections. Legend: green = on the server of Platforma. Grey = a corporate resource (dashed: optional). Red = required outbound connection. Pale red = endpoint of MiLaboratories or a public image registry that can have a mirror in the corporate network. Light grey, dashed = MiLaboratories service that is not needed to run Platforma.

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 and its jobs run on the server itself, and the Backend accepts the connections of clients directly. TLS is optional: the Backend serves it with a corporate or a self-signed certificate; without it, connections are not encrypted. Users sign in with SSO, LDAP or a static list of users, and the Backend reaches the corporate storage from the server.

> **Isolation in Single Server mode:**
>
> In Single Server mode, the analysis tools are isolated from the Backend only when Docker is turned on: then each job runs in a container that sees only its own working folder. Without Docker, the tools run as processes on the server, with the rights of the Backend.

> **Access to data libraries:**
>
> The diagram shows one of five ways for the Backend to read 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.): with its own cloud identity. The Backend can also use access keys, a cloud identity for each user, the Google account of each user, or a folder on the server or a volume. See [Data library access modes](/security-data-library-access/).

For the parts of Platforma and what each part does, see [the Desktop App and the Backend](/overview-how-platforma-works/#clients-and-the-backend).

## Single Server mode

In Single Server mode, the protection comes from the server itself. For where the data is and how it is encrypted, see [Where the data is kept](/security-data-flows/#where-the-data-is-kept).

- **System user.** The Backend runs as the system user that starts it, and its jobs run as the same user, so the rights of this user set the limit for the Backend and the jobs.
- **Environment of jobs.** Each job gets the environment variables of the Backend, also in a Docker container, but not its secrets. The Backend removes the license key, the master secret, the sign-in secrets, the storage keys and the paths of the files that hold them. It also removes the credentials of the AWS and Google Cloud tools, for example `AWS_SECRET_ACCESS_KEY` and `GOOGLE_APPLICATION_CREDENTIALS`.
- **Network.** By default, the Backend accepts connections only from the server itself. The operator (The person who installs and runs Platforma in your company, for example an IT engineer or a bioinformatician.) chooses the address that clients use, and the computers of users then reach two ports: 6345 for the API and 6347 for the files of a folder storage. The metrics port listens on the server only; the debug port is off. See [Open ports](/security-overview/#open-ports).
- **TLS.** TLS is off by default. The operator turns it on with a corporate certificate, or with a self-signed certificate that the Backend makes. Without TLS, connections are not encrypted.
- **Updates.** The operator installs a new version of the Backend when they choose.

> **Caution:**
>
> With a folder as primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.), every user can read the files of the server as a read-only data library, with the rights of the system user of the Backend. The operator can turn this off.
>
> Without Docker, a tool in a job can read every file that the system user of the Backend can read: the database, the secrets and the data of all users. Then use Single Server mode only when you trust all the Blocks (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) that users run. With Docker turned on, each job runs in a container that sees only its own working folder, and the Backend runs only tools that have a container image. See [What jobs can reach](/security-data-flows/#what-jobs-can-reach).

## Sandboxes for Block code

```mermaid
flowchart LR
  subgraph DA["Desktop App"]
    ui["Block UI: isolated view, no other pages or windows"]
    model["Block model: JavaScript sandbox"]
  end
  subgraph BE["Backend"]
    wf["Block workflow: sandbox, no network, no files"]
  end
  subgraph JB["Jobs"]
    tools["Tools: own container in Kubernetes; network as the cluster allows"]
  end
  ui --> model
  model --> wf
  wf -->|starts| tools
```

**Diagram:** Block code runs in three places, each with its limits. In the Desktop App, the Block UI runs in an isolated view that cannot open other pages or windows, and the Block model runs in a JavaScript sandbox. In the Backend, the Block workflow runs in a sandbox with no network and no file access. The workflow starts tools as jobs; in Kubernetes each job has its own container, and the tools can use the network as the cluster allows.

Platforma limits what Block code can do:

- The Block UI runs in an isolated view of the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.). It cannot open other pages or windows.
- The Block model runs in a JavaScript sandbox in the Desktop App.
- The Block workflow (The part of a Block that runs in the Backend. It starts the tools on the data and collects the results. Users do not edit it.) runs in a sandbox in the Backend. It does not have access to the network or to the file system. It can only call the functions of the Backend.

The tools that a Block starts run as jobs, outside the Backend program. In a Kubernetes cluster, each job runs in a container of its own. In Single Server mode, a job is a process on the server, or a container when Docker is turned on.

> **Caution:**
>
> The sandboxes apply to Block code, not to the tools. A tool in a job can use the network, unless the network of the cluster or the server stops it.

> **Why it is so:**
>
> Blocks come from registries, and more and more Blocks come from developers outside MiLaboratories. The sandboxes limit what Block code can do in the Desktop App and keep it away from the internals of the Backend.

## Sources and updates of each part

| Part              | Where it runs or lives                          | Who supplies it                                                                                                                                                                                                                                 | How it changes                                                                                            |
| ----------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| Desktop App       | Computer of each user                           | MiLaboratories                                                                                                                                                                                                                                  | Downloads its updates by itself and installs them when the user quits it, or at once when the user agrees |
| Backend           | Corporate infrastructure or cloud account       | MiLaboratories                                                                                                                                                                                                                                  | The operator installs a new version                                                                       |
| Blocks            | Desktop App and Backend                         | [Trusted Block registry](/security-vulnerability-management/#fixed-versions-of-components): MiLaboratories, or other developers that the user adds                                                                                              | Each Block has its own versions                                                                           |
| Software packages | Jobs                                            | Software registry (A service from which the Backend downloads the software packages of the tools that Blocks use. Only Single Server mode without Docker uses it; in a Kubernetes cluster and with Docker, the tools come as container images.) | Each Block version names its packages                                                                     |
| Primary storage   | Cloud bucket, or a folder on the Backend server | Operator                                                                                                                                                                                                                                        | Grows with the results                                                                                    |
| Data libraries    | Corporate storage                               | Operator                                                                                                                                                                                                                                        | Your company adds data                                                                                    |

A Block version can require a newer Desktop App. Then the Desktop App does not run that Block version until the user updates the Desktop App.

## Open ports

#### Variant: Kubernetes cluster

In Kubernetes, the entry point can be public, open to the internet or only to the corporate networks, or private, so that users reach it only through the corporate network or VPN. 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.) make a public entry point that is open to all addresses by default, so users connect from any network. Each request still needs a session of a user. In both clouds, the operator can let only the corporate networks reach the entry point, or make the entry point private. The Backend pod has these ports:

| Port | What                                                                                                                                                            | Open to                                                                    |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| 6345 | gRPC API for the clients: the Desktop App and pl-cli (The command-line client of Platforma. Administrators use it to manage users and projects on the Backend.) | Inside the cluster. From outside the cluster, only through the entry point |
| 9090 | Metrics and health                                                                                                                                              | Inside the cluster                                                         |
| 9091 | Debug API                                                                                                                                                       | `localhost` of the Backend pod only                                        |

The primary storage in Kubernetes is a bucket: the Desktop App gets the files from the bucket, not from the Backend. The entry point sends only the gRPC traffic to port 6345 of the pod. Port 6347, the data address in Single Server mode, is not open to clients. The Helm chart of Platforma does not open this port in the pod or its Service, and stops when an option would open it.

To reach the debug API, a person needs direct access to the pod, and thus permissions in the namespace of Platforma.

#### Variant: Single Server

In Single Server mode, the clients connect to the Backend directly, without an entry point. The Backend listens on these ports of the server:

| Port | What                                                                                                                                     | Open to                                                                                              |
| ---- | ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| 6345 | gRPC API for the clients: the Desktop App and pl-cli                                                                                     | The computers of users                                                                               |
| 6347 | Data address: the Desktop App uploads and downloads the files of the primary storage, when the primary storage is a folder on the server | The computers of users. With a bucket as the primary storage, the Desktop App does not use this port |
| 9090 | Metrics and health                                                                                                                       | The server only                                                                                      |
| 9091 | Debug API, off by default                                                                                                                | The server only                                                                                      |

The Backend listens on the listen address of the server, `127.0.0.1` by default: to accept connections from the computers of users, the operator sets this address, for example `0.0.0.0` (all addresses of the server). The firewall of the server must then let the computers of users reach ports 6345 and 6347, and must not let them reach the other ports.

The Desktop App gets the data address from the Backend. By default, this address is the listen address with port 6347, and `0.0.0.0` is not an address that a computer can connect to. Thus, with the listen address `0.0.0.0`, the operator also sets the data address to the host name that users type in the Desktop App, for example `https://platforma.example.com:6347`. For the options, see [Host name and DNS](/configuration-domain-and-tls/#host-name-and-dns).

> **Caution:**
>
> The operator can turn on a debug mode that makes the debug API listen on all addresses of the pod or the server. This mode is only for a short time, to find a problem.

## Next

- [Data library access modes](/security-data-library-access/)
- [Outbound connections](/security-outbound-connections/)
- [How Platforma works](/overview-how-platforma-works/)

Source: https://docs.platforma.bio/security-overview/
