# Data library access modes

See the access modes of data libraries and how they differ.

A 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.) is a bucket or a folder with the input data of your company that Platforma only reads. The Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) can get access to each library in one of five modes:

1. [Identity of the Backend](/security-data-library-access/#identity-of-the-backend): one 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 all.
2. [Access keys](/security-data-library-access/#access-keys): static keys for all users.
3. [Federated user access](/security-data-library-access/#federated-user-access): a cloud identity per user.
4. [Google account of the user](/security-data-library-access/#google-account-of-the-user): the Google account of each user.
5. [Folder on the server or a volume](/security-data-library-access/#folder-on-the-server-or-a-volume): read by the Backend itself.

With its own identity, with access keys and with a folder, the Backend reads the library with one identity for all users, and every user who signs 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".) can read every library. With federated access and with the Google account, each user reads with an identity of their own, so the cloud account of your company decides what each user can read.

## Identity of the Backend

The Backend reads the bucket with the cloud identity of its service account. This is the mode that the diagram of the Security overview shows.

| Part                                                                                                                    | What it means                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ----------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Backend                                                                                                                 | Uses one identity for all users. It gets temporary credentials from the cloud and renews them itself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) | The service account of the Backend is bound to the cloud identity. No Secret is necessary.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Users                                                                                                                   | All users can read the library. Any sign-in provider (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.) works. The Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.) can download files from the bucket directly, with links that the Backend signs.                                                                                                                                                                         |
| Cloud                                                                                                                   | The operator (The person who installs and runs Platforma in your company, for example an IT engineer or a bioinformatician.) gives the identity of the Backend read access to the bucket. On AWS: `s3:ListBucket`, `s3:GetObject` and `s3:GetBucketLocation`; the default policy covers the whole bucket, and it is limited to a folder only when the operator sets a prefix. On Google Cloud: the role `roles/storage.objectViewer` on the bucket, and `roles/iam.serviceAccountTokenCreator` on its own service account, to sign links. The audit log shows the identity of the Backend for each read. |

> **Caution:**
>
> On Google Cloud, a limit to a prefix works only with uniform bucket-level access, and it does not limit the list: the Backend can see the names of all objects in the bucket. Because the Desktop App can read the bucket directly, through presigned URLs that the Backend gives, the bucket needs the same network rules as the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.).

## Access keys

The Backend reads the bucket with static keys. For Amazon S3 or for storage with the S3 interface, these are an access key and a secret key. For Google Cloud Storage, this is a key file of a Google service account. Use this mode for a bucket that the cloud identity of the Backend cannot reach: in another account, at another provider, or in the data center of your company.

| Part       | What it means                                                                                                                                                             |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Backend    | Uses the same keys for all users. The keys do not expire unless the operator changes them.                                                                                |
| Kubernetes | The keys are in a Secret in the namespace of Platforma.                                                                                                                   |
| Users      | All users can read the library. Any sign-in provider works.                                                                                                               |
| Cloud      | The operator makes a user or a service account with read access to the bucket and makes its keys. The audit log shows this user for each read, not the user of Platforma. |

> **Caution:**
>
> Keys that do not expire are a risk when someone copies them. Give the keys read access to the library bucket only, and change them on a schedule.

## Federated user access

Each user reads the library with a cloud identity of their own. Users sign in with SSO (Sign-in through the identity service of the company, with the same account as for other company systems.) through any identity provider that uses OpenID Connect (OIDC, the standard sign-in protocol of SSO). The cloud account of your company trusts this identity provider (workload identity federation). When a user opens or imports files, the Backend gives the token of this user to the security token service of the cloud, and gets temporary credentials for this user only.

| Part       | What it means                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Backend    | Keeps the SSO session of each user, with a refresh token, encrypted in its database with a key made from the [master secret](/security-secrets/#master-secret). It gets temporary credentials for each user and renews them. It reads the files for the user and copies them into the primary storage.                                                                                                           |
| Kubernetes | Nothing more than for SSO: no Secret and no cloud identity for the library.                                                                                                                                                                                                                                                                                                                                      |
| Users      | Each user must sign in with SSO. A user sees only the files that the cloud allows for this user; for other files, the Desktop App shows that access is denied.                                                                                                                                                                                                                                                   |
| Cloud      | On AWS: an IAM OIDC provider for the corporate identity provider, and a role that trusts it (`sts:AssumeRoleWithWebIdentity` and `sts:TagSession`). The operator can give different rights to different users with the tags of the session, made from the claims of the token. On Google Cloud: a workload identity pool and provider. On Google Cloud, the audit log shows the federated identity of each user. |

> **Caution:**
>
> The mode needs SSO: it does not work with 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.). When the corporate identity provider ends the session of a user, the Backend can no longer read the library for this user. Copies in the primary storage stay when the user loses access to the bucket; from then on, the permissions of Platforma apply to them, not the rules of the cloud.

## Google account of the user

Each user reads the library with their own Google account. Users sign in with SSO through Google. The Backend sends the Google token of the user to Google Cloud Storage as it is, with no exchange.

| Part       | What it means                                                                                                                                                                                                                                                                                                               |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Backend    | Keeps the SSO session of each user, with a refresh token, encrypted in its database with a key made from the [master secret](/security-secrets/#master-secret). For each request, it uses the current token of the user and does not keep a copy. It reads the files for the user and copies them into the primary storage. |
| Kubernetes | Nothing more than for SSO.                                                                                                                                                                                                                                                                                                  |
| Users      | Each user must sign in with Google. A user sees only the files that the bucket allows for their Google account.                                                                                                                                                                                                             |
| Cloud      | The operator gives the Google accounts or groups of users read access to the bucket. No service account and no federation are necessary. The audit log shows the Google account of each user.                                                                                                                               |

> **Caution:**
>
> The mode works only with Google Cloud Storage and with Google as the SSO provider. The operator sets the sign-in to ask Google for access to Cloud Storage and for a refresh token; without them, the Backend does not start. The token has the rights of the user’s Google account within the scope that the operator chose. There are five scopes: read-only, read-write or full control of Cloud Storage, and read-only or full access to all of Google Cloud. The rights apply to everything that the account can reach, not only to the library. Read-only Cloud Storage is the smallest scope.

## Folder on the server or a volume

The Backend reads the files of the library itself, with its own system user. No cloud identity and no keys are necessary. When a user imports files, the Backend copies the data that a job (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) needs into the working folder of the job and into the primary storage. The Desktop App does not read the folder directly.

#### Variant: Kubernetes cluster

| Part       | What it means                                                                                                                                                                                          |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Backend    | Reads the volume with its own system user, which is not root (by default, user and group ID 1010).                                                                                                     |
| Kubernetes | A volume (PersistentVolumeClaim) in the namespace of Platforma, mounted read-only into the Backend pod only. It is never mounted into the pods of jobs. The claim must already exist in the namespace. |
| Users      | Every user who signs in can read every folder library. Any sign-in provider works.                                                                                                                     |
| Storage    | The files must be readable by the system user of the Backend. There is no cloud audit log: all reads are by the Backend.                                                                               |

#### Variant: Single Server

| Part       | What it means                                                                                                            |
| ---------- | ------------------------------------------------------------------------------------------------------------------------ |
| Backend    | Reads a folder on the server with its own system user.                                                                   |
| Kubernetes | Not used.                                                                                                                |
| Users      | Every user who signs in can read every folder library. Any sign-in provider works.                                       |
| Storage    | The files must be readable by the system user of the Backend. There is no cloud audit log: all reads are by the Backend. |

> **Caution:**
>
> The Backend does not check the rights of each user on a folder library: if a user can sign in, the user can read all of its files. 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.) with a folder as primary storage, the Backend shares the files of the server with all users as a read-only library by default. The operator can turn this off.

## Next

- [Data libraries: add a library](/configuration-data-libraries/)
- [Data flows](/security-data-flows/)

Source: https://docs.platforma.bio/security-data-library-access/
