Skip to content

Conversation

@yugangw-msft
Copy link
Contributor

@yugangw-msft yugangw-msft commented Jan 11, 2018

2 parts:

  1. Do not use explicit identity, the right term should be user assigned identity
  2. When create a role assignment for it, expose --assignee-object-id to bypass the graph query. This is needed when login as a service principal which by default has no graph permissions.
  • The PR has modified HISTORY.rst describing any customer-facing, functional changes. Note that this does not include changes only to help content. (see Modifying change log).

Command Guidelines

  • Each command and parameter has a meaningful description.
  • Each new command has a test.

(see Authoring Command Modules)

@azuresdkci
Copy link
Contributor

View a preview at https://prompt.ws/r/Azure/azure-cli/5273
This is an experimental preview for @microsoft.com users.
(It may take a minute or two for your instance to be ready)
Email feedback to 'azfeedback' with subject 'Prompt Feedback'.

@yugangw-msft yugangw-msft added this to the Sprint 29 milestone Jan 11, 2018
@yugangw-msft
Copy link
Contributor Author

//cc: @skwan

if large_resp_body:
large_resp_body._max_response_body = size # pylint: disable=protected-access

def get_guid_gen_patch(self, guids, test_seam='azure.cli.command_modules.role.custom._gen_guid'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to ensure we will have fixed guid (used in the url) recorded into the .yaml files for playback later


_CUSTOM_RULE = 'CustomRole'

# pylint: disable=too-many-lines
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is the indication that this file should be split into smaller ones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my experience working with modules that did split their custom commands into multiple files, it simply added complexity.

def create_role_assignment(cmd, role, assignee=None, assignee_object_id=None, resource_group_name=None, scope=None):
if bool(assignee) == bool(assignee_object_id):
raise CLIError('usage error: --assignee STRING | --assignee-object-id GUID')
resolve_assignee = not assignee_object_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can this assignment just be rolled into the parameter assignment on line 131?

if principal_dics.get(i['properties']['principalId']):
i['properties']['principalName'] = principal_dics[i['properties']['principalId']]
except (CloudError, GraphErrorException):
pass # failure on resolving principal due to graph permission should not block the whole thing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth log a warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me log an info. It is an expected exception when login as a SP w/p graph permission, so warning might be too much.

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple questions.

c.argument('show_all', options_list=['--all'], action='store_true', help='show all assignments under the current subscription')
c.argument('include_inherited', action='store_true', help='include assignments applied on parent scopes')
c.argument('assignee', help='represent a user, group, or service principal. supported format: object id, user sign-in name, or service principal name')
c.argument('assignee_object_id', help="assignee's graph object id, such as the 'principal id' from a managed service identity. Use this instead of '--assignee' to by-pass graph permission issues")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: by-pass should be "bypass".

return _create_role_assignment(cmd.cli_ctx, role, assignee, resource_group_name, scope)
def create_role_assignment(cmd, role, assignee=None, assignee_object_id=None, resource_group_name=None, scope=None):
if bool(assignee) == bool(assignee_object_id):
raise CLIError('usage error: --assignee STRING | --assignee-object-id GUID')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we couldn't simply accept a string or GUID for assignee? This seems like an Xplat anti-pattern.

Copy link
Contributor Author

@yugangw-msft yugangw-msft Jan 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is GUID can be used as assignee names, so w/o graph query, we would not know. For people login with service principal, they need to have the option to bypass the graph query.
I have proposed that on graph permission error cli can fallback to object id as long as it is a guid, but it is possible we could assign by mistake when service principal 2's object id happens to be the service principal 1's name.

class RoleScenarioTest(ScenarioTest):

def enable_large_payload(self, size=8192):
from azure_devtools.scenario_tests import LargeResponseBodyProcessor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider moving this into the test base. It is used in many places to work around what I would consider a bug in devtools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can port #4127 over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants