Skip to content

Commit

Permalink
Adds auditlog capability and conform to changes in core
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 20, 2024
1 parent 428e11e commit a55ac22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ public void onIndexModule(IndexModule indexModule) {

if (this.indicesToListen.contains(indexModule.getIndex().getName())) {
ResourceSharingIndexListener resourceSharingIndexListener = ResourceSharingIndexListener.getInstance();
resourceSharingIndexListener.initialize(threadPool, localClient);
resourceSharingIndexListener.initialize(threadPool, localClient, auditLog);
indexModule.addIndexOperationListener(resourceSharingIndexListener);
log.warn("Security plugin started listening to operations on index {}", indexModule.getIndex().getName());
}
Expand Down Expand Up @@ -1215,7 +1215,12 @@ public Collection<Object> createComponents(
}

final var resourceSharingIndex = ConfigConstants.OPENSEARCH_RESOURCE_SHARING_INDEX;
ResourceSharingIndexHandler rsIndexHandler = new ResourceSharingIndexHandler(resourceSharingIndex, localClient, threadPool);
ResourceSharingIndexHandler rsIndexHandler = new ResourceSharingIndexHandler(
resourceSharingIndex,
localClient,
threadPool,
auditLog
);
resourceAccessHandler = new ResourceAccessHandler(threadPool, rsIndexHandler, adminDns);

rmr = ResourceSharingIndexManagementRepository.create(rsIndexHandler);
Expand Down Expand Up @@ -2150,8 +2155,12 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
ConfigConstants.SECURITY_CONFIG_INDEX_NAME,
ConfigConstants.OPENDISTRO_SECURITY_DEFAULT_CONFIG_INDEX
);
final SystemIndexDescriptor systemIndexDescriptor = new SystemIndexDescriptor(indexPattern, "Security index");
return Collections.singletonList(systemIndexDescriptor);
final SystemIndexDescriptor securityIndexDescriptor = new SystemIndexDescriptor(indexPattern, "Security index");
final SystemIndexDescriptor resourceSharingIndexDescriptor = new SystemIndexDescriptor(
ConfigConstants.OPENSEARCH_RESOURCE_SHARING_INDEX,
"Resource Sharing index"
);
return List.of(securityIndexDescriptor, resourceSharingIndexDescriptor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private boolean checkSharing(ResourceSharing document, EntityType entityType, St
.filter(sharedWithScope -> sharedWithScope.getScope().equals(scope))
.findFirst()
.map(sharedWithScope -> {
SharedWithScope.SharedWithPerScope scopePermissions = sharedWithScope.getSharedWithPerScope();
SharedWithScope.ScopeRecipients scopePermissions = sharedWithScope.getSharedWithPerScope();

return switch (entityType) {
case EntityType.USERS -> scopePermissions.getUsers().contains(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.opensearch.search.SearchHit;
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.security.DefaultObjectMapper;
import org.opensearch.security.auditlog.AuditLog;
import org.opensearch.threadpool.ThreadPool;

import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
Expand All @@ -84,10 +85,13 @@ public class ResourceSharingIndexHandler {

private final ThreadPool threadPool;

public ResourceSharingIndexHandler(final String indexName, final Client client, ThreadPool threadPool) {
private final AuditLog auditLog;

public ResourceSharingIndexHandler(final String indexName, final Client client, final ThreadPool threadPool, final AuditLog auditLog) {
this.resourceSharingIndex = indexName;
this.client = client;
this.threadPool = threadPool;
this.auditLog = auditLog;
}

public final static Map<String, Object> INDEX_SETTINGS = Map.of("index.number_of_shards", 1, "index.auto_expand_replicas", "0-all");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.index.engine.Engine;
import org.opensearch.index.shard.IndexingOperationListener;
import org.opensearch.security.auditlog.AuditLog;
import org.opensearch.security.support.ConfigConstants;
import org.opensearch.security.user.User;
import org.opensearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -53,7 +54,7 @@ public static ResourceSharingIndexListener getInstance() {
* @param threadPool The ThreadPool instance to be used for executing operations.
* @param client The Client instance to be used for interacting with OpenSearch.
*/
public void initialize(ThreadPool threadPool, Client client) {
public void initialize(ThreadPool threadPool, Client client, AuditLog auditLog) {

if (initialized) {
return;
Expand All @@ -64,7 +65,8 @@ public void initialize(ThreadPool threadPool, Client client) {
this.resourceSharingIndexHandler = new ResourceSharingIndexHandler(
ConfigConstants.OPENSEARCH_RESOURCE_SHARING_INDEX,
client,
threadPool
threadPool,
auditLog
);

}
Expand Down

0 comments on commit a55ac22

Please sign in to comment.