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

[Key Vault] Add support for custom role definitions #16063

Merged
merged 13 commits into from
Jan 22, 2021

Conversation

mccoyp
Copy link
Member

@mccoyp mccoyp commented Jan 9, 2021

Resolves #14938.

This adds set_role_definition, get_role_definition, and delete_role_definition methods to Administration's KeyVaultAccessControlClient. set_role_definition makes permissions a required parameter in an attempt to make it more clear that a definition without defined permissions is undesirable.

@mccoyp mccoyp added KeyVault Client This issue points to a problem in the data-plane of the library. labels Jan 9, 2021
@mccoyp mccoyp added this to the [2021] February milestone Jan 9, 2021
@mccoyp mccoyp force-pushed the feature/roledefinition branch from 927eb2a to 6863c81 Compare January 13, 2021 01:58
@mccoyp mccoyp force-pushed the feature/roledefinition branch from 6863c81 to 8b3acbd Compare January 13, 2021 02:52
@mccoyp mccoyp force-pushed the feature/roledefinition branch from 6605d77 to 386da11 Compare January 20, 2021 05:53
@mccoyp mccoyp force-pushed the feature/roledefinition branch from 386da11 to 00481f3 Compare January 20, 2021 06:03
@mccoyp mccoyp marked this pull request as ready for review January 20, 2021 06:06
@mccoyp mccoyp requested a review from schaabs as a code owner January 20, 2021 06:06
keys_value = "/keys" #: use this if you want role assignments to apply to all keys


class DataActionPermission(str, Enum):
Copy link
Member

Choose a reason for hiding this comment

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

I expect we'll want a "KeyVault" prefix because the values apply only to Key Vault, and other services will have their own actions. Also, are these values better characterized as operations or actions than permissions?

Copy link
Member

Choose a reason for hiding this comment

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

/cc @christothes that's a good idea for all languages as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm... since these would be used to populate a KeyVaultPermission object and they do describe actions, I agree that something like KeyVaultDataAction might make more sense.

Copy link
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

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

Public APIs look good.

class KeyVaultRoleScope(str, Enum):
"""Collection of well known role scopes. This list is not exhaustive"""

global_value = "/" #: use this if you want role assignments to apply to everything on the resource
Copy link
Member

Choose a reason for hiding this comment

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

Is the "_value" suffix common in Python? In .NET we just use "Global" and "Keys". If so, cool.

Copy link
Member

@chlowell chlowell Jan 20, 2021

Choose a reason for hiding this comment

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

"global" is a keyword. I forget how we ended up with _value here; looking at it again I like "global_scope" and "keys". Another option I kind of like is CAPS which I think other libraries have used (sadly other Key Vault libraries use lowercase). What do you think @mccoyp?

Copy link
Member

Choose a reason for hiding this comment

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

If we decide to go with a _scope suffix, I'd suggest we do it for both.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking about how a user would use the enum and because "Scope" is already in the class name, I think "global" and "keys" would make sense, without a suffix. I also wondered about whether these should be in caps -- I kept them in snake case for consistency with other libraries, but I was under the impression that enum values should be in caps

Copy link
Member

Choose a reason for hiding this comment

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

I'm happy with caps; consistency is less important to me than making the better choice here.

keys_value = "/keys" #: use this if you want role assignments to apply to all keys


class DataActionPermission(str, Enum):
Copy link
Member

Choose a reason for hiding this comment

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

/cc @christothes that's a good idea for all languages as well.

"""Supported permissions for data actions.
"""

#: Read HSM key metadata.
Copy link
Member

Choose a reason for hiding this comment

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

Make sure these names align with what @christothes defined in the swagger PR (not merged just yet but should be soon).

KEYS = "/keys" #: use this if you want role assignments to apply to all keys


class KeyVaultDataAction(str, Enum):
Copy link
Member Author

Choose a reason for hiding this comment

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

How do we feel with this enum name?

:param role_scope: scope of the role definition. :class:`KeyVaultRoleScope` defines common broad scopes.
Specify a narrower scope as a string. Managed HSM only supports '/', or KeyVaultRoleScope.global_value.
:type role_scope: str or KeyVaultRoleScope
:param role_definition_name: the role definition's name. Must be a UUID.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
:param role_definition_name: the role definition's name. Must be a UUID.
:param role_definition_name: the role definition's name.

Thinking the form of the name isn't interesting because this role definition already exists and so must have a compliant name.

@mccoyp mccoyp merged commit 42397a9 into Azure:master Jan 22, 2021
@mccoyp mccoyp deleted the feature/roledefinition branch January 22, 2021 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. KeyVault
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for custom role definitions
4 participants