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

Regular maintenance updates for Linux VMs #1885

Merged
merged 33 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4beb403
Skeleton of sre maintenance component
craddm May 10, 2024
24b1b59
add azure_native maintenance typings
craddm May 10, 2024
d089519
Add standard maintenance configuration for linux vms
craddm May 10, 2024
a2c4a7a
Merge branch 'alan-turing-institute:develop' into maintenance-updates
craddm May 10, 2024
1404417
Correction of comment before SREMaintenanceComp
craddm May 10, 2024
1976928
Change vm patch_mode to work with maintenance config
craddm May 10, 2024
016828d
Merge branch 'alan-turing-institute:develop' into maintenance-updates
craddm May 13, 2024
8084492
Update automatic patch settings on VMs
craddm May 13, 2024
bf32481
Import and deploy maintenance config elements in workspaces
craddm May 13, 2024
8cfd2a1
Assign vm to maintenance configuration during deployment
craddm May 13, 2024
febcc02
output maintenance config id
craddm May 13, 2024
c577a73
No longer deploy maintenance at the SRE level
craddm May 13, 2024
f1ddfc7
rename to component variable to maintenance configuration
craddm May 13, 2024
0306cde
fix linting error
craddm May 13, 2024
1bb26f8
Create maintenance config in workspace RG
craddm May 14, 2024
0028eb4
Merge branch 'alan-turing-institute:develop' into maintenance-updates
craddm May 14, 2024
84099fa
Unique test filename for each workspace
craddm May 14, 2024
c584cde
Remove unneeded imports and variables
craddm May 14, 2024
2d05271
Unique name for each config assignment
craddm May 14, 2024
16b73e9
Use enumerate for vm indices
craddm May 14, 2024
e84fa40
remove unneeded variable
craddm May 14, 2024
b835aff
Remove manual increment of index
craddm May 14, 2024
3cc631c
remove SRE level monitoring component
craddm May 15, 2024
23fc03d
Update data_safe_haven/infrastructure/components/composite/virtual_ma…
JimMadge May 15, 2024
48690ad
Update data_safe_haven/infrastructure/components/composite/virtual_ma…
JimMadge May 15, 2024
7e37269
Update data_safe_haven/infrastructure/components/composite/virtual_ma…
JimMadge May 15, 2024
9513f37
Merge branch 'alan-turing-institute:develop' into maintenance-updates
craddm May 15, 2024
7972a86
Merge branch 'develop' into maintenance-updates
jemrobinson May 16, 2024
791293c
:truck: Move SREMaintenanceComponent creation to declarative_sre.py
jemrobinson May 16, 2024
13f6d98
:sparkles: Add 'iso_minute' option to next_occurrence
jemrobinson May 16, 2024
a1624b0
:wrench: Run maintenance configuration at 02:04 local time
jemrobinson May 16, 2024
fec84cb
:loud_sound: Add comment explaining 03:55 duration
jemrobinson May 16, 2024
c5bb258
:coffin: Removed unused shm-monitoring options passed to SRE
jemrobinson May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any

from pulumi import ComponentResource, Input, Output, ResourceOptions
from pulumi_azure_native import compute, network
from pulumi_azure_native import compute, maintenance, network

from data_safe_haven.functions import replace_separators
from data_safe_haven.infrastructure.components.wrapped import (
Expand Down Expand Up @@ -36,13 +36,15 @@ def __init__(
log_analytics_workspace: Input[WrappedLogAnalyticsWorkspace] | None = None,
log_analytics_workspace_id: Input[str] | None = None,
log_analytics_workspace_key: Input[str] | None = None,
maintenance_configuration_id: Input[str] | None = None,
) -> None:
self.admin_password = admin_password
self.admin_username = admin_username if admin_username else "dshvmadmin"
self.image_reference_args = None
self.ip_address_private = ip_address_private
self.ip_address_public = ip_address_public
self.location = location
self.maintenance_configuration_id = maintenance_configuration_id
if log_analytics_workspace:
self.log_analytics_workspace_id = Output.from_input(
log_analytics_workspace
Expand Down Expand Up @@ -140,6 +142,11 @@ def __init__(
linux_configuration=compute.LinuxConfigurationArgs(
patch_settings=compute.LinuxPatchSettingsArgs(
assessment_mode=compute.LinuxPatchAssessmentMode.AUTOMATIC_BY_PLATFORM,
patch_mode=compute.LinuxVMGuestPatchMode.AUTOMATIC_BY_PLATFORM,
automatic_by_platform_settings=compute.LinuxVMGuestPatchAutomaticByPlatformSettingsArgs(
bypass_platform_safety_checks_on_user_schedule=True,
reboot_setting=compute.LinuxVMGuestPatchAutomaticByPlatformRebootSetting.IF_REQUIRED,
),
),
provision_vm_agent=True,
),
Expand Down Expand Up @@ -276,6 +283,17 @@ def __init__(
tags=child_tags,
)

# Add VM to maintenance configuration
JimMadge marked this conversation as resolved.
Show resolved Hide resolved
self.configuration_assignment_resource = maintenance.ConfigurationAssignment(
f"{name_underscored}_configurationAssignment",
provider_name="Microsoft.Compute",
resource_group_name=props.resource_group_name,
resource_name_=virtual_machine.name,
resource_type="VirtualMachines",
location=props.location,
maintenance_configuration_id=props.maintenance_configuration_id,
JimMadge marked this conversation as resolved.
Show resolved Hide resolved
)
JimMadge marked this conversation as resolved.
Show resolved Hide resolved

# Register outputs
self.ip_address_private: Output[str] = Output.from_input(
props.ip_address_private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def __call__(self) -> None:

# Deploy backup service
SREBackupComponent(
"sre_user_services",
"sre_backup",
self.stack_name,
SREBackupProps(
location=self.context.location,
Expand Down
58 changes: 58 additions & 0 deletions data_safe_haven/infrastructure/programs/sre/maintenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Pulumi component for SRE Maintenance"""

from collections.abc import Mapping

from pulumi import ComponentResource, Input, Output, ResourceOptions
from pulumi_azure_native import maintenance


class SREMaintenanceProps:
"""Properties for SREMaintenanceComponent"""

def __init__(
self,
location: Input[str],
resource_group_name: Input[str],
) -> None:
self.location = location
self.resource_group_name = resource_group_name


class SREMaintenanceComponent(ComponentResource):
"""Deploy SRE maintenance with Pulumi"""

def __init__(
self,
name: str,
stack_name: str,
props: SREMaintenanceProps,
opts: ResourceOptions | None = None,
tags: Input[Mapping[str, Input[str]]] | None = None,
) -> None:
super().__init__("dsh:sre:MaintenanceComponent", name, {}, opts)
child_tags = tags if tags else {}

# Deploy maintenance configuration
maintenance_configuration = maintenance.MaintenanceConfiguration(
f"{self._name}_maintenance_configuration",
duration="03:55",
jemrobinson marked this conversation as resolved.
Show resolved Hide resolved
extension_properties={"InGuestPatchMode": "User"},
install_patches=maintenance.InputPatchConfigurationArgs(
linux_parameters=maintenance.InputLinuxParametersArgs(
classifications_to_include=["Critical", "Security"],
),
reboot_setting="IfRequired",
),
location=props.location,
maintenance_scope=maintenance.MaintenanceScope.IN_GUEST_PATCH,
recur_every="1Day",
resource_group_name=props.resource_group_name,
resource_name_=f"{stack_name}-maintenance-configuration",
start_date_time="2020-04-30 01:00",
jemrobinson marked this conversation as resolved.
Show resolved Hide resolved
time_zone="GMT Standard Time",
visibility=maintenance.Visibility.CUSTOM,
tags=child_tags,
)

# Register outputs
self.maintenance_configuration_id: Output[str] = maintenance_configuration.id
22 changes: 21 additions & 1 deletion data_safe_haven/infrastructure/programs/sre/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
LinuxVMComponentProps,
VMComponent,
)
from data_safe_haven.infrastructure.programs.sre.maintenance import (
SREMaintenanceComponent,
SREMaintenanceProps,
)
from data_safe_haven.resources import resources_path
from data_safe_haven.utility import FileReader

Expand Down Expand Up @@ -133,6 +137,17 @@ def __init__(
storage_account_data_private_sensitive_name=props.storage_account_data_private_sensitive_name,
).apply(lambda kwargs: self.read_cloudinit(**kwargs))

# Deploy maintenance configuration
maintenance_configuration = SREMaintenanceComponent(
"sre_maintenance",
stack_name,
SREMaintenanceProps(
location=props.location,
resource_group_name=resource_group.name,
),
tags=child_tags,
)

# Deploy a variable number of VMs depending on the input parameters
vms = [
VMComponent(
Expand All @@ -145,6 +160,7 @@ def __init__(
location=props.location,
log_analytics_workspace_id=props.log_analytics_workspace_id,
log_analytics_workspace_key=props.log_analytics_workspace_key,
maintenance_configuration_id=maintenance_configuration.maintenance_configuration_id,
resource_group_name=resource_group.name,
subnet_name=props.subnet_workspaces_name,
virtual_network_name=props.virtual_network_name,
Expand Down Expand Up @@ -177,13 +193,17 @@ def __init__(
file_uploads = [
(FileReader(resources_path / "workspace" / "run_all_tests.bats"), "0444")
]
vm_index = 0
for test_file in pathlib.Path(resources_path / "workspace").glob("test*"):
file_uploads.append((FileReader(test_file), "0444"))
for vm, vm_output in zip(vms, vm_outputs, strict=True):
craddm marked this conversation as resolved.
Show resolved Hide resolved
vm_index += 1
outputs: dict[str, Output[str]] = {}
for file_upload, file_permissions in file_uploads:
file_smoke_test = FileUpload(
replace_separators(f"{self._name}_file_{file_upload.name}", "_"),
replace_separators(
f"workspace_{vm_index:02d}_file_{file_upload.name}", "_"
),
FileUploadProps(
file_contents=file_upload.file_contents(
mustache_values=mustache_values
Expand Down
2 changes: 2 additions & 0 deletions typings/pulumi_azure_native/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import pulumi_azure_native.dataprotection as dataprotection
import pulumi_azure_native.dbforpostgresql as dbforpostgresql
import pulumi_azure_native.insights as insights
import pulumi_azure_native.keyvault as keyvault
import pulumi_azure_native.maintenance as maintenance
import pulumi_azure_native.managedidentity as managedidentity
import pulumi_azure_native.network as network
import pulumi_azure_native.operationalinsights as operationalinsights
Expand All @@ -24,6 +25,7 @@ __all__ = [
"dbforpostgresql",
"insights",
"keyvault",
"maintenance",
"managedidentity",
"network",
"operationalinsights",
Expand Down
Loading