# Users and roles

Choose who can sign in and who gets the administrator role.

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

Platforma has two roles: `user`, which 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".) gets, and `admin`. An administrator can read and change the data of all users and act as any user, so give this role only to the people who must support the work of others. For what each role can do, see [Roles](/security-access-control/#roles).

When you set up the Backend (The server program of Platforma. It keeps the projects, runs the Blocks and starts jobs.), you choose who can sign in and how users get 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.). At each sign-in, the Backend applies these rules to the user: you do not manage the role of each user by hand.

## Who can sign in

Who can sign in depends on the 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.):

- **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.):** each login in the file. To add a user, add a line to the file.
- **LDAP (The directory of users of a company. The Backend can check logins and passwords in it.) and SSO (Sign-in through the identity service of the company, with the same account as for other company systems.):** a person whom the directory or the identity provider accepts, and who has an account in the Backend. By default, the Backend does not create accounts for these providers: set `createUsers: true`, or make the accounts in advance with a CSV file of users. See [New users at the first sign-in](/configuration-authentication/#new-users-at-the-first-sign-in).

With `createUsers: true`, the directory or the identity provider decides who can sign in. Limit the access there: assign the application to the users of Platforma at the identity provider, or use a filter of search mode in LDAP.

## Give the administrator role

Each provider has its own rules for the administrator role. You can use one or more of them:

- [By login](#by-login): a list of logins.
- [By group](#by-group): the groups of the directory or the identity provider.
- [By another attribute](#by-another-attribute): for example, the email address.

A user who matches any rule gets the role. When several rules match, the highest role wins; a rule cannot take a role away.

MiLaboratories recommends that you keep at least one administrator on a static list of users: it does not depend on the directory or the identity provider. The `pl-cli` administrator commands work with the stored session of a user with the administrator role, from any sign-in provider, SSO included.

### By login

`adminUsers` is a list of regular expressions. Each one must match the whole login. In a regular expression, a dot matches any character, so escape a dot in a login: `alice\.smith`.

#### Variant: Kubernetes cluster

*terraform.tfvars*

```hcl
# in the provider entry; "\\." in HCL is "\." in the expression
admin_users = ["alice\\.smith", "bob"]
```

*values.yaml*

```yaml
# in the provider entry
adminUsers: ['alice\.smith', bob]
```

#### Variant: Single Server

*Options of the Backend*

```sh
--auth.admin-user='local=alice\.smith' \
--auth.admin-user=local=bob
```

### By group

`roles.groups` gives a role to the members of a group, by its exact name: `admin=<group>`. `roles.groupRegexps` takes a regular expression in place of the name: `admin=<regex>`. The Backend gets the groups from the provider:

- **LDAP:** from `memberOf` of the user, and with `groupBaseDN` also from a search for groups. Write a group as its name (`cn`) or its full DN.
- **SSO:** from the claim that `map.groups` names, for example `groups`. The identity provider must put the groups into the token. See [What to register at the identity provider](/configuration-authentication/#what-to-register-at-the-identity-provider).
- **Google Workspace:** turn on `google.groupFetch` (see [SSO](/configuration-authentication/#sso)), and write each group as its email address. Only `roles.groups` works with Google, not `roles.groupRegexps`.

**LDAP group platforma-admins:**

#### Variant: Kubernetes cluster

*terraform.tfvars*

```hcl
# in the provider entry
roles = { groups = ["admin=platforma-admins"] }
```

*values.yaml*

```yaml
# in the provider entry
roles:
  groups: [admin=platforma-admins]
```

#### Variant: Single Server

*Options of the Backend*

```sh
--auth.role.group=corp=admin=platforma-admins
```

### By another attribute

`roles.attrRegexps` gives a role when a field of the user matches a regular expression in full: `admin=<field>=<regex>`, for example `admin=email=.*@it\.example\.com`. The field must come from the provider (see `map` in [How the Backend finds the account of a user](/configuration-authentication/#how-the-backend-finds-the-account-of-a-user)). 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 option is `--auth.role.attr-regex=<provider-id>=admin=<field>=<regex>`.

## When a change of role applies

The Backend gives the role at sign-in. A change of the role of a user, by a new rule or by a change of the groups at the identity provider or in the directory, applies at the next sign-in of the user. A change of the rules also restarts the Backend (see [Change the sign-in settings](/configuration-authentication/#change-the-sign-in-settings)). The user keeps the projects and the data: only the rights change.

## Remove a user

To remove a user, take the user away where the logins come from: delete the line from the static list, or remove the user in the directory or at the identity provider. The user then cannot sign in again. The Backend refuses to renew the session of the user when it can check the user without the password: with a static list of users, LDAP in search mode and SSO. The Desktop App (The program that each user installs on their own computer to work with Platforma. It is a client of the Backend.) then continues to work with its current session for at most 7 days. With LDAP in direct bind, the Backend does not check the user at renewal. For each sign-in provider, see [Sign-in](/security-access-control/#sign-in).

To end the session of the user at once, change the master secret: see [Change the master secret](/configuration-users-and-roles/#change-the-master-secret). This signs out all users, not only the removed user.

The account and its projects stay in the Backend. To delete the account, an administrator runs `pl-cli admin delete-user`, and chooses what happens to the projects:

- `--move-projects-to <login>` moves them to another account;
- `--delete-projects` deletes them with the account.

You cannot undo the deletion. For the full command, see [Move projects](/maintain-migrating-sign-in-providers/#move-projects).

With `createUsers: true`, a deleted user who can still sign in at the identity provider or in the directory gets a new, empty account.

## Change the master secret

A new [master secret](/security-secrets/#master-secret) ends the sessions of all users at once: use it when a removed user must lose access before the current session ends. All users sign in again. Projects and data stay; for the full effect, see [The secrets of Platforma](/security-secrets/#the-secrets-of-platforma). The Backend reads the master secret only at start, so each path ends with a restart of the Backend. For what the restart does, see [Restart of the Backend](/configuration-storage/#restart-of-the-backend).

Keep a copy of the new value in the secret store of your company: a backup is restored with the master secret that was in use.

#### Variant: AWS installer

1. Put a new value into the parameter of the master secret in Parameter Store. Use the `ClusterName` and the `Region` of the stack:

   ```sh
   aws ssm put-parameter --name "/<ClusterName>/platforma/master-secret" \
     --type SecureString --overwrite --region <Region> \
     --value "$(openssl rand -base64 32 | tr -d '\n')"
   ```

2. Update the stack with the current template and set `SecretsRevision` to a larger number. The deployer then writes the new value into the Secret `platforma-master-secret`. See [Change settings](/maintain-updating-cloud-installer/#change-settings).

3. Restart the Backend. Use the namespace from `PlatformaNamespace` (default `platforma`):

   ```sh
   aws eks update-kubeconfig --name <ClusterName> --region <Region>
   kubectl rollout restart --namespace platforma deployment/platforma
   ```

#### Variant: Google Cloud installer

1. In Cloud Shell, go to the folder of the installer of the installation, and load the saved answers: `source platforma-answers.sh`.

2. Run the installer with a new value in `MASTER_SECRET`. The value must be base64 of 32 bytes or more:

   ```sh
   MASTER_SECRET="$(openssl rand -base64 32 | tr -d '\n')" bash install.sh
   ```

   The installer adds the value as a new version of the master secret in Secret Manager before it shows the review. Check the review and confirm. The installer writes the new value into the Secret `platforma-master-secret` and shows `Kubernetes Secret platforma-master-secret updated.` The new version of the secret restarts the Backend. Result: the installer shows `Done.`

Set `MASTER_SECRET` only on this run. Each run with `MASTER_SECRET` adds a new version and restarts the Backend, also with the same value. Without it, the installer keeps the value that is in Secret Manager. When you answer `n` at the review, the new version stays in Secret Manager, and the next run of the installer applies it.

#### Variant: Terraform modules

1. Replace the value in the Secret of the master secret (by default `platforma-master-secret`, key `master-secret`):

   ```sh
   openssl rand -base64 32 | tr -d '\n' > master-secret.txt
   kubectl create secret generic platforma-master-secret --namespace <namespace> \
     --from-file=master-secret=master-secret.txt --dry-run=client -o yaml | kubectl apply -f -
   ```

2. Restart the Backend. The Deployment has the name of the Helm release (`backend_service.release_name`):

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

#### Variant: Helm chart

1. Replace the value in the Secret of `secrets.masterSecret` (by default `platforma-master-secret`, key `master-secret`):

   ```sh
   openssl rand -base64 32 | tr -d '\n' > master-secret.txt
   kubectl create secret generic platforma-master-secret --namespace <namespace> \
     --from-file=master-secret=master-secret.txt --dry-run=client -o yaml | kubectl apply -f -
   ```

2. Restart the Backend. The Deployment has the name of the Helm release:

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

#### Variant: Single Server

1. Write a new value into the file of the master secret (`PL_MASTER_SECRET_FILE`, for example `/etc/platforma/master-secret`):

   ```sh
   openssl rand -base64 32 | tr -d '\n' | sudo tee /etc/platforma/master-secret > /dev/null
   ```

2. Restart the Backend: `sudo systemctl restart platforma`.

To check the result, look in the log of the Backend for the message `Master secret was rotated: all sessions and signatures are invalidated`. The Desktop App of each user then asks the user to sign in again.

## Who sees the list of users

To share a project, a user chooses a colleague from the list of users. By default, every user sees this list. On an installation that several groups or companies share, the list shows the logins of all of them, so you can limit it:

- **All users** (`users`, the default).
- **Administrators only** (`admins`). Users cannot choose a colleague from the list, but they can still share a project: they type the login of the colleague exactly, letter for letter. Only the list of users is not shown.
- **Nobody** (`nobody`).

#### Variant: Kubernetes cluster

Set the Helm value `auth.showUserListTo`, or the module input `backend_service.auth.show_user_list_to`: `users` (default), `admins` or `nobody`. The chart gives the value to the Backend, so do not add the option `--show-user-list-to` to the extra options or its variable to the environment: the chart refuses them.

*terraform.tfvars*

```hcl
backend_service = {
  auth = {
    show_user_list_to = "admins"
  }
}
```

*values.yaml*

```yaml
auth:
  showUserListTo: admins
```

#### Variant: Single Server

Add the option `--show-user-list-to` to the start command of the Backend, or its variable to the environment of the service:

*Environment of the Backend service*

```sh
PL_SHOW_USER_LIST_TO=admins   # users (default), admins or nobody
```

To see the list yourself, run `pl-cli admin user-list` with an administrator login. It works with `users` and `admins`, not with `nobody`.

## Roles and data libraries

The roles do not control the data libraries (A folder or bucket with input data of the company. Users select files from it in the Desktop App. Platforma only reads it.), and there is no setting of a library for each user or role. Every user who signs in can read every data library that the Backend reads with its own identity, with access keys or from a folder. Only federated access and the Google account mode give each user the rights of their own identity. To keep a library for some users only, use one of these two modes, or a separate installation. See [Access modes](/security-data-library-access/) and [Data libraries](/configuration-data-libraries/).

## Next

- [Storage](/configuration-storage/)

Source: https://docs.platforma.bio/configuration-users-and-roles/
