# Change the access mode of a data library

Move a data library to a mode in which each user reads it with an identity of their own, and keep the projects that use it.

In the modes [Identity of the Backend](/security-data-library-access/#identity-of-the-backend) and [Access keys](/security-data-library-access/#access-keys), the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) reads a library with one identity for all users, and every user can read every file. In the per-user modes, [Federated user access](/security-data-library-access/#federated-user-access) and [Google account of the user](/security-data-library-access/#google-account-of-the-user), each user reads with an identity of their own, so the cloud account of your company decides what each user can read. A move to a per-user mode changes the projects that already use the library:

- **Files that users imported before the change.** In a mode with one identity, a project keeps a link to each imported file, not a copy. In a per-user mode, the Backend reads the library only for a signed-in user, so a Block (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) that reads such a file again fails. Copy these files into the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.) before the change: the projects then use the copies, and the change does not touch them.
- **Files that users import after the change.** Each import copies the file into the primary storage, so the project does not need the library for it any more.

These moves are possible:

| The library                      | Per-user modes                                    |
| -------------------------------- | ------------------------------------------------- |
| Amazon S3 bucket                 | Federated user access                             |
| Google Cloud Storage bucket      | Federated user access, Google account of the user |
| Folder on the server or a volume | None: the per-user modes read only buckets        |

A move back, from a per-user mode to a mode with one identity, does not change the projects: their files are already in the primary storage. After it, every user can read every file of the library.

## Before you start

1. **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.).** Both per-user modes take the identity of the user from the SSO sign-in: federated user access needs an SSO provider that the cloud account trusts. The Google account of the user needs SSO through Google. When users sign in with 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.) or LDAP (The directory of users of a company. The Backend can check logins and passwords in it.) now, move them to SSO first, as a separate change: see [Migrate between sign-in providers](/maintain-migrating-sign-in-providers/).
2. **The cloud side.** For federated user access, the cloud account trusts the corporate identity provider and gives each user the rights to the bucket. For the Google account of the user, the Google account of each user gets the rights to the bucket. See [Federated user access](/security-data-library-access/#federated-user-access) and [Google account of the user](/security-data-library-access/#google-account-of-the-user).
3. **Space in the primary storage.** The copy takes the files of the library that projects use, not the whole library. Make sure that the primary storage has space for them.
4. **A backup.** Make a backup of the database: see [Make a backup now](/maintain-backup-and-restore/#make-a-backup-now).
5. **A time window.** From the start of the copy until the Backend starts in the new mode, users cannot work. The time depends on the size of the imported files. Tell the users before.
6. **The same library ID (The fixed name of a data library inside Platforma. Projects keep links to files through this ID; a new ID makes a new library.).** Keep the ID of the library. A new ID makes a new library, and the projects keep their links to the old one.

## Copy the files of a library into the primary storage

The Backend option `--migrate-blobs-to-primary` copies the files that projects imported from a library into the primary storage. It copies each file whose only copy is in the library, and then the Backend stops. After the copy, the projects do not need the library for these files. Run it while the library is still in the settings, in its old mode: the Backend reads the library with its own identity, the access keys or from the folder.

#### Variant: Kubernetes cluster

1. Add the option `--migrate-blobs-to-primary=<library ID>` to `extraArgs` (Helm) or `backend_service.extra_args` (Terraform), and upgrade the release. This option is not covered by the chart values or the module inputs. The Backend copies the files and then stops; Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) starts it again, and each new start does the copy again, which does not change the copied files. Users cannot work during this time.

   *terraform.tfvars*

   ```hcl
   backend_service = {
     extra_args = ["--migrate-blobs-to-primary=lab-archive"]
   }
   ```

   *values.yaml*

   ```yaml
   extraArgs:
     - "--migrate-blobs-to-primary=lab-archive"
   ```

2. Look at the log of the Backend. When it shows `All blobs migrated to primary storage`, the copy is complete: remove the option, and in the same upgrade make the change that you prepared. When it shows `Blob migration completed with failures`, some files were not copied: do not change the access mode or remove the library. Find the cause in the log, then upgrade again.

#### Variant: Single Server

1. Stop the Backend service, then run the Backend one time with the option `--migrate-blobs-to-primary <library ID>`, with all its other settings. It copies the files and then stops.

2. Make sure that the copy is complete. When a file cannot be copied, the Backend logs `Blob migration completed with failures` and exits with code 1: do not change the access mode or remove the library. When the copy is complete, make the change that you prepared, then start the Backend service.

## Switch the access mode

Make this change in the same upgrade or restart that removes `--migrate-blobs-to-primary`, so that users cannot import new files between the copy and the switch. For the options of each mode, see [Federated user access](/configuration-data-libraries/#federated-user-access) and [Google account of the user](/configuration-data-libraries/#google-account-of-the-user).

#### Variant: Kubernetes cluster

Keep the library in `dataLibraries` (Helm) or `backend_service.data_libraries` (Terraform) with the same `id`. Remove its access keys: a library with federated user access cannot have keys. Add the options of the new mode to `extraArgs` or `backend_service.extra_args`, then upgrade the release:

*values.yaml*

```yaml
dataLibraries:
  - id: lab-archive                     # the same ID as before
    name: "Lab archive"
    s3: { bucket: lab-archive-bucket, region: eu-central-1 }   # no access keys
extraArgs:
  # remove: - "--migrate-blobs-to-primary=lab-archive"
  - "--data-library-s3-federation-role-arn=lab-archive=arn:aws:iam::123456789012:role/platforma-users"
  - "--data-library-s3-federation-auth-token=lab-archive=id_token"
```

*terraform.tfvars*

```hcl
backend_service = {
  data_libraries = [
    {
      id   = "lab-archive" # the same ID as before
      name = "Lab archive"
      s3   = { bucket = "lab-archive-bucket", region = "eu-central-1" } # no access keys
    },
  ]
  extra_args = [
    # remove: "--migrate-blobs-to-primary=lab-archive",
    "--data-library-s3-federation-role-arn=lab-archive=arn:aws:iam::123456789012:role/platforma-users",
    "--data-library-s3-federation-auth-token=lab-archive=id_token",
  ]
}
```

#### Variant: Single Server

Change the options of the library in the Backend service: keep the library ID, remove the access keys, and add the options of the new mode. Then start the Backend service.

## Check the result

1. **The Backend starts.** The Backend does not check a library in a per-user mode at start, so a wrong setting of the mode shows only when a user opens the library.
2. **A user sees the library.** Sign in with SSO as a user who has the rights in the cloud, and open the library in 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 shows the files that the cloud lets this user read. When the user sees “access denied”, see [Problems](/configuration-data-libraries/#problems).
3. **Old projects work.** Open a project that used files of the library before the change, and run again a Block that reads them. It runs without the library: it reads the copies in the primary storage.
4. **New imports work.** Import a file from the library into a project. The import copies the file into the primary storage.

To go back, set the old mode of the library again and upgrade the release, or restart the Backend 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 copies in the primary storage stay, and the projects keep them.

## Next

- [Data libraries](/configuration-data-libraries/)
- [Data library access modes](/security-data-library-access/)
- [Migrate between sign-in providers](/maintain-migrating-sign-in-providers/)

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