|
30 | 30 | import org.elasticsearch.common.settings.Setting.Property;
|
31 | 31 | import org.elasticsearch.common.settings.Settings;
|
32 | 32 | import org.elasticsearch.common.transport.TransportAddress;
|
| 33 | +import org.elasticsearch.common.util.Maps; |
33 | 34 | import org.elasticsearch.common.util.concurrent.ThreadContext;
|
34 | 35 | import org.elasticsearch.core.Nullable;
|
35 | 36 | import org.elasticsearch.core.TimeValue;
|
@@ -372,32 +373,24 @@ public LoggingAuditTrail(Settings settings, ClusterService clusterService, Threa
|
372 | 373 | INCLUDE_REQUEST_BODY
|
373 | 374 | )
|
374 | 375 | );
|
375 |
| - clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_PRINCIPALS, (policyName, filtersList) -> { |
376 |
| - final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName); |
377 |
| - final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings)) |
378 |
| - .changePrincipalsFilter(filtersList); |
379 |
| - this.eventFilterPolicyRegistry.set(policyName, newPolicy); |
380 |
| - }, (policyName, filtersList) -> EventFilterPolicy.parsePredicate(filtersList)); |
381 |
| - clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_REALMS, (policyName, filtersList) -> { |
382 |
| - final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName); |
383 |
| - final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings)).changeRealmsFilter(filtersList); |
384 |
| - this.eventFilterPolicyRegistry.set(policyName, newPolicy); |
385 |
| - }, (policyName, filtersList) -> EventFilterPolicy.parsePredicate(filtersList)); |
386 |
| - clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_ROLES, (policyName, filtersList) -> { |
387 |
| - final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName); |
388 |
| - final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings)).changeRolesFilter(filtersList); |
389 |
| - this.eventFilterPolicyRegistry.set(policyName, newPolicy); |
390 |
| - }, (policyName, filtersList) -> EventFilterPolicy.parsePredicate(filtersList)); |
391 |
| - clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_INDICES, (policyName, filtersList) -> { |
392 |
| - final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName); |
393 |
| - final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings)).changeIndicesFilter(filtersList); |
394 |
| - this.eventFilterPolicyRegistry.set(policyName, newPolicy); |
395 |
| - }, (policyName, filtersList) -> EventFilterPolicy.parsePredicate(filtersList)); |
396 |
| - clusterService.getClusterSettings().addAffixUpdateConsumer(FILTER_POLICY_IGNORE_ACTIONS, (policyName, filtersList) -> { |
397 |
| - final Optional<EventFilterPolicy> policy = eventFilterPolicyRegistry.get(policyName); |
398 |
| - final EventFilterPolicy newPolicy = policy.orElse(new EventFilterPolicy(policyName, settings)).changeActionsFilter(filtersList); |
399 |
| - this.eventFilterPolicyRegistry.set(policyName, newPolicy); |
400 |
| - }, (policyName, filtersList) -> EventFilterPolicy.parsePredicate(filtersList)); |
| 376 | + clusterService.getClusterSettings() |
| 377 | + .addAffixGroupUpdateConsumer( |
| 378 | + org.elasticsearch.core.List.of( |
| 379 | + FILTER_POLICY_IGNORE_PRINCIPALS, |
| 380 | + FILTER_POLICY_IGNORE_REALMS, |
| 381 | + FILTER_POLICY_IGNORE_ROLES, |
| 382 | + FILTER_POLICY_IGNORE_INDICES, |
| 383 | + FILTER_POLICY_IGNORE_ACTIONS |
| 384 | + ), |
| 385 | + (policyName, updatedSettings) -> { |
| 386 | + if (updatedSettings.keySet().isEmpty()) { |
| 387 | + this.eventFilterPolicyRegistry.remove(policyName); |
| 388 | + } else { |
| 389 | + this.eventFilterPolicyRegistry.set(policyName, new EventFilterPolicy(policyName, updatedSettings)); |
| 390 | + } |
| 391 | + } |
| 392 | + ); |
| 393 | + |
401 | 394 | // this log filter ensures that audit events are not filtered out because of the log level
|
402 | 395 | final LoggerContext ctx = LoggerContext.getContext(false);
|
403 | 396 | MarkerFilter auditMarkerFilter = MarkerFilter.createFilter(AUDIT_MARKER.getName(), Result.ACCEPT, Result.NEUTRAL);
|
@@ -1569,92 +1562,21 @@ private static final class EventFilterPolicy {
|
1569 | 1562 | private final Predicate<String> ignoreIndicesPredicate;
|
1570 | 1563 | private final Predicate<String> ignoreActionsPredicate;
|
1571 | 1564 |
|
1572 |
| - EventFilterPolicy(String name, Settings settings) { |
1573 |
| - this( |
1574 |
| - name, |
1575 |
| - parsePredicate(FILTER_POLICY_IGNORE_PRINCIPALS.getConcreteSettingForNamespace(name).get(settings)), |
1576 |
| - parsePredicate(FILTER_POLICY_IGNORE_REALMS.getConcreteSettingForNamespace(name).get(settings)), |
1577 |
| - parsePredicate(FILTER_POLICY_IGNORE_ROLES.getConcreteSettingForNamespace(name).get(settings)), |
1578 |
| - parsePredicate(FILTER_POLICY_IGNORE_INDICES.getConcreteSettingForNamespace(name).get(settings)), |
1579 |
| - parsePredicate(FILTER_POLICY_IGNORE_ACTIONS.getConcreteSettingForNamespace(name).get(settings)) |
1580 |
| - ); |
1581 |
| - } |
1582 |
| - |
1583 | 1565 | /**
|
1584 | 1566 | * An empty filter list for a field will match events with that field missing.
|
1585 | 1567 | * An event with an undefined field has the field value the empty string ("") or
|
1586 | 1568 | * a singleton list of the empty string ([""]).
|
1587 | 1569 | */
|
1588 |
| - EventFilterPolicy( |
1589 |
| - String name, |
1590 |
| - Predicate<String> ignorePrincipalsPredicate, |
1591 |
| - Predicate<String> ignoreRealmsPredicate, |
1592 |
| - Predicate<String> ignoreRolesPredicate, |
1593 |
| - Predicate<String> ignoreIndicesPredicate, |
1594 |
| - Predicate<String> ignoreActionsPredicate |
1595 |
| - ) { |
| 1570 | + EventFilterPolicy(String name, Settings settings) { |
1596 | 1571 | this.name = name;
|
1597 | 1572 | // "null" values are "unexpected" and should not match any ignore policy
|
1598 |
| - this.ignorePrincipalsPredicate = ignorePrincipalsPredicate; |
1599 |
| - this.ignoreRealmsPredicate = ignoreRealmsPredicate; |
1600 |
| - this.ignoreRolesPredicate = ignoreRolesPredicate; |
1601 |
| - this.ignoreIndicesPredicate = ignoreIndicesPredicate; |
1602 |
| - this.ignoreActionsPredicate = ignoreActionsPredicate; |
1603 |
| - } |
1604 |
| - |
1605 |
| - private EventFilterPolicy changePrincipalsFilter(List<String> filtersList) { |
1606 |
| - return new EventFilterPolicy( |
1607 |
| - name, |
1608 |
| - parsePredicate(filtersList), |
1609 |
| - ignoreRealmsPredicate, |
1610 |
| - ignoreRolesPredicate, |
1611 |
| - ignoreIndicesPredicate, |
1612 |
| - ignoreActionsPredicate |
1613 |
| - ); |
1614 |
| - } |
1615 |
| - |
1616 |
| - private EventFilterPolicy changeRealmsFilter(List<String> filtersList) { |
1617 |
| - return new EventFilterPolicy( |
1618 |
| - name, |
1619 |
| - ignorePrincipalsPredicate, |
1620 |
| - parsePredicate(filtersList), |
1621 |
| - ignoreRolesPredicate, |
1622 |
| - ignoreIndicesPredicate, |
1623 |
| - ignoreActionsPredicate |
1624 |
| - ); |
1625 |
| - } |
1626 |
| - |
1627 |
| - private EventFilterPolicy changeRolesFilter(List<String> filtersList) { |
1628 |
| - return new EventFilterPolicy( |
1629 |
| - name, |
1630 |
| - ignorePrincipalsPredicate, |
1631 |
| - ignoreRealmsPredicate, |
1632 |
| - parsePredicate(filtersList), |
1633 |
| - ignoreIndicesPredicate, |
1634 |
| - ignoreActionsPredicate |
1635 |
| - ); |
1636 |
| - } |
1637 |
| - |
1638 |
| - private EventFilterPolicy changeIndicesFilter(List<String> filtersList) { |
1639 |
| - return new EventFilterPolicy( |
1640 |
| - name, |
1641 |
| - ignorePrincipalsPredicate, |
1642 |
| - ignoreRealmsPredicate, |
1643 |
| - ignoreRolesPredicate, |
1644 |
| - parsePredicate(filtersList), |
1645 |
| - ignoreActionsPredicate |
1646 |
| - ); |
1647 |
| - } |
1648 |
| - |
1649 |
| - private EventFilterPolicy changeActionsFilter(List<String> filtersList) { |
1650 |
| - return new EventFilterPolicy( |
1651 |
| - name, |
1652 |
| - ignorePrincipalsPredicate, |
1653 |
| - ignoreRealmsPredicate, |
1654 |
| - ignoreRolesPredicate, |
1655 |
| - ignoreIndicesPredicate, |
1656 |
| - parsePredicate(filtersList) |
| 1573 | + this.ignorePrincipalsPredicate = parsePredicate( |
| 1574 | + FILTER_POLICY_IGNORE_PRINCIPALS.getConcreteSettingForNamespace(name).get(settings) |
1657 | 1575 | );
|
| 1576 | + this.ignoreRealmsPredicate = parsePredicate(FILTER_POLICY_IGNORE_REALMS.getConcreteSettingForNamespace(name).get(settings)); |
| 1577 | + this.ignoreRolesPredicate = parsePredicate(FILTER_POLICY_IGNORE_ROLES.getConcreteSettingForNamespace(name).get(settings)); |
| 1578 | + this.ignoreIndicesPredicate = parsePredicate(FILTER_POLICY_IGNORE_INDICES.getConcreteSettingForNamespace(name).get(settings)); |
| 1579 | + this.ignoreActionsPredicate = parsePredicate(FILTER_POLICY_IGNORE_ACTIONS.getConcreteSettingForNamespace(name).get(settings)); |
1658 | 1580 | }
|
1659 | 1581 |
|
1660 | 1582 | static Predicate<String> parsePredicate(List<String> l) {
|
@@ -1725,16 +1647,18 @@ private EventFilterPolicyRegistry(Settings settings) {
|
1725 | 1647 | predicate = buildIgnorePredicate(policyMap);
|
1726 | 1648 | }
|
1727 | 1649 |
|
1728 |
| - private Optional<EventFilterPolicy> get(String policyName) { |
1729 |
| - return Optional.ofNullable(policyMap.get(policyName)); |
1730 |
| - } |
1731 |
| - |
1732 | 1650 | private synchronized void set(String policyName, EventFilterPolicy eventFilterPolicy) {
|
1733 | 1651 | policyMap = MapBuilder.newMapBuilder(policyMap).put(policyName, eventFilterPolicy).immutableMap();
|
1734 | 1652 | // precompute predicate
|
1735 | 1653 | predicate = buildIgnorePredicate(policyMap);
|
1736 | 1654 | }
|
1737 | 1655 |
|
| 1656 | + private synchronized void remove(String policyName) { |
| 1657 | + policyMap = Maps.copyMapWithRemovedEntry(policyMap, policyName); |
| 1658 | + // precompute predicate |
| 1659 | + predicate = buildIgnorePredicate(policyMap); |
| 1660 | + } |
| 1661 | + |
1738 | 1662 | Predicate<AuditEventMetaInfo> ignorePredicate() {
|
1739 | 1663 | return predicate;
|
1740 | 1664 | }
|
|
0 commit comments