Skip to content

Commit ba95c2c

Browse files
Vidhi-2510Vidhi Katyalhiaga
authored
[BACKUP] Added support for Customer Managed Keys(CMK) for Recovery Services Vault (Azure#18733)
* Merged with commit added support for CMK feature * Merged with commit Changes made * Merged with commit More changes * Changes with new version * Linter file changed * Changed test file * encryption test changed * Help Text Changed * Changes in command * help_text changed again * modified param names based on review comments * Encryption examples added Co-authored-by: Vidhi Katyal <[email protected]> Co-authored-by: Himanshu Agarwal <[email protected]>
1 parent 3823edf commit ba95c2c

34 files changed

+74277
-49792
lines changed

linter_exclusions.yml

+5
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,11 @@ backup vault backup-properties set:
819819
cross_region_restore_flag:
820820
rule_exclusions:
821821
- option_length_too_long
822+
backup vault encryption update:
823+
parameters:
824+
infrastructure_encryption:
825+
rule_exclusions:
826+
- option_length_too_long
822827
batch account create:
823828
parameters:
824829
encryption_key_identifier:

src/azure-cli/azure/cli/command_modules/backup/_client_factory.py

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ def backup_resource_vault_config_cf(cli_ctx, *_):
170170
return _backup_client_factory(cli_ctx).backup_resource_vault_configs
171171

172172

173+
def backup_resource_encryption_config_cf(cli_ctx, *_):
174+
return _backup_client_factory(cli_ctx).backup_resource_encryption_configs
175+
176+
173177
# Azure Active Directory Client Factories
174178
def aad_properties_cf(cli_ctx, *_):
175179
return _backup_client_factory(cli_ctx).aad_properties

src/azure-cli/azure/cli/command_modules/backup/_help.py

+48
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,51 @@
495495
text: az backup vault show --name MyRecoveryServicesVault --resource-group MyResourceGroup
496496
crafted: true
497497
"""
498+
helps['backup vault identity'] = """
499+
type: group
500+
short-summary: Identity details of a Recovery Services Vault.
501+
"""
502+
helps['backup vault identity assign'] = """
503+
type: command
504+
short-summary: Assign Identities to Recovery Services vault.
505+
examples:
506+
- name: Assign Identities to Recovery Services vault. (autogenerated)
507+
text: az backup vault identity assign --system-assigned --user-assigned MyIdentityId1 --resource-group MyResourceGroup --vault-name MyVault
508+
crafted: true
509+
"""
510+
helps['backup vault identity remove'] = """
511+
type: command
512+
short-summary: Remove Identities of Recovery Services vault.
513+
examples:
514+
- name: Remove Identities of Recovery Services vault. (autogenerated)
515+
text: az backup vault identity remove --system-assigned --user-assigned MyIdentityId1 --resource-group MyResourceGroup --vault-name MyVault
516+
crafted: true
517+
"""
518+
helps['backup vault identity show'] = """
519+
type: command
520+
short-summary: Show Identities of Recovery Services vault.
521+
examples:
522+
- name: Show Identities of Recovery Services vault. (autogenerated)
523+
text: az backup vault identity show --resource-group MyResourceGroup --vault-name MyVault
524+
crafted: true
525+
"""
526+
helps['backup vault encryption'] = """
527+
type: group
528+
short-summary: Encryption details of a Recovery Services Vault.
529+
"""
530+
helps['backup vault encryption update'] = """
531+
type: command
532+
short-summary: Update encryption properties of a Recovery Services Vault.
533+
examples:
534+
- name: Update encryption properties to use user assigned identity of a Recovery Services Vault.
535+
text: az backup vault encryption update --encryption-key-id MyEncryptionKeyId --mi-user-assigned MyUserAssignedIdentityId --resource-group MyResourceGroup --vault-name MyVault
536+
- name: Update encryption properties to use system assigned identity of a Recovery Services Vault.
537+
text: az backup vault encryption update --encryption-key-id MyEncryptionKeyId --mi-system-assigned --resource-group MyResourceGroup --vault-name MyVault
538+
"""
539+
helps['backup vault encryption show'] = """
540+
type: command
541+
short-summary: Show details of encryption properties of a Recovery Services Vault.
542+
examples:
543+
- name: Show details of encryption properties of a Recovery Services Vault.
544+
text: az backup vault encryption show --resource-group MyResourceGroup --vault-name MyVault
545+
"""

src/azure-cli/azure/cli/command_modules/backup/_params.py

+37
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
target_tier_help = """ The destination/target tier to which a particular recovery point has to be moved."""
4747
tier_help = """ Provide 'tier' parameter to filter recovery points."""
4848
rehyd_priority_type_help = """The type of priority to be maintained while rehydrating a recovery point """
49+
infrastructure_encryption_type_help = """Use this parameter to enable/disable infrastructure encryption. This must be set when configuring encryption of the vault for the first time. Once enabled/disabled, infrastructure encryption setting cannot be changed. Default value: Disabled. Allowed values: Enabled, Disabled"""
4950

5051
vault_name_type = CLIArgumentType(help='Name of the Recovery services vault.', options_list=['--vault-name', '-v'], completer=get_resource_name_completion_list('Microsoft.RecoveryServices/vaults'))
5152
container_name_type = CLIArgumentType(help=container_name_help, options_list=['--container-name', '-c'])
@@ -71,6 +72,14 @@
7172
target_tier_type = CLIArgumentType(help=target_tier_help, arg_type=get_enum_type(allowed_target_tier_type_chk_archivable), options_list=['--target-tier'])
7273
tier_type = CLIArgumentType(help=tier_help, arg_type=get_enum_type(allowed_tier_type), options_list=['--tier'])
7374
rehyd_priority_type = CLIArgumentType(help=rehyd_priority_type_help, arg_type=get_enum_type(allowed_rehyd_priority_type), options_list=['--rehydration-priority'])
75+
mi_user_assigned_type = CLIArgumentType(options_list=['--mi-user-assigned'], help="UserAssigned Identity Id to be used for CMK encryption, this will be applicable for encryption using userassigned identity")
76+
mi_system_assigned_type = CLIArgumentType(action='store_true', options_list=['--mi-system-assigned'], help="Provide this flag to use system assigned identity for encryption.")
77+
encryption_key_id_type = CLIArgumentType(options_list=['--encryption-key-id'], help="The encryption key id you want to use for encryption")
78+
infrastructure_encryption_type = CLIArgumentType(options_list=['--infrastructure-encryption'], arg_type=get_enum_type(['Enabled', 'Disabled']), help=infrastructure_encryption_type_help)
79+
user_assigned_type = CLIArgumentType(nargs='+', options_list=['--user-assigned'], help="Space-separated list of userassigned identities to be assigned to Recovery Services Vault.")
80+
user_assigned_remove_type = CLIArgumentType(nargs='*', options_list=['--user-assigned'], help="Space-separated list of userassigned identities to be removed from Recovery Services Vault.")
81+
system_assigned_remove_type = CLIArgumentType(action='store_true', options_list=['--system-assigned'], help="Provide this flag to remove system assigned identity for Recovery Services Vault.")
82+
system_assigned_type = CLIArgumentType(action='store_true', options_list=['--system-assigned'], help="Provide this flag to enable system assigned identity for Recovery Services Vault.")
7483

7584

7685
# pylint: disable=too-many-statements
@@ -92,6 +101,33 @@ def load_arguments(self, _):
92101
c.argument('soft_delete_feature_state', arg_type=get_enum_type(['Enable', 'Disable']), help='Set soft-delete feature state for a Recovery Services Vault.')
93102
c.argument('cross_region_restore_flag', arg_type=get_enum_type(['True', 'False']), help='Set cross-region-restore feature state for a Recovery Services Vault. Default: False.')
94103

104+
# Identity
105+
with self.argument_context('backup vault identity assign') as c:
106+
c.argument('vault_name', vault_name_type)
107+
c.argument('system_assigned', system_assigned_type)
108+
c.argument('user_assigned', user_assigned_type)
109+
110+
with self.argument_context('backup vault identity remove') as c:
111+
c.argument('vault_name', vault_name_type)
112+
c.argument('system_assigned', system_assigned_remove_type)
113+
c.argument('user_assigned', user_assigned_remove_type)
114+
115+
with self.argument_context('backup vault identity show') as c:
116+
c.argument('vault_name', vault_name_type)
117+
118+
# Encryption
119+
with self.argument_context('backup vault encryption') as c:
120+
c.argument('vault_name', vault_name_type)
121+
122+
with self.argument_context('backup vault encryption update') as c:
123+
c.argument('encryption_key_id', encryption_key_id_type)
124+
c.argument('infrastructure_encryption', infrastructure_encryption_type)
125+
c.argument('mi_user_assigned', mi_user_assigned_type)
126+
c.argument('mi_system_assigned', mi_system_assigned_type)
127+
128+
with self.argument_context('backup vault encryption show') as c:
129+
c.argument('vault_name', vault_name_type)
130+
95131
# Container
96132
with self.argument_context('backup container') as c:
97133
c.argument('vault_name', vault_name_type, id_part='name')
@@ -308,6 +344,7 @@ def load_arguments(self, _):
308344
c.argument('use_secondary_region', action='store_true', help='Use this flag to show recoverypoints in secondary region.')
309345
c.argument('rehydration_duration', type=int, help='Set the maximum time, in days (between 10-30, both inclusive) for which the recovery point stays in hydrated state. Default: 15')
310346
c.argument('rehydration_priority', rehyd_priority_type)
347+
c.argument('disk_encryption_set_id', options_list=['--disk-encryption-set-id'], help='The disk encryption set id is used for encrypting restored disks. Please ensure access to disk encryption set id that is specified here.')
311348

312349
with self.argument_context('backup restore restore-azurefileshare') as c:
313350
c.argument('resolve_conflict', resolve_conflict_type)

src/azure-cli/azure/cli/command_modules/backup/commands.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
protection_policies_cf, backup_policies_cf, protected_items_cf, backups_cf, backup_jobs_cf, \
99
job_details_cf, job_cancellations_cf, recovery_points_cf, restores_cf, backup_storage_configs_cf, \
1010
item_level_recovery_connections_cf, backup_protected_items_cf, backup_protectable_items_cf, \
11-
protection_containers_cf, protection_intent_cf # pylint: disable=unused-variable
12-
11+
protection_containers_cf, protection_intent_cf, backup_resource_encryption_config_cf # pylint: disable=unused-variable
1312
from azure.cli.command_modules.backup._format import (
1413
transform_container_list, transform_policy_list, transform_item_list, transform_job_list,
1514
transform_recovery_point_list, transform_container, transform_item, transform_protectable_item_list, transform_job,
@@ -35,6 +34,11 @@ def load_command_table(self, _):
3534
g.custom_command('backup-properties show', 'get_backup_properties', client_factory=backup_storage_configs_cf)
3635
g.custom_command('backup-properties set', 'set_backup_properties', client_factory=backup_storage_configs_cf)
3736
g.custom_command('delete', 'delete_vault', confirmation=True)
37+
g.custom_command('identity assign', 'assign_identity')
38+
g.custom_command('identity remove', 'remove_identity')
39+
g.custom_command('identity show', 'show_identity')
40+
g.custom_command('encryption update', 'update_encryption')
41+
g.custom_command('encryption show', 'show_encryption', client_factory=backup_resource_encryption_config_cf)
3842

3943
with self.command_group('backup container', backup_custom_base, client_factory=protection_containers_cf) as g:
4044
g.show_command('show', 'show_container', client_factory=backup_protection_containers_cf, table_transformer=transform_container)

0 commit comments

Comments
 (0)