kubescape / node-agent

Kubescape eBPF agent 🥷🏻
https://kubescape.io/
Apache License 2.0
8 stars 5 forks source link

Use fullPath #259

Closed dwertent closed 7 months ago

dwertent commented 7 months ago

User description

Overview


Type

enhancement


Description


Changes walkthrough

Relevant files
Enhancement
open.go
Use FullPath in open event condition check                             

pkg/containerwatcher/v1/open.go
  • Changed condition to check event.FullPath instead of event.Path when
    adding events to openWorkerChan.
  • +1/-1     
    r0002_unexpected_file_access.go
    Update Unexpected File Access Rule to Use FullPath             

    pkg/ruleengine/v1/r0002_unexpected_file_access.go
  • Updated various functions to use event.FullPath instead of event.Path.
  • Adjusted string formatting in error messages and patch commands to use
    FullPath.
  • +6/-6     
    r0006_unexpected_service_account_token_access.go
    Update Service Account Token Access Rule to Use FullPath 

    pkg/ruleengine/v1/r0006_unexpected_service_account_token_access.go
  • Updated rule processing to use event.FullPath instead of event.Path.
  • Modified patch command generation and rule descriptions to use
    FullPath.
  • +4/-4     
    r1003_malicious_ssh_connection.go
    Use FullPath for SSH Config File Check in Malicious SSH Connection
    Rule

    pkg/ruleengine/v1/r1003_malicious_ssh_connection.go
  • Changed SSH config file check to use event.FullPath instead of
    event.Path.
  • +1/-1     
    Tests
    r0002_unexpected_file_access_test.go
    Update Tests for Unexpected File Access to Use FullPath   

    pkg/ruleengine/v1/r0002_unexpected_file_access_test.go
  • Modified test cases to use event.FullPath instead of event.Path.
  • +2/-2     
    r0006_unexpected_service_account_token_access_test.go
    Update Tests for Service Account Token Access to Use FullPath

    pkg/ruleengine/v1/r0006_unexpected_service_account_token_access_test.go
  • Adjusted test cases to use event.FullPath instead of event.Path.
  • +1/-1     

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-free[bot] commented 7 months ago

    PR Description updated to latest commit (https://github.com/kubescape/node-agent/commit/378371dba437b14a88a780a17c7afdb0ad298b4a)

    codiumai-pr-agent-free[bot] commented 7 months ago

    PR Review

    ⏱️ Estimated effort to review [1-5] 2, because the changes are straightforward and consistent across multiple files, focusing on replacing 'Path' with 'FullPath'. The logic remains the same, and the modifications are repetitive.
    🧪 Relevant tests Yes
    🔍 Possible issues No
    🔒 Security concerns No

    ✨ Review tool usage guide:
    **Overview:** The `review` tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be [added](https://pr-agent-docs.codium.ai/tools/review/#general-configurations) by configuring the tool. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on any PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L23) related to the review tool (`pr_reviewer` section), use the following template: ``` /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_reviewer] some_config1=... some_config2=... ``` See the review [usage page](https://pr-agent-docs.codium.ai/tools/review/) for a comprehensive guide on using this tool.
    codiumai-pr-agent-free[bot] commented 7 months ago

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Bug
    Add a nil check for the event variable to prevent nil pointer dereferences. ___ **Consider adding a nil check for event before accessing its properties to prevent potential
    nil pointer dereferences.** [pkg/containerwatcher/v1/open.go [18-20]](https://github.com/kubescape/node-agent/pull/259/files#diff-62176d3b35342542f601e9e5c91593ff16fcbd9f948bf566af9a4d25b46cfd86R18-R20) ```diff -if event.Ret > -1 && event.FullPath != "" { +if event != nil && event.Ret > -1 && event.FullPath != "" { ch.openWorkerChan <- event } ```
    Format flagList as a JSON array to ensure the command syntax is correct. ___ **Ensure that flagList is properly formatted as a JSON array in the generatePatchCommand
    function to avoid syntax errors in the generated command.** [pkg/ruleengine/v1/r0002_unexpected_file_access.go [105]](https://github.com/kubescape/node-agent/pull/259/files#diff-90d1aefc909570233d7720d28979df55666d6e53899a1804cb20fea684236645R105-R105) ```diff -return fmt.Sprintf(baseTemplate, ap.GetName(), ap.GetNamespace(), event.GetContainer(), event.FullPath, flagList) +return fmt.Sprintf(baseTemplate, ap.GetName(), ap.GetNamespace(), event.GetContainer(), event.FullPath, json.Marshal(flagList)) ```
    Performance
    Optimize prefix checking by using a more efficient method. ___ **Use a more efficient method for checking if openEvent.FullPath starts with any prefix in
    ignorePrefixes to improve performance.** [pkg/ruleengine/v1/r0002_unexpected_file_access.go [119-123]](https://github.com/kubescape/node-agent/pull/259/files#diff-90d1aefc909570233d7720d28979df55666d6e53899a1804cb20fea684236645R119-R123) ```diff -for _, prefix := range rule.ignorePrefixes { - if strings.HasPrefix(openEvent.FullPath, prefix) { - return nil - } +if hasAnyPrefix(openEvent.FullPath, rule.ignorePrefixes) { + return nil } ```
    Security
    Validate the path before processing to enhance security and reliability. ___ **Validate openEvent.FullPath to ensure it is a valid path before processing it to avoid
    potential security risks or errors.** [pkg/ruleengine/v1/r0006_unexpected_service_account_token_access.go [89-92]](https://github.com/kubescape/node-agent/pull/259/files#diff-397dd96e7b0070e47905927ec1d599ef0cae06f2dcaaa1af58743ebd710f9fa5R89-R92) ```diff -if strings.HasPrefix(openEvent.FullPath, prefix) { +if isValidPath(openEvent.FullPath) && strings.HasPrefix(openEvent.FullPath, prefix) { shouldCheckEvent = true break } ```
    Best practice
    Implement error handling for the SSH configuration file check. ___ **Add error handling for the IsSSHConfigFile function to manage unexpected outcomes or
    failures gracefully.** [pkg/ruleengine/v1/r1003_malicious_ssh_connection.go [125-128]](https://github.com/kubescape/node-agent/pull/259/files#diff-4caaeaf9d44ed40d0917224bc264b00ef40c6516b5672eed2020e68de8c5c7feR125-R128) ```diff -if IsSSHConfigFile(openEvent.FullPath) { +isConfig, err := IsSSHConfigFile(openEvent.FullPath) +if err != nil { + return nil // or handle error appropriately +} +if isConfig { rule.accessRelatedFiles = true rule.sshInitiatorPid = openEvent.Pid rule.configFileAccessTimeStamp = int64(openEvent.Timestamp) ```

    ✨ Improve tool usage guide:
    **Overview:** The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered [automatically](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR. - When commenting, to edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L78) related to the improve tool (`pr_code_suggestions` section), use the following template: ``` /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=... ``` - With a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/), use the following template: ``` [pr_code_suggestions] some_config1=... some_config2=... ``` See the improve [usage page](https://pr-agent-docs.codium.ai/tools/improve/) for a comprehensive guide on using this tool.
    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    Summary:

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    Summary:

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    Summary:

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    Summary:

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.

    github-actions[bot] commented 7 months ago

    :sparkles: Artifacts are available here.