|
32 | 32 |
|
33 | 33 | from ._archive_utils import upload_source_code, check_remote_source_code |
34 | 34 |
|
| 35 | +CALLER_IDENTITY_ALIAS = '[caller]' |
| 36 | +SYSTEM_ASSIGNED_IDENTITY_ALIAS = '[system]' |
| 37 | + |
35 | 38 | logger = get_logger(__name__) |
36 | 39 |
|
37 | 40 |
|
@@ -278,30 +281,59 @@ def get_yaml_template(cmd_value, timeout, file): |
278 | 281 | return yaml_template |
279 | 282 |
|
280 | 283 |
|
281 | | -def get_custom_registry_credentials(cmd, |
282 | | - auth_mode=None, |
283 | | - login_server=None, |
284 | | - username=None, |
285 | | - password=None, |
286 | | - identity=None, |
287 | | - is_remove=False): |
| 284 | +def get_source_and_custom_registry_credentials(cmd, |
| 285 | + auth_mode=None, |
| 286 | + login_server=None, |
| 287 | + username=None, |
| 288 | + password=None, |
| 289 | + identity=None, |
| 290 | + is_remove=False, |
| 291 | + source_acr_auth_id=None, |
| 292 | + registry_abac_enabled=False, |
| 293 | + deprecate_auth_mode=False): |
288 | 294 | """Get the credential object from the input |
289 | 295 | :param str auth_mode: The login mode for the source registry |
290 | 296 | :param str login_server: The login server of custom registry |
291 | 297 | :param str username: The username for custom registry (plain text or a key vault secret URI) |
292 | 298 | :param str password: The password for custom registry (plain text or a key vault secret URI) |
293 | 299 | :param str identity: The task managed identity used for the credential |
| 300 | + :param str source_acr_auth_id: the managed identity used for the source registry authentication |
| 301 | + :param bool registry_abac_enabled: whether the registry is ABAC-enabled |
| 302 | + :param bool deprecate_auth_mode: whether to print the auth mode deprecation warning |
294 | 303 | """ |
295 | 304 | Credentials, CustomRegistryCredentials, SourceRegistryCredentials, SecretObject, \ |
296 | 305 | SecretObjectType = cmd.get_models( |
297 | 306 | 'Credentials', 'CustomRegistryCredentials', 'SourceRegistryCredentials', 'SecretObject', |
298 | 307 | 'SecretObjectType', |
299 | 308 | operation_group='tasks') |
300 | 309 |
|
| 310 | + if deprecate_auth_mode: |
| 311 | + check_auth_mode_for_abac(registry_abac_enabled, auth_mode) |
| 312 | + |
| 313 | + source_registry_identity = None |
| 314 | + if source_acr_auth_id: |
| 315 | + # "Default" and "None" are the allowed values for source registry auth mode. |
| 316 | + # For a non-ABAC-enabled registry, "--source-acr-auth-id" will not take effect, and authentication |
| 317 | + # will fail if the auth mode is "None". Therefore, we need to throw an error here. |
| 318 | + if not registry_abac_enabled and auth_mode and auth_mode.lower() == "none": |
| 319 | + raise CLIError('Error: Conflicting Authentication Parameters for Task Access to Source Registry. Task ' |
| 320 | + 'authentication mode for source registry access is set to "None", but an identity was ' |
| 321 | + 'provided for authentication. Remove the identity or update the authentication mode to ' |
| 322 | + 'resolve this conflict.') |
| 323 | + |
| 324 | + if source_acr_auth_id.lower() == "none": |
| 325 | + source_registry_identity = None |
| 326 | + elif source_acr_auth_id.startswith('/subscriptions/'): # user-assigned MI resource ID |
| 327 | + source_registry_identity = resolve_identity_client_id(cmd.cli_ctx, source_acr_auth_id) |
| 328 | + elif source_acr_auth_id == CALLER_IDENTITY_ALIAS or source_acr_auth_id == SYSTEM_ASSIGNED_IDENTITY_ALIAS: |
| 329 | + source_registry_identity = source_acr_auth_id |
| 330 | + else: |
| 331 | + raise CLIError('Error: Invalid value for --source-acr-auth-id.') |
| 332 | + |
301 | 333 | source_registry_credentials = None |
302 | | - if auth_mode: |
| 334 | + if auth_mode or source_registry_identity: |
303 | 335 | source_registry_credentials = SourceRegistryCredentials( |
304 | | - login_mode=auth_mode) |
| 336 | + login_mode=auth_mode, identity=source_registry_identity) |
305 | 337 |
|
306 | 338 | custom_registries = None |
307 | 339 | if login_server: |
@@ -606,3 +638,10 @@ def get_task_details_by_name(cli_ctx, resource_group_name, registry_name, task_n |
606 | 638 | from ._client_factory import cf_acr_tasks |
607 | 639 | client = cf_acr_tasks(cli_ctx) |
608 | 640 | return client.get_details(resource_group_name, registry_name, task_name) |
| 641 | + |
| 642 | + |
| 643 | +def check_auth_mode_for_abac(registry_abac_enabled, auth_mode): |
| 644 | + if registry_abac_enabled and auth_mode is not None: |
| 645 | + logger.warning("The --auth-mode flag is deprecated for specifying access to an ABAC-enabled source registry. " |
| 646 | + "Please use --source-acr-auth-id to specify an Entra identity for use in accessing an " |
| 647 | + "ABAC-enabled source registry.") |
0 commit comments