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(panic): Enhanced Support for Diverse Image ID Formats in Hash Extraction #114

Merged
merged 5 commits into from
May 30, 2023

Conversation

dwertent
Copy link

Pull Request Description

Title: Handling of Various Image ID Formats in Hash Extraction
Resolves: #111

Background:

The current implementation of hash extraction from Image IDs assumes a certain pattern and does not account for all variations of Image IDs, specifically formats like:

  • "docker://sha256:c1b135231b5b1a6799346cd701da4b59e5b7ef8e694ec7b04fb23b8dbe144137"
  • "sha256:c1b135231b5b1a6799346cd701da4b59e5b7ef8e694ec7b04fb23b8dbe144137"

There are instances where the Image ID doesn't have enough submatches (less than 3) leading to panic as the existing code tries to access an index that does not exist.

Changes:

This PR provides a robust mechanism to extract the SHA256 hash from Image IDs that can handle varying formats. The key changes include:

  1. Adding a check for plain SHA256 hashes: If the Image ID is a plain SHA256 hash, the function will now directly return it as the hash.

  2. Improved Error Handling: An error is now returned when there is an issue with the hash extraction, instead of the function panicking.

  3. Fallback Mechanism: In cases where the Image ID doesn't match the usual pattern, a fallback mechanism has been implemented to parse and extract the hash using a regular expression.

Impact:

This change will make the hash extraction from Image IDs more robust and prevent unexpected panics. It also improves error handling and provides more detailed error messages to help with troubleshooting.

Signed-off-by: David Wertenteil <dwertent@armosec.io>
@dwertent dwertent requested a review from matthyx May 28, 2023 09:57
@matthyx
Copy link
Contributor

matthyx commented May 28, 2023

Thanks for fixing it... It's weird that the official method doesn't account for these forms.
Anyway this should move to the common methods in order to use it for kubevuln, operator and backend.

@github-actions
Copy link

Summary:

  • License scan: failure
  • Credentials scan: success
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: success

@dwertent
Copy link
Author

@matthyx Where is the common method?

@matthyx
Copy link
Contributor

matthyx commented May 28, 2023

Doesn't exist yet... It would make sense to have one

@dwertent
Copy link
Author

@matthyx Should we merge this or should we write such a function? Do we know if the Operator needs such a capability?

@matthyx
Copy link
Contributor

matthyx commented May 30, 2023

let's merge it now, worst case we can extract it later...
thanks for the fix

@github-actions
Copy link

Summary:

  • License scan: failure
  • Credentials scan: success
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: success

David Wertenteil added 3 commits May 30, 2023 11:48
Signed-off-by: David Wertenteil <dwertent@armosec.io>
…fix-issue-111

Signed-off-by: David Wertenteil <dwertent@armosec.io>
Signed-off-by: David Wertenteil <dwertent@armosec.io>
@github-actions
Copy link

Summary:

  • License scan: failure
  • Credentials scan: success
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: success

@dwertent dwertent merged commit 00cc005 into main May 30, 2023
@matthyx matthyx deleted the fix-issue-111 branch May 30, 2023 14:30
dwertent pushed a commit that referenced this pull request Dec 31, 2023
fix(panic): Enhanced Support for Diverse Image ID Formats in Hash Extraction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error running kubevuln
2 participants