Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6c6441a
Support managing of Azure AD administrator on Managed Instance
SanjaMalesevic Aug 30, 2019
70b2e03
Add AAD admin test
SanjaMalesevic Sep 6, 2019
ee93a67
Add release notes
SanjaMalesevic Sep 6, 2019
d8cc932
Add release notes and upgrade version in requirements
SanjaMalesevic Sep 6, 2019
e2da8c5
Revert version in setup.py
SanjaMalesevic Sep 6, 2019
c2afe5b
Delete testcert.cer
SanjaMalesevic Sep 6, 2019
2463fba
Delete testingAadAdmin.playlist
SanjaMalesevic Sep 6, 2019
5828b13
Delete testkey.pvk
SanjaMalesevic Sep 6, 2019
c05ae62
Merge branch 'dev' into setAADAdminOnMiCliCommands
SanjaMalesevic Sep 6, 2019
1762a83
Update setup.py
SanjaMalesevic Sep 6, 2019
7965e1f
Update HISTORY.rst
SanjaMalesevic Sep 6, 2019
856bbd7
Test fixes
SanjaMalesevic Sep 6, 2019
6184aff
Merge branch 'setAADAdminOnMiCliCommands' of https://github.com/Sanja…
SanjaMalesevic Sep 6, 2019
6e76c9a
Test fixes 2
SanjaMalesevic Sep 6, 2019
229aaa7
Merge branch 'dev' into setAADAdminOnMiCliCommands
SanjaMalesevic Sep 24, 2019
6219076
Update History.rst
SanjaMalesevic Sep 24, 2019
b31e456
Code review fixes
SanjaMalesevic Sep 24, 2019
27f51f1
Resolving merge conflicts
SanjaMalesevic Sep 24, 2019
43d6b2d
Fix help file
SanjaMalesevic Sep 24, 2019
3d6ceed
Update recorded file for test SqlInstanceFailoverGroupMgmtScenarioTest
SanjaMalesevic Sep 24, 2019
649c1ce
Merge branch 'dev' into setAADAdminOnMiCliCommands
SanjaMalesevic Oct 1, 2019
cd1d265
Update _help.py based on comments
SanjaMalesevic Oct 1, 2019
489daad
Update file base on CR comment
SanjaMalesevic Oct 1, 2019
ec3b7cb
Merge branch 'dev' into setAADAdminOnMiCliCommands
SanjaMalesevic Oct 10, 2019
20ee134
Test fixes
SanjaMalesevic Oct 10, 2019
e236f28
Record the test - api version is changed
SanjaMalesevic Oct 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Release History
- Changed parameter --ask from utf-8 string to 32 character hex string.
job start:
- Changed the command from `job start` to `job create`.

**SQL**

* New Cmdlets for sql mi ad-admin that supports setting AAD administrator on Managed instance

**Compute**

Expand Down
20 changes: 20 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,26 @@
type: command
short-summary: Sets the SQL Instance's encryption protector.
"""
helps['sql mi ad-admin'] = """
type: group
short-summary: Manage a managed instance's Active Directory administrator.
"""
helps['sql mi ad-admin create'] = """
type: command
short-summary: Creates a new managed instance Active Directory administrator.
"""
helps['sql mi ad-admin update'] = """
type: command
short-summary: Updates an existing managed instance Active Directory administrator.
"""
helps['sql mi ad-admin list'] = """
type: command
short-summary: Returns a list of managed instance Active Directory Administrators.
"""
helps['sql mi ad-admin delete'] = """
type: command
short-summary: Deletes an existing managed instance Active Directory Administrator.
"""
helps['sql instance-failover-group'] = """
type: group
short-summary: Manage SQL Instance Failover Groups.
Expand Down
44 changes: 40 additions & 4 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ExportRequest,
ManagedDatabase,
ManagedInstance,
ManagedInstanceAdministrator,
Server,
ServerAzureADAdministrator,
Sku,
Expand Down Expand Up @@ -195,6 +196,14 @@ def get_location_type_with_default_from_resource_group(cli_ctx):
help='Complete the failover even if doing so may result in data loss. '
'This will allow the failover to proceed even if a primary database is unavailable.')

aad_admin_login_param_type = CLIArgumentType(
options_list=['--display-name', '-u'],
help='Display name of the Azure AD administrator user or group.')

aad_admin_sid_param_type = CLIArgumentType(
options_list=['--object-id', '-i'],
help='The unique ID of the Azure AD administrator.')

db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, BC_Gen5_2.'
dw_service_objective_examples = 'DW100, DW1000c'

Expand Down Expand Up @@ -937,12 +946,10 @@ def _configure_security_policy_storage_params(arg_ctx):
options_list=['--server-name', '--server', '-s'])

c.argument('login',
options_list=['--display-name', '-u'],
help='Display name of the Azure AD administrator user or group.')
arg_type=aad_admin_login_param_type)

c.argument('sid',
options_list=['--object-id', '-i'],
help='The unique ID of the Azure AD administrator ')
arg_type=aad_admin_sid_param_type)

c.ignore('tenant_id')

Expand Down Expand Up @@ -1199,6 +1206,35 @@ def _configure_security_policy_storage_params(arg_ctx):
arg_type=kid_param_type,
required=True,)

#####
# sql managed instance ad-admin
######
with self.argument_context('sql mi ad-admin') as c:
c.argument('managed_instance_name',
arg_type=managed_instance_param_type)

c.argument('login',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define arg types (at top of file) that can be used for both sql server and MI arguments, instead of copying

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

arg_type=aad_admin_login_param_type)

c.argument('sid',
arg_type=aad_admin_sid_param_type)

with self.argument_context('sql mi ad-admin create') as c:
# Create args that will be used to build up the ManagedInstanceAdministrator object
create_args_for_complex_type(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can put this in sql mi ad-admin section so that it applies to both create and update (to avoid repetition)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to do this, but when executing get or delete command get the following error: ValueError: command authoring error: extra argument 'login' cannot be registered to a group-level scope 'sql mi ad-admin'. It must be registered to a specific command.
So, I need to keep both "sql mi ad-admin create" and "sql mi ad-admin update" sections.

c, 'properties', ManagedInstanceAdministrator, [
'login',
'sid',
])

with self.argument_context('sql mi ad-admin update') as c:
# Create args that will be used to build up the ManagedInstanceAdministrator object
create_args_for_complex_type(
c, 'properties', ManagedInstanceAdministrator, [
'login',
'sid',
])

#####
# sql server tde-key
#####
Expand Down
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def get_sql_managed_instances_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_instances


def get_sql_managed_instance_azure_ad_administrators_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_instance_administrators


def get_sql_managed_databases_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_databases

Expand Down
14 changes: 14 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
get_sql_failover_groups_operations,
get_sql_firewall_rules_operations,
get_sql_managed_databases_operations,
get_sql_managed_instance_azure_ad_administrators_operations,
get_sql_managed_instance_encryption_protectors_operations,
get_sql_managed_instance_keys_operations,
get_sql_managed_instances_operations,
Expand Down Expand Up @@ -493,6 +494,19 @@ def load_command_table(self, _):
g.show_command('show', 'get')
g.custom_command('set', 'managed_instance_encryption_protector_update')

managed_instance_aadadmin_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#ManagedInstanceAdministratorsOperations.{}',
client_factory=get_sql_managed_instance_azure_ad_administrators_operations)

with self.command_group('sql mi ad-admin',
managed_instance_aadadmin_operations,
client_factory=get_sql_managed_instance_azure_ad_administrators_operations) as g:

g.custom_command('create', 'mi_ad_admin_set')
g.command('list', 'list_by_instance')
g.custom_command('delete', 'mi_ad_admin_delete')
g.custom_command('update', 'mi_ad_admin_set')

###############################################
# sql managed db #
###############################################
Expand Down
62 changes: 52 additions & 10 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
CapabilityStatus,
CreateMode,
DatabaseEdition,
EncryptionProtector,
FailoverGroup,
FailoverGroupReadOnlyEndpoint,
FailoverGroupReadWriteEndpoint,
Expand Down Expand Up @@ -328,6 +327,17 @@ def _db_elastic_pool_update_sku(
allow_reset_family=allow_reset_family)


def _get_tenant_id():
'''
Gets tenantId from current subscription.
'''
from azure.cli.core._profile import Profile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add '''description''' to function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


profile = Profile()
sub = profile.get_subscription()
return sub['tenantId']


_DEFAULT_SERVER_VERSION = "12.0"


Expand Down Expand Up @@ -1777,19 +1787,15 @@ def server_update(


def server_ad_admin_set(
cmd,
client,
resource_group_name,
server_name,
**kwargs):
'''
Sets a server's AD admin.
'''
from azure.cli.core._profile import Profile

profile = Profile(cli_ctx=cmd.cli_ctx)
sub = profile.get_subscription()
kwargs['tenant_id'] = sub['tenantId']
kwargs['tenant_id'] = _get_tenant_id()

return client.create_or_update(
server_name=server_name,
Expand Down Expand Up @@ -2010,10 +2016,8 @@ def encryption_protector_update(
return client.create_or_update(
resource_group_name=resource_group_name,
server_name=server_name,
parameters=EncryptionProtector(
server_key_type=server_key_type,
server_key_name=key_name
)
server_key_type=server_key_type,
server_key_name=key_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build wasn't successful because of failed test test_sql_tdebyok (azure.cli.command_modules.sql.tests.latest.test_sql_commands.SqlTransparentDataEncryptionScenarioTest). You can find more on this link https://github.com/Azure/azure-cli/runs/214404678.
After I've fixed this, all checks have passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Azure/azure-sdk-for-python@58857ae

@zikalino , can you clarify why this breaking change happened?

)

###############################################
Expand Down Expand Up @@ -2226,6 +2230,44 @@ def managed_instance_encryption_protector_update(
server_key_name=key_name
)


#####
# sql managed instance ad-admin
#####


def mi_ad_admin_set(
client,
resource_group_name,
managed_instance_name,
**kwargs):
'''
Creates a managed instance active directory administrator.
'''

kwargs['tenant_id'] = _get_tenant_id()

return client.create_or_update(
resource_group_name=resource_group_name,
managed_instance_name=managed_instance_name,
administrator_name="ActiveDirectory",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define constant, e.g. ACTIVE_DIRECTORY = "ActiveDirectory" so that string isn't repeated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unclear why this is needed compared to SQL server admin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip this for now, because it will be removed after we change api specification and update the python client

parameters=kwargs
)


def mi_ad_admin_delete(
client,
resource_group_name,
managed_instance_name):
'''
Deletes a managed instance active directory administrator.
'''
return client.delete(
resource_group_name=resource_group_name,
managed_instance_name=managed_instance_name,
administrator_name="ActiveDirectory"
)

###############################################
# sql managed db #
###############################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interactions:
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-01?api-version=2015-05-01-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-01?api-version=2018-06-01-preview
response:
body:
string: !!python/unicode '{"identity":{"principalId":"8b8ac196-72ec-43a7-9020-ab1d5fc498cb","type":"SystemAssigned","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47"},"sku":{"name":"GP_Gen4","tier":"GeneralPurpose","family":"Gen4","capacity":8},"properties":{"fullyQualifiedDomainName":"geodrmitestgp-01.eus113708aec224c.database.windows.net","administratorLogin":"cloudSA","subnetId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Network/virtualNetworks/geodrEastUSvnet/subnets/default","state":"Ready","licenseType":"LicenseIncluded","vCores":8,"storageSizeInGB":512,"collation":"SQL_Latin1_General_CP1_CI_AS","dnsZone":"eus113708aec224c","publicDataEndpointEnabled":false},"location":"eastus","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-01","name":"geodrmitestgp-01","type":"Microsoft.Sql/managedInstances"}'
Expand Down Expand Up @@ -67,7 +67,7 @@ interactions:
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-secondary?api-version=2015-05-01-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-secondary?api-version=2018-06-01-preview
response:
body:
string: !!python/unicode '{"identity":{"principalId":"647bf67a-773a-4b36-af4c-4162e766a4b8","type":"SystemAssigned","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47"},"sku":{"name":"GP_Gen5","tier":"GeneralPurpose","family":"Gen5","capacity":8},"properties":{"fullyQualifiedDomainName":"geodrmitestgp-secondary.eus113708aec224c.database.windows.net","administratorLogin":"cloudSA","subnetId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Network/virtualNetworks/vnet-geodrmitestgp-secondary/subnets/ManagedInstance","state":"Ready","licenseType":"LicenseIncluded","vCores":8,"storageSizeInGB":512,"collation":"SQL_Latin1_General_CP1_CI_AS","dnsZone":"eus113708aec224c","publicDataEndpointEnabled":false,"proxyOverride":"Proxy","timezoneId":"UTC"},"location":"westus","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-secondary","name":"geodrmitestgp-secondary","type":"Microsoft.Sql/managedInstances"}'
Expand Down Expand Up @@ -117,7 +117,7 @@ interactions:
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-01?api-version=2015-05-01-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-01?api-version=2018-06-01-preview
response:
body:
string: !!python/unicode '{"identity":{"principalId":"8b8ac196-72ec-43a7-9020-ab1d5fc498cb","type":"SystemAssigned","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47"},"sku":{"name":"GP_Gen4","tier":"GeneralPurpose","family":"Gen4","capacity":8},"properties":{"fullyQualifiedDomainName":"geodrmitestgp-01.eus113708aec224c.database.windows.net","administratorLogin":"cloudSA","subnetId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Network/virtualNetworks/geodrEastUSvnet/subnets/default","state":"Ready","licenseType":"LicenseIncluded","vCores":8,"storageSizeInGB":512,"collation":"SQL_Latin1_General_CP1_CI_AS","dnsZone":"eus113708aec224c","publicDataEndpointEnabled":false},"location":"eastus","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-01","name":"geodrmitestgp-01","type":"Microsoft.Sql/managedInstances"}'
Expand Down Expand Up @@ -167,7 +167,7 @@ interactions:
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-secondary?api-version=2015-05-01-preview
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-secondary?api-version=2018-06-01-preview
response:
body:
string: !!python/unicode '{"identity":{"principalId":"647bf67a-773a-4b36-af4c-4162e766a4b8","type":"SystemAssigned","tenantId":"72f988bf-86f1-41af-91ab-2d7cd011db47"},"sku":{"name":"GP_Gen5","tier":"GeneralPurpose","family":"Gen5","capacity":8},"properties":{"fullyQualifiedDomainName":"geodrmitestgp-secondary.eus113708aec224c.database.windows.net","administratorLogin":"cloudSA","subnetId":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Network/virtualNetworks/vnet-geodrmitestgp-secondary/subnets/ManagedInstance","state":"Ready","licenseType":"LicenseIncluded","vCores":8,"storageSizeInGB":512,"collation":"SQL_Latin1_General_CP1_CI_AS","dnsZone":"eus113708aec224c","publicDataEndpointEnabled":false,"proxyOverride":"Proxy","timezoneId":"UTC"},"location":"westus","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/geodrCLtestRG/providers/Microsoft.Sql/managedInstances/geodrmitestgp-secondary","name":"geodrmitestgp-secondary","type":"Microsoft.Sql/managedInstances"}'
Expand Down
Loading