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

feat(authz): support tenants related granularity operation #23500

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -48,6 +48,7 @@
import org.apache.pulsar.common.naming.NamedEntity;
import org.apache.pulsar.common.policies.data.TenantInfo;
import org.apache.pulsar.common.policies.data.TenantInfoImpl;
import org.apache.pulsar.common.policies.data.TenantOperation;
import org.apache.pulsar.common.util.FutureUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -62,7 +63,7 @@ public class TenantsBase extends PulsarWebResource {
@ApiResponse(code = 404, message = "Tenant doesn't exist")})
public void getTenants(@Suspended final AsyncResponse asyncResponse) {
final String clientAppId = clientAppId();
validateSuperUserAccessAsync()
validateTenantOperationAsync(null, TenantOperation.LIST_TENANTS)
.thenCompose(__ -> tenantResources().listTenantsAsync())
.thenAccept(tenants -> {
// deep copy the tenants to avoid concurrent sort exception
Expand All @@ -84,7 +85,7 @@ public void getTenants(@Suspended final AsyncResponse asyncResponse) {
public void getTenantAdmin(@Suspended final AsyncResponse asyncResponse,
@ApiParam(value = "The tenant name") @PathParam("tenant") String tenant) {
final String clientAppId = clientAppId();
validateSuperUserAccessAsync()
validateTenantOperationAsync(tenant, TenantOperation.GET_TENANT)
.thenCompose(__ -> tenantResources().getTenantAsync(tenant))
.thenApply(tenantInfo -> {
if (!tenantInfo.isPresent()) {
Expand Down Expand Up @@ -121,7 +122,7 @@ public void createTenant(@Suspended final AsyncResponse asyncResponse,
asyncResponse.resume(new RestException(Status.PRECONDITION_FAILED, "Tenant name is not valid"));
return;
}
validateSuperUserAccessAsync()
validateTenantOperationAsync(tenant, TenantOperation.CREATE_TENANT)
.thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
.thenCompose(__ -> validateClustersAsync(tenantInfo))
.thenCompose(__ -> validateAdminRoleAsync(tenantInfo))
Expand Down Expand Up @@ -169,7 +170,7 @@ public void updateTenant(@Suspended final AsyncResponse asyncResponse,
@ApiParam(value = "The tenant name") @PathParam("tenant") String tenant,
@ApiParam(value = "TenantInfo") TenantInfoImpl newTenantAdmin) {
final String clientAppId = clientAppId();
validateSuperUserAccessAsync()
validateTenantOperationAsync(tenant, TenantOperation.UPDATE_TENANT)
.thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
.thenCompose(__ -> validateClustersAsync(newTenantAdmin))
.thenCompose(__ -> validateAdminRoleAsync(newTenantAdmin))
Expand Down Expand Up @@ -206,7 +207,7 @@ public void deleteTenant(@Suspended final AsyncResponse asyncResponse,
@PathParam("tenant") @ApiParam(value = "The tenant name") String tenant,
@QueryParam("force") @DefaultValue("false") boolean force) {
final String clientAppId = clientAppId();
validateSuperUserAccessAsync()
validateTenantOperationAsync(tenant, TenantOperation.DELETE_TENANT)
.thenCompose(__ -> validatePoliciesReadOnlyAccessAsync())
.thenCompose(__ -> internalDeleteTenant(tenant, force))
.thenAccept(__ -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ public enum TenantOperation {
CREATE_NAMESPACE,
DELETE_NAMESPACE,
LIST_NAMESPACES,

// tenants level operations
LIST_TENANTS,
GET_TENANT,
CREATE_TENANT,
UPDATE_TENANT,
DELETE_TENANT,
}
Loading