> Source: https://docs.cyberelements.io/bastion/4.7/cs/Upgrade/HotVersionUpgrade/MediationController/

# Live upgrade of the Mediation Controller

> **Important**
>
> The documentation for live upgrading the Mediation Controller to version 4.7 is intended for any Mediation Controller in version 4.6, running Debian 12. The Debian version can be checked using the following command (to be executed in SSH or console access):
>
> ```
> 1
> ```

> **Information**
>
> As a reminder, switching to `root` on Debian machines must be performed using the following command:
>
> ```
> 1
> ```

> **Virtual appliances**
>
> For a Mediation Controller installed from a virtual appliance (OVA), the procedure is the same, with the following particularities:
>
> - Before the upgrade, check the disk space of `/usr`: see [Disk space extension for virtual appliances](#disk-space-extension-for-virtual-appliances).
> - Open the console with the `systancia` account, then switch to `root` with the `su -` command.
> - After the upgrade, report the hardening settings of the appliance in the replaced files, in particular the `pam_securetty` line of `/etc/pam.d/login`, from its `.dpkg-old` version. The `/etc/ssh/sshd_config` file is kept by following the table of the configuration files in [Triggering the version upgrade](#triggering-the-version-upgrade).
> - The move to Debian 13 removes the `/etc/sysctl.conf` file without asking any question; its version is kept as `/etc/sysctl.conf.dpkg-bak`: report its settings in a file of `/etc/sysctl.d/`.

## Planning and Preparation

### Opening flows

When upgrading the product, many packages must be downloaded from the Debian repositories due to the transition from Debian version 12 to 13. `TCP 80` access must be opened to `security.debian.org` and `ftp.fr.debian.org`.

To test the opening of streams on the machine, a synchronisation of the Debian repositories can be launched. If error messages regarding access to the Debian repositories are displayed, then the network flow is not open, probably blocked by the organisation's firewall. Repository synchronisation can be initiated with the following command:

```
1
```

### Downloading the mirror and necessary tools

The CyberElements Bastion 4.7 mirror can be downloaded from this link (requires the creation of a customer account): [Systancia Marketplace](https://www.systancia.com/en/my-systancia/marketplace/systancia-cleanroom/downloads-cleanroom/)

The `systancia.gpg` key for Debian 13, which authenticates the CyberElements Bastion repository, must also be downloaded from the Systancia Marketplace: it is different from the key used with Debian 12.

In addition to the mirror, third-party tools will be required for the upgrade process:

- An SSH client (on Windows, the [PuTTY](https://putty.org/) tool can be used)
- An SCP client (on Windows, the [WinSCP](https://winscp.net/eng/index.php) or [FileZilla](https://filezilla-project.org/) tools can be used)

### Installing and using the screen tool

The `screen` tool allows you to open multiple shell terminals in a single console. It is essential to use this tool to perform the CyberElements Bastion version upgrade, in order to remove dependency on the stability of network connectivity. In fact, without using the screen tool, the installation would be stopped in the event of a break in SSH connectivity with the CyberElements Bastion servers.

By using the `screen` tool, when reconnecting to the shell console of the CyberElements Bastion equipment, the terminal in which the update process was executed can be retrieved.

The screen package should be installed using the following command line:

```
1
```

To open a new `screen` terminal, the following command must be executed:

```
1
```

> **Example**
>
> For CyberElements version upgrades, the `cye-upgrade` identifier is easily identifiable. The command would therefore be as follows:
>
> ```
> 1
> ```

To retrieve a terminal opened by `screen`, simply execute the following command:

```
1
```

> **Example**
>
> The terminal previously opened with the `cye-upgrade` identifier can be retrieved with the following command:
>
> ```
> 1
> ```

To close the terminal once the upgrade is complete, enter the `exit` command or keyboard shortcut ctrl+d in the terminal.

This will return you to the console. The message “screen is terminating” confirms that the terminal has been closed.

### Disk space extension for virtual appliances

The upgrade to version 4.7 requires a `/usr` partition of **6 GB**. The virtual appliances (OVA) of version 4.6 provide a `/usr` partition of 4.6 GB, in a volume group with no free space left: the upgrade could run out of disk space and be blocked during the operation. Before the upgrade, extend `/usr` so that it reaches 6 GB.

When connecting to the server, whether via SSH or in console mode, a welcome message informs you that you are connected to a Systancia machine. On a virtual appliance, an additional line gives the version of the appliance.

> **Example**
>
> A virtual appliance in version 4.6.1 displays the following message:
>
> ```
>  1
>  2
>  3
>  4
>  5
>  6
>  7
>  8
>  9
> 10
> 11
> 12
> 13
> 14
> 15
> ```

If the server is not a virtual appliance, skip this section.

Check the size of the `/usr` partition, as `root`:

```
1
```

On a 4.6 virtual appliance whose partitioning has not been modified, the size displayed is `4.6G`: the disk must be extended by **1.5 GB**. If the size displayed is already `6.0G` or more, skip this section.

> **Backup strongly recommended**
>
> The following steps modify the disk partitioning of the server. They assume the partitioning delivered with the appliance: if it has been modified by hand, they may not be suitable and may leave the machine unusable.
>
> Before going further, back up the virtual machine or duplicate it. A snapshot prevents the extension of the disk, particularly with VMware: remove the existing snapshots before extending the disk. Once the disk is extended, a snapshot can be taken before running the commands below.

At the hypervisor level, extend the disk of the virtual machine by 1.5 GB. With VMware vSphere, the extension can be performed while the virtual machine is running: neither a shutdown nor a restart is necessary.

Once the disk is extended, run the following commands as `root` to extend the `/usr` partition:

```
1
2
3
4
5
6
```

`fdisk` displays the messages `This disk is currently in use - repartitioning is probably a bad idea.` and `Partition #5 contains a LVM2_member signature.`: they are expected, and the signature is kept. Depending on the state of the partition table, `fdisk` may also display `The kernel still uses the old partitions. The new table will be used at the next reboot.` and `Failed to update system information about partition 2: Device or resource busy`: they have no consequence, the check of the result below is what counts.

Check the result: `df -h /usr` must display a size of `6.0G`. No restart is necessary.

### Recording the name resolution settings

The upgrade may modify the `hosts` line of the `/etc/nsswitch.conf` file, which sets the order of the name resolution sources. Note its current value to restore it after the upgrade:

```
1
```

## Values used on this page

The following values are used in several commands and configuration files of this page. Enter them here: the commands displayed on this page are updated as you type.
A value used by a single command is entered in a table placed just before that command.

| Value | Variable | Definition |
|---|---|---|
|  | `SCREEN_SESSION` | Name that identifies the `screen` session, chosen when it is opened. |

## Upgrade

### Cluster architecture

In a Cluster architecture, the procedure of this page is performed on each Mediation Controller, as follows:

1. Upgrade the two Mediation Controllers either one after the other, starting with the `SLAVE` Mediation Controller, or in parallel. In both cases, the resynchronisation of the shared secret and the migration of the databases (steps 3 and 4) are performed once both Mediation Controllers have been upgraded. Until the `MASTER` Mediation Controller is upgraded, the already upgraded `SLAVE` Mediation Controller no longer publishes the consoles and the portal: plan to upgrade both Mediation Controllers within the same maintenance window.
2. On each Mediation Controller, before the restart that follows the upgrade, modify the `/etc/network/interfaces` file. The move to Debian 13 deletes the `/etc/sysctl.conf` file, which the virtual addresses of the cluster read at startup with the `sysctl -p` command; the following command replaces it with `sysctl --system`:

   ```
   1
   ```
3. Once both Mediation Controllers have been upgraded, on the `SLAVE` Mediation Controller, run the following commands to resynchronise the shared secret between the `MASTER` Mediation Controller and the `SLAVE`:

   ```
   1
   2
   ```

   Check that the `/etc/ipdiva/secure/secret` file is identical on both Mediation Controllers, by comparing the result of the following command on each of them:

   ```
   1
   ```
4. Then, from only one of the Mediation Controllers, regardless of which one, migrate the databases once: the system configuration database (`default`), then the databases of the organisations, as described in [Migration of the CyberElements Bastion database](#migration-of-the-cyberelements-bastion-database).
5. Check the access to the system console (`/system`), to the administrator interface (`/console`) and to the user portal (`/cloud`), through the virtual address of the cluster and through the address of each Mediation Controller.

### Updating Debian packages

Since upgrading CyberElements Bastion requires upgrading Debian, it is recommended that you properly update Debian 12 packages before switching to Debian 13, in order to reduce the duration of the upgrade. To do this, run the following commands as `root` (system update then removal of unnecessary packages):

```
1
2
3
```

Messages asking you to modify the configuration of several configuration files may appear. In these cases, select the option to keep the current configuration.

If a Microsoft ODBC driver is installed (`msodbcsql17` or `msodbcsql18`), its update displays the licence terms: accept them (`Yes`) to continue.

### Preparing Microsoft SQL Server drivers

Additional steps are required if Microsoft SQL Server drivers are installed.
To check whether they are present on the server, the following command can be executed as `root`:

```
1
```

If no package is listed, the drivers are not installed and you can proceed to [the mirror preparation step](#preparing-the-cyberelements-bastion-47-mirror).
Otherwise, the `msodbcsql17` or `msodbcsql18` package is listed: follow the instructions in this section.

The Microsoft repository must be declared for Debian 13. Remove the declaration of the Debian 12 repository, then install the `packages-microsoft-prod` package for Debian 13, which declares the new repository and its signature key:

```
1
2
3
4
```

After the [APT configuration](#apt-configuration), update the installed driver (`msodbcsql17` or `msodbcsql18`) with the command of its version, which accepts the Microsoft licence. The command has no effect if the driver is already up to date:

**Version 17**

> ```
> 1
> ```

**Version 18**

> ```
> 1
> ```

### Preparing the CyberElements Bastion 4.7 mirror

The mirror retrieved during the preparation phase (file with the tgz extension) must be sent to the server via SCP. It should be placed in the `/tmp/` directory.

Next, prepare the mirror by executing the following commands as `root` (residual files from an old version upgrade will be deleted):

```
1
2
3
```

### APT configuration

The APT package manager is configured to retrieve Debian 12 packages; it must be reconfigured to retrieve Debian 13 packages. It is also necessary to update the reference to the local CyberElements Bastion mirror. To do this, execute the following commands as `root`:

```
1
2
```

The local mirror is authenticated by the `systancia.gpg` key for Debian 13 downloaded during the preparation phase. Send it to the server via SCP, in the `/tmp/` directory, then install it with the following command as `root` (it replaces the key used with Debian 12):

```
1
```

In addition to configuring the new repositories, we strongly recommend applying the following setting to instruct APT not to install recommended dependencies that are not strictly necessary, in order to reduce the number of components installed. The following command applies this setting as`root`:

```
1
```

Finally, it is necessary to update the list of packages in the repositories with the following command:

```
1
```

> **Recommendation**
>
> The security hardening guide details the integrity check of the packages and of the APT repositories: see [R6](https://docs.cyberelements.io/bastion/4.7/cs/Security/SystemHardening/SystemInstallation/#r6).

### Opening the screen and the operation log

Access the Mediation Controller server via SSH and switch to `root`, then open a screen [as indicated above](#installing-and-using-the-screen-tool). The following steps are performed in this screen.

It is recommended to keep a log of the operation. The `script` command records everything displayed in the terminal in a file, until the `exit` command:

```
1
```

### Triggering the version upgrade

In the screen opened previously, initiate the upgrade with the following command:

```
1
```

During the upgrade, the following windows are displayed:

| Window | Answer |
|---|---|
| “Upgrade PostgreSQL cluster 15/main to 17?” (Debian 13 provides PostgreSQL 17) | `Yes`; the question is asked twice, and the first time `No` is preselected |
| “Do you want to upgrade glibc now?” (`libc6` package, the `postgresql` service must be stopped) | `Yes` |
| “Restart services during package upgrades without asking?” (`libc6` package) | `Yes` (`No` is preselected) |

You will also be asked several questions about whether to replace configuration files with the version of the new packages, or to keep the configuration in place. Depending on the changes made to the server, all or some of these questions may be asked. Answer `Y` to every question, **except** for the files that the following table says to keep:

| Configuration file | Recommended action |
|---|---|
| `/etc/ipdiva/plugin/plugin.xml` | To keep, answer `N` |
| `/etc/ipdiva/care/djangosettings.ini` | Apply changes, answer `Y` (the previous file is kept as `/etc/ipdiva/care/djangosettings.ini.dpkg-old`, see [Restoring configurations](#restoring-configurations)) |
| `/etc/default/grub` (menu window) | To keep, choose `keep the local version currently installed` |
| `/etc/ssh/sshd_config` (menu window) | To keep, choose `keep the local version currently installed` |

> **Attention!**
>
> When a file is replaced, its previous version is kept with the `.dpkg-old` extension (`.ucf-old` for the files of a menu window). If hardening settings had been applied to a replaced file (for example `/etc/login.defs` or `/etc/security/limits.conf`), report them in the new file after the upgrade, from its previous version. The security hardening guide details these settings: see [Accounts, privileges and local authentication](https://docs.cyberelements.io/bastion/4.7/cs/Security/SystemHardening/SystemAccounts/).

### Removing PostgreSQL 15

Once the upgrade is complete, check the state of the PostgreSQL instances:

```
1
```

The version 17 instance must be the only one `online`. The version 15 instance can then be deleted, as well as the packages that are no longer necessary:

```
1
2
```

> **Cluster architecture**
>
> On a Mediation Controller of a cluster, modify the `/etc/network/interfaces` file before the restart: see step 2 of [Cluster architecture](#cluster-architecture).

Exit the operation log, then restart the server:

```
1
2
```

### Restoring the name resolution settings

After the restart, compare the `hosts` line of the `/etc/nsswitch.conf` file with the value noted before the upgrade:

```
1
```

If it was modified, restore its previous value by editing the file, so as to avoid any name resolution problem.

### Migration of the CyberElements Bastion database

The product configuration is stored in the database, which needs to be migrated so that it can contain the configurations of the changes made by the new version. In a Standalone architecture, the system configuration database (`default`) is migrated automatically during the upgrade; in a Cluster architecture, it is migrated by the command in the box below. However, **the databases of the organisations are not migrated automatically**. The operation is performed on the Mediation Controller as `root`.

> **Cluster architecture**
>
> For a Cluster architecture, perform the operation once both Mediation Controllers have been upgraded, from only one of them, regardless of which one (see [Cluster architecture](#cluster-architecture)). Start with the migration of the system configuration database (`default`):
>
> ```
> 1
> ```

Data migration is triggered with a command equivalent to this one:

| Value | Variable | Definition |
|---|---|---|
|  | `MIGRATED_ORGANIZATION` | Name of the organisation to migrate. |

```
1
```

Please note that if the Mediation Controller has multiple organisations (multi-tenants), then you will need to run the command as many times as there are organisations to migrate.

> **Example**
>
> For a CyberElements Bastion platform that has the organisations `systancia` and `systancia-test`, you will need to run the following commands:
>
> ```
> 1
> 2
> ```

Following the database migration, the Apache2 service must be restarted:

```
1
```

During the upgrade, the sections of the organisations and of the [remote vault databases](https://docs.cyberelements.io/bastion/4.7/cs/Usage/Administration/AdminConsole/MainWorkPanel/Vault/Integrated/IntegratedVault/#remote-vault-database) are moved from the `/etc/ipdiva/care/databasesettings.ini` file to one file per database in the `/etc/ipdiva/care/databases.d/` directory; only the `[database]` section remains in `databasesettings.ini`, and the original file is kept as `/etc/ipdiva/care/databasesettings.ini.pre-migration`.

### Restoring configurations

If the `/etc/ipdiva/care/djangosettings.ini` file was replaced during the upgrade, its previous version is kept as `/etc/ipdiva/care/djangosettings.ini.dpkg-old`. The `allowed_hosts` line takes the Web VPN virtual hosts configured on the platform: it normally does not need to be restored. The other settings modified by hand in this file must however be reported in the new file. To identify them, compare the two versions as `root`:

```
1
```

After reporting settings, restart the Apache2 service as `root`:

```
1
```

## Validation

Once the upgrade has been completed, the CyberElements Bastion infrastructure must be validated to ensure it is functioning correctly before going back into production. If validation fails, consider rolling back by restoring the CyberElements Bastion server backups.

Access the system console (`/system`) and the administrator interface of an organisation (`/console`), then go to the “About” menu in the control bar to check that the Mediation Controller version has been successfully upgraded to 4.7. Also check access to the user portal (`/cloud`).

### Association with Workplace

If the [association with Workplace](https://docs.cyberelements.io/bastion/4.7/cs/Usage/Administration/AdminConsole/ConfigurationWorkPanel/WorkplaceAssociation/WorkplaceAssociation/) was enabled before the upgrade, a **site** must be chosen in its Reverse Proxy section after the upgrade, so that the communication with the Workplace server is active again. The upgrade also creates an access contract named `CleanroomAccessProfile`, which authorises access to Workplace.

Initial tests of the platform's functionality can be initiated, but we recommend using version 4.7 of Edge Gateway to ensure optimal performance of CyberElements Bastion applications.
