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

ADE OnePass changes #14

Open
wants to merge 3 commits into
base: Az.RecoveryServices_preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -98,6 +98,34 @@ public class AzureRmAsrAzureToAzureDiskReplicationConfig : SiteRecoveryCmdletBas
Constants.Standard_SSD)]
public string RecoveryTargetDiskAccountType { get; set; }

/// <summary>
/// Gets or sets DiskEncryptionVaultId.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = false)]
[ValidateNotNullOrEmpty]
public string DiskEncryptionVaultId { get; set; }

/// <summary>
/// Gets or sets DiskEncryptionSecretUrl.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = false)]
[ValidateNotNullOrEmpty]
public string DiskEncryptionSecretUrl { get; set; }

/// <summary>
/// Gets or sets KeyEncryptionKeyUrl.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = false)]
[ValidateNotNullOrEmpty]
public string KeyEncryptionKeyUrl { get; set; }

/// <summary>
/// Gets or sets KeyEncryptionVaultId.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = false)]
[ValidateNotNullOrEmpty]
public string KeyEncryptionVaultId { get; set; }

#endregion Parameters

/// <summary>
Expand Down Expand Up @@ -132,7 +160,11 @@ public override void ExecuteSiteRecoveryCmdlet()
RecoveryReplicaDiskAccountType = this.RecoveryReplicaDiskAccountType,
RecoveryResourceGroupId = this.RecoveryResourceGroupId,
RecoveryTargetDiskAccountType = this.RecoveryTargetDiskAccountType,
IsManagedDisk = true
IsManagedDisk = true,
DiskEncryptionSecretUrl = this.DiskEncryptionSecretUrl,
DiskEncryptionVaultId = this.DiskEncryptionVaultId,
KeyEncryptionKeyUrl = this.KeyEncryptionKeyUrl,
KeyEncryptionVaultId = this.KeyEncryptionVaultId
};
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,10 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
this.LastRpoCalculatedTime = details.LastRpoCalculatedTime;
this.RpoInSeconds = details.RpoInSeconds;
this.IsReplicationAgentUpdateRequired = details.IsReplicationAgentUpdateRequired;
this.VmEncryptionType = details.VmEncryptionType;
this.InitialPrimaryFabricLocation = details.InitialPrimaryFabricLocation;
this.InitialRecoveryFabricLocation = details.InitialRecoveryFabricLocation;
this.LifecycleId = details.LifecycleId;

if (details.LastHeartbeat != null)
{
Expand Down Expand Up @@ -1346,10 +1350,26 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
/// </summary>
public bool? IsReplicationAgentUpdateRequired;

// check do we need to expoxed these 2 (TODO)
// public string RecoveryFabricObjectId; //how it is different from parent RecoveryFabricId
// public string LifecycleId;
// public string managementId;
/// <summary>
/// Gets or sets the VM encryption type.
/// </summary>
public string VmEncryptionType { get; set; }

/// <summary>
/// Gets or sets the initial primary fabric location.
/// </summary>
public string InitialPrimaryFabricLocation { get; set; }

/// <summary>
ayfathim marked this conversation as resolved.
Show resolved Hide resolved
/// Gets or sets the initial recovery fabric location.
/// </summary>
public string InitialRecoveryFabricLocation { get; set; }

/// <summary>
/// Gets or sets the only constant ID throught out the enable disable cycle.
/// (with multiple switch protections in the middle) - Recovery Plans refer this ID.
/// </summary>
public string LifecycleId { get; set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to expose it ?
what is need of this field ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is required for any pre/post scripts on the ReplicationProtectedItem.

}

//
Expand Down
104 changes: 43 additions & 61 deletions src/RecoveryServices/RecoveryServices.SiteRecovery/Models/PSObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,17 +2345,12 @@ public class AsrInMageAzureV2DiskInput
public class ASRAzuretoAzureDiskReplicationConfig
{
/// <summary>
/// Initializes a new instance of the <see cref="ASRAzuretoAzureDiskReplicationConfig" /> class.
/// Initializes a new instance of the <see cref="ASRAzuretoAzureDiskReplicationConfig" /> class.
/// </summary>
public ASRAzuretoAzureDiskReplicationConfig()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="ASRRunAsAccount" /> class.
/// </summary>
/// <param name="runAsAccountDetails">Run as account object.</param>
///
/// <summary>
/// Gets or sets the disk uri.
/// </summary>
Expand Down Expand Up @@ -2395,6 +2390,26 @@ public ASRAzuretoAzureDiskReplicationConfig()
/// Gets or sets RecoveryTargetDiskAccountType.
/// </summary>
public string RecoveryTargetDiskAccountType;

/// <summary>
/// Gets or sets DiskEncryptionVaultId.
/// </summary>
public string DiskEncryptionVaultId { get; set; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep name aligned with ASRAzureToAzureProtectedDiskDetails


/// <summary>
/// Gets or sets DiskEncryptionSecretUrl.
/// </summary>
public string DiskEncryptionSecretUrl { get; set; }

/// <summary>
/// Gets or sets KeyEncryptionKeyUrl.
/// </summary>
public string KeyEncryptionKeyUrl { get; set; }

/// <summary>
/// Gets or sets KeyEncryptionVaultId.
/// </summary>
public string KeyEncryptionVaultId { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -2468,30 +2483,34 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk)
this.KeyIdentifier = disk.KeyIdentifier;
}

//
// Summary:
// Gets or sets a value indicating whether disk key got encrypted or not.
/// <summary>
/// Gets or sets a value indicating whether disk key got encrypted or not.
/// </summary>
public bool? IsDiskKeyEncrypted { get; set; }
//
// Summary:
// Gets or sets the KeyVault resource id for secret (BEK).

/// <summary>
/// Gets or sets the KeyVault resource id for secret (BEK).
/// </summary>
public string DekKeyVaultArmId { get; set; }
//
// Summary:
// Gets or sets the secret URL / identifier (BEK).

/// <summary>
/// Gets or sets the secret URL / identifier (BEK).
/// </summary>
public string SecretIdentifier { get; set; }
//
// Summary:
// Gets or sets a value indicating whether vm has encrypted os disk or not.

/// <summary>
/// Gets or sets a value indicating whether vm has encrypted os disk or not.
/// </summary>
public bool? IsDiskEncrypted { get; set; }

//
// Summary:
// Gets or sets the key URL / identifier (KEK).
/// <summary>
/// Gets or sets the key URL / identifier (KEK).
/// </summary>
public string KeyIdentifier { get; set; }
//
// Summary:
// Gets or sets the KeyVault resource id for key (KEK).

/// <summary>
/// Gets or sets the KeyVault resource id for key (KEK).
/// </summary>
public string KekKeyVaultArmId { get; set; }

/// <summary>
Expand Down Expand Up @@ -2759,41 +2778,4 @@ public override string ToString()
return sb.ToString();
}
}

/// <summary>
/// Encryption types for VM.
/// </summary>
public enum AzureDiskEncryptionType
{
/// <summary>
/// VM not encrypted.
/// </summary>
NotEncrypted,

/// <summary>
/// VM encrypted using one pass ADE flow.
/// </summary>
OnePassEncrypted,

/// <summary>
/// VM encrypted using two pass ADE flow.
/// </summary>
TwoPassEncrypted
}

/// <summary>
/// Azure Disk Encryption extension types for VMs.
/// </summary>
public enum AzureDiskEncryptionExtensionType
{
/// <summary>
/// ADE extension for Windows VM.
/// </summary>
AzureDiskEncryption,

/// <summary>
/// ADE extension for Linux VM.
/// </summary>
AzureDiskEncryptionForLinux
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,13 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
public string KeyEncryptionVaultId { get; set; }

/// <summary>
/// Gets or sets switch parameter. On passing, command waits till completion.
/// Gets or sets switch parameter. On passing, command waits till completion.
/// </summary>
[Parameter]
public SwitchParameter WaitForCompletion { get; set; }

/// <summary>
/// ProcessRecord of the command.
/// ProcessRecord of the command.
/// </summary>
public override void ExecuteSiteRecoveryCmdlet()
{
Expand Down Expand Up @@ -764,7 +764,13 @@ private void AzureToAzureReplication(EnableProtectionInput input)
RecoveryResourceGroupId = disk.RecoveryResourceGroupId,
PrimaryStagingAzureStorageAccountId = disk.LogStorageAccountId,
RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType,
RecoveryTargetDiskAccountType = disk.RecoveryTargetDiskAccountType
RecoveryTargetDiskAccountType = disk.RecoveryTargetDiskAccountType,
DiskEncryptionInfo =
Utilities.A2AEncryptionDetails(
disk.DiskEncryptionSecretUrl,
disk.DiskEncryptionVaultId,
disk.KeyEncryptionKeyUrl,
disk.KeyEncryptionVaultId)
});

}
Expand All @@ -782,42 +788,16 @@ private void AzureToAzureReplication(EnableProtectionInput input)
}
}

providerSettings.DiskEncryptionInfo = this.A2AEncryptionDetails();
providerSettings.DiskEncryptionInfo =
Utilities.A2AEncryptionDetails(
this.DiskEncryptionSecretUrl,
this.DiskEncryptionVaultId,
this.KeyEncryptionKeyUrl,
this.KeyEncryptionVaultId);

input.Properties.ProviderSpecificDetails = providerSettings;
}

/**
* Creating DiskEncryptionInfo for A2A encrypted Vm.
*/
private DiskEncryptionInfo A2AEncryptionDetails()
{
// Checking if any encryption data is present then the only creating DiskEncryptionInfo.
if (this.IsParameterBound(c => c.DiskEncryptionSecretUrl) ||
this.IsParameterBound(c => c.DiskEncryptionVaultId) ||
this.IsParameterBound(c => c.KeyEncryptionKeyUrl) ||
this.IsParameterBound(c => c.KeyEncryptionVaultId))
{
DiskEncryptionInfo diskEncryptionInfo = new DiskEncryptionInfo();
// BEK DATA is present
if (this.IsParameterBound(c => c.DiskEncryptionSecretUrl) && this.IsParameterBound(c => c.DiskEncryptionVaultId))
{
diskEncryptionInfo.DiskEncryptionKeyInfo = new DiskEncryptionKeyInfo(this.DiskEncryptionSecretUrl, this.DiskEncryptionVaultId);
// KEK Data is present in pair.
if (this.IsParameterBound(c => c.KeyEncryptionKeyUrl) && this.IsParameterBound(c => c.KeyEncryptionVaultId))
{
diskEncryptionInfo.KeyEncryptionKeyInfo = new KeyEncryptionKeyInfo(this.KeyEncryptionKeyUrl, this.KeyEncryptionVaultId);
}
}
else
{
throw new Exception("Provide Disk DiskEncryptionSecretUrl and DiskEncryptionVaultId.");
}
return diskEncryptionInfo;
}
return null;
}

/// <summary>
/// Writes Job.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,12 @@ public override void ExecuteSiteRecoveryCmdlet()
new A2AVmManagedDiskUpdateDetails(
managedDisk.DiskId,
managedDisk.RecoveryTargetDiskAccountType,
managedDisk.RecoveryReplicaDiskAccountType));
managedDisk.RecoveryReplicaDiskAccountType,
Utilities.A2AEncryptionDetails(
managedDisk.DiskEncryptionSecretUrl,
managedDisk.DiskEncryptionVaultId,
managedDisk.KeyEncryptionKeyUrl,
managedDisk.KeyEncryptionVaultId)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ private void populateManagedDiskInputDetails(
ReplicationProtectedItem replicationProtectedItemResponse)
{
if (this.AzureToAzureDiskReplicationConfiguration == null ||
this.AzureToAzureDiskReplicationConfiguration.Length == 0)
this.AzureToAzureDiskReplicationConfiguration.Length == 0)
{
var a2aReplicationDetails = ((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails);
if (!a2aReplicationDetails.FabricObjectId.ToLower().Contains(ARMResourceTypeConstants.Compute.ToLower()))
Expand Down Expand Up @@ -690,7 +690,13 @@ private void populateManagedDiskInputDetails(
RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType,
RecoveryTargetDiskAccountType = disk.RecoveryTargetDiskAccountType,
PrimaryStagingAzureStorageAccountId = disk.LogStorageAccountId,
});
DiskEncryptionInfo =
Utilities.A2AEncryptionDetails(
disk.DiskEncryptionSecretUrl,
disk.DiskEncryptionVaultId,
disk.KeyEncryptionKeyUrl,
disk.KeyEncryptionVaultId)
});
}
}
}
Expand Down
Loading