Skip to content
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

Adding tag to service principal fails #22635

Closed
andygjp opened this issue May 26, 2022 · 5 comments
Closed

Adding tag to service principal fails #22635

andygjp opened this issue May 26, 2022 · 5 comments
Assignees
Labels
Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. Graph az ad
Milestone

Comments

@andygjp
Copy link

andygjp commented May 26, 2022

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az ad sp update

Errors:

The command failed with an unexpected error. Here is the traceback:
'GraphClient' object has no attribute 'service_principals'
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/knack/cli.py", line 231, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 718, in _run_job
    return cmd_copy.exception_handler(ex)
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/command_modules/role/commands.py", line 54, in graph_err_handler
    raise ex
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 240, in handler
    result = cached_put(self.cmd, setter, **setterargs)
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 452, in cached_put
    return _put_operation()
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 446, in _put_operation
    result = operation(**kwargs)
  File "/opt/homebrew/Cellar/azure-cli/2.37.0/libexec/lib/python3.10/site-packages/azure/cli/command_modules/role/custom.py", line 988, in patch_service_principal
    object_id = _resolve_service_principal(graph_client.service_principals, identifier)
AttributeError: 'GraphClient' object has no attribute 'service_principals'

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az ad sp update --id {} --add --tags "mytag" --debug

Expected Behavior

Environment Summary

macOS-12.4-arm64-arm-64bit, Darwin 21.5.0
Python 3.10.4
Installer: HOMEBREW

azure-cli 2.37.0

Extensions:
application-insights 0.1.15

Dependencies:
msal 1.18.0b1
azure-mgmt-resource 21.1.0b1

Additional Context

@ghost ghost added customer-reported Issues that are reported by GitHub users external to the Azure organization. Auto-Assign Auto assign by bot Graph az ad labels May 26, 2022
@ghost ghost assigned jiasli May 26, 2022
@ghost ghost added this to the Backlog milestone May 26, 2022
@andygjp
Copy link
Author

andygjp commented May 26, 2022

I got the same error when I attempted to --set another property:

az ad sp update --id {} --set appRoleAssignmentRequired=$false

@jiasli
Copy link
Member

jiasli commented May 26, 2022

As explained in https://docs.microsoft.com/en-us/cli/azure/microsoft-graph-migration, generic update operations like --set are currently not supported.

You may use az rest to directly update the service principal by calling Update servicePrincipal API.

@andygjp
Copy link
Author

andygjp commented May 26, 2022

@jiasli please can you reply with an example?

I tried this:

$objectId = az ad sp show --id $clientId `
    --query id `
    --output tsv

$body = '{"tags":["mytag"]}'

az rest --uri "https://graph.microsoft.com/v1.0/servicePrincipals/$objectId" `
    --method PATCH `
    --headers "Content-Type=application/json" `
    --body $body

And I get:

Bad Request({"error":{"code":"BadRequest","message":"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format." ...

The JSON looks fine to me.

@jiasli
Copy link
Member

jiasli commented May 26, 2022

@andygjp, you are hitting a known PowerShell issue: #15529

@andygjp
Copy link
Author

andygjp commented May 27, 2022

Thank you @jiasli, changing $body = '{"tags":["mytag"]}' to $body = '{"tags":[\"mytag\"]}' worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. Graph az ad
Projects
None yet
Development

No branches or pull requests

2 participants