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:
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:
- Created 2 years ago
- Comments:13 (2 by maintainers)
@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.
@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!