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

[Amazon Security Lake] - OCSF v1.1 update with major refactor & adding support for dynamic template and mappings & system tests #10405

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

ShourieG
Copy link
Contributor

@ShourieG ShourieG commented Jul 8, 2024

Type of change

  • Enhancement

Proposed commit message

With the upgrade of OCSF schemas, we are enhancing our support to meet compatibility requirements for OCSF v1.1. We are also reworking the ingest pipeline to incorporate dynamic templates and mappings to enable faster OCSF upgrades in future.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Author's Checklist

  • Added support for User Inventory Info class events.
  • Added Terraform based system tests (requires elastic package change to work)
  • Rework ingestion pipelines to incorporate dynamic templates and dynamic mappings.
  • Add support for more event classes introduced in OCSF v1.1.
  • Add new profiles and objects as required based on OCSF v1.1 updates.
    - [ ] Update dashboards wherever required. (dashboards are at the category level and atm after inspection no changes are required since they operate on shared values).
  • Updated documentation
  • Removed system test configs

NOTE

  • Due to the nature and structure of the OCSF schema, this integration has limitations on how deep the mappings run. Some important objects like 'Actor', 'User' and 'Product' have more fleshed-out mappings compared to others which get flattened after the initial 2-3 levels of nesting to keep them maintainable in a YAML format. This will evolve on a need-by-need basis going forward.

  • The CI tests will pass once the respective elastic-package changes are implemented as defined here.

Approach

  • Segregated objects like user,actor,process,device,file,network and some more into their separate files across all data streams.
  • Implemented dynamic templates on few objects which aligned to current pipeline capabilities.
  • Implemented terraform based multi bucket system tests.
  • Added all new ocsf v1.1 classes and objects across data streams.
  • Fixed existing errors and issues in mappings and timestamp parsing across all data streams.
  • Cleaned up existing codebase and made it more maintainable.

How to review this PR

Due to the scale of the changes, intermittent merges with main to resolve conflicts and reworks all across the board, re-writing the git history and consolidating the commits with git rebase is proving to be really challenging, hence I suggest the following approach to review this PR:-

  1. Complete review of the terraform based deployer, which will later be used in system tests after elastic-package changes are available.
  2. Prioritize Commits with the "dynamic" keyword which is specific to some dynamic template implementations.
  3. Prioritize Commits withe the keywords "updated", "converted", "segregated", "fixed".
  4. Prioritise reviewing the pipeline changes as they contain core logic.
  5. The commits with "added" keywords signify addition of new mappings for ocsf v1.1. These are quite large and often times redundant to review completely due to the nature of OCSF. Having said that if you personally feel any of the mappings are worth reviewing please go ahead.
  6. Ignore commits with keywords "resolved", "merged", "test", "initial", "trying" .

Some commits have certain elements that could stand out and might have been reworked/removed later down stream. In those scenarios, feel free to review in the complete context or reach out to me in case of any confusion.

How to test this PR locally

Related issues

System Tests

--- Test results for package: amazon_security_lake - START ---
╭──────────────────────┬─────────────┬───────────┬──────────────────────┬────────┬─────────────────╮
│ PACKAGE              │ DATA STREAM │ TEST TYPE │ TEST NAME            │ RESULT │    TIME ELAPSED │
├──────────────────────┼─────────────┼───────────┼──────────────────────┼────────┼─────────────────┤
│ amazon_security_lake │ event       │ system    │ application-activity │ PASS   │ 3m12.321247667s │
│ amazon_security_lake │ event       │ system    │ discovery            │ PASS   │ 3m10.478033084s │
│ amazon_security_lake │ event       │ system    │ findings             │ PASS   │ 3m13.906812333s │
│ amazon_security_lake │ event       │ system    │ iam                  │ PASS   │ 3m13.214461166s │
│ amazon_security_lake │ event       │ system    │ network-activity     │ PASS   │ 3m10.608428458s │
│ amazon_security_lake │ event       │ system    │ system-activity      │ PASS   │ 3m12.344728625s │
╰──────────────────────┴─────────────┴───────────┴──────────────────────┴────────┴─────────────────╯

Screenshots

@ShourieG ShourieG self-assigned this Jul 8, 2024
@andrewkroh andrewkroh added Integration:amazon_security_lake Amazon Security Lake Team:Security-Service Integrations Security Service Integrations Team [elastic/security-service-integrations] labels Jul 19, 2024
…oxy_endpoint field, uupdated network activity class and segregated endpoint event mappings into separate files across all data streams. updated ocsf object as necessary across respective data streams
… data streams, added new fields to support newly added event class
…ta fields across all data streams, flattened ldap fields in event data stream to make room for more fields
…ed resources object group, added new objects as required
…ema version in comment and dashboard links to 1.1.0
@ShourieG ShourieG changed the title [Amazon Security Lake] - OCSF v1.1 update with adding support for dynamic template and mappings [Amazon Security Lake] - OCSF v1.1 update with refactor & adding support for dynamic template and mappings Aug 9, 2024
@ShourieG ShourieG changed the title [Amazon Security Lake] - OCSF v1.1 update with refactor & adding support for dynamic template and mappings [Amazon Security Lake] - OCSF v1.1 update with major refactor & adding support for dynamic template and mappings Aug 9, 2024
@ShourieG ShourieG changed the title [Amazon Security Lake] - OCSF v1.1 update with major refactor & adding support for dynamic template and mappings [Amazon Security Lake] - OCSF v1.1 update with major refactor & adding support for dynamic template and mappings & system tests Aug 9, 2024
@ShourieG ShourieG marked this pull request as ready for review August 9, 2024 16:30
@ShourieG ShourieG requested a review from a team as a code owner August 9, 2024 16:30
@elasticmachine
Copy link

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@elasticmachine
Copy link

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@andrewkroh andrewkroh added the enhancement New feature or request label Aug 19, 2024
@elasticmachine
Copy link

💚 Build Succeeded

History

cc @ShourieG

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
1.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

@chrisberkhout chrisberkhout self-requested a review August 28, 2024 08:22
@andrewkroh andrewkroh added the dashboard Relates to a Kibana dashboard bug, enhancement, or modification. label Aug 30, 2024
Copy link
Contributor

@chrisberkhout chrisberkhout left a comment

Choose a reason for hiding this comment

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

Couple of general comments.

I looked at the README and dashboard diffs.

@@ -19,6 +19,8 @@ The Amazon Security Lake integration collects logs from both [Third-party servic
### **NOTE**:
- The Amazon Security Lake integration supports events collected from [AWS services](https://docs.aws.amazon.com/security-lake/latest/userguide/internal-sources.html) and [third-party services](https://docs.aws.amazon.com/security-lake/latest/userguide/custom-sources.html).

- Due to the nature and structure of the OCSF schema, this integration has limitations on how deep the mappings run. Some important objects like 'Actor', 'User' and 'Product' have more fleshed-out mappings compared to others which get flattened after the initial 2-3 levels of nesting to keep them maintainable in a YAML format. This will evolve on a need-by-need basis going forward.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Due to the nature and structure of the OCSF schema, this integration has limitations on how deep the mappings run. Some important objects like 'Actor', 'User' and 'Product' have more fleshed-out mappings compared to others which get flattened after the initial 2-3 levels of nesting to keep them maintainable in a YAML format. This will evolve on a need-by-need basis going forward.
- Due to the nature and structure of the OCSF schema, this integration has limitations on how deep the mappings run. Some important objects like 'Actor', 'User' and 'Product' have more fleshed-out mappings compared to others which get flattened after the initial 2-3 levels of nesting to keep them maintainable and stay within field mapping [limits](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-settings-limit.html). This will evolve as needed going forward.

Copy link
Contributor

Choose a reason for hiding this comment

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

... or even, s/This will evolve as needed going forward./This will evolve as needed./

@@ -1,4 +1,9 @@
# newer versions go on top
- version: "2.0.0"
changes:
- description: Updated to support OCSF v1.1.0. with major pipeline rework and dynamic template support.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- description: Updated to support OCSF v1.1.0. with major pipeline rework and dynamic template support.
- description: Updated to support OCSF v1.1.0. with major pipeline rework and dynamic mapping support.

I think you're using dynamic field mapping, but not yet dynamic templates.
Would be good to correct this terminology in the proposed commit message as well.

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

There is a lot of colour and movement in this change which makes it difficult to be confident of the review. I have looked at:

There are a variety of comments and suggestions. I'll take another look again tomorrow.

output "bucket_arn" {
value = aws_s3_bucket.security_lake_logs.arn
description = "The ARN of the S3 bucket"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Final new line.

@@ -19,6 +19,8 @@ The Amazon Security Lake integration collects logs from both [Third-party servic
### **NOTE**:
- The Amazon Security Lake integration supports events collected from [AWS services](https://docs.aws.amazon.com/security-lake/latest/userguide/internal-sources.html) and [third-party services](https://docs.aws.amazon.com/security-lake/latest/userguide/custom-sources.html).

- Due to the nature and structure of the OCSF schema, this integration has limitations on how deep the mappings run. Some important objects like 'Actor', 'User' and 'Product' have more fleshed-out mappings compared to others which get flattened after the initial 2-3 levels of nesting to keep them maintainable in a YAML format. This will evolve on a need-by-need basis going forward.
Copy link
Contributor

Choose a reason for hiding this comment

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

... or even, s/This will evolve as needed going forward./This will evolve as needed./

@@ -14,7 +14,7 @@
type: keyword
description: The account type, normalized to the caption of 'account_type_id'. In the case of 'Other', it is defined by the event source.
- name: type_id
type: keyword
type: integer
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this being changed to an integer? In general, IDs are not semantically orderable, so a keyword is usually what is wanted, even if the underlying type is a number. If OCSF specifies that it is orderable, ignore this. Also below.

Copy link
Contributor Author

@ShourieG ShourieG Sep 26, 2024

Choose a reason for hiding this comment

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

OCSF schema defines type_id as an integer, if we define it as keyword we need to convert manually from int to string on our end for all its occurrences or use a recursive script to do so, which will be expensive. The OCSF JSON payload also has it as a number, so explicit conversion is required on our end for every instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Keywords can be numeric.

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 remember having it as a keyword in the beginning and then encountered type errors while running tests. I'll revisit once again and check.

Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to annotate the fields in numeric_keyword_fields in the test configs.

description: The type of FTP network connection (e.g. active, passive).
description: The type the event.
- name: type_id
type: integer
Copy link
Contributor

Choose a reason for hiding this comment

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

keyword

type: keyword
description: The type of the user. For example, System, AWS IAM User, etc.
- name: type_id
type: integer
Copy link
Contributor

Choose a reason for hiding this comment

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

keyword (throughout)

type: keyword
description: The type of scan.
- name: type_id
type: integer
Copy link
Contributor

Choose a reason for hiding this comment

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

keyword

type: integer
description: The number of items that were skipped.
- name: num_trusted_items
- name: num_*
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work? til

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup this works

@@ -583,6 +583,9 @@
- name: raw_data
type: flattened
description: The event data as received from the event source.
- name: raw_data_keyword
type: keyword
Copy link
Contributor

Choose a reason for hiding this comment

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

match_only_text? (throughout)

Comment on lines +33 to +41
int digits = ("" + timestamp).length();
if (digits > 16 && digits <= 19) {
return timestamp / 1000000; // Convert nanoseconds to milliseconds
} else if (digits > 13 && digits <= 16) {
return timestamp / 1000; // Convert microseconds to milliseconds
} else if (digits > 10 && digits <= 13) {
return timestamp; // Already in milliseconds, no conversion needed
} else if (digits <= 10) {
return timestamp * 1000; // Convert seconds to milliseconds
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more expensive than necessary.

        def convertToMilliseconds(long timestamp) {
              if ((long)1e19 - 1 < timestamp) {
                  throw new IllegalArgumentException("Timestamp format not recognized: " + timestamp);
              } else if ((long)1e16 - 1 < timestamp) {
                  return timestamp / 1000000;  // Convert nanoseconds to milliseconds
              } else if ((long)1e13 - 1 < timestamp) {
                  return timestamp / 1000;  // Convert microseconds to milliseconds
              } else if ((long)1e10 - 1 < timestamp) {
                  return timestamp;  // Already in milliseconds, no conversion needed
              } else {
                  return timestamp * 1000;  // Convert seconds to milliseconds
              }
        }

or alternatively (and cleaner IMO)

        def convertToMilliseconds(long timestamp) {
              if (timestamp < (long)1e10) {
                  return timestamp * (long)1e3;  // Convert seconds to milliseconds
              }
              long t = timestamp;
              // Find first milli-, micro- or nano second-sane value in multiple-steps
              // of 1000.
              for (int i = 0; i < 3; i++) {
                  if ((long)1e13 - 1  < t) {
                      return t;
                  }
                  t /= (long)1e3
              }
              throw new IllegalArgumentException("Timestamp format not recognized: " + timestamp);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.16 candidate dashboard Relates to a Kibana dashboard bug, enhancement, or modification. enhancement New feature or request Integration:amazon_security_lake Amazon Security Lake Team:Security-Service Integrations Security Service Integrations Team [elastic/security-service-integrations]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Amazon Security Lake] Add support for new objects and event classes, profiles and update schemas accordingly
5 participants