Skip to content

Fix scorecard descriptor test panic on non-object CR spec/status - #7114

Merged
acornett21 merged 1 commit into
operator-framework:masterfrom
arpitjain099:fix/scorecard-olm-descriptor-panic
Jul 16, 2026
Merged

Fix scorecard descriptor test panic on non-object CR spec/status#7114
acornett21 merged 1 commit into
operator-framework:masterfrom
arpitjain099:fix/scorecard-olm-descriptor-panic

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

Description of the change:

I work on supply-chain security and was looking at how the scorecard OLM tests handle bundle content. The olm-spec-descriptors, olm-status-descriptors, and olm-crds-have-validation tests load a CR's spec and status from a bundle's alm-examples and type-assert them to map[string]any, but they only guard against nil. If a CR has a spec or status that isn't a JSON object (say "spec": "foo", or an array), the unguarded assertion panics:

interface conversion: interface {} is string, not map[string]interface {}

That crashes the scorecard test binary when it scans a malformed or untrusted bundle. This swaps the four assertions in internal/scorecard/tests/olm.go for comma-ok checks so a non-object spec/status is handled the same as a missing one: the spec-descriptors check reports it as a failed descriptor, and the status/validation checks just skip the field. No behavior change for well-formed bundles.

The four sites: checkOwnedCSVStatusDescriptor (status len check), checkOwnedCSVSpecDescriptors (spec block), and both spec and status in isCRFromCRDApi.

Added regression tests in bundle_test.go that drive the real check functions with a scalar spec and an array status and assert they don't panic. Before this change those three specs fail with the panic above; after, all 24 specs pass.

Motivation for the change:

Crash-hardening: operator-sdk scorecard runs these tests against a bundle you may not control, so a scalar/array where an object is expected shouldn't take down the test binary.

Checklist

If the pull request includes user-facing changes, extra documentation is required:

  • Add a new changelog fragment in changelog/fragments
  • Add or update relevant sections of the docs website in website/content/en/docs

The scorecard olm-spec-descriptors, olm-status-descriptors and
olm-crds-have-validation tests read a CR's spec and status from a
bundle's alm-examples annotation and type-assert them to
map[string]any while only guarding against nil. A bundle whose CR
has a spec or status that is a JSON scalar or array instead of an
object (for example "spec": "foo") makes the unguarded assertion
panic with "interface conversion: interface {} is string, not
map[string]interface {}", crashing the scorecard test binary on
malformed or untrusted bundle content.

Use comma-ok assertions at all four sites so a non-object spec or
status is handled the same as a missing one: the spec-descriptors
check reports a failed descriptor, and the status/validation checks
skip the field cleanly. Add regression tests that drive the real
check functions with a scalar spec and an array status and assert
they do not panic.

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@acornett21
acornett21 merged commit 49ef743 into operator-framework:master Jul 16, 2026
22 of 23 checks passed
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.

2 participants