-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Keyvault} Remove useless AAD endpoint and honor user input --subscription to support cross sub operations
#26539
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -401,15 +401,14 @@ def recover_vault_or_hsm(cmd, client, resource_group_name=None, location=None, v | |
|
|
||
|
|
||
| def recover_hsm(cmd, client, hsm_name, resource_group_name, location, no_wait=False): | ||
| from azure.cli.core._profile import Profile | ||
| from azure.cli.core._profile import Profile, _TENANT_ID | ||
|
|
||
| ManagedHsm = cmd.get_models('ManagedHsm', resource_type=ResourceType.MGMT_KEYVAULT) | ||
| ManagedHsmSku = cmd.get_models('ManagedHsmSku', resource_type=ResourceType.MGMT_KEYVAULT) | ||
|
|
||
| # tenantId and sku shouldn't be required | ||
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| _, _, tenant_id = profile.get_login_credentials( | ||
| resource=cmd.cli_ctx.cloud.endpoints.active_directory_graph_resource_id) | ||
|
Comment on lines
-411
to
-412
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is indeed why a token for AD Graph is retrieved. class MSIAuthentication(BasicTokenAuthentication):
def __init__(self, port=50342, **kwargs):
....
self.set_token()When This behavior will be changed in #25959 in order to align with other MSAL-based credentials -
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another question, why does the original code choose Update: Well. It looks like #3631 simply copied the code for creating AD Graph client but only kept the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This explains why AAD call shows up when we create keyvault in Cloudshell sandbox as it's following MSI workflow.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway the whole call for |
||
| tenant_id = profile.get_subscription(subscription=cmd.cli_ctx.data.get('subscription_id', None))[_TENANT_ID] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| # Use 'Recover' as 'create_mode' temporarily since it's a bug from service side making 'create_mode' case-sensitive | ||
| # Will change it back to CreateMode.recover.value('recover') from SDK definition after service fix | ||
|
|
@@ -426,7 +425,7 @@ def recover_hsm(cmd, client, hsm_name, resource_group_name, location, no_wait=Fa | |
|
|
||
|
|
||
| def recover_vault(cmd, client, vault_name, resource_group_name, location, no_wait=False): | ||
| from azure.cli.core._profile import Profile | ||
| from azure.cli.core._profile import Profile, _TENANT_ID | ||
|
|
||
| VaultCreateOrUpdateParameters = cmd.get_models('VaultCreateOrUpdateParameters', | ||
| resource_type=ResourceType.MGMT_KEYVAULT) | ||
|
|
@@ -436,8 +435,7 @@ def recover_vault(cmd, client, vault_name, resource_group_name, location, no_wai | |
| Sku = cmd.get_models('Sku', resource_type=ResourceType.MGMT_KEYVAULT) | ||
| SkuName = cmd.get_models('SkuName', resource_type=ResourceType.MGMT_KEYVAULT) | ||
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| _, _, tenant_id = profile.get_login_credentials( | ||
| resource=cmd.cli_ctx.cloud.endpoints.active_directory_graph_resource_id) | ||
| tenant_id = profile.get_subscription(subscription=cmd.cli_ctx.data.get('subscription_id', None))[_TENANT_ID] | ||
|
|
||
| params = VaultCreateOrUpdateParameters(location=location, | ||
| properties={'tenant_id': tenant_id, | ||
|
|
@@ -596,7 +594,7 @@ def create_hsm(cmd, client, | |
|
|
||
| administrators = [admin.strip().replace('\r', '').replace('\n', '') for admin in administrators] | ||
|
|
||
| from azure.cli.core._profile import Profile | ||
| from azure.cli.core._profile import Profile, _TENANT_ID | ||
|
|
||
| if not sku: | ||
| sku = 'Standard_B1' | ||
|
|
@@ -606,8 +604,7 @@ def create_hsm(cmd, client, | |
| ManagedHsmSku = cmd.get_models('ManagedHsmSku', resource_type=ResourceType.MGMT_KEYVAULT) | ||
|
|
||
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| _, _, tenant_id = profile.get_login_credentials( | ||
| resource=cmd.cli_ctx.cloud.endpoints.active_directory_graph_resource_id) | ||
| tenant_id = profile.get_subscription(subscription=cmd.cli_ctx.data.get('subscription_id', None))[_TENANT_ID] | ||
|
|
||
| properties = ManagedHsmProperties(tenant_id=tenant_id, | ||
| enable_purge_protection=enable_purge_protection, | ||
|
|
@@ -656,7 +653,7 @@ def create_vault(cmd, client, # pylint: disable=too-many-locals, too-many-state | |
| # if client.get raise exception, we can take it as no existing vault found | ||
| # just continue the normal creation process | ||
| pass | ||
| from azure.cli.core._profile import Profile | ||
| from azure.cli.core._profile import Profile, _TENANT_ID | ||
| from azure.cli.command_modules.role import graph_client_factory, GraphError | ||
|
|
||
| VaultCreateOrUpdateParameters = cmd.get_models('VaultCreateOrUpdateParameters', | ||
|
|
@@ -671,11 +668,9 @@ def create_vault(cmd, client, # pylint: disable=too-many-locals, too-many-state | |
| VaultProperties = cmd.get_models('VaultProperties', resource_type=ResourceType.MGMT_KEYVAULT) | ||
|
|
||
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| _, _, tenant_id = profile.get_login_credentials( | ||
| resource=cmd.cli_ctx.cloud.endpoints.active_directory_graph_resource_id) | ||
|
|
||
| graph_client = graph_client_factory(cmd.cli_ctx) | ||
| subscription = profile.get_subscription() | ||
| subscription = profile.get_subscription(subscription=cmd.cli_ctx.data.get('subscription_id', None)) | ||
| tenant_id = subscription[_TENANT_ID] | ||
|
|
||
| # if bypass or default_action was specified create a NetworkRuleSet | ||
| # if neither were specified we will parse it from parameter `--network-acls` | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.