# License

Give the license key of your company to the Backend, and keep it valid.

For an installation made with an installer, see [Install in cloud with installer](/install-cloud-installer/).

One license key serves the whole installation: all users who connect to the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) share its limits, so you do not manage licenses for each user. MiLaboratories gives the key to your company. The Backend reads the key at start and checks it with the license service of MiLaboratories. For what the license gives and how the check works, see [License](/overview-backend/#license) and [License check](/security-outbound-connections/#license-check).

The Backend needs HTTPS access to `licensing-api.milaboratories.com`, and so do the jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) of tools that check their own license, for example MiXCR. For the mirror and proxy limits, see [License check](/security-outbound-connections/#license-check). For all hosts that Platforma connects to, see [External services](/security-outbound-connections/); to send the traffic through the corporate proxy, see [Proxy and custom CA](/configuration-proxy-and-custom-ca/).

## Give the license to the Backend

#### Variant: Kubernetes cluster

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.) and the chart do not create the Secret with the license. Before the install:

1. Create the Secret in the namespace of the Backend. The default name of the Secret is `platforma-license`, and the default key is `MI_LICENSE`:

   ```sh
   kubectl create secret generic platforma-license \
     --namespace <namespace> \
     --from-literal=MI_LICENSE=<license-key>
   ```

2. Name the Secret in the settings of the Backend: in the input `backend_service` of the module `platforma-tf-services`, or in the values of the chart `platforma-backend`. With the default name and key, you do not have to set anything:

   *terraform.tfvars*

   ```hcl
   backend_service = {
     secrets = {
       license = { name = "platforma-license", key = "MI_LICENSE" }
     }
   }
   ```

   *values.yaml*

   ```yaml
   secrets:
     license: { name: platforma-license, key: MI_LICENSE }
   ```

The settings hold only a reference to the Secret, never the key itself, and the license comes only from this Secret. The chart stops when a license option (`--license`, `--license-file`) is in `extraArgs`, or a license variable (`PL_LICENSE`, `MI_LICENSE`, `PL_LICENSE_FILE`, `MI_LICENSE_FILE`) is in one of the `env` lists, also in `env.secretVariables`. The module gives `extra_args` and `env` to the chart, so the same applies to them. At each install and upgrade, the chart checks that the Secret exists and has the key.

The license Secret is also the default Secret for jobs, so the jobs of tools that check their own license, for example MiXCR, get the key from it. For the Secret of jobs, see [Jobs and resources](/configuration-jobs-and-resources/).

#### Variant: Single Server

Give the key in the environment variable `PL_LICENSE` of the Backend service, or put it in a license file. Do not give the key with `--license` on the command line: other users of the server can see the command line in the list of processes.

*Environment of the Backend service*

```sh
PL_LICENSE=<license-key>
```

Or a file that holds the key, readable only by the system user of the Backend:

*Environment of the Backend service*

```sh
PL_LICENSE_FILE=/etc/platforma/platforma.license
```

When neither is set, the Backend looks for one of these files in the home directory of its system user, in this order: `pl.license`, `.pl.license`, `mi.license`, `.mi.license`. Without a key, the Backend does not start.

> **Caution:**
>
> 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.), a user who has access to Docker on the server has root rights there, and can read the key and all other secrets of the Backend. Give access to Docker only to the people who administer the server.

## Check the license

At start, the Backend writes the result of the license check to its log:

- `License is OK`: the Backend accepts the license and runs computations.
- A line that starts with `License verification failed`: the license service refused the key. Users can 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".), and the Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.) shows the license problem.

#### Variant: Kubernetes cluster

```sh
kubectl logs --namespace <namespace> deployment/<release> | grep -i license
```

`<release>` is the name of the Helm release of the Backend: the Deployment has the same name.

To see the details of the license that the license service gives, run `--show-license-info` in the pod. The pod already has the key in `PL_LICENSE`. The command asks the license service, prints the license and exits; it does not change the running Backend:

```sh
kubectl exec --namespace <namespace> deployment/<release> -- /app/platforma --show-license-info
```

#### Variant: Single Server

Look for the same lines in the log of the Backend service. To see the details of the license that the license service gives, run the Backend with the same license setting and `--show-license-info`. The Backend asks the license service, prints the license and exits; it does not start the service:

```sh
PL_LICENSE_FILE=/etc/platforma/platforma.license platforma --show-license-info
```

## When the license is not valid

A license is not valid when it has expired, when it was revoked, or when the key is wrong. The Backend has two ways to react, and you choose one:

- **Start without computations** (default). The Backend starts, users can sign in and open their projects, and the Desktop App shows the license status. The Backend does not run any computations. This mode lets users and the operator (The person who installs and runs Platforma in your company, for example an IT engineer or a bioinformatician.) see the problem in the Desktop App.
- **Stop** (`--fail-fast-on-invalid-license`). The Backend does not start, and it stops when the license becomes invalid while it runs. Choose this mode when the monitoring of the cluster must show a failed start. In Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.), the pod then restarts again and again (`CrashLoopBackOff`) until the license is valid.

In the default mode, when the license becomes invalid while the Backend runs, the Backend stops, and Kubernetes or the service manager starts it again without computations. This is one restart, not a crash loop. When the license is valid again, the Backend stops and starts again with computations. With `--fail-fast-on-invalid-license`, the Backend stops and does not start again until the license is valid. In Single Server mode, set the service manager to start the Backend again after each stop, for example `Restart=always` in a systemd unit. New jobs do not start while the license is not valid. Jobs that already run usually run to the end; a MiXCR job can stop or run to the end, depending on the moment.

The flag is not covered by the chart values or the module inputs. Set it like this:

#### Variant: Kubernetes cluster

*terraform.tfvars*

```hcl
backend_service = {
  extra_args = ["--fail-fast-on-invalid-license"]
}
```

*values.yaml*

```yaml
extraArgs:
  - --fail-fast-on-invalid-license
```

#### Variant: Single Server

*Environment of the Backend service*

```sh
PL_FAIL_FAST_ON_INVALID_LICENSE=true
```

## Renew or change the license

When the license is renewed, MiLaboratories usually extends the same key at the license service, so you do not change anything in the installation: the Backend gets the new end date at its next check.

When your company gets a new key, put it where the Backend reads it, then restart the Backend: it reads the key only at start. For what the restart does, see [Restart of the Backend](/configuration-storage/#restart-of-the-backend). Users do not sign in again, because their sessions do not depend on the license.

#### Variant: Kubernetes cluster

Replace the key in the Secret, then restart the Backend:

```sh
kubectl create secret generic platforma-license \
  --namespace <namespace> \
  --from-literal=MI_LICENSE=<new-license-key> \
  --dry-run=client -o yaml | kubectl apply -f -


kubectl rollout restart --namespace <namespace> deployment/<release>
```

#### Variant: Single Server

Replace the key in `PL_LICENSE` or in the license file, then restart the Backend service.

## Usage records

In a Kubernetes cluster, the Backend sends [usage records](/security-outbound-connections/#usage-records) when the license allows it, by default to `https://mon.pl-open.science`. You cannot turn them off with a setting. Platforma does not depend on them: when the records cannot be sent, the work continues. You choose where the records go, with one setting, the address of the monitoring service:

- **The default address.** The records go to MiLaboratories. MiLaboratories recommends this, because the records help to support your company and to make Blocks (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) better.
- **A proxy of the company.** To see what goes out, give the address of a proxy that logs the records and forwards them to MiLaboratories.
- **An address that does not accept the records.** The records do not leave the company: this turns them off in practice.

The Backend posts each record to `<URL>/v1/exec_run_record`. For a proxy, use an `https://` address: with `http://`, the records go over the network without encryption. The setting is not covered by the chart values or the module inputs. In Single Server mode, the Backend does not send usage records, so this setting is not necessary there:

#### Variant: Kubernetes cluster

*terraform.tfvars*

```hcl
backend_service = {
  extra_args = ["--telemetry-endpoint=https://<records-proxy>"]
}
```

*values.yaml*

```yaml
extraArgs:
  - --telemetry-endpoint=https://<records-proxy>
```

#### Variant: Single Server

The Backend does not send usage records in Single Server mode: do not set an address.

## Next

- [Authentication](/configuration-authentication/)

Source: https://docs.platforma.bio/configuration-license/
