Skip to content

⭐ model runtime cache images#8452

Open
MaxRink wants to merge 1 commit into
mondoohq:mainfrom
MaxRink:codex/runtime-cache-image-model-plan
Open

⭐ model runtime cache images#8452
MaxRink wants to merge 1 commit into
mondoohq:mainfrom
MaxRink:codex/runtime-cache-image-model-plan

Conversation

@MaxRink

@MaxRink MaxRink commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add MQL resources for node-local runtime delegates, runtime images, and runtime image layers
  • add Kubernetes runtime-cache-images discovery that reads the operator-provided delegate file, filters pod image observations to runtime-cache-node-name, and emits runtime-image scan assets instead of pull-capable registry-image assets
  • add the OS runtime-image connection type with an initial no-pull containerd implementation: connect to the configured mounted socket, export the already-cached image through containerd image/content services, load the OCI layout locally, and reuse the existing tar-based container scanner
  • keep existing container-images, docker-image, and registry-image behavior unchanged; unsupported runtime delegate kinds fail closed rather than falling back to registry pulls

Review fixes

  • run runtime-cache discovery once at cluster scope in the legacy discovery path so a digest reused across namespaces emits one scan asset per node/delegate cycle instead of one asset per namespace
  • add a legacy no-staged-discovery regression test that asserts one digest asset with both namespaces in the runtime-cache annotations
  • align new runtime image source headers with the repo copyright format
  • make missing pod UID/node information report notPresent instead of runtimeUnavailable
  • look up the matching pod UID before reading nodeName, avoiding unrelated pod deserialization errors

Validation

  • git diff --check
  • go test ./providers/os/connection/container -run 'TestRuntimeImage|TestContainerd'
  • go test ./providers/os/resources -run 'Test(SplitImageReferenceNames|NormalizeRuntimeImageID|StringsSetToAnySortsValues|RuntimeImageArgsFromReference)'
  • cd providers/k8s && go test ./resources -run 'Test(RuntimeCache|DiscoverRuntimeCache|RuntimeImage|Containerd|Split|Normalize|StringsSet)'
  • cd providers/k8s && go test ./resources
  • cd providers/k8s && go test ./resources -run 'TestDiscover.*RuntimeCache|TestRuntimeCache|TestLoadRuntimeCacheSettings|Test(NodeNameForPodUID|ContainerStatusPodUID|RuntimeImage)'
  • cd providers/os && go test ./connection/container ./resources -run 'Test.*Runtime|TestContainerd'

Notes

  • This draft supports read-only containerd delegates first and does not require a ctr binary in the scanner image. CRI-O, Docker, Podman, native CRI clients, richer result modeling, and further per-node scan-result reuse remain explicit follow-up work in the plan doc.

@MaxRink MaxRink changed the title docs: plan runtime cache image model feat: model runtime cache images Jun 16, 2026
@tas50 tas50 changed the title feat: model runtime cache images ⭐ model runtime cache images Jun 18, 2026
@MaxRink MaxRink marked this pull request as ready for review June 19, 2026 08:15
@MaxRink MaxRink force-pushed the codex/runtime-cache-image-model-plan branch from 2ad27a0 to 7551857 Compare June 19, 2026 08:39

@mondoo-code-review mondoo-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New runtime cache image model adds init/ephemeral container status accessors and image-to-runtime matching for K8s pods.

Comment thread providers/k8s/resources/pod.go Outdated
Comment thread providers/k8s/resources/pod.go
@MaxRink MaxRink force-pushed the codex/runtime-cache-image-model-plan branch 2 times, most recently from 7173249 to 7543f73 Compare June 25, 2026 00:25

@mondoo-code-review mondoo-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New runtime cache image fields use stale version numbers in .lr.versions, which will cause version tracking inconsistencies.

Comment thread providers/k8s/resources/k8s.lr.versions Outdated
Comment thread providers/k8s/resources/pod.go
@MaxRink MaxRink force-pushed the codex/runtime-cache-image-model-plan branch from 7543f73 to a292050 Compare June 25, 2026 00:49
@mondoo-code-review mondoo-code-review Bot dismissed their stale review June 25, 2026 00:50

Superseded by new review

@mondoo-code-review mondoo-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds runtime cache image discovery and scanning support for Kubernetes container images via containerd delegates.

Comment thread providers/os/connection/container/runtime_image.go
Comment thread providers/k8s/resources/pod.go
Comment thread providers/os/connection/container/runtime_image.go
@MaxRink MaxRink force-pushed the codex/runtime-cache-image-model-plan branch from a292050 to ea83e13 Compare June 25, 2026 01:03

@mondoo-code-review mondoo-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delegate fallback leaks mutated config on success path; layer throttling semaphore provides no effective concurrency limit.

Comment thread providers/os/connection/container/runtime_image.go Outdated
Comment thread providers/os/connection/container/runtime_image.go
@MaxRink MaxRink force-pushed the codex/runtime-cache-image-model-plan branch from ea83e13 to e719c54 Compare June 25, 2026 01:13

@mondoo-code-review mondoo-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race condition in throttledReadCloser.acquire() can permanently leak semaphore slots, eventually deadlocking all layer reads.

Comment thread providers/os/connection/container/runtime_image.go Outdated
Comment thread providers/k8s/resources/discovery.go
Comment thread providers/k8s/resources/pod.go
Comment thread providers/k8s/resources/pod.go
@MaxRink MaxRink force-pushed the codex/runtime-cache-image-model-plan branch from e719c54 to 58a00c1 Compare June 25, 2026 01:20
@mondoo-code-review mondoo-code-review Bot dismissed their stale review June 25, 2026 01:21

Superseded by new review

@mondoo-code-review mondoo-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds runtime cache image model for K8s container status matching with comprehensive test coverage.

Comment on lines +377 to +382
plugin.Resource
GetKind() *plugin.TValue[string]
}

type runtimeDelegateEndpointResource interface {
plugin.Resource

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 warningsharedRuntimeField silently swallows errors from runtime.GetSharedData — if the shared runtime returns a transient error (network blip, timeout), the caller sees false and falls through to a potentially incorrect match result instead of propagating the failure. Consider at minimum logging the error, or returning it so callers can distinguish "field not available" from "lookup failed".

Comment on lines +253 to +275
if !ok || node.Name.Data != nodeName {
continue
}
delegates := node.GetRuntimeDelegates()
if delegates.Error != nil {
return nil, false, delegates.Error
}
if !runtimeDelegateAvailable(k.MqlRuntime, delegates.Data, runtimeKindFromContainerID(k.ContainerId.Data)) {
return nil, false, nil
}

images := node.GetRuntimeImages()
if images.Error != nil {
return nil, true, images.Error
}
keys := runtimeImageMatchKeys(k.Image.Data, k.ImageId.Data)
digestKeys := runtimeImageDigestMatchKeys(k.ImageId.Data)
matches := []plugin.Resource{}
for _, item := range images.Data {
image, ok := item.(plugin.Resource)
if !ok {
continue
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestionruntimeImageMatches iterates all nodes to find the one matching nodeName, then iterates all images on that node. If the node has many images, the digest-key fast path (lines 265-269) skips tag matching entirely via continue, which is correct — but the keys map built on line 260 always includes both image and imageID candidates even when only digestKeys will be used. Minor: you could defer building keys until after the len(digestKeys) == 0 check to avoid unnecessary map allocations.

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.

1 participant