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

[Feature/Identity] Basic permissions checking from Subject #5089

Conversation

peternied
Copy link
Member

Description

Adds capability for subject to check if a permission is allowed or not and creates a mechanism for actions to describe the permissions associated with them.

Issues Resolved

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@peternied peternied requested review from a team and reta as code owners November 4, 2022 21:32
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2022

Gradle Check (Jenkins) Run Completed with:

@peternied peternied changed the title Basic permissions checking from Subject [Feature/Identity] Basic permissions checking from Subject Nov 8, 2022
Copy link
Member

@cwperks cwperks left a comment

Choose a reason for hiding this comment

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

Left some initial feedback. Thanks for putting this out there to get a conversation going around this topic.

private final String[] permissionChunks;

public Permission(final String permission) {
this.permissionChunks = permission.split("\\.");
Copy link
Member

Choose a reason for hiding this comment

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

Can this be made into a constant. wdyt about PERMISSION_DELIMITER?

Copy link
Member

Choose a reason for hiding this comment

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

We should create another constructor, which accepts delimiter as an argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

These permissions should have a consistent format, following @cwperks suggestion

server/src/main/java/org/opensearch/action/ActionType.java Outdated Show resolved Hide resolved
@Override
public List<String> requiredPermissions() {
return List.of(
"opensearch.engine.index.create",
Copy link
Member

Choose a reason for hiding this comment

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

This is a good place to start and should be expandable to index patterns. Are you thinking that all permissions in core be preceded with opensearch.engine and there will be a separate convention for actions added by plug-ins or modules?

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI @shanilpa @jimishs.

For this specific request when it comes to indexing, its clearly part of the core/engine, or maybe the prefix should just be opensearch.indexing.index.create. Maybe of the nature [Source].[Category].[Object].[Action]?

I don't plan on iterating on this name for this pull request and we will need to follow up in the broader vNext permissions conversation.

Copy link
Member

Choose a reason for hiding this comment

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

Should these be loaded from a file or some other store? (Could be part of next iteration)

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked into the relationship between permissions and actions and there is no good mechanism
to engage with actions in a way that produces a list of permissions.

Exploring the ActionModule there is a common system to register actions however this registration doesn't pass all of the information about action execution, it passes a limited version.

What I would recommend would be creating a new description for action related data that encompasses the action type, action request, action response, and the action handler. Building this into or around the ActionModule seems appropriate but this will need to be rolled out over time since it would be backwards incompatible to plugins. This is a good follow up item.

Copy link
Member

@DarshitChanpura DarshitChanpura left a comment

Choose a reason for hiding this comment

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

Ty for this PR. Added a few comments.

this.permissionChunks = permission.split("\\.");
}

public boolean matches(final String permissionRequired) {
Copy link
Member

Choose a reason for hiding this comment

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

seems like we can leverage equals method here. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

A user might have a grant represented as opensearch.indexing.index, and the checked permission will be opensearch.indexing.index.create. This isn't an equality check, but a check if the permission grant matches the permission checked.

As I'm writing this out, it might make sense to create different objects to represent the grant vs the permission them selves - I'll revisit this

private final String[] permissionChunks;

public Permission(final String permission) {
this.permissionChunks = permission.split("\\.");
Copy link
Member

Choose a reason for hiding this comment

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

We should create another constructor, which accepts delimiter as an argument.

@Override
public List<String> requiredPermissions() {
return List.of(
"opensearch.engine.index.create",
Copy link
Member

Choose a reason for hiding this comment

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

Should these be loaded from a file or some other store? (Could be part of next iteration)

if (unauthorizedException != null) {
listener.onFailure(unauthorizedException);
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

very clean 👏

Adds capability for subject to check if a permission is allowed or not
and creates a mechanism for actions to describe the permissinos
associated with them.

Signed-off-by: Peter Nied <[email protected]>
Signed-off-by: Peter Nied <[email protected]>
Comment on lines 16 to 20
try {
this.permissionChunks = permission.split(PERMISSION_DELIMITER);
} catch (Exception) {
throw new InvalidPermissionName(permission);
}
Copy link
Member

@DarshitChanpura DarshitChanpura Jan 11, 2023

Choose a reason for hiding this comment

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

This change is related to the change suggestion below for checkIsValid method

Suggested change
try {
this.permissionChunks = permission.split(PERMISSION_DELIMITER);
} catch (Exception) {
throw new InvalidPermissionName(permission);
}
this.permissionChunks = splitIntoChunks(permission);

Copy link
Member Author

Choose a reason for hiding this comment

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

I did this to throw the specific type of exception rather than having a 'string' format issue be seen

Copy link
Member

Choose a reason for hiding this comment

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

okay, i was thinking it from reusability side of things. Maybe we can change definition of the constructor and the splitIntoChunks throws InvalidPermissionException. Thoughts?

Comment on lines +35 to +37
public static void checkIsValid(final String permission) {
new Permission(permission);
}
Copy link
Member

Choose a reason for hiding this comment

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

We can introduce following for re-usability, instead of creating a new unused object everytime this method is called

Suggested change
public static void checkIsValid(final String permission) {
new Permission(permission);
}
private static String[] splitIntoChunks(final String permission){
try {
return permission.split(PERMISSION_DELIMITER);
} catch (Exception) {
throw new InvalidPermissionName(permission);
}
}
public static void checkIsValid(final String permission) {
splitIntoChunks(permission);
}

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Peter Nied <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: null ❌
  • URL: null
  • CommitID: 18eea2e
    Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green.
    Is the failure a flaky test unrelated to your change?

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Peter Nied <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Peter Nied <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Peter Nied <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Peter Nied <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@peternied
Copy link
Member Author

@cwperks already has trail blazed in this space #6029

@scrawfor99 this is a good reference for a rudimentary permission checking as applied in OpenSearch, Craig's PR above is a a way to see how shiro integration could handle some of that logic. I think we will need a blending of this and your changes we good forward

@peternied peternied closed this Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants