Skip to content

Commit 6e0b4e6

Browse files
authored
Code changes for provisioning Server & ManagedInstance with AD Only Authentication & External Administrator Properties (#15151)
* Rebase master * Update Changelog * Switch to singular noun * Fix bug * Check for administrator object * Fix test
1 parent 03663b5 commit 6e0b4e6

18 files changed

+1025
-73
lines changed

src/Sql/Sql.Test/UnitTests/AzureSqlDatabaseServerAttributeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void NewAzureSqlServerAttributes()
3838
UnitTestHelper.CheckConfirmImpact(type, System.Management.Automation.ConfirmImpact.Low);
3939

4040
UnitTestHelper.CheckCmdletParameterAttributes(type, "ServerName", isMandatory: true, valueFromPipelineByName: false);
41-
UnitTestHelper.CheckCmdletParameterAttributes(type, "SqlAdministratorCredentials", isMandatory: true, valueFromPipelineByName: false);
41+
UnitTestHelper.CheckCmdletParameterAttributes(type, "SqlAdministratorCredentials", isMandatory: false, valueFromPipelineByName: false);
4242
UnitTestHelper.CheckCmdletParameterAttributes(type, "Tags", isMandatory: false, valueFromPipelineByName: false);
4343
UnitTestHelper.CheckCmdletParameterAttributes(type, "ServerVersion", isMandatory: false, valueFromPipelineByName: false);
4444
}

src/Sql/Sql/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
## Upcoming Release
2121
* Added option to support short version of maintenance configuration id for Managed Instance in `New-AzSqlInstance` and `Set-AzSqlInstance` cmdlets
2222
* Added HighAvailabilityReplicaCount to `New-AzSqlDatabaseSecondary`
23+
* Add External Administrator and AAD Only Properties to AzSqlServer and AzSqlInstance
24+
- Added option to specify `-ExternalAdminName`, `-ExternalAdminSid`, `-EnableActiveDirectoryOnlyAuthentication` in `New-AzSqlInstance` and `Set-AzSqlInstance` cmdlets
25+
- Added option to expand external administrators information using `-ExpandActiveDirectoryAdministrator` in `Get-AzSqlServer` and `Get-AzSqlInstance` cmdlets
2326

2427
## Version 3.1.0
2528
* Updated `Set-AzSqlDatabaseVulnerabilityAssessmentRuleBaseline` documentation to include example of define array of array with one inner array.

src/Sql/Sql/ManagedInstance/Cmdlet/GetAzureSqlManagedInstance.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ public class GetAzureSqlManagedInstance : ManagedInstanceCmdletBase
112112
[ValidateNotNullOrEmpty]
113113
public override string ResourceGroupName { get; set; }
114114

115+
/// <summary>
116+
/// Expand Active Directory Administrator Information on the Managed Instance
117+
/// </summary>
118+
[Parameter(Mandatory = false,
119+
HelpMessage = "Expand Active Directory Administrator Information on the server.")]
120+
public SwitchParameter ExpandActiveDirectoryAdministrator { get; set; }
121+
115122
/// <summary>
116123
/// Entry point for the cmdlet
117124
/// </summary>
@@ -148,25 +155,27 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> GetEntity()
148155
{
149156
ICollection<AzureSqlManagedInstanceModel> results = new List<AzureSqlManagedInstanceModel>();
150157

158+
string expand = (this.ExpandActiveDirectoryAdministrator.IsPresent) ? "administrators/activeDirectory" : null;
159+
151160
if (ShouldGetByName(ResourceGroupName, Name))
152161
{
153162
results = new List<AzureSqlManagedInstanceModel>();
154-
results.Add(ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name));
163+
results.Add(ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name, expand));
155164
}
156165
else if (ShouldListByResourceGroup(ResourceGroupName, Name))
157166
{
158167
if (this.InstancePoolName != null)
159168
{
160-
results = ModelAdapter.ListManagedInstancesByInstancePool(this.ResourceGroupName, this.InstancePoolName);
169+
results = ModelAdapter.ListManagedInstancesByInstancePool(this.ResourceGroupName, this.InstancePoolName, expand);
161170
}
162171
else
163172
{
164-
results = ModelAdapter.ListManagedInstancesByResourceGroup(this.ResourceGroupName);
173+
results = ModelAdapter.ListManagedInstancesByResourceGroup(this.ResourceGroupName, expand);
165174
}
166175
}
167176
else
168177
{
169-
results = ModelAdapter.ListManagedInstances();
178+
results = ModelAdapter.ListManagedInstances(expand);
170179
}
171180

172181
return TopLevelWildcardFilter(ResourceGroupName, Name, results);

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2929
using Microsoft.Azure.Commands.Sql.Instance_Pools.Services;
3030
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
31+
using System;
3132

3233
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Cmdlet
3334
{
@@ -120,8 +121,7 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase
120121
/// <summary>
121122
/// Gets or sets the admin credential of the instance
122123
/// </summary>
123-
[Parameter(Mandatory = true, HelpMessage = "The SQL authentication credential of the instance.")]
124-
[ValidateNotNull]
124+
[Parameter(Mandatory = false, HelpMessage = "The SQL authentication credential of the instance.")]
125125
public PSCredential AdministratorCredential { get; set; }
126126

127127
/// <summary>
@@ -335,11 +335,42 @@ public class NewAzureSqlManagedInstance : ManagedInstanceCmdletBase
335335
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
336336
public SwitchParameter Force { get; set; }
337337

338+
/// <summary>
339+
/// Enable Active Directory Only Authentication on the server
340+
/// </summary>
341+
[Parameter(Mandatory = false,
342+
HelpMessage = "Enable Active Directory Only Authentication on the server.")]
343+
public SwitchParameter EnableActiveDirectoryOnlyAuthentication { get; set; }
344+
345+
/// <summary>
346+
/// Azure Active Directory display name for a user or group
347+
/// </summary>
348+
[Parameter(Mandatory = false,
349+
HelpMessage = "Specifies the display name of the user, group or application which is the Azure Active Directory administrator for the server. This display name must exist in the active directory associated with the current subscription.")]
350+
public string ExternalAdminName { get; set; }
351+
352+
/// <summary>
353+
/// Azure Active Directory object id for a user, group or application
354+
/// </summary>
355+
[Parameter(Mandatory = false,
356+
HelpMessage = "Specifies the object ID of the user, group or application which is the Azure Active Directory administrator.")]
357+
public Guid? ExternalAdminSID { get; set; }
358+
338359
/// <summary>
339360
/// Overriding to add warning message
340361
/// </summary>
341362
public override void ExecuteCmdlet()
342363
{
364+
if (this.EnableActiveDirectoryOnlyAuthentication.IsPresent && this.ExternalAdminName == null)
365+
{
366+
throw new PSArgumentException(Properties.Resources.MissingExternalAdmin, "ExternalAdminName");
367+
}
368+
369+
if (!this.EnableActiveDirectoryOnlyAuthentication.IsPresent && this.AdministratorCredential == null)
370+
{
371+
throw new PSArgumentException(Properties.Resources.MissingSQLAdministratorCredentials, "AdministratorCredential");
372+
}
373+
343374
if (this.IsParameterBound(c => c.InstancePool))
344375
{
345376
this.ResourceGroupName = this.InstancePool.ResourceGroupName;
@@ -462,8 +493,8 @@ public override void ExecuteCmdlet()
462493
Location = this.Location,
463494
ResourceGroupName = this.ResourceGroupName,
464495
FullyQualifiedDomainName = this.Name,
465-
AdministratorLogin = this.AdministratorCredential.UserName,
466-
AdministratorPassword = this.AdministratorCredential.Password,
496+
AdministratorPassword = (this.AdministratorCredential != null) ? this.AdministratorCredential.Password : null,
497+
AdministratorLogin = (this.AdministratorCredential != null) ? this.AdministratorCredential.UserName : null,
467498
Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
468499
Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
469500
LicenseType = this.LicenseType,
@@ -483,7 +514,13 @@ public override void ExecuteCmdlet()
483514
InstancePoolName = this.InstancePoolName,
484515
MinimalTlsVersion = this.MinimalTlsVersion,
485516
BackupStorageRedundancy = this.BackupStorageRedundancy,
486-
MaintenanceConfigurationId = this.MaintenanceConfigurationId
517+
MaintenanceConfigurationId = this.MaintenanceConfigurationId,
518+
Administrators = new Management.Sql.Models.ManagedInstanceExternalAdministrator()
519+
{
520+
AzureADOnlyAuthentication = (this.EnableActiveDirectoryOnlyAuthentication.IsPresent) ? (bool?)true : null,
521+
Login = this.ExternalAdminName,
522+
Sid = this.ExternalAdminSID
523+
}
487524
});
488525
return newEntity;
489526
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,10 @@ public class AzureSqlManagedInstanceModel
144144
/// Gets or sets the managed instance maintenance configuration id
145145
/// </summary>
146146
public string MaintenanceConfigurationId { get; set; }
147+
148+
/// <summary>
149+
/// Gets or sets the Azure SQL Managed Instance Active Directory administrator
150+
/// </summary>
151+
public Management.Sql.Models.ManagedInstanceExternalAdministrator Administrators { get; set; }
147152
}
148153
}

0 commit comments

Comments
 (0)