From 6411b9e1065dbeaa0a786de9629719e04a862662 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 8 Oct 2026 16:24:51 +0000 Subject: [PATCH 1/4] Redo storage account uniqueness fix for airlock v2 workspaces only (#2893) Co-authored-by: marrobi <17089773+marrobi@users.noreply.github.com> --- CHANGELOG.md | 3 + api_app/_version.py | 2 +- api_app/db/repositories/workspaces.py | 70 +++++++++++----- api_app/resources/constants.py | 5 ++ .../test_workpaces_repository.py | 82 ++++++++++++++++--- .../tre-resources-breakdown.md | 2 +- .../guacamole-azure-linuxvm/porter.yaml | 9 +- .../template_schema.json | 26 ++++++ .../terraform/locals.tf | 2 +- .../terraform/variables.tf | 5 ++ .../guacamole-azure-windowsvm/porter.yaml | 9 +- .../template_schema.json | 26 ++++++ .../terraform/locals.tf | 2 +- .../terraform/variables.tf | 5 ++ .../workspace_services/ohdsi/porter.yaml | 9 +- .../ohdsi/template_schema.json | 27 +++++- .../ohdsi/terraform/locals.tf | 2 +- .../ohdsi/terraform/variables.tf | 5 ++ .../airlock-import-review/porter.yaml | 2 +- templates/workspaces/base/porter.yaml | 16 +++- templates/workspaces/base/terraform/locals.tf | 2 +- .../workspaces/base/terraform/outputs.tf | 4 + .../workspaces/base/terraform/variables.tf | 11 +++ templates/workspaces/unrestricted/porter.yaml | 2 +- 24 files changed, 281 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffa4566239..ae3754c8e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,9 @@ BUG FIXES: Reject failed parameter discovery and keep request parameters out of completion logs. (`resource_processor` 0.13.10, `tre-shared-service-firewall` 1.6.4) ([#4903](https://github.com/microsoft/AzureTRE/issues/4903)) * Allow up to 30 checks at ten-second intervals when enabling or disabling storage public access during deployment. (`devops` 0.6.10) ([#5113](https://github.com/microsoft/AzureTRE/pull/5113)) +* Name the workspace storage account of new `airlock_version` 2 workspaces from a random 12-character suffix (`stgws{suffix}`) checked for availability before creation, instead of the last 4 characters of the workspace ID, + to prevent `StorageAccountAlreadyTaken` deployment failures. Legacy (v1) workspaces, including those later moved to v2, keep their existing names. The workspace exposes `storage_account_name`, which OHDSI and Guacamole VMs now use. + (`API` 0.28.3, `tre-workspace-base` 2.13.0, `tre-workspace-unrestricted` 0.15.2, `tre-workspace-airlock-import-review` 0.18.2, `tre-workspace-service-ohdsi` 0.4.0, `tre-service-guacamole-linuxvm` 1.5.0, `tre-service-guacamole-windowsvm` 3.1.0) ([#2893](https://github.com/microsoft/AzureTRE/issues/2893), [#3666](https://github.com/microsoft/AzureTRE/issues/3666)) * Include Azure cloud and location in isolated CI environment names to avoid retained Key Vault name conflicts after region changes. Find previous CI environments by ownership tags during explicit cleanup. (`devops` 0.6.9) ([#5106](https://github.com/microsoft/AzureTRE/issues/5106)) * Validate Certbot before `make letsencrypt` prepares Azure access, check the resource group after loading Terraform outputs, and disable optional Super-Linter publishing with read-only GitHub tokens. ([#5110](https://github.com/microsoft/AzureTRE/pull/5110)) * Preserve loaded UI views during background refresh, ignore stale workspace responses, refresh on every tab return, and keep internal Connect behavior and unavailable cost displays consistent. (`ui` 0.10.1) ([#5105](https://github.com/microsoft/AzureTRE/pull/5105)) diff --git a/api_app/_version.py b/api_app/_version.py index 6c302c1696..cc09a062c6 100644 --- a/api_app/_version.py +++ b/api_app/_version.py @@ -1 +1 @@ -__version__ = "0.28.2" +__version__ = "0.28.3" diff --git a/api_app/db/repositories/workspaces.py b/api_app/db/repositories/workspaces.py index be0d8f0928..d5bff3ae6f 100644 --- a/api_app/db/repositories/workspaces.py +++ b/api_app/db/repositories/workspaces.py @@ -1,4 +1,6 @@ import uuid +import secrets +import string from typing import List, Tuple import asyncio from azure.mgmt.storage.aio import StorageManagementClient @@ -114,9 +116,13 @@ async def get_workspace_by_id(self, workspace_id: str) -> Workspace: raise EntityDoesNotExist return TypeAdapter(Workspace).validate_python(workspaces[0]) - # Remove this method once not using last 4 digits for naming - https://github.com/microsoft/AzureTRE/issues/3666 - async def is_workspace_storage_account_available(self, credential, workspace_id: str) -> bool: - name = f"stgws{workspace_id[-4:]}" + @staticmethod + def generate_unique_identifier_suffix() -> str: + alphabet = string.ascii_lowercase + string.digits + return "".join(secrets.choice(alphabet) for _ in range(constants.UNIQUE_IDENTIFIER_SUFFIX_LENGTH)) + + async def is_workspace_storage_account_available(self, credential, name_suffix: str) -> bool: + name = constants.STORAGE_ACCOUNT_NAME_WORKSPACE.format(name_suffix) storage_client = StorageManagementClient( credential, config.SUBSCRIPTION_ID, @@ -136,25 +142,6 @@ async def create_workspace_item( self, workspace_input: WorkspaceInCreate, auth_info: dict, workspace_owner_object_id: str, user_roles: List[str] ) -> Tuple[Workspace, ResourceTemplate]: - full_workspace_id = str(uuid.uuid4()) - - # Ensure workspace with last four digits of ID does not already exist - remove when https://github.com/microsoft/AzureTRE/issues/3666 is resolved - async with credentials.get_credential_async_context() as credential: - - async def name_check(): - nonlocal full_workspace_id - while not await self.is_workspace_storage_account_available(credential, full_workspace_id): - full_workspace_id = str(uuid.uuid4()) - - try: - await asyncio.wait_for(name_check(), timeout=45.0) - except asyncio.TimeoutError: - raise StorageAccountNameGenerationTimeout( - "Unable to generate a unique storage account name within the timeout limit." - ) - except HttpResponseError as e: - raise StorageAccountNameCheckFailed("Storage name availability check failed.") from e - template = await self.validate_input_against_template( workspace_input.templateName, workspace_input, ResourceType.Workspace, user_roles ) @@ -183,6 +170,11 @@ async def name_check(): airlock_version = 1 airlock_version_param = {"airlock_version": airlock_version} + full_workspace_id, unique_identifier_suffix = await self.generate_workspace_storage_naming(airlock_version) + # Only airlock_version >= 2 workspaces use the random suffix for storage account naming. The + # suffix is set once at creation, so legacy workspaces keep their names even after moving to v2. + unique_identifier_suffix_param = {"unique_identifier_suffix": unique_identifier_suffix} + # JSON Schema defaults validate input but are not materialised by the API. Persist the # Airlock default so review-workspace templates that default it to false do not later get # interpreted as having Airlock enabled. @@ -203,6 +195,7 @@ async def name_check(): **workspace_owner_param, **airlock_version_param, **enable_airlock_param, + **unique_identifier_suffix_param, **auth_info, **self.get_workspace_spec_params(full_workspace_id), } @@ -218,6 +211,39 @@ async def name_check(): return workspace, template + async def generate_workspace_storage_naming(self, airlock_version: int) -> Tuple[str, str]: + """Generate a workspace id and storage account name suffix with an available storage account name. + + airlock_version >= 2 workspaces name their storage account from a random unique_identifier_suffix. + Legacy (v1) workspaces keep naming storage accounts from the last 4 characters of the workspace id + (https://github.com/microsoft/AzureTRE/issues/3666), and return an empty suffix. + """ + full_workspace_id = str(uuid.uuid4()) + unique_identifier_suffix = "" + + async with credentials.get_credential_async_context() as credential: + + async def name_check(): + nonlocal full_workspace_id, unique_identifier_suffix + if airlock_version >= 2: + unique_identifier_suffix = self.generate_unique_identifier_suffix() + while not await self.is_workspace_storage_account_available(credential, unique_identifier_suffix): + unique_identifier_suffix = self.generate_unique_identifier_suffix() + else: + while not await self.is_workspace_storage_account_available(credential, full_workspace_id[-4:]): + full_workspace_id = str(uuid.uuid4()) + + try: + await asyncio.wait_for(name_check(), timeout=45.0) + except asyncio.TimeoutError: + raise StorageAccountNameGenerationTimeout( + "Unable to generate a unique storage account name within the timeout limit." + ) + except HttpResponseError as e: + raise StorageAccountNameCheckFailed("Storage name availability check failed.") from e + + return full_workspace_id, unique_identifier_suffix + def get_workspace_owner(self, workspace_properties: dict, workspace_owner_object_id: str) -> str: # Add the objectId of the user that will become the workspace owner. If it is not present in # the request, we can assume the logged in user will be WorkspaceOwner diff --git a/api_app/resources/constants.py b/api_app/resources/constants.py index 5ace54a332..2f7f3e9883 100644 --- a/api_app/resources/constants.py +++ b/api_app/resources/constants.py @@ -2,6 +2,11 @@ CORE_RESOURCE_GROUP_NAME = "rg-{}" WORKSPACE_RESOURCE_GROUP_NAME = "rg-{}-ws-{}" +# Workspace storage account (templates/workspaces/base/terraform/locals.tf) +STORAGE_ACCOUNT_NAME_WORKSPACE = "stgws{}" +# Length of the random suffix used to name the storage account of airlock_version >= 2 workspaces +UNIQUE_IDENTIFIER_SUFFIX_LENGTH = 12 + IMPORT_TYPE = "import" EXPORT_TYPE = "export" diff --git a/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py b/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py index a7f99f1c71..1c8213a410 100644 --- a/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py +++ b/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py @@ -1,3 +1,4 @@ +import re import copy from unittest.mock import AsyncMock import pytest @@ -292,6 +293,69 @@ async def test_create_workspace_item_defaults_legacy_template_to_airlock_v1( assert workspace.properties["airlock_version"] == 1 +@pytest.mark.asyncio +@patch("db.repositories.workspaces.generate_new_cidr") +@patch("db.repositories.workspaces.WorkspaceRepository.validate_input_against_template") +@patch("db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available") +@patch("core.config.RESOURCE_LOCATION", "useast2") +@patch("core.config.TRE_ID", "9876") +async def test_create_workspace_item_v2_uses_available_random_storage_suffix( + mock_is_workspace_storage_account_available, + validate_input_mock, + new_cidr_mock, + workspace_repo, + basic_workspace_request, + basic_resource_template, +): + workspace_to_create = basic_workspace_request + workspace_to_create.properties["airlock_version"] = 2 + workspace_to_create.properties["unique_identifier_suffix"] = "userinput" + # first generated suffix is taken, second is available + mock_is_workspace_storage_account_available.side_effect = [False, True] + basic_resource_template.properties["airlock_version"] = Property(default=2, enum=[1, 2]) + validate_input_mock.return_value = basic_resource_template + new_cidr_mock.return_value = "1.2.3.4/24" + + workspace, _ = await workspace_repo.create_workspace_item(workspace_to_create, {}, "test_object_id", ["test_role"]) + + suffix = workspace.properties["unique_identifier_suffix"] + assert re.fullmatch(r"[a-z0-9]{12}", suffix) + assert mock_is_workspace_storage_account_available.call_count == 2 + assert mock_is_workspace_storage_account_available.call_args_list[-1].args[1] == suffix + assert mock_is_workspace_storage_account_available.call_args_list[0].args[1] != suffix + assert workspace.properties["workspace_id"] == workspace.id[-4:] + + +@pytest.mark.asyncio +@patch("db.repositories.workspaces.generate_new_cidr") +@patch("db.repositories.workspaces.WorkspaceRepository.validate_input_against_template") +@patch("db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available") +@patch("core.config.RESOURCE_LOCATION", "useast2") +@patch("core.config.TRE_ID", "9876") +async def test_create_workspace_item_v1_keeps_workspace_id_storage_naming( + mock_is_workspace_storage_account_available, + validate_input_mock, + new_cidr_mock, + workspace_repo, + basic_workspace_request, + basic_resource_template, +): + workspace_to_create = basic_workspace_request + workspace_to_create.properties["airlock_version"] = 1 + workspace_to_create.properties["unique_identifier_suffix"] = "userinput" + # first generated workspace id is taken, second is available + mock_is_workspace_storage_account_available.side_effect = [False, True] + validate_input_mock.return_value = basic_resource_template + new_cidr_mock.return_value = "1.2.3.4/24" + + workspace, _ = await workspace_repo.create_workspace_item(workspace_to_create, {}, "test_object_id", ["test_role"]) + + assert workspace.properties["airlock_version"] == 1 + assert workspace.properties["unique_identifier_suffix"] == "" + assert mock_is_workspace_storage_account_available.call_count == 2 + assert mock_is_workspace_storage_account_available.call_args_list[-1].args[1] == workspace.id[-4:] + + @pytest.mark.asyncio @patch("core.config.RESOURCE_LOCATION", "useast2") @patch("core.config.TRE_ID", "9876") @@ -486,8 +550,7 @@ def test_workspace_owner_is_not_overwritten_if_present_in_workspace_properties(w @pytest.mark.asyncio @patch("db.repositories.workspaces.StorageManagementClient") async def test_is_workspace_storage_account_available_when_name_available(mock_storage_client): - workspace_id = "workspace1234" - suffix = workspace_id[-4:] + suffix = "abc123def456" mock_storage_client_instance = MagicMock() mock_storage_client_instance.storage_accounts.check_name_availability = AsyncMock() mock_storage_client_instance.storage_accounts.check_name_availability.return_value.name_available = True @@ -495,7 +558,7 @@ async def test_is_workspace_storage_account_available_when_name_available(mock_s mock_storage_client.return_value = mock_storage_client_instance workspace_repo = WorkspaceRepository() - result = await workspace_repo.is_workspace_storage_account_available(MagicMock(), workspace_id) + result = await workspace_repo.is_workspace_storage_account_available(MagicMock(), suffix) assert result is True assert mock_storage_client_instance.storage_accounts.check_name_availability.call_count == 1 @@ -507,8 +570,7 @@ async def test_is_workspace_storage_account_available_when_name_available(mock_s @pytest.mark.asyncio @patch("db.repositories.workspaces.StorageManagementClient") async def test_is_workspace_storage_account_available_when_name_not_available(mock_storage_client): - workspace_id = "workspace1234" - suffix = workspace_id[-4:] + suffix = "abc123def456" mock_storage_client_instance = MagicMock() mock_storage_client_instance.storage_accounts.check_name_availability = AsyncMock() mock_storage_client_instance.close = AsyncMock() @@ -518,7 +580,7 @@ async def test_is_workspace_storage_account_available_when_name_not_available(mo mock_storage_client.return_value = mock_storage_client_instance workspace_repo = WorkspaceRepository() - result = await workspace_repo.is_workspace_storage_account_available(MagicMock(), workspace_id) + result = await workspace_repo.is_workspace_storage_account_available(MagicMock(), suffix) assert result is False assert mock_storage_client_instance.storage_accounts.check_name_availability.call_count == 1 @@ -530,7 +592,7 @@ async def test_is_workspace_storage_account_available_when_name_not_available(mo @pytest.mark.asyncio @patch("db.repositories.workspaces.StorageManagementClient") async def test_is_workspace_storage_account_available_when_check_raises_exception(mock_storage_client): - workspace_id = "workspace1234" + suffix = "abc123def456" mock_storage_client_instance = MagicMock() mock_storage_client_instance.storage_accounts.check_name_availability = AsyncMock() mock_storage_client_instance.storage_accounts.check_name_availability.side_effect = Exception("ARM error") @@ -539,7 +601,7 @@ async def test_is_workspace_storage_account_available_when_check_raises_exceptio workspace_repo = WorkspaceRepository() with pytest.raises(Exception, match="ARM error"): - await workspace_repo.is_workspace_storage_account_available(MagicMock(), workspace_id) + await workspace_repo.is_workspace_storage_account_available(MagicMock(), suffix) @pytest.mark.asyncio @@ -577,7 +639,7 @@ async def mock_wait_for_se(coro, timeout=None): @pytest.mark.asyncio @patch("db.repositories.workspaces.StorageManagementClient") async def test_is_workspace_storage_account_available_when_check_times_out(mock_storage_client): - workspace_id = "workspace1234" + suffix = "abc123def456" mock_storage_client_instance = MagicMock() mock_storage_client_instance.storage_accounts.check_name_availability = AsyncMock() mock_storage_client_instance.close = AsyncMock() @@ -586,7 +648,7 @@ async def test_is_workspace_storage_account_available_when_check_times_out(mock_ workspace_repo = WorkspaceRepository() with pytest.raises(asyncio.TimeoutError): - await workspace_repo.is_workspace_storage_account_available(MagicMock(), workspace_id) + await workspace_repo.is_workspace_storage_account_available(MagicMock(), suffix) assert mock_storage_client_instance.storage_accounts.check_name_availability.call_count == 1 diff --git a/docs/azure-tre-overview/tre-resources-breakdown.md b/docs/azure-tre-overview/tre-resources-breakdown.md index 3988cfe2d0..80aaf7b5c9 100644 --- a/docs/azure-tre-overview/tre-resources-breakdown.md +++ b/docs/azure-tre-overview/tre-resources-breakdown.md @@ -64,7 +64,7 @@ A TRE Workspace will be provisioned in a separate Resource Group along with its | kv-{TRE_ID}-ws-XXXX | Azure Key Vault | Management of TRE workspace secrets & certificates | [Azure Key Vault](https://docs.microsoft.com/en-us/azure/key-vault/general/overview) | | osdisk-windowsvm8f45 | Disk | Azure VM storage disk | [Managed Disks](https://docs.microsoft.com/en-us/azure/virtual-machines/managed-disks-overview) | | plan-09d0ba4f-f79f-4047-aa2c-03fc9df7b318 | App Service plan | Compute resources in which the workspace app services (Gitea) run | [App Hosting Plans](https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans) | -| stgwsb318 | Storage account | Workspace Storage account | [Storage Blobs](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blobs-overview) | +| stgwsb318 | Storage account | Workspace Storage account. Workspaces created with `airlock_version` 2 use a random suffix instead (e.g. `stgwsk3x9q2m7a1bz`) | [Storage Blobs](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blobs-overview) | | vnet-{TRE_ID}-ws-XXXX | Virtual Network | [Azure TRE VNET spoke](../networking) | [Virtual Networks](https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-overview) | | windowsvm8f45 | Virtual Machine | [Windows VM instance](../../tre-templates/user-resources/guacamole-windows-vm) for research | [Windows Virtual Machine](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/overview) | diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml index dfc9e326ff..65805928d4 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-service-guacamole-linuxvm -version: 1.4.8 +version: 1.5.0 description: "An Azure TRE User Resource Template for Guacamole (Linux)" dockerfile: Dockerfile.tmpl registry: azuretre @@ -55,6 +55,10 @@ credentials: parameters: - name: workspace_id type: string + - name: workspace_storage_name + type: string + default: "" + description: "Name of the parent workspace storage account, provided by the workspace storage_account_name output" - name: tre_id type: string - name: azure_environment @@ -170,6 +174,7 @@ install: description: "Deploy Guacamole User Resource Service (Linux VM)" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } parent_service_id: ${ bundle.parameters.parent_service_id } @@ -207,6 +212,7 @@ upgrade: description: "Update Guacamole User Resource Service (Linux VM)" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } parent_service_id: ${ bundle.parameters.parent_service_id } @@ -256,6 +262,7 @@ uninstall: description: "Delete the Guacamole User Resource Service" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } parent_service_id: ${ bundle.parameters.parent_service_id } diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json index b9d980d822..d60b83b4d4 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json @@ -248,5 +248,31 @@ "admin_username": { "classNames": "tre-hidden" } + }, + "pipeline": { + "install": [ + { + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.parent.properties.storage_account_name }}" + } + ] + } + ], + "upgrade": [ + { + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.parent.properties.storage_account_name }}" + } + ] + } + ] } } diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/locals.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/locals.tf index 75c6a70708..687ce2bd20 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/locals.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/locals.tf @@ -6,7 +6,7 @@ locals { service_resource_name_suffix = "${var.tre_id}-ws-${local.short_workspace_id}-svc-${local.short_service_id}" vm_name = "linuxvm${local.short_service_id}" keyvault_name = lower("kv-${substr(local.workspace_resource_name_suffix, -20, -1)}") - storage_name = lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) + storage_name = var.workspace_storage_name != "" ? var.workspace_storage_name : lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) admin_username = ( var.admin_username == "" ? (length(data.azuread_user.user[0].mail) > 0 && strcontains(data.azuread_user.user[0].user_principal_name, "#EXT#") ? diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/variables.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/variables.tf index 66eab5b7d6..5b4ecc6ec3 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/variables.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/terraform/variables.tf @@ -1,6 +1,11 @@ variable "workspace_id" { type = string } +variable "workspace_storage_name" { + type = string + default = "" + description = "Name of the parent workspace storage account. When empty, the legacy name derived from the workspace ID is used." +} variable "tre_id" { type = string } diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml index e7b2686f5c..ff824d3451 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-service-guacamole-windowsvm -version: 3.0.4 +version: 3.1.0 description: "An Azure TRE User Resource Template for Guacamole (Windows 11 or Windows Server 2025)" dockerfile: Dockerfile.tmpl registry: azuretre @@ -61,6 +61,10 @@ credentials: parameters: - name: workspace_id type: string + - name: workspace_storage_name + type: string + default: "" + description: "Name of the parent workspace storage account, provided by the workspace storage_account_name output" - name: tre_id type: string - name: parent_service_id @@ -190,6 +194,7 @@ install: description: "Deploy Guacamole User Resource Service (Windows VM)" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } parent_service_id: ${ bundle.parameters.parent_service_id } @@ -233,6 +238,7 @@ upgrade: description: "Update Guacamole User Resource Service (Windows VM)" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } parent_service_id: ${ bundle.parameters.parent_service_id } @@ -288,6 +294,7 @@ uninstall: description: "Delete the Guacamole User Resource Service" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } parent_service_id: ${ bundle.parameters.parent_service_id } diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json index a319bb0357..ed4c32a93c 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json @@ -282,5 +282,31 @@ "admin_username": { "classNames": "tre-hidden" } + }, + "pipeline": { + "install": [ + { + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.parent.properties.storage_account_name }}" + } + ] + } + ], + "upgrade": [ + { + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.parent.properties.storage_account_name }}" + } + ] + } + ] } } diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/locals.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/locals.tf index 2d4d619c90..41f9570a43 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/locals.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/locals.tf @@ -2,7 +2,7 @@ locals { short_workspace_id = substr(var.workspace_id, -4, -1) workspace_resource_name_suffix = "${var.tre_id}-ws-${local.short_workspace_id}" ws_resource_group_name = "rg-${var.tre_id}-ws-${local.short_workspace_id}" - storage_name = lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) + storage_name = var.workspace_storage_name != "" ? var.workspace_storage_name : lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) admin_username = ( var.admin_username == "" ? diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/variables.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/variables.tf index 2471fe009c..bc88f83395 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/variables.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/variables.tf @@ -1,6 +1,11 @@ variable "workspace_id" { type = string } +variable "workspace_storage_name" { + type = string + default = "" + description = "Name of the parent workspace storage account. When empty, the legacy name derived from the workspace ID is used." +} variable "tre_id" { type = string } diff --git a/templates/workspace_services/ohdsi/porter.yaml b/templates/workspace_services/ohdsi/porter.yaml index de2e88aba2..c8d6c976cd 100644 --- a/templates/workspace_services/ohdsi/porter.yaml +++ b/templates/workspace_services/ohdsi/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-workspace-service-ohdsi -version: 0.3.12 +version: 0.4.0 description: "An OHDSI workspace service" registry: azuretre dockerfile: Dockerfile.tmpl @@ -24,6 +24,10 @@ credentials: parameters: - name: workspace_id type: string + - name: workspace_storage_name + type: string + default: "" + description: "Name of the parent workspace storage account, provided by the workspace storage_account_name output" - name: tre_id type: string - name: address_space @@ -121,6 +125,7 @@ install: description: "Deploy OHDSI workspace service" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } tre_resource_id: ${ bundle.parameters.id } address_space: ${ bundle.parameters.address_space } @@ -174,6 +179,7 @@ upgrade: description: "Upgrade shared service" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } tre_resource_id: ${ bundle.parameters.id } address_space: ${ bundle.parameters.address_space } @@ -198,6 +204,7 @@ uninstall: description: "Tear down OHDSI workspace service" vars: workspace_id: ${ bundle.parameters.workspace_id } + workspace_storage_name: ${ bundle.parameters.workspace_storage_name } tre_id: ${ bundle.parameters.tre_id } tre_resource_id: ${ bundle.parameters.id } address_space: ${ bundle.parameters.address_space } diff --git a/templates/workspace_services/ohdsi/template_schema.json b/templates/workspace_services/ohdsi/template_schema.json index 0794edb119..17c758c94e 100644 --- a/templates/workspace_services/ohdsi/template_schema.json +++ b/templates/workspace_services/ohdsi/template_schema.json @@ -155,7 +155,14 @@ "properties": [] }, { - "stepId": "main" + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.properties.storage_account_name }}" + } + ] }, { "stepId": "7276dcc1-7d0e-496a-badf-87c8c25fc06e", @@ -257,7 +264,14 @@ "properties": [] }, { - "stepId": "main" + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.properties.storage_account_name }}" + } + ] }, { "stepId": "0d3961fd-1538-4b0e-a6ed-bf401b65c034", @@ -369,7 +383,14 @@ ] }, { - "stepId": "main" + "stepId": "main", + "properties": [ + { + "name": "workspace_storage_name", + "type": "string", + "value": "{{ resource.parent.properties.storage_account_name }}" + } + ] } ] } diff --git a/templates/workspace_services/ohdsi/terraform/locals.tf b/templates/workspace_services/ohdsi/terraform/locals.tf index 0d13412ee3..1e3e3e96e6 100644 --- a/templates/workspace_services/ohdsi/terraform/locals.tf +++ b/templates/workspace_services/ohdsi/terraform/locals.tf @@ -5,7 +5,7 @@ locals { core_resource_group_name = "rg-${var.tre_id}" service_suffix = "${local.workspace_resource_name_suffix}-svc-${local.short_service_id}" key_vault_name = lower("kv-${substr(local.workspace_resource_name_suffix, -20, -1)}") - storage_name = lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) + storage_name = var.workspace_storage_name != "" ? var.workspace_storage_name : lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) porter_yaml = yamldecode(file("${path.module}/../porter.yaml")) # ATLAS Database diff --git a/templates/workspace_services/ohdsi/terraform/variables.tf b/templates/workspace_services/ohdsi/terraform/variables.tf index fd78e18be0..aa787c4365 100644 --- a/templates/workspace_services/ohdsi/terraform/variables.tf +++ b/templates/workspace_services/ohdsi/terraform/variables.tf @@ -1,6 +1,11 @@ variable "workspace_id" { type = string } +variable "workspace_storage_name" { + type = string + default = "" + description = "Name of the parent workspace storage account. When empty, the legacy name derived from the workspace ID is used." +} variable "tre_id" { type = string } diff --git a/templates/workspaces/airlock-import-review/porter.yaml b/templates/workspaces/airlock-import-review/porter.yaml index 1b0380bf70..a91f3c85c2 100644 --- a/templates/workspaces/airlock-import-review/porter.yaml +++ b/templates/workspaces/airlock-import-review/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-workspace-airlock-import-review -version: 0.18.1 +version: 0.18.2 description: "A workspace to do Airlock Data Import Reviews for Azure TRE" dockerfile: Dockerfile.tmpl registry: azuretre diff --git a/templates/workspaces/base/porter.yaml b/templates/workspaces/base/porter.yaml index d704c94bcf..3d387c2ab9 100644 --- a/templates/workspaces/base/porter.yaml +++ b/templates/workspaces/base/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-workspace-base -version: 2.12.2 +version: 2.13.0 description: "A base Azure TRE workspace" dockerfile: Dockerfile.tmpl registry: azuretre @@ -33,6 +33,10 @@ parameters: - name: id type: string description: "the resource ID for this installation" + - name: unique_identifier_suffix + type: string + default: "" + description: "Random suffix used to name the workspace storage account of airlock_version 2 workspaces. Set by the API at creation." - name: azure_environment type: string default: "AzureCloud" @@ -247,6 +251,11 @@ outputs: applyTo: - install - upgrade + - name: storage_account_name + type: string + applyTo: + - install + - upgrade mixins: - exec @@ -261,6 +270,7 @@ install: vars: tre_id: ${ bundle.parameters.tre_id } tre_resource_id: ${ bundle.parameters.id } + unique_identifier_suffix: ${ bundle.parameters.unique_identifier_suffix } location: ${ bundle.parameters.azure_location } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } address_spaces: ${ bundle.parameters.address_spaces } @@ -316,6 +326,7 @@ install: - name: workspace_researchers_group_id - name: workspace_airlock_managers_group_id - name: airlock_signer_client_id + - name: storage_account_name upgrade: - terraform: @@ -323,6 +334,7 @@ upgrade: vars: tre_id: ${ bundle.parameters.tre_id } tre_resource_id: ${ bundle.parameters.id } + unique_identifier_suffix: ${ bundle.parameters.unique_identifier_suffix } location: ${ bundle.parameters.azure_location } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } address_spaces: ${ bundle.parameters.address_spaces } @@ -378,6 +390,7 @@ upgrade: - name: workspace_researchers_group_id - name: workspace_airlock_managers_group_id - name: airlock_signer_client_id + - name: storage_account_name - az: description: "Set Azure Cloud Environment" arguments: @@ -424,6 +437,7 @@ uninstall: vars: tre_id: ${ bundle.parameters.tre_id } tre_resource_id: ${ bundle.parameters.id } + unique_identifier_suffix: ${ bundle.parameters.unique_identifier_suffix } location: ${ bundle.parameters.azure_location } workspace_subscription_id: ${ bundle.parameters.workspace_subscription_id } address_spaces: ${ bundle.parameters.address_spaces } diff --git a/templates/workspaces/base/terraform/locals.tf b/templates/workspaces/base/terraform/locals.tf index 913a8546fa..6d5626573c 100644 --- a/templates/workspaces/base/terraform/locals.tf +++ b/templates/workspaces/base/terraform/locals.tf @@ -1,7 +1,7 @@ locals { short_workspace_id = substr(var.tre_resource_id, -4, -1) workspace_resource_name_suffix = "${var.tre_id}-ws-${local.short_workspace_id}" - storage_name = lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) + storage_name = var.unique_identifier_suffix != "" ? "stgws${var.unique_identifier_suffix}" : lower(replace("stg${substr(local.workspace_resource_name_suffix, -8, -1)}", "-", "")) keyvault_name = lower("kv-${substr(local.workspace_resource_name_suffix, -20, -1)}") redacted_senstive_value = "REDACTED" tre_workspace_tags = { diff --git a/templates/workspaces/base/terraform/outputs.tf b/templates/workspaces/base/terraform/outputs.tf index e9fc89e75b..dbee5e3108 100644 --- a/templates/workspaces/base/terraform/outputs.tf +++ b/templates/workspaces/base/terraform/outputs.tf @@ -2,6 +2,10 @@ output "workspace_resource_name_suffix" { value = local.workspace_resource_name_suffix } +output "storage_account_name" { + value = azurerm_storage_account.stg.name +} + # The following outputs are dependent on an Automatic AAD Workspace Application Registration. # If we are not creating an App Reg we simple pass back the same values that were already created # This is necessary so that we don't delete workspace properties diff --git a/templates/workspaces/base/terraform/variables.tf b/templates/workspaces/base/terraform/variables.tf index 3ddf8395bb..40d8f23187 100644 --- a/templates/workspaces/base/terraform/variables.tf +++ b/templates/workspaces/base/terraform/variables.tf @@ -8,6 +8,17 @@ variable "tre_resource_id" { description = "Resource ID" } +variable "unique_identifier_suffix" { + type = string + description = "Random suffix used to name the workspace storage account of airlock_version 2 workspaces. When empty, the legacy name derived from the last 4 characters of the resource ID is used." + default = "" + + validation { + condition = can(regex("^[a-z0-9]{0,19}$", var.unique_identifier_suffix)) + error_message = "unique_identifier_suffix must be up to 19 lowercase letters or digits." + } +} + variable "workspace_subscription_id" { type = string description = "Subscription ID for the workspace resources" diff --git a/templates/workspaces/unrestricted/porter.yaml b/templates/workspaces/unrestricted/porter.yaml index 3813a3ec5a..5f37520600 100644 --- a/templates/workspaces/unrestricted/porter.yaml +++ b/templates/workspaces/unrestricted/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-workspace-unrestricted -version: 0.15.1 +version: 0.15.2 description: "A base Azure TRE workspace" dockerfile: Dockerfile.tmpl registry: azuretre From a0b9050125cc46a1aafbcb0aae9c5b3d6669e54f Mon Sep 17 00:00:00 2001 From: Marcus Robinson Date: Fri, 9 Oct 2026 11:11:15 +0000 Subject: [PATCH 2/4] Remove workspace backup lock from the suffix-named storage account remove_backup.sh derived the storage account name from the last four characters of the workspace ID. Workspaces that use unique_identifier_suffix name the account stgws{suffix}, so the lock was never found and could block the Terraform destroy. Pass the suffix to the script and fall back to the legacy name when it is empty. Refs #2893 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- templates/workspaces/base/porter.yaml | 1 + templates/workspaces/base/remove_backup.sh | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/workspaces/base/porter.yaml b/templates/workspaces/base/porter.yaml index 3d387c2ab9..03c8a8ff05 100644 --- a/templates/workspaces/base/porter.yaml +++ b/templates/workspaces/base/porter.yaml @@ -429,6 +429,7 @@ uninstall: - ${ bundle.parameters.enable_backup } - ${ bundle.parameters.delete_backups_on_uninstall } - ${ bundle.parameters.workspace_subscription_id } + - ${ bundle.parameters.unique_identifier_suffix } envs: ARM_USE_AZUREAD: "true" ARM_USE_OIDC: "true" diff --git a/templates/workspaces/base/remove_backup.sh b/templates/workspaces/base/remove_backup.sh index 5e08cc041b..8f3b80113b 100755 --- a/templates/workspaces/base/remove_backup.sh +++ b/templates/workspaces/base/remove_backup.sh @@ -24,6 +24,7 @@ WORKSPACE_ID=$5 ENABLE_BACKUP=$6 DELETE_BACKUPS=$7 WORKSPACE_SUBSCRIPTION_ID=${8:-} +UNIQUE_IDENTIFIER_SUFFIX=${9:-} ENABLE_BACKUP=$(echo "${ENABLE_BACKUP}" | tr '[:upper:]' '[:lower:]') DELETE_BACKUPS=$(echo "${DELETE_BACKUPS}" | tr '[:upper:]' '[:lower:]') @@ -109,7 +110,13 @@ done # directly to the account are removed; the scope match is case-insensitive because # Azure lower-cases segments of the lock id. subscription_id=$(az account show --query "id" --output tsv) -storage_account_id="/subscriptions/${subscription_id}/resourceGroups/${vault_resource_group}/providers/Microsoft.Storage/storageAccounts/stgws${short_workspace_id}" +# Matches the name Terraform derives: the unique suffix when set, else the legacy last-four of the id. +if [ -n "${UNIQUE_IDENTIFIER_SUFFIX}" ]; then + storage_account_name="stgws${UNIQUE_IDENTIFIER_SUFFIX}" +else + storage_account_name="stgws${short_workspace_id}" +fi +storage_account_id="/subscriptions/${subscription_id}/resourceGroups/${vault_resource_group}/providers/Microsoft.Storage/storageAccounts/${storage_account_name}" storage_account_id_lower=$(echo "${storage_account_id}" | tr '[:upper:]' '[:lower:]') if ! lock_ids=$(az lock list --resource "${storage_account_id}" --query "[].id" --output tsv); then echo "Error: failed to list resource locks on the workspace storage account. Aborting so the uninstall can be retried." >&2 From 389a361aa8e822b1ed9b261c4d89591f28e62e17 Mon Sep 17 00:00:00 2001 From: Marcus Robinson Date: Fri, 9 Oct 2026 11:25:30 +0000 Subject: [PATCH 3/4] Gate storage suffix on templates that consume it and declare pipeline properties Only generate a random unique_identifier_suffix when the template declares it, so airlock v2-capable templates that still use legacy naming do not store a suffix the bundle ignores. Declare the unique_identifier_suffix and workspace_storage_name properties in the affected template schemas so the API accepts them. Refs #3666 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- api_app/db/repositories/workspaces.py | 10 +++++-- .../test_workpaces_repository.py | 29 +++++++++++++++++++ .../template_schema.json | 7 +++++ .../template_schema.json | 7 +++++ .../ohdsi/template_schema.json | 7 +++++ .../workspaces/base/template_schema.json | 6 ++++ 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/api_app/db/repositories/workspaces.py b/api_app/db/repositories/workspaces.py index d5bff3ae6f..1dea872f85 100644 --- a/api_app/db/repositories/workspaces.py +++ b/api_app/db/repositories/workspaces.py @@ -170,9 +170,13 @@ async def create_workspace_item( airlock_version = 1 airlock_version_param = {"airlock_version": airlock_version} - full_workspace_id, unique_identifier_suffix = await self.generate_workspace_storage_naming(airlock_version) - # Only airlock_version >= 2 workspaces use the random suffix for storage account naming. The - # suffix is set once at creation, so legacy workspaces keep their names even after moving to v2. + # Only templates that consume unique_identifier_suffix get a random storage account name. Older + # airlock v2-capable templates keep the legacy naming, so no suffix is stored that the bundle would ignore. + supports_storage_suffix = "unique_identifier_suffix" in template.properties + full_workspace_id, unique_identifier_suffix = await self.generate_workspace_storage_naming( + airlock_version if supports_storage_suffix else 1 + ) + # The suffix is set once at creation, so legacy workspaces keep their names even after moving to v2. unique_identifier_suffix_param = {"unique_identifier_suffix": unique_identifier_suffix} # JSON Schema defaults validate input but are not materialised by the API. Persist the diff --git a/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py b/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py index 1c8213a410..b14dc02ffa 100644 --- a/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py +++ b/api_app/tests_ma/test_db/test_repositories/test_workpaces_repository.py @@ -313,6 +313,8 @@ async def test_create_workspace_item_v2_uses_available_random_storage_suffix( # first generated suffix is taken, second is available mock_is_workspace_storage_account_available.side_effect = [False, True] basic_resource_template.properties["airlock_version"] = Property(default=2, enum=[1, 2]) + # the template must declare the suffix to consume it + basic_resource_template.properties["unique_identifier_suffix"] = Property(type="string") validate_input_mock.return_value = basic_resource_template new_cidr_mock.return_value = "1.2.3.4/24" @@ -326,6 +328,33 @@ async def test_create_workspace_item_v2_uses_available_random_storage_suffix( assert workspace.properties["workspace_id"] == workspace.id[-4:] +@pytest.mark.asyncio +@patch("db.repositories.workspaces.generate_new_cidr") +@patch("db.repositories.workspaces.WorkspaceRepository.validate_input_against_template") +@patch("db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available") +@patch("core.config.RESOURCE_LOCATION", "useast2") +@patch("core.config.TRE_ID", "9876") +async def test_create_workspace_item_v2_template_without_suffix_keeps_legacy_storage_naming( + mock_is_workspace_storage_account_available, + validate_input_mock, + new_cidr_mock, + workspace_repo, + basic_workspace_request, + basic_resource_template, +): + workspace_to_create = basic_workspace_request + workspace_to_create.properties["airlock_version"] = 2 + mock_is_workspace_storage_account_available.return_value = True + basic_resource_template.properties["airlock_version"] = Property(default=2, enum=[1, 2]) + validate_input_mock.return_value = basic_resource_template + new_cidr_mock.return_value = "1.2.3.4/24" + + workspace, _ = await workspace_repo.create_workspace_item(workspace_to_create, {}, "test_object_id", ["test_role"]) + + assert workspace.properties["unique_identifier_suffix"] == "" + assert mock_is_workspace_storage_account_available.call_args.args[1] == workspace.id[-4:] + + @pytest.mark.asyncio @patch("db.repositories.workspaces.generate_new_cidr") @patch("db.repositories.workspaces.WorkspaceRepository.validate_input_against_template") diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json index d60b83b4d4..ecbe99b677 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-linuxvm/template_schema.json @@ -13,6 +13,13 @@ "WorkspaceResearcher" ], "properties": { + "workspace_storage_name": { + "type": "string", + "title": "Workspace storage account name", + "description": "Set by the pipeline from the parent workspace storage account.", + "readOnly": true, + "updateable": true + }, "display_name": { "type": "string", "title": "Display name for the VM", diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json index ed4c32a93c..586681a05f 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/template_schema.json @@ -10,6 +10,13 @@ "WorkspaceResearcher" ], "properties": { + "workspace_storage_name": { + "type": "string", + "title": "Workspace storage account name", + "description": "Set by the pipeline from the parent workspace storage account.", + "readOnly": true, + "updateable": true + }, "display_name": { "type": "string", "title": "Display name for the VM", diff --git a/templates/workspace_services/ohdsi/template_schema.json b/templates/workspace_services/ohdsi/template_schema.json index 17c758c94e..a54b8f5d5b 100644 --- a/templates/workspace_services/ohdsi/template_schema.json +++ b/templates/workspace_services/ohdsi/template_schema.json @@ -6,6 +6,13 @@ "description": "Provides OHDSI within the workspace", "required": [], "properties": { + "workspace_storage_name": { + "type": "string", + "title": "Workspace storage account name", + "description": "Set by the pipeline from the parent workspace storage account.", + "readOnly": true, + "updateable": true + }, "display_name": { "type": "string", "title": "Name for the workspace service", diff --git a/templates/workspaces/base/template_schema.json b/templates/workspaces/base/template_schema.json index 26f312a88e..9e4aae7c6a 100644 --- a/templates/workspaces/base/template_schema.json +++ b/templates/workspaces/base/template_schema.json @@ -33,6 +33,12 @@ ], "updateable": true }, + "unique_identifier_suffix": { + "type": "string", + "title": "Unique identifier suffix", + "description": "Random suffix used to name the workspace storage account. Set by the API at creation and not user-editable.", + "readOnly": true + }, "app_service_plan_sku": { "type": "string", "title": "App Service Plan SKU", From 2c3f55498f71f8d4b63d6dcfaab15b7dec9494cd Mon Sep 17 00:00:00 2001 From: Marcus Robinson Date: Fri, 9 Oct 2026 16:36:07 +0000 Subject: [PATCH 4/4] Fix workspace uninstall backup-lock removal found in live testing (#2893) - Pass unique_identifier_suffix to remove_backup.sh as an environment variable. The Porter exec mixin drops empty arguments, so an empty workspace_subscription_id shifted the suffix into its position and the uninstall failed with an unknown subscription error. - Skip lock removal when the workspace storage account no longer exists, so an uninstall retried after a partial destroy can complete. - Bump tre-workspace-base to 2.13.2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 +- templates/workspaces/base/porter.yaml | 5 +++-- templates/workspaces/base/remove_backup.sh | 19 +++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae3754c8e4..22b2c2e9c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,7 @@ BUG FIXES: * Allow up to 30 checks at ten-second intervals when enabling or disabling storage public access during deployment. (`devops` 0.6.10) ([#5113](https://github.com/microsoft/AzureTRE/pull/5113)) * Name the workspace storage account of new `airlock_version` 2 workspaces from a random 12-character suffix (`stgws{suffix}`) checked for availability before creation, instead of the last 4 characters of the workspace ID, to prevent `StorageAccountAlreadyTaken` deployment failures. Legacy (v1) workspaces, including those later moved to v2, keep their existing names. The workspace exposes `storage_account_name`, which OHDSI and Guacamole VMs now use. - (`API` 0.28.3, `tre-workspace-base` 2.13.0, `tre-workspace-unrestricted` 0.15.2, `tre-workspace-airlock-import-review` 0.18.2, `tre-workspace-service-ohdsi` 0.4.0, `tre-service-guacamole-linuxvm` 1.5.0, `tre-service-guacamole-windowsvm` 3.1.0) ([#2893](https://github.com/microsoft/AzureTRE/issues/2893), [#3666](https://github.com/microsoft/AzureTRE/issues/3666)) + (`API` 0.28.3, `tre-workspace-base` 2.13.2, `tre-workspace-unrestricted` 0.15.2, `tre-workspace-airlock-import-review` 0.18.2, `tre-workspace-service-ohdsi` 0.4.0, `tre-service-guacamole-linuxvm` 1.5.0, `tre-service-guacamole-windowsvm` 3.1.0) ([#2893](https://github.com/microsoft/AzureTRE/issues/2893), [#3666](https://github.com/microsoft/AzureTRE/issues/3666)) * Include Azure cloud and location in isolated CI environment names to avoid retained Key Vault name conflicts after region changes. Find previous CI environments by ownership tags during explicit cleanup. (`devops` 0.6.9) ([#5106](https://github.com/microsoft/AzureTRE/issues/5106)) * Validate Certbot before `make letsencrypt` prepares Azure access, check the resource group after loading Terraform outputs, and disable optional Super-Linter publishing with read-only GitHub tokens. ([#5110](https://github.com/microsoft/AzureTRE/pull/5110)) * Preserve loaded UI views during background refresh, ignore stale workspace responses, refresh on every tab return, and keep internal Connect behavior and unavailable cost displays consistent. (`ui` 0.10.1) ([#5105](https://github.com/microsoft/AzureTRE/pull/5105)) diff --git a/templates/workspaces/base/porter.yaml b/templates/workspaces/base/porter.yaml index 03c8a8ff05..80dc425fc4 100644 --- a/templates/workspaces/base/porter.yaml +++ b/templates/workspaces/base/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-workspace-base -version: 2.13.0 +version: 2.13.2 description: "A base Azure TRE workspace" dockerfile: Dockerfile.tmpl registry: azuretre @@ -429,10 +429,11 @@ uninstall: - ${ bundle.parameters.enable_backup } - ${ bundle.parameters.delete_backups_on_uninstall } - ${ bundle.parameters.workspace_subscription_id } - - ${ bundle.parameters.unique_identifier_suffix } envs: ARM_USE_AZUREAD: "true" ARM_USE_OIDC: "true" + # An env var, not an argument: the exec mixin drops empty arguments, which would shift positions. + UNIQUE_IDENTIFIER_SUFFIX: "${ bundle.parameters.unique_identifier_suffix }" - terraform: description: "Tear down workspace" vars: diff --git a/templates/workspaces/base/remove_backup.sh b/templates/workspaces/base/remove_backup.sh index 8f3b80113b..dd57e839be 100755 --- a/templates/workspaces/base/remove_backup.sh +++ b/templates/workspaces/base/remove_backup.sh @@ -24,7 +24,7 @@ WORKSPACE_ID=$5 ENABLE_BACKUP=$6 DELETE_BACKUPS=$7 WORKSPACE_SUBSCRIPTION_ID=${8:-} -UNIQUE_IDENTIFIER_SUFFIX=${9:-} +UNIQUE_IDENTIFIER_SUFFIX=${UNIQUE_IDENTIFIER_SUFFIX:-} ENABLE_BACKUP=$(echo "${ENABLE_BACKUP}" | tr '[:upper:]' '[:lower:]') DELETE_BACKUPS=$(echo "${DELETE_BACKUPS}" | tr '[:upper:]' '[:lower:]') @@ -118,10 +118,21 @@ else fi storage_account_id="/subscriptions/${subscription_id}/resourceGroups/${vault_resource_group}/providers/Microsoft.Storage/storageAccounts/${storage_account_name}" storage_account_id_lower=$(echo "${storage_account_id}" | tr '[:upper:]' '[:lower:]') -if ! lock_ids=$(az lock list --resource "${storage_account_id}" --query "[].id" --output tsv); then - echo "Error: failed to list resource locks on the workspace storage account. Aborting so the uninstall can be retried." >&2 - exit 1 +lock_ids="" +lock_error_file=$(mktemp) +if ! lock_ids=$(az lock list --resource "${storage_account_id}" --query "[].id" --output tsv 2> "${lock_error_file}"); then + if grep -q "ResourceNotFound" "${lock_error_file}"; then + # A previous uninstall attempt may already have destroyed the account. + echo "Workspace storage account ${storage_account_name} not found, skipping lock removal." + lock_ids="" + else + cat "${lock_error_file}" >&2 + rm -f "${lock_error_file}" + echo "Error: failed to list resource locks on the workspace storage account. Aborting so the uninstall can be retried." >&2 + exit 1 + fi fi +rm -f "${lock_error_file}" while IFS= read -r lock_id; do [ -z "${lock_id}" ] && continue case "$(echo "${lock_id}" | tr '[:upper:]' '[:lower:]')" in