Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
az keyvault set-policy/delete-policy: Support --application-id
  • Loading branch information
evelyn-ys committed May 25, 2021
commit fd8d79e55b09bf2ec09bf85a0b0ceda28dc40774
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/keyvault/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@ class CLISecurityDomainOperation(str, Enum):

with self.argument_context('keyvault delete-policy') as c:
c.argument('object_id', validator=validate_principal)
c.argument('application_id', help='Application ID of the client making request on behalf of a principal. '
'Exposed for compound identity using on-behalf-of authentication flow.')

with self.argument_context('keyvault set-policy', arg_group='Permission') as c:
c.argument('object_id', validator=validate_principal)
c.argument('application_id', help='Application ID of the client making request on behalf of a principal. '
'Exposed for compound identity using on-behalf-of authentication flow.')
c.argument('key_permissions', arg_type=get_enum_type(KeyPermissions), metavar='PERM', nargs='*',
help='Space-separated list of key permissions to assign.', validator=validate_policy_permissions)
c.argument('secret_permissions', arg_type=get_enum_type(SecretPermissions), metavar='PERM', nargs='*',
Expand Down
10 changes: 6 additions & 4 deletions src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def _permissions_distinct(permissions):


def set_policy(cmd, client, resource_group_name, vault_name,
object_id=None, spn=None, upn=None, key_permissions=None, secret_permissions=None,
object_id=None, application_id=None, spn=None, upn=None, key_permissions=None, secret_permissions=None,
certificate_permissions=None, storage_permissions=None, no_wait=False):
""" Update security policy settings for a Key Vault. """

Expand All @@ -912,13 +912,14 @@ def set_policy(cmd, client, resource_group_name, vault_name,

# Find the existing policy to set
policy = next((p for p in vault.properties.access_policies
if object_id.lower() == p.object_id.lower() and
if object_id.lower() == p.object_id.lower() and application_id == p.application_id and
vault.properties.tenant_id.lower() == p.tenant_id.lower()), None)
if not policy:
# Add new policy as none found
vault.properties.access_policies.append(AccessPolicyEntry(
tenant_id=vault.properties.tenant_id,
object_id=object_id,
application_id=application_id,
permissions=Permissions(keys=key_permissions,
secrets=secret_permissions,
certificates=certificate_permissions,
Expand Down Expand Up @@ -1043,7 +1044,8 @@ def list_network_rules(cmd, client, resource_group_name, vault_name): # pylint:
return vault.properties.network_acls


def delete_policy(cmd, client, resource_group_name, vault_name, object_id=None, spn=None, upn=None, no_wait=False):
def delete_policy(cmd, client, resource_group_name, vault_name,
object_id=None, application_id=None, spn=None, upn=None, no_wait=False):
""" Delete security policy settings for a Key Vault. """
VaultCreateOrUpdateParameters = cmd.get_models('VaultCreateOrUpdateParameters',
resource_type=ResourceType.MGMT_KEYVAULT)
Expand All @@ -1062,7 +1064,7 @@ def delete_policy(cmd, client, resource_group_name, vault_name, object_id=None,
prev_policies_len = len(vault.properties.access_policies)
vault.properties.access_policies = [p for p in vault.properties.access_policies if
vault.properties.tenant_id.lower() != p.tenant_id.lower() or
object_id.lower() != p.object_id.lower()]
object_id.lower() != p.object_id.lower() or application_id != p.application_id]
if len(vault.properties.access_policies) == prev_policies_len:
raise CLIError('No matching policies found')

Expand Down
Loading