Skip to content

Commit 5f550a5

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-cli into support-confidential-vm-v2
2 parents 40c6439 + 91236a1 commit 5f550a5

File tree

6 files changed

+27
-39
lines changed

6 files changed

+27
-39
lines changed

src/azure-cli-core/azure/cli/core/_profile.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,20 @@ def get_raw_token(self, resource=None, scopes=None, subscription=None, tenant=No
360360

361361
managed_identity_type, managed_identity_id = Profile._parse_managed_identity_account(account)
362362

363+
non_current_tenant_template = ("For {} account, getting access token for non-current tenants is not "
364+
"supported. The specified tenant must be the current tenant "
365+
f"{account[_TENANT_ID]}")
363366
if in_cloud_console() and account[_USER_ENTITY].get(_CLOUD_SHELL_ID):
364367
# Cloud Shell
365-
if tenant:
366-
raise CLIError("Tenant shouldn't be specified for Cloud Shell account")
368+
if tenant and tenant != account[_TENANT_ID]:
369+
raise CLIError(non_current_tenant_template.format('Cloud Shell'))
367370
from .auth.msal_credentials import CloudShellCredential
368371
cred = CloudShellCredential()
369372

370373
elif managed_identity_type:
371374
# managed identity
372-
if tenant:
373-
raise CLIError("Tenant shouldn't be specified for managed identity account")
375+
if tenant and tenant != account[_TENANT_ID]:
376+
raise CLIError(non_current_tenant_template.format('managed identity'))
374377
cred = ManagedIdentityAuth.credential_factory(managed_identity_type, managed_identity_id)
375378
if credential_out:
376379
credential_out['credential'] = cred

src/azure-cli-core/azure/cli/core/tests/test_profile.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,9 +1134,15 @@ def test_get_raw_token_mi_system_assigned(self):
11341134
self.assertEqual(subscription_id, self.test_mi_subscription_id)
11351135
self.assertEqual(tenant_id, self.test_mi_tenant)
11361136

1137-
# verify tenant shouldn't be specified for MSI account
1138-
with self.assertRaisesRegex(CLIError, "Tenant shouldn't be specified"):
1139-
cred, subscription_id, _ = profile.get_raw_token(resource='http://test_resource', tenant=self.tenant_id)
1137+
# Specifying the current tenant is allowed
1138+
cred, subscription_id, tenant_id = profile.get_raw_token(tenant=self.test_mi_tenant)
1139+
self.assertEqual(tenant_id, self.test_mi_tenant)
1140+
1141+
# Specifying a non-current tenant is disallowed
1142+
with self.assertRaisesRegex(CLIError,
1143+
"For managed identity account, getting access token for non-current tenants is "
1144+
"not supported"):
1145+
profile.get_raw_token(tenant='another-tenant')
11401146

11411147
@mock.patch('azure.cli.core.auth.util.now_timestamp', new=now_timestamp_mock)
11421148
@mock.patch('azure.cli.core.auth.msal_credentials.ManagedIdentityCredential', ManagedIdentityCredentialStub)
@@ -1285,9 +1291,15 @@ def cloud_shell_credential_factory():
12851291
self.assertEqual(subscription_id, test_subscription_id)
12861292
self.assertEqual(tenant_id, test_tenant_id)
12871293

1288-
# Verify tenant shouldn't be specified for Cloud Shell account
1289-
with self.assertRaisesRegex(CLIError, 'Cloud Shell'):
1290-
profile.get_raw_token(resource='http://test_resource', tenant=self.tenant_id)
1294+
# Specifying the current tenant is allowed
1295+
cred, subscription_id, tenant_id = profile.get_raw_token(tenant=test_tenant_id)
1296+
self.assertEqual(tenant_id, test_tenant_id)
1297+
1298+
# Specifying a non-current tenant is disallowed
1299+
with self.assertRaisesRegex(CLIError,
1300+
"For Cloud Shell account, getting access token for non-current tenants is "
1301+
"not supported"):
1302+
profile.get_raw_token(tenant='another-tenant')
12911303

12921304
@mock.patch('azure.cli.core.auth.identity.Identity.get_user_credential')
12931305
def test_get_msal_token(self, get_user_credential_mock):

src/azure-cli-core/azure/cli/core/util.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
11641164

11651165

11661166
def _ssl_context():
1167-
if sys.version_info < (3, 4) or (in_cloud_console() and platform.system() == 'Windows'):
1168-
try:
1169-
return ssl.SSLContext(ssl.PROTOCOL_TLS) # added in python 2.7.13 and 3.6
1170-
except AttributeError:
1171-
return ssl.SSLContext(ssl.PROTOCOL_TLSv1)
1172-
11731167
return ssl.create_default_context()
11741168

11751169

src/azure-cli/azure/cli/command_modules/acr/helm.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from knack.util import CLIError
1111
from knack.log import get_logger
1212

13-
from azure.cli.core.util import in_cloud_console, user_confirmation
13+
from azure.cli.core.util import user_confirmation
1414

1515
from ._docker_utils import (
1616
get_access_credentials,
@@ -366,15 +366,7 @@ def _get_helm_package_name(client_version):
366366

367367

368368
def _ssl_context():
369-
import sys
370369
import ssl
371-
372-
if sys.version_info < (3, 4) or (in_cloud_console() and platform.system() == 'Windows'):
373-
try:
374-
return ssl.SSLContext(ssl.PROTOCOL_TLS) # added in python 2.7.13 and 3.6
375-
except AttributeError:
376-
return ssl.SSLContext(ssl.PROTOCOL_TLSv1)
377-
378370
return ssl.create_default_context()
379371

380372

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,13 +2218,6 @@ def k8s_install_kubelogin(cmd, client_version='latest', install_location=None, s
22182218

22192219

22202220
def _ssl_context():
2221-
if sys.version_info < (3, 4) or (in_cloud_console() and platform.system() == 'Windows'):
2222-
try:
2223-
# added in python 2.7.13 and 3.6
2224-
return ssl.SSLContext(ssl.PROTOCOL_TLS)
2225-
except AttributeError:
2226-
return ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2227-
22282221
return ssl.create_default_context()
22292222

22302223

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
from azure.cli.core.commands.client_factory import get_mgmt_service_client
4343
from azure.cli.core.commands import LongRunningOperation
44-
from azure.cli.core.util import in_cloud_console, shell_safe_json_parse, open_page_in_browser, get_json_object, \
44+
from azure.cli.core.util import shell_safe_json_parse, open_page_in_browser, get_json_object, \
4545
ConfiguredDefaultSetter, sdk_no_wait
4646
from azure.cli.core.util import get_az_user_agent, send_raw_request, get_file_json
4747
from azure.cli.core.profiles import ResourceType, get_sdk
@@ -2676,12 +2676,6 @@ def _redact_storage_accounts(properties):
26762676

26772677

26782678
def _ssl_context():
2679-
if sys.version_info < (3, 4) or (in_cloud_console() and sys.platform.system() == 'Windows'):
2680-
try:
2681-
return ssl.SSLContext(ssl.PROTOCOL_TLS) # added in python 2.7.13 and 3.6
2682-
except AttributeError:
2683-
return ssl.SSLContext(ssl.PROTOCOL_TLSv1)
2684-
26852679
return ssl.create_default_context()
26862680

26872681

0 commit comments

Comments
 (0)