-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
WalkthroughThe recent changes introduce the ability to trace network packets using Tshark in a test environment set up with the Changes
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
Assessment against linked issues
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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 functioncreateTsharkCollectorInstance
is well-structured and follows best practices in error handling and resource configuration.pkg/instance/helper.go (1)
597-606
: The functionaddTsharkCollectorSidecar
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 structTsharkCollectorConfig
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
: AddedtsharkCollectorConfig
field toInstance
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 oftsharkCollectorConfig
inNew
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 methodEnableTsharkCollector
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 inStartWithoutWait
.The conditional deployment based on the
enabled
flag is correctly implemented. Ensure that theaddTsharkCollectorSidecar
method handles errors appropriately and cleans up resources if necessary.
There was a problem hiding this 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.
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
There was a problem hiding this 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
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
There was a problem hiding this 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.
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
There was a problem hiding this 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 theTsharkCollectorConfig
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
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 inpkg/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.goLength of output: 780
Signed-off-by: Smuu <18609909+Smuu@users.noreply.github.com>
There was a problem hiding this 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
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
: TheTsharkCollectorConfig
struct is well-defined with appropriate fields for S3 configuration. Ensure that all fields are validated before use to prevent misconfigurations.
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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
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
8f592da
There was a problem hiding this 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
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 ofrequire.NoError
for immediate failure on errors andassert
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
Thanks @mojtaba-esk for driving this home! |
There was a problem hiding this 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
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 inGetMinioURL
is implemented correctly.
There was a problem hiding this 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
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
Overview
Closes #378
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Documentation