Skip to content

Fix thread usage issue for Palo Alto Panorama Syslog payload - #26960

Open
Nithin-Kasam wants to merge 3 commits into
masterfrom
issue-14949
Open

Fix thread usage issue for Palo Alto Panorama Syslog payload#26960
Nithin-Kasam wants to merge 3 commits into
masterfrom
issue-14949

Conversation

@Nithin-Kasam

Copy link
Copy Markdown
Collaborator

Description

Changed the PANORAMA_SYSLOG_PARSER regex in PaloAltoParser from adjacent unbounded lazy groups (.+?) (.+?) to non-whitespace token groups (\S+) (\S+) for the timestamp and hostname captures.

Motivation and Context

closes https://github.com/Graylog2/graylog-plugin-enterprise/issues/14949

How Has This Been Tested?

-> Added unit test cases which parses both old and new pattern payloads.
-> Manually set up palo Alto VM and created Palo Alto Networks TCP (PAN-OS v11+) input and verified the logs.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [ x] My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have requested a documentation update.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@danotorrey danotorrey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good and tested successfully on my end. One additional case that needs covering (noted inline below), plus a few smaller test improvements and nits.

private static final Pattern PANORAMA_SYSLOG_PARSER = Pattern.compile("<\\d+>[0-9] (.+?) (.+?)\\s[-]\\s[-]\\s[-]\\s[-]\\s(\\d,.*)");
// NOTE: (\S+) is used for the timestamp and hostname groups — both tokens are
// guaranteed to be whitespace-free, so \S+ is fully equivalent to the original (.+?).
private static final Pattern PANORAMA_SYSLOG_PARSER = Pattern.compile("<\\d+>[0-9] (\\S+) (\\S+)\\s[-]\\s[-]\\s[-]\\s[-]\\s(\\d,.*)");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From testing it looks like the standard-syslog pattern(STANDARD_SYSLOG_PARSER, line 57) just below this one needs the same fix as the others. The same issue still happened for that pattern. Could we apply the same fix there and add test coverage for it?

Comment on lines +51 to +52
// NOTE: (\S+) is used for the timestamp and hostname groups — both tokens are
// guaranteed to be whitespace-free, so \S+ is fully equivalent to the original (.+?).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment isn't quite right: \S+ isn't equivalent to (.+?) (the old groups could span spaces, so whitespace in a token or extra fields before the delimiter matched before and won't now). Fix is fine thought. Maybe tighten up the comment to the following would be best:

Suggested change
// NOTE: (\S+) is used for the timestamp and hostname groups — both tokens are
// guaranteed to be whitespace-free, so \S+ is fully equivalent to the original (.+?).
// Timestamp and hostname are single whitespace-free tokens, so \S+ matches
// every conformant Panorama header.


@Test
public void parse_craftedPanoramaPrefix_missingDelimiter_completesQuickly_small() {
// 200 space-separated tokens — enough to be slow with old O(n²) regex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These timing tests finish well under the 2s budget either way (I tried the previous pattern and they still pass), so they don't really lock in the change. Might be worth asserting the parse behavior directly, or sizing the payload so it would actually fail on the old pattern, so this stays a real regression guard.

}

@Test
public void parse_panoramaMessageWithNoTimezoneOffset_parsesWithProvidedZone() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: since this is the only test hitting the no-offset path with a non-UTC zone, it'd be good to also assert the resulting timestamp (right now it only checks source), otherwise the timezone handling here isn't really covered.

// 200 space-separated tokens — enough to be slow with old O(n²) regex
final String payload = buildCraftedPayload(200);

assertTimeout(Duration.ofSeconds(2), () ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I think we should swap assertTimeout for assertTimeoutPreemptively here (all three spots). assertTimeout doesn't interrupt the block, it lets it run to completion and only then checks whether it took too long, so if a parse ever actually hangs the test hangs with it instead of failing at the 2s mark. assertTimeoutPreemptively runs the block on a separate thread and aborts it when the timeout hits, which is what you want here. Let me know if you see any issue with this or if it doesn't sound correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants