Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Triple logging of audit messages #1995

Closed
jchipmunk opened this issue Aug 5, 2022 · 1 comment
Closed

[BUG] Triple logging of audit messages #1995

jchipmunk opened this issue Aug 5, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@jchipmunk
Copy link
Contributor

What is the bug?
OpenSearch log contains extra audit messages:

[2022-08-05T08:03:52,622][INFO ][sgaudit                  ] [opensearch-1] {"audit_cluster_name":"opensearch","audit_transport_headers":{"_system_index_access_allowed":"false"},"audit_node_name":"opensearch-1","audit_trace_task_id":"wlV1pg8FSlWuVvCZgniL8w:104","audit_transport_request_type":"GetIndexRequest","audit_category":"INDEX_EVENT","audit_request_origin":"REST","audit_node_id":"wlV1pg8FSlWuVvCZgniL8w","audit_request_layer":"TRANSPORT","@timestamp":"2022-08-05T08:03:52.595+00:00","audit_format_version":4,"audit_request_remote_address":"192.168.160.1","audit_request_privilege":"indices:admin/get","audit_node_host_address":"192.168.160.2","audit_request_effective_user":"admin","audit_trace_indices":[".opendistro_security"],"audit_trace_resolved_indices":[".opendistro_security"],"audit_node_host_name":"192.168.160.2"}
[2022-08-05T08:03:52,623][WARN ][sgaudit                  ] [opensearch-1] {"audit_cluster_name":"opensearch","audit_transport_headers":{"_system_index_access_allowed":"false"},"audit_node_name":"opensearch-1","audit_trace_task_id":"wlV1pg8FSlWuVvCZgniL8w:104","audit_transport_request_type":"GetIndexRequest","audit_category":"INDEX_EVENT","audit_request_origin":"REST","audit_node_id":"wlV1pg8FSlWuVvCZgniL8w","audit_request_layer":"TRANSPORT","@timestamp":"2022-08-05T08:03:52.595+00:00","audit_format_version":4,"audit_request_remote_address":"192.168.160.1","audit_request_privilege":"indices:admin/get","audit_node_host_address":"192.168.160.2","audit_request_effective_user":"admin","audit_trace_indices":[".opendistro_security"],"audit_trace_resolved_indices":[".opendistro_security"],"audit_node_host_name":"192.168.160.2"}
[2022-08-05T08:03:52,623][ERROR][sgaudit                  ] [opensearch-1] {"audit_cluster_name":"opensearch","audit_transport_headers":{"_system_index_access_allowed":"false"},"audit_node_name":"opensearch-1","audit_trace_task_id":"wlV1pg8FSlWuVvCZgniL8w:104","audit_transport_request_type":"GetIndexRequest","audit_category":"INDEX_EVENT","audit_request_origin":"REST","audit_node_id":"wlV1pg8FSlWuVvCZgniL8w","audit_request_layer":"TRANSPORT","@timestamp":"2022-08-05T08:03:52.595+00:00","audit_format_version":4,"audit_request_remote_address":"192.168.160.1","audit_request_privilege":"indices:admin/get","audit_node_host_address":"192.168.160.2","audit_request_effective_user":"admin","audit_trace_indices":[".opendistro_security"],"audit_trace_resolved_indices":[".opendistro_security"],"audit_node_host_name":"192.168.160.2"}

How can one reproduce the bug?
Steps to reproduce the behavior:

  1. Perform the following request:
    curl -XGET http://localhost:19200/.opendistro_security
    
    to get information about .opendistro_security index.
  2. Check log messages

What is the expected behavior?
The log must only contain one audit message instead of three:

[2022-08-05T08:03:52,622][INFO ][sgaudit                  ] [opensearch-1] {"audit_cluster_name":"opensearch","audit_transport_headers":{"_system_index_access_allowed":"false"},"audit_node_name":"opensearch-1","audit_trace_task_id":"wlV1pg8FSlWuVvCZgniL8w:104","audit_transport_request_type":"GetIndexRequest","audit_category":"INDEX_EVENT","audit_request_origin":"REST","audit_node_id":"wlV1pg8FSlWuVvCZgniL8w","audit_request_layer":"TRANSPORT","@timestamp":"2022-08-05T08:03:52.595+00:00","audit_format_version":4,"audit_request_remote_address":"192.168.160.1","audit_request_privilege":"indices:admin/get","audit_node_host_address":"192.168.160.2","audit_request_effective_user":"admin","audit_trace_indices":[".opendistro_security"],"audit_trace_resolved_indices":[".opendistro_security"],"audit_node_host_name":"192.168.160.2"}

What is your host/environment?

  • OS: Linux
  • Version: 1.3.4
  • Plugins: OpenSearch Security

Do you have any screenshots?
n/a

Do you have any additional context?
The bug is the incorrect usage of switch-case construction in org.opensearch.security.auditlog.sink.Log4JSink class:

private boolean isLogLevelEnabled(Logger logger, Level level) {
    boolean isEnabled = false;
    switch(level.toString()) {
        case "TRACE": isEnabled = logger.isTraceEnabled();
        case "DEBUG": isEnabled = logger.isDebugEnabled();
        case "INFO": isEnabled = logger.isInfoEnabled();
        case "WARN": isEnabled = logger.isWarnEnabled();
        case "ERROR": isEnabled = logger.isErrorEnabled();
    }
    return isEnabled;
}

private void logAtLevel(Logger logger, Level level, String msg) {
    switch(level.toString()) {
        case "TRACE": logger.trace(msg);
        case "DEBUG": logger.debug(msg);
        case "INFO": logger.info(msg);
        case "WARN": logger.warn(msg);
        case "ERROR": logger.error(msg);
    }
}

This code does not contain break/return keywords to stop switching.
It seems the changes were not rolled back in PR: Switch to log4j logger.

@jchipmunk jchipmunk added bug Something isn't working untriaged Require the attention of the repository maintainers and may need to be prioritized labels Aug 5, 2022
@peternied peternied removed the untriaged Require the attention of the repository maintainers and may need to be prioritized label Aug 8, 2022
@peternied
Copy link
Member

Thanks for filing, and thank you for the pull request!

peternied pushed a commit that referenced this issue Aug 12, 2022
Revert some changes introduced by #1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this issue Aug 12, 2022
Revert some changes introduced by #1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
(cherry picked from commit 68f5624)
opensearch-trigger-bot bot pushed a commit that referenced this issue Aug 12, 2022
Revert some changes introduced by #1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
(cherry picked from commit 68f5624)
peternied pushed a commit that referenced this issue Aug 12, 2022
Revert some changes introduced by #1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
(cherry picked from commit 68f5624)

Co-authored-by: Andrey Pustovetov <[email protected]>
stephen-crawford pushed a commit to stephen-crawford/security that referenced this issue Nov 10, 2022
…t#1996)

Revert some changes introduced by opensearch-project#1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
Signed-off-by: Stephen Crawford <[email protected]>
wuychn pushed a commit to ochprince/security that referenced this issue Mar 16, 2023
…t#1996) (opensearch-project#2024)

Revert some changes introduced by opensearch-project#1563 to correct work with log4j.

Signed-off-by: Andrey Pustovetov <[email protected]>
(cherry picked from commit 68f5624)

Co-authored-by: Andrey Pustovetov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants