# Migrate between sign-in providers

Move users to another sign-in provider, so that each user keeps their projects.

Each project belongs to the account of one user. A new 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.) usually gives other logins than the old one, so the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.) must find the old account of each user. Else the first 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 the new provider makes a new, empty account (with `createUsers: true`), or the Backend refuses the user. For how the Backend finds an account, see [How the Backend finds the account of a user](/configuration-authentication/#how-the-backend-finds-the-account-of-a-user).

There are three ways to keep the projects of users in a move, for example from a static list (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.) of users to LDAP (The directory of users of a company. The Backend can check logins and passwords in it.), or from LDAP to SSO (Sign-in through the identity service of the company, with the same account as for other company systems.):

- [Mapping file](/maintain-migrating-sign-in-providers/#mapping-file): a file adds email addresses.
- [Mapping by attributes](/maintain-migrating-sign-in-providers/#mapping-by-attributes): the new provider gives known values.
- [Move projects](/maintain-migrating-sign-in-providers/#move-projects): an administrator moves the projects.

The ways can work together: for example, a mapping file for most users, and a move of projects for a user who signed in with the new provider before the mapping. An installation made with the AWS installer or the Google Cloud installer cannot use the mapping file, because these installers do not give extra options to the Backend: see its installation page.

> **Mapping file with an installer:**
>
> You can still use the mapping file with such an installation: change the Helm release in the cluster with `helm upgrade` and add the Backend option to `app.extraArgs`. MiLaboratories does not recommend this, because you must carefully control which changes you make in Helm, and which changes you make with the installer (the CloudFormation stack or the install script) and when. The next run of the installer can remove the change that you made in Helm.

## Before you start

1. **Make a backup** of the database: see [Make a backup now](/maintain-backup-and-restore/#make-a-backup-now).
2. **Decide the login that the new provider gives.** An LDAP provider gives the login that the user types. An SSO provider gives the claim in `map.login`, or, without it, the ID of the user at the identity provider (`sub`), which is a long value that people cannot read. MiLaboratories recommends to map the login to a readable claim, for example `email`. A later change of the login gives users new accounts, so decide it now.
3. **Plan to keep the old provider.** Add the new provider next to the old one: users can then sign in both ways, move one by one, and keep a way back. When you add a provider, all sessions end, and all users sign in again; the projects stay. See [Change the sign-in settings](/configuration-authentication/#change-the-sign-in-settings).
4. **Give the administrator role (The role in the Backend that can read and change the data of all users and run the pl-cli administrator commands. The operator sets rules that give it to users by login, group or attribute.) for the new provider.** The administrator rules (`adminUsers`, `roles`) belong to each provider: write them with the logins or groups of the new provider. See [Give the administrator role](/configuration-users-and-roles/#give-the-administrator-role).
5. **Keep an administrator who can sign in with the new provider.** `pl-cli`, which moves projects, signs in as this administrator with `pl-cli login`, with SSO or with a password.

## Mapping file

Use this way when the old accounts do not have an email address, for example the accounts of a static list of users, and the new provider gives a verified email address. The file gives the email address of each old account. The new provider finds accounts by email, so the first sign-in with that email opens the old account with all its projects. The account keeps its old login. You need Backend 4.4.0 or later.

1. **Write the mapping file.** It is a CSV file with the columns `login` and `email`. Add one row for each old login, with the email address that the new provider sends for that person. To get the list of logins, run `pl-cli admin user-list`.

   ```csv
   login,email
   alice,alice@example.com
   bob,bob.smith@example.com
   ```

   - Write each login exactly as the Backend has it. Logins are case-sensitive. A login that does not have an account makes a new, empty account with that email address.
   - Leave out users who already signed in with the new provider: their email address belongs to their new account. Use [Move projects](/maintain-migrating-sign-in-providers/#move-projects) for them.
   - The Backend does not start when a row does not have a login, when a login or an email address is in two rows, or when an email address belongs to another account. Check the file before you give it to the Backend.

2. **Put the file in a place that only administrators can change.** A person who can change the file can connect any account to their own email address, also an administrator account.

   #### Variant: Kubernetes cluster

   Use a private bucket. Do not use the bucket of the primary storage (The bucket (Amazon S3 or Google Cloud Storage) or folder where Platforma keeps all results and uploaded files.), because jobs (One run of a tool on data. The Backend starts jobs on the server where it runs, or in a Kubernetes cluster.) can write to it, or the bucket of 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.), because users can see its files.

   - **Google Cloud Storage:** give the service account of the Backend the role `roles/storage.objectViewer` on the bucket.
   - **Amazon S3:** give the IAM role of the Backend `s3:GetObject` on the file. For S3-compatible storage, or without a role, make an access key that can read the file, and put it in a Kubernetes (A system that runs programs on a group of machines (a cluster). Platforma can run in a Kubernetes cluster.) Secret in the namespace of the Backend.

   #### Variant: Single Server

   Put the file on the server, for example `/etc/platforma/users.csv`, with the owner `root` and the group of the system user of the Backend, mode `640`.

3. **Give the file to the Backend, and let the new provider find users by email.** The new provider gets `lookUpAttr: email` and `map.email`. An LDAP provider must use search mode (`bindDN`): a direct bind cannot read the email attribute. When the Backend cannot read the file, it does not start.

   #### Variant: Kubernetes cluster

   The option `--user-provisioning` is not covered by the chart values or the module inputs: give it in `extraArgs` (Helm) or `backend_service.extra_args` (Terraform). Give an S3 key in `env.secretVariables` (`backend_service.env.secret_variables`): the chart refuses it in `extraArgs`. In Terraform, the provider fields are the same in `snake_case` (`look_up_attr`).

   *values.yaml*

   ```yaml
   extraArgs:
     # Google Cloud Storage
     - --user-provisioning=gcs://<bucket>/<path>/users.csv
     - --user-provisioning-gcs-project-id=<project-id>
     # Amazon S3. For S3-compatible storage: https://<endpoint>/<bucket>/<path>/users.csv
     # - --user-provisioning=s3://<bucket>/<path>/users.csv
     # - --user-provisioning-s3-region=<region>
   # Only with an access key of step 2:
   # env:
   #   secretVariables:
   #     - name: PL_USER_PROVISIONING_S3_KEY
   #       secret: { name: <secret-name>, key: <key-id-field> }
   #     - name: PL_USER_PROVISIONING_S3_SECRET
   #       secret: { name: <secret-name>, key: <secret-key-field> }
   auth:
     providers:
       - name: local                # the old provider stays
         title: "Local password"
         htpasswd:
           secret: { name: platforma-users, key: htpasswd }
       - name: corp                 # the new provider: LDAP in search mode
         title: "LDAP directory"
         ldap:
           url: "ldaps://ldap.example.com:636"
           bindDN: "<bind-dn>"
           bindPassword: { name: <secret-name>, key: bind-password }
           # ... the other LDAP settings
         lookUpAttr: email
         map:
           email: mail
       # or an SSO provider:
       # - name: <provider-name>
       #   sso:
       #     issuer: "<issuer-url>"
       #     # ... the other SSO settings
       #   lookUpAttr: email
       #   map:
       #     email: email
   ```

   *terraform.tfvars*

   ```hcl
   backend_service = {
     extra_args = [
       # Google Cloud Storage
       "--user-provisioning=gcs://<bucket>/<path>/users.csv",
       "--user-provisioning-gcs-project-id=<project-id>",
     ]
     # Only with an access key of step 2:
     # env = {
     #   secret_variables = [
     #     { name = "PL_USER_PROVISIONING_S3_KEY", secret = { name = "<secret-name>", key = "<key-id-field>" } },
     #     { name = "PL_USER_PROVISIONING_S3_SECRET", secret = { name = "<secret-name>", key = "<secret-key-field>" } },
     #   ]
     # }
     auth = {
       providers = [
         {
           name     = "local" # the old provider stays
           title    = "Local password"
           htpasswd = { secret = { name = "platforma-users", key = "htpasswd" } }
         },
         {
           name  = "corp" # the new provider: LDAP in search mode
           title = "LDAP directory"
           ldap = {
             url           = "ldaps://ldap.example.com:636"
             bind_dn       = "<bind-dn>"
             bind_password = { name = "<secret-name>", key = "bind-password" }
             # ... the other LDAP settings
           }
           look_up_attr = "email"
           map          = { email = "mail" }
         },
       ]
     }
   }
   ```

   #### Variant: Single Server

   Add these options to the Backend service. `<provider-id>` is the ID of the new provider. Declare the provider with the `--auth.*` options (`--auth.provider-id`, `--auth.provider-type`): the older `--auth-ldap-*` and `--sso-idp-*` options cannot find users by email.

   ```sh
   --user-provisioning=file:///etc/platforma/users.csv \
   --auth.look-up-attr=<provider-id>=email \
   --auth.map.email=<provider-id>=mail     # LDAP; for SSO: =email
   ```

4. **Add the new provider in the same change, and keep the old one.** Do steps 3 and 4 in one upgrade or restart, before users sign in with the new provider.

5. **Ask each user to sign in with the new provider.** The first sign-in with an email address from the file opens the old account with its projects.

   The Backend refuses an SSO sign-in by email when the identity provider does not mark the email address as verified. Microsoft Entra ID does not send this mark: set `trustUnverifiedEmail: true` on such a provider.

**Consequences:**

- Users keep their accounts, their projects and their old logins. Projects that other users shared with them stay shared.
- While the option is set, the Backend reads the file at each start, and does not start when it cannot read it or finds an error in it. Remove the option when all users have moved: see [When all users use the new provider](/maintain-migrating-sign-in-providers/#when-all-users-use-the-new-provider).

## Mapping by attributes

Use this way when the new provider can give a value that the old accounts already have. Then you do not need a file or an extra option:

- **The same login.** By default (`lookUpAttr: login`), the Backend finds the account with the login that the new provider gives. Set `map.login` of the new SSO provider so that it gives the old logins. for example A static list of users used email addresses as logins, and the SSO provider maps `login` to the claim `email`. An LDAP provider gives the login that the user types, and cannot map it.
- **The same email address.** Set `lookUpAttr: email` and `map.email` on the new provider: the Backend finds the account that has this email address. Old accounts have an email address only when the old provider stored one: an LDAP provider in search mode with `map.email`, or an SSO provider with `map.email`. Accounts of a static list of users, and of the older `--auth-ldap-*` options, do not have one: use the [Mapping file](/maintain-migrating-sign-in-providers/#mapping-file) for them.

1. **Check the values.** Run `pl-cli admin user-list` to see the logins of the accounts, and compare them with what the new provider gives.

2. **Add the new provider next to the old one**, with `map` and `lookUpAttr`:

   #### Variant: Kubernetes cluster

   *values.yaml*

   ```yaml
   auth:
     providers:
       - name: corp                 # the old provider stays
         title: "LDAP directory"
         ldap:
           url: "ldaps://ldap.example.com:636"
           # ... the other LDAP settings
       - name: sso
         title: "Company SSO"
         sso:
           issuer: "<issuer-url>"
           clientID: "<client-id>"
           # ... the other SSO settings
         lookUpAttr: email          # or leave it empty and set map.login
         map:
           email: email
   ```

   *terraform.tfvars*

   ```hcl
   backend_service = {
     auth = {
       providers = [
         {
           name  = "corp" # the old provider stays
           title = "LDAP directory"
           ldap = {
             url = "ldaps://ldap.example.com:636"
             # ... the other LDAP settings
           }
         },
         {
           name  = "sso"
           title = "Company SSO"
           sso = {
             issuer    = "<issuer-url>"
             client_id = "<client-id>"
             # ... the other SSO settings
           }
           look_up_attr = "email" # or leave it empty and set map.login
           map          = { email = "email" }
         },
       ]
     }
   }
   ```

   #### Variant: Single Server

   ```sh
   --auth.look-up-attr=<provider-id>=email \
   --auth.map.email=<provider-id>=email
   # or: --auth.map.login=<provider-id>=<claim>
   ```

3. **Ask each user to sign in with the new provider.** The first sign-in opens the old account with its projects. An SSO email address finds an account only when the identity provider marks it as verified (see `trustUnverifiedEmail` in [Mapping file](/maintain-migrating-sign-in-providers/#mapping-file)).

**Consequences:**

- Users keep their accounts, logins and projects, also the projects that other users shared with them. You do not keep a file.
- The new provider decides who gets each account: a person to whom it gives the login or the verified email address of an old account gets that account with its projects. Use only a provider that your company controls for these values.
- A user whose value does not match gets a new, empty account (with `createUsers: true`), or cannot sign in. Use [Move projects](/maintain-migrating-sign-in-providers/#move-projects) for such users.

## Move projects

Use this way when the new provider cannot give a value of the old accounts, or for a user who signed in with the new provider before the mapping. It works on every installation, also one made with an installer.

1. **Make a list** of the old login and the new login of each user. The new account must exist: the user signs in with the new provider one time, and gets a new, empty account.

2. **Move the projects to the new account.** Run these commands on a computer with Node.js 24 or later. The first command signs you in as an administrator, with the provider of your choice; see the pl-cli (The command-line client of Platforma. Administrators use it to manage users and projects on the Backend.) tab of [Connect clients](/install-connect-clients/#connect):

   ```sh
   npx @platforma-sdk/pl-cli@latest login -a https://<platforma-address> --method <provider-id>


   npx @platforma-sdk/pl-cli@latest admin delete-user <old-login> \
     --move-projects-to <new-login>
   ```

   The command shows the projects of the old account and asks for a confirmation. It moves all projects, then deletes the old account. When the old provider still accepts this user, also take the user away there, for example delete the line from the static list of users.

**Alternatives:**

- To keep the old account until the user checks the new one, copy single projects with `pl-cli admin copy-project --source-user <old-login> --source-project <project> --target-user <new-login>` (with the same session). Copy a project only when none of its Blocks (A small application for one step of an analysis, for example the import of reads or clustering. It can combine several tools.) runs. Then delete the old account with `delete-user --delete-projects`.
- A user who can still sign in with the old provider can share each project with the new account 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.). The new account gets a copy of the project.

**Consequences:**

- You cannot undo `delete-user`: the old account, its login and its email address go.
- Projects that other users shared with the old account are not shared with the new account. Ask the owners to share them again.
- When the new account already has a project with the same name, the moved project gets a suffix.

## When all users use the new provider

1. **Remove the mapping option** (`--user-provisioning`) when you used a mapping file. The accounts keep their email addresses.
2. **Remove the moved users from the old provider**, or remove the old provider. When you remove a provider, all sessions end, and all users sign in again.
3. **Keep one password login for emergencies**, for example in a static list of users, for when the identity provider or the directory does not answer.

## Next

- [Authentication](/configuration-authentication/)
- [Users and roles](/configuration-users-and-roles/)

Source: https://docs.platforma.bio/maintain-migrating-sign-in-providers/
