diff --git a/charts/matrix-stack/templates/deployment-markers/_helpers.tpl b/charts/matrix-stack/templates/deployment-markers/_helpers.tpl index 7fec6fa4..bd3207ae 100644 --- a/charts/matrix-stack/templates/deployment-markers/_helpers.tpl +++ b/charts/matrix-stack/templates/deployment-markers/_helpers.tpl @@ -53,8 +53,8 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" $ {{- /* We're only dry-run migrating so we're still stuck in legacy auth */ -}} - {{ (printf "%s-markers" $root.Release.Name) }}:MATRIX_STACK_MSC3861:legacy_auth:legacy_auth {{- else }} - {{- /* We're running the migration for real so allow to go legacy auth -> migrated but don't allow to stay in this state after another deploy */ -}} -- {{ (printf "%s-markers" $root.Release.Name) }}:MATRIX_STACK_MSC3861:syn2mas_migrated:legacy_auth + {{- /* We're running the migration for real so allow to go legacy auth -> migrated as well as allowing to stay in this state after another deploy (the migration process will no-op) */ -}} +- {{ (printf "%s-markers" $root.Release.Name) }}:MATRIX_STACK_MSC3861:syn2mas_migrated:legacy_auth;syn2mas_migrated {{- end }} {{- else }} {{- /* We've started with MAS or migrated to MAS, so allow to come from migrated -> MAS as well as staying with MAS */ -}} diff --git a/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl b/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl index 1561b40e..1d59f9c2 100644 --- a/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl +++ b/charts/matrix-stack/templates/matrix-authentication-service/_helpers.tpl @@ -273,5 +273,12 @@ true env: - name: "NAMESPACE" value: {{ $root.Release.Namespace | quote }} +{{- if $root.Values.deploymentMarkers.enabled }} +- name: "CURRENT_MARKER_STATE" + valueFrom: + configMapKeyRef: + name: "{{ $root.Release.Name }}-markers" + key: MATRIX_STACK_MSC3861 +{{- end }} {{- end -}} {{- end -}} diff --git a/docs/syn2mas.md b/docs/syn2mas.md index 9ba04dae..c9926d74 100644 --- a/docs/syn2mas.md +++ b/docs/syn2mas.md @@ -18,8 +18,8 @@ The syn2mas migration will run in a couple of minutes. It involves **three key s | Step | Action | Result | |------|--------|--------| | 1 | Setup Matrix Authentication Service and enable `syn2mas` in dryRun mode | System remains in `legacy_auth`. Matrix Authentication Service is deployed in `read-only` mode. It initializes the database. Users are still able to login using the legacy authentication. | -| 2 | Run migration (dry run disabled) | System transitions to `syn2mas_migrated`. Users now login using the delegated authentication. Rollback to legacy authentication is not possible any more. syn2mas cannot be run any more. | -| 3 | Disable syn2mas | System finalizes to `delegated_auth`. | +| 2 | Run migration (dry run disabled) | System transitions to `syn2mas_migrated`. Users now login using the delegated authentication. Rollback to legacy authentication is not possible any more. | +| 3 | Disable syn2mas | System finalizes to `delegated_auth` and stops attempting to run the `syn2mas` job. | ## Important Notes @@ -80,12 +80,12 @@ helm upgrade --namespace "ess" ess oci://ghcr.io/element-hq/ess-helm/matrix-stac - Matrix Authentication Service restarts and is ready to serve the delegated authentication - The `MATRIX_STACK_MSC3861` marker is updated to reflect the `syn2mas_migrated` state. -Your users are now able to login using the delegated authentication. It is not possible to rollback to `legacy_auth` any more, nor to run the syn2mas migration again. +Your users are now able to login using the delegated authentication. It is not possible to rollback to `legacy_auth` any more. The `syn2mas` job will keep running but will not do anything again. ### Step 3: Disable syn2mas -When in `syn2mas_migrated` state, running `helm upgrade` will prevent any deployment until `syn2mas` is disabled and the state becomes `delegated_auth`. +When in `syn2mas_migrated` state, running `helm upgrade` will succeed but will keep running a no-op `syn2mas` job until `syn2mas` is disabled and the state is finalised at `delegated_auth`. 2. Run the helm upgrade command without syn2mas arguments: diff --git a/matrix-tools/internal/cmd/syn2mas/cmd.go b/matrix-tools/internal/cmd/syn2mas/cmd.go index 7deaa31c..6ae73102 100644 --- a/matrix-tools/internal/cmd/syn2mas/cmd.go +++ b/matrix-tools/internal/cmd/syn2mas/cmd.go @@ -25,6 +25,15 @@ func Run(options *Syn2MasOptions) { os.Exit(1) } + currentMarkerState := os.Getenv("CURRENT_MARKER_STATE") + // We don't need to consider the `delegated_auth`` state (i.e. after a deployment has happened with syn2mas has been turned off) + // Because we don't allow transitioning back from `delegated_auth`` -> `syn2mas_migrated`` + // If deploymentMarkers is off then we won't have any record in cluster and we'll have the empty string here and migration will proceed + if currentMarkerState == "syn2mas_migrated" { + fmt.Println("The cluster is recording the syn2mas migration as already having occurred. Skipping the migration") + os.Exit(0) + } + // Dry-run (and check) is always executed before doing a real migration executor.DryRunSyn2MAS(options.SynapseConfig, options.MASConfig) if !options.DryRun { diff --git a/newsfragments/1584.changed.1.md b/newsfragments/1584.changed.1.md new file mode 100644 index 00000000..6daa3f22 --- /dev/null +++ b/newsfragments/1584.changed.1.md @@ -0,0 +1,3 @@ +Allow the `syn2mas` migration process to stay in stage 2 for multiple deployments. + +The actual `syn2mas` Helm hooks will keep running but will not doing anything until `matrixAuthenticationService.syn2mas.enabled: false` and the migration is finalised. diff --git a/tests/integration/test_syn2mas.py b/tests/integration/test_syn2mas.py index 605cef4f..faaeb0fb 100644 --- a/tests/integration/test_syn2mas.py +++ b/tests/integration/test_syn2mas.py @@ -1,5 +1,5 @@ # Copyright 2025 New Vector Ltd -# Copyright 2025 Element Creations Ltd +# Copyright 2025-2026 Element Creations Ltd # # SPDX-License-Identifier: AGPL-3.0-only @@ -69,10 +69,10 @@ async def test_run_syn2mas_upgrade( # Syn2Mas is running in migrate mode, so the state must have changed assert await get_deployment_marker(kube_client, generated_data, "MATRIX_STACK_MSC3861") == "syn2mas_migrated" - # Assert we cant run syn2mas again - revision, error = await deploy_with_values_patch(generated_data, helm_client, {}, timeout="15s") - assert error is not None, "There was no error" - assert revision.status == pyhelm3.ReleaseRevisionStatus.FAILED + # Assert we can run syn2mas again (same values as last run) + revision, error = await deploy_with_values_patch(generated_data, helm_client, {}) + assert error is None, error + assert revision.status == pyhelm3.ReleaseRevisionStatus.DEPLOYED # Auth metadata endpoint should be reachable response = await aiohttp_get_json(