Skip to content
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
5 changes: 5 additions & 0 deletions docs/changelog/135337.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 135337
summary: Do not pass `ProjectMetadata` to lazy index permissions builder
area: Security
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ private IndexResource(String name, @Nullable IndexAbstraction abstraction, @Null
this.selector = selector;
}

public List<Index> getFailureIndices(ProjectMetadata metadata) {
return indexAbstraction != null && IndexComponentSelector.FAILURES.equals(selector)
? indexAbstraction.getFailureIndices(metadata)
: List.of();
}

/**
* @return {@code true} if-and-only-if this object is related to a data-stream, either by having a
* {@link IndexAbstraction#getType()} of {@link IndexAbstraction.Type#DATA_STREAM} or by being the backing index for a
Expand Down Expand Up @@ -535,13 +541,12 @@ public int size(Map<String, IndexAbstraction> lookup) {
}
}

public Collection<String> resolveConcreteIndices(ProjectMetadata metadata) {
public Collection<String> resolveConcreteIndices(List<Index> failureIndices) {
if (indexAbstraction == null) {
return List.of();
} else if (indexAbstraction.getType() == IndexAbstraction.Type.CONCRETE_INDEX) {
return List.of(indexAbstraction.getName());
} else if (IndexComponentSelector.FAILURES.equals(selector)) {
final List<Index> failureIndices = indexAbstraction.getFailureIndices(metadata);
final List<String> concreteIndexNames = new ArrayList<>(failureIndices.size());
for (var idx : failureIndices) {
concreteIndexNames.add(idx.getName());
Expand Down Expand Up @@ -604,12 +609,16 @@ public IndicesAccessControl authorize(

final boolean overallGranted = isActionGranted(action, resources.values());
final int finalTotalResourceCount = totalResourceCount;
final var failureIndicesByResourceName = resources.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getFailureIndices(metadata)));

final Supplier<Map<String, IndicesAccessControl.IndexAccessControl>> indexPermissions = () -> buildIndicesAccessControl(
action,
resources,
finalTotalResourceCount,
fieldPermissionsCache,
metadata
failureIndicesByResourceName
);

return new IndicesAccessControl(overallGranted, indexPermissions);
Expand All @@ -620,7 +629,7 @@ private Map<String, IndicesAccessControl.IndexAccessControl> buildIndicesAccessC
final Map<String, IndexResource> requestedResources,
final int totalResourceCount,
final FieldPermissionsCache fieldPermissionsCache,
final ProjectMetadata metadata
final Map<String, List<Index>> failureIndicesByIndexResource
) {

// now... every index that is associated with the request, must be granted
Expand All @@ -636,7 +645,9 @@ private Map<String, IndicesAccessControl.IndexAccessControl> buildIndicesAccessC
boolean granted = false;
final String resourceName = resourceEntry.getKey();
final IndexResource resource = resourceEntry.getValue();
final Collection<String> concreteIndices = resource.resolveConcreteIndices(metadata);
final Collection<String> concreteIndices = resource.resolveConcreteIndices(
failureIndicesByIndexResource.get(resourceEntry.getKey())
);
for (Group group : groups) {
// the group covers the given index OR the given index is a backing index and the group covers the parent data stream
if (resource.checkIndex(group)) {
Expand Down