Skip to content

Support batch authorization via Authorizer #15434

@gallyamb

Description

@gallyamb

As of now Authorizer supports only one authorization request. It's ok when authorization data is accessed in-memory, but for Authorizers backed by a separate service such design adds unnecessary overhead. It'd be better to check for all grants in one network request, rather than doing multiple smaller requests

I propose adding a new method to Authorizer with a BatchAuthorizationRequest (the rest is omitted for clarity):

public interface Authorizer extends Plugin {
  /** Authorizes an action based on the actor, the resource, and required privileges. */
  default AuthorizationResult authorize(@Nonnull final AuthorizationRequest request) {
    return new AuthorizationResult(request, AuthorizationResult.Type.DENY, "Not Implemented.");
  }

  /**
   * Authorizes an actions based on the actor, the resource, and required privileges
   */
  default BatchAuthorizationResult authorizeBatch(
      @Nonnull final BatchAuthorizationRequest batchRequest) {
    List<AuthorizationResult> results = batchRequest.getIndividualRequests()
        .map(this::authorize)
        .toList();
    return new BatchAuthorizationResult(batchRequest, results);
  }
}

Then com.datahub.authorization.AuthUtil#isAuthorized(com.datahub.authorization.AuthorizationSession, com.datahub.authorization.DisjunctivePrivilegeGroup, com.datahub.authorization.EntitySpec) will take care of calculating the final decision based on the returned results (taking into account disjunctive/conjunctive groups)

Existing Authorizer implementations wouldn't notice any difference, while new ones may take advantage of the batch form

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions