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

feat(builtin-groups): support builtin groups in user.yaml #625

Merged
merged 4 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions fence/rbac/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,27 @@ def create_group(
self.logger.info("group {} has policies: {}".format(name, list(policies)))
return data

@_arborist_retry()
def grant_group_policy(self, group_name, policy_id):
url = self._group_url + "/{}/policy".format(group_name)
request = {"policy": policy_id}
response = requests.post(url, json=request)
data = _request_get_json(response)
if response.status_code != 204:
msg = data.get("error", "unhelpful response from arborist")
if isinstance(data, dict) and "error" in data:
msg = data["error"].get("message", msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need to check if "error" in data, or do non-204s always have that information?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should always be there but never hurts 👍

self.logger.error(
"could not grant policy `{}` to group `{}`: {}".format(
policy_id, group_name, msg
)
)
return None
self.logger.info(
"granted policy `{}` to group `{}`".format(policy_id, group_name)
)
return data

@_arborist_retry()
def create_user_if_not_exist(self, username):
self.logger.info("making sure user exists: `{}`".format(username))
Expand Down
4 changes: 3 additions & 1 deletion fence/resources/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def get_user_info(current_session, username):

if hasattr(flask.current_app, "arborist"):
try:
resources = flask.current_app.arborist.list_resources_for_user(user.username)
resources = flask.current_app.arborist.list_resources_for_user(
user.username
)
except ArboristError:
logger.error(
"request to arborist for user's resources failed; going to list empty"
Expand Down
8 changes: 8 additions & 0 deletions fence/sync/sync_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,4 +1114,12 @@ def _update_arborist(self, session, user_yaml):
except ArboristError as e:
self.logger.info("couldn't create group: {}".format(str(e)))

# add policies for `anonymous` and `logged-in` groups

for policy in user_yaml.rbac.get("anonymous_policies", []):
self.arborist_client.grant_group_policy("anonymous", policy)

for policy in user_yaml.rbac.get("all_users_policies", []):
self.arborist_client.grant_group_policy("logged-in", policy)

return True
5 changes: 3 additions & 2 deletions tests/data/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,9 @@ def test_rbac(
assert response.status_code == 403


def test_initialize_multipart_upload(app, client, auth_client, encoded_creds_jwt, user_client):

def test_initialize_multipart_upload(
app, client, auth_client, encoded_creds_jwt, user_client
):
class MockResponse(object):
def __init__(self, data, status_code=200):
self.data = data
Expand Down