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

add tcp flags to aws/vpcflow fileset #23157

Merged
merged 5 commits into from
Jan 13, 2021

Conversation

leehinman
Copy link
Contributor

What does this PR do?

Converts the existing aws.vpcflow.tcp_flags bit mask into an array of
tcp flags and stores them in aws.vpcflow.tcp_flags_array.

Why is it important?

makes it easier to query if a particular flag is set

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
    - [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

TESTING_FILEBEAT_MODULES=aws \
TESTING_FILEBEAT_FILESETS=vpcflow \
mage -v pythonIntegTest

Related issues

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 15, 2020
@leehinman leehinman added enhancement Filebeat Filebeat needs_backport PR is waiting to be backported to other branches. Team:Security-External Integrations labels Dec 15, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Dec 15, 2020
@elasticmachine
Copy link
Collaborator

elasticmachine commented Dec 15, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #23157 updated

    • Start Time: 2021-01-13T21:10:24.059+0000
  • Duration: 48 min 37 sec

  • Commit: b005a83

Test stats 🧪

Test Results
Failed 0
Passed 5129
Skipped 574
Total 5703

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 5129
Skipped 574
Total 5703

@ynirk
Copy link

ynirk commented Dec 16, 2020

@leehinman AWS has a weird way of dealing ACK:

In the Flow Logs, the handshake is shown as two lines, with tcp-flags values of 2 (SYN), 18 (SYN + ACK).  
ACK is reported only when it is accompanied with SYN (otherwise it would be too much noise for you to filter out).

So maybe we should have a syn-ack flag instead of ack when you have syn + ack

@leehinman
Copy link
Contributor Author

@leehinman AWS has a weird way of dealing ACK:

In the Flow Logs, the handshake is shown as two lines, with tcp-flags values of 2 (SYN), 18 (SYN + ACK).  
ACK is reported only when it is accompanied with SYN (otherwise it would be too much noise for you to filter out).

So maybe we should have a syn-ack flag instead of ack when you have syn + ack

If bitmask is 18 you should get

 "aws.vpcflow.tcp_flags_array": [
            "syn",
            "ack"
        ]

Is that OK? The code will add to the array for every bit that is set. I think what Amazon is saying is that they don't bother to report when only 'ack' is set.

@ynirk
Copy link

ynirk commented Dec 16, 2020

sounds good

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

if ((flags & 0x01) != 0) {
ctx.aws.vpcflow.tcp_flags_array.add('fin');
}
if ((flags & 0x02) != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that if you check for 0x12 first (syn-ack) and then subtract that value out this will be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that if you check for 0x12 first (syn-ack) and then subtract that value out this will be good.

This could be grumpy old networking guy talking but there is no SYN-ACK flag, you just have the syn and the ack flags set. So the array that gets populated should contain 'syn' and 'ack'.

  /g/k/h/t/n/n/
 /r/c/s/s/y/i/
/u/a/p/r/s/f/
 0 1 0 0 1 0 (0x12 or 18)

Which would give you:

"aws.vpcflow.tcp_flags_array": ["syn", "ack"]

Or we could go with a keyword instead of array where we cat the flags together separated by "-", that would give:

"aws.vpcflow.tcp_flags_array": "syn-ack"

But I have trouble mixing the two approaches. For example if all the fields were set would you expect:

"aws.vpcflow.tcp_flags_array": ["fin", "syn", "rst", "psh", "ack", "urg"]

or

"aws.vpcflow.tcp_flags_array": ["fin", "syn-ack", "rst", "psh", "urg"]

Copy link
Member

@andrewkroh andrewkroh Dec 21, 2020

Choose a reason for hiding this comment

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

I realize that there is no syn-ack flag and that this is a bitmask. 😄

The reason for the unique handling is that AWS treats ACK special. It only sets the ACK bit when it sees it as part of a SYN,ACK response. If, for example, it sees a plain ACK or PSH,ACK packet in a flow it won't report the ACK bit. So rather than having a plain ACK in the list I was thinking having the SYN-ACK in there to highlight the meaning, but we could just as well report ["SYN", "ACK"] and have consumers understand the meaning of ACK in this case.

In my experience this is distinct from how Netflow reports tcp flags. It uses a simple OR based aggregation over the flow. This makes it nearly impossible to determine which side initiated a flow or terminated it. (BTW there's a issue #12858 to do this same thing for netflow.)

Copy link
Member

Choose a reason for hiding this comment

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

From a query perspective I don't think it matters too much. You can query flags:SYN and not flags.ACK or flags:SYN and flags:ACK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see that AWS will never report a naked "ACK". 😃

Looks like AWS will also OR across the aggregation interval (19 for fin, syn & ack), added example of that.

I was also thinking the code could be useful for other data sets like liblogparser.js, which also makes me lean towards just turning the existing flags into names.

That being said, I can live with "syn-ack"

Copy link
Member

Choose a reason for hiding this comment

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

I'm good with separate keywords for each bit given that there is no loss of functionality from a query perspective.

@andrewkroh
Copy link
Member

andrewkroh commented Jan 13, 2021

@leehinman Is this one ready to merge? When we get an ECS field declared we can come back and update separately (if that's what you're waiting on).

run tests

@leehinman leehinman merged commit 8beb815 into elastic:master Jan 13, 2021
@leehinman leehinman deleted the 22820_vpcflow_tcp_flags branch January 13, 2021 22:13
@leehinman leehinman added v7.12.0 and removed needs_backport PR is waiting to be backported to other branches. labels Jan 13, 2021
leehinman added a commit to leehinman/beats that referenced this pull request Jan 14, 2021
* add tcp flags to aws/vpcflow fileset

- new field aws.vpcflow.tcp_flags_array

Closes elastic#22820

Co-authored-by: Andrew Kroh <[email protected]>
(cherry picked from commit 8beb815)
leehinman added a commit that referenced this pull request Jan 14, 2021
* add tcp flags to aws/vpcflow fileset

- new field aws.vpcflow.tcp_flags_array

Closes #22820

Co-authored-by: Andrew Kroh <[email protected]>
(cherry picked from commit 8beb815)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[filebeat][aws][vpcflow] Parse aws vpcflow tcp_flags
4 participants