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

Remove deprecated hasDataAccess method. #13574

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ public interface AccessControl extends FineGrainedAccessControl {
String WORKFLOW_NONE = "NONE";
String WORKFLOW_BASIC = "BASIC";

/**
* Return whether the client has data access to the given table.
*
* Note: This method is only used fore read access. It's being deprecated and its usage will be replaced by
* `hasAccess` method with AccessType.READ.
*
* @param httpHeaders HTTP headers containing requester identity
* @param tableName Name of the table to be accessed
* @return Whether the client has data access to the table
*/
@Deprecated
default boolean hasDataAccess(HttpHeaders httpHeaders, String tableName) {
return hasAccess(tableName, AccessType.READ, httpHeaders, null);
}

/**
* Return whether the client has permission to the given table
*
Expand All @@ -55,10 +40,8 @@ default boolean hasDataAccess(HttpHeaders httpHeaders, String tableName) {
* @param endpointUrl the request url for which this access control is called
* @return whether the client has permission
*/
default boolean hasAccess(@Nullable String tableName, AccessType accessType, HttpHeaders httpHeaders,
@Nullable String endpointUrl) {
return true;
}
boolean hasAccess(@Nullable String tableName, AccessType accessType, HttpHeaders httpHeaders,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this no longer default true? This is backwards incompatible for users of this interface

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch. Adding it back in #14382

@Nullable String endpointUrl);

/**
* Return whether the client has permission to access the endpoints with are not table level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class AllowAllAccessFactory implements AccessControlFactory {
private static final AccessControl ALLOW_ALL_ACCESS = new AccessControl() {
@Override
public boolean hasDataAccess(HttpHeaders httpHeaders, String tableName) {
public boolean hasAccess(String tableName, AccessType accessType, HttpHeaders httpHeaders, String endpointUrl) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can remove this function as the default implementation returns true?

return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public boolean protectAnnotatedOnly() {
return false;
}

@Override
public boolean hasDataAccess(HttpHeaders httpHeaders, String tableName) {
return getPrincipal(httpHeaders).filter(p -> p.hasTable(tableName)).isPresent();
}

@Override
public boolean hasAccess(String tableName, AccessType accessType, HttpHeaders httpHeaders, String endpointUrl) {
return getPrincipal(httpHeaders)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public boolean protectAnnotatedOnly() {
return false;
}

@Override
public boolean hasDataAccess(HttpHeaders httpHeaders, String tableName) {
return getPrincipal(httpHeaders).filter(p -> p.hasTable(tableName)).isPresent();
}

@Override
public boolean hasAccess(String tableName, AccessType accessType, HttpHeaders httpHeaders, String endpointUrl) {
return getPrincipal(httpHeaders).filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.pinot.controller.api.access.AccessControlFactory;
import org.apache.pinot.controller.api.access.AccessType;
import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
import org.apache.pinot.core.auth.Actions;
import org.apache.pinot.core.auth.ManualAuthorization;
import org.apache.pinot.core.query.executor.sql.SqlQueryExecutor;
import org.apache.pinot.query.QueryEnvironment;
Expand Down Expand Up @@ -292,7 +293,7 @@ private String getQueryResponse(String query, @Nullable SqlNode sqlNode, String

// Validate data access
AccessControl accessControl = _accessControlFactory.create();
if (!accessControl.hasDataAccess(httpHeaders, rawTableName)) {
if (!accessControl.hasAccess(rawTableName, AccessType.READ, httpHeaders, Actions.Table.DOWNLOAD_SEGMENT)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Actions.Table.DOWNLOAD_SEGMENT is not suited for endpointUrl? If endpointUrl is not accessible, we can use null.

Copy link
Contributor Author

@abhioncbr abhioncbr Jul 12, 2024

Choose a reason for hiding this comment

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

@vvivekiyer / @soumitra-st We need some consensus on whether to use Actions.Table.DOWNLOAD_SEGMENT or pass null.

Copy link
Contributor

Choose a reason for hiding this comment

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

@soumitra-st Passing endpointUrl is critical to allow implementations to provide different access restrictions to different read endpoints. Hence I had suggested that we add the relevant action.

All over our codebase (eg: PinotTableResstletResource), we pass the action as endpointUrl. If we feel that a better identifier is needed to identify endpointUrl, we can discuss.

@abhioncbr as this is the query endpoint, the action here should be Actions.Table.QUERY ?

Copy link
Contributor

@soumitra-st soumitra-st Jul 12, 2024

Choose a reason for hiding this comment

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

All over our codebase (eg: PinotTableResstletResource), we pass the action as endpointUrl. If we feel that a better identifier is needed to identify endpointUrl, we can discuss.

@vvivekiyer , if we pass action as endpointUrl across the board, then I am ok with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I will make the change here as suggested by @vvivekiyer and for adding endpointUrl across board, I will raise another PR. Sounds good?

return QueryException.ACCESS_DENIED_ERROR.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Response downloadSegment(
boolean hasDataAccess;
try {
AccessControl accessControl = _accessControlFactory.create();
hasDataAccess = accessControl.hasDataAccess(httpHeaders, tableName);
hasDataAccess = accessControl.hasAccess(tableName, AccessType.READ, httpHeaders, Actions.Table.DOWNLOAD_SEGMENT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, Actions.Table.DOWNLOAD_SEGMENT action used as endpointUrl. Shall we pass null?

} catch (Exception e) {
throw new ControllerApplicationException(LOGGER,
"Caught exception while validating access to table: " + tableName, Response.Status.INTERNAL_SERVER_ERROR, e);
Expand Down
Loading