Chapter 2. Upgrade Trusted Profile Analyzer to version 3
Upgrading Red Hat Trusted Profile Analyzer (RHTPA) from version 2.2.x to version 3.0 involves significant database schema changes. Also, the existing Software Bill of Materials (SBOM) documents must be migrated. The migration reprocesses the advisory documents and updates the vulnerability scores.
Ensure a controlled upgrade to minimize disruption, and to protect data integrity by leaving the existing database unmodified. The controlled update procedure consists of the following stages:
- Disabling the importers and switching RHTPA to read only mode
- Creating a clone of the PostgreSQL database
- Migrating the database to the new version
- Upgrading the services to the new version, re-enabling read/write mode in the process
- Re-enabling the importers on the new RHTPA version
Depending on the size of your existing data set, the migration times can vary, from a few minutes to many hours. For example, a large RHTPA deployment, with thousands of SBOM documents, might take 8+ hours to complete. Plan your maintenance window accordingly.
The procedure for the upgrade depends on whether you used the Helm or Operator installation method.
Upgrading an Ansible installation is not supported. However, you can create a clone of the database, remove the Ansible installation, and then use Helm or the Operator for the migration from the old database to install RHTPA 3.0.
2.1. Upgrade a Helm installation of Trusted Profile Analyzer to version 3 Copy linkLink copied to clipboard!
If you used Helm to deploy Red Hat Trusted Profile Analyzer (RHTPA), you can use a sequence of helm upgrade commands to make the necessary changes.
Prerequisites
A running RHTPA 2.2.5 service installed using Helm.
ImportantIf you are running an older version of RHTPA, you must first upgrade to version 2.2.5 before proceeding with this procedure.
-
A workstation with the
oc,helm, andpsqlbinaries installed and with the OpenShift Helm chart repository installed.
Procedure
- In the RHTPA dashboard, click Importers. In the list of importers, disable all importers.
On your workstation, open a terminal, and log in to OpenShift:
$ oc login --token=sha256~example --server=https://example.com:6443NoteYou can find your login token and URL information from the OpenShift web console to use on the command line. To find your login token and URL:
- Log in to the OpenShift web console.
- Click your user name, and click Copy login command.
- Enter your user name and password again, and click Display Token to view the command.
Switch to the project/namespace where RHTPA is installed:
$ oc project trusted-profile-analyzerReplace
trusted-profile-analyzerwith the namespace in which you installed RHTPA.Get the current RHTPA 2.2.5 image name:
$ oc get deploy -n trusted-profile-analyzer -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.template.spec.containers[0].image}{"\n"}{end}'Make note of the current RHTPA 2.2.5 image name and version number for use later on.
Save the existing Helm deployment values:
export helm_release=redhat-trusted-profile-analyzer helm get values "${helm_release}" | grep -v 'USER-SUPPLIED VALUES' > original-values.yamlCreate the
rhtpa-read-only.yamlfile with the following content:readOnly: true modules: migrateDatabase: enabled: false server: image: fullName: <TPA_IMAGE> importer: image: fullName: <TPA_IMAGE> createDatabase: enabled: false createImporters: enabled: falseReplace
<TPA_IMAGE>with the full current RHTPA 2.2.5 image name. These settings freeze the image, preventing thehelm upgradecommand from updating the services to the new version before the migration is complete. They also disable re-creating the database and importers during the migration.Run the following command to apply the changes:
helm upgrade "${helm_release}" openshift-helm-charts/redhat-trusted-profile-analyzer -f original-values.yaml -f rhtpa-read-only.yamlCheck that RHTPA is in read-only mode and rejecting requests.
Verify that RHTPA is in read-only mode:
$ oc exec -n trusted-profile-analyzer deploy/<release-name>-server -- \ curl -s http://localhost:8080/.well-known/trustify | jq '.readOnly'This command must return a value of
true. RHTPA is now in read-only mode.Verify that RHTPA is rejecting requests:
$ oc exec -n trusted-profile-analyzer deploy/<release-name>-server -- \ curl -s -o /dev/null -w '%{http_code}' -X POST http://localhost:8080/api/v2/advisoryThis command must return a
503code, signifying that incoming requests will be rejected.
Create a clone of the RHTPA PostgreSQL database. This new cloned database is the target for the data migration. Depending on your infrastructure, you can use the tools for your cloud provider to create a replica or else use the
pg_dumpandpg_restorecommands.ImportantThe cloned database must have the same username, password, and database name as the original database. If the credentials differ, update the
postgresql-credentialsandpostgresql-admin-credentialssecrets with the new values before proceeding.Create the
rhtpa-migratedb.yamlfile with the following content:modules: migrateDatabase: enabled: true migrateDatabase: host: <new-db-endpoint>Replace
<new-db-endpoint>with the endpoint URL of your new database clone.With these settings, the migration proceeds on the new database clone, while the RHTPA services continue operating in read-only mode using the original database.
Run the following command to start the database migration process.
helm upgrade --wait --timeout 24h0m0s "${helm_release}" openshift-helm-charts/redhat-trusted-profile-analyzer -f original-values.yaml -f rhtpa-read-only.yaml -f rhtpa-migratedb.yamlWarningThe database migration process can take a significant time.
After the migration process completes, create the
rhtpa-swapdb.yamlfile with the following content:readOnly: true database: host: <new-db-endpoint>Replace
<new-db-endpoint>with the endpoint URL of your new database clone, which is migrated by now.Run the following command to upgrade the services and use the new database endpoint.
helm upgrade --wait --timeout 24h0m0s "${helm_release}" openshift-helm-charts/redhat-trusted-profile-analyzer -f original-values.yaml -f rhtpa-swapdb.yamlThis command does not include the image-freeze settings from
rhtpa-read-only.yaml, so Helm upgrades the services to the new version. ThereadOnly: truesetting inrhtpa-swapdb.yamlkeeps the services in read-only mode until you verify that the upgrade is working correctly.Verify that the upgraded RHTPA services are working correctly with the migrated database:
$ oc exec -n trusted-profile-analyzer deploy/<release-name>-server -- \ curl -s http://localhost:8080/api/v3/sbom?limit=1 | jq '. | has("items")'This command queries the upgraded v3 API and confirms that the server can read from the migrated database.
After verifying that the upgraded services are working, switch RHTPA to read/write mode:
helm upgrade --wait --timeout 24h0m0s "${helm_release}" openshift-helm-charts/redhat-trusted-profile-analyzer -f original-values.yaml -f rhtpa-swapdb.yaml --set readOnly=falseConnect to the new RHTPA PostgreSQL database with the
psqlutility and then run the following optimizations:$ psql -c "VACUUM ANALYZE;" $ psql -c "REINDEX DATABASE CONCURRENTLY \"$PGDATABASE\";"- In the RHTPA dashboard, click Importers. In the list of importers, enable the importers that you use.
Result
RHTPA is upgraded to version 3.0.
If necessary, you can roll back to RHTPA 2.2.5 by using the older version of the Helm chart and pointing database.host to the original database endpoint, not the new clone.
2.2. Upgrade an Operator installation of Trusted Profile Analyzer to version 3 Copy linkLink copied to clipboard!
If you used Operator to deploy Red Hat Trusted Profile Analyzer (RHTPA), you must uninstall the old operator and then install the new one. However, before uninstalling the old operator, you can save a clone of the database. You can then ensure that the new operator migrates the database and uses it.
The RHTPA Operator does not offer a direct upgrade from version 2.2.x to 3.0.0. The stable-v1.1 channel used by version 2.2.x and the stable-v3 channel used by version 3.0 are independent. There is no automated upgrade path between them.
To upgrade, you must uninstall the old Operator and install the new one. You can preserve your existing data by pointing the new deployment at a replica or snapshot of your original database, using the same S3 storage and OIDC configuration in the new CR.
Because the new Operator begins reconciliation automatically on install, you must set readOnly: true and freeze the server and importer images in the CR before installing the new Operator, as described in the steps. This setting ensures the deployment does not start writing to the database before the migration completes.
Prerequisites
A running RHTPA 2.2.5 service installed using the Operator.
ImportantIf you are running an older version of RHTPA, you must first upgrade to version 2.2.5 before proceeding with this procedure.
Procedure
- In the RHTPA dashboard, click Importers. In the list of importers, disable all importers.
Open the RHTPA Operator CR and make the following change:
readOnly: trueCheck that RHTPA is in read-only mode and rejecting requests.
Verify that RHTPA is in read-only mode:
$ oc exec -n trusted-profile-analyzer deploy/<release-name>-server -- \ curl -s http://localhost:8080/.well-known/trustify | jq '.readOnly'This command must return a value of
true. RHTPA is now in read-only mode.Verify that RHTPA is rejecting requests:
$ oc exec -n trusted-profile-analyzer deploy/<release-name>-server -- \ curl -s -o /dev/null -w '%{http_code}' -X POST http://localhost:8080/api/v2/advisoryThis command must return a
503code, signifying that incoming requests will be rejected.
Save the current Operator CR as a backup:
$ oc get trustedprofileanalyzer <release-name> -n trusted-profile-analyzer -o yaml > original-cr.yamlReplace
<release-name>with the name of your RHTPA deployment.Create a clone of the RHTPA PostgreSQL database. This new cloned database is the target for the data migration. Depending on your infrastructure, you can use the tools for your cloud provider to create a replica or else use the
pg_dumpandpg_restorecommands. The new clone must be outside the RHTPA Operator deployment so that it does not get removed when you remove the Operator deployment.ImportantThe cloned database must have the same username, password, and database name as the original database. If the credentials differ, update the
postgresql-credentialsandpostgresql-admin-credentialssecrets with the new values before proceeding.- Remove the RHTPA 2.2.5 Operator deployment.
Start deploying the RHTPA 3.0 Operator and select the
stable-v3channel, which provides RHTPA 3.0. Before deploying the Operator, make the following changes to the CR:modules: migrateDatabase: enabled: true migrateDatabase: host: <new-db-endpoint> readOnly: true database: host: <new-db-endpoint>Replace
<new-db-endpoint>with the endpoint URL of your new database clone. These settings run the services in read-only mode while the migration completes.After the migration process completes, edit the RHTPA Operator CR and make the following change:
readOnly: falseConnect to the new RHTPA PostgreSQL database with the
psqlutility and then run the following optimizations:$ psql -c "VACUUM ANALYZE;" $ psql -c "REINDEX DATABASE CONCURRENTLY \"$PGDATABASE\";"- In the RHTPA dashboard, click Importers. In the list of importers, enable the importers that you use.
Verify that the upgraded RHTPA services are working correctly with the migrated database:
$ oc exec -n trusted-profile-analyzer deploy/<release-name>-server -- \ curl -s http://localhost:8080/api/v3/sbom?limit=1 | jq '. | has("items")'
Result
RHTPA is upgraded to version 3.0.
If necessary, you can roll back to RHTPA 2.2.5 by using the Operator version from the stable-v1.1 channel and pointing database.host to the original database endpoint, not the new clone.