Skip to content

Add protected namespaces possibility #497

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

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -1,8 +1,11 @@
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.invalidSecuredNamespaceGrantPublicAcl;
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 +108,25 @@ public HttpResponse<AccessControlEntry> apply(Authentication authentication,
@QueryValue(defaultValue = "false") boolean dryrun) {
Namespace ns = getNamespace(namespace);

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

List<String> validationErrors;

// secured namespaces are not allowed to grant public ACL
if (grantorIsSecured && granteeIsPublic) {
throw new ResourceValidationException(accessControlEntry, invalidSecuredNamespaceGrantPublicAcl());
}

// secured namespaces are not allowed to grant ACL to basic namespaces
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 secured = Boolean.FALSE;
@Builder.Default
private List<String> connectClusters = List.of();
private TopicValidator topicValidator;
private ConnectValidator connectValidator;
Expand Down
20 changes: 20 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,26 @@ 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 secured namespace grant ACL to basic namespaces.
*
* @return the error message
*/
public static String invalidSecuredNamespaceGrantPublicAcl() {
return String.format(INVALID_OPERATION, OPERATION_APPLY,
"secured namespace cannot grant public ACL");
}

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