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

fix tests for node local sbom generation #494

Merged
merged 2 commits into from
Dec 2, 2024
Merged

fix tests for node local sbom generation #494

merged 2 commits into from
Dec 2, 2024

Conversation

matthyx
Copy link
Contributor

@matthyx matthyx commented Nov 29, 2024

PR Type

enhancement, configuration changes


Description

  • Refactored SBOM and CVE retrieval to use workload tags, improving the logic for retrieving data using image tags.
  • Updated multiple vulnerability manifests and SBOM data with new metadata, annotations, and image details.
  • Changed image references in various deployment configurations to include the full Docker registry path for consistency.

Changes walkthrough 📝

Relevant files
Enhancement
4 files
relevant_cve.py
Refactor SBOM and CVE retrieval to use workload tags         

tests_scripts/helm/relevant_cve.py

  • Replaced get_imagesIDs_keys with get_workloads_images_tags for SBOM
    and CVE retrieval.
  • Updated method calls to use workload_tags instead of SBOMKeys and
    CVEsKeys.
  • +21/-21 
    base_k8s.py
    Refactor image handling and storage retrieval logic           

    tests_scripts/kubernetes/base_k8s.py

  • Changed get_image_ids to use image instead of image_id.
  • Refactored get_SBOM_from_storage and get_CVEs_from_storage to use
    workload_tags.
  • Improved logic for retrieving SBOM and CVE data using image tags.
  • +38/-30 
    python-client-to-java.json
    Update vulnerability manifest for Python client                   

    configurations/expected-result/filteredCVEs/python-client-to-java.json

  • Updated the metadata and spec fields with new values.
  • Changed the uid, name, and creationTimestamp.
  • Updated annotations and source fields.
  • +1/-1     
    golang-dynamic-simple.json
    Update SBOM for Golang dynamic deployment                               

    configurations/expected-result/filteredSBOM/golang-dynamic-simple.json

  • Replaced the entire JSON content with updated SBOM data.
  • Updated metadata and spec fields with new values.
  • Changed uid, name, and creationTimestamp.
  • Updated tool version and source metadata.
  • +1/-165 
    Configuration changes
    9 files
    python-simple.json
    Update Python vulnerability manifest metadata                       

    configurations/expected-result/CVEs/python-simple.json

  • Updated metadata and annotations for a Python vulnerability manifest.
  • Changed image ID and resource size in the annotations.
  • +1/-1     
    golang-simple.json
    Update Golang vulnerability manifest with new metadata     

    configurations/expected-result/CVEs/golang-simple.json

  • Replaced the entire JSON content with updated vulnerability manifest
    for Golang.
  • Updated metadata, annotations, and image details.
  • +1/-84   
    redis-fixed.yaml
    Update Redis deployment image reference                                   

    configurations/k8s_workloads/deployments/redis/redis-fixed.yaml

  • Updated image reference to include docker.io prefix.
  • Ensured consistent image naming convention.
  • +2/-2     
    sbomspdxv2p3s.yaml
    Update metadata name for Golang SBOM                                         

    configurations/kubescape-crds/unsupported/sbomspdxv2p3s.yaml

    • Updated the metadata name for a Golang SBOM.
    +1/-1     
    python.yaml
    Update Python deployment image reference                                 

    configurations/k8s_workloads/deployments/java-and-python/python.yaml

    • Updated image reference to include docker.io prefix.
    +1/-1     
    python-simple.yaml
    Update Python deployment image reference                                 

    configurations/k8s_workloads/deployments/python-simple/python-simple.yaml

  • Updated the image reference to include the full Docker registry path.
  • +1/-1     
    java.yaml
    Update Java deployment image reference                                     

    configurations/k8s_workloads/deployments/java-and-python/java.yaml

  • Updated the image reference to include the full Docker registry path.
  • +1/-1     
    java-simple.yaml
    Update Java simple deployment image reference                       

    configurations/k8s_workloads/deployments/java-simple/java-simple.yaml

  • Updated the image reference to include the full Docker registry path.
  • +1/-1     
    redis-fixed.json
    Update vulnerability manifest for Redis with new metadata and tool
    version.

    configurations/expected-result/filteredCVEs/redis-fixed.json

  • Replaced the entire JSON content with a new vulnerability manifest.
  • Updated metadata including name, uid, and creationTimestamp.
  • Updated tool version in the spec section.
  • Adjusted image details and layers in the source section.
  • +1/-538 
    Additional files (token-limit)
    29 files
    wikijs.json
    ...                                                                                                           

    configurations/expected-result/CVEs/wikijs.json

    ...

    +1/-2     
    java-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/java-simple.json

    ...

    +1/-2     
    python-simple.json
    ...                                                                                                           

    configurations/expected-result/SBOM/python-simple.json

    ...

    +1/-2     
    redis.json
    ...                                                                                                           

    configurations/expected-result/SBOM/redis.json

    ...

    +1/-26481
    nginx.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/nginx.json

    ...

    +1/-2     
    wikijs.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/wikijs.json

    ...

    +1/-2     
    nginx.json
    ...                                                                                                           

    configurations/expected-result/CVEs/nginx.json

    ...

    +1/-2     
    redis_incomplete.json
    ...                                                                                                           

    configurations/expected-result/SBOM/redis_incomplete.json

    ...

    +1/-53   
    redis_sleep.json
    ...                                                                                                           

    configurations/expected-result/SBOM/redis_sleep.json

    ...

    +2/-1     
    java-simple.json
    ...                                                                                                           

    configurations/expected-result/CVEs/java-simple.json

    ...

    +1/-2     
    python-client-to-java.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/python-client-to-java.json

    ...

    +1/-2     
    java-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/java-simple.json

    ...

    +1/-2     
    golang-dynamic-simple.json
    ...                                                                                                           

    configurations/expected-result/CVEs/golang-dynamic-simple.json

    ...

    +2/-5262
    redis.json
    ...                                                                                                           

    configurations/expected-result/CVEs/redis.json

    ...

    +1/-1577
    redis_sleep.json
    ...                                                                                                           

    configurations/expected-result/CVEs/redis_sleep.json

    ...

    +1/-1577
    redis.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/redis.json

    ...

    +1/-1581
    redis_sleep_updated.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/redis_sleep_updated.json

    ...

    +1/-1581
    redis_sleep_updated.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/redis_sleep_updated.json

    ...

    +1/-1279
    redis-fixed.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/redis-fixed.json

    ...

    +1/-1191
    redis_sleep.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/redis_sleep.json

    ...

    +1/-1192
    redis.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/redis.json

    ...

    +1/-1181
    redis_sleep.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/redis_sleep.json

    ...

    +1/-1162
    python-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/python-simple.json

    ...

    +1/-274 
    python-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/python-simple.json

    ...

    +1/-185 
    redis_incomplete.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/redis_incomplete.json

    ...

    +1/-56   
    golang-dynamic-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/golang-dynamic-simple.json

    ...

    +1/-97   
    golang-simple.json
    ...                                                                                                           

    configurations/expected-result/SBOM/golang-simple.json

    ...

    +1/-145 
    golang-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredSBOM/golang-simple.json

    ...

    +1/-148 
    golang-simple.json
    ...                                                                                                           

    configurations/expected-result/filteredCVEs/golang-simple.json

    ...

    +1/-87   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Code Refactoring
    The get_SBOM_from_storage and get_CVEs_from_storage methods were significantly refactored to use workload tags instead of image IDs. Verify that the new logic correctly retrieves and matches SBOM/CVE data using image tags.

    Error Handling
    New error handling was added to raise exceptions when SBOM/CVE data is not found for an image tag. Validate that these exceptions are handled appropriately by the calling code.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Validate existence of required data before attempting retrieval to provide clearer error messages

    Add error handling for cases where no matching SBOM/CVE is found for an image tag in
    the storage. Currently the code raises an exception only after attempting to get the
    data, which could lead to confusing errors.

    tests_scripts/kubernetes/base_k8s.py [1128-1135]

     for container_tags in workload_tags:
         for container, image_tag in container_tags:
             name = ""
             for sbom in namespacedSBOMs['items']:
                 if sbom['metadata']['annotations']['kubescape.io/image-tag'] == image_tag:
                     name = sbom['metadata']['name']
                     break
    +        if not name:
    +            raise Exception(f"No SBOM found in storage for image tag {image_tag}")
             SBOM_data = self.kubernetes_obj.client_CustomObjectsApi.get_namespaced_custom_object(...)
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves error handling by checking for missing SBOM data earlier in the process, providing clearer error messages and preventing potential confusing errors when trying to retrieve non-existent data.

    7

    💡 Need additional feedback ? start a PR chat

    Copy link

    Failed to generate code suggestions for PR

    @matthyx matthyx force-pushed the sbom branch 9 times, most recently from c4cd0f8 to 4e83cfb Compare November 29, 2024 15:24
    @matthyx matthyx force-pushed the sbom branch 8 times, most recently from 8f4afb5 to e954290 Compare December 2, 2024 07:25
    @matthyx matthyx merged commit d356e60 into master Dec 2, 2024
    3 checks passed
    @matthyx matthyx deleted the sbom branch December 2, 2024 14:04
    matthyx added a commit that referenced this pull request Dec 2, 2024
    This reverts commit d356e60, reversing
    changes made to 50ffcce.
    matthyx added a commit that referenced this pull request Dec 2, 2024
    Revert "Merge pull request #494 from armosec/sbom"
    @matthyx matthyx restored the sbom branch December 3, 2024 06:10
    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.

    2 participants