Skip to content

Commit a5e9fed

Browse files
committed
Adding CMK changes for PS cmdlets
1 parent f1ff493 commit a5e9fed

19 files changed

+201
-13
lines changed

src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorCreateOrUpdateProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public string ServerKeyType
5353
get { return this._serverKeyType; }
5454
set { this._serverKeyType = value; }
5555
}
56-
56+
5757
/// <summary>
5858
/// Initializes a new instance of the
5959
/// EncryptionProtectorCreateOrUpdateProperties class.

src/Sql/Sql.LegacySdk/Generated/Models/EncryptionProtectorProperties.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,19 @@ public string Uri
6262
get { return this._uri; }
6363
set { this._uri = value; }
6464
}
65-
65+
66+
private bool? _isAutoRotationEnabled;
67+
68+
/// <summary>
69+
/// Optional. Gets or sets the Azure Sql Server Encryption
70+
/// Protector Key Rotation Status
71+
/// </summary>
72+
public bool? AutoRotationEnabled
73+
{
74+
get { return this._isAutoRotationEnabled; }
75+
set { this._isAutoRotationEnabled = value; }
76+
}
77+
6678
/// <summary>
6779
/// Initializes a new instance of the EncryptionProtectorProperties
6880
/// class.

src/Sql/Sql.Test/ScenarioTests/TransparentDataEncryptionCrudTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,12 @@ public void TestServerTransparentDataEncryptionProtectorSet()
5555
{
5656
RunPowerShellTest("Test-SetTransparentDataEncryptionProtector");
5757
}
58+
59+
[Fact]
60+
[Trait(Category.AcceptanceType, Category.CheckIn)]
61+
public void TestServerTransparentDataEncryptionProtectorSetWithKeyRotation()
62+
{
63+
RunPowerShellTest("Test-SetTransparentDataEncryptionProtectorWithKeyRotation");
64+
}
5865
}
5966
}

src/Sql/Sql.Test/ScenarioTests/TransparentDataEncryptionCrudTests.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,41 @@ function Test-SetTransparentDataEncryptionProtector
154154
Remove-ResourceGroupForTest $rg
155155
}
156156
}
157+
158+
<#
159+
.SYNOPSIS
160+
Tests Setting a server transparent data encryption protector
161+
#>
162+
function Test-SetTransparentDataEncryptionProtectorWithKeyRotation
163+
{
164+
# Setup
165+
$params = Get-SqlServerKeyVaultKeyTestEnvironmentParameters
166+
$rg = Create-ServerKeyVaultKeyTestEnvironment $params
167+
$autoRotationEnabled = $true
168+
169+
try
170+
{
171+
# Encryption Protector should be set to Service Managed initially
172+
$encProtector1 = Get-AzSqlServerTransparentDataEncryptionProtector -ResourceGroupName $params.rgName -ServerName $params.serverName
173+
Assert-AreEqual ServiceManaged $encProtector1.Type
174+
Assert-AreEqual ServiceManaged $encProtector1.ServerKeyVaultKeyName
175+
176+
# Add server key
177+
$keyResult = Add-AzSqlServerKeyVaultKey -ServerName $params.serverName -ResourceGroupName $params.rgName -KeyId $params.keyId
178+
Assert-AreEqual $params.keyId $keyResult.Uri
179+
180+
# Rotate to AKV
181+
$job = Set-AzSqlServerTransparentDataEncryptionProtector -ResourceGroupName $params.rgName -ServerName $params.serverName `
182+
-Type AzureKeyVault -KeyId $params.keyId -AutoRotationEnabled $autoRotationEnabled -Force -AsJob
183+
$job | Wait-Job
184+
$encProtector2 = $job.Output
185+
186+
Assert-AreEqual AzureKeyVault $encProtector2.Type
187+
Assert-AreEqual $params.serverKeyName $encProtector2.ServerKeyVaultKeyName
188+
Assert-AreEqual $autoRotationEnabled $encProtector2.AutoRotationEnabled
189+
}
190+
finally
191+
{
192+
Remove-ResourceGroupForTest $rg
193+
}
194+
}

src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase
323323
HelpMessage = "The Maintenance configuration id for the Sql Azure Managed Instance.")]
324324
public string MaintenanceConfigurationId { get; set; }
325325

326+
/// <summary>
327+
/// Id of the primary user assigned identity
328+
/// </summary>
329+
[Parameter(Mandatory = false,
330+
HelpMessage = "The primary user assigned identity id")]
331+
public string PrimaryUserAssignedIdentityId { get; set; }
332+
333+
/// <summary>
334+
/// URI of the key to use for encryption
335+
/// </summary>
336+
[Parameter(Mandatory = false,
337+
HelpMessage = "URI of the key to use for encryption")]
338+
public string KeyId { get; set; }
339+
326340
/// <summary>
327341
/// Gets or sets whether or not to run this cmdlet in the background as a job
328342
/// </summary>
@@ -515,6 +529,8 @@ public override void ExecuteCmdlet()
515529
MinimalTlsVersion = this.MinimalTlsVersion,
516530
BackupStorageRedundancy = this.BackupStorageRedundancy,
517531
MaintenanceConfigurationId = this.MaintenanceConfigurationId,
532+
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,
533+
KeyId = this.KeyId,
518534
Administrators = new Management.Sql.Models.ManagedInstanceExternalAdministrator()
519535
{
520536
AzureADOnlyAuthentication = (this.EnableActiveDirectoryOnlyAuthentication.IsPresent) ? (bool?)true : null,

src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
182182
[PSArgumentCompleter("None", "1.0", "1.1", "1.2")]
183183
public string MinimalTlsVersion { get; set; }
184184

185+
/// <summary>
186+
/// Id of the primary user assigned identity
187+
/// </summary>
188+
[Parameter(Mandatory = false,
189+
HelpMessage = "The primary user assigned identity id")]
190+
public string PrimaryUserAssignedIdentityId { get; set; }
191+
192+
/// <summary>
193+
/// URI of the key to use for encryption
194+
/// </summary>
195+
[Parameter(Mandatory = false,
196+
HelpMessage = "URI of the key to use for encryption")]
197+
public string KeyId { get; set; }
198+
185199
/// <summary>
186200
/// Defines whether it is ok to skip the requesting of rule removal confirmation
187201
/// </summary>
@@ -291,7 +305,9 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
291305
InstancePoolName = this.InstancePoolName,
292306
MinimalTlsVersion = this.MinimalTlsVersion,
293307
MaintenanceConfigurationId = this.MaintenanceConfigurationId,
294-
AdministratorLogin = model.FirstOrDefault().AdministratorLogin
308+
AdministratorLogin = model.FirstOrDefault().AdministratorLogin,
309+
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,
310+
KeyId = this.KeyId
295311
});
296312
return updateData;
297313
}

src/Sql/Sql/ManagedInstance/Model/AzureSqlManagedInstanceModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,15 @@ public class AzureSqlManagedInstanceModel
149149
/// Gets or sets the Azure SQL Managed Instance Active Directory administrator
150150
/// </summary>
151151
public Management.Sql.Models.ManagedInstanceExternalAdministrator Administrators { get; set; }
152+
153+
/// <summary>
154+
/// Gets or sets the resource id of a user assigned identity to be used
155+
/// </summary>
156+
public string PrimaryUserAssignedIdentityId { get; set; }
157+
158+
/// <summary>
159+
/// Gets or sets a CMK URI of the key to use for encryption.
160+
/// </summary>
161+
public string KeyId { get; set; }
152162
}
153163
}

src/Sql/Sql/ManagedInstance/Services/AzureSqlManagedInstanceAdapter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanc
172172
MinimalTlsVersion = model.MinimalTlsVersion,
173173
StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy),
174174
MaintenanceConfigurationId = MaintenanceConfigurationHelper.ConvertMaintenanceConfigurationIdArgument(model.MaintenanceConfigurationId, Context.Subscription.Id),
175-
Administrators = GetActiveDirectoryInformation(model.Administrators)
175+
Administrators = GetActiveDirectoryInformation(model.Administrators),
176+
PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId,
177+
KeyId = model.KeyId
176178
});
177179

178180
return CreateManagedInstanceModelFromResponse(resp);

src/Sql/Sql/Server/Cmdlet/NewAzureSqlServer.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ public class NewAzureSqlServer : AzureSqlServerCmdletBase
8989
[PSArgumentCompleter("1.0", "1.1", "1.2")]
9090
public string MinimalTlsVersion { get; set; }
9191

92+
/// <summary>
93+
/// Id of the primary user assigned identity
94+
/// </summary>
95+
[Parameter(Mandatory = false,
96+
HelpMessage = "The primary user assigned identity id")]
97+
public string PrimaryUserAssignedIdentityId { get; set; }
98+
99+
/// <summary>
100+
/// URI of the key to use for encryption
101+
/// </summary>
102+
[Parameter(Mandatory = false,
103+
HelpMessage = "URI of the key to use for encryption")]
104+
public string KeyId { get; set; }
105+
92106
/// <summary>
93107
/// Gets or sets whether or not to run this cmdlet in the background as a job
94108
/// </summary>
@@ -187,12 +201,14 @@ public override void ExecuteCmdlet()
187201
Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
188202
MinimalTlsVersion = this.MinimalTlsVersion,
189203
PublicNetworkAccess = this.PublicNetworkAccess,
204+
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,
205+
KeyId = this.KeyId,
190206
Administrators = new Management.Sql.Models.ServerExternalAdministrator()
191207
{
192208
AzureADOnlyAuthentication = (this.EnableActiveDirectoryOnlyAuthentication.IsPresent) ? (bool?)true : null,
193209
Login = this.ExternalAdminName,
194210
Sid = this.ExternalAdminSID
195-
}
211+
}
196212
});
197213
return newEntity;
198214
}

src/Sql/Sql/Server/Cmdlet/SetAzureSqlServer.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
8383
[PSArgumentCompleter("1.0", "1.1", "1.2")]
8484
public string MinimalTlsVersion { get; set; }
8585

86+
/// <summary>
87+
/// Id of the primary user assigned identity
88+
/// </summary>
89+
[Parameter(Mandatory = false,
90+
HelpMessage = "The primary user assigned identity id")]
91+
public string PrimaryUserAssignedIdentityId { get; set; }
92+
93+
/// <summary>
94+
/// URI of the key to use for encryption
95+
/// </summary>
96+
[Parameter(Mandatory = false,
97+
HelpMessage = "URI of the key to use for encryption")]
98+
public string KeyId { get; set; }
99+
86100
/// <summary>
87101
/// Defines whether it is ok to skip the requesting of rule removal confirmation
88102
/// </summary>
@@ -123,7 +137,9 @@ public class SetAzureSqlServer : AzureSqlServerCmdletBase
123137
Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
124138
PublicNetworkAccess = this.PublicNetworkAccess,
125139
MinimalTlsVersion = this.MinimalTlsVersion,
126-
SqlAdministratorLogin = model.FirstOrDefault().SqlAdministratorLogin
140+
SqlAdministratorLogin = model.FirstOrDefault().SqlAdministratorLogin,
141+
PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId,
142+
KeyId = this.KeyId
127143
});
128144
return updateData;
129145
}

src/Sql/Sql/Server/Model/AzureSqlServerModel.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public class AzureSqlServerModel
7979
/// </summary>
8080
public string MinimalTlsVersion { get; set; }
8181

82+
/// <summary>
8283
/// Gets or sets the flag to control enable/disable public network access
8384
/// </summary>
8485
public string PublicNetworkAccess { get; set; }
@@ -87,5 +88,15 @@ public class AzureSqlServerModel
8788
/// Gets or sets the Azure SQL Server Active Directory administrator
8889
/// </summary>
8990
public Management.Sql.Models.ServerExternalAdministrator Administrators{ get; set; }
91+
92+
/// <summary>
93+
/// Gets or sets the resource id of a user assigned identity to be used
94+
/// </summary>
95+
public string PrimaryUserAssignedIdentityId { get; set; }
96+
97+
/// <summary>
98+
/// Gets or sets a CMK URI of the key to use for encryption.
99+
/// </summary>
100+
public string KeyId { get; set; }
90101
}
91102
}

src/Sql/Sql/Server/Services/AzureSqlServerAdapter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public AzureSqlServerModel UpsertServer(AzureSqlServerModel model)
140140
Identity = model.Identity,
141141
MinimalTlsVersion = model.MinimalTlsVersion,
142142
PublicNetworkAccess = model.PublicNetworkAccess,
143-
Administrators = GetActiveDirectoryInformation(model.Administrators)
143+
Administrators = GetActiveDirectoryInformation(model.Administrators),
144+
PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId,
145+
KeyId = model.KeyId
144146
});
145147

146148
return CreateServerModelFromResponse(resp);
@@ -188,6 +190,8 @@ private static AzureSqlServerModel CreateServerModelFromResponse(Management.Sql.
188190
{
189191
server.Administrators.AdministratorType = "ActiveDirectory";
190192
}
193+
server.PrimaryUserAssignedIdentityId = resp.PrimaryUserAssignedIdentityId;
194+
server.KeyId = resp.KeyId;
191195

192196
return server;
193197
}

src/Sql/Sql/Sql.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.53.0-preview" />
2525
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
2626
</ItemGroup>
27+
28+
<ItemGroup>
29+
<Reference Include="D:\repos\azure-sdk-for-net\artifacts\bin\Microsoft.Azure.Management.Sql\Debug\net461\Microsoft.Azure.Management.Sql.dll" />
30+
</ItemGroup>
2731

2832
<ItemGroup>
2933
<ProjectReference Include="..\Sql.LegacySdk\Sql.LegacySdk.csproj" />

src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureRmSqlManagedInstanceTransparentDataEncryptionProtector.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ public class SetAzureRmSqlManagedInstanceTransparentDataEncryptionProtector : Az
6464
HelpMessage = "The Azure Key Vault KeyId.")]
6565
[ValidateNotNullOrEmpty]
6666
public string KeyId { get; set; }
67-
67+
68+
/// <summary>
69+
/// Gets or sets the encryption protector key auto rotation status
70+
/// </summary>
71+
[Parameter(Mandatory = false,
72+
ValueFromPipelineByPropertyName = true,
73+
Position = 4,
74+
HelpMessage = "The Key Auto Rotation status")]
75+
[ValidateNotNullOrEmpty]
76+
public SwitchParameter AutoRotationEnabled { get; set; }
77+
6878
/// <summary>
6979
/// Defines whether it is ok to skip the requesting of setting Transparent Data Encryption protector confirmation
7080
/// </summary>
@@ -101,7 +111,8 @@ protected override IEnumerable<AzureRmSqlManagedInstanceTransparentDataEncryptio
101111
resourceGroupName: this.ResourceGroupName,
102112
managedInstanceName: this.InstanceName,
103113
type: this.Type,
104-
keyId: this.KeyId));
114+
keyId: this.KeyId,
115+
autoRotatonEnabled: this.AutoRotationEnabled));
105116

106117
return newEntity;
107118
}

src/Sql/Sql/TransparentDataEncryption/Cmdlet/SetAzureSqlServerTransparentDataEncryptionProtector.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public class SetAzureSqlServerTransparentDataEncryptionProtector : AzureSqlServe
4848
[ValidateNotNullOrEmpty]
4949
public string KeyId { get; set; }
5050

51+
/// <summary>
52+
/// Gets or sets the encryption protector key auto rotation status
53+
/// </summary>
54+
[Parameter(Mandatory = false,
55+
ValueFromPipelineByPropertyName = true,
56+
Position = 4,
57+
HelpMessage = "The Key Auto Rotation status")]
58+
[ValidateNotNullOrEmpty]
59+
public SwitchParameter AutoRotationEnabled { get; set; }
60+
5161
/// <summary>
5262
/// Defines whether it is ok to skip the requesting of setting Transparent Data Encryption protector confirmation
5363
/// </summary>
@@ -84,7 +94,8 @@ public class SetAzureSqlServerTransparentDataEncryptionProtector : AzureSqlServe
8494
ServerName = this.ServerName,
8595
Type = this.Type,
8696
ServerKeyVaultKeyName = TdeKeyHelper.CreateServerKeyNameFromKeyId(this.KeyId),
87-
KeyId = this.KeyId
97+
KeyId = this.KeyId,
98+
AutoRotationEnabled = this.AutoRotationEnabled
8899
});
89100
return newEntity;
90101
}

src/Sql/Sql/TransparentDataEncryption/Model/AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel(string r
3030
ManagedInstanceName = managedInstanceName;
3131
}
3232

33-
public AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel(string resourceGroupName, string managedInstanceName, EncryptionProtectorType type, string keyId)
33+
public AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel(string resourceGroupName, string managedInstanceName, EncryptionProtectorType type, string keyId, bool? autoRotatonEnabled)
3434
: this(resourceGroupName, managedInstanceName)
3535
{
3636
Type = type;
3737
KeyId = keyId;
38+
AutoRotationEnabled = autoRotatonEnabled;
3839
}
3940

4041
/// <summary>
@@ -62,6 +63,11 @@ public AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel(string r
6263
/// </summary>
6364
public string KeyId { get; private set; }
6465

66+
/// <summary>
67+
/// Gets or sets the key auto rotation status.
68+
/// </summary>
69+
public bool? AutoRotationEnabled { get; set; }
70+
6571
/// <summary>
6672
/// Create a AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel from a given ManagedInstanceEncryptionProtector
6773
/// </summary>
@@ -80,7 +86,8 @@ public static AzureRmSqlManagedInstanceTransparentDataEncryptionProtectorModel F
8086
{
8187
ManagedInstanceKeyVaultKeyName = managedInstanceEncryptionProtector.ServerKeyName,
8288
Type = type,
83-
KeyId = managedInstanceEncryptionProtector.Uri
89+
KeyId = managedInstanceEncryptionProtector.Uri,
90+
AutoRotationEnabled = managedInstanceEncryptionProtector.AutoRotationEnabled
8491
};
8592
}
8693
}

0 commit comments

Comments
 (0)