Skip to content

Commit

Permalink
Add secured namespaces feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv committed Dec 17, 2024
1 parent 0d0c2b9 commit e1f7bb8
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.michelin.ns4kafka.controller.acl;

import static com.michelin.ns4kafka.service.AclService.PUBLIC_GRANTED_TO;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidAclDeleteOnlyAdmin;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidImmutableField;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidNotFound;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidSecuredNamespaceGrantAcl;
import static com.michelin.ns4kafka.util.FormatErrorUtils.invalidSelfAssignedAclDelete;
import static com.michelin.ns4kafka.util.enumation.Kind.ACCESS_CONTROL_ENTRY;
import static io.micronaut.core.util.StringUtils.EMPTY_STRING;
Expand Down Expand Up @@ -105,10 +107,19 @@ public HttpResponse<AccessControlEntry> apply(Authentication authentication,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

boolean grantorIsSecured = getNamespace(accessControlEntry.getMetadata().getNamespace()).getSpec().isSecured();

boolean granteeIsSecured = !PUBLIC_GRANTED_TO.equals(accessControlEntry.getSpec().getGrantedTo())
&& getNamespace(accessControlEntry.getSpec().getGrantedTo()).getSpec().isSecured();
boolean isAdmin = authentication.getRoles().contains(ResourceBasedSecurityRule.IS_ADMIN);
boolean isSelfAssigned = namespace.equals(accessControlEntry.getSpec().getGrantedTo());

List<String> validationErrors;

if (grantorIsSecured && !granteeIsSecured) {
throw new ResourceValidationException(accessControlEntry, invalidSecuredNamespaceGrantAcl());
}

if (isAdmin && isSelfAssigned) {
// Validate overlapping OWNER
validationErrors = aclService.validateAsAdmin(accessControlEntry, ns);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/michelin/ns4kafka/model/Namespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static class NamespaceSpec {
@NotBlank
private String kafkaUser;
@Builder.Default
private boolean isSecured = Boolean.FALSE;
@Builder.Default
private List<String> connectClusters = List.of();
private TopicValidator topicValidator;
private ConnectValidator connectValidator;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/michelin/ns4kafka/util/FormatErrorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@ public static String invalidQuotaOperationCannotAdd(ResourceQuota.ResourceQuotaS
toAdd));
}

/**
* Invalid secured namespace grant ACL to basic namespaces.
*
* @return the error message
*/
public static String invalidSecuredNamespaceGrantAcl() {
return String.format(INVALID_OPERATION, OPERATION_APPLY,
"secured namespace cannot grant ACL to basic namespaces");
}

/**
* Invalid schema suffix.
*
Expand Down
Loading

0 comments on commit e1f7bb8

Please sign in to comment.