Repository navigation
Allow audit logging to be turned on/off without server restart - #147333
ankit--sethi merged 27 commits into
Conversation
…rt since AuditTrailService is initialized or not based on its value during server start. This change updates the code to always have AuditTrailService/LoggingAuditTrail ready to go, gated by current value of the setting. The setting is updated to be dynamic and AuditTrailService is updated to check its current value to switch between regular audit operations or a no-op. Various tests are adjusted to work with this change, plus three new integration tests that cover an ES server turning on with the setting on/off/unset respectively, and then flipping its value back and forth.
|
Pinging @elastic/es-security (Team:Security) |
…thout-restart' into feature/change-audit-settings-without-restart
…thout-restart' into feature/change-audit-settings-without-restart
ebarlas
left a comment
There was a problem hiding this comment.
Nice work overall. Gating at AuditTrailService.get() is a tidy solution. End-to-end coverage of the three startup states and the runtime toggle is good.
I offered a handful of suggestions, ranging from docs to code clean-up and organization.
| if (isAuditEnabled == false) { | ||
| return NOOP_AUDIT_TRAIL; | ||
| } | ||
| if (auditTrail != null) { |
There was a problem hiding this comment.
Since auditTrail is no longer nullable, this branching logic can be removed.
| /** | ||
| * Manages the lifecycle, mapping and data upgrades/migrations of the {@code RestrictedIndicesNames#SECURITY_MAIN_ALIAS} | ||
| * and {@code RestrictedIndicesNames#SECURITY_MAIN_ALIAS} alias-index pair. | ||
| * Manages the lifecycle, mapping and data upgrades/migrations of the {@link SecuritySystemIndices#SECURITY_MAIN_ALIAS} |
There was a problem hiding this comment.
This seems unrelated. Was it intended?
| public class AuditLoggingDefaultAtStartupDynamicSwitchingTests extends AuditLoggingOffAtStartupDynamicSwitchingTests { | ||
|
|
||
| @Override | ||
| protected boolean addMockHttpTransport() { |
There was a problem hiding this comment.
This override isn't needed. It's a duplicate of AuditLoggingOffAtStartupDynamicSwitchingTests.
There was a problem hiding this comment.
the abstract base class change covers these and the rest of the issues
| return Settings.builder().put(super.nodeSettings(nodeOrdinal, otherSettings)).remove(XPackSettings.AUDIT_ENABLED.getKey()).build(); | ||
| } | ||
|
|
||
| public void testFlippingAuditLogFalseToTrueToFalse() throws IOException { |
| public class AuditLoggingOnAtStartupDynamicSwitchingTests extends AuditLoggingOffAtStartupDynamicSwitchingTests { | ||
|
|
||
| @Override | ||
| protected boolean addMockHttpTransport() { |
There was a problem hiding this comment.
This override isn't needed. It's a duplicate of AuditLoggingOffAtStartupDynamicSwitchingTests.
| .build(); | ||
| } | ||
|
|
||
| public void testFlippingAuditLogFalseToTrueToFalse() throws IOException { |
| import java.io.IOException; | ||
|
|
||
| @ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1) | ||
| public class AuditLoggingOffAtStartupDynamicSwitchingTests extends SecurityIntegTestCase { |
There was a problem hiding this comment.
For clarity, you might consider a slightly different arrangement with an abstract base class and three concrete subclasses. The off-at-start concrete base class with test method overrides is somewhat surprising.
For example:
public abstract class AbstractAuditLoggingDynamicSwitchingTestCase extends SecurityIntegTestCase {
...
@Override
protected final Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
...
startupAuditEnabled().ifPresent(value -> builder.put(XPackSettings.AUDIT_ENABLED.getKey(), value));
...
}
...
protected abstract Optional<Boolean> startupAuditEnabled();
...
}
There was a problem hiding this comment.
agreed, I was getting lazy here, thanks!
| false, | ||
| Setting.Property.NodeScope | ||
| Setting.Property.NodeScope, | ||
| Setting.Property.Dynamic |
There was a problem hiding this comment.
Consider including corresponding edits in docs/reference/elasticsearch/configuration-reference/auding-settings.md
There was a problem hiding this comment.
ooh yeah that was a miss. There might also be some other doc updates downstream of merging this. I'll check.
| public AuditTrailService(AuditTrail auditTrail, XPackLicenseState licenseState, ClusterService clusterService) { | ||
| this.auditTrail = auditTrail; | ||
| this.licenseState = licenseState; | ||
| clusterService.getClusterSettings().initializeAndWatch(XPackSettings.AUDIT_ENABLED, newValue -> isAuditEnabled = newValue); |
There was a problem hiding this comment.
Consider adding a log statement in the settings callback to highlight the audit change.
🔍 Preview links for changed docs |
ℹ️ Important: Docs version tagging👋 Thanks for updating the docs! Just a friendly reminder that our docs are now cumulative. This means all 9.x versions are documented on the same page and published off of the main branch, instead of creating separate pages for each minor version. We use applies_to tags to mark version-specific features and changes. Expand for a quick overviewWhen to use applies_to tags:✅ At the page level to indicate which products/deployments the content applies to (mandatory) What NOT to do:❌ Don't remove or replace information that applies to an older version 🤔 Need help?
|
…thout-restart' into feature/change-audit-settings-without-restart
docs update Co-authored-by: shainaraskas <58563081+shainaraskas@users.noreply.github.com>
…thout-restart' into feature/change-audit-settings-without-restart
There was a problem hiding this comment.
The section needs to be updated as well to reflect the dynamic setting change.
|
|
||
| This setting can be changed at runtime using the [cluster update settings API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-settings) without requiring a node restart. | ||
|
|
||
| :::{note} |
There was a problem hiding this comment.
I believe this PR is an "enhancement", which means it will only be available in the next release, 9.5.0.
|
Hi @ankit--sethi, I've created a changelog YAML for you. |
…thout-restart' into feature/change-audit-settings-without-restart
…thout-restart' into feature/change-audit-settings-without-restart
…ic#147333) * Currently the setting `xpack.security.audit.enabled` requires a restart since AuditTrailService is initialized or not based on its value during server start. This change updates the code to always have AuditTrailService/LoggingAuditTrail ready to go, gated by current value of the setting. The setting is updated to be dynamic and AuditTrailService is updated to check its current value to switch between regular audit operations or a no-op. Various tests are adjusted to work with this change, plus three new integration tests that cover an ES server turning on with the setting on/off/unset respectively, and then flipping its value back and forth. * [CI] Auto commit changes from spotless * fix tests * [CI] Auto commit changes from spotless * fix without breaking other things * code review feedback * fix tests * Apply suggestions from code review docs update Co-authored-by: shainaraskas <58563081+shainaraskas@users.noreply.github.com> * fix tests * Update docs/changelog/147333.yaml * tweak language and update versions to reflect this is an enhancement * fix error * fix - doc changes are cumulative so not deleting the sentence. * fix - doc changes are cumulative so not deleting the sentence. --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co> Co-authored-by: shainaraskas <58563081+shainaraskas@users.noreply.github.com>
## Summary Companion Docs PR to the update [here](elastic/elasticsearch#147333). The audit logging enabled/disabled setting has changed from static to dynamic for version 9.5+. ## Generative AI disclosure <!-- To help us ensure compliance with the Elastic open source and documentation guidelines, please answer the following: --> 1. Did you use a generative AI (GenAI) tool to assist in creating this contribution? - [x] Yes - [ ] No Claude Opus --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Vlada Chirmicci <vlada.chirmicci@elastic.co>
Currently the setting
xpack.security.audit.enabledrequires a server restart to flip on/off since AuditTrailService is initialized inSecurity.javawith a null/non-nullLoggingAuditTrailinstance based on the setting value.This change updates
AuditTrailServiceto always hold a reference to a workingLoggingAuditTrailinstance; whether it gets used or not is gated by the current value of the setting.The setting itself is updated to be
Setting.Property.DynamicandAuditTrailServicewill now check its current value to switch between regular audit logging or a no-op.Various tests are adjusted to work with this change, plus three new integration tests that cover an ES server turning on with the setting on/off/unset respectively, and then flipping its value back and forth. Each integration tests uses the
PUT /_cluster/settingsAPI to updatexpack.security.audit.enabled, and uses theGET /_security/_authenticateAPI to trigger anaccess_grantedaudit event (or lack thereof).