Uh oh!
There was an error while loading. Please reload this page.
Factor common IAM policy bits into 'google.cloud.iam'. - #3188
Conversation
theacodes
commented
Mar 22, 2017
/cc @elibixby |
| @@ -0,0 +1,217 @@ | |||
| # Copyright 2016 Google Inc. | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
I had a previous proposal to do this which got abandoned due to slow review cycle, but it's here: See #2031 The key takeaway: the API representation of bindings is really gross to interact with. Client side it would be much nicer if bindings were a dict with roles as keys, and member sets as values. So instead of code like: We had code like: |
| """ | ||
| return 'allAuthenticatedUsers' | ||
| def _bind_custom_role(self, role, members): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| self.viewers = set() | ||
| @staticmethod | ||
| def user(email): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| def __init__(self, etag=None, version=None): | ||
| self.etag = etag | ||
| self.version = version | ||
| self.owners = set() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Additionally note that Roles are an API resource, and should be represented with an object. What does the Both Role resources will be user managed with the addition of custom roles (currently in alpha), and will have a list of iam permissions that they grant, which will be important for user protection of custom methods, and for identifying the necessary roles that a member needs to be granted. (combining Further explanation of suggestions like these can be found in comment threads in #2031 EDIT: Slight correction: EDIT2: This can probably be tackled in a followup PR, but should be considered when defining the interface? Do we want to make |
| @staticmethod | ||
| def user(email): | ||
| """Factory method for a user member. | ||
| def _bind_custom_role(self, role, members): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
tseaver
commented
Mar 23, 2017
@elibixby I think I have addressed your concerns about supporting user-defined roles in b625017. re: |
@tseaver But I agree that this can be tackled in a follow-up PR. Long term I still believe a common implementatoin for One Platform APIs will save you the most heartache. Storage is an oddball because it is so old (i.e. not a One Platform API) and IAM support was "backported" in a slightly weird way. But going forward all OP APIs will share a common IAM signature, and a Mixin could provide drop in support for that. |
| policy.viewers |= members | ||
| else: | ||
| policy._bind_custom_role(role, members) | ||
| members = sorted(binding['members']) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| resource['bindings'] = bindings | ||
| if len(self.bindings) > 0: | ||
| resource['bindings'] = [ | ||
| {'role': role, 'members': members} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| for role in self._OWNER_ROLES: | ||
| for member in self.bindings.get(role, ()): | ||
| result.add(member) | ||
| return result |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
lukesneeringer
commented
Mar 23, 2017
This is fine with me also. |
lukesneeringer
commented
Mar 30, 2017
@tseaver Checking on the status of this. :-) |
Pubsub-specific roles, permissions left behind in 'google.cloud.pubsub.iam'. 'google.cloud.pubsub.iam.Policy' subclasses the core one, extending it to deal with the pubsub-specific roles.
- google.cloud.iam.Policy holds a 'bindings' mapping, which doesn't enforce using known roles. - Its 'owners', 'editors', and 'viewers' are now properties which indirect over that 'bindings' attribute. Note that this is a breaking change, as users who relied on mutating one of those sets (rather than re-assigning it) will need to update.
- Don't pass roles w/ empty members to back-end. - De-duplicate role members when passing to back-end.
- Re-assign 'policy.viewers'/'policy.editors', rather than mutating them in place.
tseaver
commented
Apr 5, 2017
@lukesneeringer I'm back at this, but can't figure out what the desired resolution would be. Here is a sketch at a way forward:
Then, the question is what the desired surface would be: I'm really leery of exposing the mutable
|
Updating them in place never actually worked (they were sets created on the fly), but at least we give an appropriate error now if the user tries.
lukesneeringer
commented
Apr 6, 2017
My personal preference is the first option (making |
tseaver
commented
Apr 6, 2017
@lukesneeringer That is my preference as well. Update on the way. |
Keys are roles, values are lists of principals.
tseaver
commented
Apr 6, 2017
@lukesneeringer OK, I've updated |
lukesneeringer
left a comment
There was a problem hiding this comment.
Approved, but giving @elibixby a chance to weigh in before merge.
| return self._bindings[key] | ||
| def __setitem__(self, key, value): | ||
| self._bindings[key] = value |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
lukesneeringer
commented
Apr 12, 2017
Merging this when CI goes green. |
…b-iam-for-storage Factor common IAM policy bits into 'google.cloud.iam'.
…thon-docs-samples#3188) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
…thon-docs-samples#3188) Co-authored-by: Leah E. Cole <6719667+leahecole@users.noreply.github.com>
Toward #1679.
Pubsub-specific roles, permissions left behind in
google.cloud.pubsub.iam.google.cloud.pubsub.iam.Policysubclasses the core one, extending it to deal with the pubsub-specific roles.