Skip to content

Conversation

@sunsw1994
Copy link
Contributor

@sunsw1994 sunsw1994 commented Mar 26, 2021

Description

Update 'az synapse role' commands to support new role base access control feature.

Testing Guide

az synapse role scope -h
az synapse role assignment -h
az synapse role definition -h

History Notes

[Synapse] az synapse role scope list: List all scopes synapse supports.
[Synapse] az synapse role assignment create/list/delete: Adding --scope/--item-type/--item arguments to support manage role assignments based on scope.
[Synapse] az synapse role assignment create/list/delete: Adding --assignee-object-id argument, it will bypass Graph API and uniquely determine principal object instead of deducing principal object using --assignee argument.
[Synapse] BREAKING CHANGE: az synapse role assignment create: Role names at old version are not allowed, Sql Admin, Apache Spark Admin, Workspace Admin
[Synapse] BREAKING CHANGE: az synapse role assignment create: When --assignee argument can't uniquely determine the principal object, the command will raise error instead of adding a role assignment for the uncertain principal object.


This checklist is used to make sure that common guidelines for a pull request are followed.

@sunsw1994 sunsw1994 changed the title Synapse rbac [Synapse] Update role assignment/definition related cmdlets Mar 26, 2021
@sunsw1994
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@yonzhan
Copy link
Collaborator

yonzhan commented Mar 26, 2021

Synapse

@yonzhan yonzhan requested a review from jsntcy March 26, 2021 14:49
@yonzhan yonzhan added this to the S185 milestone Mar 26, 2021
# workspaces/{workspaceName}/bigDataPools/{bigDataPoolName}
scope = "workspaces/" + workspace_name + "/" + item_type + "/" + item
else:
scope = "workspaces/" + workspace_name
Copy link

Choose a reason for hiding this comment

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

I just want to mention that these two may be not equal from my memory: 1.scope = "workspaces/" + workspace_name 2. scope = null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @zesluo As far as my understand, the default scope is workspaces/{workspace_name}, we can discuss and confirm with @idear1203 .

Thanks for throwing it out.

Copy link
Contributor

@idear1203 idear1203 left a comment

Choose a reason for hiding this comment

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

:shipit:

@sunsw1994
Copy link
Contributor Author

Hi @jsntcy Could you help to review and merge this PR for Synapse RBAC commands. Thanks a lot.

@jsntcy jsntcy requested review from Juliehzl and evelyn-ys April 6, 2021 00:24
- name: Create a role assignment using service principal name.
text: |-
az synapse role assignment create --workspace-name testsynapseworkspace \\
--role "Sql Admin" --assignee sp_name
Copy link
Contributor

Choose a reason for hiding this comment

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

does Sql Admin still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, now Synapse is using new role name.
Synapse SQL Administrator
Synapse Apache Spark Administrator
...

https://docs.microsoft.com/en-us/azure/synapse-analytics/security/synapse-workspace-synapse-rbac-roles

Copy link
Contributor

Choose a reason for hiding this comment

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

In this way, it is breaking change to existing customers and we should try to avoid such breaking.
To not break customers, you should try to make previous definition work and add deprecation info to redirect to new definition.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just allow this breaking change considering that the module is still in preview? Now Synapse moves to new names, we don't want to allow the old names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding breaking change description at History Notes

[Synapse] BREAKING CHANGE: az synapse role assignment create: Role names at old version are not allowed, Sql Admin, Apache Spark Admin, Workspace Admin

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. According to the telemetry, there is no much usage for this command as it is in preview. So we could accept the breaking change this time. Please note that we need to avoid breaking change as possible as we can in future design.

Comment on lines 69 to 80
class PrincipalType(str, Enum):
user = "User"
group = "Group"
service_principal = "ServicePrincipal"


class ItemType(str, Enum):
bigDataPools = "bigDataPools"
scopePools = "scopePools"
integrationRuntimes = "integrationRuntimes"
credentials = "credentials"
linkedServices = "linkedServices"
Copy link
Contributor

Choose a reason for hiding this comment

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

why not define in SDK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Juliehzl I think this not belong to SDK's scope, we define these item type for CLI using friendly. User can pass item type and CLI code will use this parameter to generate scope which is defined in SDK and received by service.

PrincipalType and ItemType 's purpose is only to limit the user's input

@idear1203 Do we have a plan to move it to SDK?

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently we don't have such definitions in SDK. This is a good suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

def list_role_assignments(cmd, workspace_name, role=None, assignee=None, assignee_object_id=None,
scope=None, item=None, item_type=None):
if bool(assignee) and bool(assignee_object_id):
raise CLIError('usage error: --assignee STRING | --assignee-object-id GUID')
Copy link
Contributor

@Juliehzl Juliehzl Apr 6, 2021

Choose a reason for hiding this comment

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

Consider the following error type

class InvalidArgumentValueError(UserFault):
""" Argument value is not valid. """
pass

class ArgumentUsageError(UserFault):
""" Fallback of the argument usage related errors.
Avoid using this class unless the error can not be classified
into the Argument related specific error types. """
pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

if bool(assignee) and bool(assignee_object_id):
raise CLIError('usage error: --assignee STRING | --assignee-object-id GUID')

if bool(item) != bool(item_type):
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

g.custom_show_command('show', 'get_role_definition')

with self.command_group('synapse role scope', synapse_role_definitions_sdk,
custom_command_type=get_custom_sdk('accesscontrol', None)) as g:
Copy link
Contributor

Choose a reason for hiding this comment

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

You could declare your client factory here and don't need to define in every fuction.

"If the assignee is a principal id, make sure the corresponding principal is created "
"with 'az ad sp create --id {assignee}'.".format(assignee=assignee))

if len(result) > 1:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add breaking change description at History Notes:

[Synapse] BREAKING CHANGE: az synapse role assignment create: When --assignee can't uniquely determine the principal object, the command will raise error instead of adding a role assignment for the uncertain principal object.

@sunsw1994
Copy link
Contributor Author

@evelyn-ys @Juliehzl Thanks for your comments, these are helpful! I have fixed them and updated history notes with known breaking change information, could you help to review it and merge this PR. Hope we can catch up the latest release. Thanks a lot!

@Juliehzl Juliehzl merged commit 2cef51d into Azure:dev Apr 8, 2021
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.

7 participants