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

Cherry-pick #12579 to 7.2: Filebeat: Add support for ISO8601 dates to system.auth #12593

Merged
merged 4 commits into from
Jun 18, 2019
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ https://github.com/elastic/beats/compare/v7.2.0...7.2[Check the HEAD diff]

*Filebeat*

- Add full ISO8601 date parsing support for system/syslog module. {pull}12568[12568]
- Add ISO8601 date parsing support for system module. {pull}12568[12568] {pull}12579[12579]

*Heartbeat*

Expand Down
20 changes: 11 additions & 9 deletions filebeat/module/system/auth/ingest/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
"field": "message",
"ignore_missing": true,
"pattern_definitions" : {
"GREEDYMULTILINE" : "(.|\n)*"
"GREEDYMULTILINE" : "(.|\n)*",
"TIMESTAMP": "(?:%{TIMESTAMP_ISO8601}|%{SYSLOGTIMESTAMP})"
},
"patterns": [
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: %{DATA:system.auth.ssh.event} %{DATA:system.auth.ssh.method} for (invalid user )?%{DATA:user.name} from %{IPORHOST:source.ip} port %{NUMBER:source.port:long} ssh2(: %{GREEDYDATA:system.auth.ssh.signature})?",
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: %{DATA:system.auth.ssh.event} user %{DATA:user.name} from %{IPORHOST:source.ip}",
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: Did not receive identification string from %{IPORHOST:system.auth.ssh.dropped_ip}",
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: \\s*%{DATA:user.name} :( %{DATA:system.auth.sudo.error} ;)? TTY=%{DATA:system.auth.sudo.tty} ; PWD=%{DATA:system.auth.sudo.pwd} ; USER=%{DATA:system.auth.sudo.user} ; COMMAND=%{GREEDYDATA:system.auth.sudo.command}",
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: new group: name=%{DATA:group.name}, GID=%{NUMBER:group.id}",
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: new user: name=%{DATA:user.name}, UID=%{NUMBER:user.id}, GID=%{NUMBER:group.id}, home=%{DATA:system.auth.useradd.home}, shell=%{DATA:system.auth.useradd.shell}$",
"%{SYSLOGTIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname}? %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: %{GREEDYMULTILINE:system.auth.message}"
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: %{DATA:system.auth.ssh.event} %{DATA:system.auth.ssh.method} for (invalid user )?%{DATA:user.name} from %{IPORHOST:source.ip} port %{NUMBER:source.port:long} ssh2(: %{GREEDYDATA:system.auth.ssh.signature})?",
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: %{DATA:system.auth.ssh.event} user %{DATA:user.name} from %{IPORHOST:source.ip}",
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: Did not receive identification string from %{IPORHOST:system.auth.ssh.dropped_ip}",
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: \\s*%{DATA:user.name} :( %{DATA:system.auth.sudo.error} ;)? TTY=%{DATA:system.auth.sudo.tty} ; PWD=%{DATA:system.auth.sudo.pwd} ; USER=%{DATA:system.auth.sudo.user} ; COMMAND=%{GREEDYDATA:system.auth.sudo.command}",
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: new group: name=%{DATA:group.name}, GID=%{NUMBER:group.id}",
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname} %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: new user: name=%{DATA:user.name}, UID=%{NUMBER:user.id}, GID=%{NUMBER:group.id}, home=%{DATA:system.auth.useradd.home}, shell=%{DATA:system.auth.useradd.shell}$",
"%{TIMESTAMP:system.auth.timestamp} %{SYSLOGHOST:host.hostname}? %{DATA:process.name}(?:\\[%{POSINT:process.pid:long}\\])?: %{GREEDYMULTILINE:system.auth.message}"
]
}
},
Expand Down Expand Up @@ -44,7 +45,8 @@
"target_field": "@timestamp",
"formats": [
"MMM d HH:mm:ss",
"MMM dd HH:mm:ss"
"MMM dd HH:mm:ss",
"ISO8601"
],
{< if .convert_timezone >}"timezone": "{{ event.timezone }}",{< end >}
"ignore_failure": true
Expand Down
2 changes: 2 additions & 0 deletions filebeat/module/system/auth/test/timestamp.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2019-06-14T10:40:20.912134 localhost sudo: pam_unix(sudo-i:session): session opened for user root by userauth3(uid=0)
2019-06-14T13:01:15.412+01:30 localhost pam: user nobody logged out.
30 changes: 30 additions & 0 deletions filebeat/module/system/auth/test/timestamp.log-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"@timestamp": "2019-06-14T10:40:20.912Z",
"ecs.version": "1.0.0",
"event.dataset": "system.auth",
"event.module": "system",
"fileset.name": "auth",
"host.hostname": "localhost",
"input.type": "log",
"log.file.path": "timestamp.log",
"log.offset": 0,
"message": "pam_unix(sudo-i:session): session opened for user root by userauth3(uid=0)",
"process.name": "sudo",
"service.type": "system"
},
{
"@timestamp": "2019-06-14T11:31:15.412Z",
"ecs.version": "1.0.0",
"event.dataset": "system.auth",
"event.module": "system",
"fileset.name": "auth",
"host.hostname": "localhost",
"input.type": "log",
"log.file.path": "timestamp.log",
"log.offset": 118,
"message": "user nobody logged out.",
"process.name": "pam",
"service.type": "system"
}
]
32 changes: 16 additions & 16 deletions filebeat/tests/system/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def clean_keys(obj):
time_keys = ["event.created"]
# source path and agent.version can be different for each run
other_keys = ["log.file.path", "agent.version"]
# datasets for which @timestamp is removed due to date missing
remove_timestamp = {"icinga.startup", "redis.log", "haproxy.log", "system.auth", "system.syslog"}
# dataset + log file pairs for which @timestamp is kept as an exception from above
remove_timestamp_exception = {
('system.syslog', 'tz-offset.log'),
('system.auth', 'timestamp.log')
}

# Keep source log filename for exceptions
filename = None
Expand All @@ -225,23 +232,16 @@ def clean_keys(obj):
for key in host_keys + time_keys + other_keys:
delete_key(obj, key)

# Remove timestamp for comparison where timestamp is not part of the log line
if (obj["event.dataset"] in ["icinga.startup", "redis.log", "haproxy.log", "system.auth"]):
delete_key(obj, "@timestamp")

# HACK: This keeps @timestamp for the tz-offset.log in system.syslog.
#
# This can't be done for all syslog logs because most of them lack the year
# in their timestamp, so Elasticsearch will set it to the current year and
# that will cause the tests to fail every new year.
#
# The log.file.path key needs to be kept so that it is stored in the golden
# data, to prevent @timestamp to be removed from it before comparison.
if obj["event.dataset"] == "system.syslog":
if filename == "tz-offset.log":
obj["log.file.path"] = filename
else:
# Most logs from syslog need their timestamp removed because it doesn't
# include a year.
if obj["event.dataset"] in remove_timestamp:
if not (obj['event.dataset'], filename) in remove_timestamp_exception:
delete_key(obj, "@timestamp")
else:
# excluded events need to have their filename saved to the expected.json
# so that the exception mechanism can be triggered when the json is
# loaded.
obj["log.file.path"] = filename


def delete_key(obj, key):
Expand Down