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

feat: add support to upload tshark to s3 #409

Merged
merged 22 commits into from
Jun 14, 2024
Merged

Conversation

smuu
Copy link
Member

@smuu smuu commented May 30, 2024

Overview

Closes #378

Summary by CodeRabbit

  • New Features

    • Introduced the ability to enable and manage Tshark collectors for instances in the test environment.
    • Enhanced support for Docker settings and Minio deployment in testing scenarios.
  • Bug Fixes

    • Resolved issues related to instance configuration and command execution during tests.
  • Refactor

    • Updated instance methods to handle Tshark collector configurations seamlessly.
  • Documentation

    • Added comprehensive documentation for new testing functionalities and instance management.

Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

The recent changes introduce the ability to trace network packets using Tshark in a test environment set up with the knuu package. This involves creating instances, enabling Tshark data collection, and handling the deployment of sidecars for packet capturing. Additionally, Minio configuration handling is integrated for storing the captured data.

Changes

File Change Summary
e2e/tshark/tshark_test.go Added TestTshark function to set up instances, enable Tshark collector, execute commands, and validate output.
pkg/instance/helper.go Added tsharkCollectorConfig field to Instance struct and new method addTsharkCollectorSidecar.
pkg/instance/instance.go Introduced TsharkCollectorConfig struct, added related fields and methods to Instance struct.
pkg/minio/minio.go Added Config struct to Minio and new method GetConfigs for retrieving Minio configurations.

Sequence Diagram(s)

sequenceDiagram
    participant Tester as Tester
    participant Knuu as Knuu Package
    participant Instance as Instance
    participant Minio as Minio
    
    Tester ->> Knuu: New()
    Knuu -->> Tester: knuu instance
    Tester ->> Knuu: NewInstance()
    Knuu -->> Tester: instance
    Tester ->> Instance: SetImage(), SetCommand()
    Tester ->> Instance: EnableTsharkCollector(params)
    Instance ->> Instance: addTsharkCollectorSidecar()
    Tester ->> Knuu: Commit()
    Tester ->> Instance: Start()
    Tester ->> Instance: WaitInstanceIsRunning()
    Tester ->> Instance: ExecuteCommand()
    Tester ->> Minio: DeployMinio()
    Minio -->> Tester: Minio configurations
    
    note over Instance: Starts collecting packets using Tshark
Loading

Assessment against linked issues

Objective Addressed Explanation
Ability to trace packets from at least two nodes (#378)
Upload packet trace file to an S3 bucket (#378)

Poem

In code we traverse the network's maze,
With Tshark and packets, we now appraise.
Knuu sets the stage, instances rise,
Minio holds data beneath azure skies.
A rabbit's toil, from dawn till night,
Ensuring the network dances right. 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 32b98ab and 8ee088b.

Files selected for processing (6)
  • e2e/tshark/tshark_test.go (1 hunks)
  • pkg/instance/errors.go (1 hunks)
  • pkg/instance/helper.go (2 hunks)
  • pkg/instance/instance.go (5 hunks)
  • pkg/instance/tshark.go (1 hunks)
  • pkg/knuu/knuu_old.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/knuu/knuu_old.go
Additional comments not posted (8)
pkg/instance/tshark.go (1)

7-49: The function createTsharkCollectorInstance is well-structured and follows best practices in error handling and resource configuration.

pkg/instance/helper.go (1)

597-606: The function addTsharkCollectorSidecar is correctly implemented and follows best practices in error handling and sidecar management.

pkg/instance/errors.go (1)

228-229: The new error definitions for the Tshark collector are clear and contextually appropriate, enhancing error handling in the system.

pkg/instance/instance.go (5)

72-88: New struct TsharkCollectorConfig added to manage Tshark collector configuration.

This struct is well-defined with clear fields for managing the Tshark collector's configuration, including S3 integration. Ensure that all necessary validations are performed when these configurations are set or modified.


129-129: Added tsharkCollectorConfig field to Instance struct.

This integration allows the instance to manage its Tshark collector configuration directly, aligning with the PR's objectives to enhance Tshark data collection capabilities.


156-163: Initialization of tsharkCollectorConfig in New function.

The default configuration sets the Tshark collector as disabled and clears all S3 related settings, which is a safe default state. Consider adding a comment here to explain why these defaults are chosen.


990-1006: New method EnableTsharkCollector to enable and configure the Tshark collector.

This method correctly sets up the Tshark collector configuration. Ensure that the input parameters are validated before setting them to prevent configuration errors.


1080-1084: Integration of Tshark collector deployment in StartWithoutWait.

The conditional deployment based on the enabled flag is correctly implemented. Ensure that the addTsharkCollectorSidecar method handles errors appropriately and cleans up resources if necessary.

e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mojtaba-esk mojtaba-esk left a comment

Choose a reason for hiding this comment

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

well done, looks good.

e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
pkg/instance/tshark.go Outdated Show resolved Hide resolved
pkg/instance/tshark.go Outdated Show resolved Hide resolved
pkg/instance/tshark.go Outdated Show resolved Hide resolved
pkg/knuu/knuu_old.go Outdated Show resolved Hide resolved
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8ee088b and 7636aa8.

Files selected for processing (1)
  • pkg/instance/tshark.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/instance/tshark.go

Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

only required change is removal of the 10 min sleep in the test.
everything else can be discussed more in followups.

smuu added 3 commits June 5, 2024 09:34
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
@smuu smuu requested review from mojtaba-esk and MSevey June 5, 2024 07:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (2)
pkg/instance/instance.go (2)

72-86: Add documentation for the TsharkCollectorConfig struct.

It would be beneficial to include comments describing the purpose and usage of each field in the TsharkCollectorConfig struct to improve code readability and maintainability.


Line range hint 725-725: Avoid logging sensitive information.

Sensitive data such as s3SecretKey should not be logged in clear text as it poses a security risk. Consider masking or removing sensitive data from logs.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7636aa8 and fa4c769.

Files selected for processing (5)
  • e2e/tshark/tshark_test.go (1 hunks)
  • pkg/instance/errors.go (1 hunks)
  • pkg/instance/helper.go (2 hunks)
  • pkg/instance/instance.go (5 hunks)
  • pkg/instance/tshark.go (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • e2e/tshark/tshark_test.go
  • pkg/instance/errors.go
  • pkg/instance/helper.go
  • pkg/instance/tshark.go
Additional context used
GitHub Check: CodeQL
pkg/instance/instance.go

[failure] 725-725: Clear-text logging of sensitive information
Sensitive data returned by an access to s3SecretKey flows to a logging call.

Additional comments not posted (1)
pkg/instance/instance.go (1)

1078-1082: Ensure error handling is robust when adding the Tshark collector sidecar.

Verification successful

The addTsharkCollectorSidecar method in pkg/instance/helper.go includes error handling for both the creation of the Tshark collector instance and the addition of the sidecar. The method returns specific wrapped errors if either of these operations fails, ensuring that any issues are properly reported.

  • The method checks for errors when creating the Tshark collector instance and wraps the error with ErrCreatingTsharkCollectorInstance.
  • It also checks for errors when adding the sidecar and wraps the error with ErrAddingTsharkCollectorSidecar.

This indicates that the error handling is robust and covers the necessary cases.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that error handling for adding the Tshark collector sidecar is robust and covers all necessary cases.

# Test: Search for the method `addTsharkCollectorSidecar`. Expect: Comprehensive error handling.
rg --type go $'addTsharkCollectorSidecar'

Length of output: 222



Script:

#!/bin/bash
# Extract the implementation of the addTsharkCollectorSidecar method from pkg/instance/helper.go
ast-grep --lang go --pattern $'func (i *Instance) addTsharkCollectorSidecar(ctx context.Context) error {
  $$$
}' pkg/instance/helper.go

Length of output: 780

pkg/instance/instance.go Outdated Show resolved Hide resolved
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
pkg/instance/instance.go (1)

Line range hint 725-725: Sensitive information (s3SecretKey) should not be logged in clear text as it poses a security risk. Consider masking or removing sensitive data from logs.

- logrus.Debugf("Enabled Tshark collector for instance '%s'", i.name)
+ logrus.Debugf("Enabled Tshark collector for instance '%s' with masked sensitive data", i.name)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fa4c769 and bf2c3e8.

Files selected for processing (3)
  • e2e/tshark/tshark_test.go (1 hunks)
  • pkg/instance/errors.go (1 hunks)
  • pkg/instance/instance.go (5 hunks)
Files skipped from review as they are similar to previous changes (2)
  • e2e/tshark/tshark_test.go
  • pkg/instance/errors.go
Additional context used
GitHub Check: CodeQL
pkg/instance/instance.go

[failure] 725-725: Clear-text logging of sensitive information
Sensitive data returned by an access to s3SecretKey flows to a logging call.

Additional comments not posted (1)
pkg/instance/instance.go (1)

72-86: The TsharkCollectorConfig struct is well-defined with appropriate fields for S3 configuration. Ensure that all fields are validated before use to prevent misconfigurations.

pkg/instance/instance.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mojtaba-esk mojtaba-esk left a comment

Choose a reason for hiding this comment

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

Well done !
left some suggestions.

e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
pkg/instance/tshark.go Outdated Show resolved Hide resolved
pkg/instance/tshark.go Outdated Show resolved Hide resolved
e2e/tshark/tshark_test.go Outdated Show resolved Hide resolved
pkg/instance/instance.go Outdated Show resolved Hide resolved
MSevey
MSevey previously approved these changes Jun 5, 2024
Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

lgtm, some follow ups though that don't need to block merging this in.

tty47
tty47 previously approved these changes Jun 12, 2024
@mojtaba-esk mojtaba-esk enabled auto-merge June 12, 2024 11:37
MSevey
MSevey previously approved these changes Jun 12, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 05d4691 and 656f877.

Files selected for processing (3)
  • pkg/instance/errors.go (1 hunks)
  • pkg/instance/instance.go (8 hunks)
  • pkg/instance/tshark.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pkg/instance/errors.go
  • pkg/instance/instance.go
  • pkg/instance/tshark.go

mojtaba-esk
mojtaba-esk previously approved these changes Jun 13, 2024
@mojtaba-esk mojtaba-esk dismissed stale reviews from tty47, MSevey, and themself via 8f592da June 13, 2024 14:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 656f877 and 8f592da.

Files selected for processing (1)
  • e2e/tshark/tshark_test.go (1 hunks)
Additional comments not posted (1)
e2e/tshark/tshark_test.go (1)

23-113: Comprehensive test setup for Tshark functionality.

This test function TestTshark effectively sets up an environment to test the Tshark packet tracing functionality, ensuring that all components are properly initialized and cleaned up. The use of require.NoError for immediate failure on errors and assert for conditions that must be met are well implemented. The dynamic wait mechanism suggestion from the previous review has been incorporated, enhancing the efficiency of the test.

e2e/tshark/tshark_test.go Show resolved Hide resolved
e2e/tshark/tshark_test.go Show resolved Hide resolved
MSevey
MSevey previously approved these changes Jun 13, 2024
tty47
tty47 previously approved these changes Jun 14, 2024
Copy link
Contributor

@tty47 tty47 left a comment

Choose a reason for hiding this comment

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

🚢

@smuu
Copy link
Member Author

smuu commented Jun 14, 2024

Thanks @mojtaba-esk for driving this home!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
pkg/minio/minio.go (1)

Line range hint 35-35: Identified a potential security risk with hardcoded credentials.

Consider using Kubernetes secrets or environment variables to manage credentials securely, avoiding hardcoded values in the source code.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f592da and c904db7.

Files selected for processing (3)
  • pkg/instance/helper.go (2 hunks)
  • pkg/instance/instance.go (8 hunks)
  • pkg/minio/minio.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • pkg/instance/helper.go
  • pkg/instance/instance.go
Additional context used
Gitleaks
pkg/minio/minio.go

35-35: Identified a HashiCorp Terraform password field, risking unauthorized infrastructure configuration and security breaches. (hashicorp-tf-password)

Additional comments not posted (2)
pkg/minio/minio.go (2)

53-53: Deployment logic for Minio appears robust and well-handled.


53-53: Presigned URL generation in GetMinioURL is implemented correctly.

pkg/minio/minio.go Show resolved Hide resolved
pkg/minio/minio.go Show resolved Hide resolved
@mojtaba-esk mojtaba-esk dismissed stale reviews from tty47 and MSevey via ace7012 June 14, 2024 12:06
@mojtaba-esk mojtaba-esk requested review from tty47 and MSevey June 14, 2024 12:08
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c904db7 and ace7012.

Files selected for processing (1)
  • e2e/tshark/tshark_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/tshark/tshark_test.go

@tty47 tty47 disabled auto-merge June 14, 2024 13:29
@tty47 tty47 merged commit 2478ead into main Jun 14, 2024
10 of 11 checks passed
@tty47 tty47 deleted the smuu/collect-tshark-upload-s3 branch June 14, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add ability to trace packets
4 participants