Skip to content

Commit c8f01a0

Browse files
committed
username
1 parent 1952665 commit c8f01a0

File tree

3 files changed

+10
-49
lines changed

3 files changed

+10
-49
lines changed

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

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@
6161

6262
_AZ_LOGIN_MESSAGE = "Please run 'az login' to setup account."
6363

64-
MANAGED_IDENTITY_ID_WARNING = (
65-
"Passing the managed identity ID with --username is deprecated and will be removed in a future release. "
66-
"Please use --client-id, --object-id or --resource-id instead."
67-
)
68-
6964

7065
def load_subscriptions(cli_ctx, all_clouds=False, refresh=False):
7166
profile = Profile(cli_ctx=cli_ctx)
@@ -225,23 +220,23 @@ def login(self,
225220
self._set_subscriptions(consolidated)
226221
return deepcopy(consolidated)
227222

228-
def login_with_managed_identity(self, identity_id=None, client_id=None, object_id=None, resource_id=None,
223+
def login_with_managed_identity(self, client_id=None, object_id=None, resource_id=None,
229224
allow_no_subscriptions=None):
230225
if _on_azure_arc():
231-
return self.login_with_managed_identity_azure_arc(
232-
identity_id=identity_id, allow_no_subscriptions=allow_no_subscriptions)
226+
return self.login_with_managed_identity_azure_arc(allow_no_subscriptions=allow_no_subscriptions)
233227

234228
import jwt
235229
from azure.mgmt.core.tools import is_valid_resource_id
236230
from azure.cli.core.auth.adal_authentication import MSIAuthenticationWrapper
237231
resource = self.cli_ctx.cloud.endpoints.active_directory_resource_id
238232

239-
id_arg_count = len([arg for arg in (client_id, object_id, resource_id, identity_id) if arg])
233+
id_arg_count = len([arg for arg in (client_id, object_id, resource_id) if arg])
240234
if id_arg_count > 1:
241-
raise CLIError('Usage error: Provide only one of --client-id, --object-id, --resource-id, or --username.')
235+
raise CLIError('Usage error: Provide only one of --client-id, --object-id, --resource-id.')
242236

243237
if id_arg_count == 0:
244238
identity_type = MsiAccountTypes.system_assigned
239+
identity_id = None
245240
msi_creds = MSIAuthenticationWrapper(resource=resource)
246241
elif client_id:
247242
identity_type = MsiAccountTypes.user_assigned_client_id
@@ -255,38 +250,6 @@ def login_with_managed_identity(self, identity_id=None, client_id=None, object_i
255250
identity_type = MsiAccountTypes.user_assigned_resource_id
256251
identity_id = resource_id
257252
msi_creds = MSIAuthenticationWrapper(resource=resource, msi_res_id=resource_id)
258-
# The old way of re-using the same --username for 3 types of ID
259-
elif identity_id:
260-
logger.warning(MANAGED_IDENTITY_ID_WARNING)
261-
if is_valid_resource_id(identity_id):
262-
msi_creds = MSIAuthenticationWrapper(resource=resource, msi_res_id=identity_id)
263-
identity_type = MsiAccountTypes.user_assigned_resource_id
264-
else:
265-
authenticated = False
266-
from azure.cli.core.azclierror import AzureResponseError
267-
try:
268-
msi_creds = MSIAuthenticationWrapper(resource=resource, client_id=identity_id)
269-
identity_type = MsiAccountTypes.user_assigned_client_id
270-
authenticated = True
271-
except AzureResponseError as ex:
272-
if 'http error: 400, reason: Bad Request' in ex.error_msg:
273-
logger.info('Sniff: not an MSI client id')
274-
else:
275-
raise
276-
277-
if not authenticated:
278-
try:
279-
identity_type = MsiAccountTypes.user_assigned_object_id
280-
msi_creds = MSIAuthenticationWrapper(resource=resource, object_id=identity_id)
281-
authenticated = True
282-
except AzureResponseError as ex:
283-
if 'http error: 400, reason: Bad Request' in ex.error_msg:
284-
logger.info('Sniff: not an MSI object id')
285-
else:
286-
raise
287-
288-
if not authenticated:
289-
raise CLIError('Failed to connect to MSI, check your managed service identity id.')
290253

291254
token_entry = msi_creds.token
292255
token = token_entry['access_token']
@@ -310,9 +273,8 @@ def login_with_managed_identity(self, identity_id=None, client_id=None, object_i
310273
self._set_subscriptions(consolidated)
311274
return deepcopy(consolidated)
312275

313-
def login_with_managed_identity_azure_arc(self, identity_id=None, allow_no_subscriptions=None):
276+
def login_with_managed_identity_azure_arc(self, allow_no_subscriptions=None):
314277
import jwt
315-
identity_type = MsiAccountTypes.system_assigned
316278
from .auth.msal_credentials import ManagedIdentityCredential
317279
from .auth.constants import ACCESS_TOKEN
318280

@@ -324,8 +286,8 @@ def login_with_managed_identity_azure_arc(self, identity_id=None, allow_no_subsc
324286

325287
subscription_finder = SubscriptionFinder(self.cli_ctx)
326288
subscriptions = subscription_finder.find_using_specific_tenant(tenant, cred)
327-
base_name = ('{}-{}'.format(identity_type, identity_id) if identity_id else identity_type)
328-
user = _USER_ASSIGNED_IDENTITY if identity_id else _SYSTEM_ASSIGNED_IDENTITY
289+
base_name = MsiAccountTypes.system_assigned
290+
user = _SYSTEM_ASSIGNED_IDENTITY
329291
if not subscriptions:
330292
if allow_no_subscriptions:
331293
subscriptions = self._build_tenant_level_accounts([tenant])

src/azure-cli/azure/cli/command_modules/profile/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def load_arguments(self, command):
4545

4646
with self.argument_context('login') as c:
4747
c.argument('username', options_list=['--username', '-u'],
48-
help='User name, service principal client ID, or managed identity ID.')
48+
help='User name or service principal client ID.')
4949
c.argument('password', options_list=['--password', '-p'],
5050
help='User password or service principal secret. Will prompt if not given.')
5151
c.argument('tenant', options_list=['--tenant', '-t'], validator=validate_tenant,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ def login(cmd, username=None, password=None, tenant=None, scopes=None, allow_no_
143143
if identity:
144144
if in_cloud_console():
145145
return profile.login_in_cloud_shell()
146-
return profile.login_with_managed_identity(
147-
identity_id=username, client_id=client_id, object_id=object_id, resource_id=resource_id,
146+
return profile.login_with_managed_identity(client_id=client_id, object_id=object_id, resource_id=resource_id,
148147
allow_no_subscriptions=allow_no_subscriptions)
149148
if in_cloud_console(): # tell users they might not need login
150149
logger.warning(_CLOUD_CONSOLE_LOGIN_WARNING)

0 commit comments

Comments
 (0)