-
Notifications
You must be signed in to change notification settings - Fork 3k
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(auth): Add roles to policy engine validation logic #9178
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45dc5d2
feat(auth): Add roles to policy engine validation logic
pedro93 dd159c3
fixes
pedro93 6651afe
Add tests
pedro93 b6ded93
Merge branch 'master' into ps-add-role-validation-to-auth-engine
pedro93 08937cb
Merge branch 'master' into ps-add-role-validation-to-auth-engine
pedro93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,10 @@ | |
import java.util.stream.Stream; | ||
import javax.annotation.Nullable; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import static com.linkedin.metadata.Constants.*; | ||
|
@@ -75,6 +78,7 @@ public PolicyActors getMatchingActors( | |
final Optional<ResolvedEntitySpec> resource) { | ||
final List<Urn> users = new ArrayList<>(); | ||
final List<Urn> groups = new ArrayList<>(); | ||
final List<Urn> roles = new ArrayList<>(); | ||
boolean allUsers = false; | ||
boolean allGroups = false; | ||
if (policyMatchesResource(policy, resource)) { | ||
|
@@ -96,6 +100,9 @@ public PolicyActors getMatchingActors( | |
if (actorFilter.getGroups() != null) { | ||
groups.addAll(actorFilter.getGroups()); | ||
} | ||
if (actorFilter.getRoles() != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to only be used in the dead code above, this check is covered by isRoleMatch |
||
roles.addAll(actorFilter.getRoles()); | ||
} | ||
|
||
// 2. Fetch Actors based on resource ownership. | ||
if (actorFilter.isResourceOwners() && resource.isPresent()) { | ||
|
@@ -104,7 +111,7 @@ public PolicyActors getMatchingActors( | |
groups.addAll(groupOwners(owners)); | ||
} | ||
} | ||
return new PolicyActors(users, groups, allUsers, allGroups); | ||
return new PolicyActors(users, groups, roles, allUsers, allGroups); | ||
} | ||
|
||
private boolean isPolicyApplicable( | ||
|
@@ -438,34 +445,14 @@ public boolean isGranted() { | |
/** | ||
* Class used to represent all valid users of a policy. | ||
*/ | ||
@Value | ||
pedro93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@AllArgsConstructor(access = AccessLevel.PUBLIC) | ||
public static class PolicyActors { | ||
final List<Urn> _users; | ||
final List<Urn> _groups; | ||
final Boolean _allUsers; | ||
final Boolean _allGroups; | ||
|
||
public PolicyActors(final List<Urn> users, final List<Urn> groups, final Boolean allUsers, final Boolean allGroups) { | ||
_users = users; | ||
_groups = groups; | ||
_allUsers = allUsers; | ||
_allGroups = allGroups; | ||
} | ||
|
||
public List<Urn> getUsers() { | ||
return _users; | ||
} | ||
|
||
public List<Urn> getGroups() { | ||
return _groups; | ||
} | ||
|
||
public Boolean allUsers() { | ||
return _allUsers; | ||
} | ||
|
||
public Boolean allGroups() { | ||
return _allGroups; | ||
} | ||
List<Urn> users; | ||
List<Urn> groups; | ||
List<Urn> roles; | ||
Boolean allUsers; | ||
Boolean allGroups; | ||
} | ||
|
||
private List<Urn> userOwners(final Set<String> owners) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method seems like dead code? I don't see any references to it outside of this class and tracing back to Dexter's PR I don't see any actual usages of it. To get the actors authorized for something we go through different code unless I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not super familiar with the code.
My understanding is that this merging logic is for when we have multiple chained authorizers.
Since the interface extended a plugin interface, this was something we supported for the community.