Skip to content

[SQL] Add support for service principals for setting SQL AAD Admin. #12140

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

Merged
merged 8 commits into from
Jun 13, 2020
2 changes: 2 additions & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* Added SyncMemberAzureDatabaseResourceId to `New-AzSqlSyncMember` and `Update-AzSqlSyncMember`
* Added Guest user lookup support to Set SQL Server Azure Active Directory Admin cmdlet
* Remove IsAzureADOnlyAuthentication parameter from Set-AzSqlServerActiveDirectoryAdministrator as it is not usable.
* Added support for service principal for Set SQL Server Azure Active Directory Admin cmdlet


## Version 2.6.1
* Enhance performance of:
Expand Down
6 changes: 3 additions & 3 deletions src/Sql/Sql/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Sql/Sql/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@
<value>More than one Azure Active Directory user with the display name '{0}' was found. Please provide an Azure Active Directory object id to select the correct user. To get the object id use Get-AzADUser -SearchString "{0}"</value>
</data>
<data name="ADApplicationMoreThanOneFound" xml:space="preserve">
<value>More than one Azure Active Directory application with the display name '{0}' was found. Please provide an Azure Active Directory application id of the application to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}"</value>
<value>More than one Azure Active Directory application with the display name '{0}' was found. Please provide an Azure Active Directory application id of the application to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" or use use Get-AzADServicePrincipal -SearchString "{0}"</value>
</data>
<data name="ADApplicationDisplayNameMismatch" xml:space="preserve">
<value>Azure Active Directory application with the display name '{0}' was found. Display Name provided does not match with application display name '{1}'. Please provide right display name that names with display name of the application. To get the application id use Get-AzADApplication -SearchString "{0}" or Get-AzADApplication -SearchString "{1}".</value>
<value>Azure Active Directory application with the display name '{0}' was found. Display Name provided does not match with any service principal display name '{1}'. Please provide right display name that names with display name of the application. To get the application id use Get-AzADApplication -SearchString "{0}" or Get-AzADServicePrincipal -SearchString "{1}".</value>
</data>
<data name="ADDuplicateGroupAndApplicationFound" xml:space="preserve">
<value>Azure Active Directory application and group with same display name '{0}' was found. Please provide an Azure Active Directory application id of the application or object id of the group to select the correct application. To get the application id use Get-AzADApplication -SearchString "{0}" or to get object id use Get-AzADGroup -SearchString "{0}".</value>
<value>Azure Active Directory application and group with same display name '{0}' was found. Please provide an Azure Active Directory application id of the service principal or object id of the group to select the correct application. To get the application id use Get-AzADServicePrincipal -SearchString "{0}" or to get object id use Get-AzADGroup -SearchString "{0}".</value>
</data>
<data name="DatabaseNameExists" xml:space="preserve">
<value>Database with name: '{0}' already exists in server '{1}'.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,30 +208,30 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa
}
}

// Lookup for applications
ODataQuery<Application> odataQueryFilter;
// Lookup for serviceprincipals
ODataQuery<ServicePrincipal> odataQueryFilter;

if ((objectId != null && objectId != Guid.Empty))
{
var applicationIdString = objectId.ToString();
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.AppId == applicationIdString);
odataQueryFilter = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(a => a.AppId == applicationIdString);
}
else
{
odataQueryFilter = new Rest.Azure.OData.ODataQuery<Application>(a => a.DisplayName == displayName);
odataQueryFilter = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(a => a.DisplayName == displayName);
}

var applicationList = ActiveDirectoryClient.GetApplicationWithFilters(odataQueryFilter);
var srevicePrincipalList = ActiveDirectoryClient.FilterServicePrincipals(odataQueryFilter);

if (applicationList != null && applicationList.Count() > 1)
if (srevicePrincipalList != null && srevicePrincipalList.Count() > 1)
{
// More than one application was found.
// More than one service principal was found.
throw new ArgumentException(string.Format(Microsoft.Azure.Commands.Sql.Properties.Resources.ADApplicationMoreThanOneFound, displayName));
}
else if (applicationList != null && applicationList.Count() == 1)
else if (srevicePrincipalList != null && srevicePrincipalList.Count() == 1)
{
// Only one user was found. Get the user display name and object id
PSADApplication app = applicationList.First();
PSADServicePrincipal app = srevicePrincipalList.First();

if (displayName != null && string.CompareOrdinal(displayName, app.DisplayName) != 0)
{
Expand Down Expand Up @@ -261,7 +261,7 @@ protected ServerAzureADAdministrator GetActiveDirectoryInformation(string displa
};
}

// No group or application was found. Check for a user
// No group or service principal was found. Check for a user
filter = new ADObjectFilterOptions()
{
Id = (objectId != null && objectId != Guid.Empty) ? objectId.ToString() : null,
Expand Down