Skip to content

Commit

Permalink
Fix public ACL being visible in other clusters (#493)
Browse files Browse the repository at this point in the history
* Fix public ACL being visible to other cluster's namespace

* Fix unit tests
  • Loading branch information
ThomasCAI-mlv authored Dec 9, 2024
1 parent 85591e4 commit 36987ac
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/michelin/ns4kafka/service/AclService.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void delete(AccessControlEntry accessControlEntry) {
* @return A list of ACLs
*/
public List<AccessControlEntry> findAllGrantedToNamespace(Namespace namespace) {
return accessControlEntryRepository.findAll()
return findAllForCluster(namespace.getMetadata().getCluster())
.stream()
.filter(acl -> acl.getSpec().getGrantedTo().equals(namespace.getMetadata().getName())
|| acl.getSpec().getGrantedTo().equals(PUBLIC_GRANTED_TO))
Expand All @@ -269,7 +269,7 @@ public List<AccessControlEntry> findAllGrantedToNamespace(Namespace namespace) {
* @return A list of ACLs
*/
public List<AccessControlEntry> findAllGrantedByNamespace(Namespace namespace) {
return accessControlEntryRepository.findAll()
return findAllForCluster(namespace.getMetadata().getCluster())
.stream()
.filter(acl -> acl.getMetadata().getNamespace().equals(namespace.getMetadata().getName()))
.toList();
Expand All @@ -282,7 +282,7 @@ public List<AccessControlEntry> findAllGrantedByNamespace(Namespace namespace) {
* @return A list of ACLs
*/
public List<AccessControlEntry> findAllGrantedByNamespaceToOthers(Namespace namespace) {
return accessControlEntryRepository.findAll()
return findAllForCluster(namespace.getMetadata().getCluster())
.stream()
.filter(acl -> acl.getMetadata().getNamespace().equals(namespace.getMetadata().getName()))
.filter(acl -> !acl.getSpec().getGrantedTo().equals(namespace.getMetadata().getName()))
Expand All @@ -296,7 +296,7 @@ public List<AccessControlEntry> findAllGrantedByNamespaceToOthers(Namespace name
* @return A list of ACLs
*/
public List<AccessControlEntry> findAllRelatedToNamespace(Namespace namespace) {
return accessControlEntryRepository.findAll()
return findAllForCluster(namespace.getMetadata().getCluster())
.stream()
.filter(acl -> acl.getMetadata().getNamespace().equals(namespace.getMetadata().getName())
|| acl.getSpec().getGrantedTo().equals(namespace.getMetadata().getName())
Expand Down Expand Up @@ -374,7 +374,7 @@ public List<AccessControlEntry> findAllRelatedToNamespaceByWildcardName(Namespac
*/
public List<AccessControlEntry> findResourceOwnerGrantedToNamespace(Namespace namespace,
AccessControlEntry.ResourceType resourceType) {
return accessControlEntryRepository.findAll()
return findAllForCluster(namespace.getMetadata().getCluster())
.stream()
.filter(acl -> acl.getSpec().getGrantedTo().equals(namespace.getMetadata().getName())
&& acl.getSpec().getPermission() == AccessControlEntry.Permission.OWNER
Expand All @@ -401,7 +401,8 @@ public List<AccessControlEntry> findAllPublicGrantedTo() {
* @return A list of ACLs
*/
public List<AccessControlEntry> findAllForNamespace(Namespace namespace) {
return accessControlEntryRepository.findAll().stream()
return findAllForCluster(namespace.getMetadata().getCluster())
.stream()
.filter(accessControlEntry -> accessControlEntry.getMetadata().getNamespace()
.equals(namespace.getMetadata().getName()))
.toList();
Expand Down
Loading

0 comments on commit 36987ac

Please sign in to comment.