# Proxy and custom CA

Make Platforma work behind a corporate proxy, with a corporate certificate authority, or with access to fixed IP addresses only.

Platforma can run in a corporate network where the internet is reachable only through a proxy, where a proxy inspects TLS with a corporate certificate authority, or where the firewall allows only fixed IP addresses. Set the parts that the network needs:

- [Proxy](/configuration-proxy-and-custom-ca/#proxy): outbound connections through a proxy.
- [CA bundle](/configuration-proxy-and-custom-ca/#ca-bundle): trust a corporate certificate authority.
- [Restricted network mode](/configuration-proxy-and-custom-ca/#restricted-network-mode): access to fixed IP addresses.
- [Clients](/configuration-proxy-and-custom-ca/#clients): proxy and registry 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.) and pl-cli (The command-line client of Platforma. Administrators use it to manage users and projects on the Backend.) on each computer.

For what each part of Platforma needs behind a proxy that inspects TLS, see [TLS inspection](/configuration-proxy-and-custom-ca/#tls-inspection). For the hosts that Platforma connects to, see [Outbound connections](/security-outbound-connections/). For what Platforma expects from the proxy and the bundle, see [Proxy and CA bundle](/infrastructure-contract-identity/#proxy-and-ca-bundle).

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

## Proxy

The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) reads the standard proxy variables: `HTTPS_PROXY`, `HTTP_PROXY` and `NO_PROXY`. `NO_PROXY` lists the addresses that the Backend reaches directly, not through the proxy.

#### Variant: Kubernetes cluster

Set the variables in the environment of the Backend pod: the Helm value `env.variables`, or the Terraform input `backend_service.env.variables` of `platforma-tf-services`. `NO_PROXY` must hold:

- `.svc` and `.cluster.local`: the services inside the cluster;
- `169.254.169.254`: the metadata service of the cloud;
- the address of an object storage inside the cluster or the corporate network, when the Backend must reach it directly.

*values.yaml*

```yaml
env:
  variables:
    HTTPS_PROXY: http://proxy.example.com:3128
    HTTP_PROXY: http://proxy.example.com:3128
    NO_PROXY: .svc,.cluster.local,169.254.169.254
```

*platforma-tf-services*

```hcl
backend_service = {
  env = {
    variables = {
      HTTPS_PROXY = "http://proxy.example.com:3128"
      HTTP_PROXY  = "http://proxy.example.com:3128"
      NO_PROXY    = ".svc,.cluster.local,169.254.169.254"
    }
  }
}
```

When the proxy URL holds a password, keep the URL in a Secret, and give it with `env.secretVariables` (Terraform: `backend_service.env.secret_variables`):

*values.yaml*

```yaml
env:
  secretVariables:
    - name: HTTPS_PROXY
      secret: { name: platforma-proxy, key: url }
```

*platforma-tf-services*

```hcl
backend_service = {
  env = {
    secret_variables = [
      { name = "HTTPS_PROXY", secret = { name = "platforma-proxy", key = "url" } },
    ]
  }
}
```

The chart stops when `extraArgs` or an `env` list has an option or a variable of these kinds:

- a secret value in plain text: give it with `env.secretVariables`;
- the license, 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".), or the list of users: set them with their chart values;
- the metrics listener, or an option that another chart value sets;
- the HTTP listener and the file-system storage 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 module gives `extra_args` and `env` to the chart, so the same applies to them. For the full list, see [Environment and extra options](/reference-chart-values/#environment-and-extra-options).

The nodes pull the images through the proxy settings of their container runtime. This is a setting of the nodes, outside Platforma. Or the nodes pull from mirrors inside the corporate network: see [Registries](/configuration-registries/).

After a change of the variables, apply the values: the Backend pod starts again.

#### Variant: Single Server

Set the variables in the environment of the Backend service, for example in its systemd unit:

*/etc/systemd/system/platforma.service*

```ini
[Service]
Environment=HTTPS_PROXY=http://proxy.example.com:3128
Environment=HTTP_PROXY=http://proxy.example.com:3128
Environment=NO_PROXY=localhost,127.0.0.1
```

On a server in a cloud, also add `169.254.169.254`, the metadata service, and the address of an object storage that the Backend reaches directly.

With the Docker image of the Backend, give them with `docker run -e`. The 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, also when they run in Docker containers. Docker pulls the images of the tools through the proxy settings of the Docker service: set them there, or use a mirror (see [Registries](/configuration-registries/)).

After a change of the variables, restart the Backend.

> **Caution:**
>
> A `NO_PROXY` without the addresses inside the cluster or the metadata address sends these requests to the proxy: then the storage or 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 can stop working. The proxy must not change the answers and must not close connections that wait without data: see [Proxy and CA bundle](/infrastructure-contract-identity/#proxy-and-ca-bundle).

## CA bundle

A CA bundle (One PEM file with the certificate authorities that a program trusts. In Kubernetes, Platforma can give the Backend and all jobs one bundle with the public and the corporate certificate authorities.) lets Platforma trust a corporate certificate authority: of a proxy that inspects TLS, of a mirror, or of an object storage inside the corporate network.

#### Variant: Kubernetes cluster

Give Platforma a full bundle: one PEM file with the public certificate authorities and the corporate ones. The Backend pod and all job pods mount it read-only at the same path, so the Backend and the tools of the Blocks (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) trust the same authorities.

1. Make a ConfigMap with the bundle in the namespace of the instance. The company keeps it current: for example, a trust-manager `Bundle` joins the public certificate authorities and the corporate one into this ConfigMap. Or make it by hand:

   ```sh
   kubectl -n platforma create configmap corporate-ca-bundle \
     --from-file=ca-certificates.crt=./full-bundle.pem
   ```

2. Give its name to Platforma:

   | Helm value                | Terraform input of `platforma-tf-services` | Default                                               |
   | ------------------------- | ------------------------------------------ | ----------------------------------------------------- |
   | `caBundle.configMap.name` | `infrastructure.ca_bundle.config_map.name` | `""`: no bundle, each image keeps its own trust store |
   | `caBundle.configMap.key`  | `infrastructure.ca_bundle.config_map.key`  | `ca-certificates.crt`                                 |
   | `caBundle.filePath`       | `infrastructure.ca_bundle.file_path`       | `/etc/ssl/certs/ca-certificates.crt`                  |

   *values.yaml*

   ```yaml
   caBundle:
     configMap: { name: corporate-ca-bundle, key: ca-certificates.crt }
   ```

   On an own cluster with 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.), set `cloud_values.ca_bundle` in `cluster_config` with the same keys. With the cloud-specific Terraform modules (The Terraform modules platforma-tf-cloud-base and platforma-tf-cloud-cluster. There is one pair for each cloud, AWS and Google Cloud. The roots cloud and cluster apply them. They make the network, the Kubernetes cluster, the storage, the cloud identities and the registry caches. They give the hand-off file cluster_config to the cloud-agnostic Terraform modules.), the hand-off file `infrastructure` has `ca_bundle = null`. Add the bundle in the root `services`:

   *platforma-tf-services*

   ```hcl
   infrastructure = merge(jsondecode(file("infrastructure.json")), {
     ca_bundle = { config_map = { name = "corporate-ca-bundle" } }
   })
   ```

3. Apply. The Backend pod starts again with the bundle.

Each pod gets these variables, all set to the path of the bundle, so that common software finds it: `SSL_CERT_FILE`, `CURL_CA_BUNDLE`, `REQUESTS_CA_BUNDLE`, `CONDA_SSL_VERIFY`, `MAMBA_SSL_VERIFY`, `PIP_CERT`, `NODE_EXTRA_CA_CERTS`, `npm_config_cafile`, `YARN_HTTPS_CA_FILE_PATH`, `DENO_CERT`, `GIT_SSL_CAINFO`, `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH`, `CARGO_HTTP_CAINFO`, `PERL_LWP_SSL_CA_FILE` and `HTTPS_CA_FILE`. `NODE_USE_SYSTEM_CA` is `1`.

Tools that check their license, such as MiXCR, do not use the bundle for the license service: see [TLS inspection](/configuration-proxy-and-custom-ca/#tls-inspection).

**After the bundle changes**, new job pods get the new bundle, but the running Backend pod keeps the old one: restart the Backend (`kubectl -n platforma rollout restart deployment/platforma`).

#### Variant: Single Server

There is no bundle setting. The Backend, and the jobs that run without Docker, use the trust store of the server. Add the corporate certificate authority to it, for example with `update-ca-certificates` on Debian and Ubuntu or `update-ca-trust` on Red Hat Enterprise Linux, then restart the Backend. Jobs in Docker containers use the trust store of their image, not the corporate certificate authorities of the server.

With the Docker image of the Backend, mount the full bundle into the container at `/etc/ssl/certs/ca-certificates.crt`, or set `SSL_CERT_FILE` to the path of the bundle in the container.

For tools that check their license, such as MiXCR, see [TLS inspection](/configuration-proxy-and-custom-ca/#tls-inspection).

> **Caution:**
>
> A bundle with only the corporate certificate authorities replaces the trust store of each image, so all other TLS connections fail: always give the full bundle. Software that reads neither a PEM file nor these variables, for example Java tools, does not use the bundle.

## TLS inspection

A proxy that inspects TLS opens each HTTPS connection and signs it again with a certificate authority of your company. A connection through this proxy works only when the part of Platforma that connects trusts this certificate authority. Each part reads its trust from its own place:

| Part                                                  | What to do                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Backend                                               | Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) cluster: give the [CA bundle](/configuration-proxy-and-custom-ca/#ca-bundle). Single Server mode: add the certificate authority to the trust store of the server. This covers all HTTPS connections of the Backend: the license service, the registries, the monitoring service, the identity provider and the storage.                          |
| Jobs                                                  | Kubernetes cluster: the job pods get the same CA bundle. Single Server mode: jobs without Docker use the trust store of the server; jobs in Docker containers use the trust store of their image.                                                                                                                                                                                                                                                                        |
| Jobs of tools that check their license, such as MiXCR | Exclude `licensing-api.milaboratories.com` from the inspection. These tools check the certificate of the license service with their own trust store, not with the CA bundle.                                                                                                                                                                                                                                                                                             |
| Cluster nodes, or Docker on the server                | The container runtime pulls the images. Add the certificate authority to the trust store of the nodes, or to the settings of the container runtime. This is a setting of the nodes, outside Platforma. Or the nodes pull from mirrors inside the corporate network (see [Registries](/configuration-registries/)).                                                                                                                                                       |
| Desktop App                                           | Add the certificate authority to the trust store of the operating system. On Windows, this is the certificate store; on macOS, the keychain; on Linux, the system certificate authorities (for example, with `update-ca-certificates`). Or start the Desktop App with `NODE_EXTRA_CA_CERTS` set to a PEM file with the certificate authority: this works on each operating system. See [What the Desktop App trusts](/configuration-domain-and-tls/#what-clients-trust). |
| pl-cli                                                | Set `NODE_EXTRA_CA_CERTS` to a PEM file with the certificate authority (see [What pl-cli trusts](/configuration-domain-and-tls/#what-pl-cli-trusts)). This covers the connection to the Backend and the requests to the identity provider for SSO (Sign-in through the identity service of the company, with the same account as for other company systems.).                                                                                                            |

The Backend connects to an LDAP (The directory of users of a company. The Backend can check logins and passwords in it.) directory directly, not through the proxy. For a directory with a certificate of a corporate certificate authority, see the setting `trustedCA` in [LDAP](/configuration-authentication/#ldap).

*Desktop App with NODE_EXTRA_CA_CERTS, on Linux*

```sh
NODE_EXTRA_CA_CERTS=/etc/ssl/certs/corporate-ca.pem ./<file of the Desktop App>.AppImage
```

In Single Server mode, a tool that checks its license and runs without Docker can also trust a PEM bundle. Set `MI_CUSTOM_CA=<path of the PEM CA bundle>` in the environment of the Backend: the jobs get the environment of the Backend.

For the hosts that each part connects to, see [Outbound connections](/security-outbound-connections/).

## Restricted network mode

When the firewall allows access only to fixed IP addresses, turn on the restricted network mode. The Backend then uses `bin-ga.pl-open.science` and `blocks-ga.pl-open.science` instead of `bin.pl-open.science` and `blocks.pl-open.science`. The `-ga` hosts answer on two fixed IP addresses. The Backend gets the software packages and the assets from them. The Desktop App has its own setting for the Blocks, “Use Global Access Registry”: see [Desktop App](/configuration-proxy-and-custom-ca/#clients). For the addresses and the other services on them, see [Restricted network mode](/plan-single-server-requirements/#restricted-network-mode).

#### Variant: Kubernetes cluster

The chart values and the module inputs do not cover this setting. Set the environment variable of the Backend pod:

*values.yaml*

```yaml
env:
  variables:
    PL_USE_RESTRICTED_NETWORK_MODE: "true"
```

*platforma-tf-services*

```hcl
backend_service = {
  env = {
    variables = { PL_USE_RESTRICTED_NETWORK_MODE = "true" }
  }
}
```

#### Variant: Single Server

Start the Backend with `--use-restricted-network-mode`, or set the environment variable `PL_USE_RESTRICTED_NETWORK_MODE=true`. After the change, restart the Backend.

A mirror that you set for the assets (see [Registries](/configuration-registries/)) takes priority over the `-ga` host. After the change, new downloads use the `-ga` hosts, and the projects and their data do not change.

## Clients

The Desktop App keeps its network settings on each computer, in its settings. Give users the values that the corporate network needs:

- **Proxy settings**: “System proxy” (default) uses the proxy of the operating system. “Custom proxy” takes a “Proxy URL”, and both take an optional user name and password, which the Desktop App keeps encrypted with the keychain of the operating system. “No proxy” connects directly. For the connection to the Backend, the Desktop App tries both the direct way and the proxy, and uses the one that works.
- **Use Global Access Registry**: the Desktop App gets the Blocks from `blocks-ga.pl-open.science`, which answers on fixed IP addresses. The Desktop App turns this setting on by itself when `blocks.pl-open.science` is not reachable at start.

For the certificate authorities that the Desktop App trusts, see [What the Desktop App trusts](/configuration-domain-and-tls/#what-clients-trust). For the Block registry (A service from which the Desktop App downloads Blocks. MiLaboratories runs the main one; a company can add its own.) settings, see [Block registries in the Desktop App](/configuration-registries/#block-registries-in-the-desktop-app).

### pl-cli network settings

pl-cli takes its network settings from the environment of the computer where it runs. It does not use the settings of the Desktop App. It connects only to the address of the Backend: it does not connect to the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.), to the registries or to other services.

- **Proxy.** pl-cli uses an HTTP proxy when the environment variable `https_proxy` is set, or `http_proxy` when `https_proxy` is not set. Write the names in lowercase: on Linux and macOS, pl-cli does not read `HTTPS_PROXY`. The proxy address starts with `http://` and can hold a user name and a password. The proxy must let pl-cli open a tunnel to the Backend with the `CONNECT` method. pl-cli does not try the direct way when the proxy fails.
- **No proxy.** `no_proxy` lists the hosts that pl-cli reaches directly.

**Example:**

```sh
export https_proxy=http://proxy.example.com:3128
export no_proxy=platforma.internal.example.com
```

For the certificate authorities that pl-cli trusts, see [What pl-cli trusts](/configuration-domain-and-tls/#what-pl-cli-trusts).

## Changes on a running installation

| Change                                    | What happens                                                                                                                   | What to do                                                                    |
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- |
| Set or change the proxy                   | The Backend starts again with the new variables (see [Restart of the Backend](/configuration-storage/#restart-of-the-backend)) | Apply the new values (Kubernetes) or restart the Backend (Single Server mode) |
| Add a certificate authority to the bundle | New job pods get the new bundle at once. The Backend keeps the old one                                                         | Restart the Backend                                                           |
| Turn on the restricted network mode       | New downloads of the Backend use the `-ga` hosts. Projects and data do not change                                              | Allow the two IP addresses in the firewall first, then restart the Backend    |

## Problems

**After the proxy is set, the Backend cannot reach the storage, or its cloud identity fails.** Cause: `NO_PROXY` does not hold the addresses inside the cluster, the metadata address or the address of the storage. Fix: add them, then restart the Backend.

**Downloads of software or assets stop and do not continue.** Cause: the proxy closes connections that wait without data. Fix: allow long connections without data in the proxy. See [Proxy and CA bundle](/infrastructure-contract-identity/#proxy-and-ca-bundle).

**A tool in a job fails with a certificate error.** Cause: the bundle does not hold the corporate certificate authority. Fix: add the certificate authority to the bundle, then run the Block again: new job pods get the new bundle.

## Next

- [Registries](/configuration-registries/)
- [Outbound connections](/security-outbound-connections/)
- [Domain and TLS](/configuration-domain-and-tls/)

Source: https://docs.platforma.bio/configuration-proxy-and-custom-ca/
