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

Enhance API to handle global groups in local contexts #1159

Merged
merged 16 commits into from
Apr 26, 2017

Conversation

markan
Copy link
Contributor

@markan markan commented Mar 17, 2017

Support nonlocal group names

The server_admins group introduces an issue with ACLS and groups; we
have a global group in the context of a organization scoped
object. Not only do we have the potential of conflicts with a org
scoped group with the same name, we also lack a mechanisim to look up
groups that aren't in the org we're looking at.

This PR adds new syntax '::' to indicate scoping. ::GROUPNAME without
a prefix indicates a global (across multiple orgs) entity, while
ORGNAME::GROUPNAME refers to a group in an another org.

This should unblock the work around server admins, including improved
org creation.

There remain a few rough spots around error handling, and a few
opportunities to streamline and simplify the logic around 'lowering'
qualified names to authz_ids, but this should be enough to kickstart
the discussion.

This will need to be implemented in chef_zero to maintain feature parity.

Ticket: POOL-570

@markan markan force-pushed the ma/disambiguate_globals branch 3 times, most recently from 6bf4148 to 8a2d8d4 Compare March 24, 2017 06:06
@markan
Copy link
Contributor Author

markan commented Mar 24, 2017

@chef/chef-server-maintainers

I'm still working on dialyzer typespecs (coming shortly), but other than that this should be ready to roll.

@stevendanna
Copy link
Contributor

@markan Thanks for the heads up. Right now this is looking like it will probably land in release+1 since we've already got a ton in this release to test.

@markan markan force-pushed the ma/disambiguate_globals branch from 911cb66 to 044357a Compare March 24, 2017 22:28
@markan
Copy link
Contributor Author

markan commented Mar 25, 2017

@ssd No worries ( @marcparadise has kept me up to date on your status ). I suspect this will go through a few review cycles before it's done anyways.

This should unblock #886 & #935, so we'll probably want to bring this in early in the release cycle so we have a chance to tackle those, as well as maybe review whether #163 is still useful and relevant.

@markan markan force-pushed the ma/disambiguate_globals branch 3 times, most recently from 99d0cf8 to 399769e Compare April 5, 2017 22:24
@afiune
Copy link

afiune commented Apr 11, 2017

Im rebasing and pushing since we have merged a couple of commits from this PR.

@afiune afiune force-pushed the ma/disambiguate_globals branch 5 times, most recently from 9d86684 to ef9396f Compare April 12, 2017 14:02

%% Map org names to org ids
{NamesWithOrgIds, Errors2, _} =
lists:foldl(fun(Name, Acc) -> lookup_org_id(Name, Acc, MapperContext) end,
Copy link

Choose a reason for hiding this comment

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

I might be missing something but why do we pass the MapperContext to this lookup fun if it doesn't use it?

%% be robust to that.
case org_id_to_name(AnotherOrgId) of
not_found ->
{Expanded, Context};
Copy link

Choose a reason for hiding this comment

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

@markan I think here is where we are dropping the errors when an organization doesn't exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think per @markan's comment re deleted orgs, we should keep this, but perhaps we should log it so we can start getting a sense of how often this happens?

@afiune afiune force-pushed the ma/disambiguate_globals branch 2 times, most recently from 0544697 to 1b7fc74 Compare April 12, 2017 22:15
-spec render_names_in_context(binary(),[{binary(), [binary()]}], #context{}) -> [binary()].
render_names_in_context(OrgId, ScopedNames, Context) ->
GroupedScopedNames = group_by_key(ScopedNames),
{Expanded, _Cache} = lists:foldl(fun(E, A) -> render_names_in_context_f(OrgId, E, A) end,
Copy link

Choose a reason for hiding this comment

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

We do not use the Context in this fun. This is the only place we consume render_names_in_context_f and we drop it in _Cache. The fun itself is not using it so maybe we should remove it?

@afiune afiune force-pushed the ma/disambiguate_globals branch 4 times, most recently from 8170db3 to 5517156 Compare April 20, 2017 20:07
Copy link
Contributor

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Overall this is looking good. I'm thinking we should do the stats_hero stuff before merge so we don't forget.

filter_by_error_type/2,
authz_id_to_names/3]).

-export([make_scoped_names/2,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pretty big API for a brand new module. Do we need to export all of these functions? If so, is there anything we can do to tighten up the API a bit?

%% If no match, then we have bad name
process_match(nomatch, Name, _Context, _ScopedOk) ->
{ill_formed_name, Name};
%% If we only onl match the name, then it is an unscoped name, and we use the org context
Copy link
Contributor

Choose a reason for hiding this comment

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

Small typo in comment: only onl

%% be robust to that.
case org_id_to_name(AnotherOrgId) of
not_found ->
{Expanded, Context};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think per @markan's comment re deleted orgs, we should keep this, but perhaps we should log it so we can start getting a sense of how often this happens?

%% Design note: we drop missing orgs silently. Org deletion leaks many objects and we must
%% be robust to that.
case org_id_to_name(AnotherOrgId) of
not_found ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we log here?

Copy link

@afiune afiune Apr 21, 2017

Choose a reason for hiding this comment

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

an error_logger:warning_msg()** would be fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use lager instead of error_logger

Copy link

Choose a reason for hiding this comment

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

cool!

%%
-spec org_id_to_name(binary()) -> not_found | binary().
org_id_to_name(OrgId) ->
%% TODO maybe rework this; it bypasses a bunch of our statistics gathering code.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should probably wrap this in a stats hero timer.

%% Sometimes the list of authz ids is empty; shortcut that and save a DB call.
{[], []};
query_and_diff_authz_ids(QueryName, AuthzIds, CallbackFun) ->
case CallbackFun({QueryName, [AuthzIds]}) of
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a stats_hero timer around this as well.

@afiune
Copy link

afiune commented Apr 20, 2017

@chef/maintainers We are ready to review this change! cc/ @markan @stevendanna

@afiune afiune changed the title Ma/disambiguate globals Enhance API to handle global groups in local contexts Apr 20, 2017
markan and others added 15 commits April 25, 2017 20:12
Signed-off-by: Mark Anderson <[email protected]>
The server_admins group introduces an issue with ACLS and groups; we
have a global group in the context of a organization scoped
object. Not only do we have the potential of conflicts with a org
scoped group with the same name, we also lack a mechanisim to look up
groups that aren't in the org we're looking at.

This PR adds new syntax '::' to indicate scoping. ::GROUPNAME without
a prefix indicates a global (across multiple orgs) entity, while
ORGNAME::GROUPNAME refers to a group in an another org.

This should unblock the work around server admins, including improved
org creation.

This will need to be implemented in chef_zero to maintain feature parity.

Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
Signed-off-by: Mark Anderson <[email protected]>
chef-zero behaves a little different with `CHEF_FS` enabled.
this commit is just fixing the test failures.

Signed-off-by: Salim Afiune <[email protected]>
Also quick style fixes

Signed-off-by: Salim Afiune <[email protected]>
If a user tries to add an ACL that has a scoped group pointing to and
organization that doesn't exist, we would need to throw an error and not
allow such action.

Signed-off-by: Salim Afiune <[email protected]>
This commit re structure the oc_chef_authz_scoped_name module to
separate the fn's we need to export because other modules leverage them,
and the internal functions of the module.

Signed-off-by: Salim Afiune <[email protected]>
In order to send a proper message we need to extract the full_name from
the Scope Records.

If the provided Names are not Scope Records, just use their names.

Signed-off-by: Salim Afiune <[email protected]>
Even though this peace of code needs to be robust enough, we also would
like to be transparent and log a warning message saying that there is
something pointing to an organization that doesn't exist.

Signed-off-by: Salim Afiune <[email protected]>
We still 400 for most requests because of another latent bug that
exists on master as well.  We'll tackle that bug in a follow-up
commit.

Signed-off-by: Steven Danna <[email protected]>
@stevendanna stevendanna force-pushed the ma/disambiguate_globals branch from 5156b87 to 2cbcb5b Compare April 25, 2017 19:13
stevendanna
stevendanna previously approved these changes Apr 25, 2017
Copy link
Contributor

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

👍 Follow up plan is to follow up with some changes around the /user/USERNAME/_acl endpoints.

@stevendanna stevendanna dismissed their stale review April 25, 2017 19:48

Found another issue.

@markan
Copy link
Contributor Author

markan commented Apr 25, 2017

👍 LGTM

Copy link

@afiune afiune left a comment

Choose a reason for hiding this comment

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

@stevendanna stevendanna merged commit a9a1215 into master Apr 26, 2017
@markan markan deleted the ma/disambiguate_globals branch April 27, 2017 18:17
stevendanna added a commit that referenced this pull request May 16, 2017
Unlike users and groups, client names can contain the `.` character.
In fact, this character this likely since the client name is often
based on the node name which is based on the FQDN of the node.

In #1159, we added the ability to add name-spaced
actors and groups to ACLs.  However, that changed validated the actor
names against the more restrictive user/group regular expression.

This change uses the standard NAME_REGEX for validation which includes
`.`.  It does mean that some invalid user and group names will pass
validation; however, presumably such users and groups will fail to be
found in the database since they can't be created.

Fixes #1274

Signed-off-by: Steven Danna <[email protected]>
stevendanna added a commit that referenced this pull request May 16, 2017
Unlike users and groups, client names can contain the `.` character.
In fact, this character this likely since the client name is often
based on the node name which is based on the FQDN of the node.

In #1159, we added the ability to add name-spaced
actors and groups to ACLs.  However, that changed validated the actor
names against the more restrictive user/group regular expression.

This change uses the standard NAME_REGEX for validation which includes
`.`.  It does mean that some invalid user and group names will pass
validation; however, presumably such users and groups will fail to be
found in the database since they can't be created.

Fixes #1274

Signed-off-by: Steven Danna <[email protected]>
@tas50 tas50 added Type: Enhancement Adds new functionality. and removed enhancement labels Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Adds new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants