Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User username as VM username rather than random ID #3770

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions api_app/models/domain/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class User(BaseModel):
id: str
name: str
email: str
username: str
roles: List[str] = Field([])
roleAssignments: List[RoleAssignment] = Field([])
4 changes: 4 additions & 0 deletions api_app/models/domain/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def get_resource_request_message_payload(self, operation_id: str, step_id: str,
"operationId": operation_id,
"stepId": step_id,
"action": action,
"user_id": self.user.id,
"user_name": self.user.name,
"user_email": self.user.email,
"user_username": self.user.username,
"id": self.id,
"name": self.templateName,
"version": self.templateVersion,
Expand Down
1 change: 1 addition & 0 deletions api_app/services/aad_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def _get_user_from_token(decoded_token: dict) -> User:
return User(id=user_id,
name=decoded_token.get('name', ''),
email=decoded_token.get('email', ''),
username=decoded_token.get('preferred_username', ''),
roles=decoded_token.get('roles', []))

def _decode_token(self, token: str, ws_app_reg_id: str) -> dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
schemaVersion: 1.0.0
name: tre-service-guacamole-windowsvm
version: 0.7.9
version: 0.8.4
description: "An Azure TRE User Resource Template for Guacamole (Windows 10)"
dockerfile: Dockerfile.tmpl
registry: azuretre
Expand Down Expand Up @@ -98,6 +98,14 @@ parameters:
- name: shared_storage_name
type: string
default: "vm-shared-storage"
- name: user_id
type: string
- name: user_name
type: string
- name: user_email
type: string
- name: user_username
type: string
- name: arm_environment
type: string

Expand Down Expand Up @@ -145,6 +153,10 @@ install:
shared_storage_access: ${ bundle.parameters.shared_storage_access }
shared_storage_name: ${ bundle.parameters.shared_storage_name }
image_gallery_id: ${ bundle.parameters.image_gallery_id }
user_id: ${ bundle.parameters.user_id }
user_name: ${ bundle.parameters.user_name }
user_email: ${ bundle.parameters.user_email }
user_username: ${ bundle.parameters.user_username }
backendConfig:
resource_group_name: ${ bundle.parameters.tfstate_resource_group_name }
storage_account_name: ${ bundle.parameters.tfstate_storage_account_name }
Expand All @@ -169,6 +181,10 @@ upgrade:
shared_storage_access: ${ bundle.parameters.shared_storage_access }
shared_storage_name: ${ bundle.parameters.shared_storage_name }
image_gallery_id: ${ bundle.parameters.image_gallery_id }
user_id: ${ bundle.parameters.user_id }
user_name: ${ bundle.parameters.user_name }
user_email: ${ bundle.parameters.user_email }
user_username: ${ bundle.parameters.user_username }
backendConfig:
resource_group_name: ${ bundle.parameters.tfstate_resource_group_name }
storage_account_name: ${ bundle.parameters.tfstate_storage_account_name }
Expand Down Expand Up @@ -202,6 +218,10 @@ uninstall:
shared_storage_access: ${ bundle.parameters.shared_storage_access }
shared_storage_name: ${ bundle.parameters.shared_storage_name }
image_gallery_id: ${ bundle.parameters.image_gallery_id }
user_id: ${ bundle.parameters.user_id }
user_name: ${ bundle.parameters.user_name }
user_email: ${ bundle.parameters.user_email }
user_username: ${ bundle.parameters.user_username }
backendConfig:
resource_group_name: ${ bundle.parameters.tfstate_resource_group_name }
storage_account_name: ${ bundle.parameters.tfstate_storage_account_name }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ locals {
vm_name = "windowsvm${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)}", "-", ""))
admin_username = element(split("@", var.user_username), 0)
vm_password_secret_name = "${local.vm_name}-admin-credentials"
tre_user_resources_tags = {
tre_id = var.tre_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ output "connection_uri" {
}

output "vm_username" {
value = random_string.username.result
value = local.admin_username
}

output "vm_password_secret_name" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ variable "image_gallery_id" {
type = string
default = ""
}

variable "user_id" {
type = string
}

variable "user_name" {
type = string
}

variable "user_email" {
type = string
}

variable "user_username" {
type = string
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ resource "azurerm_network_interface" "internal" {
lifecycle { ignore_changes = [tags] }
}

resource "random_string" "username" {
length = 4
upper = true
lower = true
numeric = true
min_numeric = 1
min_lower = 1
special = false
}

resource "random_password" "password" {
length = 16
lower = true
Expand All @@ -43,7 +33,7 @@ resource "azurerm_windows_virtual_machine" "windowsvm" {
network_interface_ids = [azurerm_network_interface.internal.id]
size = local.vm_sizes[var.vm_size]
allow_extension_operations = true
admin_username = random_string.username.result
admin_username = local.admin_username
admin_password = random_password.password.result

custom_data = base64encode(templatefile(
Expand Down Expand Up @@ -104,7 +94,7 @@ PROT

resource "azurerm_key_vault_secret" "windowsvm_password" {
name = "${local.vm_name}-admin-credentials"
value = "${random_string.username.result}\n${random_password.password.result}"
value = "${local.admin_username}\n${random_password.password.result}"
key_vault_id = data.azurerm_key_vault.ws.id
tags = local.tre_user_resources_tags

Expand Down
Loading