# Secrets

See which secrets Platforma needs, who makes them and where they are kept.

## How secrets are handled

The secrets stay under the control of your company. None of 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.) creates a Secret, so no secret value is in the files that Terraform keeps or prints (state, plan, logs). The operator (The person who installs and runs Platforma in your company, for example an IT engineer or a bioinformatician.) creates the Secrets in the namespace of Platforma: by hand, or with a sync from the corporate secret manager.

The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) gets each secret in one of three ways: from an environment variable, from a file, or from an option on the command line. These secrets can come from files:

- the license key;
- the master secret;
- the 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 SSO (Sign-in through the identity service of the company, with the same account as for other company systems.) client secret;
- the LDAP (The directory of users of a company. The Backend can check logins and passwords in it.) bind password;
- the S3 keys of each data library (A folder or bucket with input data of the company. Users select files from it in the Desktop App. Platforma only reads it.);
- the key files of Google service accounts.

Other programs on the same machine can see the command line in the list of processes. So the operator gives secrets as files or environment variables.

#### Variant: Kubernetes cluster

The Helm chart of Platforma, which the Terraform modules also use, never puts a secret on the command line of the Backend. It mounts the master secret, the 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".) secrets and the S3 keys of the data libraries as files from their Secrets. The sign-in secrets are the static list of users, the SSO client secret, the LDAP bind password and certificates. The license key comes as a file and as the environment variable `PL_LICENSE`. The single-user token and the S3 keys of the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.) come as environment variables. Each value comes from a Secret in the namespace of Platforma.

The Helm chart accepts only the names of Secrets, never secret values. At installation, it checks that each Secret exists and has its key. It stops when a secret option of the Backend is in its extra options, or when a secret variable is in its plain-text variables.

The AWS installer keeps the secrets that the operator gives as stack parameters (the license key, the sign-in secrets and the keys of the data libraries) in AWS Secrets Manager. CloudFormation does not show the values of these parameters, and the installer reads them from Secrets Manager.

The Google Cloud installer keeps each secret value in Google Secret Manager, in the project of the installation. Terraform and Infrastructure Manager do not get the values: only the names of the Secrets. After it makes the cluster, the installer writes the Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) Secrets in the namespace `platforma` from Secret Manager. The Backend gets the values from these Secrets. The secrets have the label `platforma-installation=<name>-cluster`, where `<name>` is the deployment name:

| Secret Manager secret                                              | Holds                                               | Kubernetes Secret                      |
| ------------------------------------------------------------------ | --------------------------------------------------- | -------------------------------------- |
| `<name>-cluster-platforma-master-secret`                           | the master secret                                   | `platforma-master-secret`              |
| `<name>-cluster-admin-password`                                    | the password of the administrator login `platforma` | `platforma-admin-htpasswd` (as a hash) |
| `<name>-cluster-license-key`                                       | the license key                                     | `platforma-license`                    |
| `<name>-cluster-htpasswd`                                          | the static list of users                            | `platforma-htpasswd-provided`          |
| `<name>-cluster-ldap-search-password`                              | the password of the LDAP search user                | `platforma-ldap-search-password`       |
| `<name>-cluster-google-client-secret`                              | the client secret of Google sign-in                 | `platforma-sso-client-secret`          |
| `<name>-cluster-datasource-<library>-access-key` and `-secret-key` | the S3 keys of a data library                       | `platforma-datasource-<library>`       |

A secret exists only when its setting is on. The installer makes the master secret and the administrator password itself. The keys of the demo data library of MiLaboratories are public, so they go only into a Kubernetes Secret.

With the Terraform modules, access to the cloud on AWS and Google Cloud uses cloud identities, so there are no long-lived cloud keys to keep.

#### Variant: Single Server

The operator gives secrets as files or environment variables, and protects the files with file rights. A file option takes the path to a file that holds only the value; the Backend removes the spaces and line ends around it.

The Backend also writes some secrets into its data folder. The Backend can sign in users with a single-user token. When the operator does not give one, the Backend makes the token and writes it to a file that only its own system user can read (mode 0600). When the operator turns on a self-signed certificate, the Backend makes the TLS key and writes it to the data folder too.

Jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) get the environment of the Backend without the secrets: see [Single Server mode](/security-overview/#single-server-mode).

## The secrets of Platforma

| Secret                                                                                                                                                                                                                              | Necessary when                                                                                                                                                                                                                                                                                                                                                                               | Made by                                                                                                                   | When it changes                                                                                                                                                                                                                                                                               |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| License key                                                                                                                                                                                                                         | Always                                                                                                                                                                                                                                                                                                                                                                                       | MiLaboratories gives it; the operator puts it in a Secret                                                                 | The Backend checks the new key                                                                                                                                                                                                                                                                |
| [Master secret](/security-secrets/#master-secret)                                                                                                                                                                                   | Always, except with a single-user token                                                                                                                                                                                                                                                                                                                                                      | Operator: 32 random bytes                                                                                                 | All sessions end, and all users sign in again. The Backend deletes the stored SSO sessions, and encrypts again the storage keys that the operator gives in its settings. The database and the files stay readable. A storage that is no longer in the settings gets the status “secret lost”. |
| Static list of users: a file in the format of the `htpasswd` tool. The Backend accepts all formats of this tool, also weak hashes (MD5, SHA-1) and passwords in plain text. MiLaboratories recommends bcrypt (a strong, slow hash). | Sign-in with a static list of users                                                                                                                                                                                                                                                                                                                                                          | Operator                                                                                                                  | The Backend reads the file again. It refuses to renew the session of a removed user (see [Sign-in](/security-access-control/#sign-in)).                                                                                                                                                       |
| SSO client secret                                                                                                                                                                                                                   | SSO with Google: Google gives a client secret also to a public client. Platforma supports only public clients (with PKCE), and for a public client this value is not a secret: the Backend gives it to any client that starts an SSO sign-in ([SSO](/security-access-control/#sso)).                                                                                                         | Corporate identity provider                                                                                               | —                                                                                                                                                                                                                                                                                             |
| LDAP bind password                                                                                                                                                                                                                  | Sign-in with LDAP                                                                                                                                                                                                                                                                                                                                                                            | Corporate LDAP directory                                                                                                  | —                                                                                                                                                                                                                                                                                             |
| Single-user token                                                                                                                                                                                                                   | One user, for example a test installation. The token is the only key: the Backend makes its other keys from it.                                                                                                                                                                                                                                                                              | Operator; if the operator does not give one, the Backend makes a random token                                             | The user connects with the new token. The master secret is made from the token, so a new token has the same result as a new master secret.                                                                                                                                                    |
| Storage keys of the primary storage and the data libraries                                                                                                                                                                          | Storage with no 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.), for example storage with the Amazon S3 interface in the data center of your company                                                                                            | Corporate storage; the operator puts them in Secrets                                                                      | —                                                                                                                                                                                                                                                                                             |
| TLS certificate                                                                                                                                                                                                                     | In Kubernetes, always, for 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.). 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.), only when TLS is on in the Backend. | Certificate service of the cloud, or the operator. In Single Server mode, the Backend can make a self-signed certificate. | The cloud service renews its certificates; the operator renews the other certificates                                                                                                                                                                                                         |
| Secret for jobs (by default, the license Secret)                                                                                                                                                                                    | Kubernetes: jobs that need a key, for example a license key of a tool                                                                                                                                                                                                                                                                                                                        | Operator                                                                                                                  | Jobs get the keys that their 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                                                                                                                   |
| Pull secrets for image mirrors                                                                                                                                                                                                      | A private mirror that the nodes cannot reach with a cloud identity                                                                                                                                                                                                                                                                                                                           | Operator                                                                                                                  | —                                                                                                                                                                                                                                                                                             |

A change of the sign-in providers (A configured way for users to sign in to the Backend: single sign-on (SSO), LDAP or a static list of users. One Backend can have more than one.) (for example, a new provider) also makes all users sign in again.

With the AWS installer, the operator changes a secret in a stack update, and in the same update raises the parameter `SecretsRevision`: only then does the installer give the new value to the Backend.

With the Google Cloud installer, the operator changes a secret with a new run of `install.sh` with the new value. The installer adds a new version of the secret in Secret Manager only when the value is different. Then it writes the Kubernetes Secrets again and shows `created`, `updated` or `unchanged` for each of them. When a secret has a new version, the installer restarts the Backend: it reads the license key, the LDAP search password and the keys of the data libraries only at start. When no value changes, the Backend does not restart. The master secret is an exception: the installer keeps it until the operator gives a new value in `MASTER_SECRET` (see [Change the master secret](/configuration-users-and-roles/#change-the-master-secret)).

## Master secret

```mermaid
flowchart LR
  M["Master secret"] --> S["Signs the sessions of users"]
  M --> R["Signs the references to data"]
  M --> L["Signs the links to files in a folder storage"]
  M --> E["Encrypts the SSO sessions"]
  M --> K["Encrypts the storage keys of the primary storage and the data libraries"]
```

**Diagram:** The Backend makes five keys from the master secret: - a key that signs the sessions of users; - a key that signs the references to data; - a key that signs the links to files when the primary storage is a folder; - a key that encrypts the SSO sessions in the database; - a key that encrypts the storage keys of the primary storage and the data libraries in the database.

The Backend makes all its signing and encryption keys from one secret, the master secret. The operator, who sets up Platforma, keeps and backs up one value according to the security standards of your company.

The master secret encrypts only the SSO sessions and the storage keys of the primary storage and the data libraries in the database: the database and the files do not depend on it. The operator can change it; then all users sign in again. If the master secret is lost, the operator sets a new one, and the result is the same as a change.

> **Caution:**
>
> The operator keeps a copy of the master secret in a safe place. When the operator restores Platforma with the same master secret, users keep their sessions and the Backend keeps its stored keys.

## Next

- [Access control](/security-access-control/)

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