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

Add key/value suffix for schema filtering on LITERAL ACL on v3 claim #328

Merged
merged 2 commits into from
Oct 3, 2023
Merged
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 @@ -189,13 +189,25 @@ public AkhqClaimResponseV3 generateClaimV3(@Valid @Body AkhqClaimRequest request

// Add the same pattern and cluster filtering for SCHEMA as the TOPIC ones
result.addAll(result.stream()
.filter(g -> g.role.equals(config.getRoles().get(AccessControlEntry.ResourceType.TOPIC)))
.map(g -> AkhqClaimResponseV3.Group.builder()
.role(config.getRoles().get(AccessControlEntry.ResourceType.SCHEMA))
.patterns(g.getPatterns())
.clusters(g.getClusters())
.build()
).toList());
.filter(g -> g.role.equals(config.getRoles().get(AccessControlEntry.ResourceType.TOPIC)))
.map(g -> {
// Takes all the PREFIXED patterns as-is
List<String> patterns = new ArrayList<>(
g.getPatterns().stream().filter(p -> p.endsWith("\\E.*$")).toList());

// Add -key or -value prefix to the schema pattern for LITERAL patterns
patterns.addAll(g.getPatterns().stream()
.filter(p -> p.endsWith("\\E$"))
.map(p -> p.replace("\\E$", "-\\E(key|value)$"))
.toList());

return AkhqClaimResponseV3.Group.builder()
.role(config.getRoles().get(AccessControlEntry.ResourceType.SCHEMA))
.patterns(patterns)
.clusters(g.getClusters())
.build();
}
).toList());

return AkhqClaimResponseV3.builder()
.groups(result.isEmpty() ? null : Map.of("group", result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ void generateClaimAndOptimizePatterns() {
);
Assertions.assertEquals("registry-read", groups.get(2).getRole());
Assertions.assertEquals(
List.of("^\\Qproject1.\\E.*$", "^\\Qproject2.topic2\\E$", "^\\Qproject2.topic2a\\E$",
"^\\Qproject2.topic3\\E$", "^\\Qproject3.\\E.*$"),
List.of("^\\Qproject1.\\E.*$", "^\\Qproject3.\\E.*$", "^\\Qproject2.topic2-\\E(key|value)$",
"^\\Qproject2.topic2a-\\E(key|value)$", "^\\Qproject2.topic3-\\E(key|value)$"),
groups.get(2).getPatterns()
);
}
Expand Down