Skip to content
Open
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 @@ -267,12 +267,24 @@ private void auditApiRequestHandlers(RequestHandler.RequestHandlersBuilder reque
.onChangeRequest(RestRequest.Method.PATCH, request -> withEnabledAuditApi(request).map(this::processPatchRequest))
.onChangeRequest(
RestRequest.Method.PUT,
request -> withEnabledAuditApi(request).map(ignore -> processPutRequest("config", request))
request -> withCreateOrUpdateAuditApi(request).map(ignore -> processPutRequest("config", request))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth getting rid of withEnabledAuditApi entirely?

I see that there's this block which checks for doc existing in .opendistro_security.

I agree that hot reload being disabled should be intentional and not proxied by checking for the auditlog entry in the security index.

)
.override(RestRequest.Method.POST, methodNotImplementedHandler)
.override(RestRequest.Method.DELETE, methodNotImplementedHandler);
}

/**
* Allows PUT to bootstrap the audit config when the document does not exist,
* or to update it through normal validation when it does.
*/
ValidationResult<RestRequest> withCreateOrUpdateAuditApi(final RestRequest request) {
if (!securityApiDependencies.configurationRepository().isAuditHotReloadingEnabled()) {
// Document does not exist — allow PUT to bootstrap the audit config
return ValidationResult.success(request);
}
return withEnabledAuditApi(request);
}

ValidationResult<RestRequest> withEnabledAuditApi(final RestRequest request) {
if (!securityApiDependencies.configurationRepository().isAuditHotReloadingEnabled()) {
return ValidationResult.error(RestStatus.NOT_IMPLEMENTED, methodNotImplementedMessage(request.method()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.opensearch.common.settings.Settings;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.rest.RestRequest;
import org.opensearch.security.auditlog.config.AuditConfig;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
Expand All @@ -42,6 +43,26 @@ public void disabledAuditApi() {
}
}

@Test
public void putAllowedWhenAuditConfigDocDoesNotExist() {
final var auditApiAction = new AuditApiAction(clusterService, threadPool, securityApiDependencies);
when(configurationRepository.isAuditHotReloadingEnabled()).thenReturn(false);

// PUT is allowed when the audit config document does not exist (bootstrap case)
final var result = auditApiAction.withCreateOrUpdateAuditApi(FakeRestRequest.builder().withMethod(RestRequest.Method.PUT).build());
assertTrue(result.isValid());
}

@Test
public void putAllowedWhenAuditConfigDocExists() {
final var auditApiAction = new AuditApiAction(clusterService, threadPool, securityApiDependencies);
when(configurationRepository.isAuditHotReloadingEnabled()).thenReturn(true);

// PUT is also allowed when the audit config document exists (update case)
final var result = auditApiAction.withCreateOrUpdateAuditApi(FakeRestRequest.builder().withMethod(RestRequest.Method.PUT).build());
assertTrue(result.isValid());
}

@Test
public void enabledAuditApi() {
final var auditApiAction = new AuditApiAction(clusterService, threadPool, securityApiDependencies);
Expand Down
Loading