Skip to content
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

[SQL] Add new commands sql db classification show/list/update/delete and sql db classification recommendation list/enable/disable to manage sensitivity classifications for SQL databases. #11597

Merged
merged 27 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1381e56
New commands `sql db sensitivity-labels show/list/list-recommended/up…
ranisha2 Dec 17, 2019
807a51c
Merge pull request #1 from Azure/dev
ranisha2 Dec 17, 2019
6539e90
Sync
ranisha2 Dec 17, 2019
0b3b0e2
Fix history file
ranisha2 Dec 17, 2019
e8f4ae3
Fix failing style checks
ranisha2 Dec 17, 2019
b9e3779
Fix help
ranisha2 Dec 24, 2019
c410ffc
Sync
ranisha2 Dec 29, 2019
2d97b8c
Merge branch 'Azure-dev' into dev
ranisha2 Dec 29, 2019
21e46c0
Use g.command() for list, list-recommended, delete, enable-recommenda…
ranisha2 Dec 29, 2019
f559e67
rename sensitivity-labels to sensitivity-classification and add anoth…
ranisha2 Jan 5, 2020
e991537
Merge pull request #3 from Azure/dev
ranisha2 Jan 5, 2020
72715a7
Fix sensitivity classifications test after sync
ranisha2 Jan 5, 2020
55b9c25
Rename command from `sensitivity-classification` to `classification`
ranisha2 Jan 8, 2020
5005b6f
information_type and label_name should not be required
ranisha2 Jan 8, 2020
eaf00a5
Sync
ranisha2 Jan 13, 2020
8973051
Merge branch 'Azure-dev2' into dev
ranisha2 Jan 13, 2020
651d155
SQl classification - fix comments
ranisha2 Jan 14, 2020
f860bd4
Merge pull request #6 from Azure/dev
ranisha2 Jan 14, 2020
da02257
Sync
ranisha2 Jan 14, 2020
af8b772
SQL classification Additional fixes
ranisha2 Jan 14, 2020
b099a1d
Update help
ranisha2 Jan 14, 2020
5656d74
Sync
ranisha2 Jan 19, 2020
3bcd4ea
Merge branch 'Azure-dev0' into dev
ranisha2 Jan 19, 2020
c715ee2
SQL classification - show command should be seperated for current/rec…
ranisha2 Jan 19, 2020
36052f6
Sync and resolve conflicts
ranisha2 Jan 23, 2020
61afb67
Merge branch 'Azure-dev44' into dev
ranisha2 Jan 23, 2020
2a25df0
Merge branch 'dev' into dev
Juliehzl Jan 30, 2020
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 @@ -60,6 +60,10 @@ Release History
* Update azure-mgmt-storage version to 7.0.0 to use api version 2019-06-01
* Add new parameters `--enable-delete-retention` and `--delete-retention-days` to support managing delete retention policy for storage account blob-service-properties.

**SQL**
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved

* New commands `sql db classification show/list/update/delete` and `sql db classification recommendation list/enable/disable` to manage sensitivity classifications for SQL databases.

2.0.78
++++++

Expand Down
66 changes: 66 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 @@ -825,3 +825,69 @@
- name: Get the details for a virtual cluster
text: az sql virtual-cluster show -g mygroup -n mycluster
"""

helps['sql db classification'] = """
type: group
short-summary: Manage sensitivity classifications.
"""

helps['sql db classification update'] = """
type: command
short-summary: Update a columns's sensitivity classification.
examples:
- name: Update sensitivity classification for a given column.
text: az sql db classification update -g mygroup -s myserver -n mydb --schema-name dbo --table-name mytable --column-name mycolumn --information-type Name --label-name "Confidential - GDPR"
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved
"""

helps['sql db classification list'] = """
type: command
short-summary: Get the sensitivity classifications of a given database.
examples:
- name: List the sensitivity classification of a given database.
text: az sql db classification list -g mygroup -s myserver -n mydb
"""

helps['sql db classification show'] = """
type: command
short-summary: Get the sensitivity classification of a given column.
examples:
- name: Get the sensitivity classification of a given column.
text: az sql db classification show -g mygroup -s myserver -n mydb --schema-name dbo --table-name mytable --column-name mycolumn --sensitivity-label-source current
"""

helps['sql db classification delete'] = """
type: command
short-summary: Delete the sensitivity classification of a given column.
examples:
- name: Delete the sensitivity classification of a given column.
text: az sql db classification delete -g mygroup -s myserver -n mydb --schema-name dbo --table-name mytable --column-name mycolumn
"""

helps['sql db classification recommendation'] = """
type: group
short-summary: Manage sensitivity classification recommendations.
"""

helps['sql db classification recommendation list'] = """
type: command
short-summary: List the recommended sensitivity classifications of a given database.
examples:
- name: List the recommended sensitivity classifications of a given database.
text: az sql db classification recommendation list -g mygroup -s myserver -n mydb
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved
"""

helps['sql db classification recommendation enable'] = """
type: command
short-summary: Enable sensitivity recommendations for a given column (recommendations are enabled by default on all columns).
examples:
- name: Enable sensitivity recommendations for a given column.
text: az sql db classification recommendation enable -g mygroup -s myserver -n mydb --schema-name dbo --table-name mytable --column-name mycolumn
"""

helps['sql db classification recommendation disable'] = """
type: command
short-summary: Disable sensitivity recommendations for a given column (recommendations are enabled by default on all columns).
examples:
- name: Disable sensitivity recommendations for a given column.
text: az sql db classification recommendation disable -g mygroup -s myserver -n mydb --schema-name dbo --table-name mytable --column-name mycolumn
"""
24 changes: 24 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,3 +1422,27 @@ def _configure_security_policy_storage_params(arg_ctx):

c.argument('allow_data_loss',
arg_type=allow_data_loss_param_type)

###################################################
# sql sensitivity classification #
###################################################
with self.argument_context('sql db classification update') as c:
c.argument('schema_name',
required=True,
help='The name of the schema.')

c.argument('table_name',
required=True,
help='The name of the table.')

c.argument('column_name',
required=True,
help='The name of the column.')

c.argument('information_type',
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved
required=False,
help='The information type.')

c.argument('label_name',
required=False,
help='The label name')
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 @@ -40,6 +40,10 @@ def get_sql_database_blob_auditing_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).database_blob_auditing_policies


def get_sql_database_sensitivity_labels_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).sensitivity_labels


def get_sql_database_threat_detection_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).database_threat_detection_policies

Expand Down
22 changes: 22 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 @@ -25,6 +25,7 @@
get_sql_capabilities_operations,
get_sql_databases_operations,
get_sql_database_blob_auditing_policies_operations,
get_sql_database_sensitivity_labels_operations,
get_sql_database_operations_operations,
get_sql_database_threat_detection_policies_operations,
get_sql_database_transparent_data_encryption_activities_operations,
Expand Down Expand Up @@ -231,6 +232,27 @@ def load_command_table(self, _):
g.generic_update_command('update',
custom_func_name='db_audit_policy_update')

database_sensitivity_labels_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#SensitivityLabelsOperations.{}',
client_factory=get_sql_database_sensitivity_labels_operations)

with self.command_group('sql db classification',
database_sensitivity_labels_operations,
client_factory=get_sql_database_sensitivity_labels_operations) as g:

g.command('list', 'list_current_by_database')
g.show_command('show', 'get')
g.command('delete', 'delete')
g.custom_command('update', 'db_sensitivity_label_update')

with self.command_group('sql db classification recommendation',
database_sensitivity_labels_operations,
client_factory=get_sql_database_sensitivity_labels_operations) as g:

g.custom_command('list', 'db_recommended_sensitivity_labels_list')
g.command('enable', 'enable_recommendation')
g.command('disable', 'disable_recommendation')

database_threat_detection_policies_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#DatabaseThreatDetectionPoliciesOperations.{}',
client_factory=get_sql_database_threat_detection_policies_operations)
Expand Down
81 changes: 81 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,87 @@ def db_threat_detection_policy_update(
return instance


def db_recommended_sensitivity_labels_list(
client,
database_name,
server_name,
resource_group_name):
return client.list_recommended_by_database(resource_group_name, server_name, database_name)


def db_sensitivity_label_update(
cmd,
client,
database_name,
server_name,
schema_name,
table_name,
column_name,
resource_group_name,
label_name=None,
information_type=None):
'''
Updates a sensitivity label. Custom update function to apply parameters to instance.
'''

# Get the information protection policy
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.security import SecurityCenter
from msrestazure.azure_exceptions import CloudError

securityCenterclient = get_mgmt_service_client(cmd.cli_ctx, SecurityCenter, asc_location="centralus")
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved

informationProtectionPolicy = securityCenterclient.information_protection_policies.get(
scope='/providers/Microsoft.Management/managementGroups/{}'.format(_get_tenant_id()),
information_protection_policy_name="effective")

params = {
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved
'label_name': None,
'label_id': None,
'information_type': None,
'information_type_id': None}

# Get the current label
try:
current_label = client.get(
resource_group_name, server_name, database_name, schema_name, table_name, column_name, 'current')
ranisha2 marked this conversation as resolved.
Show resolved Hide resolved
# Initialize with existing values
params = {
'label_name': current_label.label_name,
'label_id': current_label.label_id,
'information_type': current_label.information_type,
'information_type_id': current_label.information_type_id}

except CloudError as ex:
if not(ex.error and ex.error.error and 'SensitivityLabelsLabelNotFound' in ex.error.error):
raise ex

# Find the label id and information type id in the policy by the label name provided
label_id = None
if label_name:
label_id = next((id for id in informationProtectionPolicy.labels
if informationProtectionPolicy.labels[id].display_name.lower() ==
label_name.lower()),
None)
if label_id is None:
raise CLIError('The provided label name was not found in the information protection policy.')
params['label_id'] = label_id
params['label_name'] = label_name
information_type_id = None
if information_type:
information_type_id = next((id for id in informationProtectionPolicy.information_types
if informationProtectionPolicy.information_types[id].display_name.lower() ==
information_type.lower()),
None)
if information_type_id is None:
raise CLIError('The provided information type was not found in the information protection policy.')
params['information_type_id'] = information_type_id
params['information_type'] = information_type

return client.create_or_update(
resource_group_name, server_name, database_name, schema_name, table_name, column_name, params)


###############################################
# sql dw #
###############################################
Expand Down
Loading