question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure Active Directory Administrator is not updated for existing SQL Server

See original GitHub issue
  • Package Name: azure-mgmt-sql
  • Package Version: 3.0.1
  • Operating System: MacOS 11.6
  • Python Version: 3.9.6

Describe the bug When updating an already-created SQL Server, the Azure Active Directory Administrator parameter is not applied to the server.

To Reproduce The following test Python class shows the issue. It first creates a SQL Server with an administrator (working as expected), and then creates a SQL Server without administrator and tries to update it to add the administrator (not working).

#!/usr/bin/python

import os
from azure.identity._credentials import client_secret
from azure.mgmt.sql import SqlManagementClient
from azure.mgmt.sql.models import Server, ServerExternalAdministrator

resource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'xxx')

subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'xxx')
credentials = client_secret.ClientSecretCredential(
    client_id=os.environ.get('AZURE_CLIENT_ID', 'xxx'),
    client_secret=os.environ.get('AZURE_CLIENT_SECRET', 'xxx'),
    tenant_id=os.environ.get('AZURE_TENANT_ID', 'xxx'),
)

sql_client = SqlManagementClient(credential=credentials, subscription_id=subscription_id)

# create sql server with AAD admin
params_with_admin = Server(
    location='eastus2',
    version='12.0',
    administrator_login='mylogin',
    administrator_login_password='Password123!',
    administrators=ServerExternalAdministrator(
        administrator_type='ActiveDirectory',
        principal_type='Group',
        login=os.environ.get('AZURE_SQL_AAD_ADMIN_NAME', 'xxx'),
        sid=os.environ.get('AZURE_SQL_AAD_ADMIN_SID', 'xxx'),
        tenant_id=os.environ.get('AZURE_TENANT_ID', 'xxx'),
        azure_ad_only_authentication=False,
    )
)
server_name = 'sql-server-aad-testing-with-admin'
print('creating server {0} with params {1}'.format(server_name, params_with_admin.as_dict()))

response = sql_client.servers.begin_create_or_update(resource_group_name=resource_group,
                                                     server_name=server_name,
                                                     parameters=params_with_admin).result()
print('response: {0}'.format(response.as_dict()))


# create sql server with no initial AAD admin
params_no_admin = Server(
    location='eastus2',
    version='12.0',
    administrator_login='mylogin',
    administrator_login_password='Password123!',
)
server_name = 'sql-server-aad-testing-no-initial-admin'
print('creating server {0} with params {1}'.format(server_name, params_no_admin.as_dict()))

response = sql_client.servers.begin_create_or_update(resource_group_name=resource_group,
                                                     server_name=server_name,
                                                     parameters=params_no_admin).result()
print('response: {0}'.format(response.as_dict()))


# update existing sql server to add AAD admin
print('updating server {0} with params {1}'.format(server_name, params_with_admin.as_dict()))
response = sql_client.servers.begin_create_or_update(resource_group_name=resource_group,
                                                     server_name=server_name,
                                                     parameters=params_with_admin).result()
print('response: {0}'.format(response.as_dict()))

Expected behavior Updating an existing SQL Server with Azure Active Directory administrator information should apply the AAD admin change on the server.

Screenshots After the update call is performed, the AAD admin is still not set on the SQL Server: Screen Shot 2021-12-03 at 10 48 01 PM

Additional context The following environment variables are used in the script. You can add here or modify the script:

export AZURE_CLIENT_ID="xxx"
export AZURE_TENANT_ID="xxx"
export AZURE_CLIENT_SECRET="xxx"
export AZURE_SUBSCRIPTION_ID="xxx"
export AZURE_SQL_AAD_ADMIN_NAME="xxx"
export AZURE_SQL_AAD_ADMIN_SID="xxx"
export AZURE_RESOURCE_GROUP="xxx"

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
SaurabhSharma-MSFTcommented, Dec 17, 2021

@l3ender Thanks for your feedback. I could see the same behavior in my environment as well and escalating this to service team members to look into this. image

1reaction
l3endercommented, Feb 8, 2022

@arvindshmicrosoft Great detail, and thanks for sharing the doc link! I appreciate the information and will proceed to close this issue as it is working by design. Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure and manage Azure AD authentication with Azure SQL
In the Add admin page, search for a user, select the user or group to be an administrator, and then select Select. (The...
Read more >
Server Azure AD Administrators - Create Or Update
Learn more about SQL Database service - Creates or updates an existing Azure Active Directory administrator.
Read more >
Set up Azure Active Directory authentication for SQL Server
Once Azure AD is configured for SQL Server, updating the certificate in SQL Server - Azure Arc resource's Azure AD pane may not...
Read more >
Troubleshooting problems related to Azure AD authentication ...
When working with Azure AD authentication for Azure SQL DB and DW, you may sometimes encounter certain issues. The table below contains some ......
Read more >
Azure Active Directory authentication for SQL Server 2022
If you are using the Azure AD admin, the database connection to <default> (master database) or any other user database is allowed. For...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found