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

Properly render hits and misses #624

Merged
merged 5 commits into from
Nov 15, 2024

Conversation

egibs
Copy link
Member

@egibs egibs commented Nov 14, 2024

Closes: #623

This PR allows for hits and misses surfaced by --err-first-hit or --err-first-miss to be displayed while also preventing additional concurrent processing/rendering of other paths.

This is achieved with a separate goroutine that reads from a channel that stores only the first match returned by errIfHitOrMiss and propagates the match and error properly.

Example output:

$ for i in (seq 1 5); go run cmd/mal/mal.go --err-first-miss analyze /Library/Application\ Support/BTServer/; end
🔎 Scanning "/Library/Application Support/BTServer/"
👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition
🔎 Scanning "/Library/Application Support/BTServer/"
👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition
🔎 Scanning "/Library/Application Support/BTServer/"
👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition
🔎 Scanning "/Library/Application Support/BTServer/"
👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition
🔎 Scanning "/Library/Application Support/BTServer/"
👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition

$ for i in (seq 1 5); go run cmd/mal/mal.go --err-first-hit analyze /usr/bin; end
🔎 Scanning "/usr/bin"
├─ 🔵 /usr/bin/SafeEjectGPU [LOW]
│     ≡ networking [LOW]
│       🔵 url/parse — Handles URL strings: NSURL
│
👋 1 matching capabilities in /usr/bin/SafeEjectGPU file: net/url/parse: matched requested condition
🔎 Scanning "/usr/bin"
├─ 🔵 /usr/bin/SafeEjectGPU [LOW]
│     ≡ networking [LOW]
│       🔵 url/parse — Handles URL strings: NSURL
│
👋 1 matching capabilities in /usr/bin/SafeEjectGPU file: net/url/parse: matched requested condition
🔎 Scanning "/usr/bin"
├─ 🔵 /usr/bin/AssetCacheManagerUtil [LOW]
│     ≡ filesystem [LOW]
│       🔵 file/write — writes to file: writeToFile:atomically:
│
👋 1 matching capabilities in /usr/bin/AssetCacheManagerUtil file: fs/file/write: matched requested condition
🔎 Scanning "/usr/bin"
├─ 🟡 /usr/bin/AssetCacheLocatorUtil [MEDIUM]
│     ≡ networking [MEDIUM]
│       🟡 ip/addr — mentions an 'IP address'
│
👋 1 matching capabilities in /usr/bin/AssetCacheLocatorUtil file: net/ip/addr: matched requested condition
🔎 Scanning "/usr/bin"
├─ 🔵 /usr/bin/SafeEjectGPU [LOW]
│     ≡ networking [LOW]
│       🔵 url/parse — Handles URL strings: NSURL
│
👋 1 matching capabilities in /usr/bin/SafeEjectGPU file: net/url/parse: matched requested condition

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs egibs requested a review from tstromberg November 14, 2024 18:00
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@tstromberg
Copy link
Collaborator

Can we simplify the exit messages? Instead of:

👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition
👋 1 matching capabilities in /usr/bin/SafeEjectGPU file: net/url/parse: matched requested condition

How about something closer to:

👋 /Library/Application Support/BTServer/pincode_defaults.db matched exit criteria
👋 /usr/bin/SafeEjectGPU matched exit criteria

In the second case, in particular, we can already see the list of capabilities just above this line. Eventually we should rename these flags to --exit-if instead of --err-if - that can be done here or in another PR.

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@egibs
Copy link
Member Author

egibs commented Nov 14, 2024

Can we simplify the exit messages? Instead of:

👋 no matching capabilities in "/Library/Application Support/BTServer/pincode_defaults.db" kind=file suffix=: matched requested condition
👋 1 matching capabilities in /usr/bin/SafeEjectGPU file: net/url/parse: matched requested condition

How about something closer to:

👋 /Library/Application Support/BTServer/pincode_defaults.db matched exit criteria
👋 /usr/bin/SafeEjectGPU matched exit criteria

In the second case, in particular, we can already see the list of capabilities just above this line. Eventually we should rename these flags to --exit-if instead of --err-if - that can be done here or in another PR.

Updated in c949cc4 (#624).

Renamed the errIfHitOrMiss function in 2f68252 (#624) as well.

@tstromberg tstromberg merged commit 56458e1 into chainguard-dev:main Nov 15, 2024
8 checks passed
@egibs egibs deleted the render-hits-misses branch November 18, 2024 16:37
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.

scan: --err-first-hit exits before showing matched output
2 participants